2024-03-09 22:48:48 +00:00
|
|
|
//! Tests for Cargo usage of rustc `--check-cfg`.
|
2022-04-14 10:20:36 +00:00
|
|
|
|
2024-06-07 19:55:21 +00:00
|
|
|
#![allow(deprecated)]
|
|
|
|
|
2021-09-09 06:10:33 +00:00
|
|
|
use cargo_test_support::{basic_manifest, project};
|
2022-04-14 10:20:36 +00:00
|
|
|
|
2022-04-14 12:16:35 +00:00
|
|
|
macro_rules! x {
|
|
|
|
($tool:tt => $what:tt $(of $who:tt)?) => {{
|
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg ",
|
|
|
|
$what, '(', $($who,)* ')', "[..]")
|
|
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
|
|
|
$what, '(', $($who,)* ')', "'", "[..]")
|
|
|
|
}
|
|
|
|
}};
|
2024-01-17 18:12:53 +00:00
|
|
|
($tool:tt => $what:tt of $who:tt with $($first_value:tt $($other_values:tt)*)?) => {{
|
2022-04-14 12:16:35 +00:00
|
|
|
#[cfg(windows)]
|
|
|
|
{
|
|
|
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg \"",
|
2024-01-17 18:12:53 +00:00
|
|
|
$what, '(', $who, ", values(", $("/\"", $first_value, "/\"", $(", ", "/\"", $other_values, "/\"",)*)* "))", '"', "[..]")
|
2022-04-14 12:16:35 +00:00
|
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
{
|
|
|
|
concat!("[RUNNING] [..]", $tool, "[..] --check-cfg '",
|
2024-01-17 18:12:53 +00:00
|
|
|
$what, '(', $who, ", values(", $("\"", $first_value, "\"", $(", ", "\"", $other_values, "\"",)*)* "))", "'", "[..]")
|
2022-04-14 12:16:35 +00:00
|
|
|
}
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2024-03-09 22:48:48 +00:00
|
|
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_with_deps() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar/" }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_with_opt_deps() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar/", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["bar"]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "bar" "default" "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_with_namespaced_features() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[dependencies]
|
|
|
|
bar = { path = "bar/", optional = true }
|
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = ["dep:bar"]
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("bar/Cargo.toml", &basic_manifest("bar", "0.1.0"))
|
|
|
|
.file("bar/src/lib.rs", "#[allow(dead_code)] fn bar() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2023-12-01 20:55:16 +00:00
|
|
|
fn features_fingerprint() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2023-12-01 20:55:16 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "#[cfg(feature = \"f_b\")] fn entry() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-12-01 20:55:16 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
|
|
|
.with_stderr_does_not_contain("[..]unexpected_cfgs[..]")
|
|
|
|
.run();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-12-01 21:05:17 +00:00
|
|
|
.with_stderr_does_not_contain("[..]rustc[..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
// checking that re-ordering the features does not invalid the fingerprint
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2023-12-01 21:05:17 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
f_b = []
|
|
|
|
f_a = []
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-12-01 20:55:16 +00:00
|
|
|
.with_stderr_does_not_contain("[..]rustc[..]")
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2023-12-01 20:55:16 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = []
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-11-19 17:56:39 +00:00
|
|
|
// we check that the fingerprint is indeed dirty
|
|
|
|
.with_stderr_contains("[..]Dirty[..]the list of declared features changed")
|
|
|
|
// that is cause rustc to be called again with the new check-cfg args
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a"))
|
|
|
|
// and that we indeed found a new warning from the unexpected_cfgs lint
|
|
|
|
.with_stderr_contains("[..]unexpected_cfgs[..]")
|
2023-12-01 20:55:16 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2023-10-18 12:15:43 +00:00
|
|
|
fn well_known_names_values() {
|
2022-04-14 10:20:36 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2024-01-17 18:12:53 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_test() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("test -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_doctest() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["f_a"]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("test -v --doc")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
2024-03-09 22:48:48 +00:00
|
|
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2023-10-18 12:15:43 +00:00
|
|
|
fn well_known_names_values_test() {
|
2022-04-14 10:20:36 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("test -v")
|
2024-01-17 18:12:53 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2023-10-18 12:15:43 +00:00
|
|
|
fn well_known_names_values_doctest() {
|
2022-04-14 10:20:36 +00:00
|
|
|
let p = project()
|
|
|
|
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
|
|
|
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("test -v --doc")
|
2024-01-17 18:12:53 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-14 10:20:36 +00:00
|
|
|
fn features_doc() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-14 10:20:36 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-14 10:20:36 +00:00
|
|
|
|
|
|
|
[features]
|
|
|
|
default = ["f_a"]
|
|
|
|
f_a = []
|
|
|
|
f_b = []
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "#[allow(dead_code)] fn foo() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("doc -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "feature" with "default" "f_a" "f_b"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "docsrs"))
|
2024-03-09 22:48:48 +00:00
|
|
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
2022-04-14 10:20:36 +00:00
|
|
|
.run();
|
|
|
|
}
|
2022-04-07 10:10:00 +00:00
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-07 10:10:00 +00:00
|
|
|
fn build_script_feedback() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-07 10:10:00 +00:00
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
2023-06-11 08:02:03 +00:00
|
|
|
r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#,
|
2022-04-07 10:10:00 +00:00
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2024-03-09 22:48:48 +00:00
|
|
|
.with_stderr_does_not_contain("[..]-Zunstable-options[..]")
|
2022-04-07 10:10:00 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-07 10:10:00 +00:00
|
|
|
fn build_script_doc() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-07 10:10:00 +00:00
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
2023-06-11 08:02:03 +00:00
|
|
|
r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#,
|
2022-04-07 10:10:00 +00:00
|
|
|
)
|
|
|
|
.build();
|
2023-10-18 12:15:43 +00:00
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("doc -v")
|
2022-04-07 10:10:00 +00:00
|
|
|
.with_stderr_does_not_contain("rustc [..] --check-cfg [..]")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
2022-04-07 10:10:00 +00:00
|
|
|
.with_stderr(
|
|
|
|
"\
|
|
|
|
[COMPILING] foo v0.0.1 ([CWD])
|
|
|
|
[RUNNING] `rustc [..] build.rs [..]`
|
|
|
|
[RUNNING] `[..]/build-script-build`
|
|
|
|
[DOCUMENTING] foo [..]
|
|
|
|
[RUNNING] `rustdoc [..] src/main.rs [..]
|
2024-02-08 19:56:17 +00:00
|
|
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [..]
|
2023-10-19 15:40:49 +00:00
|
|
|
[GENERATED] [CWD]/target/doc/foo/index.html
|
|
|
|
",
|
2022-04-07 10:10:00 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-07 10:10:00 +00:00
|
|
|
fn build_script_override() {
|
|
|
|
let target = cargo_test_support::rustc_host();
|
|
|
|
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
2022-09-22 19:50:54 +00:00
|
|
|
[package]
|
2022-04-07 10:10:00 +00:00
|
|
|
name = "foo"
|
|
|
|
version = "0.5.0"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-07 10:10:00 +00:00
|
|
|
authors = []
|
|
|
|
links = "a"
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file("build.rs", "")
|
|
|
|
.file(
|
2024-01-26 19:40:46 +00:00
|
|
|
".cargo/config.toml",
|
2022-04-07 10:10:00 +00:00
|
|
|
&format!(
|
|
|
|
r#"
|
|
|
|
[target.{}.a]
|
2023-10-18 12:15:43 +00:00
|
|
|
rustc-check-cfg = ["cfg(foo)"]
|
2022-04-07 10:10:00 +00:00
|
|
|
"#,
|
|
|
|
target
|
|
|
|
),
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("check -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
2024-01-25 13:54:09 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with))
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs"))
|
2022-04-07 10:10:00 +00:00
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
2022-04-07 10:10:00 +00:00
|
|
|
fn build_script_test() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
2024-02-29 21:48:14 +00:00
|
|
|
edition = "2015"
|
2022-04-07 10:10:00 +00:00
|
|
|
authors = []
|
|
|
|
build = "build.rs"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
2023-12-07 01:44:27 +00:00
|
|
|
r#"fn main() {
|
2023-06-11 08:02:03 +00:00
|
|
|
println!("cargo::rustc-check-cfg=cfg(foo)");
|
|
|
|
println!("cargo::rustc-cfg=foo");
|
2022-04-07 10:10:00 +00:00
|
|
|
}"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"src/lib.rs",
|
|
|
|
r#"
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// extern crate foo;
|
|
|
|
///
|
|
|
|
/// fn main() {
|
|
|
|
/// foo::foo()
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
#[cfg(foo)]
|
|
|
|
pub fn foo() {}
|
|
|
|
|
|
|
|
#[cfg(foo)]
|
|
|
|
#[test]
|
|
|
|
fn test_foo() {
|
|
|
|
foo()
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("tests/test.rs", "#[cfg(foo)] #[test] fn test_bar() {}")
|
|
|
|
.build();
|
|
|
|
|
2024-03-09 22:48:48 +00:00
|
|
|
p.cargo("test -v")
|
2023-10-18 12:15:43 +00:00
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "foo"))
|
2022-04-07 10:10:00 +00:00
|
|
|
.with_stdout_contains("test test_foo ... ok")
|
|
|
|
.with_stdout_contains("test test_bar ... ok")
|
|
|
|
.with_stdout_contains_n("test [..] ... ok", 3)
|
2023-10-27 15:10:49 +00:00
|
|
|
.run();
|
|
|
|
}
|
2024-05-15 19:31:20 +00:00
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_simple() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)", "cfg(has_bar, values(\"yes\", \"no\"))"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_bar" with "yes" "no"))
|
|
|
|
.with_stderr_does_not_contain("[..]unused manifest key[..]")
|
|
|
|
.run();
|
|
|
|
}
|
2024-05-16 11:39:29 +00:00
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_workspace() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo/"]
|
|
|
|
|
|
|
|
[workspace.lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints]
|
|
|
|
workspace = true
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("foo/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.with_stderr_does_not_contain("unexpected_cfgs")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_workspace_not_inherited() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[workspace]
|
|
|
|
members = ["foo/"]
|
|
|
|
|
|
|
|
[workspace.lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file(
|
|
|
|
"foo/Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("foo/src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.with_stderr_does_not_contain("unexpected_cfgs")
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_invalid_position() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
use_bracket = { level = "warn", check-cfg = ["cfg(has_foo)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains("[..]unused manifest key: `lints.rust.use_bracket.check-cfg`[..]")
|
|
|
|
.with_stderr_does_not_contain(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_invalid_empty() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
|
|
|
.with_stderr_contains("[..]missing field `level`[..]")
|
|
|
|
.run_expect_error();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_invalid_not_list() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = "cfg()" }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
2024-05-16 16:44:45 +00:00
|
|
|
.with_status(101)
|
2024-05-16 11:39:29 +00:00
|
|
|
.with_stderr_contains(
|
2024-05-16 16:44:45 +00:00
|
|
|
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
|
2024-05-16 11:39:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_invalid_not_list_string() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = [12] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check")
|
2024-05-16 16:44:45 +00:00
|
|
|
.with_status(101)
|
2024-05-16 11:39:29 +00:00
|
|
|
.with_stderr_contains(
|
2024-05-16 16:44:45 +00:00
|
|
|
"[ERROR] `lints.rust.unexpected_cfgs.check-cfg` must be a list of string",
|
2024-05-16 11:39:29 +00:00
|
|
|
)
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_and_features() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
my_feature = []
|
|
|
|
alloc = []
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)", "cfg(has_bar, values(\"yes\", \"no\"))"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_bar" with "yes" "no"))
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "alloc" "my_feature"))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_with_cargo_doc() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("doc -v")
|
|
|
|
.with_stderr_contains(x!("rustdoc" => "cfg" of "has_foo"))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_with_cargo_test() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(has_foo)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("test -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "has_foo"))
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_and_build_script() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
edition = "2021"
|
|
|
|
build = "build.rs"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo")) // from build.rs
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "bar")) // from config
|
|
|
|
.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_features_and_build_script() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.0.1"
|
|
|
|
edition = "2021"
|
|
|
|
build = "build.rs"
|
|
|
|
|
|
|
|
[features]
|
|
|
|
serde = []
|
|
|
|
json = []
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/main.rs", "fn main() {}")
|
|
|
|
.file(
|
|
|
|
"build.rs",
|
|
|
|
r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#,
|
|
|
|
)
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo")) // from build.rs
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "bar")) // from config
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "feature" with "json" "serde")) // features
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "docsrs")) // Cargo well known
|
|
|
|
.run();
|
|
|
|
}
|
2024-05-23 11:12:37 +00:00
|
|
|
|
|
|
|
#[cargo_test(>=1.79, reason = "--check-cfg was stabilized in Rust 1.79")]
|
|
|
|
fn config_fingerprint() {
|
|
|
|
let p = project()
|
|
|
|
.file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)"] }
|
|
|
|
"#,
|
|
|
|
)
|
|
|
|
.file("src/lib.rs", "fn entry() {}")
|
|
|
|
.build();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
|
|
|
|
.run();
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
|
|
|
.with_stderr_does_not_contain("[..]rustc[..]")
|
|
|
|
.run();
|
|
|
|
|
2024-05-23 11:20:11 +00:00
|
|
|
// checking that changing the `check-cfg` config does invalid the fingerprint
|
2024-05-23 11:12:37 +00:00
|
|
|
p.change_file(
|
|
|
|
"Cargo.toml",
|
|
|
|
r#"
|
|
|
|
[package]
|
|
|
|
name = "foo"
|
|
|
|
version = "0.1.0"
|
|
|
|
edition = "2015"
|
|
|
|
|
|
|
|
[lints.rust]
|
|
|
|
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(bar)", "cfg(foo)"] }
|
|
|
|
"#,
|
|
|
|
);
|
|
|
|
|
|
|
|
p.cargo("check -v")
|
2024-05-23 11:20:11 +00:00
|
|
|
// we check that the fingerprint is indeed dirty
|
|
|
|
.with_stderr_contains("[..]Dirty[..]the profile configuration changed")
|
|
|
|
// that cause rustc to be called again with the new check-cfg args
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "bar"))
|
|
|
|
.with_stderr_contains(x!("rustc" => "cfg" of "foo"))
|
2024-05-23 11:12:37 +00:00
|
|
|
.run();
|
|
|
|
}
|