Commits

Anonymous committed 2a68cb0

initial commit of luatesting.lua

Comments (0)

Files changed (1)

+local testing = {}
+
+function testing.run()
+	local t = { 
+		ok = true,
+		passed = 0,
+		failed = 0,
+
+		fail = function(self, msg)
+			print("FAIL:\t"..msg)
+			self.ok = false
+			error()
+		end,
+
+		err = function(self, msg)
+			print("ERR:\t"..msg)
+			self.ok = false
+		end
+	}
+
+	for _,gv in pairs(_G) do
+		if type(gv) == 'table' then
+			t.ok = true
+			for k,v in pairs(gv) do
+				if type(v) == 'function' and k:find("test") == 1 then
+					local status, _ = pcall(v, gv, t)
+					if status and t.ok then
+						print("OK:\t"..k)
+						t.passed = t.passed + 1
+					else
+						t.failed = t.failed + 1
+					end
+				end
+			end
+		end
+	end
+
+	print()
+	print("Passed: "..t.passed)
+	print("Failed: "..t.failed)
+	print()
+end
+
+return testing
+