Skip to content

Commit

Permalink
Merge pull request #166 from abonander/158-trybuild
Browse files Browse the repository at this point in the history
port compile-fail tests to trybuild
  • Loading branch information
abonander committed Jul 18, 2019
2 parents c5959b4 + 4a4256c commit 50c6c75
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
12 changes: 8 additions & 4 deletions .circleci/config.yml
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions phf_macros/Cargo.toml
Expand Up @@ -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"
7 changes: 2 additions & 5 deletions 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<UniCase<&'static str>, isize> = phf_map!( //~ ERROR duplicate key UniCase("FOO")
UniCase("FOO") => 42, //~ NOTE one occurrence here
Expand Down
11 changes: 11 additions & 0 deletions 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`.
4 changes: 0 additions & 4 deletions 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<u32, u32> = phf_map! {
Expand Down
11 changes: 11 additions & 0 deletions 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`.
29 changes: 5 additions & 24 deletions 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");
}

0 comments on commit 50c6c75

Please sign in to comment.