forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_testlib.lcb
More file actions
88 lines (66 loc) · 3.16 KB
/
_testlib.lcb
File metadata and controls
88 lines (66 loc) · 3.16 KB
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
module com.livecode.__INTERNAL._testlib
use com.livecode.foreign
----------------------------------------------------------------
-- **EXPERIMENTAL** Helper functions for testing error states
----------------------------------------------------------------
public constant ThisModule is "com.livecode.__INTERNAL._testlib"
public handler type Thunk() returns optional any
public handler MCUnitTestHandlerThrows(in pHandler as any, in pDescription as String) returns nothing
MCUnitTestHandlerThrowsImpl(pHandler, pDescription, nothing, true, false, "")
end handler
public handler MCUnitTestHandlerThrowsNamed(in pHandler as any, in pErrorName, in pDescription as String) returns nothing
MCUnitTestHandlerThrowsImpl(pHandler, pDescription, pErrorName, true, false, "")
end handler
public handler MCUnitTestHandlerThrowsBroken(in pHandler as any, in pDescription as String, in pReason as String) returns nothing
MCUnitTestHandlerThrowsImpl(pHandler, pDescription, nothing, true, true, pReason)
end handler
public handler MCUnitTestHandlerDoesntThrow(in pHandler as any, in pDescription as String) returns nothing
MCUnitTestHandlerThrowsImpl(pHandler, pDescription, nothing, false, false, "")
end handler
public handler MCUnitTestHandlerDoesntThrowBroken(in pHandler as any, in pDescription as String, in pReason as String) returns nothing
MCUnitTestHandlerThrowsImpl(pHandler, pDescription, nothing, false, true, pReason)
end handler
----------------------------------------------------------------
foreign handler MCHandlerTryToInvokeWithList(in Handler as any, inout Arguments as optional List, out Result as optional any) returns optional any binds to "<builtin>"
foreign handler MCValueGetTypeInfo(in pValue as any) returns Pointer binds to "<builtin>"
foreign handler MCNamedTypeInfoGetName(in pValue as Pointer) returns Pointer binds to "<builtin>"
foreign handler MCNameGetString(in pValue as Pointer) returns Pointer binds to "<builtin>"
foreign handler MCValueRetain(in pValue as Pointer) returns any binds to "<builtin>"
handler MCUnitTestHandlerThrowsImpl(in pHandler as any, in pDescription as String, in pErrorName as optional String, in pExpectThrow as Boolean, in pBroken as Boolean, in pReason as String) returns nothing
variable tHandler as Thunk
put pHandler into tHandler
variable tArgList as optional List
variable tResult as optional any
variable tMaybeError as optional any
put [] into tArgList
unsafe
put MCHandlerTryToInvokeWithList(tHandler, tArgList, tResult) into tMaybeError
end unsafe
variable tHasError as Boolean
put tMaybeError is not nothing into tHasError
if tHasError then
test diagnostic tMaybeError
end if
variable tTestPass as Boolean
if pExpectThrow then
if pErrorName is not nothing then
if tHasError then
unsafe
put MCValueRetain(MCNameGetString(MCNamedTypeInfoGetName(MCValueGetTypeInfo(tMaybeError)))) is pErrorName into tTestPass
end unsafe
else
put false into tTestPass
end if
else
put tHasError into tTestPass
end if
else
put not tHasError into tTestPass
end if
if pBroken then
broken test pDescription when tTestPass because pReason
else
test pDescription when tTestPass
end if
end handler
end module