Module Name:    src
Committed By:   rillig
Date:           Sun Jun 27 10:14:43 UTC 2021

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

Log Message:
tests/lint: allow skipping individual tests

Depending on the platform, some tests do not make sense or produce
platform-dependent results.  Allow these tests to be marked as such.

For example, the test lex_integer.c only works on 64-bit platforms.
Therefore it is disabled on i386 for now since it prints different
warnings there.  Even better would be a "lint1-only-on-lpi32" toggle,
but that would need detection of 'sizeof(int)' at runtime.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/lex_integer.c \
    src/tests/usr.bin/xlint/lint1/lex_integer.exp
cvs rdiff -u -r1.58 -r1.59 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/lex_integer.c
diff -u src/tests/usr.bin/xlint/lint1/lex_integer.c:1.1 src/tests/usr.bin/xlint/lint1/lex_integer.c:1.2
--- src/tests/usr.bin/xlint/lint1/lex_integer.c:1.1	Sat Jun 19 08:30:08 2021
+++ src/tests/usr.bin/xlint/lint1/lex_integer.c	Sun Jun 27 10:14:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lex_integer.c,v 1.1 2021/06/19 08:30:08 rillig Exp $	*/
+/*	$NetBSD: lex_integer.c,v 1.2 2021/06/27 10:14:43 rillig Exp $	*/
 # 3 "lex_integer.c"
 
 /*
@@ -7,6 +7,8 @@
  * C99 6.4.4.1 "Integer constants"
  */
 
+/* lint1-not-on-arch: i386 (has 32-bit long) */
+
 void sinki(int);
 void sinku(unsigned int);
 
Index: src/tests/usr.bin/xlint/lint1/lex_integer.exp
diff -u src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.1 src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.2
--- src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.1	Sat Jun 19 08:30:08 2021
+++ src/tests/usr.bin/xlint/lint1/lex_integer.exp	Sun Jun 27 10:14:43 2021
@@ -1,5 +1,5 @@
-lex_integer.c(25): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-lex_integer.c(25): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
-lex_integer.c(30): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
-lex_integer.c(42): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
-lex_integer.c(42): warning: conversion of 'unsigned long' to 'unsigned int' is out of range, arg #1 [295]
+lex_integer.c(27): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+lex_integer.c(27): warning: conversion of 'long' to 'int' is out of range, arg #1 [295]
+lex_integer.c(32): warning: argument #1 is converted from 'long' to 'int' due to prototype [259]
+lex_integer.c(44): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259]
+lex_integer.c(44): warning: conversion of 'unsigned long' to 'unsigned int' is out of range, arg #1 [295]

Index: src/tests/usr.bin/xlint/lint1/t_integration.sh
diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.58 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.59
--- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.58	Sun Jun 27 09:22:31 2021
+++ src/tests/usr.bin/xlint/lint1/t_integration.sh	Sun Jun 27 10:14:43 2021
@@ -1,4 +1,4 @@
-# $NetBSD: t_integration.sh,v 1.58 2021/06/27 09:22:31 rillig Exp $
+# $NetBSD: t_integration.sh,v 1.59 2021/06/27 10:14:43 rillig Exp $
 #
 # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -28,16 +28,19 @@
 lint1=/usr/libexec/lint1
 
 test_case_names=
+machine_arch="$(sysctl -n hw.machine_arch)"
 
 
-extract_flags()
+configure_test_case()
 {
-	local extract_flags_awk
+	local awk
 
 	# shellcheck disable=SC2016
-	extract_flags_awk='
+	awk='
 		BEGIN {
+			machine_arch = "'"$machine_arch"'"
 			flags = "-g -S -w"
+			skip = 0
 		}
 		/^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
 			if ($2 == "lint1-flags:")
@@ -45,12 +48,19 @@ extract_flags()
 			for (i = 3; i < NF; i++)
 				flags = flags " " $i
 		}
+		/^\/\* lint1-only-on-arch: .* \*\/$/ && $3 != machine_arch {
+			skip = 1
+		}
+		/^\/\* lint1-not-on-arch: .* \*\/$/ && $3 == machine_arch {
+			skip = 1
+		}
 		END {
-			print flags
+			printf("flags='\''%s'\''\n", flags)
+			printf("skip=%s\n", skip ? "yes" : "no")
 		}
 	'
 
-	awk "$extract_flags_awk" "$@"
+	eval "$(awk "$awk" "$1")"
 }
 
 # shellcheck disable=SC2155
@@ -60,13 +70,21 @@ check_lint1()
 	local exp="${src%.c}.exp"
 	local exp_ln="${src%.c}.ln"
 	local wrk_ln="${1%.c}.ln"
-	local flags="$(extract_flags "$src")"
+	local flags=""
+	local skip=""
 
 	if [ ! -f "$exp_ln" ]; then
 		exp_ln='/dev/null'
 		wrk_ln='/dev/null'
 	fi
 
+	configure_test_case "$src"
+
+	if [ "$skip" = "yes" ]; then
+		atf_check -o 'ignore' echo 'skipped'
+		return
+	fi
+
 	if [ -f "$exp" ]; then
 		# shellcheck disable=SC2086
 		atf_check -s not-exit:0 -o "file:$exp" -e empty \
@@ -77,7 +95,7 @@ check_lint1()
 		    "$lint1" $flags "$src" "$wrk_ln"
 	fi
 
-	if [ "$src_ln" != '/dev/null' ]; then
+	if [ "$exp_ln" != '/dev/null' ]; then
 		atf_check -o "file:$exp_ln" cat "$wrk_ln"
 	fi
 }

Reply via email to