Module Name:    src
Committed By:   rillig
Date:           Sun Jan 10 21:26:12 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: t_integration.sh

Log Message:
lint: allow custom flags to be specified in all unit tests

Previously, only the tests called msg_*.c could use this feature.  Since
it is useful for other tests as well, enable it everywhere.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/tests/usr.bin/xlint/lint1/t_integration.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/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.24 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.25
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.24	Sun Jan 10 18:06:38 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun Jan 10 21:26:12 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.24 2021/01/10 18:06:38 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.25 2021/01/10 21:26:12 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -29,17 +29,44 @@ LINT1=/usr/libexec/lint1
 
 Names=
 
+extract_flags()
+{
+	local extract_flags_awk
+
+	# shellcheck disable=SC2016
+	extract_flags_awk='
+		BEGIN {
+			flags = "-g -S -w"
+		}
+		/^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
+			if ($2 == "lint1-flags:")
+				flags = ""
+			for (i = 3; i < NF; i++)
+				flags = flags " " $i
+		}
+		END {
+			print flags
+		}
+	'
+
+	awk "$extract_flags_awk" "$@"
+}
+
+# shellcheck disable=SC2155
 check_lint1()
 {
 	local src="$(atf_get_srcdir)/$1"
 	local exp="${src%.c}.exp"
+	local flags="$(extract_flags "${src}")"
 
 	if [ -f "${exp}" ]; then
+		# shellcheck disable=SC2086
 		atf_check -s not-exit:0 -o "file:${exp}" -e empty \
-		    ${LINT1} -g -S -w "${src}" /dev/null
+		    ${LINT1} ${flags} "${src}" /dev/null
 	else
+		# shellcheck disable=SC2086
 		atf_check -s exit:0 \
-		    ${LINT1} -g -S -w "${src}" /dev/null
+		    ${LINT1} ${flags} "${src}" /dev/null
 	fi
 }
 
@@ -155,25 +182,9 @@ all_messages_body() {
 	srcdir="$(atf_get_srcdir)"
 	ok="true"
 
-	# shellcheck disable=SC2016
-	extract_flags_awk='
-		BEGIN {
-			flags = "-g -S -w"
-		}
-		/^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
-			if ($2 == "lint1-flags:")
-				flags = ""
-			for (i = 3; i < NF; i++)
-				flags = flags " " $i
-		}
-		END {
-			print flags
-		}
-	'
-
 	for msg in $(seq 0 329); do
 		base="$(printf '%s/msg_%03d' "${srcdir}" "${msg}")"
-		flags="$(awk "$extract_flags_awk" "${base}.c")"
+		flags="$(extract_flags "${base}.c")"
 
 		# shellcheck disable=SC2154 disable=SC2086
 		${Atf_Check} -s not-exit:0 -o "file:${base}.exp" -e empty \

Reply via email to