Skip to content

Commit

Permalink
reorganize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CapsAdmin committed Sep 25, 2024
1 parent f1a7247 commit 98f0057
Show file tree
Hide file tree
Showing 134 changed files with 85 additions and 100 deletions.
20 changes: 10 additions & 10 deletions .vscode/on_editor_save.lua
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ if normalized:find("/nattlua/", nil, true) then
then
run_lua("test/performance/analyzer.lua")
elseif normalized:find("c_declarations/main.lua", nil, true) and not has_test_focus() then
run_lua("test/run.lua", "test/nattlua/c_declarations/cdef.nlua")
run_lua("test/run.lua", "test/nattlua/c_declarations.lua")
run_lua("test/run.lua", "test/nattlua/analyzer/typed_ffi.lua")
run_lua("test/run.lua", "test/tests/c_declarations/cdef.nlua")
run_lua("test/run.lua", "test/tests/c_declarations.lua")
run_lua("test/run.lua", "test/tests/nattlua/analyzer/typed_ffi.lua")
run_lua("examples/projects/luajit/build.lua", path)
run_lua("examples/projects/love2d/nlconfig.lua", path)
elseif normalized:find("c_declarations/analyzer", nil, true) and not has_test_focus() then
run_lua("test/run.lua", "test/nattlua/c_declarations/cdef.nlua")
run_lua("test/run.lua", "test/tests/c_declarations/cdef.nlua")
elseif normalized:find("c_declarations", nil, true) and not has_test_focus() then
run_lua("test/run.lua", "test/nattlua/c_declarations.lua")
run_lua("test/run.lua", "test/tests/c_declarations.lua")
elseif normalized:find("other/coverage", nil, true) then
run_lua("test/run.lua", "test/nattlua/coverage.lua")
run_lua("test/run.lua", "test/tests/coverage.lua")
elseif normalized:find("nattlua/editor_helper/editor.lua", nil, true) then
run_lua("test/run.lua", "test/nattlua/lsp/editor.lua")
run_lua("test/run.lua", "test/tests/lsp/editor.lua")
os.execute("luajit nattlua.lua build fast && luajit nattlua.lua install")
return
elseif normalized:find("language_server/server", nil, true) then
Expand All @@ -163,7 +163,7 @@ if normalized:find("/nattlua/", nil, true) then
elseif is_nattlua and not normalized:find("/definitions/", nil, true) then
run_nattlua(path)
elseif normalized:find("formating.lua", nil, true) then
run_lua("test/run.lua", "test/nattlua/helper_test.lua")
run_lua("test/run.lua", "test/tests/helper_test.lua")
elseif normalized:find("test/", nil, true) then
run_lua("test/run.lua", path)
elseif normalized:find("javascript_emitter") then
Expand All @@ -181,10 +181,10 @@ if normalized:find("/nattlua/", nil, true) then
not normalized:find("nattlua/other")
then
if normalized:find("lexer.lua", nil, true) then
run_lua("test/run.lua", "test/nattlua/lexer.lua")
run_lua("test/run.lua", "test/tests/lexer.lua")
run_lua("test/run.lua", "test/performance/lexer.lua")
elseif normalized:find("parser.lua", nil, true) and false then
run_lua("test/run.lua", "test/nattlua/parser.lua")
run_lua("test/run.lua", "test/tests/parser.lua")
run_lua("test/run.lua", "test/performance/parser.lua")
else
run_lua("test/run.lua")
Expand Down
7 changes: 3 additions & 4 deletions format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,11 @@ local blacklist = {
"test_focus%.lua",
"build_output%.lua",
"nattlua_for_ai%.lua",
"nattlua/other/cparser%.lua",
"nattlua/other/json%.lua",
"language_server/json%.lua",
"examples/benchmarks/temp/10mb%.lua",
"examples/projects/luajit/out%.lua",
"test/nattlua/analyzer/file_importing/deep_error/.*",
"examples/projects/love2d/love%-api/.*",
"test/tests/nattlua/analyzer/file_importing/deep_error/.*",
}

local function is_blacklisted(path)
Expand Down Expand Up @@ -210,4 +209,4 @@ if dictionary then
end
end
end
end
end
2 changes: 1 addition & 1 deletion nattlua/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function META:OnDiagnostic(code, msg, severity, start, stop, node, ...)

if not info then break end

if info.source:find("@test/nattlua", nil, true) then
if info.source:find("@test/tests", nil, true) then
level = i

break
Expand Down
2 changes: 1 addition & 1 deletion test/environment.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ do

function _G.analyze(code, expect_error, expect_warning)
local info = debug.getinfo(2)
local name = info.source:match("(test/nattlua/.+)") or info.source
local name = info.source:match("(test/tests/.+)") or info.source

if not _G.ON_EDITOR_SAVE then
io.write(".")
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/debug.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ do
local path = info.source

