Skip to content

Commit 12f7dcb

Browse files
committed
Added partest-only sbt target and less verbose file generation
1 parent 9fff1ac commit 12f7dcb

File tree

2 files changed

+35
-24
lines changed

2 files changed

+35
-24
lines changed

project/Build.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ object DottyBuild extends Build {
118118

119119
("-DpartestParentID=" + pid) :: tuning ::: agentOptions ::: travis_build ::: fullpath
120120
}
121-
) ++ addCommandAlias("partest", ";test:compile;lockPartestFile;test:test;runPartestRunner")
121+
) ++ addCommandAlias("partest", ";test:compile;lockPartestFile;test:test;runPartestRunner") ++
122+
addCommandAlias("partest-only", ";test:compile;lockPartestFile;test:test-only dotc.tests;runPartestRunner")
122123

123124
lazy val dotty = Project(id = "dotty", base = file("."), settings = defaults)
124125

test/test/CompilerTest.scala

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,13 @@ abstract class CompilerTest extends DottyTest {
6161
new JFile("." + JFile.separator + "tests" + JFile.separator + "locks" + JFile.separator + s"partest-$pid.lock").exists
6262
}
6363

64-
// Delete generated files from previous run
65-
if (generatePartestFiles)
66-
CompilerTest.init
64+
// Delete generated files from previous run and create new log
65+
val logFile = if (!generatePartestFiles) None else Some(CompilerTest.init)
6766

6867
/** Always run with JUnit. */
6968
def compileLine(cmdLine: String, xerrors: Int = 0)(implicit defaultOptions: List[String]): Unit = {
7069
if (generatePartestFiles)
71-
NestUI.echoWarning("WARNING: compileLine will always run with JUnit, no partest files generated.")
70+
log("WARNING: compileLine will always run with JUnit, no partest files generated.")
7271
compileArgs(cmdLine.split("\n"), xerrors)
7372
}
7473

@@ -87,11 +86,11 @@ abstract class CompilerTest extends DottyTest {
8786
(implicit defaultOptions: List[String]): Unit = {
8887
if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions, xerrors)) {
8988
if (runTest)
90-
NestUI.echoWarning(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension")
89+
log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension")
9190
compileArgs((s"$prefix$fileName$extension" :: args).toArray, xerrors)
9291
} else {
9392
val kind = testKind(prefix, xerrors, runTest)
94-
println(s"generating partest files for test file: $prefix$fileName$extension of kind $kind")
93+
log(s"generating partest files for test file: $prefix$fileName$extension of kind $kind")
9594

9695
val sourceFile = new JFile(prefix + fileName + extension)
9796
if (sourceFile.exists) {
@@ -102,8 +101,7 @@ abstract class CompilerTest extends DottyTest {
102101
}
103102
}
104103
}
105-
106-
def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
104+
def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
107105
extension: String = ".scala")(implicit defaultOptions: List[String]): Unit =
108106
compileFile(prefix, fileName, args, xerrors, extension, true)
109107

