Skip to content

Commit ae41877

Browse files
committed
Merge pull request #7 from oli-obk/compiletest
use compiletest_rs
2 parents 86d8a07 + 211c12a commit ae41877

22 files changed

+81
-62
lines changed

Cargo.lock

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ name = "miri"
1212

1313
[dependencies]
1414
byteorder = "0.4.2"
15+
16+
[dev-dependencies]
17+
compiletest_rs = "0.1.1"

src/bin/miri.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ extern crate rustc_driver;
66

77
use miri::interpreter;
88
use rustc::session::Session;
9-
use rustc_driver::{driver, CompilerCalls, Compilation};
9+
use rustc_driver::{driver, CompilerCalls};
1010

1111
struct MiriCompilerCalls;
1212

1313
impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
1414
fn build_controller(&mut self, _: &Session) -> driver::CompileController<'a> {
1515
let mut control = driver::CompileController::basic();
16-
control.after_analysis.stop = Compilation::Stop;
1716

1817
control.after_analysis.callback = Box::new(|state| {
1918
state.session.abort_if_errors();
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(custom_attribute)]
32
#![allow(dead_code, unused_attributes)]
43

@@ -9,33 +8,33 @@ fn overwriting_part_of_relocation_makes_the_rest_undefined() -> i32 {
98
let ptr: *mut _ = &mut p;
109
*(ptr as *mut u32) = 123;
1110
}
12-
*p
11+
*p //~ ERROR: attempted to read undefined bytes
1312
}
1413

1514
#[miri_run]
1615
fn pointers_to_different_allocations_are_unorderable() -> bool {
1716
let x: *const u8 = &1;
1817
let y: *const u8 = &2;
19-
x < y
18+
x < y //~ ERROR: attempted to do math or a comparison on pointers into different allocations
2019
}
2120

2221
#[miri_run]
2322
fn invalid_bool() -> u8 {
2423
let b = unsafe { std::mem::transmute::<u8, bool>(2) };
25-
if b { 1 } else { 2 }
24+
if b { 1 } else { 2 } //~ ERROR: invalid boolean value read
2625
}
2726

2827
#[miri_run]
2928
fn undefined_byte_read() -> u8 {
3029
let v: Vec<u8> = Vec::with_capacity(10);
3130
let undef = unsafe { *v.get_unchecked(5) };
32-
undef + 1
31+
undef + 1 //~ ERROR: attempted to read undefined bytes
3332
}
3433

3534
#[miri_run]
3635
fn out_of_bounds_read() -> u8 {
3736
let v: Vec<u8> = vec![1, 2];
38-
unsafe { *v.get_unchecked(5) }
37+
unsafe { *v.get_unchecked(5) } //~ ERROR: pointer offset outside bounds of allocation
3938
}
4039

4140
#[miri_run]
@@ -44,5 +43,7 @@ fn dangling_pointer_deref() -> i32 {
4443
let b = Box::new(42);
4544
&*b as *const i32
4645
};
47-
unsafe { *p }
46+
unsafe { *p } //~ ERROR: dangling pointer was dereferenced
4847
}
48+
49+
fn main() {}

tests/compile-test.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

tests/compiletest.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
extern crate compiletest_rs as compiletest;
2+
3+
use std::path::PathBuf;
4+
5+
fn run_mode(mode: &'static str) {
6+
let mut config = compiletest::default_config();
7+
config.rustc_path = "target/debug/miri".into();
8+
let path = std::env::var("RUST_SYSROOT").expect("env variable `RUST_SYSROOT` not set");
9+
config.target_rustcflags = Some(format!("--sysroot {}", path));
10+
config.host_rustcflags = Some(format!("--sysroot {}", path));
11+
let cfg_mode = mode.parse().ok().expect("Invalid mode");
12+
13+
config.mode = cfg_mode;
14+
config.src_base = PathBuf::from(format!("tests/{}", mode));
15+
16+
compiletest::run_tests(&config);
17+
}
18+
19+
#[test]
20+
fn compile_test() {
21+
run_mode("compile-fail");
22+
run_mode("run-pass");
23+
}

tests/run-pass/arrays.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(custom_attribute)]
32
#![allow(dead_code, unused_attributes)]
43

@@ -33,3 +32,5 @@ fn index() -> i32 {
3332
fn array_repeat() -> [u8; 8] {
3433
[42; 8]
3534
}
35+
36+
fn main() {}

tests/run-pass/bools.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(custom_attribute)]
32
#![allow(dead_code, unused_attributes)]
43

@@ -27,3 +26,5 @@ fn match_bool() -> i16 {
2726
_ => 0,
2827
}
2928
}
29+
30+
fn main() {}

tests/run-pass/c_enums.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(custom_attribute)]
32
#![allow(dead_code, unused_attributes)]
43

@@ -20,3 +19,5 @@ fn unsafe_match() -> bool {
2019
_ => false,
2120
}
2221
}
22+
23+
fn main() {}

tests/run-pass/calls.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![crate_type = "lib"]
21
#![feature(custom_attribute)]
32
#![allow(dead_code, unused_attributes)]
43

@@ -39,3 +38,5 @@ fn cross_crate_fn_call() -> i64 {
3938
fn test_size_of() -> usize {
4039
::std::mem::size_of::<Option<i32>>()
4140
}
41+
42+
fn main() {}

0 commit comments

Comments
 (0)