blob: fb2c041bf3d194d8bee51358a7cbd151314b1fa5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#! /bin/sh
# $NetBSD: replace-interpreter.sh,v 1.1 2020/05/18 06:06:34 rillig Exp $
#
# Tests for mk/configure/replace-interpreter.mk.
#
set -eu
. './test.subr'
test_case_set_up() {
create_file 'setup.mk' <<-EOF
# The tools that are used by replace-interpreter.mk
CHMOD= chmod
CMP= cmp
MV= mv
SED= sed
RM= rm
# Commands that are specific to pkgsrc
RUN= @set -e;
STEP_MSG= echo '=>'
INFO_MSG= echo 'info:'
WARNING_MSG= echo 'warning:'
# Dummy interpreters
PERL5= $tmpdir/bin/perl5
WRKDIR= $tmpdir/wrkdir
WRKSRC= .
EOF
}
if test_case_begin 'regular file'; then
create_file 'test.mk' <<-EOF
REPLACE_PERL+= perl-program
.include "setup.mk"
.include "mk/configure/replace-interpreter.mk"
EOF
create_file_lines 'perl-program' \
'#! /any/path/perl'
run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \
&& exitcode=0 || exitcode=$?
assert_that "$tmpdir/output" --file-is-lines \
'=> Replacing Perl interpreter in perl-program.'
assert_that 'perl-program' --file-is-lines \
"#!$tmpdir/bin/perl5"
test_case_end
fi
if test_case_begin 'valid symlink'; then
# Valid symlinks are followed, even though they might point
# anywhere, even outside WRKSRC.
# This has "forever" been the behavior.
# It may make sense to change this, but that requires testing
# to see whether any packages rely on this behavior.
# Ouch, this replaces the symlink with a regular file,
# which is probably unexpected to the upstream author.
create_file 'test.mk' <<-EOF
REPLACE_PERL+= perl-symlink
.include "setup.mk"
.include "mk/configure/replace-interpreter.mk"
EOF
create_file_lines 'perl-program' \
'#! /any/path/perl'
ln -s 'perl-program' 'perl-symlink'
run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \
&& exitcode=0 || exitcode=$?
assert_that "$tmpdir/output" --file-is-lines \
'=> Replacing Perl interpreter in perl-symlink.'
# This should most probably still be a symlink.
[ -f 'perl-symlink' ] || assert_fail 'still a symlink\n'
# This file should be left unmodified since it is not mentioned
# in REPLACE_PERL.
assert_that 'perl-program' --file-is-lines \
"#! /any/path/perl"
assert_that 'perl-symlink' --file-is-lines \
"#!$tmpdir/bin/perl5"
test_case_end
fi
if test_case_begin 'broken symlink'; then
# Broken symlinks are skipped silently, just like directories.
create_file 'test.mk' <<-EOF
REPLACE_PERL+= perl-symlink
.include "setup.mk"
.include "mk/configure/replace-interpreter.mk"
EOF
ln -s 'does-not-exist' 'perl-symlink'
run_bmake 'test.mk' 'replace-interpreter' 1> "$tmpdir/output" 2>&1 \
&& exitcode=0 || exitcode=$?
assert_that "$tmpdir/output" --file-is-lines \
'=> Replacing Perl interpreter in perl-symlink.'
[ -h 'perl-symlink' ] || assert_fail 'not a symlink anymore'
test_case_end
fi
|