accept.sh revision 1.10
1#! /bin/sh
2# $NetBSD: accept.sh,v 1.10 2022/06/17 20:23:58 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
35set -eu
36
37: "${archsubdir:=$(make -v ARCHSUBDIR)}"
38. './t_integration.sh'		# for configure_test_case
39
40for pattern in "$@"; do
41	# shellcheck disable=SC2231
42	for test in *$pattern*.c; do
43		base=${test%.*}
44		cfile="$base.c"
45		expfile="$base.exp"
46		ln_file="$base.exp-ln"
47
48		configure_test_case "$cfile"
49		# shellcheck disable=SC2154
50		if [ "$skip" = yes ]; then
51			continue
52		fi
53
54		if [ ! -f "$ln_file" ]; then
55			ln_file='/dev/null'
56		fi
57
58		# shellcheck disable=SC2154
59		# shellcheck disable=SC2086
60		if "$lint1" $flags "$base.c" "$ln_file" > "$expfile"; then
61			if [ -s "$expfile" ]; then
62				echo "$base produces output but exits successfully"
63				sed 's,^,| ,' "$expfile"
64			fi
65		elif [ $? -ge 128 ]; then
66			echo "$base crashed"
67			continue
68		fi
69
70		case "$base" in (msg_*)
71			if grep 'This message is not used\.' "$cfile" >/dev/null; then
72				: 'Skip further checks.'
73			elif [ ! -s "$expfile" ]; then
74				echo "$base should produce warnings"
75			elif grep '^TODO: "Add example code' "$cfile" >/dev/null; then
76				: 'ok, this test is not yet written'
77			else
78				msgid=${base}
79				msgid=${msgid#msg_00}
80				msgid=${msgid#msg_0}
81				msgid=${msgid#msg_}
82				msgid=${msgid%%_*}
83				if ! grep "\\[$msgid\\]\$" "$expfile" >/dev/null; then
84					echo "$base should trigger the message '$msgid'"
85				fi
86			fi
87		esac
88	done
89done
90
91# shellcheck disable=SC2035
92lua '../check-expect.lua' *.c
93