local common = {} local game_bin = nil if package.config:sub(1,1) == "/" then -- linux or osx game_bin = "bin/client/bin/brokengine_client" server_bin = "bin/server/bin/brokengine_server" else -- windows game_bin = "bin\\client\\bin\\brokengine_client.exe" server_bin = "bin\\server\\bin\\brokengine_server.exe" end function common.rungame() f = assert(io.popen(game_bin .. " spec/headless","r")) d = assert(f:read("*all")) assert(f:close()) --print(d) return d end function common.runboth() --print("Running both") --Do we have a race condition here? (Can client start and send it's message --before the server is ready to accept? f1 = assert(io.popen(server_bin .. " spec/server","r")) f2 = assert(io.popen(game_bin .. " spec/headless","r")) --print("Both ran...") d1 = f1:read("*all") d2 = f2:read("*all") --print("Both read all") f1:close() f2:close() --print("returning") return d1, d2 end function common.writegame(...) f = 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,"\n")) f:close() end function common.writeserver(...) f = io.open("spec/server/init.lua","w") data = {...} data[#data + 1] = "\nGAME.exit()\n" f:write(table.concat(data,"\n")) f:close() end function common.assert_game_runs() assert.is_not_nil(common.rungame():find("\nGoodbye\n$")) end function common.assert_both_run() local a,b = common.runboth() assert.is_not_nil(a:find("\nGoodbye\n$")) assert.is_not_nil(b:find("\nGoodbye\n$")) end return common