forked from bluebird75/luaunit
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest_luaunit.lua
executable file
·112 lines (88 loc) · 3.08 KB
/
test_luaunit.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env lua
--[[
test_luaunit.lua
Description: Tests for the luaunit testing framework
Author: Philippe Fremy <[email protected]>
Version: 1.1
License: X11 License, see LICENSE.txt
]]--
-- This is a bit tricky since the test uses the features that it tests.
local LuaUnit = require('luaunit')
TestLuaUnit = {} --class
function TestLuaUnit:test_assertError()
local function f() end
has_error = not pcall( error, "coucou" )
assert( has_error == true )
assertError( error, "coucou" )
has_error = not pcall( assertError, error, "coucou" )
assert( has_error == false )
has_error = not pcall( f )
assert( has_error == false )
has_error = not pcall( assertError, f )
assert( has_error == true )
-- multiple arguments
local function multif(a,b,c)
if a == b and b == c then return end
error("three arguments not equal")
end
assertError( multif, 1, 1, 3 )
assertError( multif, 1, 3, 1 )
assertError( multif, 3, 1, 1 )
has_error = not pcall( assertError, multif, 1, 1, 1 )
assert( has_error == true )
end
function TestLuaUnit:test_assertEquals()
assertEquals( 1, 1 )
has_error = not pcall( assertEquals, 1, 2 )
assert( has_error == true )
end
function TestLuaUnit:Xtest_xpcall()
local function f() error("[this is a normal error]") end
local function g() f() end
g()
end
--[[ Class to test that tests are run in the right order ]]
TestToto1 = {} --class
function TestToto1:test1() end
function TestToto1:test2() end
function TestToto1:test3() end
function TestToto1:test4() end
function TestToto1:test5() end
function TestToto1:testa() end
function TestToto1:testb() end
TestToto2 = {} --class
function TestToto2:test1() end
function TestToto2:test2() end
function TestToto2:test3() end
function TestToto2:test4() end
function TestToto2:test5() end
function TestToto2:testa() end
function TestToto2:testb() end
TestToto3 = {} --class
function TestToto3:test1() end
function TestToto3:test2() end
function TestToto3:test3() end
function TestToto3:test4() end
function TestToto3:test5() end
function TestToto3:testa() end
function TestToto3:testb() end
TestTotoa = {} --class
function TestTotoa:test1() end
function TestTotoa:test2() end
function TestTotoa:test3() end
function TestTotoa:test4() end
function TestTotoa:test5() end
function TestTotoa:testa() end
function TestTotoa:testb() end
TestTotob = {} --class
function TestTotob:test1() end
function TestTotob:test2() end
function TestTotob:test3() end
function TestTotob:test4() end
function TestTotob:test5() end
function TestTotob:testa() end
function TestTotob:testb() end
-- LuaUnit:run('TestLuaBinding:test_setline') -- will execute only one test
-- LuaUnit:run('TestLuaBinding') -- will execute only one class of test
-- LuaUnit.result.verbosity = 0
LuaUnit:run() -- will execute all tests