2021-01-08 18:44:31 +01:00
|
|
|
use nu_test_support::nu;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn which_ls() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-02-09 11:58:54 +01:00
|
|
|
"which ls | get path.0 | str trim"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "Nushell built-in command");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn which_alias_ls() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-02-09 11:58:54 +01:00
|
|
|
"alias ls = ls -a; which ls | get path.0 | str trim"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
2021-01-09 18:19:46 +01:00
|
|
|
assert_eq!(actual.out, "Nushell alias: ls -a");
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn which_def_ls() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-02-09 11:58:54 +01:00
|
|
|
"def ls [] {echo def}; which ls | get path.0 | str trim"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "Nushell custom command");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn correct_precedence_alias_def_custom() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-02-09 11:58:54 +01:00
|
|
|
"def ls [] {echo def}; alias ls = echo alias; which ls | get path.0 | str trim"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
2021-01-09 18:19:46 +01:00
|
|
|
assert_eq!(actual.out, "Nushell alias: echo alias");
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multiple_reports_for_alias_def_custom() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2021-03-13 22:46:40 +01:00
|
|
|
"def ls [] {echo def}; alias ls = echo alias; which -a ls | length"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
2021-03-13 22:46:40 +01:00
|
|
|
let length: i32 = actual.out.parse().unwrap();
|
2022-03-24 04:42:41 +01:00
|
|
|
assert!(length >= 2);
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// `get_aliases_with_name` and `get_custom_commands_with_name` don't return the correct count of
|
|
|
|
// values
|
|
|
|
// I suspect this is due to the ScopeFrame getting discarded at '}' and the command is then
|
|
|
|
// executed in the parent scope
|
|
|
|
// See: parse_definition, line 2187 for reference.
|
|
|
|
#[ignore]
|
|
|
|
#[test]
|
2022-03-13 20:32:46 +01:00
|
|
|
fn correctly_report_of_shadowed_alias() {
|
2021-01-08 18:44:31 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-03-13 20:32:46 +01:00
|
|
|
r#"alias xaz = echo alias1
|
|
|
|
def helper [] {
|
|
|
|
alias xaz = echo alias2
|
|
|
|
which -a xaz
|
|
|
|
}
|
|
|
|
helper | get path | str contains alias2"#
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
2022-03-13 20:32:46 +01:00
|
|
|
assert_eq!(actual.out, "true");
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-13 20:32:46 +01:00
|
|
|
fn one_report_of_multiple_defs() {
|
2021-01-08 18:44:31 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2022-03-13 20:32:46 +01:00
|
|
|
r#"def xaz [] { echo def1 }
|
|
|
|
def helper [] {
|
|
|
|
def xaz [] { echo def2 }
|
|
|
|
which -a xaz
|
|
|
|
}
|
|
|
|
helper | length"#
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
|
|
|
|
2021-03-13 22:46:40 +01:00
|
|
|
let length: i32 = actual.out.parse().unwrap();
|
2022-03-13 20:32:46 +01:00
|
|
|
assert_eq!(length, 1);
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn def_only_seen_once() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
2021-03-13 22:46:40 +01:00
|
|
|
"def xaz [] {echo def1}; which -a xaz | length"
|
2021-01-08 18:44:31 +01:00
|
|
|
);
|
2022-03-13 20:32:46 +01:00
|
|
|
|
2021-03-13 22:46:40 +01:00
|
|
|
let length: i32 = actual.out.parse().unwrap();
|
|
|
|
assert_eq!(length, 1);
|
2021-01-08 18:44:31 +01:00
|
|
|
}
|
2022-03-13 20:32:46 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_show_hidden_aliases() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"alias foo = echo foo
|
|
|
|
hide foo
|
|
|
|
which foo | length"#
|
|
|
|
);
|
|
|
|
|
|
|
|
let length: i32 = actual.out.parse().unwrap();
|
|
|
|
assert_eq!(length, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_show_hidden_commands() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
r#"def foo [] { echo foo }
|
|
|
|
hide foo
|
|
|
|
which foo | length"#
|
|
|
|
);
|
|
|
|
|
|
|
|
let length: i32 = actual.out.parse().unwrap();
|
|
|
|
assert_eq!(length, 0);
|
|
|
|
}
|