2
2
3
3
run () {
4
4
rm -f test-tmp/log
5
- DYLD_INSERT_LIBRARIES=$PWD /build/trace-nix.so LD_PRELOAD=$PWD /build/trace-nix.so TRACE_NIX=test-tmp/log \
6
- nix-shell --run : -p -- " $@ " 2> /dev/null
7
- }
8
-
9
- run_without_p () {
10
- rm -f test-tmp/log
11
- DYLD_INSERT_LIBRARIES=$PWD /build/trace-nix.so LD_PRELOAD=$PWD /build/trace-nix.so TRACE_NIX=test-tmp/log \
12
- nix-shell --run : -- " $@ " 2> /dev/null
5
+ env \
6
+ DYLD_INSERT_LIBRARIES=" $PWD " /build/trace-nix.so \
7
+ LD_PRELOAD=" $PWD " /build/trace-nix.so \
8
+ TRACE_NIX=test-tmp/log \
9
+ nix-shell --run : " $@ " 2> /dev/null &
10
+ NIX_PID=$!
11
+ wait
13
12
}
14
13
15
14
result=0
@@ -23,6 +22,8 @@ dir_b3sum() {
23
22
}
24
23
25
24
check () {
25
+ local grep_opts=
26
+ [ " $1 " != " --first" ] || { shift ; grep_opts=-m1; }
26
27
local name=" $1 " key=" $2 " val=" $3 "
27
28
28
29
if ! grep -qzFx -- " $key " test-tmp/log; then
@@ -31,7 +32,11 @@ check() {
31
32
result=1
32
33
fi
33
34
34
- local actual_val=" $( grep -zFx -A1 -- " $key " test-tmp/log | tail -zn1 | tr -d ' \0' ) "
35
+ local actual_val=$(
36
+ grep $grep_opts -zFx -A1 -- " $key " test-tmp/log |
37
+ tail -zn1 |
38
+ tr -d ' \0'
39
+ )
35
40
if [ " $val " != " $actual_val " ]; then
36
41
printf " \33[31mFail: %s: expected '%s', got '%s'\33[m\n" \
37
42
" $name " " $val " " $actual_val "
@@ -48,71 +53,92 @@ echo '"foo"' > test-tmp/test.nix
48
53
: > test-tmp/empty
49
54
ln -s empty test-tmp/link
50
55
56
+ mkdir -p test-tmp/repo/data test-tmp/tmpdir
57
+ echo ' {}' > test-tmp/repo/data/default.nix
58
+ tar -C test-tmp/repo -cf test-tmp/repo.tar .
59
+
51
60
x=" "
52
61
for i in {1..64}; do
53
62
x=x$x
54
63
mkdir -p test-tmp/many-dirs/$x
55
64
done
56
65
57
- run ' with import <unstable> {}; bash'
66
+ export XDG_CACHE_HOME=" $PWD /test-tmp/xdg-cache"
67
+ export TMPDIR=" $PWD /test-tmp/tmpdir"
68
+
69
+
70
+ run -p ' with import <unstable> {}; bash'
58
71
check import-channel \
59
72
" s/nix/var/nix/profiles/per-user/root/channels/unstable" \
60
73
" l$( readlink /nix/var/nix/profiles/per-user/root/channels/unstable) "
61
74
62
- run ' with import <nonexistentChannel> {}; bash'
75
+ run -p ' with import <nonexistentChannel> {}; bash'
63
76
check import-channel-ne \
64
77
" s/nix/var/nix/profiles/per-user/root/channels/nonexistentChannel" ' -'
65
78
66
79
67
- run ' import ./test-tmp/test.nix'
80
+ run -p ' import ./test-tmp/test.nix'
68
81
check import-relative-nix \
69
82
" s$PWD /test-tmp/test.nix" " +"
70
83
71
- run ' import ./test-tmp'
84
+ run -p ' import ./test-tmp'
72
85
check import-relative-nix-dir \
73
86
" s$PWD /test-tmp" " d"
74
87
75
- run ' import ./nonexistent.nix'
88
+ run -p ' import ./nonexistent.nix'
76
89
check import-relative-nix-ne \
77
90
" s$PWD /nonexistent.nix" " -"
78
91
79
92
80
- run ' builtins.readFile ./test-tmp/test.nix'
93
+ run -p ' builtins.readFile ./test-tmp/test.nix'
81
94
check builtins.readFile \
82
95
" f$PWD /test-tmp/test.nix" \
83
96
" $( b3sum ./test-tmp/test.nix | head -c 32) "
84
97
85
- run ' builtins.readFile "/nonexistent/readFile"'
98
+ run -p ' builtins.readFile "/nonexistent/readFile"'
86
99
check builtins.readFile-ne \
87
100
" f/nonexistent/readFile" " -"
88
101
89
- run ' builtins.readFile ./test-tmp'
102
+ run -p ' builtins.readFile ./test-tmp'
90
103
check builtins.readFile-dir \
91
104
" f$PWD /test-tmp" " e"
92
105
93
- run ' builtins.readFile ./test-tmp/empty'
106
+ run -p ' builtins.readFile ./test-tmp/empty'
94
107
check builtins.readFile-empty \
95
108
" f$PWD /test-tmp/empty" \
96
109
" $( b3sum ./test-tmp/empty | head -c 32) "
97
110
98
111
99
- run ' builtins.readDir ./test-tmp'
112
+ run -p ' builtins.readDir ./test-tmp'
100
113
check builtins.readDir \
101
114
" d$PWD /test-tmp" " $( dir_b3sum ./test-tmp) "
102
115
103
- run ' builtins.readDir "/nonexistent/readDir"'
116
+ run -p ' builtins.readDir "/nonexistent/readDir"'
104
117
check builtins.readDir-ne \
105
118
" d/nonexistent/readDir" " -"
106
119
107
120
108
- run ' builtins.readDir ./test-tmp/many-dirs'
121
+ run -p ' builtins.readDir ./test-tmp/many-dirs'
109
122
check builtins.readDir-many-dirs \
110
123
" d$PWD /test-tmp/many-dirs" " $( dir_b3sum ./test-tmp/many-dirs) "
111
124
112
- run_without_p
125
+ run
113
126
check implicit:shell.nix \
114
127
" s$PWD /shell.nix" " -"
115
128
check implicit:default.nix \
116
129
" s$PWD /default.nix" " -"
117
130
131
+
132
+ run -p " fetchTarball file://$PWD /test-tmp/repo.tar?1"
133
+ check --first fetchTarball:create \
134
+ " t$PWD /test-tmp/tmpdir/nix-$NIX_PID -1" " +"
135
+ check fetchTarball:delete \
136
+ " t$PWD /test-tmp/tmpdir/nix-$NIX_PID -1" " -"
137
+
138
+ run -I " q=file://$PWD /test-tmp/repo.tar?2" -p " import <q>"
139
+ check --first tarball-I:create \
140
+ " t$PWD /test-tmp/tmpdir/nix-$NIX_PID -1" " +"
141
+ check tarball-I:delete \
142
+ " t$PWD /test-tmp/tmpdir/nix-$NIX_PID -1" " -"
143
+
118
144
exit $result
0 commit comments