Skip to content

Commit

Permalink
Add tests for --json unused-externs
Browse files Browse the repository at this point in the history
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
(rust-lang#96068). This is fixed in
subsequent changes.
  • Loading branch information
jsgf committed Apr 27, 2022
1 parent 0981b98 commit 2373599
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/test/ui/unused-crate-deps/deny-attr.rs
Original file line number Diff line number Diff line change
@@ -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() {}
14 changes: 14 additions & 0 deletions src/test/ui/unused-crate-deps/deny-attr.stderr
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions src/test/ui/unused-crate-deps/deny-cmdline-json.rs
Original file line number Diff line number Diff line change
@@ -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() {}
1 change: 1 addition & 0 deletions src/test/ui/unused-crate-deps/deny-cmdline-json.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"lint_level":"deny","unused_extern_names":["bar"]}
8 changes: 8 additions & 0 deletions src/test/ui/unused-crate-deps/deny-cmdline.rs
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions src/test/ui/unused-crate-deps/deny-cmdline.stderr
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions src/test/ui/unused-crate-deps/warn-cmdline-json.rs
Original file line number Diff line number Diff line change
@@ -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() {}
1 change: 1 addition & 0 deletions src/test/ui/unused-crate-deps/warn-cmdline-json.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"lint_level":"warn","unused_extern_names":["bar"]}

0 comments on commit 2373599

Please sign in to comment.