Add tests for --json unused-externs

There were none at all. These test for original functionality,
but this also adds a test that `-Dunused-crate-dependencies`
causes a compilation failure, which currently fails
(https://github.com/rust-lang/rust/issues/96068). This is fixed in
subsequent changes.
This commit is contained in:
Jeremy Fitzhardinge 2022-04-15 10:33:08 -07:00
parent 0981b9857e
commit 2373599b82
8 changed files with 58 additions and 0 deletions

View File

@ -0,0 +1,9 @@
// Check for unused crate dep, no path
// edition:2018
// aux-crate:bar=bar.rs
#![deny(unused_crate_dependencies)]
//~^ ERROR external crate `bar` unused in
fn main() {}

View File

@ -0,0 +1,14 @@
error: external crate `bar` unused in `deny_attr`: remove the dependency or add `use bar as _;`
--> $DIR/deny-attr.rs:6:1
|
LL | #![deny(unused_crate_dependencies)]
| ^
|
note: the lint level is defined here
--> $DIR/deny-attr.rs:6:9
|
LL | #![deny(unused_crate_dependencies)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to previous error

View File

@ -0,0 +1,7 @@
// Check for unused crate dep, no path
// edition:2018
// compile-flags: -Dunused-crate-dependencies -Zunstable-options --json unused-externs --error-format=json
// aux-crate:bar=bar.rs
fn main() {}

View File

@ -0,0 +1 @@
{"lint_level":"deny","unused_extern_names":["bar"]}

View File

@ -0,0 +1,8 @@
// Check for unused crate dep, no path
// edition:2018
// compile-flags: -Dunused-crate-dependencies
// aux-crate:bar=bar.rs
fn main() {}
//~^ ERROR external crate `bar` unused in

View File

@ -0,0 +1,10 @@
error: external crate `bar` unused in `deny_cmdline`: remove the dependency or add `use bar as _;`
--> $DIR/deny-cmdline.rs:7:1
|
LL | fn main() {}
| ^
|
= note: requested on the command line with `-D unused-crate-dependencies`
error: aborting due to previous error

View File

@ -0,0 +1,8 @@
// Check for unused crate dep, no path
// edition:2018
// check-pass
// compile-flags: -Wunused-crate-dependencies -Zunstable-options --json unused-externs --error-format=json
// aux-crate:bar=bar.rs
fn main() {}

View File

@ -0,0 +1 @@
{"lint_level":"warn","unused_extern_names":["bar"]}