t_xlint.sh revision 1.2
1# $NetBSD: t_xlint.sh,v 1.2 2023/06/28 09:35:43 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: "${lint:=/usr/bin/lint}"
29
30atf_test_case 'run_lint1_error'
31run_lint1_error_body()
32{
33	cat <<-EOF >input.c || atf_fail 'prepare input.c'
34		#include <stdbool.h>
35
36		bool
37		return_true(void)
38		{
39			return 1;
40		}
41	EOF
42	echo 'previous content' > input.ln
43
44	atf_check \
45	    -s 'exit:1' \
46	    -o "inline:input.c(6): error: function has return type '_Bool' but returns 'int' [211]\n" \
47	    "$lint" -aabceghiprSTxz input.c
48
49	# In case of an error, any previous output file is overwritten, and the
50	# (possibly unfinished) output file is removed.
51	atf_check \
52	    -s 'exit:1' \
53	    test -f input.ln
54}
55
56
57atf_test_case 'run_lint1_warning'
58run_lint1_warning_body()
59{
60	cat <<-EOF >input.c || atf_fail 'prepare input.c'
61		static int number;
62
63		const void *
64		function(int a, const char *s)
65		{
66			return s + a;
67		}
68	EOF
69	cat <<-EOF >input.exp || atf_fail 'prepare input.exp'
70		0sinput.c
71		Sinput.c
72		1s<built-in>
73		2s<command-line>
74		4d0.4dr8functionF2IPcCPcV
75	EOF
76
77	atf_check \
78	    -o "inline:input.c(1): warning: static variable 'number' unused [226]\n" \
79	    "$lint" -aabceghiprSTxz input.c
80	atf_check \
81	    -o 'file:input.exp' \
82	    cat input.ln
83}
84
85
86atf_test_case 'run_lint2'
87run_lint2_body()
88{
89	cat <<-EOF >input.ln || atf_fail 'prepare input.ln'
90		0sinput.c
91		Sinput.c
92		1s<built-in>
93		2s<command-line>
94		4d0.4dr8functionF2IPcCPcV
95	EOF
96
97	# Most of the command line options are not relevant for lint2,
98	# so they are effectively ignored.  The option '-i' is absent.
99	atf_check \
100	    -o 'inline:function defined( input.c(4) ), but never used\n' \
101	    -e 'inline:lint: cannot find llib-lc.ln\n' \
102	    "$lint" -aabceghprSTxz input.ln
103}
104
105
106atf_init_test_cases()
107{
108	atf_add_test_case 'run_lint1_error'
109	atf_add_test_case 'run_lint1_warning'
110	atf_add_test_case 'run_lint2'
111}
112