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

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3
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

+1-2
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();
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

-37
This file was deleted.

tests/compiletest.rs

+23
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

+2-1
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

+2-1
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

+2-1
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

+2-1
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() {}

tests/run-pass/closures.rs

+2-1
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

@@ -37,3 +36,5 @@ fn crazy_closure() -> (i32, i32, i32) {
3736
// }
3837
// y
3938
// }
39+
40+
fn main() {}

tests/run-pass/heap.rs

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

@@ -11,3 +10,5 @@ fn make_box() -> Box<(i16, i16)> {
1110
fn make_box_syntax() -> Box<(i16, i16)> {
1211
box (1, 2)
1312
}
13+
14+
fn main() {}

tests/run-pass/ints.rs

+2-1
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

@@ -53,3 +52,5 @@ fn match_int_range() -> i64 {
5352
_ => 5,
5453
}
5554
}
55+
56+
fn main() {}

tests/run-pass/loops.rs

+2-1
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

@@ -34,3 +33,5 @@ fn for_loop() -> usize {
3433
}
3534
sum
3635
}
36+
37+
fn main() {}

tests/run-pass/pointers.rs

+2-1
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

@@ -58,3 +57,5 @@ fn dangling_pointer() -> *const i32 {
5857
let b = Box::new(42);
5958
&*b as *const i32
6059
}
60+
61+
fn main() {}

tests/run-pass/products.rs

+2-1
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

@@ -30,3 +29,5 @@ fn field_access() -> (i8, i8) {
3029
p.x += 5;
3130
(p.x, p.y)
3231
}
32+
33+
fn main() {}

tests/run-pass/specialization.rs

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

@@ -18,3 +17,5 @@ impl IsUnit for () {
1817
fn specialization() -> (bool, bool) {
1918
(i32::is_unit(), <()>::is_unit())
2019
}
20+
21+
fn main() {}

tests/run-pass/std.rs

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

@@ -44,3 +43,5 @@ fn rc_reference_cycle() -> Loop {
4443
fn true_assert() {
4544
assert_eq!(1, 1);
4645
}
46+
47+
fn main() {}

tests/run-pass/strings.rs

+2-1
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

@@ -21,3 +20,5 @@ fn hello_bytes() -> &'static [u8; 13] {
2120
fn hello_bytes_fat() -> &'static [u8] {
2221
b"Hello, world!"
2322
}
23+
24+
fn main() {}

tests/run-pass/sums.rs

+2-1
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

@@ -53,3 +52,5 @@ fn match_opt_some() -> i8 {
5352
fn two_nones() -> (Option<i16>, Option<i16>) {
5453
(None, None)
5554
}
55+
56+
fn main() {}

tests/run-pass/trivial.rs

+2-1
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

@@ -10,3 +9,5 @@ fn unit_var() {
109
let x = ();
1110
x
1211
}
12+
13+
fn main() {}

tests/run-pass/vecs.rs

+2-1
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

@@ -36,3 +35,5 @@ fn vec_reallocate() -> Vec<u8> {
3635
v.push(5);
3736
v
3837
}
38+
39+
fn main() {}

0 commit comments

Comments
 (0)