mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 21:40:43 +00:00
f2e6a8f4a5
This doesn't contain all changes for 507 yet but we might want to do the Luau 0.507 release a bit earlier to end the year sooner. Changes: - Type ascription (::) now permits casts between related types in both directions, allowing to refine or loosen the type (RFC #56) - Fix type definition for tonumber to return number? since the input string isn't guaranteed to contain a valid number - Fix type refinements for field access via [] - Many stability fixes for type checker - Provide extra information in error messages for type mismatches in more cases - Improve performance of type checking for large unions when union members are string literals - Add coverage reporting support to Repl (--coverage command line argument) and lua_getcoverage C API - Work around code signing issues during Makefile builds on macOS - Improve performance of truthiness checks in some cases, particularly on Apple M1, resulting in 10-25% perf gains on qsort benchmark depending on the CPU/compiler - Fix support for little-endian systems; IBM s390x here we go!
64 lines
1.2 KiB
Lua
64 lines
1.2 KiB
Lua
-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
print("testing coverage")
|
|
|
|
function foo()
|
|
local x = 1
|
|
local y = 2
|
|
assert(x + y)
|
|
end
|
|
|
|
function bar()
|
|
local function one(x)
|
|
return x
|
|
end
|
|
|
|
local two = function(x)
|
|
return x
|
|
end
|
|
|
|
one(1)
|
|
end
|
|
|
|
function validate(stats, hits, misses)
|
|
local checked = {}
|
|
|
|
for _,l in ipairs(hits) do
|
|
if not (stats[l] and stats[l] > 0) then
|
|
return false, string.format("expected line %d to be hit", l)
|
|
end
|
|
checked[l] = true
|
|
end
|
|
|
|
for _,l in ipairs(misses) do
|
|
if not (stats[l] and stats[l] == 0) then
|
|
return false, string.format("expected line %d to be missed", l)
|
|
end
|
|
checked[l] = true
|
|
end
|
|
|
|
for k,v in pairs(stats) do
|
|
if type(k) == "number" and not checked[k] then
|
|
return false, string.format("expected line %d to be absent", k)
|
|
end
|
|
end
|
|
|
|
return true
|
|
end
|
|
|
|
foo()
|
|
c = getcoverage(foo)
|
|
assert(#c == 1)
|
|
assert(c[1].name == "foo")
|
|
assert(validate(c[1], {5, 6, 7}, {}))
|
|
|
|
bar()
|
|
c = getcoverage(bar)
|
|
assert(#c == 3)
|
|
assert(c[1].name == "bar")
|
|
assert(validate(c[1], {11, 15, 19}, {}))
|
|
assert(c[2].name == "one")
|
|
assert(validate(c[2], {12}, {}))
|
|
assert(c[3].name == nil)
|
|
assert(validate(c[3], {}, {16}))
|
|
|
|
return 'OK'
|