mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
Fix try
printing when it is not the last pipeline element (#13992)
# Description Fixes #13991. This was done by more clearly separating the case when a pipeline is drained vs when it is being written (to a file). I also added an `OutDest::Print` case which might not be strictly necessary, but is a helpful addition. # User-Facing Changes Bug fix. # Tests + Formatting Added a test. # After Submitting There are still a few redirection bugs that I found, but they require larger code changes, so I'll leave them until after the release.
This commit is contained in:
@ -107,13 +107,22 @@ fn exit_code_available_in_catch() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_catches_exit_code_in_assignment() {
|
||||
fn catches_exit_code_in_assignment() {
|
||||
let actual = nu!("let x = try { nu -c 'exit 42' } catch { |e| $e.exit_code }; $x");
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn try_catches_exit_code_in_expr() {
|
||||
fn catches_exit_code_in_expr() {
|
||||
let actual = nu!("print (try { nu -c 'exit 42' } catch { |e| $e.exit_code })");
|
||||
assert_eq!(actual.out, "42");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn prints_only_if_last_pipeline() {
|
||||
let actual = nu!("try { 'should not print' }; 'last value'");
|
||||
assert_eq!(actual.out, "last value");
|
||||
|
||||
let actual = nu!("try { ['should not print'] | every 1 }; 'last value'");
|
||||
assert_eq!(actual.out, "last value");
|
||||
}
|
||||
|
Reference in New Issue
Block a user