summaryrefslogtreecommitdiff
path: root/test.sh
blob: 87dcdcb55b7708461287c37ff4dacd97ec53178a (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
#!/bin/sh

S="$(cd $(dirname $0) && pwd)"

TEST_DIR="$S/test"
TMP_DIR="$S/tmp"
WORK_DIR="$TMP_DIR/workdir"
OUT_DIR="$TMP_DIR/outdir"
PREFIX_DIR="$TMP_DIR/prefix"

case $(uname -s) in

    MINGW* | MSYS*)
	WINDOWS=1
        ;;
esac

pre() {
    echo
    echo "test: $1"
    echo
    rm -Rf "$WORK_DIR"
    rm -Rf "$OUT_DIR"
    rm -Rf "$PREFIX_DIR"
    mkdir -p "$WORK_DIR"
    mkdir -p "$OUT_DIR"
    mkdir -p "$PREFIX_DIR"
}

post() {
    rm -Rf "$WORK_DIR"
    rm -Rf "$OUT_DIR"
    rm -Rf "$PREFIX_DIR"
}

need_ok() {
    if [ $? -ne 0 ]
    then
	echo
	echo "TEST FAILED!"
	echo
	exit 1
    fi
}

try() {
    cmd="$@"
    echo \$ "$cmd"
    OUTPUT=`$@`
    if [ $? -ne 0 ]; then
	echo
	# Using /bin/echo to avoid escaping
	/bin/echo "$OUTPUT"
	echo
	echo "TEST FAILED!"
	echo
	exit 1
    fi
}

expect_fail() {
    cmd="$@"
    echo \$ "$cmd"
    OUTPUT=`$@`
    if [ $? -eq 0 ]; then
	echo
	# Using /bin/echo to avoid escaping
	/bin/echo "$OUTPUT"
	echo
	echo "TEST FAILED!"
	echo
	exit 1
    fi
}

# Installation tests

pre "basic install"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
post

pre "basic uninstall"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/package/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

pre "not installed files"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --non-installed-prefixes=something-to-not-install,dir-to-not-install
try test -e "$WORK_DIR/package/something-to-not-install"
try test -e "$WORK_DIR/package/dir-to-not-install"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-not-install"
try test ! -e "$PREFIX_DIR/dir-to-not-install"
post

pre "verify override"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=program2
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
post

pre "tarball with package name"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc-nightly
try "$WORK_DIR/rustc-nightly/install.sh" --prefix="$PREFIX_DIR"
try test -e "$OUT_DIR/rustc-nightly.tar.gz"
post

pre "bulk directory"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --bulk-dirs=dir-to-install
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR" --uninstall
try test ! -e "$PREFIX_DIR/dir-to-install"
post

pre "nested bulk directory"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image4" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --bulk-dirs=dir-to-install/qux
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/dir-to-install/qux/bar"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR" --uninstall
try test ! -e "$PREFIX_DIR/dir-to-install/qux"
post

pre "only bulk directory, no files"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image5" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --bulk-dirs=dir-to-install
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR" --uninstall
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
post

pre "nested not installed files"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image4" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --non-installed-prefixes=dir-to-install/qux/bar
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/dir-to-install/qux/bar"
post

# Upgrade tests

pre "upgrade v1 -> v2"
mkdir "$WORK_DIR/v1"
try sh "$S/test/rust-installer-v1/gen-installer.sh" \
    --image-dir="$TEST_DIR/image2" \
    --work-dir="$WORK_DIR/v1" \
    --output-dir="$OUT_DIR/v1" \
    --verify-bin=oldprogram \
    --rel-manifest-dir=packagelib
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --rel-manifest-dir=packagelib \
    --legacy-manifest-dirs=packagelib
try "$WORK_DIR/v1/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/bar"
try test -e "$PREFIX_DIR/bin/oldprogram"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/dir-to-install/bar"
try test ! -e "$PREFIX_DIR/bin/oldprogram"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try "$WORK_DIR/package/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

pre "upgrade v1 -> v2 with multiple legacy manifests"
mkdir "$WORK_DIR/v1"
try sh "$S/test/rust-installer-v1/gen-installer.sh" \
    --image-dir="$TEST_DIR/image2" \
    --work-dir="$WORK_DIR/v1" \
    --output-dir="$OUT_DIR/v1" \
    --verify-bin=oldprogram \
    --rel-manifest-dir=rustlib
try sh "$S/test/rust-installer-v1/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR/v1b" \
    --output-dir="$OUT_DIR/v1b" \
    --verify-bin=cargo \
    --rel-manifest-dir=cargo
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --rel-manifest-dir=packagelib \
    --legacy-manifest-dirs=rustlib,cargo
try "$WORK_DIR/v1/package/install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/v1b/package/install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/dir-to-install/bar"
try test ! -e "$PREFIX_DIR/bin/oldprogram"
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/cargo"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try "$WORK_DIR/package/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

pre "multiple components"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR/c1" \
    --output-dir="$OUT_DIR/c1" \
    --component-name=rustc
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR/c2" \
    --output-dir="$OUT_DIR/c2" \
    --verify-bin=cargo \
    --component-name=cargo
try "$WORK_DIR/c1/package/install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/c2/package/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try test -e "$PREFIX_DIR/bin/cargo"
try "$WORK_DIR/c1/package/install.sh" --prefix="$PREFIX_DIR" --uninstall
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try "$WORK_DIR/c2/package/install.sh" --prefix="$PREFIX_DIR" --uninstall
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

