aboutsummaryrefslogtreecommitdiff
path: root/spec/common.lua
diff options
context:
space:
mode:
authorAlexander <alex@cogarr.net>2020-06-29 15:29:03 -0400
committerAlexander <alex@cogarr.net>2020-06-29 15:29:03 -0400
commit80789508b9655d25629223b9dcc84b4cfb77ce45 (patch)
tree37e140e532af61c1ca4699c8b6254cf2cb07ed02 /spec/common.lua
parent44a1421c393632978d59c0698a93ae22243b97e9 (diff)
downloadbrokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.tar.gz
brokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.tar.bz2
brokengine-80789508b9655d25629223b9dcc84b4cfb77ce45.zip
Updates for mdoc
Also more tests
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