| @@ -1,24 +1,24 @@ | | | @@ -1,24 +1,24 @@ |
1 | #! /bin/sh | | 1 | #! /bin/sh |
2 | # $NetBSD: check-portability.sh,v 1.5 2020/05/11 19:13:10 rillig Exp $ | | 2 | # $NetBSD: check-portability.sh,v 1.6 2021/01/04 21:07:31 rillig Exp $ |
3 | # | | 3 | # |
4 | # Test cases for mk/check/check-portability.*. | | 4 | # Test cases for mk/check/check-portability.*. |
5 | # | | 5 | # |
6 | | | 6 | |
7 | set -eu | | 7 | set -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 all files in the current directory. |
12 | check_portability_sh() { | | 12 | check_portability_sh() { |
13 | env PATCHDIR='patches' \ | | 13 | env PATCHDIR='patches' \ |
14 | PREFIX='/nonexistent' \ | | 14 | PREFIX='/nonexistent' \ |
15 | "$@" \ | | 15 | "$@" \ |
16 | sh "$pkgsrcdir/mk/check/check-portability.sh" \ | | 16 | sh "$pkgsrcdir/mk/check/check-portability.sh" \ |
17 | 1>"$tmpdir/out" 2>&1 \ | | 17 | 1>"$tmpdir/out" 2>&1 \ |
18 | && exitcode=0 || exitcode=$? | | 18 | && exitcode=0 || exitcode=$? |
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. |
22 | check_portability_awk() { | | 22 | check_portability_awk() { |
23 | env CK_FNAME="$1" \ | | 23 | env CK_FNAME="$1" \ |
24 | CK_PROGNAME='check-portability.awk' \ | | 24 | CK_PROGNAME='check-portability.awk' \ |
| @@ -235,13 +235,60 @@ fi | | | @@ -235,13 +235,60 @@ fi |
235 | if test_case_begin 'no experimental by default'; then | | 235 | if test_case_begin 'no experimental by default'; then |
236 | | | 236 | |
237 | create_file_lines 'configure.in' \ | | 237 | create_file_lines 'configure.in' \ |
238 | 'test a == b' | | 238 | 'test a == b' |
239 | | | 239 | |
240 | check_portability_sh \ | | 240 | check_portability_sh \ |
241 | 'CHECK_PORTABILITY_EXPERIMENTAL=no' | | 241 | 'CHECK_PORTABILITY_EXPERIMENTAL=no' |
242 | | | 242 | |
243 | assert_that "$tmpdir/out" --file-is-empty | | 243 | assert_that "$tmpdir/out" --file-is-empty |
244 | assert_that $exitcode --equals 0 | | 244 | assert_that $exitcode --equals 0 |
245 | | | 245 | |
246 | test_case_end | | 246 | test_case_end |
247 | fi | | 247 | fi |
| | | 248 | |
| | | 249 | |
| | | 250 | if test_case_begin 'always skip tilde files'; then |
| | | 251 | |
| | | 252 | |
| | | 253 | # Projects that use GNU autoconf 2.70 are reported to include |
| | | 254 | # backup files like 'configure~' in their distribution, for |
| | | 255 | # whatever reason. Since these files are not used by pkgsrc, |
| | | 256 | # they should be ignored. |
| | | 257 | # |
| | | 258 | # Since the filename is not one of the well-known ones, the file |
| | | 259 | # must start with a '#!' line to be actually recognized as a shell |
| | | 260 | # program. |
| | | 261 | create_file_lines 'configure~' \ |
| | | 262 | '#! /bin/sh' \ |
| | | 263 | 'test a == b' |
| | | 264 | |
| | | 265 | check_portability_sh \ |
| | | 266 | 'CHECK_PORTABILITY_EXPERIMENTAL=no' |
| | | 267 | |
| | | 268 | create_file 'expected' <<'EOF' |
| | | 269 | ERROR: [check-portability.awk] => Found test ... == ...: |
| | | 270 | ERROR: [check-portability.awk] configure~:2: test a == b |
| | | 271 | |
| | | 272 | Explanation: |
| | | 273 | =========================================================================== |
| | | 274 | The "test" command, as well as the "[" command, are not required to know |
| | | 275 | the "==" operator. Only a few implementations like bash and some |
| | | 276 | versions of ksh support it. |
| | | 277 | |
| | | 278 | When you run "test foo == foo" on a platform that does not support the |
| | | 279 | "==" operator, the result will be "false" instead of "true". This can |
| | | 280 | lead to unexpected behavior. |
| | | 281 | |
| | | 282 | There are two ways to fix this error message. If the file that contains |
| | | 283 | the "test ==" is needed for building the package, you should create a |
| | | 284 | patch for it, replacing the "==" operator with "=". If the file is not |
| | | 285 | needed, add its name to the CHECK_PORTABILITY_SKIP variable in the |
| | | 286 | package Makefile. |
| | | 287 | =========================================================================== |
| | | 288 | |
| | | 289 | EOF |
| | | 290 | assert_that "$tmpdir/out" --file-equals 'expected' |
| | | 291 | assert_that $exitcode --equals 1 |
| | | 292 | |
| | | 293 | test_case_end |
| | | 294 | fi |