From: Bruno Haible Date: Mon, 4 Aug 2025 11:23:54 +0000 (+0200) Subject: nlcanon: Add tests. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7fd19908502c4c49e1d5beb73242ac96d256dbc;p=thirdparty%2Fgnulib.git nlcanon: Add tests. * tests/test-nlcanon.sh: New file. * modules/nlcanon-tests: New file. * tests/init.sh (setup_): Adjust also top_builddir, if set. --- diff --git a/ChangeLog b/ChangeLog index ece157234f..867b5886a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2025-08-04 Bruno Haible + nlcanon: Add tests. + * tests/test-nlcanon.sh: New file. + * modules/nlcanon-tests: New file. + * tests/init.sh (setup_): Adjust also top_builddir, if set. + nlcanon: New module. * build-aux/nlcanon.sh.in: New file, with a function func_tmpdir taken from build-aux/csharpexec.sh.in. diff --git a/modules/nlcanon-tests b/modules/nlcanon-tests new file mode 100644 index 0000000000..bfcecda38e --- /dev/null +++ b/modules/nlcanon-tests @@ -0,0 +1,10 @@ +Files: +tests/test-nlcanon.sh + +Depends-on: +test-framework-sh + +Makefile.am: +TESTS += test-nlcanon.sh +TESTS_ENVIRONMENT += \ + top_builddir='@top_builddir@' diff --git a/tests/init.sh b/tests/init.sh index d695020545..d3ce11dbee 100644 --- a/tests/init.sh +++ b/tests/init.sh @@ -428,13 +428,21 @@ setup_ () test_dir_=`mktempd_ "$initial_cwd_" "$pfx_-$ME_.XXXX"` \ || fail_ "failed to create temporary directory in $initial_cwd_" cd "$test_dir_" || fail_ "failed to cd to temporary directory" - # Set variables srcdir, builddir, for the convenience of the test. + # Set variables srcdir, builddir, and optionally top_builddir, + # for the convenience of the test. case $srcdir in /* | ?:*) ;; *) srcdir="../$srcdir" ;; esac builddir=".." export srcdir builddir + if test -n "$top_builddir"; then + case $top_builddir in + /* | ?:*) ;; + *) top_builddir="../$top_builddir" ;; + esac + export top_builddir + fi # As autoconf-generated configure scripts do, ensure that IFS # is defined initially, so that saving and restoring $IFS works. diff --git a/tests/test-nlcanon.sh b/tests/test-nlcanon.sh new file mode 100755 index 0000000000..ddcfc1cd9f --- /dev/null +++ b/tests/test-nlcanon.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +if test $# != 0; then + # Callee. + printf 'stdout-contents\r\n' + printf 'stderr-contents\r\n' 1>&2 + exit $1 +else + # Unit test. + . "${srcdir=.}/init.sh"; path_prepend_ . + + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42 + # Test the exit code. + test $? = 42 || Exit 11 + # Test standard output. + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42 | grep stdout + test $? = 0 || Exit 12 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42 | grep stderr + test $? != 0 || Exit 13 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42 | tr '\r' r | grep contentsr + test $? != 0 || Exit 14 + # Test standard error. + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stdout + test $? != 0 || Exit 15 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stderr + test $? = 0 || Exit 16 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | tr '\r' r | grep contentsr + test $? = 0 || Exit 17 + + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42 + # Test the exit code. + test $? = 42 || Exit 21 + # Test standard output. + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42 | grep stdout + test $? = 0 || Exit 22 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42 | grep stderr + test $? != 0 || Exit 23 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42 | tr '\r' r | grep contentsr + test $? = 0 || Exit 24 + # Test standard error. + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stdout + test $? != 0 || Exit 25 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stderr + test $? = 0 || Exit 26 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | tr '\r' r | grep contentsr + test $? != 0 || Exit 27 + + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42 + # Test the exit code. + test $? = 42 || Exit 31 + # Test standard output. + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42 | grep stdout + test $? = 0 || Exit 32 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42 | grep stderr + test $? != 0 || Exit 33 + $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42 | tr '\r' r | grep contentsr + test $? != 0 || Exit 34 + # Test standard error. + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stdout + test $? != 0 || Exit 35 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | grep stderr + test $? = 0 || Exit 36 + { $BOURNE_SHELL ${top_builddir}/nlcanon.sh all stdout,stderr "${srcdir}/test-nlcanon.sh" 42; } 2>&1 >/dev/null | tr '\r' r | grep contentsr + test $? != 0 || Exit 37 + + Exit 0 +fi