Skip to content

Commit

Permalink
Add testing suite using frktest and lune
Browse files Browse the repository at this point in the history
  • Loading branch information
RealEthanPlayzDev committed Jun 23, 2024
1 parent 882147c commit 83b29ab
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "luau"]
path = luau
url = https://github.com/luau-lang/luau.git
[submodule "src/tests/frktest"]
path = src/tests/frktest
url = https://github.com/itsfrank/frktest.git
17 changes: 16 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,20 @@
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
},
"luau-lsp.sourcemap.enabled": false,
"luau-lsp.types.roblox": false,
"luau-lsp.require.mode": "relativeToFile",
"luau-lsp.require.directoryAliases": {
"@lune/": "~/.lune/.typedefs/0.8.5/",
"@frktest": "./src/tests/frktest/src/"
},
"luau-lsp.ignoreGlobs": [
"**/_Index/**",
"src/tests/frktest/**",
"build/**",
"utils/**",
"snippets/**"
],
"luau-lsp.diagnostics.workspace": false,
}
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
Running Luau inside Luau. Inspired by [@Rerumu's LuauInLuau](https://gist.github.com/Rerumu/ecaf1de2f2b31d0fa91b9bac8e1e15d8).

## Notes
- ``strftime`` isn't implemented, os.date will NOT work
- Proper C exception handling not available
- ``strftime`` isn't implemented, os.date will NOT work (doesn't error code, but it will return a empty string)
- There's existing work on getting analysis to work (at the ``analysis`` branch), however it doesn't work (code aborts)

## Testing
LuauCeption uses [lune](https://github.com/lune-org/lune) (runtime) and [frktest](https://github.com/itsfrank/frktest) (library). See ``src/tests`` to view the tests stuff.

To run tests, ensure you've initialized submodules (as the frktest library is imported using submodules) and simply run the ``run.luau`` script with lune.

The old testing script (``Test.luau``) at ``utils`` is still available, however it won't be used or updated for newer work.

## Special thanks
- [@Rerumu](https://github.com/Rerumu) - a LOT of troubleshooting
Expand Down
7 changes: 7 additions & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file lists tools managed by Aftman, a cross-platform toolchain manager.
# For more information, see https://github.com/LPGhatguy/aftman

# To add a new tool, add an entry to this table.
[tools]
lune = "lune-org/[email protected]"
# rojo = "rojo-rbx/[email protected]"
10 changes: 10 additions & 0 deletions src/tests/.luaurc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"languageMode": "strict",
"lint": {
"LocalShadow": false,
"LocalUnused": false
},
"aliases": {
"frktest": "./frktest/src"
}
}
1 change: 1 addition & 0 deletions src/tests/frktest
Submodule frktest added at c6d21f
15 changes: 15 additions & 0 deletions src/tests/run.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local frktest = require("@frktest/frktest")
local lune_console_reporter = require("@frktest/reporters/lune_console_reporter")
local fs = require("@lune/fs")
local process = require("@lune/process")

for _, name in fs.readDir("./suites") do
local ok = require(`./suites/{name}`) :: any
assert(ok, `could not load suite {name}`)
end

lune_console_reporter.init()
local testOk = frktest.run()
if (not testOk) then
process.exit(1)
end
36 changes: 36 additions & 0 deletions src/tests/suites/compiler.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local frktest = require("@frktest/frktest")
local test = frktest.test
local check = frktest.assert.check
local req = frktest.assert.require
local msg = frktest.assert.msg

test.suite("Compiler", function()
local Compiler = require("../../../build/Luau.LuauCeption.Compiler")
for opt = 1, 3 do
for dbg = 1, 3 do
for cov = 1, 3 do
test.case(`should be able to compile valid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
check.should_not_error(function()
Compiler.luau_compile(`print("Hello world!")\nprint({opt},{dbg},{cov})`, opt, dbg, cov)
return
end)
end)

test.case(`shouldn't be able to compile invalid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
check.should_not_error(function()
Compiler.luau_compile(`whar`, opt, dbg, cov)
return
end)
end)

test.case("first byte for invalid code from compiler should be null (0) with opt {opt} dbg {dbg} cov {cov}", function()
local bc, bcs = Compiler.luau_compile(`whar`, opt, dbg, cov)
msg(`bc: "{bc}", bcs: {bcs}, first byte: {string.byte(string.sub(bc, 1, 1))}`)
check.equal(string.byte(string.sub(bc, 1, 1)), 0)
end)
end
end
end
end)

return true
52 changes: 52 additions & 0 deletions src/tests/suites/full.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local frktest = require("@frktest/frktest")
local test = frktest.test
local check = frktest.assert.check
local req = frktest.assert.require
local msg = frktest.assert.msg

test.suite("Compiler", function()
local Full = require("../../../build/Luau.LuauCeption.Full")
for opt = 1, 3 do
for dbg = 1, 3 do
for cov = 1, 3 do
test.case(`should be able to compile valid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
check.should_not_error(function()
Full.luau_compile(`print("Hello world!")\nprint({opt},{dbg},{cov})`, opt, dbg, cov)
return
end)
end)

test.case(`shouldn't be able to compile invalid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
check.should_not_error(function()
Full.luau_compile(`whar`, opt, dbg, cov)
return
end)
end)

test.case("first byte for invalid code from compiler should be null (0) with opt {opt} dbg {dbg} cov {cov}", function()
local bc, bcs = Full.luau_compile(`whar`, opt, dbg, cov)
msg(`bc: "{bc}", bcs: {bcs}, first byte: {string.byte(string.sub(bc, 1, 1))}`)
check.equal(string.byte(string.sub(bc, 1, 1)), 0)
end)

test.case(`should be able to run valid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
local bc, bcs = Full.luau_compile(`print("Hello world!")\nprint({opt},{dbg},{cov})`, opt, dbg, cov)

msg(`no safe env, bcs: {bcs}`)
check.should_not_error(function()
Full.luau_run(bc, `LuauCeptionTest_VM_NSF_{opt},{dbg},{cov}`, false)
return
end)

msg(`safe env, bcs: {bcs}`)
check.should_not_error(function()
Full.luau_run(bc, `LuauCeptionTest_VM_WSF_{opt},{dbg},{cov}`, true)
return
end)
end)
end
end
end
end)

return true
33 changes: 33 additions & 0 deletions src/tests/suites/vm.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
local frktest = require("@frktest/frktest")
local test = frktest.test
local check = frktest.assert.check
local req = frktest.assert.require
local msg = frktest.assert.msg

test.suite("Compiler", function()
local Compiler = require("../../../build/Luau.LuauCeption.Compiler")
local VM = require("../../../build/Luau.LuauCeption.VM")
for opt = 1, 3 do
for dbg = 1, 3 do
for cov = 1, 3 do
test.case(`should be able to run valid Luau code without erroring with opt {opt} dbg {dbg} cov {cov}`, function()
local bc, bcs = Compiler.luau_compile(`print("Hello world!")\nprint({opt},{dbg},{cov})`, opt, dbg, cov)

msg(`no safe env, bcs: {bcs}`)
check.should_not_error(function()
VM.luau_run(bc, `LuauCeptionTest_VM_NSF_{opt},{dbg},{cov}`, false)
return
end)

msg(`safe env, bcs: {bcs}`)
check.should_not_error(function()
VM.luau_run(bc, `LuauCeptionTest_VM_WSF_{opt},{dbg},{cov}`, true)
return
end)
end)
end
end
end
end)

return true

0 comments on commit 83b29ab

Please sign in to comment.