Add tests for different arguments given to read-manifest
authorCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Sat, 29 Aug 2015 16:08:12 +0000 (12:08 -0400)
committerCarol (Nichols || Goulding) <carol.nichols@gmail.com>
Tue, 1 Sep 2015 01:26:29 +0000 (21:26 -0400)
Right now, only passing --manifest-path an absolute path to the
parent directory of a Cargo.toml file works, but I think the other
tests should work as well for consistency with other commands that
optionally take --manifest-path.

tests/test_cargo_read_manifest.rs [new file with mode: 0644]
tests/tests.rs

diff --git a/tests/test_cargo_read_manifest.rs b/tests/test_cargo_read_manifest.rs
new file mode 100644 (file)
index 0000000..6f52bb6
--- /dev/null
@@ -0,0 +1,79 @@
+use support::{project, execs, main_file, basic_bin_manifest};
+use hamcrest::{assert_that};
+
+fn setup() {}
+
+fn read_manifest_output() -> String {
+    "\
+{\
+    \"name\":\"foo\",\
+    \"version\":\"0.5.0\",\
+    \"dependencies\":[],\
+    \"targets\":[{\
+        \"kind\":[\"bin\"],\
+        \"name\":\"foo\",\
+        \"src_path\":\"src[..]foo.rs\",\
+        \"metadata\":null\
+    }],\
+    \"manifest_path\":\"[..]Cargo.toml\"\
+}".into()
+}
+
+test!(cargo_read_manifest_path_to_cargo_toml_relative {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+    assert_that(p.cargo_process("read-manifest")
+                 .arg("--manifest-path").arg("foo/Cargo.toml")
+                 .cwd(p.root().parent().unwrap()),
+                execs().with_status(0)
+                       .with_stdout(read_manifest_output()));
+});
+
+test!(cargo_read_manifest_path_to_cargo_toml_absolute {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+    assert_that(p.cargo_process("read-manifest")
+                 .arg("--manifest-path").arg(p.root().join("Cargo.toml"))
+                 .cwd(p.root().parent().unwrap()),
+                execs().with_status(0)
+                       .with_stdout(read_manifest_output()));
+});
+
+test!(cargo_read_manifest_path_to_cargo_toml_parent_relative {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+    assert_that(p.cargo_process("read-manifest")
+                 .arg("--manifest-path").arg("foo")
+                 .cwd(p.root().parent().unwrap()),
+                execs().with_status(0)
+                       .with_stdout(read_manifest_output()));
+});
+
+test!(cargo_read_manifest_path_to_cargo_toml_parent_absolute {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+    assert_that(p.cargo_process("read-manifest")
+                 .arg("--manifest-path").arg(p.root())
+                 .cwd(p.root().parent().unwrap()),
+                execs().with_status(0)
+                       .with_stdout(read_manifest_output()));
+});
+
+test!(cargo_read_manifest_cwd {
+    let p = project("foo")
+        .file("Cargo.toml", &basic_bin_manifest("foo"))
+        .file("src/foo.rs", &main_file(r#""i am foo""#, &[]));
+
+    assert_that(p.cargo_process("read-manifest")
+                 .cwd(p.root()),
+                execs().with_status(0)
+                       .with_stdout(read_manifest_output()));
+});
index 570267a33d39fe49ce42111cd52c7e945320a318..e9c34dfb08896de24c5d1ed83f234adb889f4885 100644 (file)
@@ -51,6 +51,7 @@ mod test_cargo_new;
 mod test_cargo_package;
 mod test_cargo_profiles;
 mod test_cargo_publish;
+mod test_cargo_read_manifest;
 mod test_cargo_registry;
 mod test_cargo_run;
 mod test_cargo_rustc;