From 884559d48af1a7c4b8d1aac8058260c58b1cc91c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= <ast@fiberby.net>
Date: Mon, 6 Mar 2017 10:58:06 +0000
Subject: tests: enable tests to be run under plain lua
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 test.lua      |  5 ++---
 test/init.lua | 18 +++++++++++++-----
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/test.lua b/test.lua
index e02345f..a61ed86 100755
--- a/test.lua
+++ b/test.lua
@@ -1,7 +1,6 @@
-#!/usr/bin/env lem
+#!/usr/bin/env lua
 
-package.path = './?/init.lua;'..package.path..';./lua/?.lua;./lua/?/init.lua;./?.lua'
-package.cpath = package.cpath..';./lua/?.so'
+package.path = './?/init.lua;./lua/?.lua;./lua/?/init.lua;./?.lua;'..package.path
 
 local test = require 'test'
 
diff --git a/test/init.lua b/test/init.lua
index 0a4e05b..97f94ac 100644
--- a/test/init.lua
+++ b/test/init.lua
@@ -1,6 +1,7 @@
-local utils = require 'lem.utils'
+--local utils = require 'lem.utils'
 
-local updatenow = utils.updatenow
+--local updatenow = utils.updatenow
+local function updatenow() return nil end
 local pack = table.pack
 local unpack = table.unpack
 local format = string.format
@@ -75,7 +76,9 @@ function test:run()
 	t1 = updatenow()
 	local ret, msg = xpcall(tester, msg_handler, self)
 	t2 = updatenow()
-	self.runtime = t2 - t1
+	if t1 then
+		self.runtime = t2 - t1
+	end
 	self:leave()
 	if not ret then
 		self.error_msg = msg
@@ -125,8 +128,13 @@ function test:stats()
 	end
 	local run, passed, asserts = master.run, master.passed, master.assert_cnt
 	if run == passed then
-		print(format('%d/%d  All tests passed, %d assertions in %.3fs',
-			run, passed, asserts, master.test.runtime))
+		local runtime = master.test.runtime
+		local runtimestr = ''
+		if runtime then
+			runtimestr = format(' in %.3fs', runtime)
+		end
+		print(format('%d/%d  All tests passed, %d assertions%s',
+			run, passed, asserts, runtimestr))
 	else
 		print(format('%d/%d  %d failed', run, passed, run-passed))
 	end
-- 
cgit v1.2.1