-
Notifications
You must be signed in to change notification settings - Fork 5
/
UT.dyalog
164 lines (145 loc) · 4.51 KB
/
UT.dyalog
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
:NameSpace UT
EN ← ⍬
∇ Z ← run Function;Res;Tmp
Tmp ← 1 ⊃ ⎕RSI
Tmp ← (⍕ ⎕THIS) ⎕NS ((⍕ Tmp),'.',Function)
:Trap 0
Res ← execute_function Function
:If #.UT.EN ≢ ⍬
Function display_expected_got #.UT.EN ⍬
Z ← 0
#.UT.EN ← ⍬
:Else
Z ← Res
:If 1 = ⍴⍴ Res
Function display_expected_got Res
Z ← 0
:EndIf
:EndIf
:Else
:If #.UT.EN ≢ ⍬
Z ← 1
:If #.UT.EN ≢ ⎕EN
Function display_expected_got #.UT.EN ⎕EN
Z ← 0
:EndIf
#.UT.EN ← ⍬
:Else
display_exception Function
Z ← ⎕EN
:EndIf
:EndTrap
⎕EX Function
∇
∇ Z ← run_file Path;TmpSpace;Fns;Res;Passed;Failed;Exception
'TmpSpace' ⎕NS ''
'TmpSpace' ⎕NS '#.DISPLAY'
{'TmpSpace' ⎕NS ⍵ } ¨ ↓ #.UT.⎕NL 3
{'TmpSpace' ⎕NS ⍵ } ¨ ↓ #.UT.⎕NL 2
⎕CS 'TmpSpace'
⎕SE.SALT.Load Path
⎕CS get_namespace
{ (⍕ ⎕THIS) ⎕NS '#.UT.',⍵ } ¨ ↓ #.UT.⎕NL 3
{ (⍕ ⎕THIS) ⎕NS '#.UT.',⍵ } ¨ ↓ #.UT.⎕NL 2
Fns ← ↓ ⎕THIS.⎕NL 3
Fns ← ( is_test ¨ Fns) / Fns
Res ← run ¨ Fns
(Passed Exception Failed) ← (⊃+/1=Res) (⊃+/0≠Res∧1≠Res) (⊃+/0=Res)
print_file_result Passed Exception Failed
⎕CS ##
⎕CS ##
⎕EX 'TmpSpace'
Z ← Passed Exception Failed
∇
∇ Z ← run_group Group;Res
⎕CS 1 ⊃ ⎕RSI
Res ← #.UT.run ¨ (⍎ Group)
⎕CS #.UT
Res ← (⊃+/1=Res) (⊃+/0≠Res∧1≠Res) (⊃+/0=Res)
Group print_group_result Res
Z ← Res
∇
∇ Z ← Group run_group_file Path;Res
'TmpSpace' ⎕NS ''
⎕CS 'TmpSpace'
⎕SE.SALT.Load Path
⎕CS ⊃ ↓ ⎕NL 9
Res ← #.UT.run ¨ ⍎ Group
⎕CS ##
⎕EX 'TmpSpace'
⎕CS #.UT
Res ← (⊃+/1=Res) (⊃+/0≠Res∧1≠Res) (⊃+/0=Res)
Group print_file_group_result Res
Z ← Res
∇
∇ Z ← LHS eq RHS
Z ← 1
:If LHS ≢ RHS
Z ← LHS RHS
:EndIf
∇
∇ Z ← execute_function Name;R;C
(R C) ← ⍴ ⎕CR Name
:If R > 1
Z ← ⍎ Name
:Else
Z ← ⍎ Name,' ⍬'
:EndIf
∇
∇ Z ← function_header Name;Matrix;R;C
Matrix ← ⎕CR Name
(R C) ← ⍴ Matrix
:If R > 1
Z ← ,Matrix[1;],' ... ',Matrix[R;]
:Else
Z ← ,Matrix
:EndIf
∇
∇ Z ← show_term Term;Tmp
:If 0=≡Term
Z ← ' ',⍕Term
:Else
Tmp ← #.DISPLAY Term
Z ← ((⍴Tmp)[1] ⍴ ' '),Tmp
:EndIf
∇
∇ Z ← get_namespace
Z ← ⊃ ↓ ⎕NL 9
∇
∇ Z ← is_test FunctionName;Index;Tmp
Index ← FunctionName ⍳ ' '
Tmp ← FunctionName
:If Index ≤ ⍴ FunctionName
Tmp ← FunctionName[⍳(¯1 + Index)]
:EndIf
Z ← '_TEST' ≡ ¯5 ↑ Tmp
∇
∇ Name display_expected_got Res
⎕ ← 'FAILED:',function_header Name
⎕ ← 'Expected'
⎕ ← show_term ⊃Res[1]
⎕ ← 'Got'
⎕ ← show_term ⊃Res[2]
∇
∇ display_exception Name
⎕ ← 'EXCEPTION:',function_header Name
⎕ ← ' EN:',⎕EN
⎕ ← ' EM:',⎕EM ⎕EN
∇
∇ print_file_result Result
(Path,' unit tests') print_totals Result
∇
∇ Group print_group_result Result
('Group ',Group) print_totals Result
∇
∇ Group print_file_group_result Result
('Group ',Group,' in ',Path) print_totals Result
∇
∇ Header print_totals (Passed Exception Failed)
⎕ ← ' '
⎕ ← Header
⎕ ← '⍋ ',(⍕ Passed),' PASSED'
⎕ ← '⋄ ',(⍕ Exception),' EXCEPTION'
⎕ ← '⍒ ',(⍕ Failed),' FAILED'
∇
:EndNameSpace