Skip to content

Commit

Permalink
Merge pull request #148 from epage/error
Browse files Browse the repository at this point in the history
Errorfix(trycmd): Error, instead of ignore, unknown bins
  • Loading branch information
epage authored Oct 6, 2022
2 parents 165be6f + 95ca380 commit 438adcf
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
6 changes: 6 additions & 0 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
"Bin": {
"description": "Target under test",
"oneOf": [
{
"type": "string",
"enum": [
"ignore"
]
},
{
"type": "object",
"required": [
Expand Down
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: 6 additions & 7 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,17 @@ impl Case {
return Ok(output);
}

#[allow(unused_variables)]
match &step.bin {
Some(crate::schema::Bin::Path(_)) => {}
Some(crate::schema::Bin::Name(name)) => {
// 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
snapbox::debug!("bin={:?} not found", name);
assert_eq!(output.spawn.status, SpawnStatus::Skipped);
return Ok(output);
}
Some(crate::schema::Bin::Error(_)) => {}
// Unlike `Name`, this always represents a bug
None => {}
}

let cmd = step.to_command(cwd).map_err(|e| output.clone().error(e))?;
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

```
5 changes: 0 additions & 5 deletions tests/cmd/unresolved.trycmd

This file was deleted.

0 comments on commit 438adcf

Please sign in to comment.