-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathharness.rs
83 lines (75 loc) · 1.63 KB
/
harness.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![feature(rustc_private)]
#[macro_use]
mod common;
use common::*;
#[test]
fn harness_zero() {
assert!(
verify_one_file(
"harness_zero",
verus_code! {
fn harness1() {
}
},
&[]
)
.is_ok()
);
}
#[test]
fn harness_invalid_rust() {
let code = verus_code! {
fn harness1() {
invalid(true);
}
};
let err = verify_one_file("harness_invalid_rust", code, &[]).unwrap_err();
assert_eq!(err.errors.len(), 1);
assert_rust_error_msg(err, "cannot find function `invalid` in this scope");
}
#[test]
fn harness_true() {
assert!(
verify_one_file(
"harness_true",
verus_code! {
fn harness1() {
assert(true);
}
},
&[]
)
.is_ok()
);
}
#[test]
fn harness_false() {
let err = verify_one_file(
"harness_false",
verus_code! {
fn harness2() {
assert(false); // FAILS
}
},
&[],
)
.unwrap_err();
assert_eq!(err.errors.len(), 1);
assert!(err.errors[0].spans.first().expect("span").text[0].text.contains("FAILS"));
}
test_verify_one_file! {
#[test] harness_macro_true verus_code! {
fn empty() { }
fn harness1_macro() {
assert(true);
}
} => Ok(())
}
test_verify_one_file! {
#[test] harness_macro_false verus_code! {
fn empty() { }
fn harness2_macro() {
assert(false); // FAILS
}
} => Err(err) => assert_one_fails(err)
}