1- # todo registration process should use parse of event, skript reflect has bugs so we are waiting for an update
2- # todo tests should be isolated between .sk files, so before/after is triggered only if a test within that script is running, need to do parse first
3- # todo all tests within %script%, remove with test name, need to do parse first
41using reflection
52
63import:
107 ch.njol.skript.lang.Condition
118 ch.njol.skript.test.runner.TestTracker
129 ch.njol.skript.log.SkriptLogger
10+ java.lang.Runnable
1311
1412local effect sendTestFailMessage %string%[, %-string%]:
1513 trigger:
@@ -19,9 +17,23 @@ local effect sendTestFailMessage %string%[, %-string%]:
1917event "skriptTest":
2018 pattern: [devdinc] test %string% [when <(.+)>]
2119 event-values: string, boolean
20+ parse:
21+ set {_origin} to SkriptLogger.getNode()
22+ set {_realscript} to script ({_origin}.getConfig().getFileName())
23+ # we don't have access to event-string or expr-1, so we can't do it in parse time.
24+ # one thing we can do is cause a call to event to register tho.
25+ set {_list::string} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
26+ set {_list::boolean} to false
27+ create section with {_proxy} stored in {_functions::run}:
28+ wait 2 ticks
29+ call custom event "skriptTest" with {_list::*}
30+ set {_proxy} to new proxy instance of Runnable using {_functions::*}
31+ Bukkit.getGlobalRegionScheduler().execute(instance of plugin "Skript", {_proxy})
32+ continue
2233 check:
34+ 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
2335 set {_ok} to true
24- set {-test.sk::tests::%expr-1%} to "%expr-1%"
36+ set {-test.sk::tests::%{_realscript}%.% expr-1%} to [ "%expr-1%", {_realscript}] # registering
2537 if "%expr-1%" is event-string:
2638 set {_raw} to first element of regex-1
2739 if {_raw} is set:
@@ -33,28 +45,29 @@ event "skriptTest":
3345
3446event "beforeSkriptTest":
3547 pattern: [devdinc] before each test
36- event-values: string, boolean
48+ event-values: string, boolean, script
3749 check:
3850 continue
3951
4052event "afterSkriptTest":
4153 pattern: [devdinc] after each test
42- event-values: string, boolean
54+ event-values: string, boolean, script
4355 check:
4456 continue
4557
4658event "beforeSkriptTestAll":
4759 pattern: [devdinc] before all tests
60+ event-values: script
4861 check:
4962 continue
5063
5164event "afterSkriptTestAll":
5265 pattern: [devdinc] after all tests
66+ event-values: script
5367 check:
5468 continue
5569
56- plural expression all tests [with test name %-string%]:
57- return type: strings
70+ plural expression [all] tests [[with] [test] [name] %-string%] [[with][in] %-script%]:
5871 parse:
5972 set {_scoped} to false if expr-2 is not set
6073 continue
@@ -64,63 +77,77 @@ plural expression all tests [with test name %-string%]:
6477 loop {-test.sk::tests::*}:
6578 if any:
6679 expr-1 is not set
67- loop-value is expr-1
80+ loop-value[0] is expr-1
6881 then:
69- add "% loop-value%" to {_r::*}
82+ add loop-value to {_r::*}
7083 else:
71- if {-test.sk::tests::%expr-1%} is set:
72- add "%expr-1%" to {_r::*}
84+ loop {-test.sk::tests::*}:
85+ loop-value[1] is expr-2
86+ if any:
87+ expr-1 is not set
88+ loop-value[0] is expr-1
89+ then:
90+ add loop-value to {_r::*}
7391
7492 return {_r::*}
7593
76- effect (1:|2:auto)run [test][s] %strings %:
94+ effect (1:|2:auto)run %objects %:
7795 trigger:
7896 set {_tests::*} to expr-1
7997 set {_alltests::*} to all tests
80- call custom event "beforeSkriptTestAll"
8198 loop {_tests::*}:
82- set {_list::string} to loop-value
99+ set {_list::script} to loop-value[1]
100+ {_scripts::*} does not contain {_list::script}
101+ add {_list::script} to {_scripts::*}
102+ call custom event "beforeSkriptTestAll" with {_list::*}
103+ loop {_tests::*}:
104+ set {_list::string} to loop-value[0]
105+ set {_list::script} to loop-value[1]
83106 set {_list::boolean} to true if parse mark is 2 else false
84107 call custom event "beforeSkriptTest" with {_list::*}
85108 call custom event "skriptTest" with {_list::*}
86109 call custom event "afterSkriptTest" with {_list::*}
87110 if any:
88- loop-value contains "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
89- {_alltests::*} does not contain loop-value
111+ {_list::string} contains "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
112+ size of ( {_alltests::*} where ["%input%" is "% loop-value%"]) is 0 # todo
90113 then:
91114 add 1 to {_forgottenTestResults}
92115 continue loop
93116 add 1 to {_testFails} if size of {-test.sk::errors::%loop-value%::*} is greater than 0
94- call custom event "afterSkriptTestAll"
117+ loop {_scripts::*}:
118+ set {_list::script} to loop-value
119+ call custom event "afterSkriptTestAll" with {_list::*}
95120 set {_validTestAmount} to size of {_tests::*} - {_forgottenTestResults}
96121 if {_validTestAmount} is not 0:
97122 send "[<gold>Skript<reset>] <yellow>%{_validTestAmount} - {_testFails}%/%{_validTestAmount}% tests passed." to console
98123 else if size of {_alltests::*} is greater than 0: # skipping if there is no initial hidden test
99124 send "[<gold>Skript<reset>] <yellow>No tests found." to console
100125
101- condition last test result [of [test] %-string %] is a (1:pass|2:fail):
126+ condition last test result [of %-object %] is a (1:pass|2:fail):
102127 usable in:
103128 custom event "skriptTest"
104129 check:
105130 if expr-1 is not set:
106131 set {_test} to event.getEventValue("string")
132+ set {_script} to event.getEventValue("script")
107133 else:
108- set {_test} to expr-1
109- stop if all tests does not contain expr-1
134+ set {_test} to expr-1[0]
135+ set {_script} to expr-1[1]
136+ stop if size of (all tests where ["%input%" is "%expr-1%"]) is 0
110137 if all:
111138 parse mark is 1
112- size of {-test.sk::errors::%{_test}%::*} <= 0
139+ size of {-test.sk::errors::%{_script}%.%{ _test}%::*} <= 0
113140 then:
114141 continue
115142 else:
116143 if all:
117144 parse mark is 2
118- size of {-test.sk::errors::%{_test}%::*} > 0
145+ size of {-test.sk::errors::%{_script}%.%{ _test}%::*} > 0
119146 then:
120147 continue
121148
122149before each test:
123- delete {-test.sk::errors::%event-string%::*}
150+ delete {-test.sk::errors::%event-script%.%event- string%::*}
124151 set {-test.sk::testblock} to test-block's type
125152
126153after each test:
@@ -129,7 +156,9 @@ after each test:
129156on load:
130157 delete {-test.sk::*}
131158 wait 1 tick
132- run test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
159+ set {_list::string} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313"
160+ set {_list::boolean} to false
161+ call custom event "skriptTest" with {_list::*}
133162 wait 1 tick
134163 set {_tests::*} to all tests
135164 autorun {_tests::*}
@@ -162,6 +191,7 @@ effect:
162191
163192 set {_label} to "assert true" if parse tags contains "1" else "assert false"
164193 set {_test} to event.getEventValue("string")
194+ set {_script} to event.getEventValue("script")
165195 if all:
166196 parse tags contains "1"
167197 {_ok} is false
@@ -181,7 +211,7 @@ effect:
181211 if parse tags does not contain "5":
182212 sendTestFailMessage "Test ""%{_test}%"" with condition '%{_label}%: %{_raw}%' failed", expr-1
183213 TestTracker.testFailed(expr-1)
184- add "%expr-1%" to {-test.sk::errors::%{_test}%::*}
214+ add "%expr-1%" to {-test.sk::errors::%{_script}%.%{ _test}%::*}
185215 if parse tags contains "3":
186216 delay effect
187217
@@ -190,10 +220,11 @@ effect (3:|4:(no|without) (halt[ing]|fail[(-| )](safe|fast)|abort[ing])) fail te
190220 custom event "skriptTest"
191221 trigger:
192222 set {_test} to event.getEventValue("string")
223+ set {_script} to event.getEventValue("script")
193224 if parse tags does not contain "5":
194225 sendTestFailMessage "Test ""%{_test}%"" failed", expr-1
195226 TestTracker.testFailed(expr-1)
196- add "%expr-1%" to {-test.sk::errors::%{_test}%::*}
227+ add "%expr-1%" to {-test.sk::errors::%{_script}%.%{ _test}%::*}
197228 if parse tags contains "3":
198229 delay effect
199230
@@ -205,14 +236,13 @@ effect stop auto [test] execution [here]:
205236 if {_bool} is true:
206237 delay effect
207238
208- expression [event(-| )]test:
209- return type: string
239+ expression event(-| )test:
210240# usable in:
211241# custom event "skriptTest"
212242 get:
213- return event.getEventValue("string")
243+ return [ event.getEventValue("string"), event.getEventValue("script")]
214244
215- condition %string% (1:is|2:is not|2:isn't) autorun:
245+ condition event(-| )test (1:is|2:is not|2:isn't) autorun:
216246 # usable in:
217247 # custom event "skriptTest"
218248 check:
@@ -257,16 +287,18 @@ plural expression last parse logs:
257287 get:
258288 return {-test.sk::latestLogs::*}
259289
260- plural expression test errors[ for [test[s]] %-strings %]:
290+ plural expression test errors[ for %-objects %]:
261291 return type: strings
262292 get:
263293 if expr-1 is not set:
264294 set {_test} to event.getEventValue("string")
265- return {-test.sk::errors::%{_test}%::*}
295+ set {_script} to event.getEventValue("script")
296+ return {-test.sk::errors::%{_script}%.%{_test}%::*}
266297 else:
267298 loop ...expr-1:
268- set {_test} to loop-value
269- add {-test.sk::errors::%{_test}%::*} to {_r::*}
299+ set {_test} to loop-value[0]
300+ set {_script} to loop-value[1]
301+ add {-test.sk::errors::%{_script}%.%{_test}%::*} to {_r::*}
270302 return {_r::*}
271303
272304expression [the] test(-| )world:
@@ -358,8 +390,8 @@ devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 stop auto execution works":
358390 broadcast "<red>ERROR: auto execution not stopped"
359391
360392devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 all tests returns this test":
361- set {_all::*} to all tests
362- assert true: {_all::*} contains "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 all tests returns this test"
393+ set {_all::*} to all tests with test name "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 all tests returns this test"
394+ assert true: size of {_all::*} > 0
363395
364396devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 all tests":
365397 set {_all::*} to all tests
@@ -373,7 +405,7 @@ devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 errors do not leak between te
373405 assert true: size of test errors is 0
374406
375407devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 event-test returns correct name":
376- assert true: event-test is event-string
408+ assert true: event-test[0] is event-string
377409
378410devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 test-block is temporary A":
379411 set {-test.sk::temptestblocka} to test-block's type
@@ -398,5 +430,5 @@ devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 last test result A":
398430 fail test with no error message
399431
400432devdinc test "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 last test result B":
401- set {_test} to "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 last test result A"
402- assert true: last test result of {_test} is a fail
433+ set {_test::* } to all tests with test name "f39f0f4a-31ee-4b71-87e9-38ddba3a2313 last test result A"
434+ assert true: last test result of {_test::1 } is a fail
0 commit comments