accept.sh revision 1.13 1 1.1 rillig #! /bin/sh
2 1.13 rillig # $NetBSD: accept.sh,v 1.13 2023/07/08 08:02:45 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.10 rillig # Run one or more lint tests, saving their output in the corresponding
32 1.10 rillig # .exp files, for incorporating the messages into the .c files as
33 1.10 rillig # 'expect' comments.
34 1.1 rillig
35 1.1 rillig set -eu
36 1.1 rillig
37 1.9 rillig : "${archsubdir:=$(make -v ARCHSUBDIR)}"
38 1.9 rillig . './t_integration.sh' # for configure_test_case
39 1.1 rillig
40 1.11 rillig done_tests=''
41 1.1 rillig for pattern in "$@"; do
42 1.5 rillig # shellcheck disable=SC2231
43 1.11 rillig for cfile in *$pattern*.c; do
44 1.11 rillig base=${cfile%.*}
45 1.13 rillig exp_tmp_file="$base.exp.tmp"
46 1.13 rillig exp_file="$base.exp"
47 1.12 rillig ln_tmp_file="$base.exp-ln.tmp"
48 1.4 rillig ln_file="$base.exp-ln"
49 1.1 rillig
50 1.1 rillig configure_test_case "$cfile"
51 1.2 rillig # shellcheck disable=SC2154
52 1.5 rillig if [ "$skip" = yes ]; then
53 1.1 rillig continue
54 1.1 rillig fi
55 1.1 rillig
56 1.1 rillig if [ ! -f "$ln_file" ]; then
57 1.1 rillig ln_file='/dev/null'
58 1.1 rillig fi
59 1.1 rillig
60 1.2 rillig # shellcheck disable=SC2154
61 1.2 rillig # shellcheck disable=SC2086
62 1.13 rillig if "$lint1" $flags "$base.c" "$ln_tmp_file" > "$exp_tmp_file"; then
63 1.13 rillig if [ -s "$exp_tmp_file" ]; then
64 1.1 rillig echo "$base produces output but exits successfully"
65 1.13 rillig sed 's,^,| ,' "$exp_tmp_file"
66 1.1 rillig fi
67 1.3 rillig elif [ $? -ge 128 ]; then
68 1.3 rillig echo "$base crashed"
69 1.3 rillig continue
70 1.1 rillig fi
71 1.1 rillig
72 1.13 rillig if [ -f "$exp_file" ] && cmp -s "$exp_tmp_file" "$exp_file"; then
73 1.13 rillig rm "$exp_tmp_file"
74 1.13 rillig else
75 1.13 rillig mv "$exp_tmp_file" "$exp_file"
76 1.13 rillig fi
77 1.13 rillig
78 1.12 rillig if [ ! -f "$ln_tmp_file" ]; then
79 1.12 rillig : 'No cleanup necessary.'
80 1.12 rillig elif [ "$ln_file" = '/dev/null' ]; then
81 1.12 rillig rm "$ln_tmp_file"
82 1.12 rillig else
83 1.12 rillig if tr -d ' \t' < "$ln_file" > "$ln_file.trimmed.tmp" &&
84 1.12 rillig tr -d ' \t' < "$ln_tmp_file" > "$ln_tmp_file.trimmed.tmp" &&
85 1.12 rillig cmp -s "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"; then
86 1.12 rillig rm "$ln_tmp_file"
87 1.12 rillig else
88 1.12 rillig echo "Replacing $ln_file"
89 1.12 rillig mv "$ln_tmp_file" "$ln_file"
90 1.12 rillig fi
91 1.12 rillig rm -f "$ln_file.trimmed.tmp" "$ln_tmp_file.trimmed.tmp"
92 1.12 rillig fi
93 1.12 rillig
94 1.1 rillig case "$base" in (msg_*)
95 1.8 rillig if grep 'This message is not used\.' "$cfile" >/dev/null; then
96 1.8 rillig : 'Skip further checks.'
97 1.13 rillig elif [ ! -s "$exp_file" ]; then
98 1.1 rillig echo "$base should produce warnings"
99 1.10 rillig elif grep '^TODO: "Add example code' "$cfile" >/dev/null; then
100 1.1 rillig : 'ok, this test is not yet written'
101 1.1 rillig else
102 1.1 rillig msgid=${base}
103 1.1 rillig msgid=${msgid#msg_00}
104 1.1 rillig msgid=${msgid#msg_0}
105 1.1 rillig msgid=${msgid#msg_}
106 1.6 rillig msgid=${msgid%%_*}
107 1.13 rillig if ! grep "\\[$msgid\\]\$" "$exp_file" >/dev/null; then
108 1.1 rillig echo "$base should trigger the message '$msgid'"
109 1.1 rillig fi
110 1.1 rillig fi
111 1.1 rillig esac
112 1.11 rillig
113 1.11 rillig done_tests="$done_tests $cfile"
114 1.1 rillig done
115 1.1 rillig done
116 1.1 rillig
117 1.11 rillig # shellcheck disable=SC2086
118 1.11 rillig lua './check-expect.lua' $done_tests
119