xref: /netbsd-src/tests/usr.bin/xlint/lint1/t_integration.sh (revision 9fb66d812c00ebfb445c0b47dea128f32aa6fe96)
1# $NetBSD: t_integration.sh,v 1.41 2021/04/14 18:27:11 rillig Exp $
2#
3# Copyright (c) 2008, 2010 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
28LINT1=/usr/libexec/lint1
29
30Names=
31
32extract_flags()
33{
34	local extract_flags_awk
35
36	# shellcheck disable=SC2016
37	extract_flags_awk='
38		BEGIN {
39			flags = "-g -S -w"
40		}
41		/^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
42			if ($2 == "lint1-flags:")
43				flags = ""
44			for (i = 3; i < NF; i++)
45				flags = flags " " $i
46		}
47		END {
48			print flags
49		}
50	'
51
52	awk "$extract_flags_awk" "$@"
53}
54
55# shellcheck disable=SC2155
56check_lint1()
57{
58	local src="$(atf_get_srcdir)/$1"
59	local exp="${src%.c}.exp"
60	local flags="$(extract_flags "${src}")"
61
62	if [ -f "${exp}" ]; then
63		# shellcheck disable=SC2086
64		atf_check -s not-exit:0 -o "file:${exp}" -e empty \
65		    ${LINT1} ${flags} "${src}" /dev/null
66	else
67		# shellcheck disable=SC2086
68		atf_check -s exit:0 \
69		    ${LINT1} ${flags} "${src}" /dev/null
70	fi
71}
72
73test_case()
74{
75	local name="${1}"; shift
76	local descr="${*}"
77
78	atf_test_case ${name}
79	eval "${name}_head() {
80		if [ \"${descr}\" ]; then
81			atf_set \"descr\" \"${descr}\"
82		fi
83		atf_set \"require.progs\" \"${LINT1}\"
84	}"
85	eval "${name}_body() {
86		check_lint1 ${name}.c
87	}"
88
89	Names="${Names} ${name}"
90}
91
92test_case d_bltinoffsetof
93test_case d_c99_anon_struct
94test_case d_c99_anon_union
95test_case d_c99_bool
96test_case d_c99_bool_strict
97test_case d_c99_bool_strict_syshdr
98test_case d_c99_compound_literal_comma
99test_case d_c99_decls_after_stmt2
100test_case d_c99_flex_array_packed
101test_case d_c99_init
102test_case d_c99_nested_struct
103test_case d_c99_union_cast
104test_case d_c99_union_init4
105test_case d_c99_union_init5
106test_case d_cast_fun_array_param
107test_case d_cast_typeof
108test_case d_decl_old_style_arguments
109test_case d_fold_test
110test_case d_gcc_extension
111test_case d_init_array_using_string
112test_case d_init_pop_member
113test_case d_lint_assert
114test_case d_return_type
115test_case d_type_question_colon
116test_case d_typefun
117test_case d_typename_as_var
118
119test_case d_c99_struct_init
120test_case d_c99_union_init1
121test_case d_c99_union_init2
122test_case d_c99_union_init3
123test_case d_c99_recursive_init
124test_case d_c9x_recursive_init
125test_case d_nested_structs
126test_case d_packed_structs
127test_case d_pr_22119
128test_case d_struct_init_nested
129
130test_case d_cast_init
131test_case d_cast_init2
132test_case d_cast_lhs
133
134test_case d_gcc_func
135test_case d_c99_func
136
137test_case d_gcc_variable_array_init
138test_case d_c9x_array_init
139test_case d_c99_decls_after_stmt
140test_case d_c99_decls_after_stmt3
141test_case d_nolimit_init
142test_case d_zero_sized_arrays
143
144test_case d_compound_literals1
145test_case d_compound_literals2
146test_case d_gcc_compound_statements1
147test_case d_gcc_compound_statements2
148test_case d_gcc_compound_statements3
149
150# XXX: Because of polymorphic __builtin_isnan and expression has null effect
151# test_case gcc_extension "Checks GCC __extension__ and __typeof__"
152
153test_case d_cvt_in_ternary
154test_case d_cvt_constant
155test_case d_ellipsis_in_switch
156test_case d_c99_complex_num
157test_case d_c99_complex_split
158test_case d_c99_for_loops
159test_case d_alignof
160test_case d_shift_to_narrower_type
161test_case d_constant_conv1
162test_case d_constant_conv2
163test_case d_type_conv1
164test_case d_type_conv2
165test_case d_type_conv3
166test_case d_incorrect_array_size
167test_case d_long_double_int
168
169test_case op_colon
170
171test_case feat_stacktrace
172
173test_case all_messages
174all_messages_body()
175{
176	local failed msg
177
178	failed=""
179
180	for msg in $(seq 0 343); do
181		name="$(printf 'msg_%03d.c' "${msg}")"
182		check_lint1 "${name}" \
183		|| failed="$failed${failed:+ }$name"
184	done
185
186	if [ "$failed" != "" ]; then
187		atf_check "false" "$failed"
188	fi
189}
190
191
192atf_init_test_cases()
193{
194	for name in ${Names}; do
195		atf_add_test_case ${name}
196	done
197}
198