Module Name:    src
Committed By:   rillig
Date:           Sun Apr 23 08:47:27 UTC 2023

Modified Files:
        src/distrib/sets/lists/tests: mi
        src/tests/usr.bin/xlint/lint1: Makefile
Added Files:
        src/tests/usr.bin/xlint/lint1: t_usage.sh

Log Message:
tests/lint: test command line parsing for message and query IDs

The parsing methods differ but shouldn't.


To generate a diff of this commit:
cvs rdiff -u -r1.1257 -r1.1258 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.140 -r1.141 src/tests/usr.bin/xlint/lint1/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/t_usage.sh

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1257 src/distrib/sets/lists/tests/mi:1.1258
--- src/distrib/sets/lists/tests/mi:1.1257	Fri Apr 21 21:50:05 2023
+++ src/distrib/sets/lists/tests/mi	Sun Apr 23 08:47:27 2023
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1257 2023/04/21 21:50:05 gutteridge Exp $
+# $NetBSD: mi,v 1.1258 2023/04/23 08:47:27 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -7384,6 +7384,7 @@
 ./usr/tests/usr.bin/xlint/lint1/stmt_if.c			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint1/stmt_if.exp			tests-obsolete		obsolete,atf
 ./usr/tests/usr.bin/xlint/lint1/t_integration			tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/xlint/lint1/t_usage				tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint2					tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint2/Atffile			tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/xlint/lint2/Kyuafile		tests-usr.bin-tests	compattestfile,atf,kyua

Index: src/tests/usr.bin/xlint/lint1/Makefile
diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.140 src/tests/usr.bin/xlint/lint1/Makefile:1.141
--- src/tests/usr.bin/xlint/lint1/Makefile:1.140	Sun Feb  5 17:23:01 2023
+++ src/tests/usr.bin/xlint/lint1/Makefile	Sun Apr 23 08:47:27 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.140 2023/02/05 17:23:01 rillig Exp $
+# $NetBSD: Makefile,v 1.141 2023/04/23 08:47:27 rillig Exp $
 
 NOMAN=		# defined
 
@@ -8,7 +8,7 @@ ARCHSUBDIR!=	cd ${NETBSDSRCDIR}/usr.bin/
 
 TESTSDIR=	${TESTSBASE}/usr.bin/xlint/lint1
 
-TESTS_SH=	t_integration
+TESTS_SH=	t_integration t_usage
 TESTS_SH_SRC_t_integration=	archsubdir.sh t_integration.sh
 CLEANFILES+=	archsubdir.sh
 CLEANFILES+=	*.exp

Added files:

Index: src/tests/usr.bin/xlint/lint1/t_usage.sh
diff -u /dev/null src/tests/usr.bin/xlint/lint1/t_usage.sh:1.1
--- /dev/null	Sun Apr 23 08:47:27 2023
+++ src/tests/usr.bin/xlint/lint1/t_usage.sh	Sun Apr 23 08:47:27 2023
@@ -0,0 +1,135 @@
+# $NetBSD: t_usage.sh,v 1.1 2023/04/23 08:47:27 rillig Exp $
+#
+# Copyright (c) 2023 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+: "${lint1:=/usr/libexec/lint1}"
+
+
+suppress_messages_head()
+{
+	:
+}
+
+suppress_messages_body()
+{
+	printf 'typedef int dummy;\n' > code.c
+
+	# Message IDs are 0-based.
+	atf_check \
+	    "$lint1" -X 0 code.c /dev/null
+
+	# The largest known message.
+	atf_check \
+	    "$lint1" -X 352 code.c /dev/null
+
+	# Larger than the largest known message.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid error message id '353'\n" \
+	    "$lint1" -X 353 code.c /dev/null
+
+	# XXX: Whitespace should not be allowed before a message ID.
+	atf_check \
+	    "$lint1" -X ' 1' code.c /dev/null
+
+	# Whitespace is not allowed after a message ID.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid error message id '1 '\n" \
+	    "$lint1" -X '1 ' code.c /dev/null
+
+	# Multiple message IDs can be comma-separated.
+	atf_check \
+	    "$lint1" -X '1,2,3,4' code.c /dev/null
+
+	# XXX: Whitespace should not be allowed after a comma.
+	atf_check \
+	    "$lint1" -X '1, 2, 3, 4' code.c /dev/null
+
+	# XXX: Trailing commas should not be allowed.
+	atf_check \
+	    "$lint1" -X '1,,,,,,,' code.c /dev/null
+}
+
+enable_queries_head()
+{
+	:
+}
+
+enable_queries_body()
+{
+	printf 'typedef int dummy;\n' > code.c
+
+	# Query IDs are 1-based.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID '0'\n" \
+	    "$lint1" -q 0 code.c /dev/null
+
+	# The largest known query.
+	atf_check \
+	    "$lint1" -q 9 code.c /dev/null
+
+	# Larger than the largest known query.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID '10'\n" \
+	    "$lint1" -q 10 code.c /dev/null
+
+	# Whitespace is not allowed before a query ID.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID ' 1'\n" \
+	    "$lint1" -q ' 1' code.c /dev/null
+
+	# Whitespace is not allowed after a query ID.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID '1 '\n" \
+	    "$lint1" -q '1 ' code.c /dev/null
+
+	# Multiple query IDs can be comma-separated.
+	atf_check \
+	    "$lint1" -q '1,2,3,4' code.c /dev/null
+
+	# Whitespace is not allowed after a comma.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID ' 2'\n" \
+	    "$lint1" -q '1, 2, 3, 4' code.c /dev/null
+
+	# Trailing commas are not allowed.
+	atf_check \
+	    -s 'exit:1' \
+	    -e "inline:lint1: invalid query ID ''\n" \
+	    "$lint1" -q '1,,,,,,,' code.c /dev/null
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case 'suppress_messages'
+	atf_add_test_case 'enable_queries'
+}

Reply via email to