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
|
// tests for the test runtime itself
use rt;
fn compile() void = {
rt::compile(rt::status::SUCCESS, "
fn test() void = {
void;
};"
)!;
rt::compile(rt::status::CHECK, "
fn test() void = {
let a: int = [1, 2, 3];
};"
)!;
};
let global = 0i;
fn foofn() str = {
global += 1;
return "foo";
};
def FOO: str = "foo";
type s = str;
type b = bool;
static assert(true);
static assert(true, "msg");
fn assert_() void = {
let foo = "foo";
static assert(true, "foo");
static assert(true: b, "foo");
static assert(true, "foo": s);
static assert(true, FOO);
static assert(true: b, FOO);
static assert(true, FOO: s);
assert(true, "foo");
assert(true: b, "foo");
assert(true, "foo": s);
assert(true, FOO);
assert(true: b, FOO);
assert(true, FOO: s);
assert(true, foo);
assert(true: b, foo);
assert(true, foo: s);
assert(true, foofn());
assert(true: b, foofn());
assert(true, foofn(): s);
assert(global == 0); // no side effects if assertion succeeds
let failures: [_]str = [
// types
"fn f() void = { assert(5); };",
"fn f() void = { assert(true, 5); };",
"fn f() void = { static assert(5); };",
"fn f() void = { static assert(true, 5); };",
// compile-time eval
"fn f() void = { let a = true; static assert(a); };",
"fn f() void = { let a = \"foo\"; static assert(true, a); };",
// top-level static assertions
"static assert(false);",
];
for (let i = 0z; i < len(failures); i += 1) {
rt::compile(rt::status::CHECK, failures[i])!;
};
rt::compile(rt::status::PARSE, "export static assert(true);")!;
};
export fn main() void = {
assert_();
compile();
};
|