t_error.sh revision 1.1 1 # $NetBSD: t_error.sh,v 1.1 2023/08/26 10:06:16 rillig Exp $
2 #
3 # Copyright (c) 2023 The NetBSD Foundation, Inc.
4 # All rights reserved.
5 #
6 # This code is derived from software contributed to The NetBSD Foundation
7 # by Roland Illig.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 # POSSIBILITY OF SUCH DAMAGE.
29 #
30
31 create_file() {
32 local fn="$1"; shift
33 printf '%s\n' "$@" > "$fn"
34 }
35
36 atf_test_case cc
37 cc_body() {
38 create_file code.c \
39 'goto error'
40 create_file err \
41 'code.c:1: error: syntax error'
42 create_file expected \
43 '/*###1 [cc] error: syntax error%%%*/' \
44 'goto error'
45
46 atf_check -o ignore \
47 error err
48 atf_check -o 'file:expected' cat code.c
49 }
50
51 atf_test_case f77
52 f77_body() {
53 create_file code.f \
54 'doi=1,1,1'
55 create_file err \
56 'Compiler error line 1 of code.f: syntax error'
57 create_file expected \
58 'C###1 [f77] Compiler error line 1 of code.f syntax error%%%' \
59 'doi=1,1,1'
60
61 atf_check -o ignore \
62 error err
63 atf_check -o 'file:expected' cat code.f
64 }
65
66 atf_test_case lint
67 lint_body() {
68 create_file code.c \
69 'goto error'
70 create_file err \
71 'code.c(1): syntax error'
72 create_file expected \
73 '/*###1 [lint] syntax error%%%*/' \
74 'goto error'
75
76 atf_check -o ignore \
77 error err
78 atf_check -o 'file:expected' cat code.c
79 }
80
81 atf_test_case mod2
82 mod2_body() {
83 create_file code.m2 \
84 'END.'
85 create_file err \
86 'File code.m2, line 1: missing BEGIN'
87 create_file expected \
88 '(*###1 [mod2] missing BEGIN%%%*)' \
89 'END.'
90
91 atf_check -o ignore \
92 error err
93 atf_check -o 'file:expected' cat code.m2
94 }
95
96 atf_init_test_cases() {
97 atf_add_test_case cc
98 atf_add_test_case f77
99 atf_add_test_case lint
100 atf_add_test_case mod2
101 }
102