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

simplify the test for let core command #9671

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 9 additions & 40 deletions crates/nu-command/tests/commands/let_.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
use nu_test_support::{nu, pipeline};

Check warning on line 1 in crates/nu-command/tests/commands/let_.rs

View workflow job for this annotation

GitHub Actions / tests (windows-latest, default)

unused import: `pipeline`

Check warning on line 1 in crates/nu-command/tests/commands/let_.rs

View workflow job for this annotation

GitHub Actions / tests (macos-latest, default)

unused import: `pipeline`

Check warning on line 1 in crates/nu-command/tests/commands/let_.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, default)

unused import: `pipeline`

Check warning on line 1 in crates/nu-command/tests/commands/let_.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, dataframe)

unused import: `pipeline`

Check warning on line 1 in crates/nu-command/tests/commands/let_.rs

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, extra)

unused import: `pipeline`

#[test]
fn let_name_builtin_var() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let in = 3
"#
));
let actual = nu!("let in = 3");

assert!(actual
.err
Expand All @@ -16,60 +11,37 @@

#[test]
fn let_doesnt_mutate() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let i = 3; $i = 4
"#
));
let actual = nu!("let i = 3; $i = 4");

assert!(actual.err.contains("immutable"));
}

#[test]
fn let_takes_pipeline() {
let actual = nu!(
cwd: ".", pipeline(
r#"
let x = "hello world" | str length; print $x
"#
));
let actual = nu!(r#"let x = "hello world" | str length; print $x"#);

assert_eq!(actual.out, "11");
}

#[test]
fn let_pipeline_allows_in() {
let actual = nu!(
cwd: ".", pipeline(
r#"
def foo [] { let x = $in | str length; print ($x + 10) }; "hello world" | foo
"#
));
let actual =
nu!(r#"def foo [] { let x = $in | str length; print ($x + 10) }; "hello world" | foo"#);

assert_eq!(actual.out, "21");
}

#[test]
fn mut_takes_pipeline() {
let actual = nu!(
cwd: ".", pipeline(
r#"
mut x = "hello world" | str length; print $x
"#
));
let actual = nu!(r#"mut x = "hello world" | str length; print $x"#);

assert_eq!(actual.out, "11");
}

#[test]
fn mut_pipeline_allows_in() {
let actual = nu!(
cwd: ".", pipeline(
r#"
def foo [] { mut x = $in | str length; print ($x + 10) }; "hello world" | foo
"#
));
let actual =
nu!(r#"def foo [] { mut x = $in | str length; print ($x + 10) }; "hello world" | foo"#);

assert_eq!(actual.out, "21");
}
Expand All @@ -79,10 +51,7 @@
fn let_with_external_failed() {
// FIXME: this test hasn't run successfully for a long time. We should
// bring it back to life at some point.
let actual = nu!(
cwd: ".",
pipeline(r#"let x = nu --testbin outcome_err "aa"; echo fail"#)
);
let actual = nu!(r#"let x = nu --testbin outcome_err "aa"; echo fail"#);

assert!(!actual.out.contains("fail"));
}