Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 01d8a2d

Browse files
committedFeb 12, 2024
Fix old_cargos tests
1 parent 06a19e6 commit 01d8a2d

File tree

1 file changed

+82
-18
lines changed

1 file changed

+82
-18
lines changed
 

‎tests/testsuite/old_cargos.rs

+82-18
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ fn new_features() {
291291

292292
let toolchains = collect_all_toolchains();
293293

294-
let config_path = paths::home().join(".cargo/config.toml");
294+
let config_path = paths::home().join(".cargo/config");
295295
let lock_path = p.root().join("Cargo.lock");
296296

297297
struct ToolchainBehavior {
@@ -305,6 +305,11 @@ fn new_features() {
305305
let mut unexpected_results: Vec<Vec<String>> = Vec::new();
306306

307307
for (version, toolchain) in &toolchains {
308+
if version >= &Version::new(1, 15, 0) && version < &Version::new(1, 18, 0) {
309+
// These versions do not stay within the sandbox, and chokes on
310+
// Cargo's own `Cargo.toml`.
311+
continue;
312+
}
308313
let mut tc_result = Vec::new();
309314
// Write a config appropriate for this version.
310315
if version < &Version::new(1, 12, 0) {
@@ -347,7 +352,7 @@ fn new_features() {
347352
let stdout = std::str::from_utf8(&output.stdout).unwrap();
348353
let version = stdout
349354
.trim()
350-
.rsplitn(2, ':')
355+
.rsplitn(2, ['@', ':'])
351356
.next()
352357
.expect("version after colon");
353358
Some(Version::parse(version).expect("parseable version"))
@@ -443,7 +448,22 @@ fn new_features() {
443448
}
444449
}
445450
Err(e) => {
446-
tc_result.push(format!("unlocked build failed: {}", e));
451+
if version < &Version::new(1, 49, 0) {
452+
// Old versions don't like the dep: syntax.
453+
check_err_contains(
454+
&mut tc_result,
455+
e,
456+
"which is neither a dependency nor another feature",
457+
);
458+
} else if version >= &Version::new(1, 49, 0) && version < &Version::new(1, 51, 0) {
459+
check_err_contains(
460+
&mut tc_result,
461+
e,
462+
"requires the `-Z namespaced-features` flag",
463+
);
464+
} else {
465+
tc_result.push(format!("unlocked build failed: {}", e));
466+
}
447467
}
448468
}
449469

@@ -469,14 +489,29 @@ fn new_features() {
469489
check_lock!(tc_result, "new-baz-dep", which, behavior.new_baz_dep, None);
470490
}
471491
Err(e) => {
472-
// When version >= 1.51 and <= 1.59,
473-
// 1.0.1 can't be used without -Znamespaced-features
474-
// It gets filtered out of the index.
475-
check_err_contains(
476-
&mut tc_result,
477-
e,
478-
"candidate versions found which didn't match: 1.0.2, 1.0.0",
479-
);
492+
if version < &Version::new(1, 49, 0) {
493+
// Old versions don't like the dep: syntax.
494+
check_err_contains(
495+
&mut tc_result,
496+
e,
497+
"which is neither a dependency nor another feature",
498+
);
499+
} else if version >= &Version::new(1, 49, 0) && version < &Version::new(1, 51, 0) {
500+
check_err_contains(
501+
&mut tc_result,
502+
e,
503+
"requires the `-Z namespaced-features` flag",
504+
);
505+
} else {
506+
// When version >= 1.51 and <= 1.59,
507+
// 1.0.1 can't be used without -Znamespaced-features
508+
// It gets filtered out of the index.
509+
check_err_contains(
510+
&mut tc_result,
511+
e,
512+
"candidate versions found which didn't match: 1.0.2, 1.0.0",
513+
);
514+
}
480515
}
481516
}
482517

@@ -503,13 +538,28 @@ fn new_features() {
503538
}
504539
}
505540
Err(e) => {
506-
// When version >= 1.51 and <= 1.59,
507-
// baz can't lock to 1.0.1, it requires -Znamespaced-features
508-
check_err_contains(
509-
&mut tc_result,
510-
e,
511-
"candidate versions found which didn't match: 1.0.0",
512-
);
541+
if version < &Version::new(1, 49, 0) {
542+
// Old versions don't like the dep: syntax.
543+
check_err_contains(
544+
&mut tc_result,
545+
e,
546+
"which is neither a dependency nor another feature",
547+
);
548+
} else if version >= &Version::new(1, 49, 0) && version < &Version::new(1, 51, 0) {
549+
check_err_contains(
550+
&mut tc_result,
551+
e,
552+
"requires the `-Z namespaced-features` flag",
553+
);
554+
} else {
555+
// When version >= 1.51 and <= 1.59,
556+
// baz can't lock to 1.0.1, it requires -Znamespaced-features
557+
check_err_contains(
558+
&mut tc_result,
559+
e,
560+
"candidate versions found which didn't match: 1.0.0",
561+
);
562+
}
513563
}
514564
}
515565

@@ -545,6 +595,7 @@ fn index_cache_rebuild() {
545595
// happening, and switching between versions should work correctly
546596
// (although it will thrash the cash, that's better than not working
547597
// correctly.
598+
let registry = registry::init();
548599
Package::new("baz", "1.0.0").publish();
549600
Package::new("bar", "1.0.0").publish();
550601
Package::new("bar", "1.0.1")
@@ -565,6 +616,19 @@ fn index_cache_rebuild() {
565616
"#,
566617
)
567618
.file("src/lib.rs", "")
619+
.file(
620+
".cargo/config.toml",
621+
&format!(
622+
r#"
623+
[source.crates-io]
624+
replace-with = 'dummy-registry'
625+
626+
[source.dummy-registry]
627+
registry = '{}'
628+
"#,
629+
registry.index_url()
630+
),
631+
)
568632
.build();
569633

570634
// This version of Cargo errors on index entries that have overlapping

0 commit comments

Comments
 (0)
Failed to load comments.