Make the name of the crate available in cargo UI tests

This commit is contained in:
Eduardo Broto 2020-05-22 22:30:28 +02:00
parent c41916d9bd
commit cff5cff2f3
7 changed files with 18 additions and 5 deletions

View File

@ -76,7 +76,8 @@ fn create_test(lint: &LintData) -> io::Result<()> {
path.push("src");
fs::create_dir(&path)?;
write_file(path.join("main.rs"), get_test_file_contents(lint_name))?;
let header = format!("// compile-flags: --crate-name={}", lint_name);
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
Ok(())
}
@ -90,7 +91,7 @@ fn create_test(lint: &LintData) -> io::Result<()> {
create_project_layout(lint.name, &test_dir, "pass", "This file should not trigger the lint")
} else {
let test_path = format!("tests/ui/{}.rs", lint.name);
let test_contents = get_test_file_contents(lint.name);
let test_contents = get_test_file_contents(lint.name, None);
write_file(lint.project_root.join(test_path), test_contents)
}
}
@ -119,8 +120,8 @@ fn to_camel_case(name: &str) -> String {
.collect()
}
fn get_test_file_contents(lint_name: &str) -> String {
format!(
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
let mut contents = format!(
"#![warn(clippy::{})]
fn main() {{
@ -128,7 +129,13 @@ fn main() {{
}}
",
lint_name
)
);
if let Some(header) = header_commands {
contents = format!("{}\n{}", header, contents);
}
contents
}
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=cargo_common_metadata
#![warn(clippy::cargo_common_metadata)]
fn main() {}

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=multiple_crate_versions
#![warn(clippy::multiple_crate_versions)]
fn main() {}

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=multiple_crate_versions
#![warn(clippy::multiple_crate_versions)]
fn main() {}

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=wildcard_dependencies
#![warn(clippy::wildcard_dependencies)]
fn main() {}

View File

@ -1,3 +1,4 @@
// compile-flags: --crate-name=wildcard_dependencies
#![warn(clippy::wildcard_dependencies)]
fn main() {}