mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
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:
parent
0a990ed105
commit
7710317224
3 changed files with 46 additions and 0 deletions
6
examples/test_hello.rs
Normal file
6
examples/test_hello.rs
Normal 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");
|
||||
}
|
|
@ -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)?;
|
||||
|
||||
|
|
35
src/tests/test_known_external.rs
Normal file
35
src/tests/test_known_external.rs
Normal 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",
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue