From 4a4256cf1963a349c8d63f4f93c7c562e8963d59 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Tue, 16 Jul 2019 12:43:02 -0700 Subject: [PATCH] port compile-fail tests to trybuild enable testing for all packages on CircleCI on stable/nightly --- .circleci/config.yml | 12 +++++--- phf_macros/Cargo.toml | 6 ++-- .../compile-fail-unicase/equivalent-keys.rs | 7 ++--- .../equivalent-keys.stderr | 11 +++++++ phf_macros/tests/compile-fail/bad-syntax.rs | 4 --- .../tests/compile-fail/bad-syntax.stderr | 11 +++++++ phf_macros/tests/compiletest.rs | 29 ++++--------------- 7 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 phf_macros/tests/compile-fail-unicase/equivalent-keys.stderr create mode 100644 phf_macros/tests/compile-fail/bad-syntax.stderr diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e6ed3c7..4bccb88b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -30,9 +30,12 @@ jobs: - *RESTORE_REGISTRY - run: cargo generate-lockfile - *SAVE_REGISTRY - - run: rustc --version > ~/rust-version + - run: rustc --version | tee ~/rust-version - *RESTORE_DEPS + - run: cargo test + - run: (cd phf_macros && cargo test) - run: cargo test -p phf_codegen_test + - run: (cd phf_shared && cargo build --features core) - *SAVE_DEPS nightly: docker: @@ -44,10 +47,11 @@ jobs: - *RESTORE_REGISTRY - run: cargo generate-lockfile - *SAVE_REGISTRY - - run: rustc --version > ~/rust-version - - run: cargo test -p phf_macros + - run: rustc --version | tee ~/rust-version + - run: cargo test + - run: (cd phf_macros && cargo test && cargo test -- --ignored --test-threads=1) - run: cargo test -p phf_codegen_test - - run: cargo test --manifest-path phf/Cargo.toml --features macros + - run: (cd phf_shared && cargo build --features core) workflows: version: 2 diff --git a/phf_macros/Cargo.toml b/phf_macros/Cargo.toml index 2e1e1ded..53a1b059 100644 --- a/phf_macros/Cargo.toml +++ b/phf_macros/Cargo.toml @@ -20,6 +20,6 @@ phf_generator = { version = "0.7.24", path = "../phf_generator" } phf_shared = { version = "0.7.24", path = "../phf_shared" } [dev-dependencies] -# requires nightly to build and dev-deps can't be optional -# compiletest_rs = "0.3.22" -phf = { version = "0.7", path = "../phf", features = ["macros"] } +trybuild = "1.0" +phf = { version = "0.7", path = "../phf", features = ["macros", "unicase"] } +unicase = "2.4.0" diff --git a/phf_macros/tests/compile-fail-unicase/equivalent-keys.rs b/phf_macros/tests/compile-fail-unicase/equivalent-keys.rs index 978b321d..2a520a1b 100644 --- a/phf_macros/tests/compile-fail-unicase/equivalent-keys.rs +++ b/phf_macros/tests/compile-fail-unicase/equivalent-keys.rs @@ -1,8 +1,5 @@ -#![feature(plugin)] -#![plugin(phf_macros)] - -extern crate phf; -extern crate unicase; +use unicase::UniCase; +use phf::phf_map; static MAP: phf::Map, isize> = phf_map!( //~ ERROR duplicate key UniCase("FOO") UniCase("FOO") => 42, //~ NOTE one occurrence here diff --git a/phf_macros/tests/compile-fail-unicase/equivalent-keys.stderr b/phf_macros/tests/compile-fail-unicase/equivalent-keys.stderr new file mode 100644 index 00000000..cf5de93b --- /dev/null +++ b/phf_macros/tests/compile-fail-unicase/equivalent-keys.stderr @@ -0,0 +1,11 @@ +error: unsupported key expression + --> $DIR/equivalent-keys.rs:5:5 + | +5 | UniCase("FOO") => 42, //~ NOTE one occurrence here + | ^^^^^^^^^^^^^^ + +error[E0601]: `main` function not found in crate `$CRATE` + | + = note: consider adding a `main` function to `$DIR/tests/compile-fail-unicase/equivalent-keys.rs` + +For more information about this error, try `rustc --explain E0601`. diff --git a/phf_macros/tests/compile-fail/bad-syntax.rs b/phf_macros/tests/compile-fail/bad-syntax.rs index fe953ed2..bff0d161 100644 --- a/phf_macros/tests/compile-fail/bad-syntax.rs +++ b/phf_macros/tests/compile-fail/bad-syntax.rs @@ -1,7 +1,3 @@ -#![feature(proc_macro_hygiene)] - -extern crate phf; - use phf::phf_map; static MAP: phf::Map = phf_map! { diff --git a/phf_macros/tests/compile-fail/bad-syntax.stderr b/phf_macros/tests/compile-fail/bad-syntax.stderr new file mode 100644 index 00000000..c3a3e11d --- /dev/null +++ b/phf_macros/tests/compile-fail/bad-syntax.stderr @@ -0,0 +1,11 @@ +error: expected identifier + --> $DIR/bad-syntax.rs:5:5 + | +5 | => //~ ERROR expected identifier + | ^^ + +error[E0601]: `main` function not found in crate `$CRATE` + | + = note: consider adding a `main` function to `$DIR/tests/compile-fail/bad-syntax.rs` + +For more information about this error, try `rustc --explain E0601`. diff --git a/phf_macros/tests/compiletest.rs b/phf_macros/tests/compiletest.rs index 4efa872c..c95f3c80 100644 --- a/phf_macros/tests/compiletest.rs +++ b/phf_macros/tests/compiletest.rs @@ -1,32 +1,13 @@ -#![cfg(compiletest)] - -extern crate compiletest_rs as compiletest; - -use compiletest::Config; -use std::path::Path; - -#[allow(dead_code)] -fn run_mode(directory: &'static str, mode: &'static str) { - let mut config = Config::default(); - let cfg_mode = mode.parse().ok().expect("Invalid mode"); - - config.mode = cfg_mode; - let dir = Path::new(env!("CARGO_MANIFEST_DIR")); - config.target_rustcflags = Some(format!("-L {}", dir.join("../target/debug/deps").display())); - config.src_base = dir.join("tests").join(directory); - - compiletest::run_tests(&config); -} - -#[cfg(feature = "unicase_support")] #[test] -#[ignore] +#[ignore] // compiler error message format is different between 1.32.0 and nightly fn compile_test_unicase() { - run_mode("compile-fail-unicase", "compile-fail"); + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile-fail-unicase/*.rs"); } #[test] #[ignore] fn compile_fail() { - run_mode("compile-fail", "compile-fail"); + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile-fail/*.rs"); }