Home | History | Annotate | Line # | Download | only in lint1
accept.sh revision 1.12
      1 #! /bin/sh
      2 # $NetBSD: accept.sh,v 1.12 2023/06/28 20:51:31 rillig Exp $
      3 #
      4 # Copyright (c) 2021 The NetBSD Foundation, Inc.
      5 # All rights reserved.
      6 #
      7 # Redistribution and use in source and binary forms, with or without
      8 # modification, are permitted provided that the following conditions
      9 # are met:
     10 # 1. Redistributions of source code must retain the above copyright
     11 #    notice, this list of conditions and the following disclaimer.
     12 # 2. Redistributions in binary form must reproduce the above copyright
     13 #    notice, this list of conditions and the following disclaimer in the
     14 #    documentation and/or other materials provided with the distribution.
     15 #
     16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19 # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26 # POSSIBILITY OF SUCH DAMAGE.
     27 #
     28 
     29 # usage: accept.sh <pattern>...
     30 #
     31 #	Run one or more lint tests, saving their output in the corresponding
     32 #	.exp files, for incorporating the messages into the .c files as
     33 #	'expect' comments.
     34 
     35 set -eu
     36 
     37 : "${archsubdir:=$(make -v ARCHSUBDIR)}"
     38 . './t_integration.sh'		# for configure_test_case
     39 
     40 done_tests=''
     41 for pattern in "$@"; do
     42 	# shellcheck disable=SC2231
     43 	for cfile in *$pattern*.c; do
     44 		base=${cfile%.*}
     45 		expfile="$base.exp"
     46 		ln_tmp_file="$base.exp-ln.tmp"
     47 		ln_file="$base.exp-ln"
     48 
     49 		configure_test_case "$cfile"
     50 		# shellcheck disable=SC2154
     51 		if [ "$skip" = yes ]; then
     52 			continue
     53 		fi
     54 
     55 		if [ ! -f "$ln_file" ]; then
     56 			ln_file='/dev/null'
     57 		fi
     58 
     59 		# shellcheck disable=SC2154
     60 		# shellcheck disable=SC2086
     61 		if "$lint1" $flags "$base.c" "$ln_tmp_file" > "$expfile"; then
     62 			if [ -s "$expfile" ]; then
     63 				echo "$base produces output but exits successfully"
     64 				sed 's,^,| ,' "$expfile"
     65 			fi
     66 		elif [ $? -ge 128 ]; then
     67 			echo "$base crashed"
     68 			continue
     69 		fi
     70 
     71 		if [ ! -f "$ln_tmp_file" ]; then
     72 			: 'No cleanup necessary.'
     73 		elif [ "$ln_file" = '/dev/null' ]; then
     74 			rm "$ln_tmp_file"
     75 		else
     76 			if tr -d ' \t' < "$ln_file" > "$ln_file.trimmed.tmp" &&
     77 			    tr -d ' \t' < "$ln_tmp_file" > "$ln_tmp_file.trimmed.tmp" &&
     78 			    cmp -s "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"; then
     79 				rm "$ln_tmp_file"
     80 			else
     81 				echo "Replacing $ln_file"
     82 				mv "$ln_tmp_file" "$ln_file"
     83 			fi
     84 			rm -f "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"
     85 		fi
     86 
     87 		case "$base" in (msg_*)
     88 			if grep 'This message is not used\.' "$cfile" >/dev/null; then
     89 				: 'Skip further checks.'
     90 			elif [ ! -s "$expfile" ]; then
     91 				echo "$base should produce warnings"
     92 			elif grep '^TODO: "Add example code' "$cfile" >/dev/null; then
     93 				: 'ok, this test is not yet written'
     94 			else
     95 				msgid=${base}
     96 				msgid=${msgid#msg_00}
     97 				msgid=${msgid#msg_0}
     98 				msgid=${msgid#msg_}
     99 				msgid=${msgid%%_*}
    100 				if ! grep "\\[$msgid\\]\$" "$expfile" >/dev/null; then
    101 					echo "$base should trigger the message '$msgid'"
    102 				fi
    103 			fi
    104 		esac
    105 
    106 		done_tests="$done_tests $cfile"
    107 	done
    108 done
    109 
    110 # shellcheck disable=SC2086
    111 lua './check-expect.lua' $done_tests
    112