From 7ce662214c0f3f93807487f60e4920b7387c890c Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sun, 25 Jun 2017 20:44:00 +0000 Subject: [PATCH] Added more tests --- .travis.yml | 1 - Cargo.toml | 2 +- README.md | 1 + docs/api/src/cargo_make/cli.rs.html | 78 +++-- docs/api/src/cargo_make/command.rs.html | 112 ++++++++ docs/api/src/cargo_make/installer.rs.html | 332 +++++++++++++++------- docs/api/src/cargo_make/log.rs.html | 6 +- 7 files changed, 408 insertions(+), 124 deletions(-) diff --git a/.travis.yml b/.travis.yml index e61ad612..110577d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,6 @@ addons: script: - cargo install --debug cargo-make - cargo make --task ci-flow -after_script: - echo "Running coverage" - wget https://github.com/SimonKagstrom/kcov/archive/v$KCOV_VERSION.zip - unzip v$KCOV_VERSION.zip diff --git a/Cargo.toml b/Cargo.toml index 18832120..2bc03465 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cargo-make" -version = "0.2.3" +version = "0.2.4" authors = ["Sagie Gur-Ari "] description = "Rust task runner and build tool." license = "Apache-2.0" diff --git a/README.md b/README.md index 355a88bc..d4d696a0 100644 --- a/README.md +++ b/README.md @@ -414,6 +414,7 @@ See [contributing guide](.github/CONTRIBUTING.md) | Date | Version | Description | | ----------- | ------- | ----------- | +| 2017-06-25 | v0.2.4 | More tests | | 2017-06-25 | v0.2.3 | Added disabled task attribute support | | 2017-06-24 | v0.2.0 | Internal fixes (renamed dependencies attribute) | | 2017-06-24 | v0.1.2 | Print build time, added internal docs, unit tests and coverage | diff --git a/docs/api/src/cargo_make/cli.rs.html b/docs/api/src/cargo_make/cli.rs.html index aa2899f9..962ca166 100644 --- a/docs/api/src/cargo_make/cli.rs.html +++ b/docs/api/src/cargo_make/cli.rs.html @@ -96,6 +96,23 @@ 51 52 53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70
 //! # cli
 //!
@@ -107,47 +124,64 @@
 use log;
 use runner;
 
