Skip to content

Commit

Permalink
Migrate from compiletest_rs to trybuild
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Sep 12, 2020
1 parent 9e6bf5c commit f132704
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 37 deletions.
3 changes: 2 additions & 1 deletion derive_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ derive_builder_core = { version = "=0.10.0-alpha", path = "../derive_builder_cor

[dev-dependencies]
pretty_assertions = "0.6"
compiletest_rs = "0.5"
skeptic = "0.13"
rustversion = "1"
trybuild = "1"

[build-dependencies]
skeptic = { version = "0.13", optional = true }
1 change: 0 additions & 1 deletion derive_builder/tests/compile-fail/deny_empty_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ extern crate derive_builder;
#[derive(Builder)]
struct Lorem {
#[builder(default = "")]
//~^ ERROR Unknown literal value ``
ipsum: String,
}

Expand Down
5 changes: 5 additions & 0 deletions derive_builder/tests/compile-fail/deny_empty_default.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error: Unknown literal value ``
--> $DIR/deny_empty_default.rs:8:25
|
8 | #[builder(default = "")]
| ^^
3 changes: 1 addition & 2 deletions derive_builder/tests/compile-fail/private_build_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ fn main() {
let lorem1 = LoremBuilder::default().my_build();

let lorem2 = LoremBuilder::default().build().unwrap();
//~^ ERROR `build` is private

println!("{:?} vs {:?}", lorem1, lorem2);
}
}
13 changes: 13 additions & 0 deletions derive_builder/tests/compile-fail/private_build_fn.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
warning: unused import: `Lorem`
--> $DIR/private_build_fn.rs:23:21
|
23 | use container::{Lorem, LoremBuilder};
| ^^^^^
|
= note: `#[warn(unused_imports)]` on by default

error[E0624]: method `build` is private
--> $DIR/private_build_fn.rs:27:42
|
27 | let lorem2 = LoremBuilder::default().build().unwrap();
| ^^^^^
2 changes: 0 additions & 2 deletions derive_builder/tests/compile-fail/private_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ pub mod foo {

fn main() {
let x = foo::LoremBuilder::default()
//~^ ERROR struct `LoremBuilder` is private
.public("Hello")
.build()
//~^ ERROR `build` is private
.unwrap();

assert_eq!(x.public, "Hello".to_string());
Expand Down
11 changes: 11 additions & 0 deletions derive_builder/tests/compile-fail/private_builder.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0603]: struct `LoremBuilder` is private
--> $DIR/private_builder.rs:17:18
|
17 | let x = foo::LoremBuilder::default()
| ^^^^^^^^^^^^

error[E0624]: method `build` is private
--> $DIR/private_builder.rs:19:10
|
19 | .build()
| ^^^^^
3 changes: 1 addition & 2 deletions derive_builder/tests/compile-fail/private_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ fn main() {
lorem.dolor(15u16);
lorem.sit = Some(true); // <-- public
lorem.dolor = Some(0); // <-- private
//~^ ERROR field `dolor` of struct `inner::LoremBuilder` is private
}
}
5 changes: 5 additions & 0 deletions derive_builder/tests/compile-fail/private_fields.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
error[E0616]: field `dolor` of struct `inner::LoremBuilder` is private
--> $DIR/private_fields.rs:25:5
|
25 | lorem.dolor = Some(0); // <-- private
| ^^^^^^^^^^^
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ extern crate derive_builder;

#[derive(Debug, PartialEq, Default, Builder, Clone)]
#[builder(setter(name = "foo"))]
//~^ ERROR Unknown field: `name`
struct Lorem {
ipsum: &'static str,
pub dolor: &'static str,
}

fn main() {
let x = LoremBuilder::default()
//~^ ERROR use of undeclared type or module `LoremBuilder`
.ipsum("ipsum")
.foo("dolor")
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: Unknown field: `name`
--> $DIR/rename_setter_struct_level.rs:7:18
|
7 | #[builder(setter(name = "foo"))]
| ^^^^

error[E0433]: failed to resolve: use of undeclared type or module `LoremBuilder`
--> $DIR/rename_setter_struct_level.rs:14:13
|
14 | let x = LoremBuilder::default()
| ^^^^^^^^^^^^ use of undeclared type or module `LoremBuilder`
32 changes: 6 additions & 26 deletions derive_builder/tests/compiletests.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
extern crate compiletest_rs as compiletest;

use std::env;
use std::path::PathBuf;

fn run_mode(mode: &'static str) {
let base_dir = env!("CARGO_MANIFEST_DIR");

let test_dir = PathBuf::from(format!("{}/tests/{}", base_dir, mode));

if !test_dir.is_dir() {
panic!("Directory does not exist: {:?}", test_dir);
}

let mut config = compiletest::Config::default();
let cfg_mode = mode.parse().ok().expect("Invalid mode");

config.mode = cfg_mode;
config.src_base = test_dir;
config.link_deps();
config.clean_rmeta();

compiletest::run_tests(&config);
}
extern crate trybuild;
extern crate rustversion;

#[rustversion::stable(1.40)]
#[test]
fn compile_test() {
run_mode("run-pass");
run_mode("compile-fail");
let t = trybuild::TestCases::new();
t.pass("tests/run-pass/*.rs");
t.compile_fail("tests/compile-fail/*.rs");
}
2 changes: 1 addition & 1 deletion derive_builder_core/build/skeptic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use std::io::{Write, Read};
const DOC_TPL_DIR: &'static str = "src/doc_tpl/";
const DOC_TPL_OUT_DIR: &'static str = "doc_tpl/";

fn generate_doc_tpl_tests() -> Result<Vec<String>, Box<Error>> {
fn generate_doc_tpl_tests() -> Result<Vec<String>, Box<dyn Error>> {
trace!("Generating doc template tests");
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR")?);
let mut tpl_dir = root_dir;
Expand Down

0 comments on commit f132704

Please sign in to comment.