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

Allow Suppressing of Failing Commands with - Prefix #687

Merged
merged 2 commits into from
Oct 3, 2020
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
7 changes: 7 additions & 0 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,11 @@ impl<'src> Line<'src> {
_ => false,
}
}

pub(crate) fn is_infallable(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('-'),
_ => false,
}
}
}
8 changes: 6 additions & 2 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ impl<'src, D> Recipe<'src, D> {
let mut evaluated = String::new();
let mut continued = false;
let quiet_command = lines.peek().map(|line| line.is_quiet()).unwrap_or(false);
let infallable_command = lines
.peek()
.map(|line| line.is_infallable())
.unwrap_or(false);
loop {
if lines.peek().is_none() {
break;
Expand All @@ -226,7 +230,7 @@ impl<'src, D> Recipe<'src, D> {
}
}
let mut command = evaluated.as_str();
if quiet_command {
if quiet_command || infallable_command {
command = &command[1..];
}

Expand Down Expand Up @@ -266,7 +270,7 @@ impl<'src, D> Recipe<'src, D> {
match InterruptHandler::guard(|| cmd.status()) {
Ok(exit_status) =>
if let Some(code) = exit_status.code() {
if code != 0 {
if code != 0 && !infallable_command {
return Err(RuntimeError::Code {
recipe: self.name(),
line_number: Some(line_number),
Expand Down
24 changes: 24 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,6 +1285,30 @@ test! {
status: EXIT_FAILURE,
}

test! {
name: infallable_command,
justfile: r#"
infallable:
-exit 101
"#,
stderr: "exit 101\n",
status: EXIT_SUCCESS,
}

test! {
name: infallable_with_failing,
justfile: r#"
infallable:
-exit 101
exit 202
"#,
stderr: r#"exit 101
exit 202
error: Recipe `infallable` failed on line 4 with exit code 202
"#,
status: 202,
}

test! {
name: quiet_recipe,
justfile: r#"
Expand Down