Set up test code per version
This commit is contained in:
parent
13d719ac06
commit
47d755a570
@ -6,50 +6,36 @@ local LUA_NAN_CANONICAL = -(0 / 0)
|
|||||||
local LUA_NAN_DEFAULT = -(0 / 0)
|
local LUA_NAN_DEFAULT = -(0 / 0)
|
||||||
local LUA_INFINITY = math.huge
|
local LUA_INFINITY = math.huge
|
||||||
|
|
||||||
local function is_number_equality(lhs, rhs)
|
local function is_number_equal(lhs, rhs)
|
||||||
if type(lhs) ~= "number" or type(rhs) ~= "number" then
|
if type(lhs) ~= "number" or type(rhs) ~= "number" then
|
||||||
return false
|
return false
|
||||||
elseif lhs ~= lhs and rhs ~= rhs then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return math.abs(lhs - rhs) < 0.00001 or string.format("%.3g", lhs) == string.format("%.3g", rhs)
|
return math.abs(lhs - rhs) < 0.00001 or string.format("%.3g", lhs) == string.format("%.3g", rhs)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function assert_eq(lhs, rhs, message, level)
|
local function assert_eq(lhs, rhs, level)
|
||||||
if lhs == rhs or is_number_equality(lhs, rhs) then
|
if lhs == rhs or is_number_equal(lhs, rhs) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if message then
|
|
||||||
message = ": " .. message
|
|
||||||
else
|
|
||||||
message = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
lhs = tostring(lhs)
|
lhs = tostring(lhs)
|
||||||
rhs = tostring(rhs)
|
rhs = tostring(rhs)
|
||||||
level = (level or 1) + 1
|
level = (level or 1) + 1
|
||||||
|
|
||||||
error(lhs .. " ~= " .. rhs .. message, level)
|
error(lhs .. " ~= " .. rhs, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function assert_neq(lhs, rhs, message, level)
|
local function assert_neq(lhs, rhs, level)
|
||||||
if lhs ~= rhs and not is_number_equality(lhs, rhs) then
|
if lhs ~= rhs and not is_number_equal(lhs, rhs) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if message then
|
|
||||||
message = ": " .. message
|
|
||||||
else
|
|
||||||
message = ""
|
|
||||||
end
|
|
||||||
|
|
||||||
lhs = tostring(lhs)
|
lhs = tostring(lhs)
|
||||||
rhs = tostring(rhs)
|
rhs = tostring(rhs)
|
||||||
level = (level or 1) + 1
|
level = (level or 1) + 1
|
||||||
|
|
||||||
error(lhs .. " == " .. rhs .. message, level)
|
error(lhs .. " == " .. rhs, level)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function raw_invoke(func, ...)
|
local function raw_invoke(func, ...)
|
||||||
@ -63,8 +49,8 @@ local function assert_trap(func, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function assert_return(data, wanted)
|
local function assert_return(data, wanted)
|
||||||
for i, v in ipairs(wanted) do
|
for i, v in wanted do
|
||||||
assert_eq(data[i], v, "Result mismatch at " .. i, 2)
|
assert_eq(data[i], v, 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -73,3 +59,22 @@ local function assert_exhaustion(func, ...)
|
|||||||
error("Failed to exhaust", 2)
|
error("Failed to exhaust", 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
linked.spectest = {
|
||||||
|
func_list = {
|
||||||
|
print = print,
|
||||||
|
print_f32 = print,
|
||||||
|
print_f64 = print,
|
||||||
|
print_f64_f64 = print,
|
||||||
|
print_i32 = print,
|
||||||
|
print_i32_f32 = print,
|
||||||
|
},
|
||||||
|
global_list = {
|
||||||
|
global_f32 = { value = 666 },
|
||||||
|
global_f64 = { value = 666 },
|
||||||
|
global_i32 = { value = 666 },
|
||||||
|
global_i64 = { value = 666LL },
|
||||||
|
},
|
||||||
|
table_list = { table = { data = {} } },
|
||||||
|
memory_list = { memory = rt.allocator.new(1, 2) },
|
||||||
|
}
|
@ -14,28 +14,7 @@ use target::{get_name_from_id, Target};
|
|||||||
|
|
||||||
mod target;
|
mod target;
|
||||||
|
|
||||||
static ASSERTION: &str = include_str!("assertion.lua");
|
static ASSERTION: &str = include_str!("luajit_assert.lua");
|
||||||
|
|
||||||
static SPEC_TEST: &str = "
|
|
||||||
linked.spectest = {
|
|
||||||
func_list = {
|
|
||||||
print = print,
|
|
||||||
print_f32 = print,
|
|
||||||
print_f64 = print,
|
|
||||||
print_f64_f64 = print,
|
|
||||||
print_i32 = print,
|
|
||||||
print_i32_f32 = print,
|
|
||||||
},
|
|
||||||
global_list = {
|
|
||||||
global_f32 = { value = 666 },
|
|
||||||
global_f64 = { value = 666 },
|
|
||||||
global_i32 = { value = 666 },
|
|
||||||
global_i64 = { value = 666LL },
|
|
||||||
},
|
|
||||||
table_list = { table = { data = {} } },
|
|
||||||
memory_list = { memory = rt.allocator.new(1, 2) },
|
|
||||||
}
|
|
||||||
";
|
|
||||||
|
|
||||||
struct LuaJIT;
|
struct LuaJIT;
|
||||||
|
|
||||||
@ -155,9 +134,8 @@ impl Target for LuaJIT {
|
|||||||
fn write_runtime(w: &mut dyn Write) -> Result<()> {
|
fn write_runtime(w: &mut dyn Write) -> Result<()> {
|
||||||
let runtime = codegen_luajit::RUNTIME;
|
let runtime = codegen_luajit::RUNTIME;
|
||||||
|
|
||||||
writeln!(w, "{ASSERTION}")?;
|
|
||||||
writeln!(w, "local rt = (function() {runtime} end)()")?;
|
writeln!(w, "local rt = (function() {runtime} end)()")?;
|
||||||
writeln!(w, "{SPEC_TEST}")
|
writeln!(w, "{ASSERTION}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_module(data: &Module, name: Option<&str>, w: &mut dyn Write) -> Result<()> {
|
fn write_module(data: &Module, name: Option<&str>, w: &mut dyn Write) -> Result<()> {
|
||||||
|
84
dev-test/tests/luau_assert.lua
Normal file
84
dev-test/tests/luau_assert.lua
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
local loaded = {}
|
||||||
|
local linked = {}
|
||||||
|
|
||||||
|
local LUA_NAN_ARITHMETIC = -(0 / 0)
|
||||||
|
local LUA_NAN_CANONICAL = -(0 / 0)
|
||||||
|
local LUA_NAN_DEFAULT = -(0 / 0)
|
||||||
|
local LUA_INFINITY = math.huge
|
||||||
|
|
||||||
|
local function is_number_equal(lhs, rhs)
|
||||||
|
if type(lhs) == "table" and type(rhs) == "table" then
|
||||||
|
return rt.eq.i64(lhs, rhs)
|
||||||
|
elseif type(lhs) ~= "number" or type(rhs) ~= "number" then
|
||||||
|
return false
|
||||||
|
elseif lhs ~= lhs and rhs ~= rhs then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
return math.abs(lhs - rhs) < 0.00001 or string.format("%.3g", lhs) == string.format("%.3g", rhs)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_eq(lhs, rhs, level)
|
||||||
|
if lhs == rhs or is_number_equal(lhs, rhs) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
lhs = tostring(lhs)
|
||||||
|
rhs = tostring(rhs)
|
||||||
|
level = (level or 1) + 1
|
||||||
|
|
||||||
|
error(lhs .. " ~= " .. rhs, level)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_neq(lhs, rhs, level)
|
||||||
|
if lhs ~= rhs and not is_number_equal(lhs, rhs) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
lhs = tostring(lhs)
|
||||||
|
rhs = tostring(rhs)
|
||||||
|
level = (level or 1) + 1
|
||||||
|
|
||||||
|
error(lhs .. " == " .. rhs, level)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function raw_invoke(func, ...)
|
||||||
|
return func(...)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_trap(func, ...)
|
||||||
|
if pcall(func, ...) then
|
||||||
|
error("Failed to trap", 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_return(data, wanted)
|
||||||
|
for i, v in wanted do
|
||||||
|
assert_eq(data[i], v, 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function assert_exhaustion(func, ...)
|
||||||
|
if pcall(func, ...) then
|
||||||
|
error("Failed to exhaust", 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
linked.spectest = {
|
||||||
|
func_list = {
|
||||||
|
print = print,
|
||||||
|
print_f32 = print,
|
||||||
|
print_f64 = print,
|
||||||
|
print_f64_f64 = print,
|
||||||
|
print_i32 = print,
|
||||||
|
print_i32_f32 = print,
|
||||||
|
},
|
||||||
|
global_list = {
|
||||||
|
global_f32 = { value = 666 },
|
||||||
|
global_f64 = { value = 666 },
|
||||||
|
global_i32 = { value = 666 },
|
||||||
|
global_i64 = { value = rt.i64.from_u32(666, 0) },
|
||||||
|
},
|
||||||
|
table_list = { table = { data = {} } },
|
||||||
|
memory_list = { memory = rt.allocator.new(1, 2) },
|
||||||
|
}
|
@ -14,28 +14,7 @@ use target::{get_name_from_id, Target};
|
|||||||
|
|
||||||
mod target;
|
mod target;
|
||||||
|
|
||||||
static ASSERTION: &str = include_str!("assertion.lua");
|
static ASSERTION: &str = include_str!("luau_assert.lua");
|
||||||
|
|
||||||
static SPEC_TEST: &str = "
|
|
||||||
linked.spectest = {
|
|
||||||
func_list = {
|
|
||||||
print = print,
|
|
||||||
print_f32 = print,
|
|
||||||
print_f64 = print,
|
|
||||||
print_f64_f64 = print,
|
|
||||||
print_i32 = print,
|
|
||||||
print_i32_f32 = print,
|
|
||||||
},
|
|
||||||
global_list = {
|
|
||||||
global_f32 = { value = 666 },
|
|
||||||
global_f64 = { value = 666 },
|
|
||||||
global_i32 = { value = 666 },
|
|
||||||
global_i64 = { value = rt.i64.from_u32(666, 0) },
|
|
||||||
},
|
|
||||||
table_list = { table = { data = {} } },
|
|
||||||
memory_list = { memory = rt.allocator.new(1, 2) },
|
|
||||||
}
|
|
||||||
";
|
|
||||||
|
|
||||||
struct Luau;
|
struct Luau;
|
||||||
|
|
||||||
@ -162,9 +141,8 @@ impl Target for Luau {
|
|||||||
fn write_runtime(w: &mut dyn Write) -> Result<()> {
|
fn write_runtime(w: &mut dyn Write) -> Result<()> {
|
||||||
let runtime = codegen_luau::RUNTIME;
|
let runtime = codegen_luau::RUNTIME;
|
||||||
|
|
||||||
writeln!(w, "{ASSERTION}")?;
|
|
||||||
writeln!(w, "local rt = (function() {runtime} end)()")?;
|
writeln!(w, "local rt = (function() {runtime} end)()")?;
|
||||||
writeln!(w, "{SPEC_TEST}")
|
writeln!(w, "{ASSERTION}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_module(data: &Module, name: Option<&str>, w: &mut dyn Write) -> Result<()> {
|
fn write_module(data: &Module, name: Option<&str>, w: &mut dyn Write) -> Result<()> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user