mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-28 11:20:36 +00:00

By rewriting the tests, with rerast (https://github.com/google/rerast), to use the newly introduced "at" method. First I added the following temporary function to cargotest::support: pub fn project_foo() -> ProjectBuilder { project("foo") } Then I defined the following rewrite.rs: use cargotest::support::{ project, project_foo }; fn rule1(a: &'static str) { replace!(project("foo") => project_foo()); replace!(project(a) => project_foo().at(a)); } Then I ran rerast: cargo +nightly rerast --rules_file=rewrite.rs --force --targets tests --file tests/testsuite/main.rs Finally I searched and replaced the references to project_foo with argument-less project (a little awkardly on macOS with a git clean). find tests -type f -exec sed -i -e 's/project_foo/project/g' {} + git clean -d tests
113 lines
2.4 KiB
Rust
113 lines
2.4 KiB
Rust
use cargotest::support::{basic_bin_manifest, execs, project, Project};
|
|
use hamcrest::assert_that;
|
|
|
|
fn verbose_output_for_lib(p: &Project) -> String {
|
|
format!(
|
|
"\
|
|
[COMPILING] {name} v{version} ({url})
|
|
[RUNNING] `rustc --crate-name {name} src[/]lib.rs --crate-type lib \
|
|
--emit=dep-info,link -C debuginfo=2 \
|
|
-C metadata=[..] \
|
|
--out-dir [..] \
|
|
-L dependency={dir}[/]target[/]debug[/]deps`
|
|
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
|
|
",
|
|
dir = p.root().display(),
|
|
url = p.url(),
|
|
name = "foo",
|
|
version = "0.0.1"
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn build_lib_only() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
authors = ["wycats@example.com"]
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/main.rs",
|
|
r#"
|
|
fn main() {}
|
|
"#,
|
|
)
|
|
.file("src/lib.rs", r#" "#)
|
|
.build();
|
|
|
|
assert_that(
|
|
p.cargo("build").arg("--lib").arg("-v"),
|
|
execs()
|
|
.with_status(0)
|
|
.with_stderr(verbose_output_for_lib(&p)),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn build_with_no_lib() {
|
|
let p = project()
|
|
.file("Cargo.toml", &basic_bin_manifest("foo"))
|
|
.file(
|
|
"src/main.rs",
|
|
r#"
|
|
fn main() {}
|
|
"#,
|
|
)
|
|
.build();
|
|
|
|
assert_that(
|
|
p.cargo("build").arg("--lib"),
|
|
execs()
|
|
.with_status(101)
|
|
.with_stderr("[ERROR] no library targets found"),
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn build_with_relative_cargo_home_path() {
|
|
let p = project()
|
|
.file(
|
|
"Cargo.toml",
|
|
r#"
|
|
[package]
|
|
|
|
name = "foo"
|
|
version = "0.0.1"
|
|
authors = ["wycats@example.com"]
|
|
|
|
[dependencies]
|
|
|
|
"test-dependency" = { path = "src/test_dependency" }
|
|
"#,
|
|
)
|
|
.file(
|
|
"src/main.rs",
|
|
r#"
|
|
fn main() {}
|
|
"#,
|
|
)
|
|
.file("src/test_dependency/src/lib.rs", r#" "#)
|
|
.file(
|
|
"src/test_dependency/Cargo.toml",
|
|
r#"
|
|
[package]
|
|
|
|
name = "test-dependency"
|
|
version = "0.0.1"
|
|
authors = ["wycats@example.com"]
|
|
"#,
|
|
)
|
|
.build();
|
|
|
|
assert_that(
|
|
p.cargo("build").env("CARGO_HOME", "./cargo_home/"),
|
|
execs().with_status(0),
|
|
);
|
|
}
|