Skip to content

Commit 84cebef

Browse files
committed
Added support for compiler tests
1 parent 72424ad commit 84cebef

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ script:
1515
travis-cargo --only nightly build -- --features spin_no_std &&
1616
travis-cargo --only nightly test -- --features spin_no_std &&
1717
travis-cargo --only nightly bench -- --features spin_no_std &&
18+
travis-cargo --only nightly build -- --features compiletest &&
19+
travis-cargo --only nightly test -- --features compiletest &&
1820
travis-cargo --only stable doc
1921
after_success:
2022
- travis-cargo --only stable doc-upload

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ categories = [ "no-std", "rust-patterns" ]
1717
version = "0.4"
1818
optional = true
1919

20+
[dependencies.compiletest_rs]
21+
version = "0.3"
22+
optional = true
23+
2024
[features]
2125
nightly = []
2226
spin_no_std = ["nightly", "spin"]
27+
compiletest = ["compiletest_rs"]
2328

2429
[badges]
2530
appveyor = { repository = "rust-lang-nursery/lazy-static.rs" }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// error-pattern:static item is never used: `UNUSED`
2+
#![deny(dead_code)]
3+
#[macro_use]
4+
extern crate lazy_static;
5+
6+
lazy_static! {
7+
static ref UNUSED: () = ();
8+
}
9+
10+
fn main() { }

tests/compile_tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![cfg(feature="compiletest")]
2+
extern crate compiletest_rs as compiletest;
3+
4+
use std::path::PathBuf;
5+
6+
fn run_mode(mode: &'static str) {
7+
let mut config = compiletest::Config::default();
8+
config.mode = mode.parse().expect("Invalid mode");
9+
config.src_base = PathBuf::from(format!("tests/{}", mode));
10+
config.target_rustcflags = Some("-L target/debug".to_string());
11+
12+
compiletest::run_tests(&config);
13+
}
14+
15+
#[test]
16+
fn compile_test() {
17+
run_mode("compile-fail");
18+
}

tests/test.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ lazy_static! {
2727
static ref UNSAFE: u32 = unsafe {
2828
std::mem::transmute::<i32, u32>(-1)
2929
};
30-
31-
// This *should* triggger warn(dead_code) by design.
32-
static ref UNUSED: () = ();
33-
3430
}
3531

3632
lazy_static! {

0 commit comments

Comments
 (0)