2020-10-25 18:46:26 +00:00
|
|
|
//! Tests for packages/target filter flags giving suggestions on which
|
|
|
|
//! packages/targets are available.
|
2019-11-25 02:42:45 +00:00
|
|
|
|
2019-09-12 17:14:29 +00:00
|
|
|
use cargo_test_support::project;
|
2018-12-29 14:13:58 +00:00
|
|
|
|
2020-10-25 18:46:26 +00:00
|
|
|
const EXAMPLE: u8 = 1 << 0;
|
|
|
|
const BIN: u8 = 1 << 1;
|
|
|
|
const TEST: u8 = 1 << 2;
|
|
|
|
const BENCH: u8 = 1 << 3;
|
|
|
|
const PACKAGE: u8 = 1 << 4;
|
2023-08-31 01:34:42 +00:00
|
|
|
const TARGET: u8 = 1 << 5;
|
2018-12-29 14:13:58 +00:00
|
|
|
|
2020-10-25 18:46:26 +00:00
|
|
|
fn list_availables_test(command: &str, targets: u8) {
|
2019-01-03 22:00:45 +00:00
|
|
|
let full_project = project()
|
2018-12-29 14:13:58 +00:00
|
|
|
.file("examples/a.rs", "fn main() { }")
|
|
|
|
.file("examples/b.rs", "fn main() { }")
|
|
|
|
.file("benches/bench1.rs", "")
|
|
|
|
.file("benches/bench2.rs", "")
|
|
|
|
.file("tests/test1.rs", "")
|
|
|
|
.file("tests/test2.rs", "")
|
|
|
|
.file("src/main.rs", "fn main() { }")
|
2020-10-27 16:26:19 +00:00
|
|
|
.file("Cargo.lock", "") // for `cargo pkgid`
|
2018-12-29 14:13:58 +00:00
|
|
|
.build();
|
|
|
|
|
2019-01-03 22:00:45 +00:00
|
|
|
if targets & EXAMPLE != 0 {
|
|
|
|
full_project
|
|
|
|
.cargo(&format!("{} --example", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--example\" takes one argument.
|
|
|
|
Available examples:
|
|
|
|
a
|
|
|
|
b
|
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & BIN != 0 {
|
|
|
|
full_project
|
|
|
|
.cargo(&format!("{} --bin", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--bin\" takes one argument.
|
|
|
|
Available binaries:
|
|
|
|
foo
|
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & BENCH != 0 {
|
|
|
|
full_project
|
|
|
|
.cargo(&format!("{} --bench", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--bench\" takes one argument.
|
2023-11-03 20:45:00 +00:00
|
|
|
Available bench targets:
|
2018-12-29 14:13:58 +00:00
|
|
|
bench1
|
|
|
|
bench2
|
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & TEST != 0 {
|
|
|
|
full_project
|
|
|
|
.cargo(&format!("{} --test", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--test\" takes one argument.
|
2023-11-03 20:45:00 +00:00
|
|
|
Available test targets:
|
2018-12-29 14:13:58 +00:00
|
|
|
test1
|
|
|
|
test2
|
|
|
|
|
2020-10-25 18:46:26 +00:00
|
|
|
",
|
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & PACKAGE != 0 {
|
|
|
|
full_project
|
|
|
|
.cargo(&format!("{} -p", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2020-10-27 14:03:54 +00:00
|
|
|
[ERROR] \"--package <SPEC>\" requires a SPEC format value, \
|
|
|
|
which can be any package ID specifier in the dependency graph.
|
|
|
|
Run `cargo help pkgid` for more information about SPEC format.
|
|
|
|
|
|
|
|
Possible packages/workspace members:
|
2020-10-25 18:46:26 +00:00
|
|
|
foo
|
|
|
|
|
2018-12-29 14:13:58 +00:00
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
let empty_project = project().file("src/lib.rs", "").build();
|
|
|
|
|
|
|
|
if targets & EXAMPLE != 0 {
|
|
|
|
empty_project
|
|
|
|
.cargo(&format!("{} --example", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--example\" takes one argument.
|
|
|
|
No examples available.
|
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & BIN != 0 {
|
|
|
|
empty_project
|
|
|
|
.cargo(&format!("{} --bin", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--bin\" takes one argument.
|
|
|
|
No binaries available.
|
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & BENCH != 0 {
|
|
|
|
empty_project
|
|
|
|
.cargo(&format!("{} --bench", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--bench\" takes one argument.
|
2023-11-03 20:45:00 +00:00
|
|
|
No bench targets available.
|
2018-12-29 14:13:58 +00:00
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
if targets & TEST != 0 {
|
|
|
|
empty_project
|
|
|
|
.cargo(&format!("{} --test", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2018-12-29 14:13:58 +00:00
|
|
|
error: \"--test\" takes one argument.
|
2023-11-03 20:45:00 +00:00
|
|
|
No test targets available.
|
2018-12-29 14:13:58 +00:00
|
|
|
|
|
|
|
",
|
2019-01-03 22:00:45 +00:00
|
|
|
)
|
|
|
|
.with_status(101)
|
|
|
|
.run();
|
|
|
|
}
|
2023-08-31 01:34:42 +00:00
|
|
|
|
|
|
|
if targets & TARGET != 0 {
|
|
|
|
empty_project
|
|
|
|
.cargo(&format!("{} --target", command))
|
|
|
|
.with_stderr(
|
|
|
|
"\
|
2023-08-31 13:56:16 +00:00
|
|
|
error: \"--target\" takes a target architecture as an argument.
|
2023-08-31 13:55:36 +00:00
|
|
|
|
|
|
|
Run `[..]` to see possible targets.
|
2023-08-31 01:34:42 +00:00
|
|
|
",
|
|
|
|
)
|
2023-08-31 01:42:45 +00:00
|
|
|
.with_status(101)
|
2023-08-31 01:34:42 +00:00
|
|
|
.run();
|
|
|
|
}
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn build_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("build", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn check_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("check", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
2019-01-03 22:00:45 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn doc_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("doc", BIN | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn fix_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("fix", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn run_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("run", EXAMPLE | BIN | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn test_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("test", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn bench_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("bench", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
2019-01-03 22:00:45 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn install_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("install", EXAMPLE | BIN | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn rustdoc_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("rustdoc", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
2019-01-03 22:00:45 +00:00
|
|
|
|
2019-06-05 18:52:53 +00:00
|
|
|
#[cargo_test]
|
2020-10-25 18:46:26 +00:00
|
|
|
fn rustc_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("rustc", EXAMPLE | BIN | TEST | BENCH | PACKAGE | TARGET);
|
2020-10-27 16:26:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn pkgid_list_availables() {
|
|
|
|
list_availables_test("pkgid", PACKAGE);
|
2018-12-29 14:13:58 +00:00
|
|
|
}
|
2020-10-27 17:33:34 +00:00
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn tree_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("tree", PACKAGE | TARGET);
|
2020-10-27 17:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn clean_list_availables() {
|
2023-08-31 01:34:42 +00:00
|
|
|
list_availables_test("clean", PACKAGE | TARGET);
|
2020-10-27 17:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test]
|
|
|
|
fn update_list_availables() {
|
|
|
|
list_availables_test("update", PACKAGE);
|
|
|
|
}
|