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

Remove file I/O from tests that don't need it #11182

Merged
merged 16 commits into from Nov 29, 2023

Conversation

cosineblast
Copy link
Contributor

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.

User-Facing Changes

None

Tests + Formatting

This only affects existing tests, which still pass.

After Submitting

None

Copy link
Collaborator

@WindSoilder WindSoilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for taking this! Really appreciated it!

I leaved some comments, mostly about format! macro usage.

continue;
.find(|term_str| contains_ignore_case(&val_str, term_str))
else {
continue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's wrongly formatted, would you please run cargo fmt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, that's a bit weird, but I did run cargo fmt:
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let ... = ... else {} formatting was only stabilized in very recent versions of rustfmt and may possibly still be treated preserved depending on the active toolchain version?

crates/nu-command/tests/commands/compact.rs Outdated Show resolved Hide resolved
tests/shell/pipeline/commands/internal.rs Outdated Show resolved Hide resolved
Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking care of all that!

I can only see two tests where should probably preserve the use of files.

Comment on lines 29 to 45
let sample = r#"
[[name, rusty_luck, origin];
[Jason, 1, Canada]]
"#;

let actual = nu!(
cwd: dirs.test(), pipeline(
let actual = nu!(pipeline(&format!(
"
mkdir temp;
cd temp;
print (open ../nu_times.csv).name.0 | table;
print (echo {sample}).name.0 | table;
cd ..;
rmdir temp
"
));
)));

// chop will remove the last escaped double quote from \"Estados Unidos\"
assert_eq!(actual.out, "Jason");
})
// chop will remove the last escaped double quote from \"Estados Unidos\"
assert_eq!(actual.out, "Jason");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title of the test suggests that this is to check that open ../nu_times.csv is properly handled.

So this probably has to be reverted.

Comment on lines 76 to 106
fn subexpression_handles_dot() {
Playground::setup("subexpression_handles_dot", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContentToBeTrimmed(
"nu_times.csv",
"
name,rusty_luck,origin
Jason,1,Canada
JT,1,New Zealand
Andrés,1,Ecuador
AndKitKatz,1,Estados Unidos
",
)]);

let actual = nu!(
cwd: dirs.test(), pipeline(
let sample = r#"
[[name, rusty_luck, origin];
[Jason, 1, Canada],
[JT, 1, "New Zealand"],
[Andrés, 1, Ecuador],
[AndKitKatz, 1, "Estados Unidos"]]
"#;

let actual = nu!(pipeline(&format!(
"
echo (open nu_times.csv)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the title this sounds like it should check for (open nu_times.csv) being handled correctly.

Else the whole construct with echo (open ...) doesn't make much sense.

Maybe the rest of the test can be simplified to make it a bit less confusing but else we should preserve that based on whatever forced us to add it in the first place.

Comment on lines +77 to +80
{sample}
| wrap name
| default "arepa!" hit
| rename --column {}
| rename --column {{}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it makes sense here to simply move the sample string into the pipe so we don't need the double {{}} here but that is just a stylistic minutia.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is better to keep the formatting inside the pipeline, as the sample data contains multiple lines, and nu! treats all lines in its argument as separate commands.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right!

Copy link
Member

@sholderbach sholderbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the iterations! Looking good and like a nice simplification

@sholderbach sholderbach dismissed WindSoilder’s stale review November 29, 2023 22:21

Suggestions implemented

@sholderbach sholderbach merged commit 54d7374 into nushell:main Nov 29, 2023
19 checks passed
hardfau1t pushed a commit to hardfau1t/nushell that referenced this pull request Dec 14, 2023
# 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 nushell#7189



# User-Facing Changes
None

# Tests + Formatting
This only affects existing tests, which still pass.
dmatos2012 pushed a commit to dmatos2012/nushell that referenced this pull request Feb 20, 2024
# 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 nushell#7189



# User-Facing Changes
None

# Tests + Formatting
This only affects existing tests, which still pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tests: Remove file I/O from all tests that don't need it
3 participants