test_compiler.rs 657 Bytes
Newer Older
John Zhang's avatar
John Zhang committed
1
extern crate libloading as ll;
2
extern crate mu;
3 4 5

use test_ir::test_ir::sum;
use test_ir::test_ir::factorial;
6
use mu::testutil;
7 8

#[test]
John Zhang's avatar
John Zhang committed
9 10
fn test_factorial() {
    let lib = testutil::compile_fnc("fac", &factorial);
11
    unsafe {
John Zhang's avatar
John Zhang committed
12 13 14
        let fac: ll::Symbol<unsafe extern fn (u64) -> u64> = lib.get(b"fac").unwrap();
        println!("fac(10) = {}", fac(10));
        assert!(fac(10) == 3628800);
15 16 17 18
    }
}

#[test]
John Zhang's avatar
John Zhang committed
19 20
fn test_sum() {
    let lib = testutil::compile_fnc("sum", &sum);
21
    unsafe {
John Zhang's avatar
John Zhang committed
22 23 24 25 26
        let sumptr: ll::Symbol<unsafe extern fn (u64) -> u64> = lib.get(b"sum").unwrap();
        assert!(sumptr(5) == 10);
        assert!(sumptr(10) == 45);
    }
}