Skip to content

Commit

Permalink
Auto merge of #6900 - jethrogb:nonconcurrent-tests, r=ehuss
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Jun 7, 2019
2 parents e30ab5e + a8c22ca commit d5723eb
Show file tree
Hide file tree
Showing 93 changed files with 1,772 additions and 1,687 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target
/tests/testsuite/support/cargo-test-macro/target
Cargo.lock
.cargo
/config.stamp
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ features = [
bufstream = "0.1"
proptest = "0.9.1"
varisat = "0.2.1"
cargo-test-macro = { "path" = "tests/testsuite/support/cargo-test-macro", version = "0.1.0" }

[[bin]]
name = "cargo"
Expand Down
44 changes: 22 additions & 22 deletions tests/testsuite/alt_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use cargo::util::ToUrl;
use std::fs::{self, File};
use std::io::Write;

#[test]
#[cargo_test]
fn depend_on_alt_registry() {
let p = project()
.file(
Expand Down Expand Up @@ -54,7 +54,7 @@ fn depend_on_alt_registry() {
.run();
}

#[test]
#[cargo_test]
fn depend_on_alt_registry_depends_on_same_registry_no_index() {
let p = project()
.file(
Expand Down Expand Up @@ -96,7 +96,7 @@ fn depend_on_alt_registry_depends_on_same_registry_no_index() {
.run();
}

#[test]
#[cargo_test]
fn depend_on_alt_registry_depends_on_same_registry() {
let p = project()
.file(
Expand Down Expand Up @@ -138,7 +138,7 @@ fn depend_on_alt_registry_depends_on_same_registry() {
.run();
}

#[test]
#[cargo_test]
fn depend_on_alt_registry_depends_on_crates_io() {
let p = project()
.file(
Expand Down Expand Up @@ -182,7 +182,7 @@ fn depend_on_alt_registry_depends_on_crates_io() {
.run();
}

#[test]
#[cargo_test]
fn registry_and_path_dep_works() {
registry::init();

Expand Down Expand Up @@ -216,7 +216,7 @@ fn registry_and_path_dep_works() {
.run();
}

#[test]
#[cargo_test]
fn registry_incompatible_with_git() {
registry::init();

Expand Down Expand Up @@ -246,7 +246,7 @@ fn registry_incompatible_with_git() {
.run();
}

#[test]
#[cargo_test]
fn cannot_publish_to_crates_io_with_registry_dependency() {
let fakeio_path = paths::root().join("fake.io");
let fakeio_url = fakeio_path.to_url().unwrap();
Expand Down Expand Up @@ -304,7 +304,7 @@ fn cannot_publish_to_crates_io_with_registry_dependency() {
.run();
}

#[test]
#[cargo_test]
fn publish_with_registry_dependency() {
let p = project()
.file(
Expand Down Expand Up @@ -365,7 +365,7 @@ fn publish_with_registry_dependency() {
);
}

#[test]
#[cargo_test]
fn alt_registry_and_crates_io_deps() {
let p = project()
.file(
Expand Down Expand Up @@ -410,7 +410,7 @@ fn alt_registry_and_crates_io_deps() {
.run();
}

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

Expand All @@ -426,7 +426,7 @@ fn block_publish_due_to_no_token() {
.run();
}

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

Expand Down Expand Up @@ -464,7 +464,7 @@ fn publish_to_alt_registry() {
);
}

#[test]
#[cargo_test]
fn publish_with_crates_io_dep() {
let p = project()
.file(
Expand Down Expand Up @@ -527,7 +527,7 @@ fn publish_with_crates_io_dep() {
);
}

#[test]
#[cargo_test]
fn passwords_in_registry_index_url_forbidden() {
registry::init();

Expand All @@ -551,7 +551,7 @@ fn passwords_in_registry_index_url_forbidden() {
.run();
}

#[test]
#[cargo_test]
fn passwords_in_registries_index_url_forbidden() {
registry::init();

Expand All @@ -575,7 +575,7 @@ fn passwords_in_registries_index_url_forbidden() {
.run();
}

#[test]
#[cargo_test]
fn patch_alt_reg() {
Package::new("bar", "0.1.0").publish();
let p = project()
Expand Down Expand Up @@ -616,7 +616,7 @@ fn patch_alt_reg() {
.run();
}

#[test]
#[cargo_test]
fn bad_registry_name() {
let p = project()
.file(
Expand Down Expand Up @@ -664,7 +664,7 @@ Caused by:
}
}

#[test]
#[cargo_test]
fn no_api() {
Package::new("bar", "0.0.1").alternative(true).publish();
// Configure without `api`.
Expand Down Expand Up @@ -746,7 +746,7 @@ fn no_api() {
.run();
}

#[test]
#[cargo_test]
fn alt_reg_metadata() {
// Check for "registry" entries in `cargo metadata` with alternative registries.
let p = project()
Expand Down Expand Up @@ -1019,7 +1019,7 @@ fn alt_reg_metadata() {
.run();
}

#[test]
#[cargo_test]
fn unknown_registry() {
// A known registry refers to an unknown registry.
// foo -> bar(crates.io) -> baz(alt)
Expand Down Expand Up @@ -1166,7 +1166,7 @@ fn unknown_registry() {
.run();
}

#[test]
#[cargo_test]
fn registries_index_relative_url() {
let config = paths::root().join(".cargo/config");
fs::create_dir_all(config.parent().unwrap()).unwrap();
Expand Down Expand Up @@ -1216,7 +1216,7 @@ fn registries_index_relative_url() {
.run();
}

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

#[test]
#[cargo_test]
fn registries_index_relative_path_not_allowed() {
let config = paths::root().join(".cargo/config");
fs::create_dir_all(config.parent().unwrap()).unwrap();
Expand Down
Loading

0 comments on commit d5723eb

Please sign in to comment.