Mon May 4 21:48:18 2020 UTC ()
mk/check/check-portability: fix error message when no patches are found


(rillig)
diff -r1.20 -r1.21 pkgsrc/mk/check/check-portability.sh
diff -r1.1 -r1.2 pkgsrc/regress/infra-unittests/check-portability.sh

cvs diff -r1.20 -r1.21 pkgsrc/mk/check/check-portability.sh (expand / switch to unified diff)

--- pkgsrc/mk/check/check-portability.sh 2020/05/04 21:32:48 1.20
+++ pkgsrc/mk/check/check-portability.sh 2020/05/04 21:48:18 1.21
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1# $NetBSD: check-portability.sh,v 1.20 2020/05/04 21:32:48 rillig Exp $ 1# $NetBSD: check-portability.sh,v 1.21 2020/05/04 21:48:18 rillig Exp $
2# 2#
3# This program checks all files in the current directory and any 3# This program checks all files in the current directory and any
4# subdirectories for portability issues that are likely to result in 4# subdirectories for portability issues that are likely to result in
5# false assumptions by the package. 5# false assumptions by the package.
6# 6#
7# The most prominent example is the "==" operator of test(1), which is 7# The most prominent example is the "==" operator of test(1), which is
8# only implemented by bash and some versions of the ksh. 8# only implemented by bash and some versions of the ksh.
9# 9#
10# usage: cd $WRKSRC && [SKIP_FILTER=...] check-portability.sh 10# usage: cd $WRKSRC && [SKIP_FILTER=...] check-portability.sh
11# 11#
12 12
13set -eu 13set -eu
14 14
@@ -24,27 +24,36 @@ check_shell() { @@ -24,27 +24,36 @@ check_shell() {
24 CK_FNAME="$1" \ 24 CK_FNAME="$1" \
25 CK_PROGNAME="check-portability.awk" \ 25 CK_PROGNAME="check-portability.awk" \
26 awk -f "$checkdir/check-subr.awk" \ 26 awk -f "$checkdir/check-subr.awk" \
27 -f "$checkdir/check-portability.awk" \ 27 -f "$checkdir/check-portability.awk" \
28 < "$1" 1>&2 \ 28 < "$1" 1>&2 \
29 || cs_exitcode=1 29 || cs_exitcode=1
30 30
31 if test -f "${PREFIX}/bin/check-portability"; then 31 if test -f "${PREFIX}/bin/check-portability"; then
32 ${PREFIX}/bin/check-portability "$1" 1>&2 \ 32 ${PREFIX}/bin/check-portability "$1" 1>&2 \
33 || cs_exitcode=1 33 || cs_exitcode=1
34 fi 34 fi
35} 35}
36 36
37patched_files=",$(awk 'BEGIN { ORS = "," } /^\+\+\+ / { print $2 }' "$PATCHDIR"/patch-*)," 37patched_files=",$(awk '
 38 BEGIN {
 39 if (ARGV[1] ~ /\/patch-\*$/)
 40 exit;
 41 ORS = ","
 42 }
 43 /^\+\+\+ / {
 44 print $2
 45 }' \
 46 "$PATCHDIR"/patch-*),"
38 47
39find ./* -type f -print 2>/dev/null \ 48find ./* -type f -print 2>/dev/null \
40| sed 's,$,_,' \ 49| sed 's,$,_,' \
41| { 50| {
42 opsys=`uname -s`-`uname -r` 51 opsys=`uname -s`-`uname -r`
43 while read fname; do 52 while read fname; do
44 fname="${fname#./}" 53 fname="${fname#./}"
45 fname="${fname%_}" 54 fname="${fname%_}"
46 55
47 skip=no 56 skip=no
48 eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac" 57 eval "case \"\$fname\" in $SKIP_FILTER *.orig) skip=yes;; esac"
49 case "$fname" in *.in) 58 case "$fname" in *.in)
50 case ",$patched_files," in *,"${fname%.in}",*) 59 case ",$patched_files," in *,"${fname%.in}",*)

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

--- pkgsrc/regress/infra-unittests/check-portability.sh 2020/05/04 21:32:48 1.1
+++ pkgsrc/regress/infra-unittests/check-portability.sh 2020/05/04 21:48:18 1.2
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: check-portability.sh,v 1.1 2020/05/04 21:32:48 rillig Exp $ 2# $NetBSD: check-portability.sh,v 1.2 2020/05/04 21:48:18 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 sh "$pkgsrcdir/mk/check/check-portability.sh" \ 15 sh "$pkgsrcdir/mk/check/check-portability.sh" \
@@ -165,13 +165,31 @@ if test_case_begin 'special characters i @@ -165,13 +165,31 @@ if test_case_begin 'special characters i
165 create_file_lines 'work/patches/patch-aa' \ 165 create_file_lines 'work/patches/patch-aa' \
166 '+++ [[[[(`" 2020-05-04' 166 '+++ [[[[(`" 2020-05-04'
167 create_file_lines 'work/+++ [[[[(`"' \ 167 create_file_lines 'work/+++ [[[[(`"' \
168 '#! /bin/sh' \ 168 '#! /bin/sh' \
169 'test a = b' 169 'test a = b'
170 170
171 check_portability_sh 171 check_portability_sh
172 172
173 assert_that 'out' --file-is-empty 173 assert_that 'out' --file-is-empty
174 assert_that $exitcode --equals 0 174 assert_that $exitcode --equals 0
175 175
176 test_case_end 176 test_case_end
177fi 177fi
 178
 179
 180if test_case_begin 'no patches'; then
 181
 182 # Ensure that no error message is printed when there are no
 183 # patch files.
 184
 185 create_file_lines 'file' \
 186 '#! /bin/sh' \
 187 'test a = b'
 188
 189 check_portability_sh
 190
 191 assert_that 'out' --file-is-empty
 192 assert_that $exitcode --equals 0
 193
 194 test_case_end
 195fi