forked from scalatest/scalatest
/
WordSpecSpec.scala
4077 lines (3715 loc) · 167 KB
/
WordSpecSpec.scala
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2001-2013 Artima, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.scalatest.wordspec
// elements
import org.scalatest._
import org.scalatest.SharedHelpers._
import org.scalatest.events._
import org.scalactic.Prettifier
import java.awt.AWTError
import java.lang.annotation.AnnotationFormatError
import java.nio.charset.CoderMalfunctionError
import javax.xml.parsers.FactoryConfigurationError
import javax.xml.transform.TransformerFactoryConfigurationError
import org.scalactic.exceptions.NullArgumentException
import org.scalatest.exceptions.DuplicateTestNameException
import org.scalatest.exceptions.NotAllowedException
import org.scalatest.exceptions.TestCanceledException
import org.scalatest.exceptions.TestFailedException
import org.scalatest.exceptions.TestRegistrationClosedException
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.wordspec.AnyWordSpec
class WordSpecSpec extends AnyFunSpec with GivenWhenThen {
private val prettifier = Prettifier.default
describe("A WordSpec") {
it("should invoke withFixture from runTest") {
class SpecA extends AnyWordSpec {
var withFixtureWasInvoked = false
var testWasInvoked = false
override def withFixture(test: NoArgTest): Outcome = {
withFixtureWasInvoked = true
super.withFixture(test)
}
"do something" in {
testWasInvoked = true
/* ASSERTION_SUCCEED */
}
}
val a = new SpecA
import scala.language.reflectiveCalls
a.run(None, Args(SilentReporter))
assert(a.withFixtureWasInvoked)
assert(a.testWasInvoked)
}
it("should pass the correct test name in the NoArgTest passed to withFixture") {
class SpecA extends AnyWordSpec {
var correctTestNameWasPassed = false
override def withFixture(test: NoArgTest): Outcome = {
correctTestNameWasPassed = test.name == "do something"
super.withFixture(test)
}
"do something" in {/* ASSERTION_SUCCEED */}
}
val a = new SpecA
import scala.language.reflectiveCalls
a.run(None, Args(SilentReporter))
assert(a.correctTestNameWasPassed)
}
it("should pass the correct config map in the NoArgTest passed to withFixture") {
class SpecA extends AnyWordSpec {
var correctConfigMapWasPassed = false
override def withFixture(test: NoArgTest): Outcome = {
correctConfigMapWasPassed = (test.configMap == ConfigMap("hi" -> 7))
super.withFixture(test)
}
"do something" in {/* ASSERTION_SUCCEED */}
}
val a = new SpecA
import scala.language.reflectiveCalls
a.run(None, Args(SilentReporter, Stopper.default, Filter(), ConfigMap("hi" -> 7), None, new Tracker(), Set.empty))
assert(a.correctConfigMapWasPassed)
}
describe("(when a nesting rule has been violated)") {
it("should, if they call a should from within an in clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" should {
//DOTTY-ONLY ()
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"should\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a should with a nested in from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" should {
"should never run" in {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"should\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a when from within an in clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" when {
//DOTTY-ONLY ()
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"when\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a when with a nested in from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" when {
"should never run" in {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"when\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a that from within an in clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" that {
//DOTTY-ONLY ()
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"that\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a that with a nested in from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" that {
"should never run" in {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"that\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a which from within an in clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" which {
//DOTTY-ONLY ()
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"which\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a which with a nested in from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" which {
"should never run" in {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"which\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a can from within an in clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" can {
//DOTTY-ONLY ()
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"can\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a can with a nested in from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" can {
"should never run" in {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceivedWithCorrectMessage(spec, "should blow up", "a \"can\" clause may not appear inside an \"in\" clause")
}
it("should, if they call a nested it from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"should never run" in {
assert(1 === 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a nested it with tags from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"should never run" taggedAs(mytags.SlowAsMolasses) in {
assert(1 === 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a nested registerTest with tags from within a registerTest clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
registerTest("should blow up") {
registerTest("should never run", mytags.SlowAsMolasses) {
assert(1 == 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a describe with a nested ignore from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"in the wrong place, at the wrong time" should {
"should never run" ignore {
assert(1 === 1)
}
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a nested ignore from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"should never run" ignore {
assert(1 === 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a nested ignore with tags from within an it clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
"should blow up" in {
"should never run" taggedAs(mytags.SlowAsMolasses) ignore {
assert(1 === 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
it("should, if they call a nested registerIgnoredTest with tags from within a registerTest clause, result in a TestFailedException when running the test") {
class MySpec extends AnyWordSpec {
registerTest("should blow up") {
registerIgnoredTest("should never run", mytags.SlowAsMolasses) {
assert(1 == 1)
}
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
ensureTestFailedEventReceived(spec, "should blow up")
}
}
it("should return the test names in registration order from testNames") {
val a = new AnyWordSpec {
"it should test this" in {/* ASSERTION_SUCCEED */}
"it should test that" in {/* ASSERTION_SUCCEED */}
}
assertResult(List("it should test this", "it should test that")) {
a.testNames.iterator.toList
}
val b = new AnyWordSpec {}
assertResult(List[String]()) {
b.testNames.iterator.toList
}
val c = new AnyWordSpec {
"it should test that" in {/* ASSERTION_SUCCEED */}
"it should test this" in {/* ASSERTION_SUCCEED */}
}
assertResult(List("it should test that", "it should test this")) {
c.testNames.iterator.toList
}
val d = new AnyWordSpec {
"A Tester" should {
"test that" in {/* ASSERTION_SUCCEED */}
"test this" in {/* ASSERTION_SUCCEED */}
}
}
assertResult(List("A Tester should test that", "A Tester should test this")) {
d.testNames.iterator.toList
}
val e = new AnyWordSpec {
"A Tester" should {
"test this" in {/* ASSERTION_SUCCEED */}
"test that" in {/* ASSERTION_SUCCEED */}
}
}
assertResult(List("A Tester should test this", "A Tester should test that")) {
e.testNames.iterator.toList
}
}
it("should throw DuplicateTestNameException if a duplicate test name registration is attempted") {
intercept[DuplicateTestNameException] {
new AnyWordSpec {
"should test this" in {/* ASSERTION_SUCCEED */}
"should test this" in {/* ASSERTION_SUCCEED */}
}
}
intercept[DuplicateTestNameException] {
new AnyWordSpec {
"should test this" in {/* ASSERTION_SUCCEED */}
"should test this" ignore {/* ASSERTION_SUCCEED */}
}
}
intercept[DuplicateTestNameException] {
new AnyWordSpec {
"should test this" ignore {/* ASSERTION_SUCCEED */}
"should test this" ignore {/* ASSERTION_SUCCEED */}
}
}
intercept[DuplicateTestNameException] {
new AnyWordSpec {
"should test this" ignore {/* ASSERTION_SUCCEED */}
"should test this" in {/* ASSERTION_SUCCEED */}
}
}
}
describe("(with info calls)") {
class InfoInsideTestSpec extends AnyWordSpec {
val msg = "hi there, dude"
val testName = "test name"
testName in {
info(msg)
/* ASSERTION_SUCCEED */
}
}
// In a Spec, any InfoProvided's fired during the test should be cached and sent out after the test has
// suceeded or failed. This makes the report look nicer, because the info is tucked under the "specifier'
// text for that test.
it("should, when the info appears in the code of a successful test, report the info in the TestSucceeded") {
val spec = new InfoInsideTestSpec
val (testStartingIndex, testSucceededIndex) =
getIndexesForTestInformerEventOrderTests(spec, spec.testName, spec.msg)
assert(testStartingIndex < testSucceededIndex)
}
class InfoBeforeTestSpec extends AnyWordSpec {
val msg = "hi there, dude"
val testName = "test name"
info(msg)
testName in {/* ASSERTION_SUCCEED */}
}
it("should, when the info appears in the body before a test, report the info before the test") {
val spec = new InfoBeforeTestSpec
val (infoProvidedIndex, testStartingIndex, testSucceededIndex) =
getIndexesForInformerEventOrderTests(spec, spec.testName, spec.msg)
assert(infoProvidedIndex < testStartingIndex)
assert(testStartingIndex < testSucceededIndex)
}
it("should, when the info appears in the body after a test, report the info after the test runs") {
val msg = "hi there, dude"
val testName = "test name"
class MySpec extends AnyWordSpec {
testName in {/* ASSERTION_SUCCEED */}
info(msg)
}
val (infoProvidedIndex, testStartingIndex, testSucceededIndex) =
getIndexesForInformerEventOrderTests(new MySpec, testName, msg)
assert(testStartingIndex < testSucceededIndex)
assert(testSucceededIndex < infoProvidedIndex)
}
it("should print to stdout when info is called by a method invoked after the suite has been executed") {
class MySpec extends AnyWordSpec {
callInfo() // This should work fine
def callInfo(): Unit = {
info("howdy")
}
"howdy also" in {
callInfo() // This should work fine
/* ASSERTION_SUCCEED */
}
}
val spec = new MySpec
val myRep = new EventRecordingReporter
spec.run(None, Args(myRep))
spec.callInfo() // TODO: Actually test that This prints to stdout
}
it("should send an InfoProvided with an IndentedText formatter with level 1 when called outside a test") {
val spec = new InfoBeforeTestSpec
val indentedText = getIndentedTextFromInfoProvided(spec)
assert(indentedText === IndentedText("+ " + spec.msg, spec.msg, 0))
}
it("should send an InfoProvided with an IndentedText formatter with level 2 when called within a test") {
val spec = new InfoInsideTestSpec
val indentedText = getIndentedTextFromTestInfoProvided(spec)
assert(indentedText === IndentedText(" + " + spec.msg, spec.msg, 1))
}
}
it("should throw NullArgumentException if a null test tag is provided") {
// it
intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(null) in {/* ASSERTION_SUCCEED */}
}
}
val caught = intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(mytags.SlowAsMolasses, null) in {/* ASSERTION_SUCCEED */}
}
}
assert(caught.getMessage === "a test tag was null")
intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(mytags.SlowAsMolasses, null, mytags.WeakAsAKitten) in {/* ASSERTION_SUCCEED */}
}
}
// ignore
intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(null) ignore {/* ASSERTION_SUCCEED */}
}
}
val caught2 = intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(mytags.SlowAsMolasses, null) ignore {/* ASSERTION_SUCCEED */}
}
}
assert(caught2.getMessage === "a test tag was null")
intercept[NullArgumentException] {
new AnyWordSpec {
"hi" taggedAs(mytags.SlowAsMolasses, null, mytags.WeakAsAKitten) ignore {/* ASSERTION_SUCCEED */}
}
}
// registerTest
intercept[NullArgumentException] {
new AnyWordSpec {
registerTest("hi", null) {/* ASSERTION_SUCCEED */}
}
}
val caught3 = intercept[NullArgumentException] {
new AnyWordSpec {
registerTest("hi", mytags.SlowAsMolasses, null) {/* ASSERTION_SUCCEED */}
}
}
assert(caught3.getMessage == "a test tag was null")
intercept[NullArgumentException] {
new AnyWordSpec {
registerTest("hi", mytags.SlowAsMolasses, null, mytags.WeakAsAKitten) {/* ASSERTION_SUCCEED */}
}
}
// registerIgnoredTest
intercept[NullArgumentException] {
new AnyWordSpec {
registerIgnoredTest("hi", null) {/* ASSERTION_SUCCEED */}
}
}
val caught4 = intercept[NullArgumentException] {
new AnyWordSpec {
registerIgnoredTest("hi", mytags.SlowAsMolasses, null) {/* ASSERTION_SUCCEED */}
}
}
assert(caught4.getMessage == "a test tag was null")
intercept[NullArgumentException] {
new AnyWordSpec {
registerIgnoredTest("hi", mytags.SlowAsMolasses, null, mytags.WeakAsAKitten) {/* ASSERTION_SUCCEED */}
}
}
}
it("should return a correct tags map from the tags method using is (pending)") {
val a = new AnyWordSpec {
"test this" ignore {/* ASSERTION_SUCCEED */}
"test that" is (pending)
}
assertResult(Map("test this" -> Set("org.scalatest.Ignore"))) {
a.tags
}
val b = new AnyWordSpec {
"test this" is (pending)
"test that" ignore {/* ASSERTION_SUCCEED */}
}
assertResult(Map("test that" -> Set("org.scalatest.Ignore"))) {
b.tags
}
val c = new AnyWordSpec {
"test this" ignore {/* ASSERTION_SUCCEED */}
"test that" ignore {/* ASSERTION_SUCCEED */}
}
assertResult(Map("test this" -> Set("org.scalatest.Ignore"), "test that" -> Set("org.scalatest.Ignore"))) {
c.tags
}
val d = new AnyWordSpec {
"test this" taggedAs(mytags.SlowAsMolasses) is (pending)
"test that" taggedAs(mytags.SlowAsMolasses) ignore {/* ASSERTION_SUCCEED */}
}
assertResult(Map("test this" -> Set("org.scalatest.SlowAsMolasses"), "test that" -> Set("org.scalatest.Ignore", "org.scalatest.SlowAsMolasses"))) {
d.tags
}
val e = new AnyWordSpec {
"test this" is (pending)
"test that" is (pending)
}
assertResult(Map()) {
e.tags
}
val f = new AnyWordSpec {
"test this" taggedAs(mytags.SlowAsMolasses, mytags.WeakAsAKitten) is (pending)
"test that" taggedAs(mytags.SlowAsMolasses) in {/* ASSERTION_SUCCEED */}
}
assertResult(Map("test this" -> Set("org.scalatest.SlowAsMolasses", "org.scalatest.WeakAsAKitten"), "test that" -> Set("org.scalatest.SlowAsMolasses"))) {
f.tags
}
val g = new AnyWordSpec {
"test this" taggedAs(mytags.SlowAsMolasses, mytags.WeakAsAKitten) is (pending)
"test that" taggedAs(mytags.SlowAsMolasses) in {/* ASSERTION_SUCCEED */}
}
assertResult(Map("test this" -> Set("org.scalatest.SlowAsMolasses", "org.scalatest.WeakAsAKitten"), "test that" -> Set("org.scalatest.SlowAsMolasses"))) {
g.tags
}
}
class TestWasCalledSuite extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"run this" in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"run that, maybe" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
it("should execute all tests when run is called with testName None") {
val b = new TestWasCalledSuite
b.run(None, Args(SilentReporter))
assert(b.theTestThisCalled)
assert(b.theTestThatCalled)
}
it("should execute one test when run is called with a defined testName") {
val a = new TestWasCalledSuite
a.run(Some("run this"), Args(SilentReporter))
assert(a.theTestThisCalled)
assert(!a.theTestThatCalled)
}
it("should report as ignored, and not run, tests marked ignored") {
class SpecA extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val a = new SpecA
import scala.language.reflectiveCalls
val repA = new TestIgnoredTrackingReporter
a.run(None, Args(repA))
assert(!repA.testIgnoredReceived)
assert(a.theTestThisCalled)
assert(a.theTestThatCalled)
class SpecB extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val b = new SpecB
val repB = new TestIgnoredTrackingReporter
b.run(None, Args(repB))
assert(repB.testIgnoredReceived)
assert(repB.lastEvent.isDefined)
assert(repB.lastEvent.get.testName endsWith "test this")
assert(!b.theTestThisCalled)
assert(b.theTestThatCalled)
class SpecC extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" ignore { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val c = new SpecC
val repC = new TestIgnoredTrackingReporter
c.run(None, Args(repC))
assert(repC.testIgnoredReceived)
assert(repC.lastEvent.isDefined)
assert(repC.lastEvent.get.testName endsWith "test that", repC.lastEvent.get.testName)
assert(c.theTestThisCalled)
assert(!c.theTestThatCalled)
// The order I want is order of appearance in the file.
// Will try and implement that tomorrow. Subtypes will be able to change the order.
class SpecD extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" ignore { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val d = new SpecD
val repD = new TestIgnoredTrackingReporter
d.run(None, Args(repD))
assert(repD.testIgnoredReceived)
assert(repD.lastEvent.isDefined)
assert(repD.lastEvent.get.testName endsWith "test that") // last because should be in order of appearance
assert(!d.theTestThisCalled)
assert(!d.theTestThatCalled)
}
it("should ignore a test marked as ignored if run is invoked with that testName") {
// If I provide a specific testName to run, then it should ignore an Ignore on that test
// method and actually invoke it.
class SpecE extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val e = new SpecE
import scala.language.reflectiveCalls
val repE = new TestIgnoredTrackingReporter
e.run(Some("test this"), Args(repE))
assert(repE.testIgnoredReceived)
assert(!e.theTestThisCalled)
assert(!e.theTestThatCalled)
}
it("should run only those tests selected by the tags to include and exclude sets") {
// Nothing is excluded
class SpecA extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" taggedAs(mytags.SlowAsMolasses) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val a = new SpecA
import scala.language.reflectiveCalls
val repA = new TestIgnoredTrackingReporter
a.run(None, Args(repA))
assert(!repA.testIgnoredReceived)
assert(a.theTestThisCalled)
assert(a.theTestThatCalled)
// SlowAsMolasses is included, one test should be excluded
class SpecB extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" taggedAs(mytags.SlowAsMolasses) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val b = new SpecB
val repB = new TestIgnoredTrackingReporter
b.run(None, Args(repB, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set()), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repB.testIgnoredReceived)
assert(b.theTestThisCalled)
assert(!b.theTestThatCalled)
// SlowAsMolasses is included, and both tests should be included
class SpecC extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" taggedAs(mytags.SlowAsMolasses) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val c = new SpecC
val repC = new TestIgnoredTrackingReporter
c.run(None, Args(repB, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set()), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repC.testIgnoredReceived)
assert(c.theTestThisCalled)
assert(c.theTestThatCalled)
// SlowAsMolasses is included. both tests should be included but one ignored
class SpecD extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
"test this" taggedAs(mytags.SlowAsMolasses) ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val d = new SpecD
val repD = new TestIgnoredTrackingReporter
d.run(None, Args(repD, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set("org.scalatest.Ignore")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(repD.testIgnoredReceived)
assert(!d.theTestThisCalled)
assert(d.theTestThatCalled)
// SlowAsMolasses included, FastAsLight excluded
class SpecE extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" in { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val e = new SpecE
val repE = new TestIgnoredTrackingReporter
e.run(None, Args(repE, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set("org.scalatest.FastAsLight")),
ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repE.testIgnoredReceived)
assert(!e.theTestThisCalled)
assert(e.theTestThatCalled)
assert(!e.theTestTheOtherCalled)
// An Ignored test that was both included and excluded should not generate a TestIgnored event
class SpecF extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" in { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val f = new SpecF
val repF = new TestIgnoredTrackingReporter
f.run(None, Args(repF, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set("org.scalatest.FastAsLight")),
ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repF.testIgnoredReceived)
assert(!f.theTestThisCalled)
assert(f.theTestThatCalled)
assert(!f.theTestTheOtherCalled)
// An Ignored test that was not included should not generate a TestIgnored event
class SpecG extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" ignore { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val g = new SpecG
val repG = new TestIgnoredTrackingReporter
g.run(None, Args(repG, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set("org.scalatest.FastAsLight")),
ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repG.testIgnoredReceived)
assert(!g.theTestThisCalled)
assert(g.theTestThatCalled)
assert(!g.theTestTheOtherCalled)
// No tagsToInclude set, FastAsLight excluded
class SpecH extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" in { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val h = new SpecH
val repH = new TestIgnoredTrackingReporter
h.run(None, Args(repH, Stopper.default, Filter(None, Set("org.scalatest.FastAsLight")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repH.testIgnoredReceived)
assert(!h.theTestThisCalled)
assert(h.theTestThatCalled)
assert(h.theTestTheOtherCalled)
// No tagsToInclude set, mytags.SlowAsMolasses excluded
class SpecI extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) in { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) in { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" in { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val i = new SpecI
val repI = new TestIgnoredTrackingReporter
i.run(None, Args(repI, Stopper.default, Filter(None, Set("org.scalatest.SlowAsMolasses")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repI.testIgnoredReceived)
assert(!i.theTestThisCalled)
assert(!i.theTestThatCalled)
assert(i.theTestTheOtherCalled)
// No tagsToInclude set, mytags.SlowAsMolasses excluded, TestIgnored should not be received on excluded ones
class SpecJ extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) ignore { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" in { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val j = new SpecJ
val repJ = new TestIgnoredTrackingReporter
j.run(None, Args(repJ, Stopper.default, Filter(None, Set("org.scalatest.SlowAsMolasses")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repI.testIgnoredReceived)
assert(!j.theTestThisCalled)
assert(!j.theTestThatCalled)
assert(j.theTestTheOtherCalled)
// Same as previous, except Ignore specifically mentioned in excludes set
class SpecK extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
"test this" taggedAs(mytags.SlowAsMolasses, mytags.FastAsLight) ignore { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
"test that" taggedAs(mytags.SlowAsMolasses) ignore { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
"test the other" ignore { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}
val k = new SpecK
val repK = new TestIgnoredTrackingReporter
k.run(None, Args(repK, Stopper.default, Filter(None, Set("org.scalatest.SlowAsMolasses", "org.scalatest.Ignore")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(repK.testIgnoredReceived)
assert(!k.theTestThisCalled)
assert(!k.theTestThatCalled)
assert(!k.theTestTheOtherCalled)
}
it("should run only those registered tests selected by the tags to include and exclude sets") {
// Nothing is excluded
class SpecA extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
registerTest("test this", mytags.SlowAsMolasses) { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test that") { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val a = new SpecA
import scala.language.reflectiveCalls
val repA = new TestIgnoredTrackingReporter
a.run(None, Args(repA))
assert(!repA.testIgnoredReceived)
assert(a.theTestThisCalled)
assert(a.theTestThatCalled)
// SlowAsMolasses is included, one test should be excluded
class SpecB extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
registerTest("test this", mytags.SlowAsMolasses) { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test that") { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val b = new SpecB
val repB = new TestIgnoredTrackingReporter
b.run(None, Args(repB, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set()), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repB.testIgnoredReceived)
assert(b.theTestThisCalled)
assert(!b.theTestThatCalled)
// SlowAsMolasses is included, and both tests should be included
class SpecC extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
registerTest("test this", mytags.SlowAsMolasses) { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test that", mytags.SlowAsMolasses) { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val c = new SpecC
val repC = new TestIgnoredTrackingReporter
c.run(None, Args(repB, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set()), ConfigMap.empty, None, new Tracker, Set.empty))
assert(!repC.testIgnoredReceived)
assert(c.theTestThisCalled)
assert(c.theTestThatCalled)
// SlowAsMolasses is included. both tests should be included but one ignored
class SpecD extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
registerIgnoredTest("test this", mytags.SlowAsMolasses) { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test that", mytags.SlowAsMolasses) { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
}
val d = new SpecD
val repD = new TestIgnoredTrackingReporter
d.run(None, Args(repD, Stopper.default, Filter(Some(Set("org.scalatest.SlowAsMolasses")), Set("org.scalatest.Ignore")), ConfigMap.empty, None, new Tracker, Set.empty))
assert(repD.testIgnoredReceived)
assert(!d.theTestThisCalled)
assert(d.theTestThatCalled)
// SlowAsMolasses included, FastAsLight excluded
class SpecE extends AnyWordSpec {
var theTestThisCalled = false
var theTestThatCalled = false
var theTestTheOtherCalled = false
registerTest("test this", mytags.SlowAsMolasses, mytags.FastAsLight) { theTestThisCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test that", mytags.SlowAsMolasses) { theTestThatCalled = true; /* ASSERTION_SUCCEED */ }
registerTest("test the other") { theTestTheOtherCalled = true; /* ASSERTION_SUCCEED */ }
}