Skip to content

Commit d5723eb

Browse files
committed
Auto merge of #6900 - jethrogb:nonconcurrent-tests, r=ehuss
Fix nonconcurrent tests The cargo testsuite relies on a clean test “root” for every test (i.e. `#[test]`-annotated function). It relied on the `test` crate's behavior to spawn a new thread for each test, which isn't done when tests aren't run concurrently, breaking the test suite. In this PR, I'm using backtraces to figure out which test is being run, which is much more robust. I also cleaned up the root initialization logic so that it no longer recursive calls the `init` function. Fixes #6746
2 parents e30ab5e + a8c22ca commit d5723eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1772
-1687
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
/tests/testsuite/support/cargo-test-macro/target
23
Cargo.lock
34
.cargo
45
/config.stamp

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ features = [
104104
bufstream = "0.1"
105105
proptest = "0.9.1"
106106
varisat = "0.2.1"
107+
cargo-test-macro = { "path" = "tests/testsuite/support/cargo-test-macro", version = "0.1.0" }
107108

108109
[[bin]]
109110
name = "cargo"

tests/testsuite/alt_registry.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use cargo::util::ToUrl;
55
use std::fs::{self, File};
66
use std::io::Write;
77

8-
#[test]
8+
#[cargo_test]
99
fn depend_on_alt_registry() {
1010
let p = project()
1111
.file(
@@ -54,7 +54,7 @@ fn depend_on_alt_registry() {
5454
.run();
5555
}
5656

57-
#[test]
57+
#[cargo_test]
5858
fn depend_on_alt_registry_depends_on_same_registry_no_index() {
5959
let p = project()
6060
.file(
@@ -96,7 +96,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
9696
.run();
9797
}
9898

99-
#[test]
99+
#[cargo_test]
100100
fn depend_on_alt_registry_depends_on_same_registry() {
101101
let p = project()
102102
.file(
@@ -138,7 +138,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
138138
.run();
139139
}
140140

141-
#[test]
141+
#[cargo_test]
142142
fn depend_on_alt_registry_depends_on_crates_io() {
143143
let p = project()
144144
.file(
@@ -182,7 +182,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
182182
.run();
183183
}
184184

185-
#[test]
185+
#[cargo_test]
186186
fn registry_and_path_dep_works() {
187187
registry::init();
188188

@@ -216,7 +216,7 @@ fn registry_and_path_dep_works() {
216216
.run();
217217
}
218218

219-
#[test]
219+
#[cargo_test]
220220
fn registry_incompatible_with_git() {
221221
registry::init();
222222

@@ -246,7 +246,7 @@ fn registry_incompatible_with_git() {
246246
.run();
247247
}
248248

249-
#[test]
249+
#[cargo_test]
250250
fn cannot_publish_to_crates_io_with_registry_dependency() {
251251
let fakeio_path = paths::root().join("fake.io");
252252
let fakeio_url = fakeio_path.to_url().unwrap();
@@ -304,7 +304,7 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {
304304
.run();
305305
}
306306

307-
#[test]
307+
#[cargo_test]
308308
fn publish_with_registry_dependency() {
309309
let p = project()
310310
.file(
@@ -365,7 +365,7 @@ fn publish_with_registry_dependency() {
365365
);
366366
}
367367

368-
#[test]
368+
#[cargo_test]
369369
fn alt_registry_and_crates_io_deps() {
370370
let p = project()
371371
.file(
@@ -410,7 +410,7 @@ fn alt_registry_and_crates_io_deps() {
410410
.run();
411411
}
412412

413-
#[test]
413+
#[cargo_test]
414414
fn block_publish_due_to_no_token() {
415415
let p = project().file("src/main.rs", "fn main() {}").build();
416416

@@ -426,7 +426,7 @@ fn block_publish_due_to_no_token() {
426426
.run();
427427
}
428428

429-
#[test]
429+
#[cargo_test]
430430
fn publish_to_alt_registry() {
431431
let p = project().file("src/main.rs", "fn main() {}").build();
432432

@@ -464,7 +464,7 @@ fn publish_to_alt_registry() {
464464
);
465465
}
466466

467-
#[test]
467+
#[cargo_test]
468468
fn publish_with_crates_io_dep() {
469469
let p = project()
470470
.file(
@@ -527,7 +527,7 @@ fn publish_with_crates_io_dep() {
527527
);
528528
}
529529

530-
#[test]
530+
#[cargo_test]
531531
fn passwords_in_registry_index_url_forbidden() {
532532
registry::init();
533533

@@ -551,7 +551,7 @@ fn passwords_in_registry_index_url_forbidden() {
551551
.run();
552552
}
553553

554-
#[test]
554+
#[cargo_test]
555555
fn passwords_in_registries_index_url_forbidden() {
556556
registry::init();
557557

@@ -575,7 +575,7 @@ fn passwords_in_registries_index_url_forbidden() {
575575
.run();
576576
}
577577

578-
#[test]
578+
#[cargo_test]
579579
fn patch_alt_reg() {
580580
Package::new("bar", "0.1.0").publish();
581581
let p = project()
@@ -616,7 +616,7 @@ fn patch_alt_reg() {
616616
.run();
617617
}
618618

619-
#[test]
619+
#[cargo_test]
620620
fn bad_registry_name() {
621621
let p = project()
622622
.file(
@@ -664,7 +664,7 @@ Caused by:
664664
}
665665
}
666666

667-
#[test]
667+
#[cargo_test]
668668
fn no_api() {
669669
Package::new("bar", "0.0.1").alternative(true).publish();
670670
// Configure without `api`.
@@ -746,7 +746,7 @@ fn no_api() {
746746
.run();
747747
}
748748

749-
#[test]
749+
#[cargo_test]
750750
fn alt_reg_metadata() {
751751
// Check for "registry" entries in `cargo metadata` with alternative registries.
752752
let p = project()
@@ -1019,7 +1019,7 @@ fn alt_reg_metadata() {
10191019
.run();
10201020
}
10211021

1022-
#[test]
1022+
#[cargo_test]
10231023
fn unknown_registry() {
10241024
// A known registry refers to an unknown registry.
10251025
// foo -> bar(crates.io) -> baz(alt)
@@ -1166,7 +1166,7 @@ fn unknown_registry() {
11661166
.run();
11671167
}
11681168

1169-
#[test]
1169+
#[cargo_test]
11701170
fn registries_index_relative_url() {
11711171
let config = paths::root().join(".cargo/config");
11721172
fs::create_dir_all(config.parent().unwrap()).unwrap();
@@ -1216,7 +1216,7 @@ fn registries_index_relative_url() {
12161216
.run();
12171217
}
12181218

1219-
#[test]
1219+
#[cargo_test]
12201220
fn registry_index_relative_url() {
12211221
let config = paths::root().join(".cargo/config");
12221222
fs::create_dir_all(config.parent().unwrap()).unwrap();
@@ -1268,7 +1268,7 @@ warning: custom registry support via the `registry.index` configuration is being
12681268
.run();
12691269
}
12701270

1271-
#[test]
1271+
#[cargo_test]
12721272
fn registries_index_relative_path_not_allowed() {
12731273
let config = paths::root().join(".cargo/config");
12741274
fs::create_dir_all(config.parent().unwrap()).unwrap();

0 commit comments

Comments
 (0)