local game_bin = nil if package.config:sub(1,1) == "/" then -- linux or osx game_bin = "bin/client/bin/brokengine_client" else game_bin = "bin\\client\\bin\\brokengine_client.exe" end function rungame() f = io.popen(game_bin .. " spec/headless","r") d = f:read("*all") f:close() return d end function writegame(...) f = assert(io.open("spec/headless/init.lua","w")) data = {"GAME.crashy()"} for _,v in pairs({...}) do data[#data + 1] = v end data[#data + 1] = "\nGAME.exit()\n" f:write(table.concat(data)) f:close() end function assert_game_runs() local results = rungame() assert.truthy(results:find("\nGoodbye\n$"), results) end gui_api = { button = { func = "gui.newbutton", params = { { name = "dimensions", required = true, type = "rect4d", }, { name = "default_text", required = true, type = "string", }, { name = "parent", required = false, type = "guielement", }, }, callbacks = { "onClick", "onFocus", "onUnfocus", "onHover", "onLeave" } }, fileopendialog = { func = "gui.newfileopendialog", params = { { name = "title", required = false, type = "string", }, { name = "path", required = false, type = "filepath", }, { name = "parent", required = false, type = "guielement", }, { name = "modal", required = false, type = "boolean", } }, callbacks = { "onDirectorySelect","onFileSelect","onCanceled" } }, label = { func = "gui.newlabel", params = { { name = "pos", required = true, type = "rect4d", }, { name = "text", required = true, type = "string", }, { name = "parent", required = false, type = "guielement", } }, callbacks = { } }, } --[[For some reason these can't be local, _ENV dosn't find them.]] local function mr() return string.format("%d",math.floor(math.random()*100)) end function generate_rect4d() return string.format("{{%d,%d},{%d,%d}}",mr(),mr(),mr(),mr()) end function generate_string() return "\"test!\"" end function generate_guielement() return "gui.getroot()" end function generate_filepath() return "\".\"" end function generate_boolean() return "true" end describe("Brok[en]gine",function() describe("gui system",function() for k,v in pairs(gui_api) do describe(k,function() local paramstring = {} local num_optional_args = 0 local num_required_args = 0 for i,j in pairs(v.params) do assert(_ENV["generate_" .. j.type], "Could not find a generator for type: " .. j.type) if j.required then num_required_args = num_required_args + 1 else num_optional_args = num_optional_args + 1 end paramstring[#paramstring + 1] = _ENV["generate_" .. j.type]() end for i = num_required_args, num_required_args + num_optional_args do it(string.format(" with %d params", i),function() local truncated_params = {} for j = 1, i do truncated_params[j] = paramstring[j] end local game_file = string.format("%s(%s)",v.func,table.concat(truncated_params, ",")) --print("running:",game_file) writegame(game_file) assert_game_runs() end) it(string.format(" 100 elemants with %d params", i),function() local game_file = {} for j = 1,100 do local truncated_params = {} for k = 1, i do truncated_params[k] = paramstring[k] end game_file[#game_file + 1] = string.format("%s(%s)",v.func,table.concat(truncated_params, ",")) end writegame(table.concat(game_file,"\n")) assert_game_runs() end) end end) end end) end)