From 26361c5003fa7036889c79fc99ad5f33d6dc2986 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Sun, 20 Dec 2015 19:48:23 -0800 Subject: [PATCH] Add support for using busted 2.0 to run automation tests Supply a definition of socket.gettime() to remove the dependency on LuaSocket, as installing binary deps from luarocks doesn't work with a custom build of luajit. --- .travis.yml | 2 +- automation/Makefile | 2 +- automation/tests/busted.lua | 23 ++++++++++++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ff1a4ea4..f44bdd505 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ before_install: - sudo pip install cpp-coveralls install: - sudo apt-get install -y -qq libasound2-dev libfftw3-dev libhunspell-dev yasm libfribidi-dev libass-dev libffms2-dev libwxgtk3.0-dev libicu-dev luarocks - - sudo luarocks install busted 1.10.0 > /dev/null + - sudo luarocks install busted > /dev/null - sudo luarocks install moonscript > /dev/null - sudo luarocks install uuid > /dev/null diff --git a/automation/Makefile b/automation/Makefile index 05464cec8..d5425b730 100644 --- a/automation/Makefile +++ b/automation/Makefile @@ -19,7 +19,7 @@ aegisub-lua_LIBS := $(LIBS_WX) $(LIBS_BOOST) $(LIBS_ICU) PROGRAM += $(d)aegisub-lua test-automation: $(PROGRAM) - eval `luarocks path`; cd $(TOP)automation; LUA=./aegisub-lua busted -p 'moon' tests/modules + eval `luarocks path`; cd $(TOP)automation; ./aegisub-lua tests/busted.lua -p 'moon' tests/modules test: test-automation diff --git a/automation/tests/busted.lua b/automation/tests/busted.lua index a8b4c6c08..e26acfa23 100644 --- a/automation/tests/busted.lua +++ b/automation/tests/busted.lua @@ -1 +1,22 @@ -require 'busted.runner'({ batch = true }) +local ffi = require("ffi") + +ffi.cdef[[ + typedef struct timeval { + long tv_sec; + long tv_usec; + } timeval; + + int gettimeofday(timeval *t, void *tzp); +]] + +-- busted depends on luasocket just for gettime(), so just supply a definition +-- of that to avoid the dep +package.loaded['socket'] = { + gettime = function() + local t = ffi.new("timeval") + ffi.C.gettimeofday(t, nil) + return tonumber(t.tv_sec) + tonumber(t.tv_usec) / 1000000.0 + end +} + +require 'busted.runner'({ batch = true, standalone = false })