cargo/tests/testsuite/verify_project.rs
Dale Wijnand 7fe2fbc8a3
Remove the argument from the project test support function
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
2018-07-20 13:31:50 +01:00

58 lines
1.5 KiB
Rust

use cargotest::support::{basic_bin_manifest, execs, main_file, project};
use hamcrest::assert_that;
fn verify_project_success_output() -> String {
r#"{"success":"true"}"#.into()
}
#[test]
fn cargo_verify_project_path_to_cargo_toml_relative() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();
assert_that(
p.cargo("verify-project")
.arg("--manifest-path")
.arg("foo/Cargo.toml")
.cwd(p.root().parent().unwrap()),
execs()
.with_status(0)
.with_stdout(verify_project_success_output()),
);
}
#[test]
fn cargo_verify_project_path_to_cargo_toml_absolute() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();
assert_that(
p.cargo("verify-project")
.arg("--manifest-path")
.arg(p.root().join("Cargo.toml"))
.cwd(p.root().parent().unwrap()),
execs()
.with_status(0)
.with_stdout(verify_project_success_output()),
);
}
#[test]
fn cargo_verify_project_cwd() {
let p = project()
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();
assert_that(
p.cargo("verify-project").cwd(p.root()),
execs()
.with_status(0)
.with_stdout(verify_project_success_output()),
);
}