Skip to content

Commit

Permalink
Add compile tests for crate = "..."
Browse files Browse the repository at this point in the history
  • Loading branch information
TedDriggs committed Nov 28, 2022
1 parent 757a8c5 commit 2439b97
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
16 changes: 16 additions & 0 deletions derive_builder/tests/compile-fail/crate_root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#[macro_use]
extern crate derive_builder;

// This is a stand-in for any bad crate directive
mod empty {}

#[derive(Builder)]
// It would be nice if the "failed to resolve" errors would identify `"empty"` as the error span,
// but doing so would require rewriting a lot of the code generation to use the crate_root span
// for the full path of the thing being imported, and that doesn't seem worth the code churn.
#[builder(crate = "empty")]
struct BadCrate {
lorem: String,
}

fn main() {}
97 changes: 97 additions & 0 deletions derive_builder/tests/compile-fail/crate_root.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ could not find `export` in `empty`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty::export::core::option`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this enum
|
5 | use derive_builder::export::core::option::Option;
|

error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty::export::core::clone`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
|
5 | use derive_builder::export::core::clone::Clone;
|

error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty::export::core::result`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these items
|
5 | use derive_builder::export::core::fmt::Result;
|
5 | use derive_builder::export::core::io::Result;
|
5 | use derive_builder::export::core::result::Result;
|
5 | use derive_builder::export::core::thread::Result;
|

error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty::export::core::convert`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
|
5 | use derive_builder::export::core::convert::Into;
|

error[E0433]: failed to resolve: could not find `UninitializedFieldError` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
5 | use derive_builder::UninitializedFieldError;
|

error[E0433]: failed to resolve: could not find `export` in `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty::export::core::default`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this trait
|
5 | use derive_builder::export::core::default::Default;
|

error[E0412]: cannot find type `UninitializedFieldError` in module `empty`
--> tests/compile-fail/crate_root.rs:7:10
|
7 | #[derive(Builder)]
| ^^^^^^^ not found in `empty`
|
= note: this error originates in the derive macro `Builder` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this struct
|
5 | use derive_builder::UninitializedFieldError;
|
24 changes: 24 additions & 0 deletions derive_builder/tests/run-pass/crate_alias.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! Test that an alias of derive_builder is valid in #[builder(crate = "...")]
//!
//! This test is imperfect, as it still passes without setting `crate = "..."`.
//! This is likely because `derive_builder` is automatically present in 2018
//! without needing the extern crate line.
//!
//! The test will fail if an incorrect alias is used, so it adds limited value.

#[macro_use]
extern crate derive_builder as db;

#[derive(Builder)]
#[builder(crate = "db")]
struct AliasedCrate {
#[builder(setter(into))]
lorem: String,
}

fn main() {
AliasedCrateBuilder::default()
.lorem("hello")
.build()
.unwrap();
}

0 comments on commit 2439b97

Please sign in to comment.