diff --git a/ChangeLog b/ChangeLog index 19b3be599..b6ddb35b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2024-11-27 G. Branden Robinson + + Fix Savannah #66479 (1a/2). + + * HACKING: Document macOS wc(1) irritation. + + * tmac/tests/an_vertical-margins-are-correct.sh: + * tmac/tests/doc-old_vertical-margins-are-correct.sh: + * tmac/tests/doc_vertical-margins-are-correct.sh: Work around + macOS wc(1)'s right-alignment of its integer output field. + 2024-11-25 G. Branden Robinson * src/roff/troff/input.cpp (token::is_usable_as_delimiter): If diff --git a/HACKING b/HACKING index 2702eed18..3c2c8adf9 100644 --- a/HACKING +++ b/HACKING @@ -153,6 +153,19 @@ Here are some portability notes on writing automated tests. # emulate "seq 53" n=1; while [ $n -le 53 ]; do echo $n; n=$(( n + 1 )); done; unset n +* The "wc" command on macOS can prefix the numeric count in its output + with spaces, which can be undesirable when storing that output to + variable that is later expanded within double quotes in the shell. + + Here is a workaround. + + res=$(whatever | wc -l) + res=$(expr "$res" + 0) || exit 99 + + "expr"'s output is more rigidly specified, and if for some reason we + get unacceptable non-integer garbage from "wc", we exit the test + script with the code reserved for "hard errors". + * The "od" command on macOS can put extra space characters (i.e., spaces that don't correspond to the input) at the ends of lines when using the "od -t c" format; GNU od does not. diff --git a/tmac/tests/an_vertical-margins-are-correct.sh b/tmac/tests/an_vertical-margins-are-correct.sh index d12d330b4..f8c211cdf 100755 --- a/tmac/tests/an_vertical-margins-are-correct.sh +++ b/tmac/tests/an_vertical-margins-are-correct.sh @@ -89,7 +89,10 @@ output=$(printf "%s" "$input1" "$input2" \ echo "$output" echo "checking page length" >&2 -test "$(echo "$output" | wc -l)" = 66 || wail +res=$(echo "$output" | wc -l) +# macOS `wc` prefixes the line count with spaces. Get rid of them. +res=$(expr "$res" + 0) || exit 99 +test "$res" = 66 || wail echo "checking placement of page header" >&2 echo "$output" \ diff --git a/tmac/tests/doc-old_vertical-margins-are-correct.sh b/tmac/tests/doc-old_vertical-margins-are-correct.sh index 053157617..e7ce92ed3 100755 --- a/tmac/tests/doc-old_vertical-margins-are-correct.sh +++ b/tmac/tests/doc-old_vertical-margins-are-correct.sh @@ -91,7 +91,10 @@ output=$(printf "%s" "$input1" "$input2" \ echo "$output" echo "checking page length" >&2 -test "$(echo "$output" | wc -l)" = 66 || wail +res=$(echo "$output" | wc -l) +# macOS `wc` prefixes the line count with spaces. Get rid of them. +res=$(expr "$res" + 0) || exit 99 +test "$res" = 66 || wail echo "checking placement of page header" >&2 echo "$output" \ diff --git a/tmac/tests/doc_vertical-margins-are-correct.sh b/tmac/tests/doc_vertical-margins-are-correct.sh index addcfd5fb..90f922393 100755 --- a/tmac/tests/doc_vertical-margins-are-correct.sh +++ b/tmac/tests/doc_vertical-margins-are-correct.sh @@ -91,7 +91,10 @@ output=$(printf "%s" "$input1" "$input2" \ echo "$output" echo "checking page length" >&2 -test "$(echo "$output" | wc -l)" = 66 || wail +res=$(echo "$output" | wc -l) +# macOS `wc` prefixes the line count with spaces. Get rid of them. +res=$(expr "$res" + 0) || exit 99 +test "$res" = 66 || wail echo "checking placement of page header" >&2 echo "$output" \