Refactor tests (using cococo instead of ^echo) (#11479)

- related PR: #11478 

# Description

Now we can use `nu --testbin cococo` instead of `^echo` to echo messages
to stdout in tests.

But `nu` treats parameters as its own flags when parameter starts with
`-`. So `^echo --foo='bar'` still use `^echo`.

# User-Facing Changes

(none)

# Tests + Formatting

- [x] `cargo fmt --all -- --check` to check standard code formatting
(`cargo fmt --all` applies these changes)
- [x] `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used`
to check that you're using the standard code style
- [x] `cargo test --workspace` to check that all tests pass (on Windows
make sure to [enable developer
mode](https://learn.microsoft.com/en-us/windows/apps/get-started/developer-mode-features-and-debugging))
- [x] `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library


# After Submitting

(none)
This commit is contained in:
tomoda 2024-01-05 12:40:56 +09:00 committed by GitHub
parent ee5a18167c
commit ad95e4cc27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 12 deletions

View File

@ -197,7 +197,7 @@ fn def_wrapped_with_block() {
#[test] #[test]
fn def_wrapped_from_module() { fn def_wrapped_from_module() {
let actual = nu!(r#"module spam { let actual = nu!(r#"module spam {
export def --wrapped my-echo [...rest] { ^echo ...$rest } export def --wrapped my-echo [...rest] { nu --testbin cococo ...$rest }
} }
use spam use spam

View File

@ -139,14 +139,13 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds() {
}) })
} }
#[cfg(not(windows))]
#[test] #[test]
fn external_args_with_quoted() { fn external_args_with_quoted() {
Playground::setup("external failed command with semicolon", |dirs, _| { Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
^echo "foo=bar 'hi'" nu --testbin cococo "foo=bar 'hi'"
"# "#
)); ));
@ -187,14 +186,13 @@ fn external_arg_with_variable_name() {
}) })
} }
#[cfg(not(windows))]
#[test] #[test]
fn external_command_escape_args() { fn external_command_escape_args() {
Playground::setup("external failed command with semicolon", |dirs, _| { Playground::setup("external failed command with semicolon", |dirs, _| {
let actual = nu!( let actual = nu!(
cwd: dirs.test(), pipeline( cwd: dirs.test(), pipeline(
r#" r#"
^echo "\"abcd" nu --testbin cococo "\"abcd"
"# "#
)); ));
@ -308,13 +306,12 @@ fn can_run_batch_files_without_bat_extension() {
); );
} }
#[cfg(windows)]
#[test] #[test]
fn quotes_trimmed_when_shelling_out() { fn quotes_trimmed_when_shelling_out() {
// regression test for a bug where we weren't trimming quotes around string args before shelling out to cmd.exe // regression test for a bug where we weren't trimming quotes around string args before shelling out to cmd.exe
let actual = nu!(pipeline( let actual = nu!(pipeline(
r#" r#"
^echo "foo" nu --testbin cococo "foo"
"# "#
)); ));

View File

@ -85,7 +85,7 @@ fn execute_binary_in_string() {
#[test] #[test]
fn single_quote_dollar_external() { fn single_quote_dollar_external() {
let actual = nu!("let author = 'JT'; ^echo $'foo=($author)'"); let actual = nu!("let author = 'JT'; nu --testbin cococo $'foo=($author)'");
assert_eq!(actual.out, "foo=JT"); assert_eq!(actual.out, "foo=JT");
} }
@ -493,18 +493,16 @@ mod external_command_arguments {
) )
} }
#[cfg(not(windows))]
#[test] #[test]
fn semicolons_are_sanitized_before_passing_to_subshell() { fn semicolons_are_sanitized_before_passing_to_subshell() {
let actual = nu!("^echo \"a;b\""); let actual = nu!("nu --testbin cococo \"a;b\"");
assert_eq!(actual.out, "a;b"); assert_eq!(actual.out, "a;b");
} }
#[cfg(not(windows))]
#[test] #[test]
fn ampersands_are_sanitized_before_passing_to_subshell() { fn ampersands_are_sanitized_before_passing_to_subshell() {
let actual = nu!("^echo \"a&b\""); let actual = nu!("nu --testbin cococo \"a&b\"");
assert_eq!(actual.out, "a&b"); assert_eq!(actual.out, "a&b");
} }