-/// Handles the command line arguments and executes the runner.
-pub fn run_cli() {
-    let name = "make";
-    let version = env!("CARGO_PKG_VERSION");
-    let author = env!("CARGO_PKG_AUTHORS");
-    let description = env!("CARGO_PKG_DESCRIPTION");
+static NAME: &str = "make";
+static VERSION: &str = env!("CARGO_PKG_VERSION");
+static AUTHOR: &str = env!("CARGO_PKG_AUTHORS");
+static DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
+static DEFAULT_TOML: &str = "Makefile.toml";
+
+fn run(
+    build_file: &str,
+    task: &str,
+    log_level: &str,
+) {
+    let logger = log::create(log_level);
+
+    logger.info::<()>("Using Build File: ", &[build_file], None);
+    logger.info::<()>("Task: ", &[task], None);
 
-    let default_toml = "Makefile.toml";
+    let config = descriptor::load(&build_file, &logger);
 
+    runner::run(&logger, &config, &task);
+}
+
+/// Handles the command line arguments and executes the runner.
+pub fn run_cli() {
     let mut build_file_arg = "-b, --buildFile=[FILE] 'Build toml file containing the build descriptor (default: ".to_string();
-    build_file_arg.push_str(&default_toml);
+    build_file_arg.push_str(&DEFAULT_TOML);
     build_file_arg.push_str(" if exists)'");
 
     let matches = App::new("cargo")
         .subcommand(
-            SubCommand::with_name(name)
-                .version(version)
-                .author(author)
-                .about(description)
+            SubCommand::with_name(NAME)
+                .version(VERSION)
+                .author(AUTHOR)
+                .about(DESCRIPTION)
                 .arg_from_usage(&build_file_arg)
                 .arg_from_usage("-t, --task=[TASK NAME] 'The task name to execute (default: default)'")
                 .arg(Arg::from_usage("-l, --loglevel=[LOG LEVEL] 'The log level (default: info)'").possible_values(&["verbose", "info", "error"]))
         )
         .get_matches();
 
-    match matches.subcommand_matches(name) {
+    match matches.subcommand_matches(NAME) {
         Some(cmd_matches) => {
-            let build_file = cmd_matches.value_of("buildFile").unwrap_or(&default_toml);
+            let build_file = cmd_matches.value_of("buildFile").unwrap_or(&DEFAULT_TOML);
             let task = cmd_matches.value_of("task").unwrap_or("default");
             let log_level = cmd_matches.value_of("loglevel").unwrap_or("info");
 
-            let logger = log::create(log_level);
-
-            logger.info::<()>("Using Build File: ", &[build_file], None);
-            logger.info::<()>("Task: ", &[task], None);
+            run(build_file, task, log_level);
+        }
+        None => panic!("cargo-{} not invoked via cargo command.", NAME),
+    }
+}
 
-            let config = descriptor::load(&build_file, &logger);
+#[cfg(test)]
+mod tests {
+    use super::*;
 
-            runner::run(&logger, &config, &task);
-        }
-        None => panic!("cargo-{} not invoked via cargo command.", name),
+    #[test]
+    fn run_empty_task() {
+        run("bad.toml", "empty", "error");
     }
 }
 
diff --git a/docs/api/src/cargo_make/command.rs.html b/docs/api/src/cargo_make/command.rs.html index 6099929d..65eabae1 100644 --- a/docs/api/src/cargo_make/command.rs.html +++ b/docs/api/src/cargo_make/command.rs.html @@ -219,6 +219,62 @@ 174 175 176 +177 +178 +179 +180 +181 +182 +183 +184 +185 +186 +187 +188 +189 +190 +191 +192 +193 +194 +195 +196 +197 +198 +199 +200 +201 +202 +203 +204 +205 +206 +207 +208 +209 +210 +211 +212 +213 +214 +215 +216 +217 +218 +219 +220 +221 +222 +223 +224 +225 +226 +227 +228 +229 +230 +231 +232
 //! # command
 //!
@@ -388,13 +444,69 @@
 #[cfg(test)]
 mod tests {
     use super::*;
+    use log;
     use std::io::ErrorKind;
+    use types::Task;
 
     #[test]
     #[should_panic]
     fn validate_exit_code_error() {
         validate_exit_code(Err(Error::new(ErrorKind::Other, "test")));
     }
+
+    #[test]
+    fn run_no_command() {
+        let logger = log::create("error");
+        let task = Task {
+            install_crate: None,
+            command: None,
+            args: None,
+            disabled: None,
+            alias: None,
+            install_script: None,
+            script: None,
+            dependencies: None
+        };
+        let step = Step { name: "test".to_string(), config: task };
+
+        run(&logger, &step);
+    }
+
+    #[test]
+    fn run_command() {
+        let logger = log::create("error");
+        let task = Task {
+            command: Some("echo".to_string()),
+            args: Some(vec!["1".to_string()]),
+            install_crate: None,
+            disabled: None,
+            alias: None,
+            install_script: None,
+            script: None,
+            dependencies: None
+        };
+        let step = Step { name: "test".to_string(), config: task };
+
+        run(&logger, &step);
+    }
+
+    #[test]
+    fn run_script() {
+        let logger = log::create("error");
+        let task = Task {
+            script: Some(vec!["echo 1".to_string()]),
+            command: None,
+            install_crate: None,
+            args: None,
+            disabled: None,
+            alias: None,
+            install_script: None,
+            dependencies: None
+        };
+        let step = Step { name: "test".to_string(), config: task };
+
+        run(&logger, &step);
+    }
 }
 
diff --git a/docs/api/src/cargo_make/installer.rs.html b/docs/api/src/cargo_make/installer.rs.html index eaa59229..013051df 100644 --- a/docs/api/src/cargo_make/installer.rs.html +++ b/docs/api/src/cargo_make/installer.rs.html @@ -43,103 +43,172 @@ -
 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
-10
-11
-12
-13
-14
-15
-16
-17
-18
-19
-20
-21
-22
-23
-24
-25
-26
-27
-28
-29
-30
-31
-32
-33
-34
-35
-36
-37
-38
-39
-40
-41
-42
-43
-44
-45
-46
-47
-48
-49
-50
-51
-52
-53
-54
-55
-56
-57
-58
-59
-60
-61
-62
-63
-64
-65
-66
-67
-68
-69
-70
-71
-72
-73
-74
-75
-76
-77
-78
-79
-80
-81
-82
-83
-84
-85
-86
-87
-88
-89
-90
-91
-92
-93
-94
-95
-96
-97
+    
  1
+  2
+  3
+  4
+  5
+  6
+  7
+  8
+  9
+ 10
+ 11
+ 12
+ 13
+ 14
+ 15
+ 16
+ 17
+ 18
+ 19
+ 20
+ 21
+ 22
+ 23
+ 24
+ 25
+ 26
+ 27
+ 28
+ 29
+ 30
+ 31
+ 32
+ 33
+ 34
+ 35
+ 36
+ 37
+ 38
+ 39
+ 40
+ 41
+ 42
+ 43
+ 44
+ 45
+ 46
+ 47
+ 48
+ 49
+ 50
+ 51
+ 52
+ 53
+ 54
+ 55
+ 56
+ 57
+ 58
+ 59
+ 60
+ 61
+ 62
+ 63
+ 64
+ 65
+ 66
+ 67
+ 68
+ 69
+ 70
+ 71
+ 72
+ 73
+ 74
+ 75
+ 76
+ 77
+ 78
+ 79
+ 80
+ 81
+ 82
+ 83
+ 84
+ 85
+ 86
+ 87
+ 88
+ 89
+ 90
+ 91
+ 92
+ 93
+ 94
+ 95
+ 96
+ 97
+ 98
+ 99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
 
 //! # installer
 //!
@@ -237,6 +306,75 @@
         let output = is_crate_installed(&logger, "badbadbad");
         assert!(!output);
     }
