mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 00:44:57 +02:00
Remove file I/O from tests that don't need it (#11182)
# Description This PR implements modifications to command tests that write unnecessary json and csv to disk then load it with open, by using nuon literals instead. - Fixes #7189 # User-Facing Changes None # Tests + Formatting This only affects existing tests, which still pass.
This commit is contained in:
@ -1,40 +1,29 @@
|
||||
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
|
||||
#[test]
|
||||
fn groups() {
|
||||
Playground::setup("group_by_test_1", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[first_name, last_name, rusty_at, type];
|
||||
[Andrés, Robalino, "10/11/2013", A],
|
||||
[JT, Turner, "10/12/2013", B],
|
||||
[Yehuda, Katz, "10/11/2013", A]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.csv
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
{sample}
|
||||
| group-by rusty_at
|
||||
| get "10/11/2013"
|
||||
| length
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert_eq!(actual.out, "2");
|
||||
})
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_given_unknown_column_name() {
|
||||
Playground::setup("group_by_test_2", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.json",
|
||||
r#"
|
||||
let sample = r#"
|
||||
{
|
||||
"nu": {
|
||||
"committers": [
|
||||
@ -54,46 +43,33 @@ fn errors_if_given_unknown_column_name() {
|
||||
]
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)]);
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
r#"
|
||||
open los_tres_caballeros.json
|
||||
| group-by {|| get nu.releases.version }
|
||||
let actual = nu!(pipeline(&format!(
|
||||
r#"
|
||||
'{sample}'
|
||||
| from json
|
||||
| group-by {{|| get nu.releases.version }}
|
||||
"#
|
||||
));
|
||||
)));
|
||||
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("requires a table with one value for grouping"));
|
||||
})
|
||||
assert!(actual
|
||||
.err
|
||||
.contains("requires a table with one value for grouping"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn errors_if_column_not_found() {
|
||||
Playground::setup("group_by_test_3", |dirs, sandbox| {
|
||||
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
||||
"los_tres_caballeros.csv",
|
||||
r#"
|
||||
first_name,last_name,rusty_at,type
|
||||
Andrés,Robalino,10/11/2013,A
|
||||
JT,Turner,10/12/2013,B
|
||||
Yehuda,Katz,10/11/2013,A
|
||||
"#,
|
||||
)]);
|
||||
let sample = r#"
|
||||
[[first_name, last_name, rusty_at, type];
|
||||
[Andrés, Robalino, "10/11/2013", A],
|
||||
[JT, Turner, "10/12/2013", B],
|
||||
[Yehuda, Katz, "10/11/2013", A]]
|
||||
"#;
|
||||
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(), pipeline(
|
||||
"
|
||||
open los_tres_caballeros.csv
|
||||
| group-by ttype
|
||||
"
|
||||
));
|
||||
let actual = nu!(pipeline(&format!("{sample} | group-by ttype")));
|
||||
|
||||
assert!(actual.err.contains("did you mean 'type'"),);
|
||||
})
|
||||
assert!(actual.err.contains("did you mean 'type'"),);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Reference in New Issue
Block a user