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 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 {
|
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];
|
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::{
|
use reid::{
|
||||||
compile_module,
|
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 codegen = assert_err(mir_context.codegen(&context));
|
||||||
|
|
||||||
let output = codegen.compile().output();
|
let output = codegen.compile().output();
|
||||||
let in_path = PathBuf::from("/tmp/temp.o");
|
let time = SystemTime::now();
|
||||||
let out_path = in_path.with_extension("out");
|
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!");
|
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")
|
LDRunner::from_command("ld")
|
||||||
.with_library("c")
|
.with_library("c")
|
||||||
.invoke(&in_path, &out_path);
|
.invoke(&in_path, &out_path);
|
||||||
|
std::fs::remove_file(in_path).unwrap();
|
||||||
|
|
||||||
let executed = Command::new(&out_path).output().unwrap();
|
let executed = Command::new(&out_path).output();
|
||||||
assert_eq!(expected_exit_code, executed.status.code().unwrap());
|
std::fs::remove_file(out_path).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(expected_exit_code, executed.unwrap().status.code().unwrap());
|
||||||
|
|
||||||
Ok::<(), ()>(())
|
Ok::<(), ()>(())
|
||||||
})))
|
})))
|
||||||
@ -43,64 +60,63 @@ fn test(source: &str, name: &str, expected_exit_code: i32) {
|
|||||||
fn arithmetic_compiles_well() {
|
fn arithmetic_compiles_well() {
|
||||||
test(include_str!("../../examples/arithmetic.reid"), "test", 48);
|
test(include_str!("../../examples/arithmetic.reid"), "test", 48);
|
||||||
}
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn array_compiles_well() {
|
fn array_structs_compiles_well() {
|
||||||
// test(include_str!("../../examples/array.reid"), "test");
|
test(include_str!("../../examples/array_structs.reid"), "test", 5);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn array_structs_compiles_well() {
|
fn array_compiles_well() {
|
||||||
// test(include_str!("../../examples/array_structs.reid"), "test");
|
test(include_str!("../../examples/array.reid"), "test", 3);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn borrow_compiles_well() {
|
fn borrow_compiles_well() {
|
||||||
// test(include_str!("../../examples/borrow.reid"), "test");
|
test(include_str!("../../examples/borrow.reid"), "test", 17);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn borrow_hard_compiles_well() {
|
fn borrow_hard_compiles_well() {
|
||||||
// test(include_str!("../../examples/borrow_hard.reid"), "test");
|
test(include_str!("../../examples/borrow_hard.reid"), "test", 17);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn cast_compiles_well() {
|
fn cast_compiles_well() {
|
||||||
// test(include_str!("../../examples/cast.reid"), "test");
|
test(include_str!("../../examples/cast.reid"), "test", 6);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn char_compiles_well() {
|
fn char_compiles_well() {
|
||||||
// test(include_str!("../../examples/char.reid"), "test");
|
test(include_str!("../../examples/char.reid"), "test", 98);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn div_mod_compiles_well() {
|
fn div_mod_compiles_well() {
|
||||||
// test(include_str!("../../examples/div_mod.reid"), "test");
|
test(include_str!("../../examples/div_mod.reid"), "test", 12);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn fibonacci_compiles_well() {
|
fn fibonacci_compiles_well() {
|
||||||
// test(include_str!("../../examples/fibonacci.reid"), "test");
|
test(include_str!("../../examples/fibonacci.reid"), "test", 1);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn float_compiles_well() {
|
fn float_compiles_well() {
|
||||||
// test(include_str!("../../examples/float.reid"), "test");
|
test(include_str!("../../examples/float.reid"), "test", 1);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn hello_world_compiles_well() {
|
fn hello_world_compiles_well() {
|
||||||
// test(include_str!("../../examples/hello_world.reid"), "test");
|
test(include_str!("../../examples/hello_world.reid"), "test", 0);
|
||||||
// }
|
}
|
||||||
// #[test]
|
#[test]
|
||||||
// fn mutable_compiles_well() {
|
fn mutable_compiles_well() {
|
||||||
// test(include_str!("../../examples/mutable.reid"), "test");
|
test(include_str!("../../examples/mutable.reid"), "test", 21);
|
||||||
// }
|
}
|
||||||
|
#[test]
|
||||||
// #[test]
|
fn ptr_compiles_well() {
|
||||||
// fn ptr_compiles_well() {
|
test(include_str!("../../examples/ptr.reid"), "test", 5);
|
||||||
// test(include_str!("../../examples/ptr.reid"), "test");
|
}
|
||||||
// }
|
#[test]
|
||||||
// #[test]
|
fn std_test_compiles_well() {
|
||||||
// fn std_test_compiles_well() {
|
test(include_str!("../../examples/std_test.reid"), "test", 3);
|
||||||
// test(include_str!("../../examples/std_test.reid"), "test");
|
}
|
||||||
// }
|
#[test]
|
||||||
// #[test]
|
fn strings_compiles_well() {
|
||||||
// fn strings_compiles_well() {
|
test(include_str!("../../examples/strings.reid"), "test", 5);
|
||||||
// test(include_str!("../../examples/strings.reid"), "test");
|
}
|
||||||
// }
|
#[test]
|
||||||
// #[test]
|
fn struct_compiles_well() {
|
||||||
// fn struct_compiles_well() {
|
test(include_str!("../../examples/struct.reid"), "test", 17);
|
||||||
// test(include_str!("../../examples/struct.reid"), "test");
|
}
|
||||||
// }
|
|
||||||
|
Loading…
Reference in New Issue
Block a user