mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 02:45:08 +02:00
Revert "Add extern
for nu
command" (#16180)
Reverts nushell/nushell#16119
This commit is contained in:
@ -22,7 +22,7 @@ fn basic_string_fails() {
|
||||
#[test]
|
||||
fn short_stream_binary() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 5 | bytes ends-with 0x[010101]
|
||||
nu --testbin repeater (0x[01]) 5 | bytes ends-with 0x[010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -31,7 +31,7 @@ fn short_stream_binary() {
|
||||
#[test]
|
||||
fn short_stream_mismatch() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[010203]) 5 | bytes ends-with 0x[010204]
|
||||
nu --testbin repeater (0x[010203]) 5 | bytes ends-with 0x[010204]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -40,7 +40,7 @@ fn short_stream_mismatch() {
|
||||
#[test]
|
||||
fn short_stream_binary_overflow() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 5 | bytes ends-with 0x[010101010101]
|
||||
nu --testbin repeater (0x[01]) 5 | bytes ends-with 0x[010101010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -49,7 +49,7 @@ fn short_stream_binary_overflow() {
|
||||
#[test]
|
||||
fn long_stream_binary() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 32768 | bytes ends-with 0x[010101]
|
||||
nu --testbin repeater (0x[01]) 32768 | bytes ends-with 0x[010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -59,7 +59,7 @@ fn long_stream_binary() {
|
||||
fn long_stream_binary_overflow() {
|
||||
// .. ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 32768 | bytes ends-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
||||
nu --testbin repeater (0x[01]) 32768 | bytes ends-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -69,7 +69,7 @@ fn long_stream_binary_overflow() {
|
||||
fn long_stream_binary_exact() {
|
||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01020304]) 8192 | bytes ends-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
||||
nu --testbin repeater (0x[01020304]) 8192 | bytes ends-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -79,7 +79,7 @@ fn long_stream_binary_exact() {
|
||||
fn long_stream_string_exact() {
|
||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater hell 8192 | bytes ends-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
||||
nu --testbin repeater hell 8192 | bytes ends-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -92,7 +92,7 @@ fn long_stream_mixed_exact() {
|
||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||
|
||||
^nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes ends-with (bytes build $binseg $strseg)
|
||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes ends-with (bytes build $binseg $strseg)
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
@ -109,7 +109,7 @@ fn long_stream_mixed_overflow() {
|
||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||
|
||||
^nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes ends-with (bytes build 0x[01] $binseg $strseg)
|
||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes ends-with (bytes build 0x[01] $binseg $strseg)
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -22,7 +22,7 @@ fn basic_string_fails() {
|
||||
#[test]
|
||||
fn short_stream_binary() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101]
|
||||
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -31,7 +31,7 @@ fn short_stream_binary() {
|
||||
#[test]
|
||||
fn short_stream_mismatch() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[010203]) 5 | bytes starts-with 0x[010204]
|
||||
nu --testbin repeater (0x[010203]) 5 | bytes starts-with 0x[010204]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -40,7 +40,7 @@ fn short_stream_mismatch() {
|
||||
#[test]
|
||||
fn short_stream_binary_overflow() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101010101]
|
||||
nu --testbin repeater (0x[01]) 5 | bytes starts-with 0x[010101010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -49,7 +49,7 @@ fn short_stream_binary_overflow() {
|
||||
#[test]
|
||||
fn long_stream_binary() {
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 32768 | bytes starts-with 0x[010101]
|
||||
nu --testbin repeater (0x[01]) 32768 | bytes starts-with 0x[010101]
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -59,7 +59,7 @@ fn long_stream_binary() {
|
||||
fn long_stream_binary_overflow() {
|
||||
// .. ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01]) 32768 | bytes starts-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
||||
nu --testbin repeater (0x[01]) 32768 | bytes starts-with (0..32768 | each {|| 0x[01] } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "false");
|
||||
@ -69,7 +69,7 @@ fn long_stream_binary_overflow() {
|
||||
fn long_stream_binary_exact() {
|
||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater (0x[01020304]) 8192 | bytes starts-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
||||
nu --testbin repeater (0x[01020304]) 8192 | bytes starts-with (0..<8192 | each {|| 0x[01020304] } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -79,7 +79,7 @@ fn long_stream_binary_exact() {
|
||||
fn long_stream_string_exact() {
|
||||
// ranges are inclusive..inclusive, so we don't need to +1 to check for an overflow
|
||||
let actual = nu!(r#"
|
||||
^nu --testbin repeater hell 8192 | bytes starts-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
||||
nu --testbin repeater hell 8192 | bytes starts-with (0..<8192 | each {|| "hell" | into binary } | bytes collect)
|
||||
"#);
|
||||
|
||||
assert_eq!(actual.out, "true");
|
||||
@ -92,7 +92,7 @@ fn long_stream_mixed_exact() {
|
||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||
|
||||
^nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg)
|
||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg)
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
@ -109,7 +109,7 @@ fn long_stream_mixed_overflow() {
|
||||
let binseg = (0..<2048 | each {|| 0x[003d9fbf] } | bytes collect)
|
||||
let strseg = (0..<2048 | each {|| "hell" | into binary } | bytes collect)
|
||||
|
||||
^nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg 0x[01])
|
||||
nu --testbin repeat_bytes 003d9fbf 2048 68656c6c 2048 | bytes starts-with (bytes build $binseg $strseg 0x[01])
|
||||
"#);
|
||||
|
||||
assert_eq!(
|
||||
|
@ -4,14 +4,6 @@ use nu_test_support::playground::Playground;
|
||||
use rstest::rstest;
|
||||
use rstest_reuse::*;
|
||||
|
||||
// Get full path to nu, so we don't use the nu extern
|
||||
fn nu_path(prefix: &str) -> String {
|
||||
let binary = nu_test_support::fs::executable_path()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
format!("{prefix}{}", binary)
|
||||
}
|
||||
|
||||
// Template for run-external test to ensure tests work when calling
|
||||
// the binary directly, using the caret operator, and when using
|
||||
// the run-external command
|
||||
@ -26,8 +18,8 @@ fn run_external_prefixes(#[case] prefix: &str) {}
|
||||
fn better_empty_redirection(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
"ls | each {{ |it| {} `--testbin` cococo $it.name }} | ignore",
|
||||
nu_path(prefix)
|
||||
"ls | each {{ |it| {}nu `--testbin` cococo $it.name }} | ignore",
|
||||
prefix
|
||||
);
|
||||
|
||||
eprintln!("out: {}", actual.out);
|
||||
@ -47,9 +39,9 @@ fn explicit_glob(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo ('*.txt' | into glob)
|
||||
{}nu `--testbin` cococo ('*.txt' | into glob)
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("D&D_volume_1.txt"));
|
||||
@ -69,9 +61,9 @@ fn bare_word_expand_path_glob(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"
|
||||
{} `--testbin` cococo *.txt
|
||||
{}nu `--testbin` cococo *.txt
|
||||
",
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("D&D_volume_1.txt"));
|
||||
@ -91,9 +83,9 @@ fn backtick_expand_path_glob(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo `*.txt`
|
||||
{}nu `--testbin` cococo `*.txt`
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert!(actual.out.contains("D&D_volume_1.txt"));
|
||||
@ -113,9 +105,9 @@ fn single_quote_does_not_expand_path_glob(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo '*.txt'
|
||||
{}nu `--testbin` cococo '*.txt'
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "*.txt");
|
||||
@ -134,9 +126,9 @@ fn double_quote_does_not_expand_path_glob(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo "*.txt"
|
||||
{}nu `--testbin` cococo "*.txt"
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "*.txt");
|
||||
@ -149,9 +141,9 @@ fn failed_command_with_semicolon_will_not_execute_following_cmds(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"
|
||||
{} `--testbin` fail; echo done
|
||||
{}nu `--testbin` fail; echo done
|
||||
",
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert!(!actual.out.contains("done"));
|
||||
@ -164,9 +156,9 @@ fn external_args_with_quoted(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo "foo=bar 'hi'"
|
||||
{}nu `--testbin` cococo "foo=bar 'hi'"
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "foo=bar 'hi'");
|
||||
@ -206,9 +198,9 @@ fn external_arg_with_non_option_like_embedded_quotes(#[case] prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo foo='bar' 'foo'=bar
|
||||
{}nu `--testbin` cococo foo='bar' 'foo'=bar
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "foo=bar foo=bar");
|
||||
@ -225,9 +217,9 @@ fn external_arg_with_string_interpolation(#[case] prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo foo=(2 + 2) $"foo=(2 + 2)" foo=$"(2 + 2)"
|
||||
{}nu `--testbin` cococo foo=(2 + 2) $"foo=(2 + 2)" foo=$"(2 + 2)"
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "foo=4 foo=4 foo=4");
|
||||
@ -241,9 +233,9 @@ fn external_arg_with_variable_name(prefix: &str) {
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
let dump_command = "PGPASSWORD='db_secret' pg_dump -Fc -h 'db.host' -p '$db.port' -U postgres -d 'db_name' > '/tmp/dump_name'";
|
||||
{} `--testbin` nonu $dump_command
|
||||
{}nu `--testbin` nonu $dump_command
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -259,9 +251,9 @@ fn external_command_escape_args(prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo "\"abcd"
|
||||
{}nu `--testbin` cococo "\"abcd"
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, r#""abcd"#);
|
||||
@ -272,9 +264,9 @@ fn external_command_escape_args(prefix: &str) {
|
||||
fn external_command_ndots_args(prefix: &str) {
|
||||
let actual = nu!(
|
||||
r#"
|
||||
{} `--testbin` cococo foo/. foo/.. foo/... foo/./bar foo/../bar foo/.../bar ./bar ../bar .../bar
|
||||
{}nu `--testbin` cococo foo/. foo/.. foo/... foo/./bar foo/../bar foo/.../bar ./bar ../bar .../bar
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -294,9 +286,9 @@ fn external_command_ndots_leading_dot_slash(prefix: &str) {
|
||||
// Don't expand ndots with a leading `./`
|
||||
let actual = nu!(
|
||||
r#"
|
||||
{} `--testbin` cococo ./... ./....
|
||||
{}nu `--testbin` cococo ./... ./....
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "./... ./....");
|
||||
@ -308,9 +300,9 @@ fn external_command_url_args(prefix: &str) {
|
||||
// here
|
||||
let actual = nu!(
|
||||
r#"
|
||||
{} `--testbin` cococo http://example.com http://example.com/.../foo //foo
|
||||
{}nu `--testbin` cococo http://example.com http://example.com/.../foo //foo
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
@ -367,9 +359,9 @@ fn external_arg_expand_tilde(#[case] prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
{} `--testbin` cococo ~/foo ~/(2 + 2)
|
||||
{}nu `--testbin` cococo ~/foo ~/(2 + 2)
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
let home = dirs::home_dir().expect("failed to find home dir");
|
||||
@ -390,7 +382,7 @@ fn external_command_not_expand_tilde_with_quotes(prefix: &str) {
|
||||
Playground::setup(
|
||||
"external command not expand tilde with quotes",
|
||||
|dirs, _| {
|
||||
let actual = nu!(cwd: dirs.test(), r#"{} `--testbin` nonu "~""#, nu_path(prefix));
|
||||
let actual = nu!(cwd: dirs.test(), r#"{}nu `--testbin` nonu "~""#, prefix);
|
||||
assert_eq!(actual.out, r#"~"#);
|
||||
},
|
||||
)
|
||||
@ -401,7 +393,7 @@ fn external_command_expand_tilde_with_back_quotes(prefix: &str) {
|
||||
Playground::setup(
|
||||
"external command not expand tilde with quotes",
|
||||
|dirs, _| {
|
||||
let actual = nu!(cwd: dirs.test(), r#"{} `--testbin` nonu `~`"#, nu_path(prefix));
|
||||
let actual = nu!(cwd: dirs.test(), r#"{}nu `--testbin` nonu `~`"#, prefix);
|
||||
assert!(!actual.out.contains('~'));
|
||||
},
|
||||
)
|
||||
@ -412,8 +404,8 @@ fn external_command_receives_raw_binary_data(prefix: &str) {
|
||||
Playground::setup("external command receives raw binary data", |dirs, _| {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
"0x[deadbeef] | {} `--testbin` input_bytes_length",
|
||||
nu_path(prefix)
|
||||
"0x[deadbeef] | {}nu `--testbin` input_bytes_length",
|
||||
prefix
|
||||
);
|
||||
assert_eq!(actual.out, r#"4"#);
|
||||
})
|
||||
@ -502,9 +494,9 @@ fn quotes_trimmed_when_shelling_out(prefix: &str) {
|
||||
// regression test for a bug where we weren't trimming quotes around string args before shelling out to cmd.exe
|
||||
let actual = nu!(
|
||||
r#"
|
||||
{} `--testbin` cococo "foo"
|
||||
{}nu `--testbin` cococo "foo"
|
||||
"#,
|
||||
nu_path(prefix)
|
||||
prefix
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "foo");
|
||||
@ -573,9 +565,8 @@ fn expand_command_if_list(#[case] prefix: &str) {
|
||||
let actual = nu!(
|
||||
cwd: dirs.test(),
|
||||
r#"
|
||||
let cmd = ['{}' `--testbin`]; {}$cmd meow foo.txt
|
||||
let cmd = [nu `--testbin`]; {}$cmd meow foo.txt
|
||||
"#,
|
||||
nu_path(""),
|
||||
prefix
|
||||
);
|
||||
|
||||
|
@ -19,8 +19,7 @@ pub(crate) fn compile_call(
|
||||
let decl = working_set.get_decl(call.decl_id);
|
||||
|
||||
// Check if this call has --help - if so, just redirect to `help`
|
||||
// Special case the `nu` extern: we want to forward --help to the script
|
||||
if call.named_iter().any(|(name, _, _)| name.item == "help") && decl.name() != "nu" {
|
||||
if call.named_iter().any(|(name, _, _)| name.item == "help") {
|
||||
let name = working_set
|
||||
.find_decl_name(call.decl_id) // check for name in scope
|
||||
.and_then(|name| std::str::from_utf8(name).ok())
|
||||
|
@ -715,14 +715,6 @@ impl CustomExample {
|
||||
result: self.result.clone(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_example(example: Example<'_>) -> Self {
|
||||
Self {
|
||||
example: example.example.to_string(),
|
||||
description: example.description.to_string(),
|
||||
result: example.result,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
|
Reference in New Issue
Block a user