Skip to content

Commit

Permalink
Auto merge of #56 - killercup:feature/list-missing-as-empty, r=killercup
Browse files Browse the repository at this point in the history
`cargo list` missing sections as empty

Based on @tbu-'s #42. This just adds integration tests for `cargo list`.
  • Loading branch information
homu committed Oct 24, 2015
2 parents 3f5bb9b + 225b35e commit 28bfe43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
5 changes: 5 additions & 0 deletions src/bin/list/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod list_error;
mod tree;

use list::list_section;
use list_error::ListError;
use tree::parse_lock_file as list_tree;

static USAGE: &'static str = r"
Expand Down Expand Up @@ -79,6 +80,10 @@ fn handle_list(args: &Args) -> Result<String, Box<Error>> {
} else {
let manifest = try!(Manifest::open(&args.flag_manifest_path.as_ref().map(|s| &s[..])));
list_section(&manifest, args.get_section())
.or_else(|err| match err {
ListError::SectionMissing(..) => Ok("".into()),
_ => Err(err),
})
}
.map_err(From::from)
}
Expand Down
38 changes: 28 additions & 10 deletions tests/cargo-list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
#[macro_use]
extern crate assert_cli;

#[test]
fn listing() {
assert_cli!("target/debug/cargo-list",
&["list", "--manifest-path=tests/fixtures/list/Cargo.toml"] =>
Success, r#"cargo-edit path: "../../../"
clippy git: "https://github.com/Manishearth/rust-clippy.git" (optional)
docopt 0.6
pad 0.1
rustc-serialize 0.3
semver 0.1
toml 0.1"#)
.unwrap();
}

#[test]
fn listing_dev() {
assert_cli!("target/debug/cargo-list",
Expand All @@ -18,17 +32,21 @@ fn listing_build() {
}

#[test]
fn listing() {
fn treat_missing_section_as_empty() {
// empty dependencies
assert_cli!("target/debug/cargo-list",
&["list", "--manifest-path=tests/fixtures/list/Cargo.toml"] =>
Success, r#"cargo-edit path: "../../../"
clippy git: "https://github.com/Manishearth/rust-clippy.git" (optional)
docopt 0.6
pad 0.1
rustc-serialize 0.3
semver 0.1
toml 0.1"#)
.unwrap();
&["list", "--manifest-path=tests/fixtures/list-empty/Cargo.toml"] =>
Success, "\n").unwrap();

// empty dev-dependencies
assert_cli!("target/debug/cargo-list",
&["list", "--dev", "--manifest-path=tests/fixtures/list-empty/Cargo.toml"] =>
Success, "\n").unwrap();

// empty build-dependencies
assert_cli!("target/debug/cargo-list",
&["list", "--build", "--manifest-path=tests/fixtures/list-empty/Cargo.toml"] =>
Success, "\n").unwrap();
}

#[test]
Expand Down
7 changes: 7 additions & 0 deletions tests/fixtures/list-empty/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "cargo-list-empty-test-fixture"
version = "0.1.0"

[[bin]]
name = "main"
path = "src/main.rs"

0 comments on commit 28bfe43

Please sign in to comment.