aboutsummaryrefslogtreecommitdiff
path: root/lua/visrc.lua
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2017-03-03 11:09:37 +0100
committerMarc André Tanner <mat@brain-dump.org>2017-03-03 11:29:35 +0100
commit2f8f3871b98d0a431ca90372f318df67e5b7d01f (patch)
tree6b652eceab043fb37486a4b82128282694b52618 /lua/visrc.lua
parent85f9eac4b981629af2f63c94407843d4dd554ca7 (diff)
downloadvis-2f8f3871b98d0a431ca90372f318df67e5b7d01f.tar.gz
vis-2f8f3871b98d0a431ca90372f318df67e5b7d01f.tar.xz
test/lua: add infrastructure for busted based unit tests
Diffstat (limited to 'lua/visrc.lua')
-rw-r--r--lua/visrc.lua27
1 files changed, 21 insertions, 6 deletions
diff --git a/lua/visrc.lua b/lua/visrc.lua
index af40306..16aa8b9 100644
--- a/lua/visrc.lua
+++ b/lua/visrc.lua
@@ -1,13 +1,28 @@
-dofile("utils.lua")
+package.path = '../../lua/?.lua;'..package.path
+dofile("../../lua/vis.lua")
-vis.events = {}
-vis.events.win_open = function(win)
+-- redirect output to stdout, stderr is used by the vis UI
+io.stderr = io.stdout
+
+-- make sure we gracefully terminate, cleanup terminal state etc.
+os.exit = function(status)
+ vis:exit(status)
+end
+
+vis.events.subscribe(vis.events.WIN_OPEN, function(win)
-- test.in file passed to vis
local in_file = win.file.name
if in_file then
-- use the corresponding test.lua file
lua_file = string.gsub(in_file, '%.in$', '.lua')
- dofile(lua_file)
- vis:command('qall!')
+ local ok, msg = pcall(dofile, lua_file)
+ if not ok then
+ if type(msg) == 'string' then
+ print(msg)
+ end
+ vis:exit(1)
+ return
+ end
end
-end
+ vis:exit(0)
+end)