-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcbUnit.runtime.cb
More file actions
72 lines (58 loc) · 2.34 KB
/
cbUnit.runtime.cb
File metadata and controls
72 lines (58 loc) · 2.34 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
//
// PRIVATE DEFINITIONS
// May only be used within this file, or in *.skeleton.cb files.
//
Const CBUNIT_MESSAGE_CONTEXT = 1
Const CBUNIT_MESSAGE_FAILURE = 2
Const CBUNIT_MESSAGE_SUCCESS = 3
Const CBUNIT_MESSAGE_FINISH = 4
Global cbUnit_CurrentContext$
Global cbUnit_HasFailures
//
// PRIVATE FUNCTIONS
// May only be called within this file, or in *.skeleton.cb files.
//
Function cbUnit_SetCurrentContext(current_context$)
cbUnit_CurrentContext = current_context
cbUnit_WriteMessage(CBUNIT_MESSAGE_CONTEXT) // Do this Last so that cbUnit_WriteMessage() will Read the New context, Not the old one.
EndFunction
Function cbUnit_FillMessage(message$, default_message$, a$, b$="", c$="",d$="")
If "" = message Then
// We only have a Default message, defined in an assert*() Function.
message = default_message
Else
// We have a custom message in addition To the Default one.
// Use the custom message As a primary message And append the Default message To the End in parenthesis.
message = message + " (" + default_message + ")"
EndIf
message = Replace(message, "a$", a)
message = Replace(message, "b$", b)
message = Replace(message, "c$", c)
message = Replace(message, "d$", d)
Return message
EndFunction
Function cbUnit_EndProgram()
cbUnit_SetCurrentContext("hook_Cleanup")
hook_Cleanup() // Hook For test_*.cb To cleanup Before Exit
cbUnit_SetCurrentContext("")
cbUnit_WriteMessage(CBUNIT_MESSAGE_FINISH)
End
EndFunction
//
// Sends a message to the main cbUnit program via a file.
//
Function cbUnit_WriteMessage(message_type, message_content$="")
Dim file
// Open the output file (will be created If does Not exist) And seek To Write To the End of it, in Case it happens To have old content.
file = OpenToEdit(CBUNIT_OUTPUT_FILE_PATH)
SeekFile file, FileSize(CBUNIT_OUTPUT_FILE_PATH)
// Write common information
WriteByte file, 255 // A constant indicator mark that a message starts here
WriteByte file, message_type
WriteString file, cbUnit_CurrentContext
// Write message If this is a failure
If CBUNIT_MESSAGE_FAILURE = message_type Then WriteString file, message_content
// Finish
WriteByte file, 127 // A constant indicator mark that a message ends here
CloseFile file // We need To close the file To actually Write it's content To the filesystem.
EndFunction