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