+
+    #[test]
+    fn install_empty() {
+        let logger = log::create("error");
+        let task = Task {
+            install_crate: None,
+            command: None,
+            args: None,
+            disabled: None,
+            alias: None,
+            install_script: None,
+            script: None,
+            dependencies: None
+        };
+
+        install(&logger, &task);
+    }
+
+    #[test]
+    fn install_crate_already_installed() {
+        let logger = log::create("error");
+        let task = Task {
+            install_crate: Some("test".to_string()),
+            command: Some("cargo".to_string()),
+            args: Some(vec!["test".to_string()]),
+            disabled: None,
+            alias: None,
+            install_script: None,
+            script: None,
+            dependencies: None
+        };
+
+        install(&logger, &task);
+    }
+
+    #[test]
+    #[should_panic]
+    fn install_crate_missing_cargo_command() {
+        let logger = log::create("error");
+        let task = Task {
+            install_crate: Some("test".to_string()),
+            command: Some("cargo".to_string()),
+            args: None,
+            disabled: None,
+            alias: None,
+            install_script: None,
+            script: None,
+            dependencies: None
+        };
+
+        install(&logger, &task);
+    }
+
+    #[test]
+    fn install_script_ok() {
+        let logger = log::create("error");
+        let task = Task {
+            install_script: Some(vec!["exit 0".to_string()]),
+            install_crate: None,
+            command: None,
+            args: None,
+            disabled: None,
+            alias: None,
+            script: None,
+            dependencies: None
+        };
+
+        install(&logger, &task);
+    }
 }
 
diff --git a/docs/api/src/cargo_make/log.rs.html b/docs/api/src/cargo_make/log.rs.html index ae2a0bdf..74544515 100644 --- a/docs/api/src/cargo_make/log.rs.html +++ b/docs/api/src/cargo_make/log.rs.html @@ -374,7 +374,7 @@ assert!(logger.is_verbose_enabled()); assert!(logger.is_info_enabled()); - logger.verbose::<()>("test", &[], None); + logger.verbose::<()>("test", &["test"], None); } #[test] @@ -384,7 +384,7 @@ assert!(!logger.is_verbose_enabled()); assert!(logger.is_info_enabled()); - logger.info::<()>("test", &[], None); + logger.info::<()>("test", &["test"], None); } #[test] @@ -395,7 +395,7 @@ assert!(!logger.is_verbose_enabled()); assert!(!logger.is_info_enabled()); - logger.error::<()>("test", &[], None); + logger.error::<()>("test", &["test"], None); } }