Skip to content

Commit

Permalink
Allow using - and @ in any order (#1063)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Jan 3, 2022
1 parent a3b25c1 commit 3372efe
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
10 changes: 7 additions & 3 deletions src/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ impl<'src> Line<'src> {

pub(crate) fn is_quiet(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('@'),
Some(Fragment::Text { token }) => {
token.lexeme().starts_with('@') || token.lexeme().starts_with("-@")
}
_ => false,
}
}

pub(crate) fn is_infallable(&self) -> bool {
pub(crate) fn is_infallible(&self) -> bool {
match self.fragments.first() {
Some(Fragment::Text { token }) => token.lexeme().starts_with('-'),
Some(Fragment::Text { token }) => {
token.lexeme().starts_with('-') || token.lexeme().starts_with("@-")
}
_ => false,
}
}
Expand Down
11 changes: 8 additions & 3 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'src, D> Recipe<'src, D> {
let mut evaluated = String::new();
let mut continued = false;
let quiet_command = lines.peek().map_or(false, |line| line.is_quiet());
let infallable_command = lines.peek().map_or(false, |line| line.is_infallable());
let infallible_command = lines.peek().map_or(false, |line| line.is_infallible());
loop {
if lines.peek().is_none() {
break;
Expand All @@ -229,7 +229,12 @@ impl<'src, D> Recipe<'src, D> {
}
}
let mut command = evaluated.as_str();
if quiet_command || infallable_command {

if quiet_command {
command = &command[1..];
}

if infallible_command {
command = &command[1..];
}

Expand Down Expand Up @@ -274,7 +279,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 && !infallable_command {
if code != 0 && !infallible_command {
return Err(Error::Code {
recipe: self.name(),
line_number: Some(line_number),
Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod init;
mod interrupts;
mod invocation_directory;
mod json;
mod line_prefixes;
mod misc;
mod positional_arguments;
mod quiet;
Expand Down
25 changes: 25 additions & 0 deletions tests/line_prefixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use crate::common::*;

#[test]
fn infallible_after_quiet() {
Test::new()
.justfile(
"
foo:
@-exit 1
",
)
.run();
}

#[test]
fn quiet_after_infallible() {
Test::new()
.justfile(
"
foo:
-@exit 1
",
)
.run();
}
10 changes: 5 additions & 5 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,25 +1035,25 @@ foo:
}

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

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

0 comments on commit 3372efe

Please sign in to comment.