From 09e635cf97a1cc84d2d3110d7a5e2d9d45f37e32 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Mon, 30 Dec 2024 23:14:10 +0100 Subject: Add a --help/--version to AsciiDoc convertor liberty is now self-contained, from opt_handler to manual page. --- tests/help2adoc.sh | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100755 tests/help2adoc.sh (limited to 'tests') diff --git a/tests/help2adoc.sh b/tests/help2adoc.sh new file mode 100755 index 0000000..393c6a9 --- /dev/null +++ b/tests/help2adoc.sh @@ -0,0 +1,214 @@ +#!/bin/sh -e +# This test very exactly matches the output, +# but help2adoc is more or less feature-complete already. +self=$(realpath "$0") +help2adoc=$(realpath "$(dirname "$0")/../tools/help2adoc.awk") + +#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +test_oneline_help() { +cat <… — Be wild +What's happening? + -f, --frequency hz-2-foo frequency to --foo at + --foo=bar + Foobar. + Boo far. + + Subsection: + --help + --version + Oh my. + +Major section: +And now for something completely different. + Very wild +END +} + +test_wild_version() { +cat <<'END' +wild 1 +Copies left and right. +END +} + +test_wild_out() { +cat <<'END' +wild(1) +======= +:doctype: manpage +:manmanual: wild Manual +:mansource: wild 1 + +Name +---- +wild - manual page for wild 1 + +Synopsis +-------- +*wild* [__option__]... <__command__>... + + +Description +----------- +Be **wild** + +What's happening? + +*-f*, **--frequency** __hz-2-foo__:: + frequency to **--foo** at + +*--foo*=__bar__:: + Foobar. + Boo far. + + +Subsection +~~~~~~~~~~ + +*--help*:: + +*--version*:: + Oh my. + + +Major section +------------- +And now for something completely different. + Very wild +END +} + +#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +run() { + echo "-- help2adoc/$1" + local selfquoted=$(echo "$self" | sed 's/\\/&&/g') + local output=$(TEST=$1 awk -f "$help2adoc" -v Target="$selfquoted") + local expect="$($1_out)" + if [ "$output" = "$expect" ] + then return + fi + + echo "== Expected" + sed 's/^/ /' <<-END + $expect + END + echo "== Received" + sed 's/^/ /' <<-END + $output + END + exit 1 +} + +if [ -z "$TEST" ] +then + run test_oneline + run test_simple + run test_wild + echo "-- OK" +elif [ "$1" = "--help" ] +then ${TEST}_help +elif [ "$1" = "--version" ] +then ${TEST}_version +else + echo "Wrong usage" + exit 1 +fi -- cgit v1.2.3-70-g09d2