Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errorfix(trycmd): Error, instead of ignore, unknown bins #148

Merged
merged 2 commits into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.