Add known external tests (#5216)

* Add known external tests

* Add some documentation to the tests

* Document test_hello example

* Set PWD in run_test
This commit is contained in:
Hristo Filaretov 2022-04-17 12:39:56 +02:00 committed by GitHub
parent 0a990ed105
commit 7710317224
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 0 deletions

6
examples/test_hello.rs Normal file
View file

@ -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");
}

View file

@ -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)?;

View file

@ -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",
)
}