From 9e9be703c8f1c58c76fd2051dd6fa6ce49a7a306 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 31 Oct 2018 12:43:59 -0400 Subject: Started on unit tests Added a GAME.exit() function Added some bare bones unit tests --- spec/test1_spec.lua | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 spec/test1_spec.lua (limited to 'spec/test1_spec.lua') diff --git a/spec/test1_spec.lua b/spec/test1_spec.lua new file mode 100644 index 0000000..bcb5756 --- /dev/null +++ b/spec/test1_spec.lua @@ -0,0 +1,58 @@ +print("Hello, world!") + +function rungame() + f = io.popen("bin\\client\\bin\\brokengine_client.exe spec/headless","r") + d = f:read("*all") + f:close() + return d +end + +function writegame(...) + f = io.open("spec/headless/init.lua","w") + data = {...} + data[#data + 1] = "\nGAME.exit()\n" + f:write(table.concat(data)) + f:close() +end + +function assert_game_runs() + assert.truthy(rungame():find("\nGoodbye\n$")) +end + +describe("Brok[en]gine",function() + it("should run",function() + writegame() + d = rungame() + assert_game_runs() + end) + it("should provide a lua environment",function() + writegame("print(\"Hello from lua!\")") + d = rungame() + assert.truthy(d:find("\nHello from lua!\n")) + end) + + for k,v in pairs({ + buttons = "newbutton", + checkboxes = "newcheckbox", + colorselectors = "newcolorselector", + editboxes = "neweditbox", + openfiledialogs = "newfileopendialog", + images = "newiguiimage", + labels = "newlabel", + spinboxes = "newspinbox", + treeviews = "newtreeview", + windows = "newwindow", + }) do + it("should provide functions to make gui " .. k,function() + writegame("assert(gui." .. v .. ")") + assert_game_runs() + end) + end + + it("should provide functions to get the width and height of the screen",function() + writegame("assert(scrw)") + assert_game_runs() + writegame("assert(scrh)") + assert_game_runs() + end) +end) -- cgit v1.2.3-70-g09d2