diff --git a/examples/test_hello.rs b/examples/test_hello.rs new file mode 100644 index 0000000000..f38c4f6d13 --- /dev/null +++ b/examples/test_hello.rs @@ -0,0 +1,6 @@ +/// This function is only meant to be used as part of the test suite +/// as a simple, cross-platform executable with known output. + +fn main() { + println!("test-hello"); +} diff --git a/src/tests.rs b/src/tests.rs index 6d27785b68..c2bcae93d1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -5,6 +5,7 @@ mod test_engine; mod test_env; mod test_hiding; mod test_iteration; +mod test_known_external; mod test_math; mod test_modules; mod test_parser; @@ -42,6 +43,10 @@ pub fn run_test(input: &str, expected: &str) -> TestResult { let mut cmd = Command::cargo_bin("nu")?; cmd.arg(name); + cmd.env( + "PWD", + std::env::current_dir().expect("Can't get current dir"), + ); writeln!(file, "{}", input)?; diff --git a/src/tests/test_known_external.rs b/src/tests/test_known_external.rs new file mode 100644 index 0000000000..598fadf3ae --- /dev/null +++ b/src/tests/test_known_external.rs @@ -0,0 +1,35 @@ +use crate::tests::{fail_test, run_test, TestResult}; + +#[test] +fn known_external_runs() -> TestResult { + run_test( + r#"extern "cargo run" [-q, --example: string, ...args]; cargo run -q --example test_hello"#, + "test-hello", + ) +} + +#[test] +fn known_external_unknown_flag() -> TestResult { + fail_test( + r#"extern "cargo run" [-q, --example: string, ...args]; cargo run -d"#, + "command doesn't have flag", + ) +} + +/// GitHub issues #5179, #4618 +#[test] +fn known_external_alias() -> TestResult { + run_test( + r#"extern "cargo run" [-q, --example: string, ...args]; alias cr = cargo run; cr -q --example test_hello"#, + "test-hello", + ) +} + +/// GitHub issues #5179, #4618 +#[test] +fn known_external_subcommand_alias() -> TestResult { + run_test( + r#"extern "cargo run" [-q, --example: string, ...args]; alias c = cargo; c run -q --example test_hello"#, + "test-hello", + ) +}