Mon Jan 4 21:07:31 2021 UTC ()
regress: add test for portability check in configure~ files


(rillig)
diff -r1.5 -r1.6 pkgsrc/regress/infra-unittests/check-portability.sh

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

--- pkgsrc/regress/infra-unittests/check-portability.sh 2020/05/11 19:13:10 1.5
+++ pkgsrc/regress/infra-unittests/check-portability.sh 2021/01/04 21:07:31 1.6
@@ -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
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 all files in the current directory.
12check_portability_sh() { 12check_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.
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' \
@@ -235,13 +235,60 @@ fi @@ -235,13 +235,60 @@ fi
235if test_case_begin 'no experimental by default'; then 235if 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
247fi 247fi
 248
 249
 250if 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'
 269ERROR: [check-portability.awk] => Found test ... == ...:
 270ERROR: [check-portability.awk] configure~:2: test a == b
 271
 272Explanation:
 273===========================================================================
 274The "test" command, as well as the "[" command, are not required to know
 275the "==" operator. Only a few implementations like bash and some
 276versions of ksh support it.
 277
 278When 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
 280lead to unexpected behavior.
 281
 282There are two ways to fix this error message. If the file that contains
 283the "test ==" is needed for building the package, you should create a
 284patch for it, replacing the "==" operator with "=". If the file is not
 285needed, add its name to the CHECK_PORTABILITY_SKIP variable in the
 286package Makefile.
 287===========================================================================
 288
 289EOF
 290 assert_that "$tmpdir/out" --file-equals 'expected'
 291 assert_that $exitcode --equals 1
 292
 293 test_case_end
 294fi