]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
nlcanon: Add tests.
authorBruno Haible <bruno@clisp.org>
Mon, 4 Aug 2025 11:23:54 +0000 (13:23 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 4 Aug 2025 11:23:54 +0000 (13:23 +0200)
* tests/test-nlcanon.sh: New file.
* modules/nlcanon-tests: New file.
* tests/init.sh (setup_): Adjust also top_builddir, if set.

ChangeLog
modules/nlcanon-tests [new file with mode: 0644]
tests/init.sh
tests/test-nlcanon.sh [new file with mode: 0755]

index ece157234ffabd0bbdac936f251d16b48738295f..867b5886a900c02bb15f02e1172694ac971dde05 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2025-08-04  Bruno Haible  <bruno@clisp.org>
 
+       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 (file)
index 0000000..bfcecda
--- /dev/null
@@ -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@'
index d695020545f3b48304c078a03dafa7da7c2fa9bb..d3ce11dbee4b5a9609af23590093311062c35bea 100644 (file)
@@ -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 (executable)
index 0000000..ddcfc1c
--- /dev/null
@@ -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