Skip to content

Commit

Permalink
PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchieAtkinson committed Jan 12, 2025
1 parent dcab358 commit b27a26a
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 120 deletions.
10 changes: 5 additions & 5 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ use super::*;
pub(crate) enum Attribute<'src> {
Confirm(Option<StringLiteral<'src>>),
Doc(Option<StringLiteral<'src>>),
ExitMessage,
Extension(StringLiteral<'src>),
Group(StringLiteral<'src>),
Linux,
Macos,
NoCd,
NoExitMessage,
ExitMessage,
NoQuiet,
Openbsd,
PositionalArguments,
Expand All @@ -33,11 +33,11 @@ impl AttributeDiscriminant {
match self {
Self::Confirm | Self::Doc => 0..=1,
Self::Group | Self::Extension | Self::WorkingDirectory => 1..=1,
Self::Linux
Self::ExitMessage
| Self::Linux
| Self::Macos
| Self::NoCd
| Self::NoExitMessage
| Self::ExitMessage
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
Expand Down Expand Up @@ -80,13 +80,13 @@ impl<'src> Attribute<'src> {
Ok(match discriminant {
AttributeDiscriminant::Confirm => Self::Confirm(arguments.into_iter().next()),
AttributeDiscriminant::Doc => Self::Doc(arguments.into_iter().next()),
AttributeDiscriminant::ExitMessage => Self::ExitMessage,
AttributeDiscriminant::Extension => Self::Extension(arguments.into_iter().next().unwrap()),
AttributeDiscriminant::Group => Self::Group(arguments.into_iter().next().unwrap()),
AttributeDiscriminant::Linux => Self::Linux,
AttributeDiscriminant::Macos => Self::Macos,
AttributeDiscriminant::NoCd => Self::NoCd,
AttributeDiscriminant::NoExitMessage => Self::NoExitMessage,
AttributeDiscriminant::ExitMessage => Self::ExitMessage,
AttributeDiscriminant::NoQuiet => Self::NoQuiet,
AttributeDiscriminant::Openbsd => Self::Openbsd,
AttributeDiscriminant::PositionalArguments => Self::PositionalArguments,
Expand Down Expand Up @@ -132,11 +132,11 @@ impl Display for Attribute<'_> {
Self::Script(Some(shell)) => write!(f, "({shell})")?,
Self::Confirm(None)
| Self::Doc(None)
| Self::ExitMessage
| Self::Linux
| Self::Macos
| Self::NoCd
| Self::NoExitMessage
| Self::ExitMessage
| Self::NoQuiet
| Self::Openbsd
| Self::PositionalArguments
Expand Down
48 changes: 0 additions & 48 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,54 +724,6 @@ mod tests {
}
}

run_error! {
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! {
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
2 changes: 1 addition & 1 deletion src/keyword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ pub(crate) enum Keyword {
IgnoreComments,
Import,
Mod,
NoExitMessage,
PositionalArguments,
Quiet,
NoExitMessage,
ScriptInterpreter,
Set,
Shell,
Expand Down
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,9 @@ impl<'src> Node<'src> for Set<'src> {
| Setting::DotenvRequired(value)
| Setting::Export(value)
| Setting::Fallback(value)
| Setting::NoExitMessage(value)
| Setting::PositionalArguments(value)
| Setting::Quiet(value)
| Setting::NoExitMessage(value)
| Setting::Unstable(value)
| Setting::WindowsPowerShell(value)
| Setting::IgnoreComments(value) => {
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,9 @@ impl<'run, 'src> Parser<'run, 'src> {
Keyword::Export => Some(Setting::Export(self.parse_set_bool()?)),
Keyword::Fallback => Some(Setting::Fallback(self.parse_set_bool()?)),
Keyword::IgnoreComments => Some(Setting::IgnoreComments(self.parse_set_bool()?)),
Keyword::NoExitMessage => Some(Setting::NoExitMessage(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()?)),
Keyword::Unstable => Some(Setting::Unstable(self.parse_set_bool()?)),
Keyword::WindowsPowershell => Some(Setting::WindowsPowerShell(self.parse_set_bool()?)),
_ => None,
Expand Down
12 changes: 9 additions & 3 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,15 @@ impl<'src, D> Recipe<'src, D> {
}

fn print_exit_message(&self, settings: &Settings) -> bool {
self.attributes.contains(AttributeDiscriminant::ExitMessage)
|| (!settings.no_exit_message
&& !self.attributes.contains(AttributeDiscriminant::NoExitMessage))
if self.attributes.contains(AttributeDiscriminant::ExitMessage) {
return true;
}

if settings.no_exit_message {
return false;
}

!self.attributes.contains(AttributeDiscriminant::NoExitMessage)
}

fn working_directory<'a>(&'a self, context: &'a ExecutionContext) -> Option<PathBuf> {
Expand Down
4 changes: 2 additions & 2 deletions src/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub(crate) enum Setting<'src> {
Export(bool),
Fallback(bool),
IgnoreComments(bool),
NoExitMessage(bool),
PositionalArguments(bool),
Quiet(bool),
NoExitMessage(bool),
ScriptInterpreter(Interpreter<'src>),
Shell(Interpreter<'src>),
Tempdir(StringLiteral<'src>),
Expand All @@ -33,9 +33,9 @@ impl Display for Setting<'_> {
| Self::Export(value)
| Self::Fallback(value)
| Self::IgnoreComments(value)
| Self::NoExitMessage(value)
| Self::PositionalArguments(value)
| Self::Quiet(value)
| Self::NoExitMessage(value)
| Self::Unstable(value)
| Self::WindowsPowerShell(value) => write!(f, "{value}"),
Self::ScriptInterpreter(shell) | Self::Shell(shell) | Self::WindowsShell(shell) => {
Expand Down
8 changes: 4 additions & 4 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub(crate) struct Settings<'src> {
pub(crate) export: bool,
pub(crate) fallback: bool,
pub(crate) ignore_comments: bool,
pub(crate) no_exit_message: bool,
pub(crate) positional_arguments: bool,
pub(crate) quiet: bool,
pub(crate) no_exit_message: bool,
#[serde(skip)]
pub(crate) script_interpreter: Option<Interpreter<'src>>,
pub(crate) shell: Option<Interpreter<'src>>,
Expand Down Expand Up @@ -62,15 +62,15 @@ impl<'src> Settings<'src> {
Setting::IgnoreComments(ignore_comments) => {
settings.ignore_comments = ignore_comments;
}
Setting::NoExitMessage(no_exit_message) => {
settings.no_exit_message = no_exit_message;
}
Setting::PositionalArguments(positional_arguments) => {
settings.positional_arguments = positional_arguments;
}
Setting::Quiet(quiet) => {
settings.quiet = quiet;
}
Setting::NoExitMessage(no_exit_message) => {
settings.no_exit_message = no_exit_message;
}
Setting::ScriptInterpreter(script_interpreter) => {
settings.script_interpreter = Some(script_interpreter);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ struct Settings<'a> {
export: bool,
fallback: bool,
ignore_comments: bool,
no_exit_message: bool,
positional_arguments: bool,
quiet: bool,
no_exit_message: bool,
shell: Option<Interpreter<'a>>,
tempdir: Option<&'a str>,
unstable: bool,
Expand Down
130 changes: 76 additions & 54 deletions tests/no_exit_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,66 +130,88 @@ hello:
status: 100,
}

test! {
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]
fn recipe_exit_message_setting_suppressed() {
Test::new()
.justfile(
r#"
set no-exit-message
# This is a doc comment
hello:
@echo "Hello, World!"
@exit 100
"#,
)
.stdout("Hello, World!\n")
.status(100)
.run();
}


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]
fn shebang_exit_message_setting_suppressed() {
Test::new()
.justfile(
"
set no-exit-message
hello:
#!/usr/bin/env bash
echo 'Hello, World!'
exit 100
",
)
.stdout("Hello, World!\n")
.status(100)
.run();
}

test! {
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]
fn exit_message_override_no_exit_setting() {
Test::new()
.justfile(
"
set no-exit-message
[exit-message]
fail:
@exit 100
",
)
.status(100)
.stderr("error: Recipe `fail` failed on line 5 with exit code 100\n")
.run();
}

#[test]
fn exit_message_override_no_exit_attribute() {
Test::new()
.justfile(
"
[exit-message, no-exit-message]
fail:
@exit 100
",
)
.status(100)
.stderr("error: Recipe `fail` failed on line 3 with exit code 100\n")
.run();
}

test! {
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,
#[test]
fn exit_message_override_no_exit_setting_and_attribute() {
Test::new()
.justfile(
"
set no-exit-message
[exit-message, no-exit-message]
fail:
@exit 100
",
)
.status(100)
.stderr("error: Recipe `fail` failed on line 5 with exit code 100\n")
.run();
}

0 comments on commit b27a26a

Please sign in to comment.