Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/indent tests/indent: allow golden stderr file,...



details:   https://anonhg.NetBSD.org/src/rev/3edf6341df93
branches:  trunk
changeset: 960124:3edf6341df93
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Mar 08 20:01:16 2021 +0000

description:
tests/indent: allow golden stderr file, improve filenames, clean up code

When indent runs in filter mode, it may output messages to stderr.
Allow tests with non-empty expected stderr.

In the ATF output, the filename 'output_file.parsed' was not helpful for
casual readers of diff output since they expect the filenames to be
meaningful.  Embed the name of the test case in that filename.

Fix quoting of the shell variables.

Remove the repetition of the regular expression to clean up the test
files.

diffstat:

 tests/usr.bin/indent/t_indent.sh |  39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diffs (58 lines):

diff -r 980a0ff25e8a -r 3edf6341df93 tests/usr.bin/indent/t_indent.sh
--- a/tests/usr.bin/indent/t_indent.sh  Mon Mar 08 19:38:10 2021 +0000
+++ b/tests/usr.bin/indent/t_indent.sh  Mon Mar 08 20:01:16 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_indent.sh,v 1.2 2021/03/07 08:57:38 rillig Exp $
+# $NetBSD: t_indent.sh,v 1.3 2021/03/08 20:01:16 rillig Exp $
 #
 # Copyright 2016 Dell EMC
 # All rights reserved.
@@ -44,25 +44,32 @@
        # IDs, preventing them to be broken into several lines.  It also
        # allows for remarks that are only needed in either the input or the
        # output.  These removals affect the line numbers in the diffs.
-       local out_file="${tc}.stdout"
-       if [ -f "${out_file}" ]; then
-               parsed_file=output_file.parsed
+       for fname in "$tc" "$tc.stdout" "$tc.stderr"; do
+               if [ -f "$fname" ]; then
+                       atf_check -o "save:$fname.clean" \
+                           sed -e '/^\/\*[[:space:]]$.*/d' "$fname"
+               fi
+       done
 
-               atf_check -o save:$parsed_file sed -e '/^\/\*[[:space:]]$.*/d' \
-                   ${tc}.stdout
-               out_flag="-o file:$parsed_file"
+       local out_arg='empty'
+       if [ -f "$tc.stdout.clean" ]; then
+               out_arg="file:$tc.stdout.clean"
        fi
-       local profile_file="${tc}.pro"
-       if [ -f "${profile_file}" ]; then
-               profile_flag="-P${profile_file}"
-       else
-               # Make sure we don't implicitly use ~/.indent.pro from the test
-               # host, for determinism purposes.
-               profile_flag="-npro"
+
+       local err_arg='empty'
+       if [ -f "$tc.stderr.clean" ]; then
+               err_arg="file:$tc.stderr.clean"
        fi
-       sed -e '/^\/\*[[:space:]]$.*/d'  ${tc} > input_file.parsed
 
-       atf_check -s exit:${tc##*.} ${out_flag} ${indent} ${profile_flag} < input_file.parsed
+       # Make sure we don't implicitly use ~/.indent.pro from the test
+       # host, for determinism purposes.
+       local pro_arg='-npro'
+       if [ -f "$tc.pro" ]; then
+               pro_arg="-P$tc.pro"
+       fi
+
+       atf_check -s "exit:${tc##*.}" -o "$out_arg" -e "$err_arg" \
+           "$indent" "$pro_arg" < "$tc.clean"
 }
 
 add_testcase()



Home | Main Index | Thread Index | Old Index