t_xlint.sh revision 1.2
11.2Srillig# $NetBSD: t_xlint.sh,v 1.2 2023/06/28 09:35:43 rillig Exp $
21.1Srillig#
31.1Srillig# Copyright (c) 2023 The NetBSD Foundation, Inc.
41.1Srillig# All rights reserved.
51.1Srillig#
61.1Srillig# Redistribution and use in source and binary forms, with or without
71.1Srillig# modification, are permitted provided that the following conditions
81.1Srillig# are met:
91.1Srillig# 1. Redistributions of source code must retain the above copyright
101.1Srillig#    notice, this list of conditions and the following disclaimer.
111.1Srillig# 2. Redistributions in binary form must reproduce the above copyright
121.1Srillig#    notice, this list of conditions and the following disclaimer in the
131.1Srillig#    documentation and/or other materials provided with the distribution.
141.1Srillig#
151.1Srillig# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
161.1Srillig# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
171.1Srillig# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
181.1Srillig# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
191.1Srillig# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
201.1Srillig# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
211.1Srillig# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
221.1Srillig# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
231.1Srillig# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
241.1Srillig# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
251.1Srillig# POSSIBILITY OF SUCH DAMAGE.
261.1Srillig#
271.1Srillig
281.2Srillig: "${lint:=/usr/bin/lint}"
291.1Srillig
301.2Srilligatf_test_case 'run_lint1_error'
311.1Srilligrun_lint1_error_body()
321.1Srillig{
331.1Srillig	cat <<-EOF >input.c || atf_fail 'prepare input.c'
341.1Srillig		#include <stdbool.h>
351.1Srillig
361.1Srillig		bool
371.1Srillig		return_true(void)
381.1Srillig		{
391.1Srillig			return 1;
401.1Srillig		}
411.1Srillig	EOF
421.2Srillig	echo 'previous content' > input.ln
431.1Srillig
441.1Srillig	atf_check \
451.1Srillig	    -s 'exit:1' \
461.1Srillig	    -o "inline:input.c(6): error: function has return type '_Bool' but returns 'int' [211]\n" \
471.1Srillig	    "$lint" -aabceghiprSTxz input.c
481.1Srillig
491.2Srillig	# In case of an error, any previous output file is overwritten, and the
501.2Srillig	# (possibly unfinished) output file is removed.
511.1Srillig	atf_check \
521.1Srillig	    -s 'exit:1' \
531.1Srillig	    test -f input.ln
541.1Srillig}
551.1Srillig
561.1Srillig
571.2Srilligatf_test_case 'run_lint1_warning'
581.1Srilligrun_lint1_warning_body()
591.1Srillig{
601.1Srillig	cat <<-EOF >input.c || atf_fail 'prepare input.c'
611.1Srillig		static int number;
621.1Srillig
631.1Srillig		const void *
641.1Srillig		function(int a, const char *s)
651.1Srillig		{
661.1Srillig			return s + a;
671.1Srillig		}
681.1Srillig	EOF
691.1Srillig	cat <<-EOF >input.exp || atf_fail 'prepare input.exp'
701.1Srillig		0sinput.c
711.1Srillig		Sinput.c
721.1Srillig		1s<built-in>
731.1Srillig		2s<command-line>
741.1Srillig		4d0.4dr8functionF2IPcCPcV
751.1Srillig	EOF
761.1Srillig
771.1Srillig	atf_check \
781.1Srillig	    -o "inline:input.c(1): warning: static variable 'number' unused [226]\n" \
791.1Srillig	    "$lint" -aabceghiprSTxz input.c
801.1Srillig	atf_check \
811.1Srillig	    -o 'file:input.exp' \
821.1Srillig	    cat input.ln
831.1Srillig}
841.1Srillig
851.1Srillig
861.2Srilligatf_test_case 'run_lint2'
871.1Srilligrun_lint2_body()
881.1Srillig{
891.1Srillig	cat <<-EOF >input.ln || atf_fail 'prepare input.ln'
901.1Srillig		0sinput.c
911.1Srillig		Sinput.c
921.1Srillig		1s<built-in>
931.1Srillig		2s<command-line>
941.1Srillig		4d0.4dr8functionF2IPcCPcV
951.1Srillig	EOF
961.1Srillig
971.1Srillig	# Most of the command line options are not relevant for lint2,
981.1Srillig	# so they are effectively ignored.  The option '-i' is absent.
991.1Srillig	atf_check \
1001.1Srillig	    -o 'inline:function defined( input.c(4) ), but never used\n' \
1011.1Srillig	    -e 'inline:lint: cannot find llib-lc.ln\n' \
1021.1Srillig	    "$lint" -aabceghprSTxz input.ln
1031.1Srillig}
1041.1Srillig
1051.1Srillig
1061.1Srilligatf_init_test_cases()
1071.1Srillig{
1081.1Srillig	atf_add_test_case 'run_lint1_error'
1091.1Srillig	atf_add_test_case 'run_lint1_warning'
1101.1Srillig	atf_add_test_case 'run_lint2'
1111.1Srillig}
112