summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorG. Branden Robinson <g.branden.robinson@gmail.com>2024-01-13 08:08:16 -0600
committerG. Branden Robinson <g.branden.robinson@gmail.com>2024-01-13 08:08:16 -0600
commit974c063f0a9e1ef6c0d2cac4755a3b9d6e925b0d (patch)
tree2763737a9e49aa06e9f96f4609e0ac13721e2cad
parent1f1731a5e275179a96737f0e5f0710b4d965fae3 (diff)
[troff]: Unit-test device control spec chars.
* src/roff/groff/tests/device-control-special-character-handling.sh: Add unit test for this feature. We want to be able to consistently pass (some) special character escape sequences to device control commands, and we want the `device` request and `\X` escape sequences to behave consistently with each other. * src/roff/groff/groff.am (groff_TESTS): Run test. Test fails at this commit. See Savannah #64484.
-rw-r--r--ChangeLog10
-rw-r--r--src/roff/groff/groff.am1
-rwxr-xr-xsrc/roff/groff/tests/device-control-special-character-handling.sh77
3 files changed, 88 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0d9860dde..45db977cc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,15 @@
2024-01-13 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * src/roff/groff/tests/\
+ device-control-special-character-handling.sh: Add unit test for
+ this feature. We want to be able to consistently pass (some)
+ special character escape sequences to device control commands,
+ and we want the `device` request and `\X` escape sequences to
+ behave consistently with each other.
+ * src/roff/groff/groff.am (groff_TESTS): Run test.
+
+2024-01-13 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* src/roff/troff/input.cpp (encode_char_for_troff_output):
Qualify `c` argument as `const`. Reorder comparisons to avoid
inadvertent lvalue assignment. (Yes--suspenders _and_ a belt.)
diff --git a/src/roff/groff/groff.am b/src/roff/groff/groff.am
index 99a8ced95..5c7ed2f3b 100644
--- a/src/roff/groff/groff.am
+++ b/src/roff/groff/groff.am
@@ -45,6 +45,7 @@ groff_TESTS = \
src/roff/groff/tests/detect-evil-link-time-optimizer.sh \
src/roff/groff/tests/device-request-works.sh \
src/roff/groff/tests/device_control_escapes_express_basic_latin.sh \
+ src/roff/groff/tests/device-control-special-character-handling.sh \
src/roff/groff/tests/do_not_loop_infinitely_when_breaking_cjk.sh \
src/roff/groff/tests/dot-cp_register_works.sh \
src/roff/groff/tests/dot-nm_register_works.sh \
diff --git a/src/roff/groff/tests/device-control-special-character-handling.sh b/src/roff/groff/tests/device-control-special-character-handling.sh
new file mode 100755
index 000000000..5ad3713d7
--- /dev/null
+++ b/src/roff/groff/tests/device-control-special-character-handling.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 Free Software Foundation, Inc.
+#
+# This file is part of groff.
+#
+# groff is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# groff is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo ...FAILED >&2
+ fail=YES
+}
+
+input='.nf
+\X#bogus1: esc \%man-beast\[u1F63C]\\[u1F00] -\[aq]\[dq]\[ga]\[ha]\[rs]\[ti]#
+.device bogus1: req \%man-beast\[u1F63C]\\[u1F00] -\[aq]\[dq]\[ga]\[ha]\[rs]\[ti]
+.ec @
+@X#bogus2: esc @%man-beast@[u1F63C]@@[u1F00] -@[aq]@[dq]@[ga]@[ha]@[rs]@[ti]#
+.device bogus2: req @%man-beast@[u1F63C]@@[u1F00] -@[aq]@[dq]@[ga]@[ha]@[rs]@[ti]'
+
+output=$(printf '%s\n' "$input" | "$groff" -T ps -Z 2> /dev/null \
+ | grep '^x X')
+error=$(printf '%s\n' "$input" | "$groff" -T ps -Z 2>&1 > /dev/null)
+
+echo "$output"
+
+echo "checking X escape sequence, default escape character" >&2
+# x X bogus1: esc man-beast\[u1F00] -'"`^\~
+echo "$output" \
+ | grep -qx 'x X bogus1: esc man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+ || wail
+
+echo "checking device request, default escape character" >&2
+# x X bogus1: req man-beast\[u1F00] -'"`^\~
+echo "$output" \
+ | grep -qx 'x X bogus1: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+ || wail
+
+echo "checking X escape sequence, alternate escape character" >&2
+# x X bogus2: esc man-beast\[u1F00] -'"`^\~
+echo "$output" \
+ | grep -qx 'x X bogus2: esc man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+ || wail
+
+echo "checking device request, alternate escape character" >&2
+# x X bogus2: req man-beast\[u1F00] -'"`^\~
+echo "$output" \
+ | grep -qx 'x X bogus2: req man-beast\\\[u1F00\] -'"'"'"`^\\~' \
+ || wail
+
+echo "checking for errors on unsupported special character escapes" >&2
+for lineno in 2 3 5 6
+do
+ echo "$error" \
+ | grep -q 'troff:.*:'$lineno':.* invalid.*device control command' \
+ || wail
+done
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72: