aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorvsalvis <salvisbergvera@gmail.com>2015-05-20 13:43:14 +0200
committervsalvis <salvisbergvera@gmail.com>2015-05-22 11:13:41 +0200
commitadfe78d740b2443dd09c9008c78bc98f0f3894a0 (patch)
treec3dbfb7098b1fa3f7ae2f08e6a23147d9f71277b /test
parented31c2a82d6b59ef092e17bd8811278f5ffd15e9 (diff)
downloaddotty-adfe78d740b2443dd09c9008c78bc98f0f3894a0.tar.gz
dotty-adfe78d740b2443dd09c9008c78bc98f0f3894a0.tar.bz2
dotty-adfe78d740b2443dd09c9008c78bc98f0f3894a0.zip
Update-check option for partest, added "do not edit" header
Diffstat (limited to 'test')
-rw-r--r--test/dotty/partest/DPConsoleRunner.scala54
-rwxr-xr-xtest/partest12
-rw-r--r--test/test/CompilerTest.scala31
3 files changed, 66 insertions, 31 deletions
diff --git a/test/dotty/partest/DPConsoleRunner.scala b/test/dotty/partest/DPConsoleRunner.scala
index b0d05f4bf..788abe0e1 100644
--- a/test/dotty/partest/DPConsoleRunner.scala
+++ b/test/dotty/partest/DPConsoleRunner.scala
@@ -39,13 +39,13 @@ object DPConsoleRunner {
// console runner has a suite runner which creates a test runner for each test
class DPConsoleRunner(args: String, extraJars: List[String]) extends ConsoleRunner(args) {
- println("ConsoleRunner options: " + args)
override val suiteRunner = new DPSuiteRunner (
testSourcePath = optSourcePath getOrElse DPConfig.testRoot,
fileManager = new DottyFileManager(extraJars),
updateCheck = optUpdateCheck,
- failed = optFailed)
+ failed = optFailed,
+ consoleArgs = args)
override def run = {}
def runPartest = super.run
@@ -62,6 +62,7 @@ class DPSuiteRunner(testSourcePath: String, // relative path, like "files", or "
fileManager: DottyFileManager,
updateCheck: Boolean,
failed: Boolean,
+ consoleArgs: String,
javaCmdPath: String = PartestDefaults.javaCmd,
javacCmdPath: String = PartestDefaults.javacCmd,
scalacExtraArgs: Seq[String] = Seq.empty)
@@ -76,9 +77,11 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
override def banner: String = {
s"""|Welcome to Partest for Dotty! Partest version: ${Properties.versionNumberString}
|Compiler under test: dotty.tools.dotc.Bench or dotty.tools.dotc.Main
- |Test root: ${PathSettings.srcDir}${File.separator}
+ |Generated test sources: ${PathSettings.srcDir}${File.separator}
|Test directories: ${DPConfig.testDirs.toList.mkString(", ")}
+ |Debugging: failed tests have compiler output in test-kind.clog, run output in test-kind.log, class files in test-kind.obj
|Parallel: ${DPConfig.runTestsInParallel}
+ |Options: (use partest --help for usage information) ${consoleArgs}
""".stripMargin
}
@@ -92,12 +95,13 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
// Parts of test output might end up in the wrong file or get lost.
Console.out.flush
Console.err.flush
- val clog = SFile(runner.logFile).changeExtension("clog")
+ val clog = runner.cLogFile
val stream = new PrintStream(new FileOutputStream(clog.jfile), true)
val result = Console.withOut(stream)({ Console.withErr(stream)({
- runner.run()
+ val res = runner.run()
Console.err.flush
Console.out.flush
+ res
})})
result match {
// Append compiler output to transcript if compilation failed,
@@ -117,6 +121,8 @@ extends SuiteRunner(testSourcePath, fileManager, updateCheck, failed, javaCmdPat
}
class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runner(testFile, suiteRunner) {
+ val cLogFile = SFile(logFile).changeExtension("clog")
+
// override to provide DottyCompiler
override def newCompiler = new dotty.partest.DPDirectCompiler(this)
@@ -199,6 +205,38 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
}
}
+ // override to change check file updating to original file, not generated
+ override def diffIsOk: Boolean = {
+ // always normalize the log first
+ normalizeLog()
+ val diff = currentDiff
+ // if diff is not empty, is update needed?
+ val updating: Option[Boolean] = (
+ if (diff == "") None
+ else Some(suiteRunner.updateCheck)
+ )
+ pushTranscript(s"diff $logFile $checkFile")
+ nextTestAction(updating) {
+ case Some(true) =>
+ val origCheck = SFile(checkFile.changeExtension("checksrc").fileLines(1))
+ NestUI.echo("Updating original checkfile " + origCheck)
+ origCheck writeAll file2String(logFile)
+ genUpdated()
+ case Some(false) =>
+ // Get a word-highlighted diff from git if we can find it
+ val bestDiff = if (updating.isEmpty) "" else {
+ if (checkFile.canRead)
+ gitDiff(logFile, checkFile) getOrElse {
+ s"diff $logFile $checkFile\n$diff"
+ }
+ else diff
+ }
+ pushTranscript(bestDiff)
+ genFail("output differs")
+ case None => genPass() // redundant default case
+ } getOrElse true
+ }
+
// override because Dotty currently doesn't handle separate compilation well,
// so we ignore groups (tests suffixed with _1 and _2)
override def groupedFiles(sources: List[File]): List[List[File]] = {
@@ -223,4 +261,10 @@ class DPTestRunner(testFile: File, suiteRunner: DPSuiteRunner) extends nest.Runn
// override to add dotty and scala jars to classpath
override def extraClasspath = suiteRunner.fileManager.asInstanceOf[DottyFileManager].extraJarList ::: super.extraClasspath
+ // override to keep class files if failed and delete clog if ok
+ override def cleanup = if (lastState.isOk) {
+ logFile.delete
+ cLogFile.delete
+ Directory(outDir).deleteRecursively
+ }
}
diff --git a/test/partest b/test/partest
index 5794e2e57..0ac50aa8e 100755
--- a/test/partest
+++ b/test/partest
@@ -1,12 +1,4 @@
#!/usr/bin/env bash
-# partest error message references partest script to update check files, but
-# doesn't work for dotty because we don't know where tests came from.
+# partest error message references partest script to update check files
-if [ $1='--update-check' ];
-then
- echo """ERROR: Since dotty partest runs on generated files, please update the check
-files in the original location (run tests) or update the expected error count
-(neg tests) in the test file."
-else
- echo "This script doesn't launch partest, please use sbt partest instead."
-fi \ No newline at end of file
+exec sbt "partest-only $*"
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala
index 36a1b9d34..4a8ec6da0 100644
--- a/test/test/CompilerTest.scala
+++ b/test/test/CompilerTest.scala
@@ -101,7 +101,7 @@ abstract class CompilerTest extends DottyTest {
}
}
}
- def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
+ def runFile(prefix: String, fileName: String, args: List[String] = Nil, xerrors: Int = 0,
extension: String = ".scala")(implicit defaultOptions: List[String]): Unit =
compileFile(prefix, fileName, args, xerrors, extension, true)
@@ -131,7 +131,7 @@ abstract class CompilerTest extends DottyTest {
val firstDest = Directory(DPConfig.testRoot + JFile.separator + kind + JFile.separator + dirName)
computeDestAndCopyFiles(sourceDir, firstDest, kind, flags, xerrors.toString)
if (deep == "deep")
- deleteDir(sourceDir)
+ Directory(sourceDir).deleteRecursively
} else {
throw new java.io.FileNotFoundException(s"Unable to locate test dir $prefix$dirName")
}
@@ -172,7 +172,7 @@ abstract class CompilerTest extends DottyTest {
recCopyFiles(jfile, destDir / jfile.getName)
})
compileDir(DPConfig.testRoot + JFile.separator, testName, args, xerrors)
- deleteDir(destDir.jfile)
+ destDir.deleteRecursively
}
}
@@ -186,14 +186,14 @@ abstract class CompilerTest extends DottyTest {
}
// In particular, don't copy flags from scalac tests
- private val extensionsToCopy = scala.collection.immutable.HashSet("scala", "java", "check")
+ private val extensionsToCopy = scala.collection.immutable.HashSet("scala", "java")
/** Determines what kind of test to run. */
private def testKind(prefixDir: String, xerrors: Int, runTest: Boolean) = {
if (runTest) "run"
else if (xerrors > 0) "neg"
else if (prefixDir.endsWith("run" + JFile.separator)) {
- log("WARNING: test is being run as pos test despite being in a run directory. " +
+ log("WARNING: test is being run as pos test despite being in a run directory. " +
"Use runFile/runDir instead of compileFile/compileDir to do a run test")
"pos"
} else "pos"
@@ -239,10 +239,12 @@ abstract class CompilerTest extends DottyTest {
if (nerr != "0")
dest.changeExtension("nerr").createFile(true).writeAll(nerr)
sourceFile.changeExtension("check").ifFile({ check =>
- if (kind == "run")
+ if (kind == "run") {
FileManager.copyFile(check.jfile, dest.changeExtension("check").jfile)
- else
+ dest.changeExtension("checksrc").createFile(true).writeAll("check file generated from source:\n" + check.toString)
+ } else {
log(s"WARNING: ignoring $check for test kind $kind")
+ }
})
}
@@ -253,7 +255,12 @@ abstract class CompilerTest extends DottyTest {
processFileDir(sourceFile, { sf =>
if (extensionsToCopy.contains(sf.extension)) {
dest.parent.jfile.mkdirs
- FileManager.copyFile(sourceFile.jfile, dest.jfile)
+ dest.toFile.writeAll("/* ==========================================\n",
+ " * ========= AUTOMATICALLY GENERATED ========\n",
+ " * ========= DO NOT EDIT THIS FILE ==========\n",
+ " * ==========================================\n",
+ " * Original: " + sf.toString + " */\n\n",
+ sf.slurp())
} else {
log(s"WARNING: ignoring $sf")
}
@@ -326,14 +333,6 @@ abstract class CompilerTest extends DottyTest {
destDir.jfile
}
- /** Recursively deletes directories (and files). */
- private def deleteDir(dir: JFile): Unit = {
- val children = dir.listFiles
- if (children != null)
- children.foreach(deleteDir(_))
- dir.delete
- }
-
/** Write either to console (JUnit) or log file (partest). */
private def log(msg: String) = logFile.map(_.appendAll(msg + "\n")).getOrElse(println(msg))
}