# Combined installer tests

pre "combine installers"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz"
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try test -e "$PREFIX_DIR/bin/cargo"
try "$WORK_DIR/rust/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

pre "combine three installers"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image4" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust-docs \
    --component-name=rust-docs
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz,$OUT_DIR/rust-docs.tar.gz"
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try test -e "$PREFIX_DIR/bin/cargo"
try test -e "$PREFIX_DIR/dir-to-install/qux/bar"
try "$WORK_DIR/rust/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/packagelib"
try test ! -e "$PREFIX_DIR/dir-to-install/qux/bar"
post

pre "combine installers with overlay"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo
mkdir -p "$WORK_DIR/overlay"
touch "$WORK_DIR/overlay/README"
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz" \
    --non-installed-overlay="$WORK_DIR/overlay"
try test -e "$WORK_DIR/rust/README"
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/README"
post

pre "combined with bulk dirs"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc \
    --bulk-dirs=dir-to-install
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz"
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try "$WORK_DIR/rust/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/dir-to-install"
post

pre "combine install with separate uninstall"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc \
    --rel-manifest-dir=rustlib
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo \
    --rel-manifest-dir=rustlib
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz" \
    --rel-manifest-dir=rustlib
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try test -e "$PREFIX_DIR/bin/cargo"
try "$WORK_DIR/rustc/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try "$WORK_DIR/cargo/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/packagelib"
post

pre "combined v1 -> v2 upgrade"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rustc \
    --component-name=rustc \
    --rel-manifest-dir=rustlib
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --verify-bin=cargo \
    --package-name=cargo \
    --component-name=cargo \
    --rel-manifest-dir=rustlib
try sh "$S/combine-installers.sh" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=rust \
    --input-tarballs="$OUT_DIR/rustc.tar.gz,$OUT_DIR/cargo.tar.gz" \
    --rel-manifest-dir=rustlib \
    --legacy-manifest-dirs=cargo,rustlib
try sh "$S/test/rust-installer-v1/gen-installer.sh" \
    --image-dir="$TEST_DIR/image2" \
    --work-dir="$WORK_DIR/v1" \
    --output-dir="$OUT_DIR/v1" \
    --verify-bin=oldprogram \
    --rel-manifest-dir=rustlib
try sh "$S/test/rust-installer-v1/gen-installer.sh" \
    --image-dir="$TEST_DIR/image3" \
    --work-dir="$WORK_DIR/v1b" \
    --output-dir="$OUT_DIR/v1b" \
    --verify-bin=cargo \
    --rel-manifest-dir=cargo
try "$WORK_DIR/v1/package//install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/v1b/package//install.sh" --prefix="$PREFIX_DIR"
try "$WORK_DIR/rust/install.sh" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/dir-to-install/bar"
try test ! -e "$PREFIX_DIR/bin/oldprogram"
try test ! -e "$PREFIX_DIR/lib/cargo"
try test -e "$PREFIX_DIR/something-to-install"
try test -e "$PREFIX_DIR/dir-to-install/foo"
try test -e "$PREFIX_DIR/bin/program"
try test -e "$PREFIX_DIR/bin/program2"
try test -e "$PREFIX_DIR/bin/bad-bin"
try test -e "$PREFIX_DIR/bin/cargo"
try test -e "$PREFIX_DIR/lib/rustlib"
try "$WORK_DIR/rust/install.sh --uninstall" --prefix="$PREFIX_DIR"
try test ! -e "$PREFIX_DIR/something-to-install"
try test ! -e "$PREFIX_DIR/dir-to-install/foo"
try test ! -e "$PREFIX_DIR/bin/program"
try test ! -e "$PREFIX_DIR/bin/program2"
try test ! -e "$PREFIX_DIR/bin/bad-bin"
try test ! -e "$PREFIX_DIR/bin/cargo"
try test ! -e "$PREFIX_DIR/lib/rustlib"
post

# Smoke tests

pre "can't run bins error"
try sh "$S/gen-installer.sh" \
    --verify-bin=bad-bin \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR"
expect_fail "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
post

if [ ! -n "$WINDOWS" ]; then
    # chmod doesn't work on windows
    pre "can't write error"
    try sh "$S/gen-installer.sh" \
	--image-dir="$TEST_DIR/image1" \
	--work-dir="$WORK_DIR" \
	--output-dir="$OUT_DIR"
    chmod u-w "$PREFIX_DIR"
    expect_fail "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
    chmod u+w "$PREFIX_DIR"
    post
fi

pre "can't install to installer"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --package-name=my-package
expect_fail "$WORK_DIR/my-package/install.sh" --prefix="$WORK_DIR/my-package"
post

pre "upgrade from future installer error"
try sh "$S/gen-installer.sh" \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR" \
    --rel-manifest-dir=rustlib
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
echo 100 > "$PREFIX_DIR/lib/rustlib/rust-installer-version"
expect_fail "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR"
post

pre "disable-verify"
try sh "$S/gen-installer.sh" \
    --verify-bin=bad-bin \
    --image-dir="$TEST_DIR/image1" \
    --work-dir="$WORK_DIR" \
    --output-dir="$OUT_DIR"
try "$WORK_DIR/package/install.sh" --prefix="$PREFIX_DIR" --disable-verify
post

# TODO: DESTDIR
# TODO: mandir/libdir/bindir, etc.

echo
echo "TOTAL SUCCESS!"
echo