accept.sh revision 1.5
1#! /bin/sh
2# $NetBSD: accept.sh,v 1.5 2021/08/08 13:19:51 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#	Accept the actual output from running the lint tests and save them
32#	back into the .exp files.
33
34set -eu
35
36. './t_integration.sh'
37
38for pattern in "$@"; do
39	# shellcheck disable=SC2231
40	for test in *$pattern*.c; do
41		base=${test%.*}
42		cfile="$base.c"
43		expfile="$base.exp"
44		tmpfile="$base.exp.tmp"
45		ln_file="$base.exp-ln"
46
47		configure_test_case "$cfile"
48		# shellcheck disable=SC2154
49		if [ "$skip" = yes ]; then
50			continue
51		fi
52
53		if [ ! -f "$ln_file" ]; then
54			ln_file='/dev/null'
55		fi
56
57		# shellcheck disable=SC2154
58		# shellcheck disable=SC2086
59		if "$lint1" $flags "$base.c" "$ln_file" > "$tmpfile"; then
60			if [ -s "$tmpfile" ]; then
61				echo "$base produces output but exits successfully"
62				sed 's,^,| ,' "$tmpfile"
63			fi
64			rm -f "$expfile" "$tmpfile"
65		elif [ $? -ge 128 ]; then
66			echo "$base crashed"
67			continue
68		else
69			if [ -f "$tmpfile" ] && cmp -s "$tmpfile" "$expfile"; then
70				rm "$tmpfile"
71			else
72				echo "replacing $base"
73				mv "$tmpfile" "$expfile"
74			fi
75		fi
76
77		case "$base" in (msg_*)
78			if [ ! -f "$expfile" ]; then
79				echo "$base should produce warnings"
80			elif grep '^TODO: "Add example code' "$base.c" >/dev/null; then
81				: 'ok, this test is not yet written'
82			else
83				msgid=${base}
84				msgid=${msgid#msg_00}
85				msgid=${msgid#msg_0}
86				msgid=${msgid#msg_}
87				msgid=${msgid%_*}
88				if ! grep "\\[$msgid\\]" "$expfile" >/dev/null; then
89					echo "$base should trigger the message '$msgid'"
90				fi
91			fi
92		esac
93
94	done
95done
96
97# shellcheck disable=SC2035
98lua '../check-expect.lua' *.c
99