Set name of root project if no name is known

This commit makes sure that between every run in batch mode the local
root project name is updated if no name is set.

This fixes project/generated-root-no-project that was assuming that the
root directory name was `generated-root-no-project`. This invariant does
not hold anymore with the batch-mode. Now one sbt dir is shared for lots
of scripted tests.
This commit is contained in:
jvican 2017-05-02 16:29:01 +02:00
parent 9b3a2e6f0f
commit 7519e63f50
No known key found for this signature in database
GPG Key ID: 42DAFA0F112E8050
1 changed files with 21 additions and 6 deletions

View File

@ -92,9 +92,8 @@ final class ScriptedTests(resourceBaseDirectory: File,
case (groupDir, nameDir) =>
val groupName = groupDir.getName
val testName = nameDir.getName
val testLabel = s"$groupName / $testName"
val testDirectory = testResources.readOnlyResourceDirectory(groupName, testName)
testLabel -> testDirectory
(groupName, testName) -> testDirectory
}
val batchSeed = labelsAndDirs.size / sbtInstances
@ -107,6 +106,21 @@ final class ScriptedTests(resourceBaseDirectory: File,
.toList
}
/** Sets the name of the local root project for those tests run in batch mode.
*
* This is necessary because the current design to run tests in batch mode force
* scripted tests to share one common sbt dir instead of each one having its own.
*
* Sbt extracts the local root project name from the directory name. So those
* scripted tests that don't set the name for the root and whose test files check
* information based on the name will fail.
*
* @param testName The test name used to extract the root project name.
* @return A string-based implementation to run between every reload.
*/
private def setNameImplementation(testName: String) =
s"""set name in LocalRootProject := {if (name.value.startsWith("sbt_")) "$testName" else name.value}"""
/** Defines the batch execution of scripted tests.
*
* Scripted tests are run one after the other one recycling the handlers, under
@ -125,7 +139,7 @@ final class ScriptedTests(resourceBaseDirectory: File,
* @param log The logger.
*/
private def runBatchedTests(
groupedTests: Seq[(String, File)],
groupedTests: Seq[((String, String), File)],
tempTestDir: File,
preHook: File => Unit,
log: Logger
@ -140,7 +154,8 @@ final class ScriptedTests(resourceBaseDirectory: File,
def runBatchTests = {
groupedTests.map {
case (label, originalDir) =>
case ((group, name), originalDir) =>
val label = s"$group / $name"
println(s"Running $label")
// Copy test's contents and reload the sbt instance to pick them up
IO.copyDirectory(originalDir, tempTestDir)
@ -148,8 +163,8 @@ final class ScriptedTests(resourceBaseDirectory: File,
val runTest = () => {
// Reload and initialize (to reload contents of .sbtrc files)
val sbtHandler = handlers.getOrElse('>', sys.error("Missing sbt handler."))
val statement =
Statement(";reload;initialize", Nil, successExpected = true, line = -1)
val cmds = s";reload;initialize;${setNameImplementation(name)}"
val statement = Statement(cmds, Nil, successExpected = true, line = -1)
// Run reload inside the hook to reuse error handling for pending tests
val wrapHook = (file: File) => {
preHook(file)