Skip to content

Commit

Permalink
tests: fix for empty command removal
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkal committed Aug 6, 2020
1 parent 07ac432 commit 6213d59
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/executor.rs
Expand Up @@ -72,8 +72,8 @@ pub fn execute_command(
fixed_dir: bool,
) -> Option<io::Result<process::ExitStatus>> {
if cmd.script.source == "" {
let msg = "CommandBlock has no script.";
return Some(Err(io::Error::new(io::ErrorKind::Other, msg)));
let msg = "CommandBlock has no script."; // cov:include (unusual)
return Some(Err(io::Error::new(io::ErrorKind::Other, msg))); // cov:include
}

if cmd.script.executor == "" && !cmd.script.source.trim().starts_with("#!") {
Expand Down Expand Up @@ -251,7 +251,7 @@ fn add_flag_variables(mut child: process::Command, cmd: &CommandBlock) -> proces
// Add all required args as environment variables
for arg in &cmd.args {
let val = if arg.val.is_empty() && arg.default.is_some() {
arg.default
arg.default // cov:include (tested by default_args integration)
.as_ref()
.expect("unable to ref command default arg")
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/parser.rs
Expand Up @@ -466,6 +466,9 @@ echo "Ignore me"
## string
OPTIONS
- flag: -s --str |string| A string
```
echo "the string is $str"
```
"#,
)
.expect("build tree failed");
Expand Down Expand Up @@ -600,15 +603,12 @@ echo "abc"
}

#[test]
fn does_not_add_verbose_optional_flag_to_command_with_no_script() {
fn excludes_no_script() {
let tree = build_command_structure(TEST_INKJETFILE).expect("build tree failed");
let no_script_command = tree
.subcommands
.iter()
.find(|cmd| cmd.name == "no_script")
.expect("no_script command missing");

assert_eq!(no_script_command.option_flags.len(), 0);
let cmd = tree.subcommands.iter().find(|cmd| cmd.name == "no_script");
if cmd.is_some() {
panic!("docs command should not exist")
}
}

#[test]
Expand Down
15 changes: 14 additions & 1 deletion src/runner.rs
Expand Up @@ -518,9 +518,22 @@ fn not_number_err_msg(name: &str) -> String {
}

#[cfg(test)]
mod main_tests {
mod runner_tests {
use super::*;
#[test]
fn fake_language() {
let contents = r#"
## default
```fake
echo "This should not run"
```
"#;
let args = svec!("inkjet", "--inkfile", contents);
let (rc, err_str, _) = run(args, false);
assert_eq!(rc, 10);
assert_eq!(err_str, "No such file or directory (os error 2)");
}
#[test]
fn numbers() {
let is_f = is_invalid_number(false, "string");
assert_eq!(is_f, false);
Expand Down
10 changes: 8 additions & 2 deletions tests/arguments_and_flags_test.rs
Expand Up @@ -275,8 +275,14 @@ mod version_flag {

#[test]
fn exits_with_error_when_subcommand_has_version_flag() {
let (_temp, inkfile_path) = common::inkfile("## foo");

let (_temp, inkfile_path) = common::inkfile(
r#"
## foo
```
echo "boo"
```
"#,
);
// The setting "VersionlessSubcommands" removes the version flags (-V, --version)
// from subcommands. Only the root command has a version flag.

Expand Down
9 changes: 7 additions & 2 deletions tests/subcommands_test.rs
Expand Up @@ -45,6 +45,9 @@ fn exits_with_error_when_missing_subcommand() {
r#"
## service
### service start
```
echo "starting...
```
"#,
);

Expand Down Expand Up @@ -90,8 +93,10 @@ echo "system, online"
common::run_inkjet(&inkfile_path)
.command("start")
.assert()
.code(10)
.stderr(contains("CommandBlock has no script."))
.code(1)
.stderr(contains(
"which wasn't expected, or isn't valid in this context",
))
.failure();
}
}

0 comments on commit 6213d59

Please sign in to comment.