Mon May 11 19:13:10 2020 UTC ()
regress/infra-unittests: run tests in a temporary directory

This isolates the tests from the test infrastructure and allows the test
infrastructure to create arbitrary files for its own purpose without
affecting any of the tests.


(rillig)
diff -r1.4 -r1.5 pkgsrc/regress/infra-unittests/check-portability.sh
diff -r1.4 -r1.5 pkgsrc/regress/infra-unittests/extract.sh
diff -r1.33 -r1.34 pkgsrc/regress/infra-unittests/subst.sh
diff -r1.13 -r1.14 pkgsrc/regress/infra-unittests/test.subr

cvs diff -r1.4 -r1.5 pkgsrc/regress/infra-unittests/check-portability.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/check-portability.sh 2020/05/05 06:11:29 1.4
+++ pkgsrc/regress/infra-unittests/check-portability.sh 2020/05/11 19:13:10 1.5
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: check-portability.sh,v 1.4 2020/05/05 06:11:29 rillig Exp $ 2# $NetBSD: check-portability.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
3# 3#
4# Test cases for mk/check/check-portability.*. 4# Test cases for mk/check/check-portability.*.
5# 5#
6 6
7set -eu 7set -eu
8 8
9. "./test.subr" 9. "./test.subr"
10 10
11# Runs the shell program for the given file. 11# Runs the shell program for the given file.
12check_portability_sh() { 12check_portability_sh() {
13 env PATCHDIR='patches' \ 13 env PATCHDIR='patches' \
14 PREFIX='/nonexistent' \ 14 PREFIX='/nonexistent' \
15 "$@" \ 15 "$@" \
@@ -19,59 +19,48 @@ check_portability_sh() { @@ -19,59 +19,48 @@ check_portability_sh() {
19} 19}
20 20
21# Runs the AWK program in standalone mode for the given file. 21# Runs the AWK program in standalone mode for the given file.
22check_portability_awk() { 22check_portability_awk() {
23 env CK_FNAME="$1" \ 23 env CK_FNAME="$1" \
24 CK_PROGNAME='check-portability.awk' \ 24 CK_PROGNAME='check-portability.awk' \
25 awk -f "$pkgsrcdir/mk/check/check-subr.awk" \ 25 awk -f "$pkgsrcdir/mk/check/check-subr.awk" \
26 -f "$pkgsrcdir/mk/check/check-portability.awk" \ 26 -f "$pkgsrcdir/mk/check/check-portability.awk" \
27 "$1" \ 27 "$1" \
28 1>"$tmpdir/out" 2>&1 \ 28 1>"$tmpdir/out" 2>&1 \
29 && exitcode=0 || exitcode=$? 29 && exitcode=0 || exitcode=$?
30} 30}
31 31
32test_case_set_up() { 
33 rm -rf "$tmpdir/work" 
34 mkdir "$tmpdir/work" 
35 cd "$tmpdir/work" 
36} 
37 
38# TODO: remove the "work/" from the tests. 
39# The $tmpdir must be a bit structured: 
40# $tmpdir/pkgsrc these files override the actual pkgsrc files 
41# $tmpdir/work current working directory 
42 
43 32
44if test_case_begin "test ... = ..."; then 33if test_case_begin "test ... = ..."; then
45 34
46 create_file_lines 'work/file' \ 35 create_file_lines 'file' \
47 'if [ "$var" = value ]; then' \ 36 'if [ "$var" = value ]; then' \
48 ' ...' \ 37 ' ...' \
49 'elif test "$var" = value ]; then' \ 38 'elif test "$var" = value ]; then' \
50 ' ...' \ 39 ' ...' \
51 'fi' 40 'fi'
52 41
53 check_portability_awk 'file' 42 check_portability_awk 'file'
54 43
55 assert_that 'out' --file-is-empty 44 assert_that "$tmpdir/out" --file-is-empty
56 assert_that $exitcode --equals 0 45 assert_that $exitcode --equals 0
57 46
58 test_case_end 47 test_case_end
59fi 48fi
60 49
61 50
62if test_case_begin 'test ... == ...'; then 51if test_case_begin 'test ... == ...'; then
63 52
64 create_file_lines 'work/file' \ 53 create_file_lines 'file' \
65 'if [ "$var" == value ]; then' \ 54 'if [ "$var" == value ]; then' \
66 ' ...' \ 55 ' ...' \
67 'elif test "$var" == value ]; then' \ 56 'elif test "$var" == value ]; then' \
68 ' ...' \ 57 ' ...' \
69 'fi' 58 'fi'
70 59
71 check_portability_awk 'file' 60 check_portability_awk 'file'
72 61
73 create_file 'expected' <<'EOF' 62 create_file 'expected' <<'EOF'
74ERROR: [check-portability.awk] => Found test ... == ...: 63ERROR: [check-portability.awk] => Found test ... == ...:
75ERROR: [check-portability.awk] file:1: if [ "$var" == value ]; then 64ERROR: [check-portability.awk] file:1: if [ "$var" == value ]; then
76ERROR: [check-portability.awk] file:3: elif test "$var" == value ]; then 65ERROR: [check-portability.awk] file:3: elif test "$var" == value ]; then
77 66
@@ -83,101 +72,101 @@ versions of ksh support it. @@ -83,101 +72,101 @@ versions of ksh support it.
83 72
84When you run "test foo == foo" on a platform that does not support the 73When you run "test foo == foo" on a platform that does not support the
85"==" operator, the result will be "false" instead of "true". This can 74"==" operator, the result will be "false" instead of "true". This can
86lead to unexpected behavior. 75lead to unexpected behavior.
87 76
88There are two ways to fix this error message. If the file that contains 77There are two ways to fix this error message. If the file that contains
89the "test ==" is needed for building the package, you should create a 78the "test ==" is needed for building the package, you should create a
90patch for it, replacing the "==" operator with "=". If the file is not 79patch for it, replacing the "==" operator with "=". If the file is not
91needed, add its name to the CHECK_PORTABILITY_SKIP variable in the 80needed, add its name to the CHECK_PORTABILITY_SKIP variable in the
92package Makefile. 81package Makefile.
93=========================================================================== 82===========================================================================
94 83
95EOF 84EOF
96 assert_that 'out' --file-equals 'expected' 85 assert_that "$tmpdir/out" --file-equals 'expected'
97 assert_that $exitcode --equals 1 86 assert_that $exitcode --equals 1
98 87
99 test_case_end 88 test_case_end
100fi 89fi
101 90
102 91
103if test_case_begin 'configure patched, configure.in bad'; then 92if test_case_begin 'configure patched, configure.in bad'; then
104 93
105 create_file_lines 'work/patches/patch-aa' \ 94 create_file_lines 'patches/patch-aa' \
106 '+++ configure 2020-05-04' 95 '+++ configure 2020-05-04'
107 create_file_lines 'work/configure' \ 96 create_file_lines 'configure' \
108 '#! /bin/sh' \ 97 '#! /bin/sh' \
109 'good' 98 'good'
110 create_file_lines 'work/configure.in' \ 99 create_file_lines 'configure.in' \
111 'test a == b' 100 'test a == b'
112 101
113 check_portability_sh \ 102 check_portability_sh \
114 'CHECK_PORTABILITY_EXPERIMENTAL=yes' 103 'CHECK_PORTABILITY_EXPERIMENTAL=yes'
115 104
116 assert_that "out" --file-is-empty 105 assert_that "$tmpdir/out" --file-is-empty
117 assert_that $exitcode --equals 0 106 assert_that $exitcode --equals 0
118 107
119 test_case_end 108 test_case_end
120fi 109fi
121 110
122 111
123if test_case_begin 'Makefile.in patched, Makefile.am bad'; then 112if test_case_begin 'Makefile.in patched, Makefile.am bad'; then
124 113
125 # As of 2020-05-05, Makefile.am is not checked at all since only 114 # As of 2020-05-05, Makefile.am is not checked at all since only
126 # very few packages actually use that file during the build. 115 # very few packages actually use that file during the build.
127 116
128 create_file_lines 'work/patches/patch-aa' \ 117 create_file_lines 'patches/patch-aa' \
129 '+++ Makefile.in 2020-05-05' 118 '+++ Makefile.in 2020-05-05'
130 create_file_lines 'work/Makefile.in' \ 119 create_file_lines 'Makefile.in' \
131 'test a = b' 120 'test a = b'
132 create_file_lines 'work/Makefile.am' \ 121 create_file_lines 'Makefile.am' \
133 'test a == b' 122 'test a == b'
134 123
135 check_portability_sh \ 124 check_portability_sh \
136 'CHECK_PORTABILITY_EXPERIMENTAL=yes' 125 'CHECK_PORTABILITY_EXPERIMENTAL=yes'
137 126
138 assert_that "out" --file-is-empty 127 assert_that "$tmpdir/out" --file-is-empty
139 assert_that $exitcode --equals 0 128 assert_that $exitcode --equals 0
140 129
141 test_case_end 130 test_case_end
142fi 131fi
143 132
144 133
145if test_case_begin 'files that are usually not used for building'; then 134if test_case_begin 'files that are usually not used for building'; then
146 135
147 # The following files are mostly interesting to the upstream 136 # The following files are mostly interesting to the upstream
148 # developers and are not used during the actual build, except 137 # developers and are not used during the actual build, except
149 # if the package rebuilds everything using the GNU autotools. 138 # if the package rebuilds everything using the GNU autotools.
150 139
151 create_file_lines 'work/configure.ac' \ 140 create_file_lines 'configure.ac' \
152 'test a == b' 141 'test a == b'
153 create_file_lines 'work/Makefile.am' \ 142 create_file_lines 'Makefile.am' \
154 'test a == b' 143 'test a == b'
155 144
156 check_portability_sh \ 145 check_portability_sh \
157 'CHECK_PORTABILITY_EXPERIMENTAL=yes' 146 'CHECK_PORTABILITY_EXPERIMENTAL=yes'
158 147
159 assert_that "out" --file-is-empty 148 assert_that "$tmpdir/out" --file-is-empty
160 assert_that $exitcode --equals 0 149 assert_that $exitcode --equals 0
161 150
162 test_case_end 151 test_case_end
163fi 152fi
164 153
165 154
166if test_case_begin 'configure patched and still bad'; then 155if test_case_begin 'configure patched and still bad'; then
167 156
168 create_file_lines 'work/patches/patch-aa' \ 157 create_file_lines 'patches/patch-aa' \
169 '+++ configure 2020-05-04' 158 '+++ configure 2020-05-04'
170 create_file_lines 'work/configure' \ 159 create_file_lines 'configure' \
171 '#! /bin/sh' \ 160 '#! /bin/sh' \
172 'test a == b' 161 'test a == b'
173 162
174 check_portability_sh \ 163 check_portability_sh \
175 'CHECK_PORTABILITY_EXPERIMENTAL=yes' 164 'CHECK_PORTABILITY_EXPERIMENTAL=yes'
176 165
177 create_file 'expected' <<'EOF' 166 create_file 'expected' <<'EOF'
178ERROR: [check-portability.awk] => Found test ... == ...: 167ERROR: [check-portability.awk] => Found test ... == ...:
179ERROR: [check-portability.awk] configure:2: test a == b 168ERROR: [check-portability.awk] configure:2: test a == b
180 169
181Explanation: 170Explanation:
182=========================================================================== 171===========================================================================
183The "test" command, as well as the "[" command, are not required to know 172The "test" command, as well as the "[" command, are not required to know
@@ -186,72 +175,73 @@ versions of ksh support it. @@ -186,72 +175,73 @@ versions of ksh support it.
186 175
187When you run "test foo == foo" on a platform that does not support the 176When you run "test foo == foo" on a platform that does not support the
188"==" operator, the result will be "false" instead of "true". This can 177"==" operator, the result will be "false" instead of "true". This can
189lead to unexpected behavior. 178lead to unexpected behavior.
190 179
191There are two ways to fix this error message. If the file that contains 180There are two ways to fix this error message. If the file that contains
192the "test ==" is needed for building the package, you should create a 181the "test ==" is needed for building the package, you should create a
193patch for it, replacing the "==" operator with "=". If the file is not 182patch for it, replacing the "==" operator with "=". If the file is not
194needed, add its name to the CHECK_PORTABILITY_SKIP variable in the 183needed, add its name to the CHECK_PORTABILITY_SKIP variable in the
195package Makefile. 184package Makefile.
196=========================================================================== 185===========================================================================
197 186
198EOF 187EOF
199 assert_that 'out' --file-equals 'expected' 188 assert_that "$tmpdir/out" --file-equals 'expected'
200 assert_that $exitcode --equals 1 189 assert_that $exitcode --equals 1
201 190
202 test_case_end 191 test_case_end
203fi 192fi
204 193
205 194
206if test_case_begin 'special characters in filenames'; then 195if test_case_begin 'special characters in filenames'; then
207 196
208 # Ensure that the filename matching for patched files 197 # Ensure that the filename matching for patched files
209 # does not treat special characters as shell metacharacters. 198 # does not treat special characters as shell metacharacters.
210 199
211 create_file_lines 'work/patches/patch-aa' \ 200 create_file_lines 'patches/patch-aa' \
212 '+++ [[[[(`" 2020-05-04' 201 '+++ [[[[(`" 2020-05-04'
213 create_file_lines 'work/+++ [[[[(`"' \ 202 create_file_lines '+++ [[[[(`"' \
214 '#! /bin/sh' \ 203 '#! /bin/sh' \
215 'test a = b' 204 'test a = b'
216 205
217 check_portability_sh \ 206 check_portability_sh \
218 'CHECK_PORTABILITY_EXPERIMENTAL=yes' 207 'CHECK_PORTABILITY_EXPERIMENTAL=yes'
219 208
220 assert_that 'out' --file-is-empty 209 assert_that "$tmpdir/out" --file-is-empty
221 assert_that $exitcode --equals 0 210 assert_that $exitcode --equals 0
222 211
223 test_case_end 212 test_case_end
224fi 213fi
225 214
226 215
227if test_case_begin 'no patches'; then 216if test_case_begin 'no patches'; then
228 217
229 # Ensure that no error message is printed when there are no 218 # Ensure that no error message is printed when there are no
230 # patch files. 219 # patch files.
231 220
232 create_file_lines 'file' \ 221 create_file_lines 'file' \
233 '#! /bin/sh' \ 222 '#! /bin/sh' \
234 'test a = b' 223 'test a = b'
235 224
236 check_portability_sh 225 check_portability_sh \
 226 CHECK_PORTABILITY_EXPERIMENTAL=no
237 227
238 assert_that 'out' --file-is-empty 228 assert_that "$tmpdir/out" --file-is-empty
239 assert_that $exitcode --equals 0 229 assert_that $exitcode --equals 0
240 230
241 test_case_end 231 test_case_end
242fi 232fi
243 233
244 234
245if test_case_begin 'no experimental by default'; then 235if test_case_begin 'no experimental by default'; then
246 236
247 create_file_lines 'configure.in' \ 237 create_file_lines 'configure.in' \
248 'test a == b' 238 'test a == b'
249 239
250 check_portability_sh \ 240 check_portability_sh \
251 'CHECK_PORTABILITY_EXPERIMENTAL=no' 241 'CHECK_PORTABILITY_EXPERIMENTAL=no'
252 242
253 assert_that 'out' --file-is-empty 243 assert_that "$tmpdir/out" --file-is-empty
254 assert_that $exitcode --equals 0 244 assert_that $exitcode --equals 0
255 245
256 test_case_end 246 test_case_end
257fi 247fi

