-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathcli_v2.rs
More file actions
2575 lines (2359 loc) · 66.2 KB
/
cli_v2.rs
File metadata and controls
2575 lines (2359 loc) · 66.2 KB
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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Test cases of the rustup command, using v2 manifests, mostly
//! derived from multirust/test-v2.sh
use std::fs;
use std::io::Write;
use std::path::PathBuf;
use rustup::dist::TargetTriple;
use rustup::dist::manifest::Manifest;
use rustup::test::{
CROSS_ARCH1, CROSS_ARCH2, CliTestContext, Config, Scenario, create_hash, this_host_triple,
};
#[tokio::test]
async fn rustc_no_default_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustc"])
.await
.with_stderr(snapbox::str![[r#"
...
error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
...
"#]])
.is_err();
}
#[tokio::test]
async fn expected_bins_exist() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_toolchain_from_channel() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
cx.config
.expect(["rustup", "default", "beta"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
cx.config
.expect(["rustup", "default", "stable"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_toolchain_from_archive() {
let cx = CliTestContext::new(Scenario::ArchivesV2).await;
cx.config
.expect(["rustup", "default", "nightly-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-nightly-1)
"#]])
.is_ok();
cx.config
.expect(["rustup", "default", "beta-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-beta-1.1.0)
"#]])
.is_ok();
cx.config
.expect(["rustup", "default", "stable-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.0.0 (hash-stable-1.0.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_toolchain_from_version() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "1.1.0"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_with_profile() {
let cx = CliTestContext::new(Scenario::UnavailableRls).await;
// Start with a config that uses the "complete" profile
cx.config.set_current_dist_date("2015-01-01");
cx.config
.expect(["rustup", "set", "profile", "complete"])
.await
.is_ok();
// Installing with minimal profile should only install rustc
cx.config
.expect([
"rustup",
"toolchain",
"install",
"--profile",
"minimal",
"nightly",
])
.await
.is_ok();
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config.expect_component_executable("rustup").await;
cx.config.expect_component_executable("rustc").await;
cx.config.expect_component_not_executable("cargo").await;
// After an update, we should _still_ only have the profile-dictated components
cx.config.set_current_dist_date("2015-01-02");
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config.expect_component_executable("rustup").await;
cx.config.expect_component_executable("rustc").await;
cx.config.expect_component_not_executable("cargo").await;
}
#[tokio::test]
async fn default_existing_toolchain() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "default", "nightly"])
.await
.with_stderr(snapbox::str![[r#"
...
info: using existing install for 'nightly-[HOST_TRIPLE]'
...
"#]])
.is_ok();
}
#[tokio::test]
async fn update_channel() {
let cx = CliTestContext::new(Scenario::ArchivesV2).await;
cx.config.set_current_dist_date("2015-01-01");
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-nightly-1)
"#]])
.is_ok();
cx.config.set_current_dist_date("2015-01-02");
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
}
#[tokio::test]
async fn list_toolchains() {
let cx = CliTestContext::new(Scenario::ArchivesV2).await;
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "update", "beta-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
beta-2015-01-01-[HOST_TRIPLE]
nightly-[HOST_TRIPLE] (active, default)
"#]])
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list", "-v"])
.await
.with_stdout(snapbox::str![[r#"
beta-2015-01-01-[HOST_TRIPLE] [..]/toolchains/beta-2015-01-01-[HOST_TRIPLE]
nightly-[HOST_TRIPLE] (active, default) [..]/toolchains/nightly-[HOST_TRIPLE]
"#]])
.is_ok();
}
#[tokio::test]
async fn list_toolchains_with_bogus_file() {
// #520
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
let name = "bogus_regular_file.txt";
let path = cx.config.rustupdir.join("toolchains").join(name);
rustup::utils::write_file(name, &path, "").unwrap();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
nightly-[HOST_TRIPLE] (active, default)
"#]])
.is_ok();
}
#[tokio::test]
async fn list_toolchains_with_none() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
no installed toolchains
"#]])
.is_ok();
}
#[tokio::test]
async fn remove_toolchain_default() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "remove", "nightly"])
.await
.with_stderr(snapbox::str![[r#"
...
warn: removing the default toolchain; proc-macros and build scripts might no longer build
...
"#]])
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
no installed toolchains
"#]])
.is_ok();
}
#[tokio::test]
async fn remove_toolchain_active() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "set", "stable"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "remove", "stable"])
.await
.with_stderr(snapbox::str![[r#"
...
warn: removing the active toolchain; a toolchain override will be required for running Rust tools
...
"#]])
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
nightly-[HOST_TRIPLE] (default)
"#]])
.is_ok();
}
// Issue #2873
#[tokio::test]
async fn remove_toolchain_ignore_trailing_slash() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
// custom toolchain name with trailing slash
let path = cx.config.customdir.join("custom-1");
let path_str = path.to_string_lossy();
cx.config
.expect(["rustup", "toolchain", "link", "dev", &path_str])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "remove", "dev/"])
.await
.with_stderr(snapbox::str![[r#"
...
info: toolchain 'dev' uninstalled
...
"#]])
.is_ok();
// check if custom toolchain directory contents are not removed
let toolchain_dir_is_non_empty = fs::read_dir(&path).unwrap().next().is_some();
assert!(toolchain_dir_is_non_empty);
// distributable toolchain name with trailing slash
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
cx.config
.expect([
"rustup",
"toolchain",
"remove",
&format!("nightly-{}/", this_host_triple()),
])
.await
.with_stderr(snapbox::str![[r#"
...
info: toolchain 'nightly-[HOST_TRIPLE]' uninstalled
...
"#]])
.is_ok();
}
#[tokio::test]
async fn add_remove_multiple_toolchains() {
async fn go(add: &str, rm: &str) {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
let tch1 = "beta";
let tch2 = "nightly";
cx.config
.expect(["rustup", "toolchain", add, tch1, tch2])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
beta-[HOST_TRIPLE] (active, default)
nightly-[HOST_TRIPLE]
"#]])
.is_ok();
cx.config
.expect(["rustup", "toolchain", rm, tch1, tch2])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
no installed toolchains
"#]])
.is_ok();
cx.config
.expect(["rustup", "toolchain", "list"])
.await
.with_stdout(snapbox::str![[r#"
no installed toolchains
"#]])
.is_ok();
}
for add in &["add", "update", "install"] {
for rm in &["remove", "uninstall"] {
go(add, rm).await;
}
}
}
#[tokio::test]
async fn remove_override_toolchain_err_handling() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let cx = cx.change_dir(tempdir.path());
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
cx.config
.expect(["rustup", "toolchain", "remove", "beta"])
.await
.is_ok();
cx.config
.expect_with_env(["rustc", "--version"], [("RUSTUP_AUTO_INSTALL", "1")])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.with_stderr(snapbox::str![[r#"
...
info: syncing channel updates for 'beta-[HOST_TRIPLE]'
info: latest update on 2015-01-02, rust version 1.2.0 (hash-beta-1.2.0)
info: downloading component[..]
...
"#]])
.is_ok();
cx.config
.expect(["rustup", "component", "list", "--installed"])
.await
.is_ok()
.with_stdout(snapbox::str![[r#"
cargo-[HOST_TRIPLE]
rust-docs-[HOST_TRIPLE]
rust-std-[HOST_TRIPLE]
rustc-[HOST_TRIPLE]
"#]]);
}
#[tokio::test]
async fn file_override_toolchain_err_handling() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
let cwd = cx.config.current_dir();
let toolchain_file = cwd.join("rust-toolchain");
rustup::utils::raw::write_file(&toolchain_file, "beta").unwrap();
cx.config
.expect_with_env(["rustc", "--version"], [("RUSTUP_AUTO_INSTALL", "1")])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.with_stderr(snapbox::str![[r#"
...
info: syncing channel updates for 'beta-[HOST_TRIPLE]'
info: latest update on 2015-01-02, rust version 1.2.0 (hash-beta-1.2.0)
info: downloading component[..]
...
"#]])
.is_ok();
cx.config
.expect(["rustup", "component", "list", "--installed"])
.await
.is_ok()
.with_stdout(snapbox::str![[r#"
cargo-[HOST_TRIPLE]
rust-docs-[HOST_TRIPLE]
rust-std-[HOST_TRIPLE]
rustc-[HOST_TRIPLE]
"#]]);
}
#[tokio::test]
async fn plus_override_toolchain_err_handling() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect_with_env(
["rustc", "+beta", "--version"],
[("RUSTUP_AUTO_INSTALL", "0")],
)
.await
.with_stderr(snapbox::str![[r#"
...
error: toolchain 'beta-[HOST_TRIPLE]' is not installed
...
"#]])
.is_err();
cx.config
.expect_with_env(
["rustc", "+beta", "--version"],
[("RUSTUP_AUTO_INSTALL", "1")],
)
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn bad_sha_on_manifest() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
// Corrupt the sha
let sha_file = cx
.config
.distdir
.as_ref()
.unwrap()
.join("dist/channel-rust-nightly.toml.sha256");
let sha_str = fs::read_to_string(&sha_file).unwrap();
let mut sha_bytes = sha_str.into_bytes();
sha_bytes[..10].clone_from_slice(b"aaaaaaaaaa");
let sha_str = String::from_utf8(sha_bytes).unwrap();
rustup::utils::raw::write_file(&sha_file, &sha_str).unwrap();
// We fail because the sha is bad, but we should emit the special message to that effect.
cx.config
.expect(["rustup", "default", "nightly"])
.await
.with_stderr(snapbox::str![[r#"
...
info: this might indicate an issue with the third-party release server '[..]'
...
"#]])
.is_err();
}
#[tokio::test]
async fn bad_manifest() {
// issue #3851
let cx = CliTestContext::new(Scenario::SimpleV2).await;
// install some toolchain
cx.config
.expect(["rustup", "update", "nightly"])
.await
.is_ok();
let path = [
"toolchains",
&format!("nightly-{}", this_host_triple()),
"lib",
"rustlib",
"multirust-channel-manifest.toml",
]
.into_iter()
.collect::<PathBuf>();
assert!(cx.config.rustupdir.has(&path));
let path = cx.config.rustupdir.join(&path);
// corrupt the manifest file by inserting a NUL byte at some position
let old = fs::read_to_string(&path).unwrap();
let pattern = "[[pkg.rust.targ";
let (prefix, suffix) = old.split_once(pattern).unwrap();
let new = format!("{prefix}{pattern}\u{0}{suffix}");
fs::write(&path, new).unwrap();
// run some commands that try to load the manifest and
// check that the manifest parsing error includes the manifest file path
cx.config
.expect(["rustup", "check"])
.await
.with_stderr(snapbox::str![[r#"
...
error: could not parse manifest file: '[..]': [..]
...
"#]])
.is_err();
}
#[tokio::test]
async fn bad_sha_on_installer() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
// Since the v2 sha's are contained in the manifest, corrupt the installer
let dir = cx.config.distdir.as_ref().unwrap().join("dist/2015-01-02");
for file in fs::read_dir(dir).unwrap() {
let file = file.unwrap();
let path = file.path();
let filename = path.to_string_lossy();
if filename.ends_with(".tar.gz")
|| filename.ends_with(".tar.xz")
|| filename.ends_with(".tar.zst")
{
rustup::utils::raw::write_file(&path, "xxx").unwrap();
}
}
cx.config
.expect(["rustup", "default", "nightly"])
.await
.with_stderr(snapbox::str![[r#"
...
error: component download failed for cargo-[HOST_TRIPLE]: checksum failed for '[..]', expected: '[..]', calculated: '[..]'
...
"#]])
.is_err();
}
#[tokio::test]
async fn install_override_toolchain_from_channel() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "override", "add", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
cx.config
.expect(["rustup", "override", "add", "stable"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_override_toolchain_from_archive() {
let cx = CliTestContext::new(Scenario::ArchivesV2).await;
cx.config
.expect(["rustup", "override", "add", "nightly-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-nightly-1)
"#]])
.is_ok();
cx.config
.expect(["rustup", "override", "add", "beta-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-beta-1.1.0)
"#]])
.is_ok();
cx.config
.expect(["rustup", "override", "add", "stable-2015-01-01"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.0.0 (hash-stable-1.0.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn install_override_toolchain_from_version() {
let cx = CliTestContext::new(Scenario::SimpleV2).await;
cx.config
.expect(["rustup", "override", "add", "1.1.0"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn override_overrides_default() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
let cx = cx.change_dir(tempdir.path());
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn multiple_overrides() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir1 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
{
let cx = cx.change_dir(tempdir1.path());
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
}
{
let cx = cx.change_dir(tempdir2.path());
cx.config
.expect(["rustup", "override", "add", "stable"])
.await
.is_ok();
}
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
{
let cx = cx.change_dir(tempdir1.path());
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
}
{
let cx = cx.change_dir(tempdir2.path());
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
}
// #316
#[cfg(windows)]
#[tokio::test]
async fn override_windows_root() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
use std::path::{Component, PathBuf};
let cwd = cx.config.current_dir();
let prefix = cwd.components().next().unwrap();
let prefix = match prefix {
Component::Prefix(p) => p,
_ => panic!(),
};
// This value is probably "C:"
// Really sketchy to be messing with C:\ in a test...
let prefix = prefix.as_os_str().to_str().unwrap();
let prefix = format!("{prefix}\\");
let cx = cx.change_dir(&PathBuf::from(&prefix));
cx.config
.expect(["rustup", "default", "stable"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "add", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]])
.is_ok();
cx.config
.expect(["rustup", "override", "remove"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.1.0 (hash-stable-1.1.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn change_override() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let cx = cx.change_dir(tempdir.path());
cx.config
.expect(["rustup", "override", "add", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.with_stdout(snapbox::str![[r#"
1.2.0 (hash-beta-1.2.0)
"#]])
.is_ok();
}
#[tokio::test]
async fn remove_override_no_default() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let cx = cx.change_dir(tempdir.path());
cx.config
.expect(["rustup", "override", "add", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "remove"])
.await
.is_ok();
cx.config
.expect(["rustc"])
.await
.with_stderr(snapbox::str![[r#"
...
error: rustup could not choose a version of rustc to run, because one wasn't specified explicitly, and no default is configured.
...
"#]])
.is_err();
}
#[tokio::test]
async fn remove_override_with_default() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let cx = cx.change_dir(tempdir.path());
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
cx.config
.expect(["rustup", "override", "remove"])
.await
.is_ok();
cx.config
.expect(["rustc", "--version"])
.await
.is_ok()
.with_stdout(snapbox::str![[r#"
1.3.0 (hash-nightly-2)
"#]]);
}
#[tokio::test]
async fn remove_override_with_multiple_overrides() {
let mut cx = CliTestContext::new(Scenario::SimpleV2).await;
let tempdir1 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
let tempdir2 = tempfile::Builder::new().prefix("rustup").tempdir().unwrap();
cx.config
.expect(["rustup", "default", "nightly"])
.await
.is_ok();
{
let cx = cx.change_dir(tempdir1.path());
cx.config
.expect(["rustup", "override", "add", "beta"])
.await
.is_ok();
}
{
let cx = cx.change_dir(tempdir2.path());
cx.config
.expect(["rustup", "override", "add", "stable"])
.await
.is_ok();
}
cx.config