2023-11-10 20:15:11 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2022-12-21 22:33:26 +00:00
|
|
|
use crate::tests::{fail_test, run_test, run_test_contains, TestResult};
|
2022-04-17 19:31:03 +00:00
|
|
|
|
|
|
|
// cargo version prints a string of the form:
|
|
|
|
// cargo 1.60.0 (d1fd9fe2c 2022-03-01)
|
2022-04-17 10:39:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_runs() -> TestResult {
|
2022-04-17 19:31:03 +00:00
|
|
|
run_test_contains(r#"extern "cargo version" []; cargo version"#, "cargo")
|
2022-04-17 10:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_unknown_flag() -> TestResult {
|
2022-12-21 22:33:26 +00:00
|
|
|
run_test_contains(r#"extern "cargo" []; cargo --version"#, "cargo")
|
2022-04-17 10:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// GitHub issues #5179, #4618
|
|
|
|
#[test]
|
|
|
|
fn known_external_alias() -> TestResult {
|
2022-04-17 19:31:03 +00:00
|
|
|
run_test_contains(
|
|
|
|
r#"extern "cargo version" []; alias cv = cargo version; cv"#,
|
|
|
|
"cargo",
|
2022-04-17 10:39:56 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GitHub issues #5179, #4618
|
|
|
|
#[test]
|
|
|
|
fn known_external_subcommand_alias() -> TestResult {
|
2022-04-17 19:31:03 +00:00
|
|
|
run_test_contains(
|
|
|
|
r#"extern "cargo version" []; alias c = cargo; c version"#,
|
|
|
|
"cargo",
|
2022-04-17 10:39:56 +00:00
|
|
|
)
|
|
|
|
}
|
2022-12-21 22:33:26 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_complex_unknown_args() -> TestResult {
|
|
|
|
run_test_contains(
|
|
|
|
"extern echo []; echo foo -b -as -9 --abc -- -Dxmy=AKOO - bar",
|
|
|
|
"foo -b -as -9 --abc -- -Dxmy=AKOO - bar",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-08-18 17:45:33 +00:00
|
|
|
#[test]
|
|
|
|
fn known_external_from_module() -> TestResult {
|
|
|
|
run_test_contains(
|
|
|
|
r#"module spam {
|
|
|
|
export extern echo []
|
|
|
|
}
|
|
|
|
|
|
|
|
use spam echo
|
|
|
|
echo foo -b -as -9 --abc -- -Dxmy=AKOO - bar
|
|
|
|
"#,
|
|
|
|
"foo -b -as -9 --abc -- -Dxmy=AKOO - bar",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-12-21 22:33:26 +00:00
|
|
|
#[test]
|
2023-04-15 08:24:51 +00:00
|
|
|
fn known_external_short_flag_batch_arg_allowed() -> TestResult {
|
|
|
|
run_test_contains("extern echo [-a, -b: int]; echo -ab 10", "-b 10")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_short_flag_batch_arg_disallowed() -> TestResult {
|
|
|
|
fail_test(
|
|
|
|
"extern echo [-a: int, -b]; echo -ab 10",
|
|
|
|
"last flag can take args",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_short_flag_batch_multiple_args() -> TestResult {
|
2022-12-21 22:33:26 +00:00
|
|
|
fail_test(
|
2023-04-15 08:24:51 +00:00
|
|
|
"extern echo [-a: int, -b: int]; echo -ab 10 20",
|
|
|
|
"last flag can take args",
|
2022-12-21 22:33:26 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_missing_positional() -> TestResult {
|
|
|
|
fail_test("extern echo [a]; echo", "missing_positional")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_type_mismatch() -> TestResult {
|
|
|
|
fail_test("extern echo [a: int]; echo 1.234", "mismatch")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_missing_flag_param() -> TestResult {
|
|
|
|
fail_test(
|
|
|
|
"extern echo [--foo: string]; echo --foo",
|
|
|
|
"missing_flag_param",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn known_external_misc_values() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"
|
|
|
|
let x = 'abc'
|
|
|
|
extern echo []
|
|
|
|
echo $x [ a b c ]
|
|
|
|
"#,
|
|
|
|
"abc a b c",
|
|
|
|
)
|
|
|
|
}
|
2023-01-22 19:40:18 +00:00
|
|
|
|
|
|
|
/// GitHub issue #7822
|
|
|
|
#[test]
|
|
|
|
fn known_external_subcommand_from_module() -> TestResult {
|
2023-11-10 20:15:11 +00:00
|
|
|
let output = Command::new("cargo").arg("check").arg("-h").output()?;
|
|
|
|
run_test(
|
2023-01-22 19:40:18 +00:00
|
|
|
r#"
|
|
|
|
module cargo {
|
|
|
|
export extern check []
|
|
|
|
};
|
|
|
|
use cargo;
|
|
|
|
cargo check -h
|
|
|
|
"#,
|
2023-11-10 20:15:11 +00:00
|
|
|
String::from_utf8(output.stdout)?.trim(),
|
2023-01-22 19:40:18 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// GitHub issue #7822
|
|
|
|
#[test]
|
|
|
|
fn known_external_aliased_subcommand_from_module() -> TestResult {
|
2023-11-10 20:15:11 +00:00
|
|
|
let output = Command::new("cargo").arg("check").arg("-h").output()?;
|
|
|
|
run_test(
|
2023-01-22 19:40:18 +00:00
|
|
|
r#"
|
|
|
|
module cargo {
|
|
|
|
export extern check []
|
|
|
|
};
|
|
|
|
use cargo;
|
|
|
|
alias cc = cargo check;
|
|
|
|
cc -h
|
|
|
|
"#,
|
2023-11-10 20:15:11 +00:00
|
|
|
String::from_utf8(output.stdout)?.trim(),
|
2023-01-22 19:40:18 +00:00
|
|
|
)
|
|
|
|
}
|