cvs diff -r1.4 -r1.5 pkgsrc/regress/infra-unittests/extract.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/extract.sh 2020/04/26 12:46:33 1.4
+++ pkgsrc/regress/infra-unittests/extract.sh 2020/05/11 19:13:10 1.5
@@ -1,109 +1,104 @@ @@ -1,109 +1,104 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: extract.sh,v 1.4 2020/04/26 12:46:33 rillig Exp $ 2# $NetBSD: extract.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $
3# 3#
4# Test cases for mk/extract/extract. 4# Test cases for mk/extract/extract.
5# 5#
6 6
7set -eu 7set -eu
8 8
9. "./test.subr" 9. "./test.subr"
10 10
11test_case_set_up() { 11test_case_set_up() {
12 # XXX: The mocked pkgsrc directory should be somewhere else. 
13 rm -rf "$tmpdir/pkgsrc" "$tmpdir/expected" 
14 
15 cd "$tmpdir" 
16 
17 LC_ALL=C 12 LC_ALL=C
18 export LC_ALL 13 export LC_ALL
19} 14}
20 15
21if test_case_begin "exclude directory by basename"; then 16if test_case_begin "exclude directory by basename"; then
22 17
23 # Demonstrates that excluding a directory name also excludes that 18 # Demonstrates that excluding a directory name also excludes that
24 # directory further down in the hierarchy. 19 # directory further down in the hierarchy.
25 # 20 #
26 # For example, with BSD tar and GNU tar it is not possible to exclude 21 # For example, with BSD tar and GNU tar it is not possible to exclude
27 # only the top-level "contrib" directory but still extract other 22 # only the top-level "contrib" directory but still extract other
28 # contrib directories. 23 # contrib directories.
29 # 24 #
30 # Experienced in lang/gcc*, which has contrib/ and java-lib/contrib/. 25 # Experienced in lang/gcc*, which has contrib/ and java-lib/contrib/.
31 26
32 create_file_lines "contrib/file" "content" 27 create_file_lines "contrib/file" "content"
33 create_file_lines "other/file" "content" 28 create_file_lines "other/file" "content"
34 create_file_lines "other/contrib/file" "content" 29 create_file_lines "other/contrib/file" "content"
35 30
36 tar cf "archive.tar" "contrib" "other" 31 tar cf "$tmpdir/archive.tar" "contrib" "other"
37 rm -r "contrib" "other" 32 rm -r "contrib" "other"
38 33
39 sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib" 34 sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib"
40 35
41 find . -print | sort > "extracted" 36 find . -print | sort > "$tmpdir/extracted"
42 37
43 assert_that "extracted" --file-is-lines \ 38 assert_that "$tmpdir/extracted" --file-is-lines \
44 "." \ 39 "." \
45 "./archive.tar" \ 
46 "./extracted" \ 
47 "./other" \ 40 "./other" \
48 "./other/file" 41 "./other/file"
49 42
50 test_case_end 43 test_case_end
51fi 44fi
52 45
53if test_case_begin "try to exclude directory by pattern with slash"; then 46if test_case_begin "try to exclude directory by pattern with slash"; then
54 47
55 # Having exclusion patterns with slash does not work at all for 48 # Having exclusion patterns with slash does not work at all for
56 # the default tar extractor. The patterns are matched against 49 # the default tar extractor. The patterns are matched against
57 # the basename of the file to be extracted, and that basename 50 # the basename of the file to be extracted, and that basename
58 # obviously cannot contain a slash. 51 # obviously cannot contain a slash.
59 52
60 create_file_lines "contrib/file" "content" 53 create_file_lines "contrib/file" "content"
61 create_file_lines "other/file" "content" 54 create_file_lines "other/file" "content"
62 create_file_lines "other/contrib/file" "content" 55 create_file_lines "other/contrib/file" "content"
63 56
64 tar cf "archive.tar" "contrib" "other" 57 tar cf "$tmpdir/archive.tar" "contrib" "other"
65 rm -r "contrib" "other" 58 rm -r "contrib" "other"
66 59
67 sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "contrib/*" 60 sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "contrib/*"
68 61
69 find . -print | sort > "extracted" 62 find . -print | sort > "$tmpdir/extracted"
70 63
71 assert_that "extracted" --file-is-lines \ 64 assert_that "$tmpdir/extracted" --file-is-lines \
72 "." \ 65 "." \
73 "./archive.tar" \ 
74 "./contrib" \ 66 "./contrib" \
75 "./extracted" \ 
76 "./other" \ 67 "./other" \
77 "./other/contrib" \ 68 "./other/contrib" \
78 "./other/file" 69 "./other/file"
79 70
80 test_case_end 71 test_case_end
81fi 72fi
82 73
83if test_case_begin "exclude asterisk"; then 74if test_case_begin "exclude asterisk"; then
84 75
85 # Ensure that the exclusion pattern "*" is not expanded by the 76 # Ensure that the exclusion pattern "*" is not expanded by the
86 # shell but passed as-is to the extractor. 77 # shell but passed as-is to the extractor.
 78 #
 79 # If the pattern were expanded, it would expand to 'expanded'
 80 # and would thus not exclude anything from the actual archive,
 81 # which means that all files in the archive would be extracted.
87 82
88 create_file_lines "contrib/file" "content" 83 create_file_lines "contrib/file" "content"
89 create_file_lines "other/file" "content" 84 create_file_lines "other/file" "content"
90 create_file_lines "other/contrib/file" "content" 85 create_file_lines "other/contrib/file" "content"
91 86
92 tar cf "archive.tar" "contrib" "other" 87 tar cf "$tmpdir/archive.tar" "contrib" "other"
93 rm -r "contrib" "other" 88 rm -r "contrib" "other"
94 89
95 sh "$pkgsrcdir/mk/extract/extract" -x "archive.tar" "*" 90 > 'expanded'
 91 sh "$pkgsrcdir/mk/extract/extract" -x "$tmpdir/archive.tar" "*"
 92 rm 'expanded'
96 93
97 find . -print | sort > "extracted" 94 find . -print | sort > "$tmpdir/extracted"
98 95
99 assert_that "extracted" --file-is-lines \ 96 assert_that "$tmpdir/extracted" --file-is-lines \
100 "." \ 97 "."
101 "./archive.tar" \ 
102 "./extracted" 
103 98
104 test_case_end 99 test_case_end
105fi 100fi
106 101
107# TODO: test -x on an archiver that doesn't support it. 102# TODO: test -x on an archiver that doesn't support it.
108 103
109# TODO: add test for extracting only a few files. 104# TODO: add test for extracting only a few files.

cvs diff -r1.33 -r1.34 pkgsrc/regress/infra-unittests/subst.sh (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/subst.sh 2020/05/09 17:10:38 1.33
+++ pkgsrc/regress/infra-unittests/subst.sh 2020/05/11 19:13:10 1.34
@@ -1,25 +1,26 @@ @@ -1,25 +1,26 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: subst.sh,v 1.33 2020/05/09 17:10:38 rillig Exp $ 2# $NetBSD: subst.sh,v 1.34 2020/05/11 19:13:10 rillig Exp $
3# 3#
4# Tests for mk/subst.mk. 4# Tests for mk/subst.mk.
5# 5#
6 6
7set -eu 7set -eu
8 8
9. "./test.subr" 9. "./test.subr"
10 10
11test_case_set_up() { 11test_case_set_up() {
12 rm -rf "$tmpdir"/.??* "$tmpdir"/* 12 wrkdir="$tmpdir/wrkdir"
 13 mkdir "$wrkdir"
13 14
14 create_file "prepare-subst.mk" <<-EOF 15 create_file "prepare-subst.mk" <<-EOF
15 # The tools that are used by subst.mk 16 # The tools that are used by subst.mk
16 AWK= awk 17 AWK= awk
17 CHMOD= chmod 18 CHMOD= chmod
18 CMP= cmp 19 CMP= cmp
19 DIFF= diff 20 DIFF= diff
20 ECHO= echo 21 ECHO= echo
21 MKDIR= mkdir -p 22 MKDIR= mkdir -p
22 MV= mv 23 MV= mv
23 RM= rm 24 RM= rm
24 RMDIR= rmdir 25 RMDIR= rmdir
25 SED= sed 26 SED= sed
@@ -27,83 +28,91 @@ test_case_set_up() { @@ -27,83 +28,91 @@ test_case_set_up() {
27 TOUCH= touch 28 TOUCH= touch
28 TOUCH_FLAGS= # none 29 TOUCH_FLAGS= # none
29 TR= tr 30 TR= tr
30 TRUE= true 31 TRUE= true
31 32
32 # Commands that are specific to pkgsrc 33 # Commands that are specific to pkgsrc
33 RUN= @set -e; 34 RUN= @set -e;
34 STEP_MSG= echo "=>" 35 STEP_MSG= echo "=>"
35 DO_NADA= : do-nada 36 DO_NADA= : do-nada
36 INFO_MSG= echo "info:" 37 INFO_MSG= echo "info:"
37 WARNING_MSG= echo "warning:" 38 WARNING_MSG= echo "warning:"
38 FAIL_MSG= sh $pkgsrcdir/mk/scripts/fail echo "fail:" 39 FAIL_MSG= sh $pkgsrcdir/mk/scripts/fail echo "fail:"
39 40
40 WRKDIR= $tmpdir 41 WRKDIR= $tmpdir/wrkdir
41 WRKSRC= $tmpdir 42 WRKSRC= .
42 EOF 43 EOF
43} 44}
44 45
 46test_case_tear_down() {
 47 # Clean up the .subst_*_done cookie files.
 48 rm -r "$wrkdir"
 49}
 50
45 51
46if test_case_begin "single file"; then 52if test_case_begin "single file"; then
47 53
48 # A single file is patched successfully. 54 # A single file is patched successfully.
49 55
50 create_file "subst-single.mk" <<-EOF 56 create_file "subst-single.mk" <<-EOF
51 SUBST_CLASSES+= class 57 SUBST_CLASSES+= class
52 SUBST_STAGE.class= pre-configure 58 SUBST_STAGE.class= pre-configure
53 SUBST_FILES.class= subst-single.txt 59 SUBST_FILES.class= subst-single.txt
54 SUBST_SED.class= -e 's,before,after,' 60 SUBST_SED.class= -e 's,before,after,'
55 61
56 .include "prepare-subst.mk" 62 .include "prepare-subst.mk"
57 .include "mk/subst.mk" 63 .include "mk/subst.mk"
58 64
59 all: subst-class 65 all: subst-class
60 EOF 66 EOF
61 67
62 create_file_lines "subst-single.txt" \ 68 create_file_lines "subst-single.txt" \
63 "before" 69 "before"
64 70
65 run_bmake "subst-single.mk" > "$tmpdir/output" 71 run_bmake "subst-single.mk" > "$tmpdir/output"
66 72
67 assert_that "output" --file-contains-exactly "=> Substituting \"class\" in subst-single.txt" 73 assert_that "$tmpdir/output" --file-contains-exactly \
68 assert_that "subst-single.txt" --file-contains-exactly "after" 74 "=> Substituting \"class\" in subst-single.txt"
 75 assert_that "subst-single.txt" --file-contains-exactly \
 76 "after"
69 77
70 test_case_end 78 test_case_end
71fi 79fi
72 80
73 81
74if test_case_begin "several individual files"; then 82if test_case_begin "several individual files"; then
75 83
76 # Several individual files are patched successfully. 84 # Several individual files are patched successfully.
77 85
78 create_file "testcase.mk" <<-EOF 86 create_file "testcase.mk" <<-EOF
79 SUBST_CLASSES+= class 87 SUBST_CLASSES+= class
80 SUBST_STAGE.class= pre-configure 88 SUBST_STAGE.class= pre-configure
81 SUBST_FILES.class= first second third 89 SUBST_FILES.class= first second third
82 SUBST_SED.class= -e 's,file,example,' 90 SUBST_SED.class= -e 's,file,example,'
83 91
84 .include "prepare-subst.mk" 92 .include "prepare-subst.mk"
85 .include "mk/subst.mk" 93 .include "mk/subst.mk"
86 94
87 all: subst-class 95 all: subst-class
88 EOF 96 EOF
89 97
90 create_file_lines "first" "the first file" 98 create_file_lines "first" "the first file"
91 create_file_lines "second" "the second file" 99 create_file_lines "second" "the second file"
92 create_file_lines "third" "the third file" 100 create_file_lines "third" "the third file"
93 101
94 output=$(run_bmake "testcase.mk") 102 run_bmake "testcase.mk" > "$tmpdir/output"
95 103
96 assert_that "$output" --equals "=> Substituting \"class\" in first second third" 104 assert_that "$tmpdir/output" --file-is-lines \
 105 "=> Substituting \"class\" in first second third"
97 assert_that "first" --file-contains-exactly "the first example" 106 assert_that "first" --file-contains-exactly "the first example"
98 assert_that "second" --file-contains-exactly "the second example" 107 assert_that "second" --file-contains-exactly "the second example"
99 assert_that "third" --file-contains-exactly "the third example" 108 assert_that "third" --file-contains-exactly "the third example"
100 109
101 test_case_end 110 test_case_end
102fi 111fi
103 112
104 113
105if test_case_begin "several files by pattern"; then 114if test_case_begin "several files by pattern"; then
106 115
107 # Several files are patched successfully. 116 # Several files are patched successfully.
108 # The filenames are given by a pattern. 117 # The filenames are given by a pattern.
109 118
@@ -149,242 +158,243 @@ if test_case_begin "pattern with 1 noop" @@ -149,242 +158,243 @@ if test_case_begin "pattern with 1 noop"
149 SUBST_FILES.class= pattern-* 158 SUBST_FILES.class= pattern-*
150 SUBST_SED.class= -e 's,file,example,' 159 SUBST_SED.class= -e 's,file,example,'
151 160
152 .include "prepare-subst.mk" 161 .include "prepare-subst.mk"
153 .include "mk/subst.mk" 162 .include "mk/subst.mk"
154 163
155 all: subst-class 164 all: subst-class
156 EOF 165 EOF
157 166
158 create_file_lines "pattern-first" "the first file" 167 create_file_lines "pattern-first" "the first file"
159 create_file_lines "pattern-second" "the second is already an example" 168 create_file_lines "pattern-second" "the second is already an example"
160 create_file_lines "pattern-third" "the third file" 169 create_file_lines "pattern-third" "the third file"
161 170
162 run_bmake "testcase.mk" > "$tmpdir/actual-output" 171 run_bmake "testcase.mk" > "$tmpdir/output"
163 create_file_lines "expected-output" \ 172 create_file_lines "expected-output" \
164 '=> Substituting "class" in pattern-*' \ 173 '=> Substituting "class" in pattern-*' \
165 'info: [subst.mk:class] Nothing changed in "pattern-second".' 174 'info: [subst.mk:class] Nothing changed in "pattern-second".'
166 175
167 assert_that "actual-output" --file-equals "expected-output" 176 assert_that "$tmpdir/output" --file-equals "expected-output"
168 assert_that "pattern-first" --file-contains-exactly "the first example" 177 assert_that "pattern-first" --file-contains-exactly "the first example"
169 assert_that "pattern-second" --file-contains-exactly "the second is already an example" 178 assert_that "pattern-second" --file-contains-exactly "the second is already an example"
170 assert_that "pattern-third" --file-contains-exactly "the third example" 179 assert_that "pattern-third" --file-contains-exactly "the third example"
171 180
172 test_case_end 181 test_case_end
173fi 182fi
174 183
175 184
176if test_case_begin "single file noop, noop_ok=yes"; then 185if test_case_begin "single file noop, noop_ok=yes"; then
177 186
178 create_file "testcase.mk" <<-EOF 187 create_file "testcase.mk" <<-EOF
179 SUBST_CLASSES+= class 188 SUBST_CLASSES+= class
180 SUBST_STAGE.class= pre-configure 189 SUBST_STAGE.class= pre-configure
181 SUBST_FILES.class= single 190 SUBST_FILES.class= single
182 SUBST_SED.class= -e 's,file,example,' 191 SUBST_SED.class= -e 's,file,example,'
183 SUBST_NOOP_OK.class= yes 192 SUBST_NOOP_OK.class= yes
184 193
185 .include "prepare-subst.mk" 194 .include "prepare-subst.mk"
186 .include "mk/subst.mk" 195 .include "mk/subst.mk"
187 196
188 all: subst-class 197 all: subst-class
189 EOF 198 EOF
190 199
191 create_file_lines "single" "already an example" 200 create_file_lines "single" "already an example"
192 201
193 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 202 run_bmake "testcase.mk" > "$tmpdir/output" \
 203 && exitcode=0 || exitcode=$?
194 204
195 create_file_lines "expected-output" \ 205 assert_that "$tmpdir/output" --file-is-lines \
196 '=> Substituting "class" in single' \ 206 '=> Substituting "class" in single' \
197 'info: [subst.mk:class] Nothing changed in "single".' 207 'info: [subst.mk:class] Nothing changed in "single".'
198 assert_that "actual-output" --file-equals "expected-output" 
199 assert_that "single" --file-contains-exactly "already an example" 208 assert_that "single" --file-contains-exactly "already an example"
200 assert_that "$exitcode" --equals "0" 209 assert_that "$exitcode" --equals "0"
201 210
202 test_case_end 211 test_case_end
203fi 212fi
204 213
205 214
206if test_case_begin "single file noop, noop_ok=no"; then 215if test_case_begin "single file noop, noop_ok=no"; then
207 216
208 create_file "testcase.mk" <<-EOF 217 create_file "testcase.mk" <<-EOF
209 SUBST_CLASSES+= class 218 SUBST_CLASSES+= class
210 SUBST_STAGE.class= pre-configure 219 SUBST_STAGE.class= pre-configure
211 SUBST_FILES.class= single 220 SUBST_FILES.class= single
212 SUBST_SED.class= -e 's,file,example,' 221 SUBST_SED.class= -e 's,file,example,'
213 SUBST_NOOP_OK.class= no 222 SUBST_NOOP_OK.class= no
214 223
215 .include "prepare-subst.mk" 224 .include "prepare-subst.mk"
216 .include "mk/subst.mk" 225 .include "mk/subst.mk"
217 226
218 all: subst-class 227 all: subst-class
219 EOF 228 EOF
220 229
221 create_file_lines "single" "already an example" 230 create_file_lines "single" "already an example"
222 231
223 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 232 run_bmake "testcase.mk" > "$tmpdir/output" \
 233 && exitcode=0 || exitcode=$?
224 234
225 create_file_lines "expected-output" \ 235 create_file_lines "expected-output" \
226 '=> Substituting "class" in single' \ 236 '=> Substituting "class" in single' \
227 'warning: [subst.mk:class] Nothing changed in "single".' \ 237 'warning: [subst.mk:class] Nothing changed in "single".' \
228 'fail: [subst.mk:class] The filename pattern "single" has no effect.' \ 238 'fail: [subst.mk:class] The filename pattern "single" has no effect.' \
229 '*** Error code 1' \ 239 '*** Error code 1' \
230 '' \ 240 '' \
231 'Stop.' \ 241 'Stop.' \
232 "$make: stopped in $PWD" 242 "$make: stopped in $PWD"
233 assert_that "actual-output" --file-equals "expected-output" 243 assert_that "$tmpdir/output" --file-equals "expected-output"
234 assert_that "single" --file-contains-exactly "already an example" 244 assert_that "single" --file-contains-exactly "already an example"
235 assert_that "$exitcode" --equals "1" 245 assert_that "$exitcode" --equals "1"
236 246
237 test_case_end 247 test_case_end
238fi 248fi
239 249
240 250
241if test_case_begin "single file nonexistent"; then 251if test_case_begin "single file nonexistent"; then
242 252
243 create_file "testcase.mk" <<-EOF 253 create_file "testcase.mk" <<-EOF
244 SUBST_CLASSES+= class 254 SUBST_CLASSES+= class
245 SUBST_STAGE.class= pre-configure 255 SUBST_STAGE.class= pre-configure
246 SUBST_FILES.class= nonexistent 256 SUBST_FILES.class= nonexistent
247 SUBST_SED.class= -e 's,file,example,' 257 SUBST_SED.class= -e 's,file,example,'
248 SUBST_NOOP_OK.class= no 258 SUBST_NOOP_OK.class= no
249 259
250 .include "prepare-subst.mk" 260 .include "prepare-subst.mk"
251 .include "mk/subst.mk" 261 .include "mk/subst.mk"
252 262
253 all: subst-class 263 all: subst-class
254 EOF 264 EOF
255 265
256 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 266 run_bmake "testcase.mk" > "$tmpdir/output" \
 267 && exitcode=0 || exitcode=$?
257 268
258 create_file_lines "expected-output" \ 269 assert_that "$tmpdir/output" --file-is-lines \
259 '=> Substituting "class" in nonexistent' \ 270 '=> Substituting "class" in nonexistent' \
260 'warning: [subst.mk:class] Ignoring nonexistent file "nonexistent".' \ 271 'warning: [subst.mk:class] Ignoring nonexistent file "nonexistent".' \
261 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \ 272 'fail: [subst.mk:class] The filename pattern "nonexistent" has no effect.' \
262 '*** Error code 1' \ 273 '*** Error code 1' \
263 '' \ 274 '' \
264 'Stop.' \ 275 'Stop.' \
265 "$make: stopped in $PWD" 276 "$make: stopped in $PWD"
266 assert_that "actual-output" --file-equals "expected-output" 
267 assert_that "$exitcode" --equals "1" 277 assert_that "$exitcode" --equals "1"
268 278
269 test_case_end 279 test_case_end
270fi 280fi
271 281
272 282
273if test_case_begin "single file nonexistent ok"; then 283if test_case_begin "single file nonexistent ok"; then
274 284
275 create_file "testcase.mk" <<-EOF 285 create_file "testcase.mk" <<-EOF
276 SUBST_CLASSES+= class 286 SUBST_CLASSES+= class
277 SUBST_STAGE.class= pre-configure 287 SUBST_STAGE.class= pre-configure
278 SUBST_FILES.class= nonexistent 288 SUBST_FILES.class= nonexistent
279 SUBST_SED.class= -e 's,file,example,' 289 SUBST_SED.class= -e 's,file,example,'
280 SUBST_NOOP_OK.class= yes 290 SUBST_NOOP_OK.class= yes
281 291
282 .include "prepare-subst.mk" 292 .include "prepare-subst.mk"
283 .include "mk/subst.mk" 293 .include "mk/subst.mk"
284 294
285 all: subst-class 295 all: subst-class
286 EOF 296 EOF
287 297
288 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 298 run_bmake "testcase.mk" > "$tmpdir/output" \
 299 && exitcode=0 || exitcode=$?
289 300
290 create_file_lines "expected-output" \ 301 assert_that "$tmpdir/output" --file-is-lines \
291 '=> Substituting "class" in nonexistent' \ 302 '=> Substituting "class" in nonexistent' \
292 'info: [subst.mk:class] Ignoring nonexistent file "nonexistent".' 303 'info: [subst.mk:class] Ignoring nonexistent file "nonexistent".'
293 assert_that "actual-output" --file-equals "expected-output" 
294 assert_that "$exitcode" --equals "0" 304 assert_that "$exitcode" --equals "0"
295 305
296 test_case_end 306 test_case_end
297fi 307fi
298 308
299 309
300if test_case_begin "several patterns, 1 nonexistent"; then 310if test_case_begin "several patterns, 1 nonexistent"; then
301 311
302 create_file "testcase.mk" <<-EOF 312 create_file "testcase.mk" <<-EOF
303 SUBST_CLASSES+= class 313 SUBST_CLASSES+= class
304 SUBST_STAGE.class= pre-configure 314 SUBST_STAGE.class= pre-configure
305 SUBST_FILES.class= *exist* *not-found* 315 SUBST_FILES.class= *exist* *not-found*
306 SUBST_SED.class= -e 's,file,example,' 316 SUBST_SED.class= -e 's,file,example,'
307 317
308 .include "prepare-subst.mk" 318 .include "prepare-subst.mk"
309 .include "mk/subst.mk" 319 .include "mk/subst.mk"
310 320
311 all: subst-class 321 all: subst-class
312 EOF 322 EOF
313 323
314 create_file_lines "exists" "this file exists" 324 create_file_lines "exists" "this file exists"
315 325
316 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 326 run_bmake "testcase.mk" > "$tmpdir/output" \
 327 && exitcode=0 || exitcode=$?
317 328
318 create_file_lines "expected-output" \ 329 assert_that "$tmpdir/output" --file-is-lines \
319 '=> Substituting "class" in *exist* *not-found*' \ 330 '=> Substituting "class" in *exist* *not-found*' \
320 'info: [subst.mk:class] Ignoring nonexistent file "./*not-found*".' 331 'info: [subst.mk:class] Ignoring nonexistent file "./*not-found*".'
321 assert_that "actual-output" --file-equals "expected-output" 
322 assert_that "exists" --file-contains-exactly "this example exists" 332 assert_that "exists" --file-contains-exactly "this example exists"
323 assert_that "$exitcode" --equals "0" 333 assert_that "$exitcode" --equals "0"
324 334
325 test_case_end 335 test_case_end
326fi 336fi
327 337
328 338
329if test_case_begin "multiple missing files, all are reported at once"; then 339if test_case_begin "multiple missing files, all are reported at once"; then
330 340
331 create_file "testcase.mk" <<-EOF 341 create_file "testcase.mk" <<-EOF
332 SUBST_CLASSES+= class 342 SUBST_CLASSES+= class
333 SUBST_STAGE.class= pre-configure 343 SUBST_STAGE.class= pre-configure
334 SUBST_FILES.class= does not exist 344 SUBST_FILES.class= does not exist
335 SUBST_SED.class= -e 'sahara' 345 SUBST_SED.class= -e 'sahara'
336 346
337 .include "prepare-subst.mk" 347 .include "prepare-subst.mk"
338 .include "mk/subst.mk" 348 .include "mk/subst.mk"
339 EOF 349 EOF
340 350
341 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 351 run_bmake "testcase.mk" > "$tmpdir/output" \
 352 && exitcode=0 || exitcode=$?
342 353
343 create_file_lines "expected-output" \ 354 assert_that "$tmpdir/output" --file-is-lines \
344 '=> Substituting "class" in does not exist' \ 355 '=> Substituting "class" in does not exist' \
345 'info: [subst.mk:class] Ignoring nonexistent file "does".' \ 356 'info: [subst.mk:class] Ignoring nonexistent file "does".' \
346 'info: [subst.mk:class] Ignoring nonexistent file "not".' \ 357 'info: [subst.mk:class] Ignoring nonexistent file "not".' \
347 'info: [subst.mk:class] Ignoring nonexistent file "exist".' 358 'info: [subst.mk:class] Ignoring nonexistent file "exist".'
348 assert_that "actual-output" --file-equals "expected-output" 
349 assert_that "$exitcode" --equals "0" 359 assert_that "$exitcode" --equals "0"
350 360
351 test_case_end 361 test_case_end
352fi 362fi
353 363
354 364
355if test_case_begin "multiple no-op files, all are reported at once"; then 365if test_case_begin "multiple no-op files, all are reported at once"; then
356 366
357 create_file "testcase.mk" <<-EOF 367 create_file "testcase.mk" <<-EOF
358 SUBST_CLASSES+= class 368 SUBST_CLASSES+= class
359 SUBST_STAGE.class= pre-configure 369 SUBST_STAGE.class= pre-configure
360 SUBST_FILES.class= first second third 370 SUBST_FILES.class= first second third
361 SUBST_SED.class= -e 's,from,to,' 371 SUBST_SED.class= -e 's,from,to,'
362 372
363 .include "prepare-subst.mk" 373 .include "prepare-subst.mk"
364 .include "mk/subst.mk" 374 .include "mk/subst.mk"
365 EOF 375 EOF
366 create_file_lines "first" "text" 376 create_file_lines "first" "text"
367 create_file_lines "second" "second" 377 create_file_lines "second" "second"
368 create_file_lines "third" "third" 378 create_file_lines "third" "third"
369 379
370 run_bmake "testcase.mk" > "$tmpdir/actual-output" && exitcode=0 || exitcode=$? 380 run_bmake "testcase.mk" > "$tmpdir/output" \
 381 && exitcode=0 || exitcode=$?
371 382
372 create_file_lines "expected-output" \ 383 assert_that "$tmpdir/output" --file-is-lines \
373 '=> Substituting "class" in first second third' \ 384 '=> Substituting "class" in first second third' \
374 'info: [subst.mk:class] Nothing changed in "first".' \ 385 'info: [subst.mk:class] Nothing changed in "first".' \
375 'info: [subst.mk:class] Nothing changed in "second".' \ 386 'info: [subst.mk:class] Nothing changed in "second".' \
376 'info: [subst.mk:class] Nothing changed in "third".' 387 'info: [subst.mk:class] Nothing changed in "third".'
377 assert_that "actual-output" --file-equals "expected-output" 
378 assert_that "$exitcode" --equals "0" 388 assert_that "$exitcode" --equals "0"
379 389
380 test_case_end 390 test_case_end
381fi 391fi
382 392
383 393
384if test_case_begin "late evaluation of SUBST_FILES"; then 394if test_case_begin "late evaluation of SUBST_FILES"; then
385 395
386 # Ensure that SUBST_FILES is evaluated as late as possible. 396 # Ensure that SUBST_FILES is evaluated as late as possible.
387 # Evaluating it early breaks cases like pkglocaledir where the 397 # Evaluating it early breaks cases like pkglocaledir where the
388 # list of files is generated by a shell command. 398 # list of files is generated by a shell command.
389 # See mk/configure/replace-localedir.mk. 399 # See mk/configure/replace-localedir.mk.
390 400
@@ -403,37 +413,36 @@ WRKSRC= \${WRKDIR}/package-1.0 @@ -403,37 +413,36 @@ WRKSRC= \${WRKDIR}/package-1.0
403.include "mk/subst.mk" 413.include "mk/subst.mk"
404 414
405# It is tricky that the dependency must use an internal implementation 415# It is tricky that the dependency must use an internal implementation
406# detail, but that's the only way to guarantee the correct ordering. 416# detail, but that's the only way to guarantee the correct ordering.
407\${_SUBST_COOKIE.class}: prepare-subst-class 417\${_SUBST_COOKIE.class}: prepare-subst-class
408prepare-subst-class: 418prepare-subst-class:
409 \${RUN} \${MKDIR} \${WRKSRC} 419 \${RUN} \${MKDIR} \${WRKSRC}
410 \${RUN} \${ECHO} "from" > "\${WRKSRC}/first" 420 \${RUN} \${ECHO} "from" > "\${WRKSRC}/first"
411 \${RUN} \${ECHO} "from" > "\${WRKSRC}/second" 421 \${RUN} \${ECHO} "from" > "\${WRKSRC}/second"
412 \${RUN} \${ECHO} "from" > "\${WRKSRC}/third" 422 \${RUN} \${ECHO} "from" > "\${WRKSRC}/third"
413EOF 423EOF
414 424
415 run_bmake "testcase.mk" "subst-class" \ 425 run_bmake "testcase.mk" "subst-class" \
416 1> "$tmpdir/actual-output" \ 426 1> "$tmpdir/stdout" \
417 2> "$tmpdir/actual-stderr" \ 427 2> "$tmpdir/stderr" \
418 && exitcode=0 || exitcode=$? 428 && exitcode=0 || exitcode=$?
419 429
420 create_file_lines "expected-output" \ 430 assert_that "$tmpdir/stdout" --file-is-lines \
421 '=> Substituting "class" in first third' 431 '=> Substituting "class" in first third'
422 assert_that "actual-output" --file-equals "expected-output" 432 assert_that "$tmpdir/stderr" --file-is-empty
423 assert_that "actual-stderr" --file-is-empty 433 assert_that "$wrkdir/package-1.0/first" --file-contains-exactly "to"
424 assert_that "package-1.0/first" --file-contains-exactly "to" 434 assert_that "$wrkdir/package-1.0/second" --file-contains-exactly "from"
425 assert_that "package-1.0/second" --file-contains-exactly "from" 435 assert_that "$wrkdir/package-1.0/third" --file-contains-exactly "to"
426 assert_that "package-1.0/third" --file-contains-exactly "to" 
427 assert_that "$exitcode" --equals "0" 436 assert_that "$exitcode" --equals "0"
428 437
429 test_case_end 438 test_case_end
430fi 439fi
431 440
432 441
433if test_case_begin "special characters in filenames"; then 442if test_case_begin "special characters in filenames"; then
434 443
435 create_file "testcase.mk" <<-EOF 444 create_file "testcase.mk" <<-EOF
436 SUBST_CLASSES+= class 445 SUBST_CLASSES+= class
437 SUBST_STAGE.class= pre-configure 446 SUBST_STAGE.class= pre-configure
438 SUBST_FILES.class= * 447 SUBST_FILES.class= *
439 SUBST_SED.class= -e s,before,after, 448 SUBST_SED.class= -e s,before,after,
@@ -447,33 +456,30 @@ if test_case_begin "special characters i @@ -447,33 +456,30 @@ if test_case_begin "special characters i
447 create_file_lines "0123456789:;<=>?" "before" 456 create_file_lines "0123456789:;<=>?" "before"
448 create_file_lines "@ABCDEFGHIJKLMNO" "before" 457 create_file_lines "@ABCDEFGHIJKLMNO" "before"
449 create_file_lines "PQRSTUVWXYZ[\\]^_" "before" 458 create_file_lines "PQRSTUVWXYZ[\\]^_" "before"
450 create_file_lines "\`abcdefghijklmno" "before" 459 create_file_lines "\`abcdefghijklmno" "before"
451 create_file_lines "pqrstuvwxyz{|}~" "before" 460 create_file_lines "pqrstuvwxyz{|}~" "before"
452 create_file_lines "--no-option" "before" 461 create_file_lines "--no-option" "before"
453 create_file_lines ".hidden" "before" 462 create_file_lines ".hidden" "before"
454 463
455 run_bmake "testcase.mk" "subst-class" \ 464 run_bmake "testcase.mk" "subst-class" \
456 1> "$tmpdir/stdout" \ 465 1> "$tmpdir/stdout" \
457 2> "$tmpdir/stderr" \ 466 2> "$tmpdir/stderr" \
458 && exitcode=0 || exitcode=$? 467 && exitcode=0 || exitcode=$?
459 468
460 assert_that "stdout" --file-is-lines \ 469 assert_that "$tmpdir/stdout" --file-is-lines \
461 '=> Substituting "class" in *' \ 470 '=> Substituting "class" in *' \
462 'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".' \ 471 'info: [subst.mk:class] Nothing changed in "prepare-subst.mk".'
463 'info: [subst.mk:class] Nothing changed in "stderr".' \ 472 assert_that "$tmpdir/stderr" --file-is-empty
464 'info: [subst.mk:class] Nothing changed in "stdout".' \ 
465 'info: [subst.mk:class] Nothing changed in "test.subr.main.mk".' 
466 assert_that "stderr" --file-is-empty 
467 assert_that "$exitcode" --equals "0" 473 assert_that "$exitcode" --equals "0"
468 474
469 assert_that " !\"#\$%&'()*+,-." --file-is-lines "after" 475 assert_that " !\"#\$%&'()*+,-." --file-is-lines "after"
470 assert_that "0123456789:;<=>?" --file-is-lines "after" 476 assert_that "0123456789:;<=>?" --file-is-lines "after"
471 assert_that "@ABCDEFGHIJKLMNO" --file-is-lines "after" 477 assert_that "@ABCDEFGHIJKLMNO" --file-is-lines "after"
472 assert_that "PQRSTUVWXYZ[\\]^_" --file-is-lines "after" 478 assert_that "PQRSTUVWXYZ[\\]^_" --file-is-lines "after"
473 assert_that "\`abcdefghijklmno" --file-is-lines "after" 479 assert_that "\`abcdefghijklmno" --file-is-lines "after"
474 assert_that "pqrstuvwxyz{|}~" --file-is-lines "after" 480 assert_that "pqrstuvwxyz{|}~" --file-is-lines "after"
475 assert_that "--no-option" --file-is-lines "after" 481 assert_that "--no-option" --file-is-lines "after"
476 assert_that ".hidden" --file-is-lines "before" 482 assert_that ".hidden" --file-is-lines "before"
477 483
478 test_case_end 484 test_case_end
479fi 485fi
@@ -491,29 +497,29 @@ if test_case_begin "brackets in filename @@ -491,29 +497,29 @@ if test_case_begin "brackets in filename
491 .include "mk/subst.mk" 497 .include "mk/subst.mk"
492 EOF 498 EOF
493 499
494 create_file_lines "any" "before" 500 create_file_lines "any" "before"
495 create_file_lines "x" "before" 501 create_file_lines "x" "before"
496 create_file_lines "*" "before" 502 create_file_lines "*" "before"
497 create_file_lines "[*]" "before" 503 create_file_lines "[*]" "before"
498 504
499 run_bmake "testcase.mk" "subst-class" \ 505 run_bmake "testcase.mk" "subst-class" \
500 1> "$tmpdir/stdout" \ 506 1> "$tmpdir/stdout" \
501 2> "$tmpdir/stderr" \ 507 2> "$tmpdir/stderr" \
502 && exitcode=0 || exitcode=$? 508 && exitcode=0 || exitcode=$?
503 509
504 assert_that "stdout" --file-is-lines \ 510 assert_that "$tmpdir/stdout" --file-is-lines \
505 '=> Substituting "class" in [*]' 511 '=> Substituting "class" in [*]'
506 assert_that "stderr" --file-is-empty 512 assert_that "$tmpdir/stderr" --file-is-empty
507 assert_that "$exitcode" --equals "0" 513 assert_that "$exitcode" --equals "0"
508 514
509 assert_that "any" --file-is-lines "before" 515 assert_that "any" --file-is-lines "before"
510 assert_that "x" --file-is-lines "before" 516 assert_that "x" --file-is-lines "before"
511 assert_that "*" --file-is-lines "after" 517 assert_that "*" --file-is-lines "after"
512 assert_that "[*]" --file-is-lines "before" 518 assert_that "[*]" --file-is-lines "before"
513 519
514 test_case_end 520 test_case_end
515fi 521fi
516 522
517 523
518if test_case_begin "duplicate SUBST class"; then 524if test_case_begin "duplicate SUBST class"; then
519 525
@@ -524,28 +530,28 @@ SUBST_CLASSES+= one @@ -524,28 +530,28 @@ SUBST_CLASSES+= one
524 530
525all: 531all:
526 @printf 'fail reason: %s\n' \${PKG_FAIL_REASON} 1>&2 532 @printf 'fail reason: %s\n' \${PKG_FAIL_REASON} 1>&2
527 533
528.include "prepare-subst.mk" 534.include "prepare-subst.mk"
529.include "mk/subst.mk" 535.include "mk/subst.mk"
530EOF 536EOF
531 537
532 run_bmake "testcase.mk" "all" \ 538 run_bmake "testcase.mk" "all" \
533 1> "$tmpdir/stdout" \ 539 1> "$tmpdir/stdout" \
534 2> "$tmpdir/stderr" \ 540 2> "$tmpdir/stderr" \
535 && exitcode=0 || exitcode=$? 541 && exitcode=0 || exitcode=$?
536 542
537 assert_that "stdout" --file-is-empty 543 assert_that "$tmpdir/stdout" --file-is-empty
538 assert_that "stderr" --file-is-lines \ 544 assert_that "$tmpdir/stderr" --file-is-lines \
539 "fail reason: [subst.mk] duplicate SUBST class in: one one two" 545 "fail reason: [subst.mk] duplicate SUBST class in: one one two"
540 assert_that "$exitcode" --equals 0 546 assert_that "$exitcode" --equals 0
541 547
542 test_case_end 548 test_case_end
543fi 549fi
544 550
545 551
546if test_case_begin "several SUBST classes"; then 552if test_case_begin "several SUBST classes"; then
547 553
548 # It's ok to have several SUBST classes that apply to the same file. 554 # It's ok to have several SUBST classes that apply to the same file.
549 # The order of execution is not guaranteed though. 555 # The order of execution is not guaranteed though.
550 556
551 create_file_lines "file" "zero one two three four" 557 create_file_lines "file" "zero one two three four"
@@ -569,31 +575,31 @@ if test_case_begin "several SUBST classe @@ -569,31 +575,31 @@ if test_case_begin "several SUBST classe
569 .include "prepare-subst.mk" 575 .include "prepare-subst.mk"
570 .include "mk/subst.mk" 576 .include "mk/subst.mk"
571 EOF 577 EOF
572 578
573 run_bmake "testcase.mk" "pre-configure" \ 579 run_bmake "testcase.mk" "pre-configure" \
574 1> "$tmpdir/stdout" \ 580 1> "$tmpdir/stdout" \
575 2> "$tmpdir/stderr" \ 581 2> "$tmpdir/stderr" \
576 && exitcode=0 || exitcode=$? 582 && exitcode=0 || exitcode=$?
577 583
578 # The order of the above output is not guaranteed. 584 # The order of the above output is not guaranteed.
579 LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted" 585 LC_ALL=C sort < "$tmpdir/stdout" > "$tmpdir/stdout-sorted"
580 586
581 assert_that "file" --file-is-lines "zero I II III four" 587 assert_that "file" --file-is-lines "zero I II III four"
582 assert_that "stdout-sorted" --file-is-lines \ 588 assert_that "$tmpdir/stdout-sorted" --file-is-lines \
583 "=> Substituting \"one\" in file" \ 589 "=> Substituting \"one\" in file" \
584 "=> Substituting \"three\" in file" \ 590 "=> Substituting \"three\" in file" \
585 "=> Substituting \"two\" in file" 591 "=> Substituting \"two\" in file"
586 assert_that "stderr" --file-is-empty 592 assert_that "$tmpdir/stderr" --file-is-empty
587 assert_that "$exitcode" --equals 0 593 assert_that "$exitcode" --equals 0
588 594
589 test_case_end 595 test_case_end
590fi 596fi
591 597
592 598
593if test_case_begin "show diff"; then 599if test_case_begin "show diff"; then
594 600
595 create_file_lines "file" "one" "two" "three" 601 create_file_lines "file" "one" "two" "three"
596 602
597 create_file "testcase.mk" <<-EOF 603 create_file "testcase.mk" <<-EOF
598 SUBST_CLASSES+= two 604 SUBST_CLASSES+= two
599 SUBST_STAGE.two= pre-configure 605 SUBST_STAGE.two= pre-configure
@@ -605,36 +611,36 @@ if test_case_begin "show diff"; then @@ -605,36 +611,36 @@ if test_case_begin "show diff"; then
605 .include "mk/subst.mk" 611 .include "mk/subst.mk"
606 EOF 612 EOF
607 613
608 LC_ALL=C \ 614 LC_ALL=C \
609 run_bmake "testcase.mk" "pre-configure" \ 615 run_bmake "testcase.mk" "pre-configure" \
610 1> "$tmpdir/stdout" \ 616 1> "$tmpdir/stdout" \
611 2> "$tmpdir/stderr" \ 617 2> "$tmpdir/stderr" \
612 && exitcode=0 || exitcode=$? 618 && exitcode=0 || exitcode=$?
613 619
614 awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ 620 awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
615 < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" 621 < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
616 622
617 assert_that "file" --file-is-lines "one" "II" "three" 623 assert_that "file" --file-is-lines "one" "II" "three"
618 assert_that "stdout-filtered" --file-is-lines \ 624 assert_that "$tmpdir/stdout-filtered" --file-is-lines \
619 "=> Substituting \"two\" in file" \ 625 "=> Substituting \"two\" in file" \
620 "--- file (filtered timestamp)" \ 626 "--- file (filtered timestamp)" \
621 "+++ file.subst.sav (filtered timestamp)" \ 627 "+++ file.subst.sav (filtered timestamp)" \
622 "@@ -1,3 +1,3 @@" \ 628 "@@ -1,3 +1,3 @@" \
623 " one" \ 629 " one" \
624 "-two" \ 630 "-two" \
625 "+II" \ 631 "+II" \
626 " three" 632 " three"
627 assert_that "stderr" --file-is-empty 633 assert_that "$tmpdir/stderr" --file-is-empty
628 assert_that "$exitcode" --equals 0 634 assert_that "$exitcode" --equals 0
629 635
630 test_case_end 636 test_case_end
631fi 637fi
632 638
633 639
634if test_case_begin "global show diff"; then 640if test_case_begin "global show diff"; then
635 641
636 create_file_lines "file" "one" "two" "three" 642 create_file_lines "file" "one" "two" "three"
637 643
638 create_file "testcase.mk" <<-EOF 644 create_file "testcase.mk" <<-EOF
639 SUBST_CLASSES+= two 645 SUBST_CLASSES+= two
640 SUBST_STAGE.two= pre-configure 646 SUBST_STAGE.two= pre-configure
@@ -645,36 +651,36 @@ if test_case_begin "global show diff"; t @@ -645,36 +651,36 @@ if test_case_begin "global show diff"; t
645 .include "prepare-subst.mk" 651 .include "prepare-subst.mk"
646 .include "mk/subst.mk" 652 .include "mk/subst.mk"
647 EOF 653 EOF
648 654
649 run_bmake "testcase.mk" "pre-configure" \ 655 run_bmake "testcase.mk" "pre-configure" \
650 1> "$tmpdir/stdout" \ 656 1> "$tmpdir/stdout" \
651 2> "$tmpdir/stderr" \ 657 2> "$tmpdir/stderr" \
652 && exitcode=0 || exitcode=$? 658 && exitcode=0 || exitcode=$?
653 659
654 awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \ 660 awk '{ if (/^(---|\+\+\+) /) { print $1 " " $2 " (filtered timestamp)" } else { print $0 } }' \
655 < "$tmpdir/stdout" > "$tmpdir/stdout-filtered" 661 < "$tmpdir/stdout" > "$tmpdir/stdout-filtered"
656 662
657 assert_that "file" --file-is-lines "one" "II" "three" 663 assert_that "file" --file-is-lines "one" "II" "three"
658 assert_that "stdout-filtered" --file-is-lines \ 664 assert_that "$tmpdir/stdout-filtered" --file-is-lines \
659 "=> Substituting \"two\" in file" \ 665 "=> Substituting \"two\" in file" \
660 "--- file (filtered timestamp)" \ 666 "--- file (filtered timestamp)" \
661 "+++ file.subst.sav (filtered timestamp)" \ 667 "+++ file.subst.sav (filtered timestamp)" \
662 "@@ -1,3 +1,3 @@" \ 668 "@@ -1,3 +1,3 @@" \
663 " one" \ 669 " one" \
664 "-two" \ 670 "-two" \
665 "+II" \ 671 "+II" \
666 " three" 672 " three"
667 assert_that "stderr" --file-is-empty 673 assert_that "$tmpdir/stderr" --file-is-empty
668 assert_that "$exitcode" --equals 0 674 assert_that "$exitcode" --equals 0
669 675
670 test_case_end 676 test_case_end
671fi 677fi
672 678
673 679
674if test_case_begin "SUBST_VARS"; then 680if test_case_begin "SUBST_VARS"; then
675 681
676 create_file_lines "testcase.mk" \ 682 create_file_lines "testcase.mk" \
677 'SUBST_CLASSES+= vars' \ 683 'SUBST_CLASSES+= vars' \
678 'SUBST_STAGE.vars= pre-configure' \ 684 'SUBST_STAGE.vars= pre-configure' \
679 'SUBST_FILES.vars= vars.txt' \ 685 'SUBST_FILES.vars= vars.txt' \
680 'SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE' \ 686 'SUBST_VARS.vars= PLAIN DQUOT SQUOT DELIM PRINTABLE' \
@@ -702,29 +708,29 @@ if test_case_begin "SUBST_VARS"; then @@ -702,29 +708,29 @@ if test_case_begin "SUBST_VARS"; then
702 2> "$tmpdir/stderr" \ 708 2> "$tmpdir/stderr" \
703 && exitcode=0 || exitcode=$? 709 && exitcode=0 || exitcode=$?
704 710
705 # The double quotes and single quotes are kept since the variables 711 # The double quotes and single quotes are kept since the variables
706 # are treated as simple string variables, not as lists of shell 712 # are treated as simple string variables, not as lists of shell
707 # words. In these string variables, the quotes are part of the value. 713 # words. In these string variables, the quotes are part of the value.
708 assert_that "vars.txt" --file-is-lines \ 714 assert_that "vars.txt" --file-is-lines \
709 "plain" \ 715 "plain" \
710 "\"double quoted\"" \ 716 "\"double quoted\"" \
711 "'single quoted'" \ 717 "'single quoted'" \
712 "hello, world" \ 718 "hello, world" \
713 '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \ 719 '!"#$%&'\''()*+,-./09:;<=>?@AZ[\]^_`az{|}' \
714 "" 720 ""
715 assert_that "stdout" --file-is-lines \ 721 assert_that "$tmpdir/stdout" --file-is-lines \
716 "=> Substituting \"vars\" in vars.txt" 722 "=> Substituting \"vars\" in vars.txt"
717 assert_that "stderr" --file-is-empty 723 assert_that "$tmpdir/stderr" --file-is-empty
718 assert_that "$exitcode" --equals 0 724 assert_that "$exitcode" --equals 0
719 725
720 test_case_end 726 test_case_end
721fi 727fi
722 728
723if test_case_begin "SUBST_VARS with surrounding whitespace"; then 729if test_case_begin "SUBST_VARS with surrounding whitespace"; then
724 730
725 # Ensure that leading and trailing whitespace is preserved 731 # Ensure that leading and trailing whitespace is preserved
726 # in the variable values. 732 # in the variable values.
727 733
728 create_file_lines "testcase.mk" \ 734 create_file_lines "testcase.mk" \
729 'SUBST_CLASSES+= vars' \ 735 'SUBST_CLASSES+= vars' \
730 'SUBST_STAGE.vars= pre-configure' \ 736 'SUBST_STAGE.vars= pre-configure' \
@@ -745,29 +751,29 @@ if test_case_begin "SUBST_VARS with surr @@ -745,29 +751,29 @@ if test_case_begin "SUBST_VARS with surr
745 run_bmake "testcase.mk" "pre-configure" \ 751 run_bmake "testcase.mk" "pre-configure" \
746 1> "$tmpdir/stdout" \ 752 1> "$tmpdir/stdout" \
747 2> "$tmpdir/stderr" \ 753 2> "$tmpdir/stderr" \
748 && exitcode=0 || exitcode=$? 754 && exitcode=0 || exitcode=$?
749 755
750 space=' ' 756 space=' '
751 tab=' ' 757 tab=' '
752 newline=' 758 newline='
753' 759'
754 assert_that "vars.txt" --file-is-lines \ 760 assert_that "vars.txt" --file-is-lines \
755 "$space""between spaces""$space" \ 761 "$space""between spaces""$space" \
756 "$tab""between tabs""$tab" \ 762 "$tab""between tabs""$tab" \
757 "$newline""between newlines""$newline" 763 "$newline""between newlines""$newline"
758 assert_that "stdout" --file-is-lines \ 764 assert_that "$tmpdir/stdout" --file-is-lines \
759 "=> Substituting \"vars\" in vars.txt" 765 "=> Substituting \"vars\" in vars.txt"
760 assert_that "stderr" --file-is-empty 766 assert_that "$tmpdir/stderr" --file-is-empty
761 assert_that "$exitcode" --equals 0 767 assert_that "$exitcode" --equals 0
762 768
763 test_case_end 769 test_case_end
764fi 770fi
765 771
766 772
767if test_case_begin "SUBST_VARS with backslashes"; then 773if test_case_begin "SUBST_VARS with backslashes"; then
768 774
769 create_file_lines "testcase.mk" \ 775 create_file_lines "testcase.mk" \
770 'SUBST_CLASSES+= bs' \ 776 'SUBST_CLASSES+= bs' \
771 'SUBST_STAGE.bs= pre-configure' \ 777 'SUBST_STAGE.bs= pre-configure' \
772 'SUBST_FILES.bs= backslash.txt' \ 778 'SUBST_FILES.bs= backslash.txt' \
773 'SUBST_VARS.bs= BACKSLASHES' \ 779 'SUBST_VARS.bs= BACKSLASHES' \
@@ -775,29 +781,29 @@ if test_case_begin "SUBST_VARS with back @@ -775,29 +781,29 @@ if test_case_begin "SUBST_VARS with back
775 'BACKSLASHES= \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \ 781 'BACKSLASHES= \" \, \\, \" \'\'' \0\000 \x40 \089 \a \$$' \
776 '' \ 782 '' \
777 '.include "prepare-subst.mk"' \ 783 '.include "prepare-subst.mk"' \
778 '.include "mk/subst.mk"' 784 '.include "mk/subst.mk"'
779 create_file_lines "backslash.txt" "@BACKSLASHES@" 785 create_file_lines "backslash.txt" "@BACKSLASHES@"
780 786
781 run_bmake "testcase.mk" "pre-configure" \ 787 run_bmake "testcase.mk" "pre-configure" \
782 1> "$tmpdir/stdout" \ 788 1> "$tmpdir/stdout" \
783 2> "$tmpdir/stderr" \ 789 2> "$tmpdir/stderr" \
784 && exitcode=0 || exitcode=$? 790 && exitcode=0 || exitcode=$?
785 791
786 assert_that "backslash.txt" --file-is-lines \ 792 assert_that "backslash.txt" --file-is-lines \
787 '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$' 793 '\" \, \\, \" \'\'' \0\000 \x40 \089 \a \$'
788 assert_that "stdout" --file-is-lines \ 794 assert_that "$tmpdir/stdout" --file-is-lines \
789 "=> Substituting \"bs\" in backslash.txt" 795 "=> Substituting \"bs\" in backslash.txt"
790 assert_that "stderr" --file-is-empty 796 assert_that "$tmpdir/stderr" --file-is-empty
791 assert_that "$exitcode" --equals 0 797 assert_that "$exitcode" --equals 0
792 798
793 test_case_end 799 test_case_end
794fi 800fi
795 801
796 802
797if test_case_begin "SUBST_VARS for variables with regex characters"; then 803if test_case_begin "SUBST_VARS for variables with regex characters"; then
798 804
799 # Ensure that special regex characters like dots and parentheses 805 # Ensure that special regex characters like dots and parentheses
800 # may appear in variable names and are properly escaped. 806 # may appear in variable names and are properly escaped.
801 807
802 # Variable names containing a dollar are not supported. 808 # Variable names containing a dollar are not supported.
803 # Bmake behaves very surprisingly when a $ is expanded inside a :C 809 # Bmake behaves very surprisingly when a $ is expanded inside a :C
@@ -840,139 +846,137 @@ if test_case_begin "SUBST_VARS for varia @@ -840,139 +846,137 @@ if test_case_begin "SUBST_VARS for varia
840 1> "$tmpdir/stdout" \ 846 1> "$tmpdir/stdout" \
841 2> "$tmpdir/stderr" \ 847 2> "$tmpdir/stderr" \
842 && exitcode=0 || exitcode=$? 848 && exitcode=0 || exitcode=$?
843 849
844 assert_that "vars.txt" --file-is-lines \ 850 assert_that "vars.txt" --file-is-lines \
845 "dots" \ 851 "dots" \
846 "letters" \ 852 "letters" \
847 "parentheses" \ 853 "parentheses" \
848 "angle brackets" \ 854 "angle brackets" \
849 "square brackets" \ 855 "square brackets" \
850 '@VAR.$x@' \ 856 '@VAR.$x@' \
851 'circumflex' \ 857 'circumflex' \
852 'backslash' 858 'backslash'
853 assert_that "stdout" --file-is-lines \ 859 assert_that "$tmpdir/stdout" --file-is-lines \
854 "=> Substituting \"vars\" in vars.txt" 860 "=> Substituting \"vars\" in vars.txt"
855 assert_that "stderr" --file-is-empty 861 assert_that "$tmpdir/stderr" --file-is-empty
856 assert_that "$exitcode" --equals 0 862 assert_that "$exitcode" --equals 0
857 863
858 test_case_end 864 test_case_end
859fi 865fi
860 866
861if test_case_begin "pattern matches directory"; then 867if test_case_begin "pattern matches directory"; then
862 868
863 # When a pattern matches a directory, that directory is silently 869 # When a pattern matches a directory, that directory is silently
864 # skipped. 870 # skipped.
865 # 871 #
866 # In this test case, the pattern also matches a regular file that 872 # In this test case, the pattern also matches a regular file that
867 # is actually modified. Therefore the pattern has an effect, and 873 # is actually modified. Therefore the pattern has an effect, and
868 # there is no error message. 874 # there is no error message.
869 875
870 create_file_lines "testcase.mk" \ 876 create_file_lines "testcase.mk" \
871 'SUBST_CLASSES+= dir' \ 877 'SUBST_CLASSES+= dir' \
872 'SUBST_STAGE.dir= pre-configure' \ 878 'SUBST_STAGE.dir= pre-configure' \
873 'SUBST_FILES.dir= sub*' \ 879 'SUBST_FILES.dir= sub*' \
874 'SUBST_VARS.dir= VAR' \ 880 'SUBST_VARS.dir= VAR' \
875 'SUBST_NOOP_OK.dir= no' \ 881 'SUBST_NOOP_OK.dir= no' \
876 '' \ 882 '' \
877 'VAR= value' \ 883 'VAR= value' \
878 '' \ 884 '' \
879 '.include "prepare-subst.mk"' \ 885 '.include "prepare-subst.mk"' \
880 '.include "mk/subst.mk"' 886 '.include "mk/subst.mk"'
881 mkdir "$tmpdir/subdir" 
882 create_file_lines "subdir/subfile" \ 887 create_file_lines "subdir/subfile" \
883 "@VAR@" 888 "@VAR@"
884 create_file_lines "subst-file" \ 889 create_file_lines "subst-file" \
885 "@VAR@" 890 "@VAR@"
886 891
887 run_bmake "testcase.mk" "pre-configure" \ 892 run_bmake "testcase.mk" "pre-configure" \
888 1> "$tmpdir/stdout" \ 893 1> "$tmpdir/stdout" \
889 2> "$tmpdir/stderr" \ 894 2> "$tmpdir/stderr" \
890 && exitcode=0 || exitcode=$? 895 && exitcode=0 || exitcode=$?
891 896
892 assert_that "subst-file" --file-is-lines "value" 897 assert_that "subst-file" --file-is-lines "value"
893 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged 898 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged
894 assert_that "stdout" --file-is-lines \ 899 assert_that "$tmpdir/stdout" --file-is-lines \
895 "=> Substituting \"dir\" in sub*" 900 "=> Substituting \"dir\" in sub*"
896 assert_that "stderr" --file-is-empty 901 assert_that "$tmpdir/stderr" --file-is-empty
897 assert_that "$exitcode" --equals 0 902 assert_that "$exitcode" --equals 0
898 903
899 test_case_end 904 test_case_end
900fi 905fi
901 906
902 907
903if test_case_begin "pattern matches only directory"; then 908if test_case_begin "pattern matches only directory"; then
904 909
905 # When a pattern matches a directory, that directory is silently 910 # When a pattern matches a directory, that directory is silently
906 # skipped. 911 # skipped.
907 912
908 create_file_lines "testcase.mk" \ 913 create_file_lines "testcase.mk" \
909 'SUBST_CLASSES+= dir' \ 914 'SUBST_CLASSES+= dir' \
910 'SUBST_STAGE.dir= pre-configure' \ 915 'SUBST_STAGE.dir= pre-configure' \
911 'SUBST_FILES.dir= sub*' \ 916 'SUBST_FILES.dir= sub*' \
912 'SUBST_VARS.dir= VAR' \ 917 'SUBST_VARS.dir= VAR' \
913 'SUBST_NOOP_OK.dir= no' \ 918 'SUBST_NOOP_OK.dir= no' \
914 '' \ 919 '' \
915 'VAR= value' \ 920 'VAR= value' \
916 '' \ 921 '' \
917 '.include "prepare-subst.mk"' \ 922 '.include "prepare-subst.mk"' \
918 '.include "mk/subst.mk"' 923 '.include "mk/subst.mk"'
919 mkdir "$tmpdir/subdir" 
920 create_file_lines "subdir/subfile" \ 924 create_file_lines "subdir/subfile" \
921 "@VAR@" 925 "@VAR@"
922 926
923 run_bmake "testcase.mk" "pre-configure" \ 927 run_bmake "testcase.mk" "pre-configure" \
924 1> "$tmpdir/stdout" \ 928 1> "$tmpdir/stdout" \
925 2> "$tmpdir/stderr" \ 929 2> "$tmpdir/stderr" \
926 && exitcode=0 || exitcode=$? 930 && exitcode=0 || exitcode=$?
927 931
928 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged 932 assert_that "subdir/subfile" --file-is-lines "@VAR@" # unchanged
929 assert_that "stdout" --file-is-lines \ 933 assert_that "$tmpdir/stdout" --file-is-lines \
930 "=> Substituting \"dir\" in sub*" \ 934 "=> Substituting \"dir\" in sub*" \
931 'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \ 935 'fail: [subst.mk:dir] The filename pattern "sub*" has no effect.' \
932 "*** Error code 1" \ 936 "*** Error code 1" \
933 "" \ 937 "" \
934 "Stop." \ 938 "Stop." \
935 "$make: stopped in $PWD" 939 "$make: stopped in $PWD"
936 assert_that "stderr" --file-is-empty 940 assert_that "$tmpdir/stderr" --file-is-empty
937 assert_that "$exitcode" --equals 1 941 assert_that "$exitcode" --equals 1
938 942
939 test_case_end 943 test_case_end
940fi 944fi
941 945
942 946
943if test_case_begin "two filename patterns have no effect"; then 947if test_case_begin "two filename patterns have no effect"; then
944 948
945 # All patterns of SUBST_FILES should be applied before erroring out, 949 # All patterns of SUBST_FILES should be applied before erroring out,
946 # to give a complete picture of the situation. 950 # to give a complete picture of the situation.
947 951
948 create_file_lines "testcase.mk" \ 952 create_file_lines "testcase.mk" \
949 'SUBST_CLASSES+= id' \ 953 'SUBST_CLASSES+= id' \
950 'SUBST_STAGE.id= pre-configure' \ 954 'SUBST_STAGE.id= pre-configure' \
951 'SUBST_FILES.id= file1 file2' \ 955 'SUBST_FILES.id= file1 file2' \
952 'SUBST_VARS.id= A B' \ 956 'SUBST_VARS.id= A B' \
953 'SUBST_NOOP_OK.id= no' \ 957 'SUBST_NOOP_OK.id= no' \
954 'A= a-value' \ 958 'A= a-value' \
955 'B= b-value' \ 959 'B= b-value' \
956 '' \ 960 '' \
957 '.include "prepare-subst.mk"' \ 961 '.include "prepare-subst.mk"' \
958 '.include "mk/subst.mk"' 962 '.include "mk/subst.mk"'
959 create_file_lines "file1" "nothing to replace" 963 create_file_lines "file1" "nothing to replace"
960 create_file_lines "file2" "nothing to replace" 964 create_file_lines "file2" "nothing to replace"
961 965
962 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ 966 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
963 && exitcode=0 || exitcode=$? 967 && exitcode=0 || exitcode=$?
964 968
965 assert_that "out" --file-is-lines \ 969 assert_that "$tmpdir/output" --file-is-lines \
966 '=> Substituting "id" in file1 file2' \ 970 '=> Substituting "id" in file1 file2' \
967 'warning: [subst.mk:id] Nothing changed in "file1".' \ 971 'warning: [subst.mk:id] Nothing changed in "file1".' \
968 'warning: [subst.mk:id] Nothing changed in "file2".' \ 972 'warning: [subst.mk:id] Nothing changed in "file2".' \
969 'fail: [subst.mk:id] The filename patterns "file1 file2" have no effect.' \ 973 'fail: [subst.mk:id] The filename patterns "file1 file2" have no effect.' \
970 '*** Error code 1' \ 974 '*** Error code 1' \
971 '' \ 975 '' \
972 'Stop.' \ 976 'Stop.' \
973 "$make: stopped in $PWD" 977 "$make: stopped in $PWD"
974 978
975 test_case_end 979 test_case_end
976fi 980fi
977 981
978 982
@@ -984,56 +988,56 @@ if test_case_begin "empty SUBST_FILES";  @@ -984,56 +988,56 @@ if test_case_begin "empty SUBST_FILES";
984 create_file_lines "testcase.mk" \ 988 create_file_lines "testcase.mk" \
985 'SUBST_CLASSES+= id' \ 989 'SUBST_CLASSES+= id' \
986 'SUBST_STAGE.id= pre-configure' \ 990 'SUBST_STAGE.id= pre-configure' \
987 'SUBST_FILES.id= # none' \ 991 'SUBST_FILES.id= # none' \
988 'SUBST_SED.id= -e s,from,to,' \ 992 'SUBST_SED.id= -e s,from,to,' \
989 'SUBST_NOOP_OK.id= no' \ 993 'SUBST_NOOP_OK.id= no' \
990 '' \ 994 '' \
991 'all:' \ 995 'all:' \
992 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ 996 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \
993 '' \ 997 '' \
994 '.include "prepare-subst.mk"' \ 998 '.include "prepare-subst.mk"' \
995 '.include "mk/subst.mk"' 999 '.include "mk/subst.mk"'
996 1000
997 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ 1001 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
998 && exitcode=0 || exitcode=$? 1002 && exitcode=0 || exitcode=$?
999 1003
1000 assert_that "out" --file-is-lines \ 1004 assert_that "$tmpdir/output" --file-is-lines \
1001 '=> Substituting "id" in ' \ 1005 '=> Substituting "id" in ' \
1002 'ok' 1006 'ok'
1003 1007
1004 test_case_end 1008 test_case_end
1005fi 1009fi
1006 1010
1007 1011
1008if test_case_begin "empty SUBST_SED"; then 1012if test_case_begin "empty SUBST_SED"; then
1009 1013
1010 create_file_lines "testcase.mk" \ 1014 create_file_lines "testcase.mk" \
1011 'SUBST_CLASSES+= id' \ 1015 'SUBST_CLASSES+= id' \
1012 'SUBST_STAGE.id= pre-configure' \ 1016 'SUBST_STAGE.id= pre-configure' \
1013 'SUBST_FILES.id= file' \ 1017 'SUBST_FILES.id= file' \
1014 'SUBST_SED.id= # none' \ 1018 'SUBST_SED.id= # none' \
1015 'SUBST_NOOP_OK.id= no' \ 1019 'SUBST_NOOP_OK.id= no' \
1016 '' \ 1020 '' \
1017 'all:' \ 1021 'all:' \
1018 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ 1022 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \
1019 '' \ 1023 '' \
1020 '.include "prepare-subst.mk"' \ 1024 '.include "prepare-subst.mk"' \
1021 '.include "mk/subst.mk"' 1025 '.include "mk/subst.mk"'
1022 1026
1023 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ 1027 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
1024 && exitcode=0 || exitcode=$? 1028 && exitcode=0 || exitcode=$?
1025 1029
1026 assert_that "out" --file-is-lines \ 1030 assert_that "$tmpdir/output" --file-is-lines \
1027 '=> Substituting "id" in file' \ 1031 '=> Substituting "id" in file' \
1028 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \ 1032 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \
1029 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1033 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1030 '*** Error code 1' \ 1034 '*** Error code 1' \
1031 '' \ 1035 '' \
1032 'Stop.' \ 1036 'Stop.' \
1033 "$make: stopped in $PWD" 1037 "$make: stopped in $PWD"
1034 1038
1035 test_case_end 1039 test_case_end
1036fi 1040fi
1037 1041
1038 1042
1039if test_case_begin "typo in SUBST_CLASSES"; then 1043if test_case_begin "typo in SUBST_CLASSES"; then
@@ -1044,30 +1048,30 @@ if test_case_begin "typo in SUBST_CLASSE @@ -1044,30 +1048,30 @@ if test_case_begin "typo in SUBST_CLASSE
1044 create_file_lines "testcase.mk" \ 1048 create_file_lines "testcase.mk" \
1045 'SUBST_CLASSES=+ id' \ 1049 'SUBST_CLASSES=+ id' \
1046 'SUBST_STAGE.id= pre-configure' \ 1050 'SUBST_STAGE.id= pre-configure' \
1047 'SUBST_FILES.id= file' \ 1051 'SUBST_FILES.id= file' \
1048 'SUBST_SED.id= # none' \ 1052 'SUBST_SED.id= # none' \
1049 'SUBST_NOOP_OK.id= no' \ 1053 'SUBST_NOOP_OK.id= no' \
1050 '' \ 1054 '' \
1051 'all:' \ 1055 'all:' \
1052 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \ 1056 ' @printf "%s\n" ${PKG_FAIL_REASON:Uok}' \
1053 '' \ 1057 '' \
1054 '.include "prepare-subst.mk"' \ 1058 '.include "prepare-subst.mk"' \
1055 '.include "mk/subst.mk"' 1059 '.include "mk/subst.mk"'
1056 1060
1057 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/out" 2>&1 \ 1061 run_bmake "testcase.mk" "pre-configure" "all" 1> "$tmpdir/output" 2>&1 \
1058 && exitcode=0 || exitcode=$? 1062 && exitcode=0 || exitcode=$?
1059 1063
1060 assert_that "out" --file-is-lines \ 1064 assert_that "$tmpdir/output" --file-is-lines \
1061 '=> Substituting "id" in file' \ 1065 '=> Substituting "id" in file' \
1062 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \ 1066 'warning: [subst.mk:id] Ignoring nonexistent file "file".' \
1063 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1067 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1064 '*** Error code 1' \ 1068 '*** Error code 1' \
1065 '' \ 1069 '' \
1066 'Stop.' \ 1070 'Stop.' \
1067 "$make: stopped in $PWD" 1071 "$make: stopped in $PWD"
1068 1072
1069 test_case_end 1073 test_case_end
1070fi 1074fi
1071 1075
1072 1076
1073if test_case_begin "executable bit is preserved"; then 1077if test_case_begin "executable bit is preserved"; then
@@ -1075,62 +1079,62 @@ if test_case_begin "executable bit is pr @@ -1075,62 +1079,62 @@ if test_case_begin "executable bit is pr
1075 create_file_lines "testcase.mk" \ 1079 create_file_lines "testcase.mk" \
1076 'SUBST_CLASSES+= id' \ 1080 'SUBST_CLASSES+= id' \
1077 'SUBST_STAGE.id= pre-configure' \ 1081 'SUBST_STAGE.id= pre-configure' \
1078 'SUBST_FILES.id= cmd data' \ 1082 'SUBST_FILES.id= cmd data' \
1079 'SUBST_VARS.id= VAR' \ 1083 'SUBST_VARS.id= VAR' \
1080 'VAR= replaced' \ 1084 'VAR= replaced' \
1081 '' \ 1085 '' \
1082 '.include "prepare-subst.mk"' \ 1086 '.include "prepare-subst.mk"' \
1083 '.include "mk/subst.mk"' 1087 '.include "mk/subst.mk"'
1084 create_file_lines "cmd" \ 1088 create_file_lines "cmd" \
1085 '@VAR@' 1089 '@VAR@'
1086 create_file_lines "data" \ 1090 create_file_lines "data" \
1087 '@VAR@' 1091 '@VAR@'
1088 chmod +x "$tmpdir/cmd" 1092 chmod +x 'cmd'
1089 1093
1090 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ 1094 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
1091 && exitcode=0 || exitcode=$? 1095 && exitcode=0 || exitcode=$?
1092 1096
1093 assert_that "out" --file-is-lines \ 1097 assert_that "$tmpdir/output" --file-is-lines \
1094 '=> Substituting "id" in cmd data' 1098 '=> Substituting "id" in cmd data'
1095 assert_that "cmd" --file-is-lines "replaced" 1099 assert_that "cmd" --file-is-lines "replaced"
1096 assert_that "data" --file-is-lines "replaced" 1100 assert_that "data" --file-is-lines "replaced"
1097 [ -x "$tmpdir/cmd" ] \ 1101 [ -x 'cmd' ] \
1098 || assert_fail "cmd must still be executable" 1102 || assert_fail 'cmd must still be executable\n'
1099 [ -x "$tmpdir/data" ] \ 1103 [ -x 'data' ] \
1100 && assert_fail "data must not be executable" 1104 && assert_fail 'data must not be executable\n'
1101 1105
1102 test_case_end 1106 test_case_end
1103fi 1107fi
1104 1108
1105 1109
1106if test_case_begin "unreadable file"; then 1110if test_case_begin "unreadable file"; then
1107 1111
1108 create_file_lines "testcase.mk" \ 1112 create_file_lines "testcase.mk" \
1109 'SUBST_CLASSES+= id' \ 1113 'SUBST_CLASSES+= id' \
1110 'SUBST_STAGE.id= pre-configure' \ 1114 'SUBST_STAGE.id= pre-configure' \
1111 'SUBST_FILES.id= unreadable-file' \ 1115 'SUBST_FILES.id= unreadable-file' \
1112 'SUBST_SED.id= -e s,before,after,' \ 1116 'SUBST_SED.id= -e s,before,after,' \
1113 '' \ 1117 '' \
1114 '.include "prepare-subst.mk"' \ 1118 '.include "prepare-subst.mk"' \
1115 '.include "mk/subst.mk"' 1119 '.include "mk/subst.mk"'
1116 create_file_lines "unreadable-file" \ 1120 create_file_lines "unreadable-file" \
1117 'before' 1121 'before'
1118 chmod 0000 "$tmpdir/unreadable-file" 1122 chmod 0000 'unreadable-file'
1119 1123
1120 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/out" 2>&1 \ 1124 run_bmake "testcase.mk" "pre-configure" 1> "$tmpdir/output" 2>&1 \
1121 && exitcode=0 || exitcode=$? 1125 && exitcode=0 || exitcode=$?
1122 1126
1123 assert_that "out" --file-is-lines \ 1127 assert_that "$tmpdir/output" --file-is-lines \
1124 '=> Substituting "id" in unreadable-file' \ 1128 '=> Substituting "id" in unreadable-file' \
1125 'sh: cannot open unreadable-file: permission denied' \ 1129 'sh: cannot open unreadable-file: permission denied' \
1126 'sh: cannot open unreadable-file: permission denied' \ 1130 'sh: cannot open unreadable-file: permission denied' \
1127 '*** Error code 1' \ 1131 '*** Error code 1' \
1128 '' \ 1132 '' \
1129 'Stop.' \ 1133 'Stop.' \
1130 "$make: stopped in $PWD" 1134 "$make: stopped in $PWD"
1131 1135
1132 test_case_end 1136 test_case_end
1133fi 1137fi
1134 1138
1135 1139
1136if test_case_begin "identity substitution implementation"; then 1140if test_case_begin "identity substitution implementation"; then
@@ -1243,83 +1247,83 @@ if test_case_begin "identity substitutio @@ -1243,83 +1247,83 @@ if test_case_begin "identity substitutio
1243 create_file_lines "testcase.mk" \ 1247 create_file_lines "testcase.mk" \
1244 'SUBST_CLASSES+= id' \ 1248 'SUBST_CLASSES+= id' \
1245 'SUBST_FILES.id= file' \ 1249 'SUBST_FILES.id= file' \
1246 'SUBST_SED.id= -e s,before,before,' \ 1250 'SUBST_SED.id= -e s,before,before,' \
1247 'SUBST_SED.id+= -e "s,before,before,"' \ 1251 'SUBST_SED.id+= -e "s,before,before,"' \
1248 "SUBST_SED.id+= -e 's,before,before,'" \ 1252 "SUBST_SED.id+= -e 's,before,before,'" \
1249 'SUBST_NOOP_OK.id= no' \ 1253 'SUBST_NOOP_OK.id= no' \
1250 '' \ 1254 '' \
1251 '.include "prepare-subst.mk"' \ 1255 '.include "prepare-subst.mk"' \
1252 '.include "mk/subst.mk"' 1256 '.include "mk/subst.mk"'
1253 create_file_lines "file" \ 1257 create_file_lines "file" \
1254 'before' 1258 'before'
1255 1259
1256 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1260 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1257 && exitcode=0 || exitcode=$? 1261 && exitcode=0 || exitcode=$?
1258 1262
1259 assert_that "out" --file-is-lines \ 1263 assert_that "$tmpdir/output" --file-is-lines \
1260 '=> Substituting "id" in file' 1264 '=> Substituting "id" in file'
1261 1265
1262 test_case_end 1266 test_case_end
1263fi 1267fi
1264 1268
1265 1269
1266if test_case_begin "identity substitution, not found in file"; then 1270if test_case_begin "identity substitution, not found in file"; then
1267 1271
1268 create_file_lines "testcase.mk" \ 1272 create_file_lines "testcase.mk" \
1269 'SUBST_CLASSES+= id' \ 1273 'SUBST_CLASSES+= id' \
1270 'SUBST_FILES.id= file' \ 1274 'SUBST_FILES.id= file' \
1271 'SUBST_SED.id= s,before,before,' \ 1275 'SUBST_SED.id= s,before,before,' \
1272 'SUBST_NOOP_OK.id= no' \ 1276 'SUBST_NOOP_OK.id= no' \
1273 '' \ 1277 '' \
1274 '.include "prepare-subst.mk"' \ 1278 '.include "prepare-subst.mk"' \
1275 '.include "mk/subst.mk"' 1279 '.include "mk/subst.mk"'
1276 create_file_lines "file" \ 1280 create_file_lines "file" \
1277 'other' 1281 'other'
1278 1282
1279 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1283 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1280 && exitcode=0 || exitcode=$? 1284 && exitcode=0 || exitcode=$?
1281 1285
1282 assert_that "out" --file-is-lines \ 1286 assert_that "$tmpdir/output" --file-is-lines \
1283 '=> Substituting "id" in file' \ 1287 '=> Substituting "id" in file' \
1284 'warning: [subst.mk:id] Nothing changed in "file".' \ 1288 'warning: [subst.mk:id] Nothing changed in "file".' \
1285 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1289 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1286 '*** Error code 1' \ 1290 '*** Error code 1' \
1287 '' \ 1291 '' \
1288 'Stop.' \ 1292 'Stop.' \
1289 "$make: stopped in $PWD" 1293 "$make: stopped in $PWD"
1290 1294
1291 test_case_end 1295 test_case_end
1292fi 1296fi
1293 1297
1294 1298
1295if test_case_begin "identity + effective substitution"; then 1299if test_case_begin "identity + effective substitution"; then
1296 1300
1297 create_file_lines "testcase.mk" \ 1301 create_file_lines "testcase.mk" \
1298 'SUBST_CLASSES+= id' \ 1302 'SUBST_CLASSES+= id' \
1299 'SUBST_FILES.id= file' \ 1303 'SUBST_FILES.id= file' \
1300 'SUBST_SED.id= -e s,no-op,no-op,g' \ 1304 'SUBST_SED.id= -e s,no-op,no-op,g' \
1301 'SUBST_SED.id+= -e s,from,to,' \ 1305 'SUBST_SED.id+= -e s,from,to,' \
1302 'SUBST_NOOP_OK.id= no' \ 1306 'SUBST_NOOP_OK.id= no' \
1303 '' \ 1307 '' \
1304 '.include "prepare-subst.mk"' \ 1308 '.include "prepare-subst.mk"' \
1305 '.include "mk/subst.mk"' 1309 '.include "mk/subst.mk"'
1306 create_file_lines "file" \ 1310 create_file_lines "file" \
1307 'from' 1311 'from'
1308 1312
1309 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1313 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1310 && exitcode=0 || exitcode=$? 1314 && exitcode=0 || exitcode=$?
1311 1315
1312 assert_that "out" --file-is-lines \ 1316 assert_that "$tmpdir/output" --file-is-lines \
1313 '=> Substituting "id" in file' 1317 '=> Substituting "id" in file'
1314 assert_that "file" --file-is-lines \ 1318 assert_that "file" --file-is-lines \
1315 'to' 1319 'to'
1316 1320
1317 test_case_end 1321 test_case_end
1318fi 1322fi
1319 1323
1320 1324
1321if test_case_begin "identity + no-op substitution"; then 1325if test_case_begin "identity + no-op substitution"; then
1322 1326
1323 # If there were only an identity substitution, it wouldn't be an 1327 # If there were only an identity substitution, it wouldn't be an
1324 # error. But since there is a regular substitution as well, 1328 # error. But since there is a regular substitution as well,
1325 # that substitution is an unexpected no-op and is therefore 1329 # that substitution is an unexpected no-op and is therefore
@@ -1327,30 +1331,30 @@ if test_case_begin "identity + no-op sub @@ -1327,30 +1331,30 @@ if test_case_begin "identity + no-op sub
1327 1331
1328 create_file_lines "testcase.mk" \ 1332 create_file_lines "testcase.mk" \
1329 'SUBST_CLASSES+= id' \ 1333 'SUBST_CLASSES+= id' \
1330 'SUBST_FILES.id= file' \ 1334 'SUBST_FILES.id= file' \
1331 'SUBST_SED.id= -e s,no-op,no-op,g' \ 1335 'SUBST_SED.id= -e s,no-op,no-op,g' \
1332 'SUBST_SED.id+= -e s,from,to,' \ 1336 'SUBST_SED.id+= -e s,from,to,' \
1333 'SUBST_NOOP_OK.id= no' \ 1337 'SUBST_NOOP_OK.id= no' \
1334 '' \ 1338 '' \
1335 '.include "prepare-subst.mk"' \ 1339 '.include "prepare-subst.mk"' \
1336 '.include "mk/subst.mk"' 1340 '.include "mk/subst.mk"'
1337 create_file_lines "file" \ 1341 create_file_lines "file" \
1338 'other' 1342 'other'
1339 1343
1340 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1344 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1341 && exitcode=0 || exitcode=$? 1345 && exitcode=0 || exitcode=$?
1342 1346
1343 assert_that "out" --file-is-lines \ 1347 assert_that "$tmpdir/output" --file-is-lines \
1344 '=> Substituting "id" in file' \ 1348 '=> Substituting "id" in file' \
1345 'warning: [subst.mk:id] Nothing changed in "file".' \ 1349 'warning: [subst.mk:id] Nothing changed in "file".' \
1346 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1350 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1347 '*** Error code 1' \ 1351 '*** Error code 1' \
1348 '' \ 1352 '' \
1349 'Stop.' \ 1353 'Stop.' \
1350 "$make: stopped in $PWD" 1354 "$make: stopped in $PWD"
1351 assert_that "file" --file-is-lines \ 1355 assert_that "file" --file-is-lines \
1352 'other' 1356 'other'
1353 1357
1354 test_case_end 1358 test_case_end
1355fi 1359fi
1356 1360
@@ -1362,90 +1366,90 @@ if test_case_begin "SUBST_FILTER_CMD + S @@ -1362,90 +1366,90 @@ if test_case_begin "SUBST_FILTER_CMD + S
1362 # redundant variable definitions, this case fails fast. 1366 # redundant variable definitions, this case fails fast.
1363 1367
1364 create_file_lines "testcase.mk" \ 1368 create_file_lines "testcase.mk" \
1365 'SUBST_CLASSES+= id' \ 1369 'SUBST_CLASSES+= id' \
1366 'SUBST_FILES.id= file' \ 1370 'SUBST_FILES.id= file' \
1367 'SUBST_FILTER_CMD.id= tr -d "0-9"' \ 1371 'SUBST_FILTER_CMD.id= tr -d "0-9"' \
1368 'SUBST_SED.id= -e s,x,x,' \ 1372 'SUBST_SED.id= -e s,x,x,' \
1369 'SUBST_NOOP_OK.id= no' \ 1373 'SUBST_NOOP_OK.id= no' \
1370 '' \ 1374 '' \
1371 '.include "prepare-subst.mk"' \ 1375 '.include "prepare-subst.mk"' \
1372 '.include "mk/subst.mk"' 1376 '.include "mk/subst.mk"'
1373 create_file_lines "file" \ 1377 create_file_lines "file" \
1374 'letters 123 letters' 1378 'letters 123 letters'
1375 create_file_lines "main.mk" \ 1379 create_file_lines "$tmpdir/main.mk" \
1376 "PKGSRCDIR= $pkgsrcdir" \ 1380 "PKGSRCDIR= $pkgsrcdir" \
1377 ".PATH: $mocked_pkgsrcdir" \ 1381 ".PATH: $mocked_pkgsrcdir" \
1378 ".PATH: $pkgsrcdir" \ 1382 ".PATH: $pkgsrcdir" \
1379 ".include \"testcase.mk\"" \ 1383 ".include \"testcase.mk\"" \
1380 '' \ 1384 '' \
1381 'all: subst-id' \ 1385 'all: subst-id' \
1382 ' @printf '\''fail reason: %s\n'\'' ${PKG_FAIL_REASON} 1>&2' 1386 ' @printf '\''fail reason: %s\n'\'' ${PKG_FAIL_REASON} 1>&2'
1383 1387
1384 "$make" -f "$tmpdir/main.mk" "all" 1> "$tmpdir/out" 2>&1 \ 1388 "$make" -f "$tmpdir/main.mk" "all" 1> "$tmpdir/output" 2>&1 \
1385 && exitcode=0 || exitcode=$? 1389 && exitcode=0 || exitcode=$?
1386 1390
1387 assert_that "out" --file-is-lines \ 1391 assert_that "$tmpdir/output" --file-is-lines \
1388 '=> Substituting "id" in file' \ 1392 '=> Substituting "id" in file' \
1389 'fail reason: [subst.mk:id] SUBST_FILTER_CMD and SUBST_SED/SUBST_VARS cannot be combined.' 1393 'fail reason: [subst.mk:id] SUBST_FILTER_CMD and SUBST_SED/SUBST_VARS cannot be combined.'
1390 assert_that "file" --file-is-lines \ 1394 assert_that "file" --file-is-lines \
1391 'letters letters' 1395 'letters letters'
1392 1396
1393 test_case_end 1397 test_case_end
1394fi 1398fi
1395 1399
1396 1400
1397if test_case_begin "effective SUBST_FILTER_CMD in NOOP_OK=no mode"; then 1401if test_case_begin "effective SUBST_FILTER_CMD in NOOP_OK=no mode"; then
1398 1402
1399 create_file_lines "testcase.mk" \ 1403 create_file_lines "testcase.mk" \
1400 'SUBST_CLASSES+= id' \ 1404 'SUBST_CLASSES+= id' \
1401 'SUBST_FILES.id= file' \ 1405 'SUBST_FILES.id= file' \
1402 'SUBST_FILTER_CMD.id= tr -d "0-9"' \ 1406 'SUBST_FILTER_CMD.id= tr -d "0-9"' \
1403 'SUBST_NOOP_OK.id= no' \ 1407 'SUBST_NOOP_OK.id= no' \
1404 '' \ 1408 '' \
1405 '.include "prepare-subst.mk"' \ 1409 '.include "prepare-subst.mk"' \
1406 '.include "mk/subst.mk"' 1410 '.include "mk/subst.mk"'
1407 create_file_lines "file" \ 1411 create_file_lines "file" \
1408 'letters 123 letters' 1412 'letters 123 letters'
1409 1413
1410 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1414 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1411 && exitcode=0 || exitcode=$? 1415 && exitcode=0 || exitcode=$?
1412 1416
1413 assert_that "out" --file-is-lines \ 1417 assert_that "$tmpdir/output" --file-is-lines \
1414 '=> Substituting "id" in file' 1418 '=> Substituting "id" in file'
1415 assert_that "file" --file-is-lines \ 1419 assert_that "file" --file-is-lines \
1416 'letters letters' 1420 'letters letters'
1417 1421
1418 test_case_end 1422 test_case_end
1419fi 1423fi
1420 1424
1421 1425
1422if test_case_begin "no-op SUBST_FILTER_CMD in NOOP_OK=no mode"; then 1426if test_case_begin "no-op SUBST_FILTER_CMD in NOOP_OK=no mode"; then
1423 1427
1424 create_file_lines "testcase.mk" \ 1428 create_file_lines "testcase.mk" \
1425 'SUBST_CLASSES+= id' \ 1429 'SUBST_CLASSES+= id' \
1426 'SUBST_FILES.id= file' \ 1430 'SUBST_FILES.id= file' \
1427 'SUBST_FILTER_CMD.id= tr -d "0-9"' \ 1431 'SUBST_FILTER_CMD.id= tr -d "0-9"' \
1428 'SUBST_NOOP_OK.id= no' \ 1432 'SUBST_NOOP_OK.id= no' \
1429 '' \ 1433 '' \
1430 '.include "prepare-subst.mk"' \ 1434 '.include "prepare-subst.mk"' \
1431 '.include "mk/subst.mk"' 1435 '.include "mk/subst.mk"'
1432 create_file_lines "file" \ 1436 create_file_lines "file" \
1433 'only letters' 1437 'only letters'
1434 1438
1435 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1439 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1436 && exitcode=0 || exitcode=$? 1440 && exitcode=0 || exitcode=$?
1437 1441
1438 assert_that "out" --file-is-lines \ 1442 assert_that "$tmpdir/output" --file-is-lines \
1439 '=> Substituting "id" in file' \ 1443 '=> Substituting "id" in file' \
1440 'warning: [subst.mk:id] Nothing changed in "file".' \ 1444 'warning: [subst.mk:id] Nothing changed in "file".' \
1441 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1445 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1442 '*** Error code 1' \ 1446 '*** Error code 1' \
1443 '' \ 1447 '' \
1444 'Stop.' \ 1448 'Stop.' \
1445 "$make: stopped in $PWD" 1449 "$make: stopped in $PWD"
1446 1450
1447 assert_that "file" --file-is-lines \ 1451 assert_that "file" --file-is-lines \
1448 'only letters' 1452 'only letters'
1449 1453
1450 test_case_end 1454 test_case_end
1451fi 1455fi
@@ -1453,55 +1457,55 @@ fi @@ -1453,55 +1457,55 @@ fi
1453 1457
1454if test_case_begin "backtick in SUBST_SED"; then 1458if test_case_begin "backtick in SUBST_SED"; then
1455 1459
1456 create_file_lines "testcase.mk" \ 1460 create_file_lines "testcase.mk" \
1457 'SUBST_CLASSES+= id' \ 1461 'SUBST_CLASSES+= id' \
1458 'SUBST_FILES.id= file' \ 1462 'SUBST_FILES.id= file' \
1459 "SUBST_SED.id= -e 's,\"\\\\\`,\"\\\\\`,'" \ 1463 "SUBST_SED.id= -e 's,\"\\\\\`,\"\\\\\`,'" \
1460 '' \ 1464 '' \
1461 '.include "prepare-subst.mk"' \ 1465 '.include "prepare-subst.mk"' \
1462 '.include "mk/subst.mk"' 1466 '.include "mk/subst.mk"'
1463 create_file_lines "file" \ 1467 create_file_lines "file" \
1464 'from`' 1468 'from`'
1465 1469
1466 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1470 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1467 && exitcode=0 || exitcode=$? 1471 && exitcode=0 || exitcode=$?
1468 1472
1469 assert_that "out" --file-is-lines \ 1473 assert_that "$tmpdir/output" --file-is-lines \
1470 '=> Substituting "id" in file' \ 1474 '=> Substituting "id" in file' \
1471 'info: [subst.mk:id] Nothing changed in "file".' 1475 'info: [subst.mk:id] Nothing changed in "file".'
1472 1476
1473 test_case_end 1477 test_case_end
1474fi 1478fi
1475 1479
1476 1480
1477if test_case_begin "multiple sed commands with semicolon"; then 1481if test_case_begin "multiple sed commands with semicolon"; then
1478 1482
1479 # From PR pkg/55226: 1483 # From PR pkg/55226:
1480 # ===> Configuring for perl-5.30.2 1484 # ===> Configuring for perl-5.30.2
1481 # sh: 1: Syntax error: Word "/d"p" unexpected (expecting ")") 1485 # sh: 1: Syntax error: Word "/d"p" unexpected (expecting ")")
1482 1486
1483 create_file_lines "testcase.mk" \ 1487 create_file_lines "testcase.mk" \
1484 'SUBST_CLASSES+= id' \ 1488 'SUBST_CLASSES+= id' \
1485 'SUBST_FILES.id= file' \ 1489 'SUBST_FILES.id= file' \
1486 'SUBST_SED.id= -e "s/755/755/g;/umask(/d"' \ 1490 'SUBST_SED.id= -e "s/755/755/g;/umask(/d"' \
1487 'SUBST_NOOP_OK.id= no' \ 1491 'SUBST_NOOP_OK.id= no' \
1488 '' \ 1492 '' \
1489 '.include "prepare-subst.mk"' \ 1493 '.include "prepare-subst.mk"' \
1490 '.include "mk/subst.mk"' 1494 '.include "mk/subst.mk"'
1491 create_file_lines "file" \ 1495 create_file_lines "file" \
1492 '$mode = 755;' 1496 '$mode = 755;'
1493 1497
1494 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/out" 2>&1 \ 1498 run_bmake "testcase.mk" "subst-id" 1> "$tmpdir/output" 2>&1 \
1495 && exitcode=0 || exitcode=$? 1499 && exitcode=0 || exitcode=$?
1496 1500
1497 assert_that "out" --file-is-lines \ 1501 assert_that "$tmpdir/output" --file-is-lines \
1498 '=> Substituting "id" in file' \ 1502 '=> Substituting "id" in file' \
1499 'warning: [subst.mk:id] Nothing changed in "file".' \ 1503 'warning: [subst.mk:id] Nothing changed in "file".' \
1500 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \ 1504 'fail: [subst.mk:id] The filename pattern "file" has no effect.' \
1501 '*** Error code 1' \ 1505 '*** Error code 1' \
1502 '' \ 1506 '' \
1503 'Stop.' \ 1507 'Stop.' \
1504 "$make: stopped in $PWD" 1508 "$make: stopped in $PWD"
1505 1509
1506 test_case_end 1510 test_case_end
1507fi 1511fi

cvs diff -r1.13 -r1.14 pkgsrc/regress/infra-unittests/test.subr (expand / switch to unified diff)

--- pkgsrc/regress/infra-unittests/test.subr 2020/05/09 17:41:08 1.13
+++ pkgsrc/regress/infra-unittests/test.subr 2020/05/11 19:13:10 1.14
@@ -1,47 +1,50 @@ @@ -1,47 +1,50 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: test.subr,v 1.13 2020/05/09 17:41:08 rillig Exp $ 2# $NetBSD: test.subr,v 1.14 2020/05/11 19:13:10 rillig Exp $
3# 3#
4# This file defines utilities for testing Makefile fragments and shell 4# This file defines utilities for testing Makefile fragments and shell
5# programs from the pkgsrc infrastructure. While testing one part of the 5# programs from the pkgsrc infrastructure. While testing one part of the
6# infrastructure, other parts can be mocked away. 6# infrastructure, other parts can be mocked away.
7# 7#
8# A test case is defined by the following functions: 8# A test case is defined by the following functions:
9# 9#
10# test_case_begin 10# test_case_begin
11# test_case_set_up 11# test_case_set_up
12# test_case_tear_down 12# test_case_tear_down
13# test_case_end 13# test_case_end
14# 14#
15# These functions form the structure for a test. To define a test, use the 15# These functions form the structure for a test. To define a test, use the
16# following pattern: 16# following pattern:
17# 17#
18# if test_case_begin "description of the test"; then 18# if test_case_begin "description of the test"; then
19# ... 19# ...
20# test_end 20# test_case_end
21# fi 21# fi
22# 22#
23# The functions test_case_set_up and test_case_tear_down can be defined in the 23# The functions test_case_set_up and test_case_tear_down can be defined in the
24# test file to provide a test fixture that is common to all test cases. These 24# test file to provide a test fixture that is common to all test cases. These
25# functions are called by test_case_begin and test_case_end, respectively. 25# functions are called by test_case_begin and test_case_end, respectively.
26# 26#
27# During a test case, the following variables are defined: 27# During a test case, the following variables are defined:
28# 28#
29# tmpdir a directory for creating intermediate files 29# tmpdir
30# pkgsrcdir the real pkgsrc directory 30# a directory for creating intermediate files
31# mocked_pkgsrcdir 31#
32# the directory where the mock files are installed, 32# pkgsrcdir
33# which override the Makefile fragments from the real 33# the real pkgsrc directory
34# pkgsrc infrastructure 34#
 35# mocked_pkgsrcdir
 36# the directory where the mock files are installed, which override
 37# the Makefile fragments from the real pkgsrc infrastructure
35# 38#
36# 39#
37# Setting up a test 40# Setting up a test
38# 41#
39# mock_cmd 42# mock_cmd
40# Returns the path to a newly created shell program whose behavior 43# Returns the path to a newly created shell program whose behavior
41# (output and exit status) is specified by pairs of 44# (output and exit status) is specified by pairs of
42# --when-args/--then-output or --when-args/--then-exit. 45# --when-args/--then-output or --when-args/--then-exit.
43# 46#
44# Example: 47# Example:
45# 48#
46# hello=$(mock_cmd mock-hello \ 49# hello=$(mock_cmd mock-hello \
47# --when-args "" --then-output "Hello, world!" \ 50# --when-args "" --then-output "Hello, world!" \
@@ -150,26 +153,31 @@ verbose_printf() { @@ -150,26 +153,31 @@ verbose_printf() {
150 153
151test_case_name="unknown test" 154test_case_name="unknown test"
152test_case_begun=0 155test_case_begun=0
153test_case_ended=0 156test_case_ended=0
154 157
155test_case_begin() { 158test_case_begin() {
156 test_case_name="$1" 159 test_case_name="$1"
157 [ "$(expr "$test_case_name" : "$test_case_filter")" -gt 0 ] \ 160 [ "$(expr "$test_case_name" : "$test_case_filter")" -gt 0 ] \
158 || return 1 161 || return 1
159 162
160 test_case_begun="`expr "$test_case_begun" + 1`" 163 test_case_begun="`expr "$test_case_begun" + 1`"
161 verbose_printf 'running test case "%s"\n' "$test_case_name" 164 verbose_printf 'running test case "%s"\n' "$test_case_name"
162 165
 166 cd "$tmpdir" || exit 1
 167 rm -rf 'work'
 168 mkdir 'work' || exit 1
 169 cd 'work' || exit 1
 170
163 test_case_set_up 171 test_case_set_up
164} 172}
165 173
166# Can be redefined by actual tests. 174# Can be redefined by actual tests.
167test_case_set_up() { 175test_case_set_up() {
168 : 176 :
169} 177}
170 178
171# Can be redefined by actual tests. 179# Can be redefined by actual tests.
172test_case_tear_down() { 180test_case_tear_down() {
173 : 181 :
174} 182}
175 183
@@ -233,38 +241,38 @@ EOF @@ -233,38 +241,38 @@ EOF
233 done 241 done
234 cat <<EOF 242 cat <<EOF
235printf 'error: %s: no mock behavior defined for arguments "%s"\n' "\$0" "\$*" 1>&2 243printf 'error: %s: no mock behavior defined for arguments "%s"\n' "\$0" "\$*" 1>&2
236exit 1 244exit 1
237EOF 245EOF
238 } > "$tmpdir/$cmdname" 246 } > "$tmpdir/$cmdname"
239 chmod +x "$tmpdir/$cmdname" 247 chmod +x "$tmpdir/$cmdname"
240 248
241 printf '%s\n' "$tmpdir/$cmdname" 249 printf '%s\n' "$tmpdir/$cmdname"
242} 250}
243 251
244create_file() { 252create_file() {
245 assert_that "$#" --equals 1 253 assert_that "$#" --equals 1
246 mkdir -p "$(dirname "$tmpdir/$1")" 254 mkdir -p "$(dirname -- "$1")"
247 cat > "$tmpdir/$1" 255 cat > "$1"
248} 256}
249 257
250create_file_lines() { 258create_file_lines() {
251 mkdir -p "$(dirname "$tmpdir/$1")" 
252 _cfl_filename="$1"; shift 259 _cfl_filename="$1"; shift
253 printf '%s\n' "$@" > "$tmpdir/$_cfl_filename" 260 mkdir -p "$(dirname -- "$_cfl_filename")"
 261 printf '%s\n' "$@" > "$_cfl_filename"
254} 262}
255 263
256create_pkgsrc_file() { 264create_pkgsrc_file() {
257 mkdir -p "$(dirname "$mocked_pkgsrcdir/$1")" 265 mkdir -p "$(dirname -- "$mocked_pkgsrcdir/$1")"
258 cat > "$mocked_pkgsrcdir/$1" 266 cat > "$mocked_pkgsrcdir/$1"
259} 267}
260 268
261run_bmake() { 269run_bmake() {
262 cat <<EOF > "$tmpdir/test.subr.main.mk" 270 cat <<EOF > "$tmpdir/test.subr.main.mk"
263PKGSRCDIR= $pkgsrcdir 271PKGSRCDIR= $pkgsrcdir
264.PATH: $mocked_pkgsrcdir 272.PATH: $mocked_pkgsrcdir
265.PATH: $pkgsrcdir 273.PATH: $pkgsrcdir
266.include "$1" 274.include "$1"
267EOF 275EOF
268 shift 276 shift
269 277
270 "$make" -f "$tmpdir/test.subr.main.mk" "$@" 278 "$make" -f "$tmpdir/test.subr.main.mk" "$@"
@@ -279,80 +287,78 @@ assert_succeed() { @@ -279,80 +287,78 @@ assert_succeed() {
279} 287}
280 288
281assert_fail() { 289assert_fail() {
282 printf '%s' "$assert_fail_sep" 1>&2 290 printf '%s' "$assert_fail_sep" 1>&2
283 assert_fail_sep=' 291 assert_fail_sep='
284' 292'
285 293
286 printf 'assertion failed in "%s": ' "$test_case_name" 1>&2 294 printf 'assertion failed in "%s": ' "$test_case_name" 1>&2
287 295
288 printf "$@" 1>&2 296 printf "$@" 1>&2
289 assert_failed=`expr "$assert_failed" + 1` 297 assert_failed=`expr "$assert_failed" + 1`
290} 298}
291 299
292tmpdir_equal() { 300files_equal() {
293 (cd "$tmpdir" && diff -u -- "$@" >/dev/null) || return 1 301 (diff -u -- "$@" >/dev/null) || return 1
294} 302}
295 303
296tmpdir_diff() { 304diff_without_timestamps() {
297 # removes the timestamps from the diff files since these are not 305 (diff -u -- "$@" || true) \
298 # useful in tests. 
299 (cd "$tmpdir" && diff -u -- "$@" || true) \ 
300 | awk '/^(---|[+][+][+]) / { print($1, $2); next } { print }' 1>&2 306 | awk '/^(---|[+][+][+]) / { print($1, $2); next } { print }' 1>&2
301} 307}
302 308
303assert_that() { 309assert_that() {
304 case "$2" in 310 case "$2" in
305 (--equals) 311 (--equals)
306 if [ "x$1" = "x$3" ]; then 312 if [ "x$1" = "x$3" ]; then
307 assert_succeed 313 assert_succeed
308 return 0 314 return 0
309 fi 315 fi
310 assert_fail '\n expected: <%s>\n but was: <%s>\n' "$3" "$1" 316 assert_fail '\n expected: <%s>\n but was: <%s>\n' "$3" "$1"
311 ;; 317 ;;
312 318
313 (--file-contains-exactly) 319 (--file-contains-exactly)
314 printf '%s\n' "$3" > "$tmpdir/expected" 320 printf '%s\n' "$3" > "$tmpdir/expected"
315 if tmpdir_equal "expected" "$1"; then 321 if files_equal "$tmpdir/expected" "$1"; then
316 assert_succeed 322 assert_succeed
317 return 0 323 return 0
318 fi 324 fi
319 assert_fail 'file "%s" has unexpected content:\n' "$1" 325 assert_fail 'file "%s" has unexpected content:\n' "$1"
320 tmpdir_diff "expected" "$1" 326 diff_without_timestamps "$tmpdir/expected" "$1"
321 ;; 327 ;;
322 328
323 (--file-equals) 329 (--file-equals)
324 if tmpdir_equal "$3" "$1"; then 330 if files_equal "$3" "$1"; then
325 assert_succeed 331 assert_succeed
326 return 0 332 return 0
327 fi 333 fi
328 assert_fail 'files "%s" and "%s" differ:\n' "$1" "$3" 334 assert_fail 'files "%s" and "%s" differ:\n' "$1" "$3"
329 tmpdir_diff "$3" "$1" 335 diff_without_timestamps "$3" "$1"
330 ;; 336 ;;
331 337
332 (--file-is-empty) 338 (--file-is-empty)
333 if tmpdir_equal "/dev/null" "$1"; then 339 if files_equal "/dev/null" "$1"; then
334 assert_succeed 340 assert_succeed
335 return 0 341 return 0
336 fi 342 fi
337 assert_fail 'file "%s" is not empty:\n' "$1" 343 assert_fail 'file "%s" is not empty:\n' "$1"
338 tmpdir_diff "/dev/null" "$1" 344 diff_without_timestamps "/dev/null" "$1"
339 ;; 345 ;;
340 346
341 (--file-is-lines) 347 (--file-is-lines)
342 _assert_that_tmp_actual="$1" 348 _assert_that_tmp_actual="$1"
343 _assert_that_filename="$1"; shift 2 349 _assert_that_filename="$1"; shift 2
344 350
345 printf '%s\n' "$@" > "$tmpdir/expected" 351 printf '%s\n' "$@" > "$tmpdir/expected"
346 if tmpdir_equal "expected" "$_assert_that_tmp_actual"; then 352 if files_equal "$tmpdir/expected" "$_assert_that_tmp_actual"; then
347 assert_succeed 353 assert_succeed
348 return 0 354 return 0
349 fi 355 fi
350 assert_fail 'file "%s" has unexpected content:\n' "$_assert_that_filename" 356 assert_fail 'file "%s" has unexpected content:\n' "$_assert_that_filename"
351 tmpdir_diff "expected" "$_assert_that_tmp_actual" 357 diff_without_timestamps "$tmpdir/expected" "$_assert_that_tmp_actual"
352 ;; 358 ;;
353 359
354 (*) 360 (*)
355 printf 'usage: assert_that <expr> --equals <expr>\n' 1>&2 361 printf 'usage: assert_that <expr> --equals <expr>\n' 1>&2
356 exit 1 362 exit 1
357 esac 363 esac
358} 364}