diff options
| author | Eduardo Broto <ebroto@tutanota.com> | 2020-05-22 22:30:28 +0200 |
|---|---|---|
| committer | Eduardo Broto <ebroto@tutanota.com> | 2020-05-25 20:00:08 +0200 |
| commit | cff5cff2f3a6687dfaf12b92762e70545e0abefe (patch) | |
| tree | 981c18b14cf0ce24d81f434c927ca0a5746f3b7c /clippy_dev | |
| parent | c41916d9bd2ca98c9291d07a095503d9e934da60 (diff) | |
Make the name of the crate available in cargo UI tests
Diffstat (limited to 'clippy_dev')
| -rw-r--r-- | clippy_dev/src/new_lint.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/clippy_dev/src/new_lint.rs b/clippy_dev/src/new_lint.rs index 08a2e0c0918..c0b2dac2f60 100644 --- a/clippy_dev/src/new_lint.rs +++ b/clippy_dev/src/new_lint.rs @@ -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 { |
