Source-Changes-HG archive

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

[src/trunk]: src tests/lint: test command line parsing for message and query IDs



details:   https://anonhg.NetBSD.org/src/rev/3aa4621f4b69
branches:  trunk
changeset: 374452:3aa4621f4b69
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Apr 23 08:47:27 2023 +0000

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

The parsing methods differ but shouldn't.

diffstat:

 distrib/sets/lists/tests/mi          |    3 +-
 tests/usr.bin/xlint/lint1/Makefile   |    4 +-
 tests/usr.bin/xlint/lint1/t_usage.sh |  135 +++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+), 3 deletions(-)

diffs (174 lines):

diff -r 2ed9d9a03f3f -r 3aa4621f4b69 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Apr 23 08:38:53 2023 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Apr 23 08:47:27 2023 +0000
@@ -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
diff -r 2ed9d9a03f3f -r 3aa4621f4b69 tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sun Apr 23 08:38:53 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sun Apr 23 08:47:27 2023 +0000
@@ -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
diff -r 2ed9d9a03f3f -r 3aa4621f4b69 tests/usr.bin/xlint/lint1/t_usage.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/t_usage.sh      Sun Apr 23 08:47:27 2023 +0000
@@ -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'
+}



Home | Main Index | Thread Index | Old Index