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

Adds no-exit-message Setting and [exit-message] attribute #2568

Merged
merged 12 commits into from
Jan 22, 2025
4 changes: 4 additions & 0 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) enum Attribute<'src> {
Macos,
NoCd,
NoExitMessage,
ExitMessage,
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
NoQuiet,
Openbsd,
PositionalArguments,
Expand All @@ -36,6 +37,7 @@ impl AttributeDiscriminant {
| Self::Macos
| Self::NoCd
| Self::NoExitMessage
| Self::ExitMessage
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
Expand Down Expand Up @@ -84,6 +86,7 @@ impl<'src> Attribute<'src> {
AttributeDiscriminant::Macos => Self::Macos,
AttributeDiscriminant::NoCd => Self::NoCd,
AttributeDiscriminant::NoExitMessage => Self::NoExitMessage,
AttributeDiscriminant::ExitMessage => Self::ExitMessage,
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
AttributeDiscriminant::NoQuiet => Self::NoQuiet,
AttributeDiscriminant::Openbsd => Self::Openbsd,
AttributeDiscriminant::PositionalArguments => Self::PositionalArguments,
Expand Down Expand Up @@ -133,6 +136,7 @@ impl Display for Attribute<'_> {
| Self::Macos
| Self::NoCd
| Self::NoExitMessage
| Self::ExitMessage
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
Expand Down
48 changes: 48 additions & 0 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,54 @@ mod tests {
}
}

run_error! {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
name: exit_message_error,
src: "
set no-exit-message

[exit-message]
fail:
@exit 100
",
args: ["fail"],
error: Code {
recipe,
line_number,
code,
print_message,
},
check: {
assert_eq!(recipe, "fail");
assert_eq!(code, 100);
assert_eq!(line_number, Some(5));
assert!(print_message);
}
}

run_error! {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
name: exit_message_overrides_error,
src: "
set no-exit-message

[exit-message, no-exit-message]
fail:
@exit 100
",
args: ["fail"],
error: Code {
recipe,
line_number,
code,
print_message,
},
check: {
assert_eq!(recipe, "fail");
assert_eq!(code, 100);
assert_eq!(line_number, Some(5));
assert!(print_message);
}
}

fn case(input: &str, expected: &str) {
let justfile = compile(input);
let actual = format!("{}", justfile.color_display(Color::never()));
Expand Down
1 change: 1 addition & 0 deletions src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub(crate) enum Keyword {
Mod,
PositionalArguments,
Quiet,
NoExitMessage,
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
ScriptInterpreter,
Set,
Shell,
Expand Down
1 change: 1 addition & 0 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl<'src> Node<'src> for Set<'src> {
| Setting::Fallback(value)
| Setting::PositionalArguments(value)
| Setting::Quiet(value)
| Setting::NoExitMessage(value)
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
| Setting::Unstable(value)
| Setting::WindowsPowerShell(value)
| Setting::IgnoreComments(value) => {
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,7 @@ impl<'run, 'src> Parser<'run, 'src> {
Keyword::IgnoreComments => Some(Setting::IgnoreComments(self.parse_set_bool()?)),
Keyword::PositionalArguments => Some(Setting::PositionalArguments(self.parse_set_bool()?)),
Keyword::Quiet => Some(Setting::Quiet(self.parse_set_bool()?)),
Keyword::NoExitMessage => Some(Setting::NoExitMessage(self.parse_set_bool()?)),
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
Keyword::Unstable => Some(Setting::Unstable(self.parse_set_bool()?)),
Keyword::WindowsPowershell => Some(Setting::WindowsPowerShell(self.parse_set_bool()?)),
_ => None,
Expand Down
12 changes: 6 additions & 6 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ impl<'src, D> Recipe<'src, D> {
|| (cfg!(windows) && windows)
}

fn print_exit_message(&self) -> bool {
!self
.attributes
.contains(AttributeDiscriminant::NoExitMessage)
fn print_exit_message(&self, settings: &Settings) -> bool {
casey marked this conversation as resolved.
Show resolved Hide resolved
self.attributes.contains(AttributeDiscriminant::ExitMessage)
|| (!settings.no_exit_message
&& !self.attributes.contains(AttributeDiscriminant::NoExitMessage))
}

fn working_directory<'a>(&'a self, context: &'a ExecutionContext) -> Option<PathBuf> {
Expand Down Expand Up @@ -304,7 +304,7 @@ impl<'src, D> Recipe<'src, D> {
recipe: self.name(),
line_number: Some(line_number),
code,
print_message: self.print_exit_message(),
print_message: self.print_exit_message(&context.module.settings),
});
}
} else {
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<'src, D> Recipe<'src, D> {
recipe: self.name(),
line_number: None,
code,
print_message: self.print_exit_message(),
print_message: self.print_exit_message(&context.module.settings),
})
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) enum Setting<'src> {
IgnoreComments(bool),
PositionalArguments(bool),
Quiet(bool),
NoExitMessage(bool),
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
ScriptInterpreter(Interpreter<'src>),
Shell(Interpreter<'src>),
Tempdir(StringLiteral<'src>),
Expand All @@ -34,6 +35,7 @@ impl Display for Setting<'_> {
| Self::IgnoreComments(value)
| Self::PositionalArguments(value)
| Self::Quiet(value)
| Self::NoExitMessage(value)
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
| Self::Unstable(value)
| Self::WindowsPowerShell(value) => write!(f, "{value}"),
Self::ScriptInterpreter(shell) | Self::Shell(shell) | Self::WindowsShell(shell) => {
Expand Down
4 changes: 4 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub(crate) struct Settings<'src> {
pub(crate) ignore_comments: bool,
pub(crate) positional_arguments: bool,
pub(crate) quiet: bool,
pub(crate) no_exit_message: bool,
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
#[serde(skip)]
pub(crate) script_interpreter: Option<Interpreter<'src>>,
pub(crate) shell: Option<Interpreter<'src>>,
Expand Down Expand Up @@ -67,6 +68,9 @@ impl<'src> Settings<'src> {
Setting::Quiet(quiet) => {
settings.quiet = quiet;
}
Setting::NoExitMessage(no_exit_message) => {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
settings.no_exit_message = no_exit_message;
}
Setting::ScriptInterpreter(script_interpreter) => {
settings.script_interpreter = Some(script_interpreter);
}
Expand Down
1 change: 1 addition & 0 deletions tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ struct Settings<'a> {
ignore_comments: bool,
positional_arguments: bool,
quiet: bool,
no_exit_message: bool,
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
shell: Option<Interpreter<'a>>,
tempdir: Option<&'a str>,
unstable: bool,
Expand Down
64 changes: 64 additions & 0 deletions tests/no_exit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,67 @@ hello:
stderr: "",
status: 100,
}

test! {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
name: recipe_exit_message_setting_suppressed,
justfile: r#"
set no-exit-message

# This is a doc comment
hello:
@echo "Hello, World!"
@exit 100
"#,
stdout: "Hello, World!\n",
stderr: "",
status: 100,
}


test! {
name: shebang_exit_message_setting_suppressed,
justfile: r"
set no-exit-message

hello:
#!/usr/bin/env bash
echo 'Hello, World!'
exit 100
",
stdout: "Hello, World!\n",
stderr: "",
status: 100,
}

test! {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
name: exit_message_attribute_and_setting,
justfile: r"
set no-exit-message

[no-exit-message]
hello:
echo 'Hello, World!'
exit 100
",
stdout: "Hello, World!\n",
stderr: r#"
echo 'Hello, World!'
exit 100
"#,
status: 100,
}


test! {
ArchieAtkinson marked this conversation as resolved.
Show resolved Hide resolved
name: silent_recipe_exit_message_setting_suppressed,
justfile: r#"
set no-exit-message

@hello:
echo "Hello, World!"
exit 100
"#,
stdout: "Hello, World!\n",
stderr: "",
status: 100,
}