Skip to content

Commit

Permalink
Auto merge of #52 - rgardner:rm-add-tests, r=killercup
Browse files Browse the repository at this point in the history
Add tests for removing existing dependencies

This adds `remove_existing_dependency` and
`remove_existing_dependency_from_specific_section` to test removing
dependencies from arbitrary, build, and dev sections.

This also modifies the Cargo.toml fixture to add a build section to test
removing from this section.
  • Loading branch information
homu committed Oct 23, 2015
2 parents 1095316 + 7cf1ad9 commit 0d3f304
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
33 changes: 32 additions & 1 deletion tests/cargo-rm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ extern crate assert_cli;
mod utils;
use utils::{clone_out_test, execute_command, get_toml};

#[test]
fn remove_existing_dependency() {
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/rm/Cargo.toml");

let toml = get_toml(&manifest);
assert!(toml.lookup("dependencies.docopt").is_some());
execute_command(&["rm","docopt"], &manifest);
let toml = get_toml(&manifest);
assert!(toml.lookup("dependencies.docopt").is_none());
}

#[test]
fn remove_existing_dependency_from_specific_section() {
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/rm/Cargo.toml");

// Test removing dev dependency.
let toml = get_toml(&manifest);
assert!(toml.lookup("dev-dependencies.regex").is_some());
execute_command(&["rm", "--dev", "regex"], &manifest);
let toml = get_toml(&manifest);
assert!(toml.lookup("dev-dependencies.regex").is_none());

// Test removing build dependency.
let toml = get_toml(&manifest);
assert!(toml.lookup("build-dependencies.semver").is_some());
execute_command(&["rm", "--build", "semver"], &manifest);
let toml = get_toml(&manifest);
assert!(toml.lookup("build-dependencies.semver").is_none());
}

#[test]
fn remove_section_after_removed_last_dependency() {
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/rm/Cargo.toml");
Expand All @@ -12,7 +42,7 @@ fn remove_section_after_removed_last_dependency() {
assert!(toml.lookup("dev-dependencies.regex").is_some());
assert_eq!(toml.lookup("dev-dependencies").unwrap().as_table().unwrap().len(), 1);

execute_command(&["rm", "-D", "regex"], &manifest);
execute_command(&["rm", "--dev", "regex"], &manifest);

let toml = get_toml(&manifest);
assert!(toml.lookup("dev-dependencies.regex").is_none());
Expand Down Expand Up @@ -58,6 +88,7 @@ ERROR: The dependency `invalid_dependency_name` could not be found in `dependenc
fn invalid_section() {
let (_tmpdir, manifest) = clone_out_test("tests/fixtures/rm/Cargo.toml");

execute_command(&["rm", "semver", "--build"], &manifest);
assert_cli!("target/debug/cargo-rm",
&["rm", "semver", "--build", &format!("--manifest-path={}", manifest)]
=> Error 1, "Could not edit `Cargo.toml`.
Expand Down
5 changes: 2 additions & 3 deletions tests/fixtures/rm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ version = "0.1.0"
name = "main"
path = "src/main.rs"

[features]
default = []
dev = ["clippy"]
[build-dependencies]
semver = "0.1.0"

[dependencies]
docopt = "0.6"
Expand Down

0 comments on commit 0d3f304

Please sign in to comment.