Module Name:    src
Committed By:   rillig
Date:           Mon Mar  8 20:01:16 UTC 2021

Modified Files:
        src/tests/usr.bin/indent: t_indent.sh

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/t_indent.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/indent/t_indent.sh
diff -u src/tests/usr.bin/indent/t_indent.sh:1.2 src/tests/usr.bin/indent/t_indent.sh:1.3
--- src/tests/usr.bin/indent/t_indent.sh:1.2	Sun Mar  7 08:57:38 2021
+++ src/tests/usr.bin/indent/t_indent.sh	Mon Mar  8 20:01:16 2021
@@ -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 @@ check()
 	# 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
-
-		atf_check -o save:$parsed_file sed -e '/^\/\*[[:space:]]$.*/d' \
-		    ${tc}.stdout
-		out_flag="-o file:$parsed_file"
+	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
+
+	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
+
+	# 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
-	sed -e '/^\/\*[[:space:]]$.*/d'  ${tc} > input_file.parsed
 
-	atf_check -s exit:${tc##*.} ${out_flag} ${indent} ${profile_flag} < input_file.parsed
+	atf_check -s "exit:${tc##*.}" -o "$out_arg" -e "$err_arg" \
+	    "$indent" "$pro_arg" < "$tc.clean"
 }
 
 add_testcase()

Reply via email to