1#!/bin/sh
2
3# Copyright (C) 2012, Benjamin Drung <bdrung@debian.org>
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
17set -u
18
19if test "${1:-}" = --installed; then
20    COMMAND=checkbashisms
21    shift
22else
23    # shellcheck disable=SC2034
24    COMMAND="../scripts/checkbashisms.pl"
25fi
26
27WORKDIR="$(readlink -f "${0%/*}")"
28
29. "${0%/*}/shunit2-helper-functions.sh"
30
31clean() {
32    cd "$WORKDIR"
33    runCommand "$1" "" "" 0
34}
35
36found() {
37    cd "$WORKDIR"
38    runCommand "$1" "" "$2" 1
39}
40
41test_531327() {
42    clean "bashisms/531327.sh"
43}
44
45test_535368() {
46    clean "-f bashisms/535368.mk"
47}
48
49test_808271() {
50    found "bashisms/808271.sh" "$(cat bashisms/808271.sh.out)"
51}
52
53test_arith() {
54    found "bashisms/arith.sh" "$(cat bashisms/arith.sh.out)"
55}
56
57test_array_expansion() {
58    found "bashisms/array-expansion.sh" "$(cat bashisms/array-expansion.sh.out)"
59}
60
61test_ash_setvar() {
62    found "bashisms/ash-setvar.sh" "$(cat bashisms/ash-setvar.sh.out)"
63}
64
65test_basic() {
66    found "-f bashisms/basic.mk" "$(cat bashisms/basic.mk.out)"
67}
68
69test_basic_bash() {
70    clean "-f bashisms/basic-bash.mk"
71}
72
73test_brace_expansion() {
74    found "-f bashisms/brace-expansion.sh" "$(cat bashisms/brace-expansion.sh.out)"
75}
76
77test_basic_bash_override() {
78    clean "-f bashisms/basic-bash-override.mk"
79}
80
81test_case_modification() {
82    found "-f bashisms/case-modification.sh" "$(cat bashisms/case-modification.sh.out)"
83}
84
85test_comments_in_quoted_strings1() {
86    clean "bashisms/comments-in-quoted-strings1.sh"
87}
88
89test_comments_in_quoted_strings2() {
90    clean "bashisms/comments-in-quoted-strings2.sh"
91}
92
93test_command() {
94    found "bashisms/command.sh" "$(cat bashisms/command.sh.out)"
95}
96
97test_comments_parsing_fns() {
98    found "bashisms/comments-parsing-fns.sh" "$(cat bashisms/comments-parsing-fns.sh.out)"
99}
100
101test_coproc() {
102    found "bashisms/coproc.sh" "$(cat bashisms/coproc.sh.out)"
103}
104
105test_dynamic_length() {
106    found "bashisms/dynamic-length.sh" "$(cat bashisms/dynamic-length.sh.out)"
107}
108
109test_exit_code() {
110    found "bashisms/exit-code.sh" "$(cat bashisms/exit-code.sh.out)"
111}
112
113test_fail2ban() {
114    clean "bashisms/fail2ban.sh"
115}
116
117test_fps() {
118    found "bashisms/fps.sh" "$(cat bashisms/fps.sh.out)"
119}
120
121test_functions() {
122    found "bashisms/functions.sh" "$(cat bashisms/functions.sh.out)"
123}
124
125test_gettext() {
126    found "bashisms/gettext.sh" "$(cat bashisms/gettext.sh.out)"
127}
128
129test_glob_ignore() {
130    found "bashisms/glob-ignore.sh" "$(cat bashisms/glob-ignore.sh.out)"
131}
132
133test_hash() {
134    found "bashisms/hash.sh" "$(cat bashisms/hash.sh.out)"
135}
136
137test_heredocs() {
138    found "bashisms/heredocs.sh" "$(cat bashisms/heredocs.sh.out)"
139}
140
141test_heredoc_with_dash() {
142    clean "bashisms/heredoc-with-dash.sh"
143}
144
145test_heredoc_with_others() {
146    clean "bashisms/heredoc-with-others.sh"
147}
148
149test_jobs() {
150    found "bashisms/jobs.sh" "$(cat bashisms/jobs.sh.out)"
151}
152
153test_line_continuation() {
154    found "bashisms/line-continuation.sh" "$(cat bashisms/line-continuation.sh.out)"
155}
156
157test_negations() {
158    found "bashisms/negations.sh" "$(cat bashisms/negations.sh.out)"
159}
160
161test_other_vars() {
162    found "bashisms/other-vars.sh" "$(cat bashisms/other-vars.sh.out)"
163}
164
165test_printf() {
166    found "bashisms/printf.sh" "$(cat bashisms/printf.sh.out)"
167}
168
169test_quoted_strings() {
170    found "bashisms/quoted-strings.sh" "$(cat bashisms/quoted-strings.sh.out)"
171}
172
173test_return() {
174    found "bashisms/return.sh" "$(cat bashisms/return.sh.out)"
175}
176
177test_shell_vars() {
178    clean "-f bashisms/shell-vars.mk"
179}
180
181test_source() {
182    found "bashisms/source" "$(cat bashisms/source.out)"
183}
184
185test_special_case() {
186    found "bashisms/special-case.sh" "$(cat bashisms/special-case.sh.out)"
187}
188
189test_special_expansions() {
190    found "bashisms/special-expansions.sh" "$(cat bashisms/special-expansions.sh.out)"
191}
192
193test_subshell_no_arith() {
194    clean "bashisms/subshell-no-arith.sh"
195}
196
197test_tilde_expansion() {
198    found "bashisms/tilde-expansion.sh" "$(cat bashisms/tilde-expansion.sh.out)"
199}
200
201test_traps() {
202    found "bashisms/traps.sh" "$(cat bashisms/traps.sh.out)"
203}
204
205test_underscore_var() {
206    found "bashisms/underscore-var.sh" "$(cat bashisms/underscore-var.sh.out)"
207}
208
209test_unknown_fns() {
210    found "bashisms/unknown-fns.sh" "$(cat bashisms/unknown-fns.sh.out)"
211}
212
213test_unterminated_string() {
214    clean "bashisms/unterminated-string.sh"
215}
216
217test_unterminated_string2() {
218    clean "bashisms/unterminated-string2.sh"
219}
220
221. shunit2
222