-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathTesting.scala
138 lines (119 loc) · 4.85 KB
/
Testing.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
import Dependencies._
import sbt.Defaults._
import sbt.Keys._
import sbt._
import complete.DefaultParsers._
import sbt.util.Logger
import scala.sys.process._
object Testing {
private val AllTests = config("alltests") extend Test
private val CromwellBenchmarkTest = config("benchmark") extend Test
private val DockerTestTag = "DockerTest"
private val CromwellIntegrationTestTag = "CromwellIntegrationTest"
private val GcsIntegrationTestTag = "GcsIntegrationTest"
private val AwsIntegrationTestTag = "AwsTest"
private val DbmsTestTag = "DbmsTest"
private val AllTestTags = List(
DockerTestTag,
CromwellIntegrationTestTag,
GcsIntegrationTestTag,
AwsIntegrationTestTag,
DbmsTestTag
)
val minnieKenny = inputKey[Unit]("Run minnie-kenny.")
private val includeTestTags: Seq[String] =
sys.env
.get("CROMWELL_SBT_TEST_INCLUDE_TAGS")
.filter(_.nonEmpty)
.map(_.split(",").toList.map(_.trim))
.getOrElse(Nil)
private val excludeTestTags: Seq[String] =
sys.env
.get("CROMWELL_SBT_TEST_EXCLUDE_TAGS")
.filter(_.nonEmpty)
.map(_.split(",").toList.map(_.trim))
.getOrElse(AllTestTags)
private val spanScaleFactor: String = sys.env.getOrElse("CROMWELL_SBT_TEST_SPAN_SCALE_FACTOR", "1")
/*
The arguments that will be added to the default test config, but removed from all other configs.
`sbt coverage test` adds other arguments added to generate the coverage reports.
Tracking the arguments we add to the default allows one to later remove them when building up other configurations.
*/
private val includeTestArgs = includeTestTags.map(Tests.Argument(TestFrameworks.ScalaTest, "-n", _))
private val excludeTestArgs = excludeTestTags.map(Tests.Argument(TestFrameworks.ScalaTest, "-l", _))
private val filterTestArgs = if (includeTestArgs.nonEmpty) includeTestArgs else excludeTestArgs
private val TestReportArgs =
Tests.Argument(
TestFrameworks.ScalaTest,
"-oDSI",
"-u",
"target/test-reports",
"-F",
spanScaleFactor,
"-W",
"300",
"300"
)
/** Run minnie-kenny only once per sbt invocation. */
class MinnieKennySingleRunner() {
private val mutex = new Object
private var resultOption: Option[Int] = None
/** Run using the logger, throwing an exception only on the first failure. */
def runOnce(log: Logger, args: Seq[String]): Unit =
mutex synchronized {
if (resultOption.isEmpty) {
log.debug(s"Running minnie-kenny.sh${args.mkString(" ", " ", "")}")
val result = ("./minnie-kenny.sh" +: args) ! log
resultOption = Option(result)
if (result == 0)
log.debug("Successfully ran minnie-kenny.sh")
else
sys.error("Running minnie-kenny.sh failed. Please double check for errors above.")
}
}
}
// Only run one minnie-kenny.sh at a time!
private lazy val minnieKennySingleRunner = new MinnieKennySingleRunner
private val ScalaMeterFramework = new TestFramework("org.scalameter.ScalaMeterFramework")
val testSettings = List(
libraryDependencies ++= testDependencies.map(_ % Test),
// `test` (or `assembly`) - Run most tests
Test / testOptions ++= Seq(TestReportArgs) ++ filterTestArgs,
// `alltests:test` - Run all tests
AllTests / testOptions := (Test / testOptions).value.diff(filterTestArgs),
// Reduce the load on SBT by only searching for ScalaTest specs excluding others like JUnit and ScalaCheck
testFrameworks := List(TestFrameworks.ScalaTest),
// Add scalameter as a test framework in the CromwellBenchmarkTest scope
CromwellBenchmarkTest / testFrameworks := List(TestFrameworks.ScalaTest, ScalaMeterFramework),
// Don't execute benchmarks in parallel
CromwellBenchmarkTest / parallelExecution := false,
// Until we move away from Travis do not execute ANY tests in parallel (see also Settings.sharedSettings)
Test / parallelExecution := false,
// Since parallelExecution is off do not buffer test results
Test / logBuffered := false,
// Make sure no secrets are committed to git
minnieKenny := {
val log = streams.value.log
val args = spaceDelimited("<arg>").parsed
minnieKennySingleRunner.runOnce(log, args)
},
Test / test := {
minnieKenny.toTask("").value
(Test / test).value
}
)
private val integrationTestSettings = List(
libraryDependencies ++= testDependencies.map(_ % IntegrationTest)
) ++ itSettings
def addTestSettings(project: Project) =
project
.settings(testSettings)
.configs(AllTests)
.settings(inConfig(AllTests)(Defaults.testTasks): _*)
.configs(CromwellBenchmarkTest)
.settings(inConfig(CromwellBenchmarkTest)(Defaults.testTasks): _*)
def addIntegrationTestSettings(project: Project) =
project
.settings(integrationTestSettings)
.configs(IntegrationTest)
}