t_xlint.sh revision 1.4
11.4Srillig# $NetBSD: t_xlint.sh,v 1.4 2023/09/07 06:24:31 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.3Srillig cat <<-EOF > expected.out 451.3Srillig input.c(5): warning: missing header declaration for 'return_true' [351] 461.3Srillig input.c(6): error: function has return type '_Bool' but returns 'int' [211] 471.3Srillig EOF 481.3Srillig 491.1Srillig atf_check \ 501.1Srillig -s 'exit:1' \ 511.3Srillig -o 'file:expected.out' \ 521.1Srillig "$lint" -aabceghiprSTxz input.c 531.1Srillig 541.2Srillig # In case of an error, any previous output file is overwritten, and the 551.2Srillig # (possibly unfinished) output file is removed. 561.1Srillig atf_check \ 571.1Srillig -s 'exit:1' \ 581.1Srillig test -f input.ln 591.1Srillig} 601.1Srillig 611.1Srillig 621.2Srilligatf_test_case 'run_lint1_warning' 631.1Srilligrun_lint1_warning_body() 641.1Srillig{ 651.1Srillig cat <<-EOF >input.c || atf_fail 'prepare input.c' 661.1Srillig static int number; 671.1Srillig 681.1Srillig const void * 691.1Srillig function(int a, const char *s) 701.1Srillig { 711.1Srillig return s + a; 721.1Srillig } 731.1Srillig EOF 741.1Srillig cat <<-EOF >input.exp || atf_fail 'prepare input.exp' 751.1Srillig 0sinput.c 761.1Srillig Sinput.c 771.1Srillig 1s<built-in> 781.1Srillig 2s<command-line> 791.1Srillig 4d0.4dr8functionF2IPcCPcV 801.1Srillig EOF 811.3Srillig cat <<-EOF >expected.out 821.3Srillig input.c(5): warning: missing header declaration for 'function' [351] 831.3Srillig input.c(1): warning: static variable 'number' unused [226] 841.3Srillig EOF 851.1Srillig 861.1Srillig atf_check \ 871.3Srillig -o 'file:expected.out' \ 881.1Srillig "$lint" -aabceghiprSTxz input.c 891.1Srillig atf_check \ 901.1Srillig -o 'file:input.exp' \ 911.1Srillig cat input.ln 921.1Srillig} 931.1Srillig 941.1Srillig 951.2Srilligatf_test_case 'run_lint2' 961.1Srilligrun_lint2_body() 971.1Srillig{ 981.1Srillig cat <<-EOF >input.ln || atf_fail 'prepare input.ln' 991.1Srillig 0sinput.c 1001.1Srillig Sinput.c 1011.1Srillig 1s<built-in> 1021.1Srillig 2s<command-line> 1031.1Srillig 4d0.4dr8functionF2IPcCPcV 1041.1Srillig EOF 1051.1Srillig 1061.1Srillig # Most of the command line options are not relevant for lint2, 1071.1Srillig # so they are effectively ignored. The option '-i' is absent. 1081.4Srillig # 1091.4Srillig # Depending on whether the lint libraries are installed or not, there 1101.4Srillig # may be a warning 'cannot find llib-lc.ln' on stderr. 1111.1Srillig atf_check \ 1121.1Srillig -o 'inline:function defined( input.c(4) ), but never used\n' \ 1131.4Srillig -e 'ignore' \ 1141.1Srillig "$lint" -aabceghprSTxz input.ln 1151.1Srillig} 1161.1Srillig 1171.1Srillig 1181.1Srilligatf_init_test_cases() 1191.1Srillig{ 1201.1Srillig atf_add_test_case 'run_lint1_error' 1211.1Srillig atf_add_test_case 'run_lint1_warning' 1221.1Srillig atf_add_test_case 'run_lint2' 1231.1Srillig} 124