if path:sub(1, 1) == "@" then
if path:sub(2):find("test/nattlua/analyzer") then
if path:sub(2):find("test/tests/nattlua/analyzer") then
print(info.source:sub(2) .. ":" .. info.currentline)
end
end
end
end
end

return lib
return lib
2 changes: 0 additions & 2 deletions test/nattlua/analyzer/file_importing/complex/adapter.lua

This file was deleted.

3 changes: 0 additions & 3 deletions test/nattlua/analyzer/file_importing/complex/bar.lua

This file was deleted.

3 changes: 0 additions & 3 deletions test/nattlua/analyzer/file_importing/complex/first_file.lua

This file was deleted.

7 changes: 0 additions & 7 deletions test/nattlua/analyzer/file_importing/complex/foo.lua

This file was deleted.

2 changes: 0 additions & 2 deletions test/nattlua/analyzer/file_importing/complex/main.nlua

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions test/nattlua/analyzer/file_importing/deep_error/main.nlua

This file was deleted.

5 changes: 0 additions & 5 deletions test/nattlua/analyzer/file_importing/require_cache/main.nlua

This file was deleted.

4 changes: 0 additions & 4 deletions test/nattlua/analyzer/file_importing/test/main.nlua

This file was deleted.

15 changes: 0 additions & 15 deletions test/nattlua/typesystem/bench.lua

This file was deleted.

24 changes: 12 additions & 12 deletions test/performance/tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ local time = os.clock()

do
local tests = {
"test/nattlua/lsp/editor.lua",
"test/nattlua/luajit_project.lua",
"test/nattlua/analyzer/complex/self/tuple.nlua",
"test/nattlua/analyzer/complex/self/union.nlua",
"test/nattlua/c_declarations/cdef.nlua",
"test/nattlua/analyzer/complex/self/string.nlua",
"test/nattlua/analyzer/complex/self/lexer.nlua",
"test/nattlua/analyzer/complex/self/base_parser.nlua",
"test/nattlua/analyzer/complex/ljsocket.nlua",
"test/nattlua/analyzer/complex/cdata.nlua",
"test/nattlua/analyzer/load.lua",
"test/nattlua/analyzer/lua.lua",
"test/tests/editor_helper.lua",
"test/tests/nattlua/project.lua",
"test/tests/nattlua/analyzer/complex/self/tuple.nlua",
"test/tests/nattlua/analyzer/complex/self/union.nlua",
"test/tests/nattlua/c_declarations/cdef.nlua",
"test/tests/nattlua/analyzer/complex/self/string.nlua",
"test/tests/nattlua/analyzer/complex/self/lexer.nlua",
"test/tests/nattlua/analyzer/complex/self/base_parser.nlua",
"test/tests/nattlua/analyzer/complex/ljsocket.nlua",
"test/tests/nattlua/analyzer/complex/cdata.nlua",
"test/tests/nattlua/analyzer/load.lua",
"test/tests/nattlua/analyzer/lua.lua",
}

for _, path in ipairs(tests) do
Expand Down
2 changes: 1 addition & 1 deletion test/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ local function find_tests(path)
if path and path:sub(-5) == ".nlua" then return {path} end

