Skip to content

Commit

Permalink
feat(trycmd): Ignore at the bin level
Browse files Browse the repository at this point in the history
This would allow a markdown code fence to interpserse supported and
unsupported commands without having to put a `? skipped`
  • Loading branch information
epage committed Oct 6, 2022
1 parent bd69224 commit 1e30596
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl BinRegistry {
let bin = self.resolve_name(&name);
Ok(bin)
}
crate::schema::Bin::Ignore => Ok(crate::schema::Bin::Ignore),
crate::schema::Bin::Error(err) => Err(err),
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,19 @@ impl Case {
return Ok(output);
}

match &step.bin {
// Will be handled by `Step::to_command`
Some(crate::schema::Bin::Path(_))
| Some(crate::schema::Bin::Name(_))
| Some(crate::schema::Bin::Error(_))
| None => {}
Some(crate::schema::Bin::Ignore) => {
// Unhandled by resolve
assert_eq!(output.spawn.status, SpawnStatus::Skipped);
return Ok(output);
}
}

let cmd = step.to_command(cwd).map_err(|e| output.clone().error(e))?;
let cmd_output = cmd
.output()
Expand Down
2 changes: 2 additions & 0 deletions src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ impl Step {
let bin = match &self.bin {
Some(Bin::Path(path)) => Ok(path.clone()),
Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {}", name).into()),
Some(Bin::Ignore) => Err("Internal error: tried to run an ignored bin".into()),
Some(Bin::Error(err)) => Err(err.clone()),
None => Err("No bin specified".into()),
}?;
Expand Down Expand Up @@ -683,6 +684,7 @@ impl Env {
pub enum Bin {
Path(std::path::PathBuf),
Name(String),
Ignore,
#[serde(skip)]
Error(crate::Error),
}
Expand Down
1 change: 1 addition & 0 deletions tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ fn cli_tests() {
t.skip("tests/cmd/timeout.toml");
}
t.extend_vars([("[EXAMPLE]", "example")]).unwrap();
t.register_bin("ignored-bin", trycmd::schema::Bin::Ignore);
}
6 changes: 6 additions & 0 deletions tests/cmd/ignored_bin.trycmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Ignored by test runner:
```
$ ignored-bin I have No Impact
I'm ignored too

```

0 comments on commit 1e30596

Please sign in to comment.