From 80789508b9655d25629223b9dcc84b4cfb77ce45 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 29 Jun 2020 15:29:03 -0400 Subject: Updates for mdoc Also more tests --- spec/common.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 spec/common.lua (limited to 'spec/common.lua') diff --git a/spec/common.lua b/spec/common.lua new file mode 100644 index 0000000..4df1a7c --- /dev/null +++ b/spec/common.lua @@ -0,0 +1,63 @@ +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 = io.popen(game_bin .. " spec/headless","r") + d = f:read("*all") + 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 = io.popen(server_bin .. " spec/server","r") + f2 = 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 -- cgit v1.2.3-70-g09d2