-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestframework.sk
More file actions
329 lines (293 loc) · 12 KB
/
testframework.sk
File metadata and controls
329 lines (293 loc) · 12 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
using reflection
import:
ch.njol.skript.lang.parser.ParserInstance
org.bukkit.Bukkit
ch.njol.skript.test.utils.TestOfflinePlayer
ch.njol.skript.lang.Condition
ch.njol.skript.test.runner.TestTracker
ch.njol.skript.log.SkriptLogger
java.lang.Runnable
local effect sendTestFailMessage %string%[, %-string%]:
trigger:
set {_msg} to " %expr-2%" if expr-2 is set else ""
send "[<gold>Skript<reset>] [&cTEST FAILURE<reset>] %expr-1%%{_msg}%" to console
event "skriptTest":
pattern: [devdinc] test %string% [when <(.+)>]
event-values: string, boolean
parse:
set {_origin} to SkriptLogger.getNode()
set {_realscript} to script ({_origin}.getConfig().getFileName())
# we don't have access to event-string or expr-1, so we can't do it in parse time.
# one thing we can do is cause a call to event to register tho.
set {_list::string} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
set {_list::boolean} to false
create section with {_proxy} stored in {_functions::run}:
wait 2 ticks
call custom event "skriptTest" with {_list::*}
set {_proxy} to new proxy instance of Runnable using {_functions::*}
Bukkit.getGlobalRegionScheduler().execute(instance of plugin "Skript", {_proxy})
continue
check:
set {_realscript} to current script if {_realscript} is not set # before skript-reflect 2.6.4, parse section in events within same script doesn't run
set {_ok} to true
set {-test.sk::tests::%{_realscript}%.%expr-1%} to ["%expr-1%", {_realscript}] # registering
if "%expr-1%" is event-string:
set {_raw} to first element of regex-1
if {_raw} is set:
set {_cond} to Condition.parse({_raw}, "Can't understand condition: " + {_raw})
if {_cond} is set:
set {_ok} to {_cond}.check(event)
continue if {_ok} is true
event "beforeSkriptTest":
pattern: [devdinc] before each test
event-values: string, boolean, script
check:
continue
event "afterSkriptTest":
pattern: [devdinc] after each test
event-values: string, boolean, script
check:
continue
event "beforeSkriptTestAll":
pattern: [devdinc] before all tests
event-values: script
check:
continue
event "afterSkriptTestAll":
pattern: [devdinc] after all tests
event-values: script
check:
continue
plural expression [all] tests [[with] [test] [name] %-string%] [[with][in] %-script%]:
parse:
set {_scoped} to false if expr-2 is not set
continue
get:
if {_scoped} is false:
loop {-test.sk::tests::*}:
if any:
expr-1 is not set
loop-value[0] is expr-1
then:
add loop-value to {_r::*}
else:
loop {-test.sk::tests::*}:
loop-value[1] is expr-2
if any:
expr-1 is not set
loop-value[0] is expr-1
then:
add loop-value to {_r::*}
return {_r::*}
effect (1:|2:auto)run %objects%:
trigger:
set {_tests::*} to expr-1
set {_alltests::*} to all tests
loop {_tests::*}:
set {_list::script} to loop-value[1]
{_scripts::*} does not contain {_list::script}
add {_list::script} to {_scripts::*}
call custom event "beforeSkriptTestAll" with {_list::*}
loop {_tests::*}:
set {_list::string} to loop-value[0]
set {_list::script} to loop-value[1]
set {_list::boolean} to true if parse mark is 2 else false
call custom event "beforeSkriptTest" with {_list::*}
call custom event "skriptTest" with {_list::*}
call custom event "afterSkriptTest" with {_list::*}
if any:
{_list::string} contains "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
size of ({_alltests::*} where ["%input%" is "%loop-value%"]) is 0
then:
add 1 to {_forgottenTestResults}
continue loop
add 1 to {_testFails} if size of {-test.sk::errors::%{_list::script}%.%{_list::string}%::*} is greater than 0
loop {_scripts::*}:
set {_list::script} to loop-value
call custom event "afterSkriptTestAll" with {_list::*}
set {_validTestAmount} to size of {_tests::*} - {_forgottenTestResults}
if {_validTestAmount} is not 0:
send "[<gold>Skript<reset>] <yellow>%{_validTestAmount} - {_testFails}%/%{_validTestAmount}% tests passed." to console
else if size of {_alltests::*} is greater than 0: # skipping if there is no initial hidden test
send "[<gold>Skript<reset>] <yellow>No tests found." to console
condition last test result [of %-object%] is a (1:pass|2:fail):
usable in:
custom event "skriptTest"
check:
if expr-1 is not set:
set {_test} to event.getEventValue("string")
set {_script} to event.getEventValue("script")
else:
set {_test} to expr-1[0]
set {_script} to expr-1[1]
stop if size of (all tests where ["%input%" is "%expr-1%"]) is 0
if all:
parse mark is 1
size of {-test.sk::errors::%{_script}%.%{_test}%::*} <= 0
then:
continue
else:
if all:
parse mark is 2
size of {-test.sk::errors::%{_script}%.%{_test}%::*} > 0
then:
continue
before each test:
delete {-test.sk::errors::%event-script%.%event-string%::*}
set {-test.sk::testblock} to test-block's type
after each test:
set test-block to {-test.sk::testblock}
on load:
delete {-test.sk::*}
wait 1 tick
set {_list::string} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
set {_list::boolean} to false
call custom event "skriptTest" with {_list::*}
wait 1 tick
set {_tests::*} to all tests
autorun {_tests::*}
effect:
patterns:
(3:|4:(no|without) (halt[ing]|fail[(-| )](safe|fast)|abort[ing])) assert(1:|1: true|2: false)[ with (6:|5:no )[[error] message][ %-string%]]\: <(.+)>
(3:|4:(no|without) (halt[ing]|fail[(-| )](safe|fast)|abort[ing])) assert <(.+)> (1:|2:to fail)[ with (6:|5:no )[[error][ message]][ %-string%]]
usable in:
custom event "skriptTest"
parse:
set {_raw} to first element of regex-1
set {_origin} to SkriptLogger.getNode()
set {_currentscript} to script ({_origin}.getConfig().getFileName())
set {_parser} to ParserInstance.get()
set {_parser}.[ParserInstance]isActive to true
set {_backup} to {_parser}.backup()
{_parser}.setCurrentScript({_currentscript})
{_parser}.setCurrentEvent("assert condition", (custom event "skriptTest").getClass())
set {_cond} to Condition.parse({_raw}, "Can't understand condition: " + {_raw})
set {_parser}.[ParserInstance]isActive to false
{_parser}.restoreBackup({_backup})
continue
trigger:
set {_ok} to {_cond}.check(event)
set {_label} to "assert true" if parse tags contains "1" else "assert false"
set {_test} to event.getEventValue("string")
set {_script} to event.getEventValue("script")
if all:
parse tags contains "1"
{_ok} is false
then:
set {_bool1} to true
if all:
parse tags contains "2"
{_ok} is true
then:
set {_bool2} to true
if any:
{_bool1} is true
{_bool2} is true
then:
if parse tags does not contain "5":
sendTestFailMessage "Test ""%{_test}%"" with condition '%{_label}%: %{_raw}%' failed", expr-1
TestTracker.testFailed(expr-1)
add "%expr-1%" to {-test.sk::errors::%{_script}%.%{_test}%::*}
if parse tags contains "3":
delay effect
effect (3:|4:(no|without) (halt[ing]|fail[(-| )](safe|fast)|abort[ing])) fail test[ with (6:|5:no )[[error] message][ %-string%]]:
usable in:
custom event "skriptTest"
trigger:
set {_test} to event.getEventValue("string")
set {_script} to event.getEventValue("script")
if parse tags does not contain "5":
sendTestFailMessage "Test ""%{_test}%"" failed", expr-1
TestTracker.testFailed(expr-1)
add "%expr-1%" to {-test.sk::errors::%{_script}%.%{_test}%::*}
if parse tags contains "3":
delay effect
effect stop auto [test] execution [here]:
usable in:
custom event "skriptTest"
trigger:
set {_bool} to event.getEventValue("boolean")
if {_bool} is true:
delay effect
expression event(-| )test:
# usable in:
# custom event "skriptTest"
get:
return [event.getEventValue("string"), event.getEventValue("script")]
condition event(-| )test (1:is|2:is not|2:isn't) autorun:
# usable in:
# custom event "skriptTest"
check:
set {_bool} to event.getEventValue("boolean")
if {_bool} is true:
parse mark is 1
continue
else:
parse mark is 2
continue
import:
ch.njol.skript.ScriptLoader
condition parse:
parse:
set {_parser} to ParserInstance.get()
set {_parseSection} to {_parser}.getNode()
set {_parseBackup} to {_parser}.backup()
# nodes are not fully loaded here yet
continue
usable in:
custom event "skriptTest"
check:
{_parser}.restoreBackup({_parseBackup})
set {_logger} to SkriptLogger.startRetainingLog()
ScriptLoader.loadItems({_parseSection})
clear {-test.sk::latestLogs::*}
loop ...{_logger}.getLog():
add loop-value.getMessage() to {_logs::*}
set {-test.sk::latestLogs::*} to {_logs::*}
{_logger}.close()
{_parser}.reset()
plural expression last parse logs:
usable in:
custom event "skriptTest"
get:
return {-test.sk::latestLogs::*}
plural expression test errors[ for %-objects%]:
return type: strings
get:
if expr-1 is not set:
set {_test} to event.getEventValue("string")
set {_script} to event.getEventValue("script")
return {-test.sk::errors::%{_script}%.%{_test}%::*}
else:
loop ...expr-1:
set {_test} to loop-value[0]
set {_script} to loop-value[1]
add {-test.sk::errors::%{_script}%.%{_test}%::*} to {_r::*}
return {_r::*}
expression [the] test(-| )world:
return type: world
get:
set {_world} to Bukkit.getWorld("skripttest")
if any:
{_world} is not set
{_world} is null
then:
return Bukkit.getWorlds().get(0)
else:
return {_world}
expression [the] test(-| )location:
return type: location
get:
return test-world.getSpawnLocation().add(10, 1, 0)
expression [the] test(-| )block:
return type: block
get:
return test-location.getBlock()
set:
set block at test-location to change value
expression [the] test(-| )offline[-| ]player:
return type: offlineplayer
get:
set {_instance} to new TestOfflinePlayer()
# TestOfflinePlayer.[TestOfflinePlayer]PLAYER_PROFILE.setProperty(new ProfileProperty("textures", "ewogICJ0aW1lc3RhbXAiIDogMTc0NzQyOTg2MTQwOCwKICAicHJvZmlsZUlkIiA6ICI2OWUzNzAyNjJjN2Q0MjU1YWM3NjliMTNhNWZlOGY3NCIsCiAgInByb2ZpbGVOYW1lIiA6ICJTYWh2ZGUiLAogICJzaWduYXR1cmVSZXF1aXJlZCIgOiB0cnVlLAogICJ0ZXh0dXJlcyIgOiB7CiAgICAiU0tJTiIgOiB7CiAgICAgICJ1cmwiIDogImh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNTE2MGFiZWVhNDI1YzZmODMyYjc0NmE0NTQ0YzVmYjlhOTgxYjAyZTFiZDg1ZmVhNWM3ZWY4MzFiZGM4NzRmMyIKICAgIH0KICB9Cn0="));
return {_instance}