Check that tests always return a specific value
This commit is contained in:
parent
59ecaa0d92
commit
9fcf19383c
@ -18,7 +18,7 @@ fn main() -> u32 {
|
||||
|
||||
let mut a = &mut value;
|
||||
|
||||
let test = *a.field;
|
||||
*a.second[2] = 5;
|
||||
|
||||
return 0;
|
||||
return *a.second[2];
|
||||
}
|
||||
|
@ -8,11 +8,9 @@ fn other() -> i16 {
|
||||
}
|
||||
|
||||
fn main() -> u32 {
|
||||
let value = other() as u32;
|
||||
let other_value = other() as f32;
|
||||
let same_value = other() as i16;
|
||||
|
||||
let v = (allocate(4) as *u32);
|
||||
let mut v = (allocate(4) as *u32);
|
||||
v[0] = other() as u32;
|
||||
|
||||
return v[0];
|
||||
}
|
||||
|
@ -1,4 +1,10 @@
|
||||
use std::{path::PathBuf, process::Command};
|
||||
use std::{
|
||||
alloc::System,
|
||||
path::PathBuf,
|
||||
process::Command,
|
||||
thread,
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
use reid::{
|
||||
compile_module,
|
||||
@ -25,15 +31,26 @@ fn test(source: &str, name: &str, expected_exit_code: i32) {
|
||||
let codegen = assert_err(mir_context.codegen(&context));
|
||||
|
||||
let output = codegen.compile().output();
|
||||
let in_path = PathBuf::from("/tmp/temp.o");
|
||||
let out_path = in_path.with_extension("out");
|
||||
let time = SystemTime::now();
|
||||
let in_path = PathBuf::from(format!(
|
||||
"/tmp/temp-{}.o",
|
||||
time.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_nanos()
|
||||
));
|
||||
|
||||
std::fs::write(&in_path, &output.obj_buffer).expect("Could not write OBJ-file!");
|
||||
|
||||
let out_path = in_path.with_extension("out");
|
||||
LDRunner::from_command("ld")
|
||||
.with_library("c")
|
||||
.invoke(&in_path, &out_path);
|
||||
std::fs::remove_file(in_path).unwrap();
|
||||
|
||||
let executed = Command::new(&out_path).output().unwrap();
|
||||
assert_eq!(expected_exit_code, executed.status.code().unwrap());
|
||||
let executed = Command::new(&out_path).output();
|
||||
std::fs::remove_file(out_path).unwrap();
|
||||
|
||||
assert_eq!(expected_exit_code, executed.unwrap().status.code().unwrap());
|
||||
|
||||
Ok::<(), ()>(())
|
||||
})))
|
||||
@ -43,64 +60,63 @@ fn test(source: &str, name: &str, expected_exit_code: i32) {
|
||||
fn arithmetic_compiles_well() {
|
||||
test(include_str!("../../examples/arithmetic.reid"), "test", 48);
|
||||
}
|
||||
// #[test]
|
||||
// fn array_compiles_well() {
|
||||
// test(include_str!("../../examples/array.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn array_structs_compiles_well() {
|
||||
// test(include_str!("../../examples/array_structs.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn borrow_compiles_well() {
|
||||
// test(include_str!("../../examples/borrow.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn borrow_hard_compiles_well() {
|
||||
// test(include_str!("../../examples/borrow_hard.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn cast_compiles_well() {
|
||||
// test(include_str!("../../examples/cast.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn char_compiles_well() {
|
||||
// test(include_str!("../../examples/char.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn div_mod_compiles_well() {
|
||||
// test(include_str!("../../examples/div_mod.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn fibonacci_compiles_well() {
|
||||
// test(include_str!("../../examples/fibonacci.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn float_compiles_well() {
|
||||
// test(include_str!("../../examples/float.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn hello_world_compiles_well() {
|
||||
// test(include_str!("../../examples/hello_world.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn mutable_compiles_well() {
|
||||
// test(include_str!("../../examples/mutable.reid"), "test");
|
||||
// }
|
||||
|
||||
// #[test]
|
||||
// fn ptr_compiles_well() {
|
||||
// test(include_str!("../../examples/ptr.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn std_test_compiles_well() {
|
||||
// test(include_str!("../../examples/std_test.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn strings_compiles_well() {
|
||||
// test(include_str!("../../examples/strings.reid"), "test");
|
||||
// }
|
||||
// #[test]
|
||||
// fn struct_compiles_well() {
|
||||
// test(include_str!("../../examples/struct.reid"), "test");
|
||||
// }
|
||||
#[test]
|
||||
fn array_structs_compiles_well() {
|
||||
test(include_str!("../../examples/array_structs.reid"), "test", 5);
|
||||
}
|
||||
#[test]
|
||||
fn array_compiles_well() {
|
||||
test(include_str!("../../examples/array.reid"), "test", 3);
|
||||
}
|
||||
#[test]
|
||||
fn borrow_compiles_well() {
|
||||
test(include_str!("../../examples/borrow.reid"), "test", 17);
|
||||
}
|
||||
#[test]
|
||||
fn borrow_hard_compiles_well() {
|
||||
test(include_str!("../../examples/borrow_hard.reid"), "test", 17);
|
||||
}
|
||||
#[test]
|
||||
fn cast_compiles_well() {
|
||||
test(include_str!("../../examples/cast.reid"), "test", 6);
|
||||
}
|
||||
#[test]
|
||||
fn char_compiles_well() {
|
||||
test(include_str!("../../examples/char.reid"), "test", 98);
|
||||
}
|
||||
#[test]
|
||||
fn div_mod_compiles_well() {
|
||||
test(include_str!("../../examples/div_mod.reid"), "test", 12);
|
||||
}
|
||||
#[test]
|
||||
fn fibonacci_compiles_well() {
|
||||
test(include_str!("../../examples/fibonacci.reid"), "test", 1);
|
||||
}
|
||||
#[test]
|
||||
fn float_compiles_well() {
|
||||
test(include_str!("../../examples/float.reid"), "test", 1);
|
||||
}
|
||||
#[test]
|
||||
fn hello_world_compiles_well() {
|
||||
test(include_str!("../../examples/hello_world.reid"), "test", 0);
|
||||
}
|
||||
#[test]
|
||||
fn mutable_compiles_well() {
|
||||
test(include_str!("../../examples/mutable.reid"), "test", 21);
|
||||
}
|
||||
#[test]
|
||||
fn ptr_compiles_well() {
|
||||
test(include_str!("../../examples/ptr.reid"), "test", 5);
|
||||
}
|
||||
#[test]
|
||||
fn std_test_compiles_well() {
|
||||
test(include_str!("../../examples/std_test.reid"), "test", 3);
|
||||
}
|
||||
#[test]
|
||||
fn strings_compiles_well() {
|
||||
test(include_str!("../../examples/strings.reid"), "test", 5);
|
||||
}
|
||||
#[test]
|
||||
fn struct_compiles_well() {
|
||||
test(include_str!("../../examples/struct.reid"), "test", 17);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user