t_usage.sh revision 1.25 1 # $NetBSD: t_usage.sh,v 1.25 2024/11/28 22:32:53 rillig Exp $
2 #
3 # Copyright (c) 2023 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
14 #
15 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 # POSSIBILITY OF SUCH DAMAGE.
26 #
27
28 : "${lint1:=/usr/libexec/lint1}"
29
30
31 atf_test_case 'suppress_messages'
32 suppress_messages_body()
33 {
34 printf 'typedef int dummy;\n' > code.c
35
36 # Message IDs are 0-based.
37 atf_check \
38 "$lint1" -X 0 code.c /dev/null
39
40 # The largest known message.
41 atf_check \
42 "$lint1" -X 383 code.c /dev/null
43
44 # Larger than the largest known message.
45 atf_check \
46 -s 'exit:1' \
47 -e "inline:lint1: invalid message ID '384'\n" \
48 "$lint1" -X 384 code.c /dev/null
49
50 # Whitespace is not allowed before a message ID.
51 atf_check \
52 -s 'exit:1' \
53 -e "inline:lint1: invalid message ID ' 1'\n" \
54 "$lint1" -X ' 1' code.c /dev/null
55
56 # Whitespace is not allowed after a message ID.
57 atf_check \
58 -s 'exit:1' \
59 -e "inline:lint1: invalid message ID '1 '\n" \
60 "$lint1" -X '1 ' code.c /dev/null
61
62 # Multiple message IDs can be comma-separated.
63 atf_check \
64 "$lint1" -X '1,2,3,4' code.c /dev/null
65
66 # Whitespace is not allowed after a comma.
67 atf_check \
68 -s 'exit:1' \
69 -e "inline:lint1: invalid message ID ' 2'\n" \
70 "$lint1" -X '1, 2, 3, 4' code.c /dev/null
71
72 # Trailing commas are not allowed.
73 atf_check \
74 -s 'exit:1' \
75 -e "inline:lint1: invalid message ID ''\n" \
76 "$lint1" -X '1,,,,,,,' code.c /dev/null
77 }
78
79 atf_test_case 'enable_queries'
80 enable_queries_body()
81 {
82 printf 'typedef int dummy;\n' > code.c
83
84 # Query IDs are 1-based.
85 atf_check \
86 -s 'exit:1' \
87 -e "inline:lint1: invalid query ID '0'\n" \
88 "$lint1" -q 0 code.c /dev/null
89
90 # The largest known query.
91 atf_check \
92 "$lint1" -q 24 code.c /dev/null
93
94 # Larger than the largest known query.
95 atf_check \
96 -s 'exit:1' \
97 -e "inline:lint1: invalid query ID '25'\n" \
98 "$lint1" -q 25 code.c /dev/null
99
100 # Whitespace is not allowed before a query ID.
101 atf_check \
102 -s 'exit:1' \
103 -e "inline:lint1: invalid query ID ' 1'\n" \
104 "$lint1" -q ' 1' code.c /dev/null
105
106 # Whitespace is not allowed after a query ID.
107 atf_check \
108 -s 'exit:1' \
109 -e "inline:lint1: invalid query ID '1 '\n" \
110 "$lint1" -q '1 ' code.c /dev/null
111
112 # Multiple query IDs can be comma-separated.
113 atf_check \
114 "$lint1" -q '1,2,3,4' code.c /dev/null
115
116 # Whitespace is not allowed after a comma.
117 atf_check \
118 -s 'exit:1' \
119 -e "inline:lint1: invalid query ID ' 2'\n" \
120 "$lint1" -q '1, 2, 3, 4' code.c /dev/null
121
122 # Trailing commas are not allowed.
123 atf_check \
124 -s 'exit:1' \
125 -e "inline:lint1: invalid query ID ''\n" \
126 "$lint1" -q '1,,,,,,,' code.c /dev/null
127 }
128
129 atf_init_test_cases()
130 {
131 atf_add_test_case 'suppress_messages'
132 atf_add_test_case 'enable_queries'
133 }
134