Input output checking (#9680)

# Description

This PR tights input/output type-checking a bit more. There are a lot of
commands that don't have correct input/output types, so part of the
effort is updating them.

This PR now contains updates to commands that had wrong input/output
signatures. It doesn't add examples for these new signatures, but that
can be follow-up work.

# User-Facing Changes

BREAKING CHANGE BREAKING CHANGE

This work enforces many more checks on pipeline type correctness than
previous nushell versions. This strictness may uncover incompatibilities
in existing scripts or shortcomings in the type information for internal
commands.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- -c "use std testing; testing run-tests --path
crates/nu-std"` to run the tests for the standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
JT
2023-07-14 15:20:35 +12:00
committed by GitHub
parent e66139e6bb
commit 786ba3bf91
89 changed files with 480 additions and 106 deletions

View File

@ -91,5 +91,5 @@ fn nth_missing_first_argument() {
fn fail_on_non_iterator() {
let actual = nu!("1 | drop 50");
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -78,7 +78,7 @@ fn last_errors_on_negative_index() {
fn fail_on_non_iterator() {
let actual = nu!("1 | last");
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}
#[test]

View File

@ -32,5 +32,5 @@ fn can_round_float_with_negative_precision() {
fn fails_with_wrong_input_type() {
let actual = nu!("\"not_a_number\" | math round");
assert!(actual.err.contains("Input type not supported"))
assert!(actual.err.contains("command doesn't support"))
}

View File

@ -70,7 +70,6 @@ fn print_created_paths() {
pipeline(
r#"
mkdir -v dir_1 dir_2 dir_3
| length
"#
));

View File

@ -83,7 +83,7 @@ fn errors_if_no_columns_present() {
"#
));
assert!(actual.err.contains("only record input data is supported"));
assert!(actual.err.contains("command doesn't support"));
})
}

View File

@ -14,5 +14,5 @@ fn can_get_reverse_first() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | reverse"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -19,5 +19,5 @@ fn binary_skip() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip 2"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -54,5 +54,5 @@ fn condition_is_met() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip until {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -54,5 +54,5 @@ fn condition_is_met() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | skip while {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -126,5 +126,5 @@ fn no_column_specified_fails() {
fn fail_on_non_iterator() {
let actual = nu!("1 | sort-by");
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -51,7 +51,7 @@ fn fails_on_string() {
"#
));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}
#[test]

View File

@ -55,5 +55,5 @@ fn condition_is_met() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | take until {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -54,5 +54,5 @@ fn condition_is_met() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline("1 | take while {|row| $row == 2}"));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}

View File

@ -180,7 +180,7 @@ fn contains_operator() {
fn fail_on_non_iterator() {
let actual = nu!(cwd: ".", pipeline(r#"{"name": "foo", "size": 3} | where name == "foo""#));
assert!(actual.err.contains("only_supports_this_input_type"));
assert!(actual.err.contains("command doesn't support"));
}
// Test that filtering on columns that might be missing/null works

View File

@ -405,5 +405,5 @@ fn string_to_csv_error() {
"#
));
assert!(actual.err.contains("can't convert"))
assert!(actual.err.contains("command doesn't support"))
}

View File

@ -70,7 +70,7 @@ fn table_to_toml_fails() {
"#
));
assert_eq!(actual.out, "true");
assert!(actual.err.contains("command doesn't support"));
}
#[test]
@ -83,7 +83,7 @@ fn string_to_toml_fails() {
"#
));
assert_eq!(actual.out, "true");
assert!(actual.err.contains("command doesn't support"));
}
#[test]