From 3f6b28c4fb48f7e9cbfe5b71837679aee7a6f732 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Wed, 9 Jan 2019 00:24:34 +0100 Subject: [PATCH 04/12] tests: migrate test 'printf_escapechars' to the new testsuite For migrating, merge with the basic structure from 'tests/sample-test', i.e., source in 'tests/init.sh', call 'print_ver_', "Exit $fail", etc. Also remove now-common functions like die() and framework_failure_(). * find/testsuite/test_escapechars.golden: Remove, as the axpected output is created on the fly by the new test. * find/testsuite/test_escapechars.sh: Move to ... * tests/find/printf_escapechars.sh: ... this, and apply the above. Create the expected output on the fly, and also check for the expected error diagnostic on stderr. * find/testsuite/Makefile.am (EXTRA_DIST_GOLDEN): Remove. (EXTRA_DIST): Remove $(EXTRA_DIST_GOLDEN). (tests_shell_progs): Remove the reference to this test ... * tests/local.mk (all_tests): .. and add it here. --- find/testsuite/Makefile.am | 6 +- find/testsuite/test_escapechars.golden | 13 ---- find/testsuite/test_escapechars.sh | 59 ------------------ tests/find/printf_escapechars.sh | 86 ++++++++++++++++++++++++++ tests/local.mk | 1 + 5 files changed, 88 insertions(+), 77 deletions(-) delete mode 100644 find/testsuite/test_escapechars.golden delete mode 100755 find/testsuite/test_escapechars.sh create mode 100755 tests/find/printf_escapechars.sh diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am index 1e88c6c3..a5861f53 100644 --- a/find/testsuite/Makefile.am +++ b/find/testsuite/Makefile.am @@ -251,11 +251,7 @@ find.posix/typesize.exp \ find.posix/user-empty.exp \ find.posix/user-missing.exp -EXTRA_DIST_GOLDEN = \ - test_escapechars.golden - test_shell_progs = \ -test_escapechars.sh \ test_escape_c.sh \ test_inode.sh \ test_type-list.sh \ @@ -264,7 +260,7 @@ sv-48030-exec-plus-bug.sh \ sv-48180-refuse-noop.sh \ sv-52220.sh -EXTRA_DIST = $(EXTRA_DIST_EXP) $(EXTRA_DIST_XO) $(EXTRA_DIST_GOLDEN) \ +EXTRA_DIST = $(EXTRA_DIST_EXP) $(EXTRA_DIST_XO) \ $(test_shell_progs) binary_locations.sh checklists.py CLEANFILES = *.log *.sum site.exp site.bak configured-testfiles.txt diff --git a/find/testsuite/test_escapechars.golden b/find/testsuite/test_escapechars.golden deleted file mode 100644 index c5cd8ede..00000000 --- a/find/testsuite/test_escapechars.golden +++ /dev/null @@ -1,13 +0,0 @@ -OCTAL1:  -OCTAL2:  -OCTAL3:  -OCTAL4: 4 -OCTAL8: 8 -BEL:  -CR: -FF: -TAB: -VTAB: -BS:  -BACKSLASH: \ -UNKNOWN: \z diff --git a/find/testsuite/test_escapechars.sh b/find/testsuite/test_escapechars.sh deleted file mode 100755 index 1d4dd27e..00000000 --- a/find/testsuite/test_escapechars.sh +++ /dev/null @@ -1,59 +0,0 @@ -#! /bin/sh -# Copyright (C) 2011-2019 Free Software Foundation, Inc. -# -# This program 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. -# -# This program 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 . -# -testname="$(basename $0)" - -. "${srcdir}"/binary_locations.sh - -goldenfile="${srcdir}/test_escapechars.golden" - -if outfile=$(mktemp); then - for executable in "$oldfind" "$ftsfind" - do - if "$executable" . -maxdepth 0 \ - -printf 'OCTAL1: \1\n' \ - -printf 'OCTAL2: \02\n' \ - -printf 'OCTAL3: \003\n' \ - -printf 'OCTAL4: \0044\n' \ - -printf 'OCTAL8: \0028\n' \ - -printf 'BEL: \a\n' \ - -printf 'CR: \r\n' \ - -printf 'FF: \f\n' \ - -printf 'TAB: \t\n' \ - -printf 'VTAB: \v\n' \ - -printf 'BS: \b\n' \ - -printf 'BACKSLASH: \\\n' \ - -printf 'UNKNOWN: \z\n' \ - >| "${outfile}" 2>/dev/null; then - if cmp "${outfile}" "${goldenfile}"; then - rm "${outfile}" - else - exec >&2 - echo "FAIL: $executable produced incorrect output:" - od -c "${outfile}" - echo "Expected output was:" - od -c "${goldenfile}" - exit 1 - fi - else - echo "FAIL: $executable returned $?" >&2 - exit 1 - fi - done -else - echo "FAIL: could not create a test output file." >&2 - exit 1 -fi diff --git a/tests/find/printf_escapechars.sh b/tests/find/printf_escapechars.sh new file mode 100755 index 00000000..861dd0b0 --- /dev/null +++ b/tests/find/printf_escapechars.sh @@ -0,0 +1,86 @@ +#!/bin/sh +# Test -printf with octal and letter escapes. + +# Copyright (C) 2011-2019 Free Software Foundation, Inc. + +# This program 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. + +# This program 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 . + +. "${srcdir=.}/tests/init.sh" +print_ver_ find oldfind + +# Check for working od(1). +echo test | od -c >/dev/null \ + || skip_ "no working 'od -c' found" + +# Create file with expected output interpreted as octal; use: +# $ printf '%s' \ +# $'OCTAL1: \1\n' \ +# $'OCTAL2: \02\n' \ +# $'OCTAL3: \003\n' \ +# $'OCTAL4: \0044\n' \ +# $'OCTAL8: \0028\n' \ +# $'BEL: \a\n' \ +# $'CR: \r\n' \ +# $'FF: \f\n' \ +# $'TAB: \t\n' \ +# $'VTAB: \v\n' \ +# $'BS: \b\n' \ +# $'BACKSLASH: \\\n' \ +# $'UNKNOWN: \z\n' \ +# | od -t o1 +cat <<_EOD_ > expout || framework_failure_ +0000000 117 103 124 101 114 061 072 040 001 012 117 103 124 101 114 062 +0000020 072 040 002 012 117 103 124 101 114 063 072 040 003 012 117 103 +0000040 124 101 114 064 072 040 004 064 012 117 103 124 101 114 070 072 +0000060 040 002 070 012 102 105 114 072 040 007 012 103 122 072 040 015 +0000100 012 106 106 072 040 014 012 124 101 102 072 040 011 012 126 124 +0000120 101 102 072 040 013 012 102 123 072 040 010 012 102 101 103 113 +0000140 123 114 101 123 110 072 040 134 012 125 116 113 116 117 127 116 +0000160 072 040 134 172 012 +0000165 +_EOD_ + +# Prepare expected stderr. +echo "warning: unrecognized escape" > experr || framework_failure_ + +for executable in oldfind find; do + rm -f out* err* || framework_failure_ + + $executable . -maxdepth 0 \ + -printf 'OCTAL1: \1\n' \ + -printf 'OCTAL2: \02\n' \ + -printf 'OCTAL3: \003\n' \ + -printf 'OCTAL4: \0044\n' \ + -printf 'OCTAL8: \0028\n' \ + -printf 'BEL: \a\n' \ + -printf 'CR: \r\n' \ + -printf 'FF: \f\n' \ + -printf 'TAB: \t\n' \ + -printf 'VTAB: \v\n' \ + -printf 'BS: \b\n' \ + -printf 'BACKSLASH: \\\n' \ + -printf 'UNKNOWN: \z\n' \ + > out 2> err || fail=1 + + # Some 'od' implementations (e.g. on the *BSDs) produce different indentation + # and trailing spaces, therefore squeeze the former and remove the latter. + od -t o1 < out | sed 's/ */ /g; s/ *$//;' > out2 || framework_failure_ + compare expout out2 || fail=1 + + sed 's/^.*\(warning: unrecognized escape\) .*$/\1/' err > err2 \ + || framework_failure_ + compare experr err2 || fail=1 +done + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 292ff54f..d5e88081 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -106,6 +106,7 @@ all_tests = \ tests/misc/help-version.sh \ tests/find/many-dir-entries-vs-OOM.sh \ tests/find/name-lbracket-literal.sh \ + tests/find/printf_escapechars.sh \ $(all_root_tests) $(TEST_LOGS): $(PROGRAMS) -- 2.20.1