/
Suites.scala
102 lines (93 loc) · 3.8 KB
/
Suites.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
/*
* 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
import org.scalactic.Requirements._
import org.scalactic.exceptions.NullArgumentException
/**
* A <code>Suite</code> class that takes zero to many <code>Suite</code>s in its constructor,
* which will be returned from its <code>nestedSuites</code> method.
*
* <p>
* For example, you can define a suite that always executes a list of
* nested suites like this:
* </p>
*
* <pre class="stHighlighted">
* <span class="stReserved">class</span> <span class="stType">StepsSuite</span> <span class="stReserved">extends</span> <span class="stType">Suites</span>(
* <span class="stReserved">new</span> <span class="stType">Step1Suite</span>,
* <span class="stReserved">new</span> <span class="stType">Step2Suite</span>,
* <span class="stReserved">new</span> <span class="stType">Step3Suite</span>,
* <span class="stReserved">new</span> <span class="stType">Step4Suite</span>,
* <span class="stReserved">new</span> <span class="stType">Step5Suite</span>
* )
* </pre>
*
* <p>
* If <code>StepsSuite</code> is executed sequentially, it will execute its
* nested suites in the passed order: <code>Step1Suite</code>, <code>Step2Suite</code>,
* <code>Step3Suite</code>, <code>Step4Suite</code>, and <code>Step5Suite</code>.
* If <code>StepsSuite</code> is executed in parallel, the nested suites will
* be executed concurrently.
* </p>
*
* @param suitesToNest a sequence of <code>Suite</code>s to nest.
*
* @throws NullPointerException if <code>suitesToNest</code>, or any suite
* it contains, is <code>null</code>.
*
* @author Bill Venners
*/
//SCALATESTJS-ONLY @scala.scalajs.reflect.annotation.EnableReflectiveInstantiation
//SCALATESTNATIVE-ONLY @scala.scalanative.reflect.annotation.EnableReflectiveInstantiation
class Suites(suitesToNest: Suite*) extends Suite { thisSuite =>
requireNonNull(suitesToNest)
for (s <- suitesToNest) {
if (s == null)
throw new NullArgumentException("A passed suite was null")
}
/**
* Returns an immutable <code>IndexedSeq</code> containing the suites passed to the constructor in
* the order they were passed.
*/
override val nestedSuites: collection.immutable.IndexedSeq[Suite] = Vector.empty ++ suitesToNest
/**
* Returns a user friendly string for this suite, composed of the
* simple name of the class (possibly simplified further by removing dollar signs if added by the Scala interpeter) and, if this suite
* contains nested suites, the result of invoking <code>toString</code> on each
* of the nested suites, separated by commas and surrounded by parentheses.
*
* @return a user-friendly string for this suite
*/
override def toString: String = Suite.suiteToString(None, thisSuite)
}
/**
* Companion object to class <code>Suites</code> that offers an <code>apply</code> factory method
* for creating a <code>Suites</code> instance.
*
* <p>
* One use case for this object is to run multiple specification-style suites in the Scala interpreter, like this:
* </p>
*
* <pre class="stREPL">
* scala> Suites(new MyFirstSuite, new MyNextSuite).execute()
* </pre>
*/
object Suites {
/**
* Factory method for creating a <code>Suites</code> instance.
*/
def apply(suitesToNest: Suite*): Suites = new Suites(suitesToNest: _*)
}