mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 08:06:03 +02:00
ensure that when nu evaluates files, it allows early returns (#7415)
# Description Fixes #7301. # User-Facing Changes `return` can now be used in scripts without explicit `def main`. # Tests + Formatting Don't forget to add tests that cover your changes. (I'm not sure how to test this.) Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
@ -23,3 +23,15 @@ fn early_return_if_false() {
|
||||
|
||||
assert_eq!(actual.out, r#"100"#);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn return_works_in_script_without_def_main() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
nu early_return.nu
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
@ -314,3 +314,15 @@ fn source_env_const_file() {
|
||||
assert_eq!(actual.out, "foo");
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn source_respects_early_return() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats", pipeline(
|
||||
r#"
|
||||
source early_return.nu
|
||||
"#
|
||||
));
|
||||
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
Reference in New Issue
Block a user