@@ -113,7 +111,7 @@ abstract class CompilerTest extends DottyTest {
113111
(implicit defaultOptions: List[String]): Unit = {
114112
if (!generatePartestFiles || !partestableDir(prefix, dirName, args ++ defaultOptions, xerrors)) {
115113
if (runTest)
116-
NestUI.echoWarning(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
114+
log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$dirName")
117115
val dir = Directory(prefix + dirName)
118116
val (files, normArgs) = args match {
119117
case "-deep" :: args1 => (dir.deepFiles, args1)
@@ -127,21 +125,18 @@ abstract class CompilerTest extends DottyTest {
127125
case _ => (new JFile(prefix + dirName), args ++ defaultOptions, "shallow")
128126
}
129127
val kind = testKind(prefix, xerrors, runTest)
130-
println(s"generating partest files for test directory ($deep): $prefix$dirName of kind $kind")
128+
log(s"generating partest files for test directory ($deep): $prefix$dirName of kind $kind")
131129

132130
if (sourceDir.exists) {
133131
val firstDest = Directory(DPConfig.testRoot + JFile.separator + kind + JFile.separator + dirName)
134132
computeDestAndCopyFiles(sourceDir, firstDest, kind, flags, xerrors.toString)
135-
if (deep == "deep") {
136-
sourceDir.listFiles.foreach(_.delete)
137-
sourceDir.delete
138-
}
133+
if (deep == "deep")
134+
deleteDir(sourceDir)
139135
} else {
140136
throw new java.io.FileNotFoundException(s"Unable to locate test dir $prefix$dirName")
141137
}
142138
}
143139
}
144-
145140
def runDir(prefix: String, dirName: String, args: List[String] = Nil, xerrors: Int = 0)
146141
(implicit defaultOptions: List[String]): Unit =
147142
compileDir(prefix, dirName, args, xerrors, true)
@@ -153,11 +148,11 @@ abstract class CompilerTest extends DottyTest {
153148
val dir = Directory(path)
154149
val fileNames = dir.files.toArray.map(_.jfile.getName).filter(name => (name endsWith ".scala") || (name endsWith ".java"))
155150
for (name <- fileNames) {
156-
if (verbose) println(s"testing $path$name")
151+
if (verbose) log(s"testing $path$name")
157152
compileFile(path, name, args, 0, "", runTest)
158153
}
159154
for (subdir <- dir.dirs) {
160-
if (verbose) println(s"testing $subdir")
155+
if (verbose) log(s"testing $subdir")
161156
compileDir(path, subdir.jfile.getName, args, 0, runTest)
162157
}
163158
}
@@ -177,6 +172,7 @@ abstract class CompilerTest extends DottyTest {
177172
recCopyFiles(jfile, destDir / jfile.getName)
178173
})
179174
compileDir(DPConfig.testRoot + JFile.separator, testName, args, xerrors)
175+
deleteDir(destDir.jfile)
180176
}
181177
}
182178

@@ -197,7 +193,7 @@ abstract class CompilerTest extends DottyTest {
197193
if (runTest) "run"
198194
else if (xerrors > 0) "neg"
199195
else if (prefixDir.endsWith("run" + JFile.separator)) {
200-
NestUI.echoWarning("WARNING: test is being run as pos test despite being in a run directory. " +
196+
log("WARNING: test is being run as pos test despite being in a run directory. " +
201197
"Use runFile/runDir instead of compileFile/compileDir to do a run test")
202198
"pos"
203199
} else "pos"
@@ -246,7 +242,7 @@ abstract class CompilerTest extends DottyTest {
246242
if (kind == "run")
247243
FileManager.copyFile(check.jfile, dest.changeExtension("check").jfile)
248244
else
249-
NestUI.echoWarning(s"WARNING: ignoring $check for test kind $kind")
245+
log(s"WARNING: ignoring $check for test kind $kind")
250246
})
251247

252248
}
@@ -259,7 +255,7 @@ abstract class CompilerTest extends DottyTest {
259255
dest.parent.jfile.mkdirs
260256
FileManager.copyFile(sourceFile.jfile, dest.jfile)
261257
} else {
262-
NestUI.echoWarning(s"WARNING: ignoring $sf")
258+
log(s"WARNING: ignoring $sf")
263259
}
264260
}, { sdir =>
265261
dest.jfile.mkdirs
@@ -330,14 +326,28 @@ abstract class CompilerTest extends DottyTest {
330326
destDir.jfile
331327
}
332328

329+
/** Recursively deletes directories (and files). */
330+
private def deleteDir(dir: JFile): Unit = {
331+
val children = dir.listFiles
332+
if (children != null)
333+
children.foreach(deleteDir(_))
334+
dir.delete
335+
}
336+
337+
/** Write either to console (JUnit) or log file (partest). */
338+
private def log(msg: String) = logFile.map(_.appendAll(msg + "\n")).getOrElse(println(msg))
333339
}
334340

335341
object CompilerTest extends App {
336342

337-
/** Delete generated partest sources from a previous run. */
338-
lazy val init = {
343+
/** Deletes generated partest sources from a previous run, recreates
344+
* directory and returns the freshly created log file. */
345+
lazy val init: SFile = {
339346
scala.reflect.io.Directory(DPConfig.testRoot).deleteRecursively
340-
new java.io.File(DPConfig.testRoot).mkdirs
347+
new JFile(DPConfig.testRoot).mkdirs
348+
val log = (Path(DPConfig.testRoot) / Path("gen.log")).createFile(true)
349+
println(s"CompilerTest is generating tests for partest, log: $log")
350+
log
341351
}
342352

343353
// val dotcDir = "/Users/odersky/workspace/dotty/src/dotty/"

0 commit comments

Comments
 (0)