/
ScalaTestAntTask.scala
1137 lines (1006 loc) · 32 KB
/
ScalaTestAntTask.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.tools
import scala.collection.mutable.ListBuffer
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.Task
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.AntClassLoader
import org.apache.tools.ant.taskdefs.Java
/**
* <p>
* An ant task to run ScalaTest. Instructions on how to specify various
* options are below. See the main documentation for object <a href="Runner$.html"><code>Runner</code></a> class for a description
* of what each of the options does.
* </p>
*
* <p>
* To use the ScalaTest ant task, you must first define it in your ant file using <code>taskdef</code>.
* Here's an example:
* </p>
*
* <pre>
* <path id="scalatest.classpath">
* <pathelement location="${lib}/scalatest.jar"/>
* <pathelement location="${lib}/scala-library.jar"/>
* <-- scala-actors.jar needed only for ScalaTest <= 1.9.1 on Scala >= 2.10.0 -->
* <pathelement location="${lib}/scala-actors.jar"/>
* </path>
*
* <target name="main" depends="dist">
* <taskdef name="scalatest" classname="org.scalatest.tools.ScalaTestAntTask">
* <classpath refid="scalatest.classpath"/>
* </taskdef>
*
* <scalatest ...
* </target>
* </pre>
*
* <p>
* Note that you only need the <code>scala-actors.jar</code> if you are using ScalaTest version 1.9.1 or earlier
* with Scala 2.10 or later.
* Once defined, you use the task by specifying information in a <code>scalatest</code> element:
* </p>
*
* <pre>
* <scalatest ...>
* ...
* </scalatest>
* </pre>
*
* <p>
* You can place key value pairs into the <a href="Runner$.html#configMapSection">config map</a> using nested <code><config></code> elements,
* like this:
* </p>
*
* <pre>
* <scalatest>
* <config name="dbname" value="testdb"/>
* <config name="server" value="192.168.1.188"/>
* </pre>
*
* <p>
* You can specify a <a href="Runner$.html#specifyingARunpath">runpath</a> using either a <code>runpath</code> attribute and/or nested
* <code><runpath></code> elements, using standard ant path notation:
* </p>
*
* <pre>
* <scalatest runpath="serviceuitest-1.1beta4.jar:myjini">
* </pre>
*
* <p>
* or
* </p>
*
* <pre>
* <scalatest>
* <runpath>
* <pathelement location="serviceuitest-1.1beta4.jar"/>
* <pathelement location="myjini"/>
* </runpath>
* </pre>
*
* <p>
* To add a URL to your runpath, use a <code><runpathurl></code> element
* (since ant paths don't support URLs):
* </p>
*
* <pre>
* <scalatest>
* <runpathurl url="http://foo.com/bar.jar"/>
* </pre>
*
* <p>
* You can specify <a href="Runner$.html#specifyingReporters">reporters</a> using nested <code><reporter></code> elements, where the <code>type</code>
* attribute must be one of the following:
* </p>
*
* <ul>
* <li> <code>graphic</code> </li>
* <li> <code>file</code> </li>
* <li> <code>memory</code> </li>
* <li> <code>junitxml</code> </li>
* <li> <code>html</code> </li>
* <li> <code>stdout</code> </li>
* <li> <code>stderr</code> </li>
* <li> <code>reporterclass</code> </li>
* </ul>
*
* <p>
* Each may include a <code>config</code> attribute to specify the <a href="Runner$.html#configuringReporters">reporter configuration</a>.
* Types <code>file</code>, <code>memory</code>, <code>junitxml</code>, <code>html</code>, and <code>reporterclass</code>
* require additional attributes (the css attribute is optional for the html reporter):
* </p>
*
* <pre>
* <scalatest>
* <reporter type="stdout" config="FD"/>
* <reporter type="file" filename="test.out"/>
* <reporter type="memory" filename="target/memory.out"/>
* <reporter type="junitxml" directory="target"/>
* <reporter type="html" directory="target" css="src/main/html/mystylesheet.css"/>
* <reporter type="reporterclass" classname="my.ReporterClass"/>
* </pre>
*
* <p>
* Specify <a href="Runner$.html#specifyingTagsToIncludeAndExclude">tags to include and/or exclude</a> using <code><tagsToInclude></code> and
* <code><tagsToExclude></code> elements, like this:
* </p>
*
* <pre>
* <scalatest>
* <tagsToInclude>
* CheckinTests
* FunctionalTests
* </tagsToInclude>
*
* <tagsToExclude>
* SlowTests
* NetworkTests
* </tagsToExclude>
* </pre>
*
* <p>
* Tags to include or exclude can also be specified using attributes
* tagsToInclude and tagsToExclude, with arguments specified as whitespace-
* delimited lists.
* </p>
*
* <p>
* To specify <a href="Runner$.html#selectingSuitesAndTests">suites to run</a>, use either a <code>suite</code> attribute or nested
* <code><suite></code> elements:
* </p>
*
* <pre>
* <scalatest suite="com.artima.serviceuitest.ServiceUITestkit">
* </pre>
*
* <p>
* or
* </p>
*
* <pre>
* <scalatest>
* <suite classname="com.artima.serviceuitest.ServiceUITestkit"/>
* </pre>
*
* <p>
* To specify <a href="Runner$.html#selectingSuitesAndTests">tests to run</a>, use nested <code><test></code> elements with
* either a 'name' or 'substring' attribute:
* </p>
*
* <pre>
* <scalatest>
* <test name="hello test"/>
* <test substring="hello"/>
* </pre>
*
* <p>
* To specify suites using <a href="Runner$.html#membersOnlyWildcard">members-only or wildcard</a> package names, use
* either the <code>membersonly</code> or <code>wildcard</code> attributes, or nested
* <code><membersonly></code> or <code><wildcard></code> elements:
* </p>
*
* <pre>
* <scalatest membersonly="com.artima.serviceuitest">
* </pre>
*
* <p>
* or
* </p>
*
* <pre>
* <scalatest wildcard="com.artima.joker">
* </pre>
*
* <p>
* or
* </p>
*
* <pre>
* <scalatest>
* <membersonly package="com.artima.serviceuitest"/>
* <wildcard package="com.artima.joker"/>
* </pre>
*
* <p>
* Use attribute <code>suffixes="[pipe-delimited list of suffixes]"</code>
* to specify that only classes whose names end in one of the specified <a href="Runner$.html#specifyingSuffixesToDiscover">suffixes</a>
* should be included in discovery searches for Suites to test. This can
* be used to improve discovery time or to limit the scope of a test. E.g.:
* </p>
*
* <pre>
* <scalatest suffixes="Spec|Suite">
* </pre>
*
* <p>
* Use attribute <code>testsfile="[file name]"</code> or nested
* <testsfile> elements to specify files containing a list of
* tests to be run. This is used to rerun failed/canceled tests
* listed in files written by the memory reporter. E.g.:
* </p>
*
* <pre>
* <scalatest testsfile="target/memory.out">
* </pre>
*
* <p>
* or
* </p>
*
* <pre>
* <scalatest>
* <testsfile filename="target/memory.out"/>
* </pre>
*
* <p>
* Use attribute <code>parallel="true"</code> to specify <a href="Runner$.html#executingSuitesInParallel">parallel execution</a> of suites.
* (If the <code>parallel</code> attribute is left out or set to false, suites will be executed sequentially by one thread.)
* When <code>parallel</code> is true, you can include an optional <code>sortSuites</code> attribute to request that events be sorted on-the-fly so that
* events for the same suite are reported together, with a timeout, (<em>e.g.</em>, <code>sortSuites="true"</code>),
* and an optional <code>numthreads</code> attribute to specify the number
* of threads to be created in thread pool (<em>e.g.</em>, <code>numthreads="10"</code>).
* </p>
*
* <p>
* Use attribute <code>haltonfailure="true"</code> to cause ant to fail the
* build if there's a test failure.
* </p>
*
* <p>
* Use attribute <code>fork="true"</code> to cause ant to run the tests in
* a separate process.
* </p>
*
* <p>
* When <code>fork</code> is <code>true</code>, attribute <code>maxmemory</code> may be used to specify
* the maximum memory size that will be passed to the forked jvm. For example, the following setting
* will cause <code>"-Xmx1280M"</code> to be passed to the java command used to
* run the tests.
* </p>
*
* <pre>
* <scalatest maxmemory="1280M">
* </pre>
*
* <p>
* When <code>fork</code> is true, nested <code><jvmarg></code> elements may be used
* to pass additional arguments to the forked jvm.
* For example, if you are running into 'PermGen space' memory errors,
* you could add the following <code>jvmarg</code> to bump up the JVM's <code>MaxPermSize</code> value:
* </p>
*
* <pre>
* <jvmarg value="-XX:MaxPermSize=128m"/>
* </pre>
*
* @author George Berger
*/
class ScalaTestAntTask extends Task {
private var includes: String = ""
private var excludes: String = ""
private var maxMemory: String = null
private var suffixes: String = null
private var parallel = false
private var sortSuites = false
private var haltonfailure = false
private var fork = false
private var spanScaleFactor = 1.0
private var numthreads = 0
private val runpath = new ListBuffer[String]
private val jvmArgs = new ListBuffer[String]
private val suites = new ListBuffer[SuiteElement]
private val tests = new ListBuffer[TestElement]
private val membersonlys = new ListBuffer[String]
private val wildcards = new ListBuffer[String]
private val testNGSuites = new ListBuffer[String]
private val chosenStyles = new ListBuffer[String]
private val testsfiles = new ListBuffer[String]
private val reporters = new ListBuffer[ReporterElement]
private val properties = new ListBuffer[NameValuePair]
/**
* Executes the task.
*/
override def execute: Unit = {
val argsList = buildArgsList
val success = if (fork) javaTaskRunner(argsList)
else Runner.run(argsList.toArray)
if (!success && haltonfailure)
throw new BuildException("ScalaTest run failed.")
}
def buildArgsList: List[String] = {
val args = new ListBuffer[String]
addSuiteArgs(args)
addTestArgs(args)
addReporterArgs(args)
addPropertyArgs(args)
addIncludesArgs(args)
addExcludesArgs(args)
addRunpathArgs(args)
addTestNGSuiteArgs(args)
addParallelArg(args)
addSuffixesArg(args)
addTestsfileArgs(args)
addChosenStyles(args)
addSpanScaleFactorArg(args)
args.toList
}
private def javaTaskRunner(args: List[String]): Boolean = {
val java = new Java
java.bindToOwner(this)
java.init()
java.setFork(true)
java.setClassname("org.scalatest.tools.Runner")
val classLoader = getClass.getClassLoader.asInstanceOf[AntClassLoader]
java.setClasspath(new Path(getProject, classLoader.getClasspath))
if (maxMemory != null) java.createJvmarg.setValue("-Xmx" + maxMemory)
for (jvmArg <- jvmArgs)
java.createJvmarg.setValue(jvmArg)
for (arg <- args)
java.createArg.setValue(arg)
val result = java.executeJava
return (result == 0)
}
//
// Adds '-P runpath' arg pair to args list if a runpath
// element or attribute was specified for task.
//
private def addRunpathArgs(args: ListBuffer[String]): Unit = {
if (runpath.size > 0) {
args += "-R"
args += getSpacedOutPathStr(runpath.toList)
}
}
private def addTestNGSuiteArgs(args: ListBuffer[String]): Unit = {
if (testNGSuites.size > 0) {
args += "-b"
args += getSpacedOutPathStr(testNGSuites.toList)
}
}
private def addChosenStyles(args: ListBuffer[String]): Unit = {
chosenStyles.foreach { style =>
args += "-y"
args += style
}
}
//
// Adds '-C' arg to args list if 'parallel' attribute was
// specified true for task.
//
private def addParallelArg(args: ListBuffer[String]): Unit = {
if (parallel) {
args += (if (sortSuites) "-PS" else "-P") + (if (numthreads > 0) ("" + numthreads) else "")
}
}
//
// Add -F arg to args list if spanScaleFactor attribute was
// specified for task
//
private def addSpanScaleFactorArg(args: ListBuffer[String]): Unit = {
args += "-F"
args += spanScaleFactor.toString
}
//
// Adds '-q' arg to args list if 'suffixes' attribute was
// specified for task.
//
private def addSuffixesArg(args: ListBuffer[String]): Unit = {
if (suffixes != null) {
args += "-q"
args += suffixes
}
}
//
// Adds '-A' arg to args list if 'testsfile' attribute was
// specified for task.
//
private def addTestsfileArgs(args: ListBuffer[String]): Unit = {
for (testsfile <- testsfiles) {
args += "-A"
args += testsfile
}
}
//
// Adds '-n includes-list' arg pair to args list if a tagsToInclude
// element or attribute was supplied for task.
//
private def addIncludesArgs(args: ListBuffer[String]): Unit = {
if ((includes != null) && (includes.trim != "")) {
args += "-n"
args += singleSpace(includes)
}
}
//
// Adds '-l excludes-list' arg pair to args list if a tagsToExclude
// element or attribute was supplied for task.
//
private def addExcludesArgs(args: ListBuffer[String]): Unit = {
if ((excludes != null) && (excludes.trim != "")) {
args += "-l"
args += singleSpace(excludes)
}
}
//
// Adds '-Dname=value' argument to args list for each nested
// <property> element supplied for task.
//
private def addPropertyArgs(args: ListBuffer[String]): Unit = {
for (pair <- properties)
args += "-D" + pair.getName + "=" + pair.getValue
}
//
// Adds '-s classname' argument to args list for each suite
// specified for task. Adds '-m packagename' for each
// membersonly element specified, and '-w packagename' for
// each wildcard element specified.
//
private def addSuiteArgs(args: ListBuffer[String]): Unit = {
for (suite <- suites) {
if (suite == null)
throw new BuildException(
"missing classname attribute for <suite> element")
args += "-s"
args += suite.getClassName
suite.getTestNames.foreach { tn =>
if (tn == null)
throw new BuildException("missing name attribute for <test> element")
args += "-t"
args += tn
}
suite.getNestedSuites.foreach { ns =>
if (ns.getSuiteId == null)
throw new BuildException("missing suiteId attribute for <nested> element")
args += "-i"
args += ns.getSuiteId
ns.getTestNames.foreach { tn =>
if (tn == null)
throw new BuildException("missing name attribute for <test> element")
args += "-t"
args += tn
}
}
}
for (packageName <- membersonlys) {
if (packageName == null)
throw new BuildException(
"missing package attribute for <membersonly> element")
args += "-m"
args += packageName
}
for (packageName <- wildcards) {
if (packageName == null)
throw new BuildException(
"missing package attribute for <wildcard> element")
args += "-w"
args += packageName
}
}
//
// Adds '-t testname' or '-z substring' argument to args list for
// each test specified for task.
//
private def addTestArgs(args: ListBuffer[String]): Unit = {
for (test <- tests) {
if (test.getName != null) {
args += "-t"
args += test.getName
}
else if (test.getSubstring != null) {
args += "-z"
args += test.getSubstring
}
else
throw new BuildException(
"missing name or substring attribute for <test> element")
}
}
//
// Adds appropriate reporter options to args list for each
// nested reporter element specified for task. Defaults to
// stdout if no reporter specified.
//
private def addReporterArgs(args: ListBuffer[String]): Unit = {
if (reporters.size == 0)
args += "-o"
for (reporter <- reporters) {
reporter.getType match {
case "stdout" => addReporterOption(args, reporter, "-o")
case "stderr" => addReporterOption(args, reporter, "-e")
case "graphic" => addReporterOption(args, reporter, "-g")
case "file" => addFileReporter(args, reporter)
case "memory" => addMemoryReporter(args, reporter)
case "xml" => addXmlReporter(args, reporter)
case "junitxml" => addJunitXmlReporter(args, reporter)
case "dashboard" => addDashboardReporter(args, reporter)
case "html" => addHtmlReporter(args, reporter)
case "reporterclass" => addReporterClass(args, reporter)
case t =>
throw new BuildException("unexpected reporter type [" + t + "]")
}
}
}
//
// Adds specified option to args for reporter. Appends reporter
// config string to option if specified, e.g. "-eFD".
//
private def addReporterOption(args: ListBuffer[String],
reporter: ReporterElement,
option: String): Unit =
{
val config = reporter.getConfig
if (config == null) args += option
else args += option + config
}
//
// Adds '-f' file reporter option to args. Appends reporter
// config string to option if specified. Adds reporter's
// filename as additional argument, e.g. "-fFD", "filename".
//
private def addFileReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-f")
if (reporter.getFilename == null)
throw new BuildException(
"reporter type 'file' requires 'filename' attribute")
args += reporter.getFilename
}
//
// Adds '-M' memory reporter option to args. Adds reporter's
// filename as additional argument, e.g. "-M", "filename".
//
private def addMemoryReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-M")
if (reporter.getFilename == null)
throw new BuildException(
"reporter type 'memory' requires 'filename' attribute")
args += reporter.getFilename
}
//
// Adds '-x' xml reporter option to args. Adds reporter's
// directory as additional argument, e.g. "-x", "directory".
// [disabled for now]
//
private def addXmlReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-x")
if (reporter.getDirectory == null)
throw new BuildException(
"reporter type 'xml' requires 'directory' attribute")
args += reporter.getDirectory
}
//
// Adds '-u' junit xml reporter option to args. Adds reporter's
// directory as additional argument, e.g. "-u", "directory".
//
private def addJunitXmlReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-u")
if (reporter.getDirectory == null)
throw new BuildException(
"reporter type 'junitxml' requires 'directory' attribute")
args += reporter.getDirectory
}
//
// Adds '-d' Dashboard reporter option to args. Adds reporter's
// directory as additional argument, e.g. "-d", "directory".
//
private def addDashboardReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-d")
if (reporter.getDirectory == null)
throw new BuildException(
"reporter type 'dashboard' requires 'directory' attribute")
args += reporter.getDirectory
if (reporter.getNumfiles >= 0) {
args += "-a"
args += reporter.getNumfiles.toString
}
}
//
// Adds '-h' html reporter option to args. Appends reporter
// config string to option if specified. Adds reporter's
// filename as additional argument, e.g. "-hFD", "filename".
//
private def addHtmlReporter(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-h")
if (reporter.getDirectory == null)
throw new BuildException(
"reporter type 'html' requires 'directory' attribute")
args += reporter.getDirectory
if (reporter.getCss != null) {
args += "-Y"
args += reporter.getCss
}
}
//
// Adds '-C' reporter class option to args. Appends
// reporter config string to option if specified. Adds
// reporter's classname as additional argument, e.g. "-C",
// "my.ReporterClass".
//
private def addReporterClass(args: ListBuffer[String],
reporter: ReporterElement): Unit =
{
addReporterOption(args, reporter, "-C")
if (reporter.getClassName == null)
throw new BuildException(
"reporter type 'reporterclass' requires 'classname' attribute")
args += reporter.getClassName
}
/**
* Sets value of the <code>runpath</code> attribute.
*/
def setRunpath(runpath: Path): Unit = {
for (element <- runpath.list) {
this.runpath += element
}
}
/**
* Sets value of the <code>tagsToExclude</code> attribute.
*/
def setTagsToExclude(tagsToExclude: String): Unit = {
this.excludes += " " + tagsToExclude
}
/**
* Sets value of the <code>tagsToInclude</code> attribute.
*/
def setTagsToInclude(tagsToInclude: String): Unit = {
this.includes += " " + tagsToInclude
}
/**
* Sets value of the <code>haltonfailure</code> attribute.
*/
def setHaltonfailure(haltonfailure: Boolean): Unit = {
this.haltonfailure = haltonfailure
}
/**
* Sets value of the <code>fork</code> attribute.
*/
def setFork(fork: Boolean): Unit = {
this.fork = fork
}
/**
* Sets value of the <code>suffixes</code> attribute.
*/
def setSuffixes(suffixes: String): Unit = {
this.suffixes = suffixes
}
/**
* Sets value of the <code>testsfile</code> attribute.
*/
def setTestsfile(testsfile: String): Unit = {
this.testsfiles += testsfile
}
/**
* Sets value of the <code>maxmemory</code> attribute.
*/
def setMaxmemory(max: String): Unit = {
this.maxMemory = max
}
/**
* Sets value of the <code>testngsuites</code> attribute.
*/
def setTestNGSuites(testNGSuitePath: Path): Unit = {
for (element <- testNGSuitePath.list)
this.testNGSuites += element
}
/**
* Sets value of the <code>numthreads</code> attribute.
*/
def setNumthreads(numthreads: Int): Unit = {
this.numthreads = numthreads
}
/**
* Sets value of the <code>parallel</code> attribute.
*/
def setParallel(parallel: Boolean): Unit = {
this.parallel = parallel
}
/**
* Sets value of the <code>sortSuites</code> attribute.
*/
def setSortSuites(sortSuites: Boolean): Unit = {
this.sortSuites = sortSuites
}
/**
* Sets value of the <code>spanScaleFactor</code> attribute.
*/
def setSpanScaleFactor(spanScaleFactor: Double): Unit = {
this.spanScaleFactor = spanScaleFactor
}
/**
* Sets value from nested element <code>runpath</code>.
*/
def addConfiguredRunpath(runpath: Path): Unit = {
for (element <- runpath.list)
this.runpath += element
}
/**
* Sets value from nested element <code>testngsuites</code>.
*/
def addConfiguredTestNGSuites(testNGSuitePath: Path): Unit = {
for (element <- testNGSuitePath.list)
this.testNGSuites += element
}
/**
* Sets value from nested element <code>runpathurl</code>.
*/
def addConfiguredRunpathUrl(runpathurl: RunpathUrl): Unit = {
runpath += runpathurl.getUrl
}
/**
* Sets value from nested element <code>jvmarg</code>.
*/
def addConfiguredJvmArg(arg: JvmArg): Unit = {
jvmArgs += arg.getValue
}
/**
* Sets values from nested element <code>config</code>.
*/
def addConfiguredConfig(config: NameValuePair): Unit = {
properties += config
}
/**
* Sets value of <code>suite</code> attribute.
*/
def setSuite(suite: SuiteElement): Unit = {
suites += suite
}
/**
* Sets value of <code>membersonly</code> attribute.
*/
def setMembersonly(packageName: String): Unit = {
membersonlys += packageName
}
/**
* Sets value of <code>wildcard</code> attribute.
*/
def setWildcard(packageName: String): Unit = {
wildcards += packageName
}
/**
* Sets value of <code>style</code> attribute.
*/
def setStyle(style: String): Unit = {
chosenStyles += style
}
/**
* Sets value from nested element <code>suite</code>.
*/
def addConfiguredSuite(suite: SuiteElement): Unit = {
suites += suite
}
/**
* Sets value from nested element <code>test</code>.
*/
def addConfiguredTest(test: TestElement): Unit = {
tests += test
}
/**
* Sets value from nested element <code>membersonly</code>.
*/
def addConfiguredMembersOnly(membersonly: PackageElement): Unit = {
membersonlys += membersonly.getPackage
}
/**
* Sets value from nested element <code>wildcard</code>.
*/
def addConfiguredWildcard(wildcard: PackageElement): Unit = {
wildcards += wildcard.getPackage
}
/**
* Sets value from nested element <code>reporter</code>.
*/
def addConfiguredReporter(reporter: ReporterElement): Unit = {
reporters += reporter
}
/**
* Sets value from nested element <code>tagsToInclude</code>.
*/
def addConfiguredTagsToInclude(tagsToInclude: TextElement): Unit = {
this.includes += " " + tagsToInclude.getText
}
def addConfiguredStyle(style: StyleElement): Unit = {
this.chosenStyles += style.getName
}
/**
* Sets value from nested element <code>testsfile</code>.
*/
def addConfiguredTestsfile(testsfile: TestsfileElement): Unit = {
this.testsfiles += testsfile.getFilename
}
/**
* Sets value from nested element <code>tagsToExclude</code>.
*/
def addConfiguredTagsToExclude(tagsToExclude: TextElement): Unit = {
this.excludes += " " + tagsToExclude.getText
}
//
// Translates a list of strings making up a path into a
// single space-delimited string. Uses backslashes to escape
// spaces within individual path elements, since that's what
// Runner's -p option expects.
//
private def getSpacedOutPathStr(path: List[String]): String = {
path.map(_.replaceAll(" ", """\\ """)).mkString("", " ", "")
}
//
// Translates a whitespace-delimited string into a
// whitespace-delimited string, but not the same whitespace. Trims
// off leading and trailing whitespace and converts inter-element
// whitespace to a single space.
//
private def singleSpace(str: String): String = {
str.trim.replaceAll("\\s+", " ")
}
}
//
// Class to hold data from <style> elements.
//
private class StyleElement {
private var name: String = null
def setName(name: String): Unit = {
this.name = name
}
def getName = name
}
//
// Class to hold data from <testsfile> elements.
//
private class TestsfileElement {
private var filename: String = null
def setFilename(filename: String): Unit = {
this.filename = filename
}
def getFilename = filename
}
//
// Class to hold data from <membersonly> and <wildcard> elements.
//
private class PackageElement {
private var packageName: String = null
def setPackage(packageName: String): Unit = {
this.packageName = packageName
}
def getPackage = packageName
}
//
// Class to hold data from <suite> elements.
//
private class SuiteElement {
private var className: String = null
private val testNamesBuffer = new ListBuffer[String]()
private val nestedSuitesBuffer = new ListBuffer[NestedSuiteElement]()