@@ -4,12 +4,52 @@ Test the error message when unzip is needed but not installed.
44
55 $ make_lockdir
66
7+ Set up our fake decompressor binaries, they all just copy the file to the
8+ expected location:
9+
10+ $ mkdir -p . binaries
11+ $ cat > . binaries/ gnutar << ' EOF'
12+ > # !/usr/bin/env sh
13+ > case " $1" in
14+ > -- version)
15+ > echo " tar"
16+ > ;;
17+ > * )
18+ > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
19+ > esac
20+ > EOF
21+ $ chmod + x . binaries/ gnutar
22+ $ cat > . binaries/ bsdtar << ' EOF'
23+ > # !/usr/bin/env sh
24+ > case " $1" in
25+ > -- version)
26+ > echo " bsdtar"
27+ > ;;
28+ > * )
29+ > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
30+ > esac
31+ > EOF
32+ $ chmod + x . binaries/ bsdtar
33+ $ cat > . binaries/ unzip << ' EOF'
34+ > # !/usr/bin/env sh
35+ > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
36+ > EOF
37+ $ chmod + x . binaries/ unzip
38+
39+ Set up a folder that we will inject as fake PATH:
40+
741 $ mkdir -p . fakebin
842 $ ln -s $ (which dune) . fakebin/ dune
943 $ ln -s $ (which sh) . fakebin/ sh
1044 $ ln -s $ (which cp) . fakebin/ cp
45+ $ show_path() {
46+ > ls . fakebin | sort | xargs
47+ > }
1148
12- $ echo " random" >> test. txt. zip
49+ Our " compressed" ZIP file is not compressed (as the extraction is just a copy ),
50+ but does have a . zip suffix:
51+
52+ $ echo " random" > test. txt. zip
1353
1454 $ makepkg() {
1555 > make_lockpkg $1 << EOF
@@ -23,76 +63,51 @@ Test the error message when unzip is needed but not installed.
2363 $ makepkg foo
2464
2565Build the package in an environment without unzip, or tar, or bsdtar.
26- $ PATH= . fakebin build_pkg foo 2 > &1 | grep ' ^Error:' -A 3
66+
67+ (NOTE: We wrap `(PATH= . fakebin foo)` in parens, otherwise the value of the PATH
68+ variable can escape to subseqent shell invocations on MacOS. )
69+
70+ $ show_path
71+ cp dune sh
72+ $ (PATH= . fakebin build_pkg foo 2 > &1 | grep ' ^Error:' -A 3 )
2773 Error: No program found to extract zip file. Tried:
2874 - unzip
2975 - bsdtar
3076 - tar
3177
32- Build with only tar that doesn 't work, not bsdtar or unzip, it should still fail to build
78+ Build with only GNU tar that can 't extract ZIP archives :
3379
34- $ cat > . fakebin/ tar << ' EOF'
35- > # !/usr/bin/env sh
36- > case $1 in
37- > -- version)
38- > echo " tar"
39- > ;;
40- > * )
41- > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
42- > esac
43- > EOF
44- $ chmod + x . fakebin/ tar
45- $ PATH= . fakebin build_pkg foo 2 > &1 | grep ' ^Error:' -A 3
80+ $ ln -s . binaries/ gnutar . fakebin/ tar
81+ $ show_path
82+ cp dune sh tar
83+ $ (PATH= . fakebin build_pkg foo 2 > &1 | grep ' ^Error:' -A 3 )
4684 Error: No program found to extract zip file. Tried:
4785 - unzip
4886 - bsdtar
4987 - tar
5088
51- Build with only tar that works, not bsdtar or unzip, it should work
89+ Build with bsdtar that can extract ZIP archives, without unzip. It should work:
5290
53- (NOTE: We wrap `(PATH= . fakebin foo)` in parens, otherwise the value of the PATH
54- variable can escape to subseqent shell invocations on MacOS. )
55-
56- $ cat > . fakebin/ tar << ' EOF'
57- > # !/usr/bin/env sh
58- > case $1 in
59- > -- version)
60- > echo " bsdtar"
61- > ;;
62- > * )
63- > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
64- > esac
65- > EOF
66- $ chmod + x . fakebin/ tar
91+ $ rm . fakebin/ tar
92+ $ cp . binaries/ bsdtar . fakebin/ tar
93+ $ show_path
94+ cp dune sh tar
6795 $ (PATH= . fakebin build_pkg foo)
6896
6997Build the package with bsdtar and tar. Now our fake bsdtar will get picked up
70- and built .
98+ and used to extract :
7199
72- $ cat > . fakebin/ bsdtar << ' EOF'
73- > # !/usr/bin/env sh
74- > case $1 in
75- > -- version)
76- > echo " bsdtar"
77- > ;;
78- > * )
79- > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
80- > esac
81- > EOF
82- $ chmod + x . fakebin/ bsdtar
100+ $ rm . fakebin/ tar
101+ $ ln -s . binaries/ gnutar . fakebin/ tar
102+ $ ln -s . binaries/ bsdtar . fakebin/ bsdtar
103+ $ show_path
104+ bsdtar cp dune sh tar
83105 $ (PATH= . fakebin build_pkg foo)
84106
85- Build with unzip
107+ Build with unzip only :
86108
87- $ cat > . fakebin/ unzip << ' EOF'
88- > # !/usr/bin/env sh
89- > case $1 in
90- > -- version)
91- > echo " unzip"
92- > ;;
93- > * )
94- > cp " $2" " $4/$(basename " $ {2 % . zip }" )"
95- > esac
96- > EOF
97- $ chmod + x . fakebin/ unzip
109+ $ ln -s . binaries/ unzip . fakebin/ unzip
110+ $ rm . fakebin/ bsdtar . fakebin/ tar
111+ $ show_path
112+ cp dune sh unzip
98113 $ (PATH= . fakebin build_pkg foo)
0 commit comments