aboutsummaryrefslogtreecommitdiff
path: root/spec/common.lua
diff options
context:
space:
mode:
Diffstat (limited to 'spec/common.lua')
-rw-r--r--spec/common.lua63
1 files changed, 63 insertions, 0 deletions
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