Simplify tests
authorAleksey Kladov <aleksey.kladov@gmail.com>
Tue, 10 May 2016 23:52:02 +0000 (02:52 +0300)
committerAleksey Kladov <aleksey.kladov@gmail.com>
Wed, 11 May 2016 00:04:19 +0000 (03:04 +0300)
tests/support/mod.rs
tests/test_bad_config.rs
tests/test_cargo_install.rs

index bfaf48ca7b31f98308772ec27ce4e84bfa790c10..0837473250ce2c2e0d2b58892f728632a5d11332 100644 (file)
@@ -354,7 +354,7 @@ impl Execs {
                  description: &str, extra: &[u8],
                  partial: bool) -> ham::MatchResult {
         let out = match expected {
-            Some(out) => out,
+            Some(out) => substitute_macros(out),
             None => return ham::success(),
         };
         let actual = match str::from_utf8(actual) {
@@ -657,6 +657,32 @@ pub fn path2url(p: PathBuf) -> Url {
     Url::from_file_path(&*p).ok().unwrap()
 }
 
+fn substitute_macros(input: &str) -> String {
+    let macros = [
+        ("[RUNNING]",     "     Running"),
+        ("[COMPILING]",   "   Compiling"),
+        ("[ERROR]",       "error:"),
+        ("[DOCUMENTING]", " Documenting"),
+        ("[FRESH]",       "       Fresh"),
+        ("[UPDATING]",    "    Updating"),
+        ("[ADDING]",      "      Adding"),
+        ("[REMOVING]",    "    Removing"),
+        ("[DOCTEST]",     "   Doc-tests"),
+        ("[PACKAGING]",   "   Packaging"),
+        ("[DOWNLOADING]", " Downloading"),
+        ("[UPLOADING]",   "   Uploading"),
+        ("[VERIFYING]",   "   Verifying"),
+        ("[ARCHIVING]",   "   Archiving"),
+        ("[INSTALLING]",  "  Installing"),
+        ("[REPLACING]",   "   Replacing")
+    ];
+    let mut result = input.to_owned();
+    for &(pat, subst) in macros.iter() {
+        result = result.replace(pat, subst)
+    }
+    return result;
+}
+
 pub static RUNNING:     &'static str = "     Running";
 pub static COMPILING:   &'static str = "   Compiling";
 pub static ERROR:       &'static str = "error:";
index c0c36d0cded894ac46fb40fefdf68344d038d404..de882cdc4f3f725918e3f92e257d39908c79b633 100644 (file)
@@ -1,4 +1,4 @@
-use support::{project, execs, ERROR};
+use support::{project, execs};
 use support::registry::Package;
 use hamcrest::assert_that;
 
@@ -19,11 +19,10 @@ test!(bad1 {
         "#);
     assert_that(foo.cargo_process("build").arg("-v")
                    .arg("--target=nonexistent-target"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} expected table for configuration key `target.nonexistent-target`, \
+                execs().with_status(101).with_stderr("\
+[ERROR] expected table for configuration key `target.nonexistent-target`, \
 but found string in [..]config
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad2 {
@@ -40,8 +39,8 @@ test!(bad2 {
                 proxy = 3.0
         "#);
     assert_that(foo.cargo_process("publish").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} Couldn't load Cargo configuration
+                execs().with_status(101).with_stderr("\
+[ERROR] Couldn't load Cargo configuration
 
 Caused by:
   failed to load TOML configuration from `[..]config`
@@ -54,7 +53,7 @@ Caused by:
 
 Caused by:
   found TOML configuration value of unknown type `float`
-", error = ERROR)));
+"));
 });
 
 test!(bad3 {
@@ -71,11 +70,10 @@ test!(bad3 {
               proxy = true
         "#);
     assert_that(foo.cargo_process("publish").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} invalid configuration for key `http.proxy`
+                execs().with_status(101).with_stderr("\
+[ERROR] invalid configuration for key `http.proxy`
 expected a string, but found a boolean in [..]config
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad4 {
@@ -85,14 +83,13 @@ test!(bad4 {
               name = false
         "#);
     assert_that(foo.cargo_process("new").arg("-v").arg("foo"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} Failed to create project `foo` at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] Failed to create project `foo` at `[..]`
 
 Caused by:
   invalid configuration for key `cargo-new.name`
 expected a string, but found a boolean in [..]config
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad5 {
@@ -106,8 +103,8 @@ test!(bad5 {
     foo.build();
     assert_that(foo.cargo("new")
                    .arg("-v").arg("foo").cwd(&foo.root().join("foo")),
-                execs().with_status(101).with_stderr(&format!("\
-{error} Couldn't load Cargo configuration
+                execs().with_status(101).with_stderr("\
+[ERROR] Couldn't load Cargo configuration
 
 Caused by:
   failed to merge key `foo` between files:
@@ -116,8 +113,7 @@ Caused by:
 
 Caused by:
   expected integer, but found string
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad_cargo_config_jobs {
@@ -134,10 +130,9 @@ test!(bad_cargo_config_jobs {
         jobs = -1
     "#);
     assert_that(foo.cargo_process("build").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} build.jobs must be positive, but found -1 in [..]
-",
-    error = ERROR)));
+                execs().with_status(101).with_stderr("\
+[ERROR] build.jobs must be positive, but found -1 in [..]
+"));
 });
 
 test!(default_cargo_config_jobs {
@@ -189,8 +184,8 @@ test!(invalid_global_config {
     .file("src/lib.rs", "");
 
     assert_that(foo.cargo_process("build").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} Couldn't load Cargo configuration
+                execs().with_status(101).with_stderr("\
+[ERROR] Couldn't load Cargo configuration
 
 Caused by:
   could not parse TOML configuration in `[..]config`
@@ -199,8 +194,7 @@ Caused by:
   could not parse input as TOML
 [..]config:1:2 expected `=`, but found eof
 
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad_cargo_lock {
@@ -215,13 +209,12 @@ test!(bad_cargo_lock {
     .file("src/lib.rs", "");
 
     assert_that(foo.cargo_process("build").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse lock file at: [..]Cargo.lock
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse lock file at: [..]Cargo.lock
 
 Caused by:
   expected a section for the key `root`
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad_git_dependency {
@@ -238,16 +231,15 @@ test!(bad_git_dependency {
     .file("src/lib.rs", "");
 
     assert_that(foo.cargo_process("build").arg("-v"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} Unable to update file:///
+                execs().with_status(101).with_stderr("\
+[ERROR] Unable to update file:///
 
 Caused by:
   failed to clone into: [..]
 
 Caused by:
   [[..]] 'file:///' is not a valid local file URI
-",
-    error = ERROR)));
+"));
 });
 
 test!(bad_crate_type {
@@ -285,15 +277,14 @@ test!(malformed_override {
     .file("src/lib.rs", "");
 
     assert_that(foo.cargo_process("build"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse manifest at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
 
 Caused by:
   could not parse input as TOML
 Cargo.toml:[..]
 
-",
-    error = ERROR)));
+"));
 });
 
 test!(duplicate_binary_names {
@@ -316,13 +307,12 @@ test!(duplicate_binary_names {
     .file("b.rs", r#"fn main() -> () {}"#);
 
     assert_that(foo.cargo_process("build"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse manifest at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
 
 Caused by:
   found duplicate binary name e, but all binary targets must have a unique name
-",
-    error = ERROR)));
+"));
 });
 
 test!(duplicate_example_names {
@@ -345,13 +335,12 @@ test!(duplicate_example_names {
     .file("examples/ex2.rs", r#"fn main () -> () {}"#);
 
     assert_that(foo.cargo_process("build").arg("--example").arg("ex"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse manifest at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
 
 Caused by:
   found duplicate example name ex, but all binary targets must have a unique name
-",
-    error = ERROR)));
+"));
 });
 
 test!(duplicate_bench_names {
@@ -374,13 +363,12 @@ test!(duplicate_bench_names {
     .file("benches/ex2.rs", r#"fn main () {}"#);
 
     assert_that(foo.cargo_process("bench"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse manifest at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
 
 Caused by:
   found duplicate bench name ex, but all binary targets must have a unique name
-",
-    error = ERROR)));
+"));
 });
 
 test!(duplicate_deps {
@@ -418,13 +406,12 @@ test!(duplicate_deps {
     .file("src/main.rs", r#"fn main () {}"#);
 
     assert_that(foo.cargo_process("build"),
-                execs().with_status(101).with_stderr(&format!("\
-{error} failed to parse manifest at `[..]`
+                execs().with_status(101).with_stderr("\
+[ERROR] failed to parse manifest at `[..]`
 
 Caused by:
   found duplicate dependency name bar, but all dependencies must have a unique name
-",
-    error = ERROR)));
+"));
 });
 
 test!(unused_keys {
index f32ed786b55766124d8b67686d03b9c5fab88d7d..26408e6fad5e0b7736dd7023831da16cd998654f 100644 (file)
@@ -62,23 +62,18 @@ test!(simple {
 
     assert_that(cargo_process("install").arg("foo"),
                 execs().with_status(0).with_stdout(&format!("\
-{updating} registry `[..]`
-{downloading} foo v0.0.1 (registry file://[..])
-{compiling} foo v0.0.1 (registry file://[..])
-{installing} {home}[..]bin[..]foo[..]
+[UPDATING] registry `[..]`
+[DOWNLOADING] foo v0.0.1 (registry file://[..])
+[COMPILING] foo v0.0.1 (registry file://[..])
+[INSTALLING] {home}[..]bin[..]foo[..]
 ",
-        updating = UPDATING,
-        downloading = DOWNLOADING,
-        compiling = COMPILING,
-        installing = INSTALLING,
         home = cargo_home().display())));
     assert_that(cargo_home(), has_installed_exe("foo"));
 
     assert_that(cargo_process("uninstall").arg("foo"),
                 execs().with_status(0).with_stdout(&format!("\
-{removing} {home}[..]bin[..]foo[..]
+[REMOVING] {home}[..]bin[..]foo[..]
 ",
-        removing = REMOVING,
         home = cargo_home().display())));
     assert_that(cargo_home(), is_not(has_installed_exe("foo")));
 });