@@ -58,7 +58,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
58
58
def flags : TestFlags
59
59
def sourceFiles : Array [JFile ]
60
60
61
- def runClassPath : String = outDir.getAbsolutePath + JFile .pathSeparator + flags.runClassPath
61
+ def runClassPath : String = outDir.getPath + JFile .pathSeparator + flags.runClassPath
62
62
63
63
def title : String = self match {
64
64
case self : JointCompilationSource =>
@@ -86,16 +86,18 @@ trait ParallelTesting extends RunnerOrchestration { self =>
86
86
val sb = new StringBuilder
87
87
val maxLen = 80
88
88
var lineLen = 0
89
+ val delimiter = " "
89
90
90
91
sb.append(
91
92
s """ |
92
93
|Test ' $title' compiled with $errors error(s) and $warnings warning(s),
93
- |the test can be reproduced by running: """ .stripMargin
94
+ |the test can be reproduced by running from SBT (prefix it with ./bin/ if you
95
+ |want to run from the command line): """ .stripMargin
94
96
)
95
- sb.append(" \n\n ./bin/dotc " )
97
+ sb.append(" \n\n dotc " )
96
98
flags.all.foreach { arg =>
97
99
if (lineLen > maxLen) {
98
- sb.append(" \\\n " )
100
+ sb.append(delimiter )
99
101
lineLen = 4
100
102
}
101
103
sb.append(arg)
@@ -105,8 +107,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
105
107
106
108
self match {
107
109
case source : JointCompilationSource => {
108
- source.sourceFiles.map(_.getAbsolutePath ).foreach { path =>
109
- sb.append(" \\\n " )
110
+ source.sourceFiles.map(_.getPath ).foreach { path =>
111
+ sb.append(delimiter )
110
112
sb.append(path)
111
113
sb += ' '
112
114
}
@@ -117,7 +119,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
117
119
val fsb = new StringBuilder (command)
118
120
self.compilationGroups.foreach { files =>
119
121
files.map(_.getPath).foreach { path =>
120
- fsb.append(" \\\n " )
122
+ fsb.append(delimiter )
121
123
lineLen = 8
122
124
fsb.append(path)
123
125
fsb += ' '
@@ -215,21 +217,20 @@ trait ParallelTesting extends RunnerOrchestration { self =>
215
217
*/
216
218
final def checkFile (testSource : TestSource ): Option [JFile ] = (testSource match {
217
219
case ts : JointCompilationSource =>
218
- ts.files.collectFirst { case f if ! f.isDirectory => new JFile (f.getAbsolutePath .replaceFirst(" \\ .scala$" , " .check" )) }
220
+ ts.files.collectFirst { case f if ! f.isDirectory => new JFile (f.getPath .replaceFirst(" \\ .scala$" , " .check" )) }
219
221
220
222
case ts : SeparateCompilationSource =>
221
- Option (new JFile (ts.dir.getAbsolutePath + " .check" ))
223
+ Option (new JFile (ts.dir.getPath + " .check" ))
222
224
}).filter(_.exists)
223
225
224
226
/**
225
227
* Checks if the given actual lines are the same as the ones in the check file.
226
228
* If not, fails the test.
227
229
*/
228
- final def diffTest (testSource : TestSource , checkFile : JFile , actual : List [String ]) = {
230
+ final def diffTest (testSource : TestSource , checkFile : JFile , actual : List [String ], reporters : Seq [ TestReporter ], logger : LoggedRunnable ) = {
229
231
val expected = Source .fromFile(checkFile, " UTF-8" ).getLines().toList
230
232
for (msg <- diffMessage(testSource.title, actual, expected)) {
231
- echo(msg)
232
- failTestSource(testSource)
233
+ onFailure(testSource, reporters, logger, Some (msg))
233
234
dumpOutputToFile(checkFile, actual)
234
235
}
235
236
}
@@ -318,9 +319,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
318
319
if (! testFilter.isDefined) testSources
319
320
else testSources.filter {
320
321
case JointCompilationSource (_, files, _, _, _, _) =>
321
- files.exists(file => file.getAbsolutePath .contains(testFilter.get))
322
+ files.exists(file => file.getPath .contains(testFilter.get))
322
323
case SeparateCompilationSource (_, dir, _, _) =>
323
- dir.getAbsolutePath .contains(testFilter.get)
324
+ dir.getPath .contains(testFilter.get)
324
325
}
325
326
326
327
/** Total amount of test sources being compiled by this test */
@@ -422,9 +423,8 @@ trait ParallelTesting extends RunnerOrchestration { self =>
422
423
}
423
424
424
425
protected def compile (files0 : Array [JFile ], flags0 : TestFlags , suppressErrors : Boolean , targetDir : JFile ): TestReporter = {
425
-
426
- val flags = flags0.and(" -d" , targetDir.getAbsolutePath)
427
- .withClasspath(targetDir.getAbsolutePath)
426
+ val flags = flags0.and(" -d" , targetDir.getPath)
427
+ .withClasspath(targetDir.getPath)
428
428
429
429
def flattenFiles (f : JFile ): Array [JFile ] =
430
430
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
@@ -468,10 +468,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
468
468
469
469
// If a test contains a Java file that cannot be parsed by Dotty's Java source parser, its
470
470
// name must contain the string "JAVA_ONLY".
471
- val dottyFiles = files.filterNot(_.getName.contains(" JAVA_ONLY" )).map(_.getAbsolutePath )
471
+ val dottyFiles = files.filterNot(_.getName.contains(" JAVA_ONLY" )).map(_.getPath )
472
472
driver.process(allArgs ++ dottyFiles, reporter = reporter)
473
473
474
- val javaFiles = files.filter(_.getName.endsWith(" .java" )).map(_.getAbsolutePath )
474
+ val javaFiles = files.filter(_.getName.endsWith(" .java" )).map(_.getPath )
475
475
val javaErrors = compileWithJavac(javaFiles)
476
476
477
477
if (javaErrors.isDefined) {
@@ -485,7 +485,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
485
485
protected def compileFromTasty (flags0 : TestFlags , suppressErrors : Boolean , targetDir : JFile ): TestReporter = {
486
486
val tastyOutput = new JFile (targetDir.getPath + " _from-tasty" )
487
487
tastyOutput.mkdir()
488
- val flags = flags0 and (" -d" , tastyOutput.getAbsolutePath ) and " -from-tasty"
488
+ val flags = flags0 and (" -d" , tastyOutput.getPath ) and " -from-tasty"
489
489
490
490
def tastyFileToClassName (f : JFile ): String = {
491
491
val pathStr = targetDir.toPath.relativize(f.toPath).toString.replace(JFile .separatorChar, '.' )
@@ -609,11 +609,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
609
609
}
610
610
}
611
611
612
- private def verifyOutput (checkFile : Option [JFile ], dir : JFile , testSource : TestSource , warnings : Int ) = {
612
+ private def verifyOutput (checkFile : Option [JFile ], dir : JFile , testSource : TestSource , warnings : Int , reporters : Seq [ TestReporter ], logger : LoggedRunnable ) = {
613
613
if (Properties .testsNoRun) addNoRunWarning()
614
614
else runMain(testSource.runClassPath) match {
615
615
case Success (output) => checkFile match {
616
- case Some (file) if file.exists => diffTest(testSource, file, output.linesIterator.toList)
616
+ case Some (file) if file.exists => diffTest(testSource, file, output.linesIterator.toList, reporters, logger )
617
617
case _ =>
618
618
}
619
619
case Failure (output) =>
@@ -627,7 +627,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
627
627
}
628
628
629
629
override def onSuccess (testSource : TestSource , reporters : Seq [TestReporter ], logger : LoggedRunnable ) =
630
- verifyOutput(checkFile(testSource), testSource.outDir, testSource, countWarnings(reporters))
630
+ verifyOutput(checkFile(testSource), testSource.outDir, testSource, countWarnings(reporters), reporters, logger )
631
631
}
632
632
633
633
private final class NegTest (testSources : List [TestSource ], times : Int , threadLimit : Option [Int ], suppressAllOutput : Boolean )(implicit summaryReport : SummaryReporting )
@@ -649,11 +649,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
649
649
}
650
650
651
651
override def onSuccess (testSource : TestSource , reporters : Seq [TestReporter ], logger : LoggedRunnable ): Unit =
652
- checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters)))
652
+ checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger ))
653
653
654
654
def reporterOutputLines (reporters : Seq [TestReporter ]): List [String ] =
655
- reporters.flatMap(_.allErrors).sortBy(_.pos.source.toString).flatMap { error =>
656
- (error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().linesIterator.toList }.toList
655
+ reporters.flatMap(_.consoleOutput.split(" \n " )).toList
657
656
658
657
// In neg-tests we allow two types of error annotations,
659
658
// "nopos-error" which doesn't care about position and "error" which
@@ -668,7 +667,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
668
667
Source .fromFile(file, " UTF-8" ).getLines().zipWithIndex.foreach { case (line, lineNbr) =>
669
668
val errors = line.sliding(" // error" .length).count(_.mkString == " // error" )
670
669
if (errors > 0 )
671
- errorMap.put(s " ${file.getAbsolutePath }: ${lineNbr}" , errors)
670
+ errorMap.put(s " ${file.getPath }: ${lineNbr}" , errors)
672
671
673
672
val noposErrors = line.sliding(" // nopos-error" .length).count(_.mkString == " // nopos-error" )
674
673
if (noposErrors > 0 ) {
@@ -686,7 +685,9 @@ trait ParallelTesting extends RunnerOrchestration { self =>
686
685
687
686
def getMissingExpectedErrors (errorMap : HashMap [String , Integer ], reporterErrors : Iterator [MessageContainer ]) = ! reporterErrors.forall { error =>
688
687
val key = if (error.pos.exists) {
689
- val fileName = error.pos.source.file.toString
688
+ def toRelative (path : String ): String = // For some reason, absolute paths leak from the compiler itself...
689
+ path.split(" /" ).dropWhile(_ != " tests" ).mkString(" /" )
690
+ val fileName = toRelative(error.pos.source.file.toString)
690
691
s " $fileName: ${error.pos.line}"
691
692
692
693
} else " nopos"
@@ -715,16 +716,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
715
716
def linesMatch =
716
717
(outputLines, checkLines).zipped.forall(_ == _)
717
718
718
- if (outputLines.length != checkLines.length || ! linesMatch) {
719
- // Print diff to files and summary:
720
- val diff = DiffUtil .mkColoredLineDiff(checkLines :+ DiffUtil .EOF , outputLines :+ DiffUtil .EOF )
721
-
722
- Some (
723
- s """ |Output from ' $sourceTitle' did not match check file.
724
- |Diff (expected on the left, actual right):
725
- | """ .stripMargin + diff + " \n " )
726
- } else None
727
-
719
+ if (outputLines.length != checkLines.length || ! linesMatch) Some (
720
+ s """ |Output from ' $sourceTitle' did not match check file. Actual output:
721
+ | ${outputLines.mkString(EOL )}
722
+ | """ .stripMargin + " \n " )
723
+ else None
728
724
}
729
725
730
726
/** The `CompilationTest` is the main interface to `ParallelTesting`, it
@@ -943,7 +939,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
943
939
* and if so copying recursively
944
940
*/
945
941
private def copyToDir (dir : JFile , file : JFile ): JFile = {
946
- val target = Paths .get(dir.getAbsolutePath , file.getName)
942
+ val target = Paths .get(dir.getPath , file.getName)
947
943
Files .copy(file.toPath, target, REPLACE_EXISTING )
948
944
if (file.isDirectory) file.listFiles.map(copyToDir(target.toFile, _))
949
945
target.toFile
@@ -1221,7 +1217,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
1221
1217
val (dirs, files) = compilationTargets(sourceDir, fromTastyFilter)
1222
1218
1223
1219
val filteredFiles = testFilter match {
1224
- case Some (str) => files.filter(_.getAbsolutePath .contains(str))
1220
+ case Some (str) => files.filter(_.getPath .contains(str))
1225
1221
case None => files
1226
1222
}
1227
1223
0 commit comments