mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 06:30:08 +02:00
fix(nu-command/tests): further remove unnecessary pipeline() and cwd() (#8793)
# Description This PR further fixes tests as part of #8670 # User-Facing Changes None # Tests + Formatting None # After Submitting None --------- Signed-off-by: Harshal Chaudhari <harshal.chaudhary@gmail.com> Co-authored-by: Reilly Wood <reilly.wood@icloud.com>
This commit is contained in:
committed by
GitHub
parent
1c5846e1fb
commit
35e8420780
@ -1,5 +1,5 @@
|
||||
use nu_test_support::nu;
|
||||
use nu_test_support::playground::Playground;
|
||||
use nu_test_support::{nu, pipeline};
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
@ -39,85 +39,49 @@ param:string #My cool attractive param
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_multiple_short_flags() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ --long(-l)(-o) ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ --long(-l)(-o) ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected only one short flag"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_comma_before_alternative_short_flag() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ --long, (-l) ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ --long, (-l) ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_comma_before_equals() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ foo, = 1 ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ foo, = 1 ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_comma_before_colon() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ foo, : int ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ foo, : int ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_multiple_colons() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ foo::int ] {}
|
||||
"#
|
||||
));
|
||||
|
||||
let actual = nu!("def test-command [ foo::int ] {}");
|
||||
assert!(actual.err.contains("expected type"));
|
||||
}
|
||||
|
||||
#[ignore = "This error condition is not implemented yet"]
|
||||
#[test]
|
||||
fn def_errors_with_multiple_types() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ foo:int:string ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ foo:int:string ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn def_errors_with_multiple_commas() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def test-command [ foo,,bar ] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def test-command [ foo,,bar ] {}");
|
||||
|
||||
assert!(actual.err.contains("expected parameter"));
|
||||
}
|
||||
@ -125,28 +89,13 @@ fn def_errors_with_multiple_commas() {
|
||||
#[test]
|
||||
fn def_fails_with_invalid_name() {
|
||||
let err_msg = "command name can't be a number, a filesize, or contain a hash # or caret ^";
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def 1234 = echo "test"
|
||||
"#
|
||||
));
|
||||
let actual = nu!(r#"def 1234 = echo "test""#);
|
||||
assert!(actual.err.contains(err_msg));
|
||||
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def 5gib = echo "test"
|
||||
"#
|
||||
));
|
||||
let actual = nu!(r#"def 5gib = echo "test""#);
|
||||
assert!(actual.err.contains(err_msg));
|
||||
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def ^foo [] {}
|
||||
"#
|
||||
));
|
||||
let actual = nu!(r#"def ^foo [] {}"#);
|
||||
assert!(actual.err.contains(err_msg));
|
||||
}
|
||||
|
||||
@ -188,12 +137,7 @@ param: list = [one]
|
||||
|
||||
#[test]
|
||||
fn def_with_paren_params() {
|
||||
let actual = nu!(
|
||||
cwd: ".", pipeline(
|
||||
r#"
|
||||
def foo (x: int, y: int) { $x + $y }; foo 1 2
|
||||
"#
|
||||
));
|
||||
let actual = nu!("def foo (x: int, y: int) { $x + $y }; foo 1 2");
|
||||
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
Reference in New Issue
Block a user