Skip to content

Commit

Permalink
Simplify test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghuan committed May 29, 2020
1 parent 3526d4b commit 4868cb1
Show file tree
Hide file tree
Showing 7 changed files with 229 additions and 9 deletions.
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,8 @@ ModelManifest.xml

# FAKE - F# Make
.fake/
test/**/*.lua
test/**/out/*.lua
test/**/out/**/*.lua
/CSharp.lua/Properties/launchSettings.json
/CSharp.lua.Launcher/Properties/launchSettings.json
/download/*.zip
/Test/TestCases/out/
!/test/BridgeNetTests/Tests/run.lua
!/test/BridgeNetTests/Tests/strict.lua
/download/*.zip
61 changes: 61 additions & 0 deletions test/BridgeNetTests/Tests/launcher.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
local traceback
if arg[1] == "nodebug" then
traceback = debug.traceback
debug = nil
else
require("strict")
end

package.path = package.path .. ";../../../CSharp.lua/Coresystem.lua/?.lua"
package.path = package.path .. ";../?.lua"

package.path = package.path .. ";CSharp.lua/Coresystem.lua/?.lua"
package.path = package.path .. ";test/BridgeNetTests/?.lua;"

local now = 0
local timeoutQueue

local conf = {
traceback = traceback,
setTimeout = function (f, delay)
if not timeoutQueue then
timeoutQueue = System.TimeoutQueue()
end
return timeoutQueue:Add(now, delay, f)
end,
clearTimeout = function (t)
timeoutQueue:Erase(t)
end
}
require("All")("", conf) -- coresystem.lua/All.lua

local modules = {
"BridgeAttributes",
"BridgeTestNUnit",
"ClientTestHelper",
"Batch1",
"Tests"
}

for i = 1, #modules do
local name = modules[i]
require(name .. "/out/manifest")(name .. "/out")
end

collectgarbage("collect")
print(collectgarbage("count"))

local main = System.Reflection.Assembly.GetEntryAssembly():getEntryPoint()
main:Invoke()

if timeoutQueue then
while true do
local nextExpiration = timeoutQueue:getNextExpiration()
if nextExpiration ~= timeoutQueue.MaxExpiration then
now = nextExpiration
timeoutQueue:RunLoop(now)
else
break
end
end
end
64 changes: 64 additions & 0 deletions test/BridgeNetTests/Tests/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require("run")

local function src(module)
return ("../%s/src"):format(module)
end

local function out(module)
return ("../%s/out"):format(module)
end

local function lib(module)
return ("../%s/bin/Debug/netcoreapp3.0/%s.dll!"):format(module, module)
end

local function libs(...)
local t = {}
for i = 1, select("#", ...) do
t[i] = lib(select(i, ...))
end
return table.concat(t, ';')
end

run {
{
depth = 3,
input = src("BridgeAttributes"),
output = out("BridgeAttributes"),
metadata = true,
module = true
},
{
depth = 3,
input = src("BridgeTestNUnit"),
output = out("BridgeTestNUnit"),
libs = lib("BridgeAttributes"),
metadata = true,
module = true
},
{
depth = 3,
input = src("ClientTestHelper"),
output = out("ClientTestHelper"),
libs = libs("BridgeAttributes", "BridgeTestNUnit"),
metadata = true,
module = true
},
{
depth = 3,
input = src("Batch1"),
output = out("Batch1"),
libs = libs("BridgeAttributes", "BridgeTestNUnit", "ClientTestHelper"),
attr = true,
metadata = true,
module = true
},
{
depth = 3,
input = "src",
output = "out",
libs = libs("BridgeTestNUnit", "Batch1"),
metadata = true,
module = true
},
}
11 changes: 11 additions & 0 deletions test/TestCases/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require("run")

run {
depth = 2,
input = "src",
output = "out",
libs = "Bridge/Bridge.dll",
metaFiles = "Bridge/Bridge.xml",
attr = "TestCase",
metadata = true,
}
88 changes: 88 additions & 0 deletions test/__bin/Lua/lua/run.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
local function execute(cmd)
print("execute", cmd)
local code = os.execute(cmd)
assert(code == 0)
end

local luaVersions = {
"Lua5.3",
"LuaJIT-2.0.2",
"MoonJIT-2.2.0"
}

local function compile(arg)
local CSharpLua = ("../"):rep(arg.depth) .. "CSharp.lua.Launcher/bin/Debug/netcoreapp3.0/CSharp.lua.Launcher.dll"
local cmd = ("dotnet %s -s %s -d %s"):format(CSharpLua, arg.input, arg.output)
if arg.libs then
cmd = cmd .. " -l " .. arg.libs
end
if arg.metaFiles then
cmd = cmd .. " -m " .. arg.metaFiles
end
if arg.attr then
if arg.attr == true then
cmd = cmd .. " -a"
else
cmd = cmd .. " -a " .. arg.attr
end
end
if arg.metadata then
cmd = cmd .. " -metadata"
end
if arg.classic then
cmd = cmd .. " -c"
end
if arg.inlineProperty then
cmd = cmd .. " -inline-property"
end
if arg.nodebug then
cmd = cmd .. " -p"
end
if arg.module then
cmd = cmd .. " -module"
end
if arg.extra then
cmd = cmd .. " " .. arg.extra
end
execute(cmd)
end

local function launcher(arg, luaVersion)
local luaPath = ("..\\"):rep(arg.depth - 1) .. "__bin\\"
cmd = ("\"%s%s\\lua.exe\" %s"):format(luaPath, luaVersion, "launcher.lua")
if arg.nodebug then
cmd = cmd .. " nodebug"
end
execute(cmd)
end

local function runAll(t, args)
for _, v in ipairs(luaVersions) do
print("--------------------", v, "--------------------")
for _, arg in ipairs(args) do
if v:find("JIT") then
t.classic = true
t.extra = "-csc /define:__JIT__"
else
t.classic = false
t.extra = nil
end
arg.__index = arg
setmetatable(t, arg)
compile(t, v)
end
launcher(t, v)
end
end


function run(args)
execute("dotnet build --configuration Debug")
if args[1] == nil then
args = { args }
end
runAll({}, args)
runAll({ inlineProperty = true }, args)
runAll({ nodebug = true }, args)
runAll({ inlineProperty = true, nodebug = true }, args)
end
2 changes: 1 addition & 1 deletion test/self-compiling/self.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ set dir=bin/Release/PublishOutput/
dotnet publish ../../ --configuration Release --output %dir%
set obj="../../CSharp.lua/obj"
if exist %obj% rd /s /q %obj%
dotnet "%dir%CSharp.lua.Launcher.dll" -s ../../CSharp.lua/ -d selfout -l %dir%Microsoft.CodeAnalysis.CSharp.dll;%dir%Microsoft.CodeAnalysis.dll -metadata
dotnet "%dir%CSharp.lua.Launcher.dll" -s ../../CSharp.lua/ -d out -l %dir%Microsoft.CodeAnalysis.CSharp.dll;%dir%Microsoft.CodeAnalysis.dll -metadata
rd /s /q bin
pause
4 changes: 1 addition & 3 deletions test/test.bat
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
cd TestCases
call test
if not %errorlevel%==0 (
cd ..
goto:Fail
goto:Fail
)
cd ..

cd BridgeNetTests/Tests
call test
if not %errorlevel%==0 (
cd ../..
goto:Fail
)
cd ../..
Expand Down

0 comments on commit 4868cb1

Please sign in to comment.