Skip to content

Commit f012d9f

Browse files
authored
Merge pull request #90 from fuine/compiletest
Add support for compiler tests
2 parents 72424ad + e5b6815 commit f012d9f

File tree

7 files changed

+67
-7
lines changed

7 files changed

+67
-7
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ 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 clean &&
19+
travis-cargo --only nightly build -- --features compiletest &&
20+
travis-cargo --only nightly test -- --features compiletest &&
21+
travis-cargo --only nightly clean &&
1822
travis-cargo --only stable doc
1923
after_success:
2024
- travis-cargo --only stable doc-upload

Cargo.toml

+5
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" }

appveyor.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ environment:
4040
# (Based on from https://github.com/rust-lang/libc/blob/master/appveyor.yml)
4141
install:
4242
- appveyor-retry appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
43-
- rustup-init.exe -y --default-host %TARGET%
43+
- rustup-init.exe -y --default-toolchain %CHANNEL% --default-host %TARGET%
4444
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
4545
- if "%TARGET%" == "i686-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw32\bin
4646
- if "%TARGET%" == "x86_64-pc-windows-gnu" set PATH=%PATH%;C:\msys64\mingw64\bin
@@ -50,5 +50,10 @@ install:
5050
build: false
5151

5252
test_script:
53-
- cargo build --verbose --target %TARGET%
54-
- cargo test --target %TARGET%
53+
- cargo build --verbose
54+
- cargo test
55+
- if [%CHANNEL%]==[nightly] (
56+
cargo clean &&
57+
cargo build --verbose --features "compiletest" &&
58+
cargo test --features "compiletest"
59+
)

tests/compile-fail/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
This directory contains snippets of code that should yield a
2+
warning/note/help/error at compilation. Syntax of annotations is described in
3+
[rust documentation](https://github.com/rust-lang/rust/blob/master/src/test/COMPILER_TESTS.md).
4+
For more information check out [`compiletest` crate](https://github.com/laumann/compiletest-rs).
5+
6+
To run compile tests issue `cargo +nightly --test --features compiletest`.
7+
8+
## Notes on working with `compiletest` crate
9+
10+
* Currently code that is inside macro should not be annotated, as `compiletest`
11+
crate cannot deal with the fact that macro invocations effectively changes
12+
line numbering. To prevent this add a `// error-pattern:<your error message here>`
13+
on the top of the file and make sure that you set `deny` lint level
14+
if you want to test compiler message different than error.
15+
* `compiletest` crate by default sets `allow(dead_code)` lint level so make sure
16+
that you change it to something suiting your needs even if the warning is
17+
issued prior to any macro invocation.
18+
* If you get a message `error: 0 unexpected errors found, 1 expected errors not found`
19+
despite the fact that some error was bound to occur don't worry - it's a known
20+
issue in the `compiletest` crate and your error was probably not registered -
21+
make sure that your annotations are correct and that you are setting correct
22+
lint levels.
+10
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

+18
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+
fn run_mode(mode: &'static str) {
5+
let mut config = compiletest::Config::default();
6+
config.mode = mode.parse().expect("Invalid mode");
7+
config.src_base = ["tests", mode].iter().collect();
8+
config.target_rustcflags = Some("-L target/debug/ -L target/debug/deps/".to_owned());
9+
10+
config.verbose = true;
11+
12+
compiletest::run_tests(&config);
13+
}
14+
15+
#[test]
16+
fn compile_test() {
17+
run_mode("compile-fail");
18+
}

tests/test.rs

-4
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)