local what = path
local path = "test/" .. ((what and what .. "/") or "nattlua/")
local path = "test/" .. ((what and what .. "/") or "tests/")
local found = {}
local cmd = "find"

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local num = require("test.tests.nattlua.analyzer.file_importing.complex.first_file")
return num
3 changes: 3 additions & 0 deletions test/tests/nattlua/analyzer/file_importing/complex/bar.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local val = require("test.tests.nattlua.analyzer.file_importing.complex.test")
val.init()
return val.get()
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local foo = require("test.tests.nattlua.analyzer.file_importing.complex.foo")()
local bar = require("test.tests.nattlua.analyzer.file_importing.complex.bar")
return foo.get() + bar
7 changes: 7 additions & 0 deletions test/tests/nattlua/analyzer/file_importing/complex/foo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
local META = {}
require("test.tests.nattlua.analyzer.file_importing.complex.baz")(META)
require("test.tests.nattlua.analyzer.file_importing.complex.baz")(META)
require("test.tests.nattlua.analyzer.file_importing.complex.baz")(META)
return function(config)
return META
end
2 changes: 2 additions & 0 deletions test/tests/nattlua/analyzer/file_importing/complex/main.nlua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
local num = require("test.tests.nattlua.analyzer.file_importing.complex.first_file")
return num
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
--[[
some lines before the code
]] local a = 2 + 1
-- ERROR3
assert(
loadfile(
"test/tests/nattlua/analyzer/file_importing/deep_error/deep_error/file_that_errors.nlua"
)
)()
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if true then
-- ERROR2
require("test.tests.nattlua.analyzer.file_importing.deep_error.deep_error.foo")
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ local foo = 1337
--[[#local type bar = 888]]
-- these upvalues should not leak to other_file.lua
-- this is fixed by using analyzer:CreateAndPushModuleScope() rather than analyzer:CreateAndPushFunctionScope()
require("test.nattlua.analyzer.file_importing.env_leak.other_file")
require("test.tests.nattlua.analyzer.file_importing.env_leak.other_file")
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
local lib1 = require("test/tests/nattlua/analyzer/file_importing/require_cache/lib")
local lib2 = require("test/tests/nattlua/analyzer/file_importing/require_cache/lib")
-- we cannot guarantee this when doing imports
--§ assert(env.runtime.lib1 == env.runtime.lib2)
attest.equal(lib1, lib2)
4 changes: 4 additions & 0 deletions test/tests/nattlua/analyzer/file_importing/test/main.nlua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local liba = assert(loadfile("test/tests/nattlua/analyzer/file_importing/test/lib_returns_1.nlua"))()
local libb = assert(loadfile("test/tests/nattlua/analyzer/file_importing/test/lib_returns_2.nlua"))()
local libc = assert(loadfile("test/tests/nattlua/analyzer/file_importing/test/foo/returns_5.lua"))
return liba.Foo() + libb.Foo() + libc()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@ analyze[[
attest.equal(assert(load("return " .. 2))(), 2)
]]
analyze[[
attest.equal(require("test.nattlua.analyzer.file_importing.expect_5")(5), 1337)
attest.equal(require("test.tests.nattlua.analyzer.file_importing.expect_5")(5), 1337)
]]
-- file import
equal(
8,
assert(require("nattlua").File("test/nattlua/analyzer/file_importing/test/main.nlua")):Analyze().AnalyzedResult:GetFirstValue():GetData()
assert(require("nattlua").File("test/tests/nattlua/analyzer/file_importing/test/main.nlua")):Analyze().AnalyzedResult:GetFirstValue():GetData()
)
--[=[
run([[
-- ERROR1
loadfile("test/nattlua/analyzer/file_importing/deep_error/main.nlua")()
loadfile("test/tests/nattlua/analyzer/file_importing/deep_error/main.nlua")()
]], function(err)
for i = 1, 4 do
assert(err:find("ERROR" .. i, nil, true), "cannot find stack trace " .. i)
end
end)
]=] analyze([[
attest.equal(loadfile("test/nattlua/analyzer/file_importing/complex/main.nlua")(), 14)
attest.equal(loadfile("test/tests/nattlua/analyzer/file_importing/complex/main.nlua")(), 14)
]])
analyze[[
attest.equal(require("test.nattlua.analyzer.file_importing.complex.adapter"), 14)
attest.equal(require("test.tests.nattlua.analyzer.file_importing.complex.adapter"), 14)
]]
analyze[[
attest.equal(require("table.new"), _ as function=(number, number)>({[number] = any}))
Expand All @@ -49,8 +49,8 @@ analyze[[
]]
--[=[
analyze[[
require("test.nattlua.analyzer.file_importing.env_leak.main")
require("test.tests.nattlua.analyzer.file_importing.env_leak.main")
]]
]=] analyze[[
loadfile("test/nattlua/analyzer/file_importing/require_cache/main.nlua")()
]]
loadfile("test/tests/nattlua/analyzer/file_importing/require_cache/main.nlua")()
]]
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion web_playground/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const getAllFiles = function (dirPath, arrayOfFiles) {

let tests = []

for (let path of getAllFiles("../test/nattlua/analyzer/")) {
for (let path of getAllFiles("../test/tests/nattlua/analyzer/")) {
if (path.endsWith(".nlua")) {
tests.push(fs.readFileSync(path).toString())
} else {
Expand Down
12 changes: 6 additions & 6 deletions web_playground/src/examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ local anagram = string.char(all_letters, all_letters, all_letters, all_letters,
assert(anagram == "SLEEP")
print<|anagram|> -- see console or hover me`,

base64: import("../../test/nattlua/analyzer/complex/base64.nlua"),
typescript: import("../../test/nattlua/analyzer/complex/typescript.nlua"),
spritemanager: import("../../test/nattlua/analyzer/complex/spritemanager.nlua"),
brainfudge: import("../../test/nattlua/analyzer/complex/brainfudge.nlua"),
["js-array"]: import("../../test/nattlua/analyzer/complex/array.nlua"),
["maze"]: import("../../test/nattlua/analyzer/complex/maze.nlua"),
base64: import("../../test/tests/nattlua/analyzer/complex/base64.nlua"),
typescript: import("../../test/tests/nattlua/analyzer/complex/typescript.nlua"),
spritemanager: import("../../test/tests/nattlua/analyzer/complex/spritemanager.nlua"),
brainfudge: import("../../test/tests/nattlua/analyzer/complex/brainfudge.nlua"),
["js-array"]: import("../../test/tests/nattlua/analyzer/complex/array.nlua"),
["maze"]: import("../../test/tests/nattlua/analyzer/complex/maze.nlua"),
}

0 comments on commit 98f0057

Please sign in to comment.