Skip to content

Commit

Permalink
cargotest/support: remove internal mutability in favor of switching t…
Browse files Browse the repository at this point in the history
…ypes

Remove is_build: Cell<bool> from ProjectBuilder and introduce a new type Project.

is_build==false <-> ProjectBuilder
is_build==true <-> Project

Also add #[must_use] to ProjectBuilder to confirm its instances are surely consumed by its build() method to produce Project.

The same goes for RepoBuilder.

ProjectBuilder::cargo_process() was removed as its design heavily depended on the internal mutability.

Signed-off-by: NODA, Kai <nodakai@gmail.com>
  • Loading branch information
nodakai committed Oct 10, 2017
1 parent 463e850 commit d43ee1d
Show file tree
Hide file tree
Showing 62 changed files with 3,034 additions and 2,410 deletions.
639 changes: 336 additions & 303 deletions tests/bad-config.rs

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions tests/bad-manifest-path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ use hamcrest::{assert_that};
fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

assert_that(p.cargo_process(command)
assert_that(p.cargo(command)
.arg("--manifest-path").arg(manifest_path_argument)
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
Expand All @@ -19,11 +20,11 @@ fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {


fn assert_cargo_toml_doesnt_exist(command: &str, manifest_path_argument: &str) {
let p = project("foo");
let p = project("foo").build();
let expected_path = manifest_path_argument
.split('/').collect::<Vec<_>>().join("[..]");

assert_that(p.cargo_process(command)
assert_that(p.cargo(command)
.arg("--manifest-path").arg(manifest_path_argument)
.cwd(p.root().parent().unwrap()),
execs().with_status(101)
Expand Down Expand Up @@ -317,9 +318,10 @@ fn update_dir_to_nonexistent_cargo_toml() {
fn verify_project_dir_containing_cargo_toml() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

assert_that(p.cargo_process("verify-project")
assert_that(p.cargo("verify-project")
.arg("--manifest-path").arg("foo")
.cwd(p.root().parent().unwrap()),
execs().with_status(1)
Expand All @@ -332,9 +334,10 @@ fn verify_project_dir_containing_cargo_toml() {
fn verify_project_dir_plus_file() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

assert_that(p.cargo_process("verify-project")
assert_that(p.cargo("verify-project")
.arg("--manifest-path").arg("foo/bar")
.cwd(p.root().parent().unwrap()),
execs().with_status(1)
Expand All @@ -347,9 +350,10 @@ fn verify_project_dir_plus_file() {
fn verify_project_dir_plus_path() {
let p = project("foo")
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
.file("src/foo.rs", &main_file(r#""i am foo""#, &[]))
.build();

assert_that(p.cargo_process("verify-project")
assert_that(p.cargo("verify-project")
.arg("--manifest-path").arg("foo/bar/baz")
.cwd(p.root().parent().unwrap()),
execs().with_status(1)
Expand All @@ -360,8 +364,8 @@ fn verify_project_dir_plus_path() {

#[test]
fn verify_project_dir_to_nonexistent_cargo_toml() {
let p = project("foo");
assert_that(p.cargo_process("verify-project")
let p = project("foo").build();
assert_that(p.cargo("verify-project")
.arg("--manifest-path").arg("foo/bar/baz/Cargo.toml")
.cwd(p.root().parent().unwrap()),
execs().with_status(1)
Expand Down
Loading

0 comments on commit d43ee1d

Please sign in to comment.