gbranden pushed a commit to branch master
in repository groff.
commit 0a71eba831d8e22b8fbac562d1cfab19992e61de
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Oct 21 14:28:35 2025 -0500
[gropdf]: Add unit tests.
...for pdfmom(1)'s replacement of external man page reference hyperlinks
with internal links to document bookmarks.
* tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh:
* tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh:
* tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh: Do it.
* tmac/tmac.am (tmac_TESTS): Run tests.
---
ChangeLog | 12 +++
.../an_MR-internal-hyperlinks-work-with-pdfmom.sh | 68 ++++++++++++
.../andoc_internal-hyperlinks-work-with-pdfmom.sh | 117 +++++++++++++++++++++
.../doc_Xr-internal-hyperlinks-work-with-pdfmom.sh | 74 +++++++++++++
tmac/tmac.am | 3 +
5 files changed, 274 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index c501d518d..8f08a48af 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2025-10-21 G. Branden Robinson <[email protected]>
+
+ [gropdf]: Add unit tests for pdfmom(1)'s replacement of external
+ man page reference hyperlinks with internal links to document
+ bookmarks.
+
+ * tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh:
+ * tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh:
+ * tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh: Do
+ it.
+ * tmac/tmac.am (tmac_TESTS): Run tests.
+
2025-10-21 G. Branden Robinson <[email protected]>
[gropdf]: Make pdfmom able to run the build tree's groff.
diff --git a/tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh
b/tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh
new file mode 100755
index 000000000..220b27662
--- /dev/null
+++ b/tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+#
+# Copyright 2025 G. Branden Robinson
+#
+# 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/>.
+
+pdfmom="${abs_top_builddir:-.}/pdfmom"
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo ...FAILED >&2
+ fail=yes
+}
+
+# We test backward links first because that is the more robust
+# operation; it doesn't require two-pass formatting.
+
+input='.
+.TH foo 1 2025-10-21 "groff test suite"
+.SH Name
+foo \\- a command with a very short name
+.SH Description
+The real work is done by
+.MR bar 1 .
+.TH bar 1 2025-10-21 "groff test suite"
+.SH Name
+bar \\- a command that is difficult to use
+.SH Description
+Novice users should avoid this command in favor of its wrapper,
+.MR foo 1 .
+.'
+
+output=$(echo "$input" \
+ | GROFF_COMMAND="$groff" "$pdfmom" --roff -rU1 -man -Z | nl -ba)
+echo "$output"
+
+# Expected (lines truncated):
+# 109 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /bar(1)
+# 265 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /foo(1)
+
+echo "checking that backward internal links work" >&2
+echo "$output" \
+ | grep -Eq '^ *265[[:space:]]+x X pdf: markstart .*/Dest /foo\(1\)' \
+ || wail
+
+echo "checking that forward internal links work" >&2
+echo "$output" \
+ | grep -Eq '^ *109[[:space:]]+x X pdf: markstart .*/Dest /bar\(1\)' \
+ || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
diff --git a/tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh
b/tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh
new file mode 100755
index 000000000..f7e91ce86
--- /dev/null
+++ b/tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh
@@ -0,0 +1,117 @@
+#!/bin/sh
+#
+# Copyright 2025 G. Branden Robinson
+#
+# 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/>.
+
+pdfmom="${abs_top_builddir:-.}/pdfmom"
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo ...FAILED >&2
+ fail=yes
+}
+
+# Test cross-package internal hyperlinks.
+#
+# We test backward links first because that is the more robust
+# operation; it doesn't require two-pass formatting.
+
+# First, arrange a man(7) document before an mdoc(7) one.
+
+input1='.
+.TH foo 1 2025-10-21 "groff test suite"
+.SH Name
+foo \\- a command with a very short name
+.SH Description
+The real work is done by
+.MR bar 1 .
+.Dd 2025-10-21
+.Dt bar 1
+.Os "groff test suite"
+.Sh Name
+.Nm bar
+.Nd a command that is difficult to use
+.Sh Description
+Novice users should avoid this command in favor of its wrapper,
+.Xr foo 1 .
+.'
+
+output1=$(echo "$input1" \
+ | GROFF_COMMAND="$groff" "$pdfmom" --roff -rU1 -mandoc -Z | nl -ba)
+echo "$output1"
+
+# Expected (lines truncated):
+# 109 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /bar(1)
+# 244 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /foo(1)
+
+echo "checking that backward internal link from mdoc(7) document" \
+ "to man(7) document works" >&2
+echo "$output1" \
+ | grep -Eq '^ *244[[:space:]]+x X pdf: markstart .*/Dest /foo\(1\)' \
+ || wail
+
+echo "checking that forward internal link from man(7) document" \
+ "to mdoc(7) document works" >&2
+echo "$output1" \
+ | grep -Eq '^ *109[[:space:]]+x X pdf: markstart .*/Dest /bar\(1\)' \
+ || wail
+
+# Second, arrange an mdoc(7) document before a man(7) one.
+
+input2='.
+.Dd 2025-10-21
+.Dt foo 1
+.Os "groff test suite"
+.Sh Name
+.Nm foo
+.Nd a command with a very short name
+.Sh Description
+The real work is done by
+.Xr bar 1 .
+.TH bar 1 2025-10-21 "groff test suite"
+.SH Name
+bar \\- a command that is difficult to use
+.SH Description
+Novice users should avoid this command in favor of its wrapper,
+.MR foo 1 .
+.'
+
+output2=$(echo "$input1" \
+ | GROFF_COMMAND="$groff" "$pdfmom" --roff -rU1 -mandoc -Z | nl -ba)
+echo "$output2"
+
+# Expected (lines truncated):
+# 109 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /bar(1)
+# 244 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /foo(1)
+
+echo "checking that backward internal link from man(7) document" \
+ "to mdoc(7) document works" >&2
+echo "$output2" \
+ | grep -Eq '^ *244[[:space:]]+x X pdf: markstart .*/Dest /foo\(1\)' \
+ || wail
+
+echo "checking that forward internal link from mdoc(7) document" \
+ "to man(7) document works" >&2
+echo "$output2" \
+ | grep -Eq '^ *109[[:space:]]+x X pdf: markstart .*/Dest /bar\(1\)' \
+ || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
diff --git a/tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh
b/tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh
new file mode 100755
index 000000000..663901e93
--- /dev/null
+++ b/tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh
@@ -0,0 +1,74 @@
+#!/bin/sh
+#
+# Copyright 2025 G. Branden Robinson
+#
+# 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/>.
+
+pdfmom="${abs_top_builddir:-.}/pdfmom"
+groff="${abs_top_builddir:-.}/test-groff"
+
+fail=
+
+wail () {
+ echo ...FAILED >&2
+ fail=yes
+}
+
+# We test backward links first because that is the more robust
+# operation; it doesn't require two-pass formatting.
+
+input='.
+.Dd 2025-10-21
+.Dt foo 1
+.Os "groff test suite"
+.Sh Name
+.Nm foo
+.Nd a command with a very short name
+.Sh Description
+The real work is done by
+.Xr bar 1 .
+.Dd 2025-10-21
+.Dt bar 1
+.Os "groff test suite"
+.Sh Name
+.Nm bar
+.Nd a command that is difficult to use
+.Sh Description
+Novice users should avoid this command in favor of its wrapper,
+.Xr foo 1 .
+.'
+
+output=$(echo "$input" \
+ | GROFF_COMMAND="$groff" "$pdfmom" --roff -rU1 -mdoc -Z | nl -ba)
+echo "$output"
+
+# Expected (lines truncated):
+# 90 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /bar(1)
+# 222 x X pdf: markstart 6830 -1770 2000 /Subtype /Link /Dest /foo(1)
+
+echo "checking that backward internal links work" >&2
+echo "$output" \
+ | grep -Eq '^ *222[[:space:]]+x X pdf: markstart .*/Dest /foo\(1\)' \
+ || wail
+
+echo "checking that forward internal links work" >&2
+echo "$output" \
+ | grep -Eq '^ *90[[:space:]]+x X pdf: markstart .*/Dest /bar\(1\)' \
+ || wail
+
+test -z "$fail"
+
+# vim:set autoindent expandtab shiftwidth=2 tabstop=2 textwidth=72:
diff --git a/tmac/tmac.am b/tmac/tmac.am
index bff99f2d6..138be42d6 100644
--- a/tmac/tmac.am
+++ b/tmac/tmac.am
@@ -144,6 +144,7 @@ tmac_TESTS = \
tmac/tests/an_HY-register-works.sh \
tmac/tests/an_LL-register-initializes-sanely.sh \
tmac/tests/an_ME-second-argument-hyphenates.sh \
+ tmac/tests/an_MR-internal-hyperlinks-work-with-pdfmom.sh \
tmac/tests/an_MR-works.sh \
tmac/tests/an_MT-body-hyphenates.sh \
tmac/tests/an_MT-works.sh \
@@ -193,6 +194,7 @@ tmac_TESTS = \
tmac/tests/andoc_check-an-to-doc-transition.sh \
tmac/tests/andoc_clear-doc-traps.sh \
tmac/tests/andoc_flush-between-packages.sh \
+ tmac/tests/andoc_internal-hyperlinks-work-with-pdfmom.sh \
tmac/tests/andoc_report-useful-line-numbers-in-diagnostics.sh \
tmac/tests/doc-old_vertical-margins-are-correct.sh \
tmac/tests/doc_CS-register-works.sh \
@@ -206,6 +208,7 @@ tmac_TESTS = \
tmac/tests/doc_Rs-works.sh \
tmac/tests/doc_TS-do-not-keep-tables-when-cR-set.sh \
tmac/tests/doc_X-register-works.sh \
+ tmac/tests/doc_Xr-internal-hyperlinks-work-with-pdfmom.sh \
tmac/tests/doc_Xr-works.sh \
tmac/tests/doc_accept-mixed-case-section-headings.sh \
tmac/tests/doc_adjustment-mode-restoration-works.sh \
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit