Skip to content

Commit 3e6fc39

Browse files
authored
Merge pull request #5852 from dotty-staging/fix-#5743
Fix #5743: Add check files to neg tests
2 parents 276d9af + 0d80546 commit 3e6fc39

File tree

17 files changed

+97
-25
lines changed

17 files changed

+97
-25
lines changed

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -616,23 +616,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
616616
else runMain(testSource.runClassPath) match {
617617
case Success(_) if !checkFile.isDefined || !checkFile.get.exists => // success!
618618
case Success(output) => {
619-
val outputLines = output.linesIterator.toArray :+ DiffUtil.EOF
620-
val checkLines: Array[String] = Source.fromFile(checkFile.get, "UTF-8").getLines().toArray :+ DiffUtil.EOF
619+
val outputLines = output.linesIterator.toSeq
620+
val checkLines: Seq[String] = Source.fromFile(checkFile.get, "UTF-8").getLines().toSeq
621621
val sourceTitle = testSource.title
622622

623-
def linesMatch =
624-
outputLines
625-
.zip(checkLines)
626-
.forall { case (x, y) => x == y }
623+
diffMessage(sourceTitle, outputLines, checkLines).foreach { msg =>
627624

628-
if (outputLines.length != checkLines.length || !linesMatch) {
629-
// Print diff to files and summary:
630-
val diff = DiffUtil.mkColoredLineDiff(checkLines, outputLines)
631-
632-
val msg =
633-
s"""|Output from '$sourceTitle' did not match check file.
634-
|Diff (expected on the left, actual right):
635-
|""".stripMargin + diff + "\n"
636625
echo(msg)
637626
addFailureInstruction(msg)
638627

@@ -765,13 +754,34 @@ trait ParallelTesting extends RunnerOrchestration { self =>
765754
}
766755
}
767756

757+
def fail(msg: String): Unit = {
758+
echo(msg)
759+
failTestSource(testSource)
760+
}
761+
762+
def reporterOutputLines(reporters: List[TestReporter]): List[String] = {
763+
reporters.flatMap(_.allErrors).sortBy(_.pos.source.toString).flatMap { error =>
764+
(error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().lines.toList
765+
}
766+
}
767+
def checkFileTest(sourceName: String, checkFile: JFile, actual: List[String]) = {
768+
val expexted = Source.fromFile(checkFile, "UTF-8").getLines().toList
769+
diffMessage(sourceName, actual, expexted).foreach(fail)
770+
}
771+
768772
val (compilerCrashed, expectedErrors, actualErrors, hasMissingAnnotations, errorMap) = testSource match {
769773
case testSource @ JointCompilationSource(_, files, flags, outDir, fromTasty, decompilation) =>
770774
val sourceFiles = testSource.sourceFiles
771775
val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(sourceFiles)
772776
val reporter = compile(sourceFiles, flags, true, outDir)
773777
val actualErrors = reporter.errorCount
774-
778+
files.foreach { file =>
779+
if (!file.isDirectory) {
780+
val checkFile = new JFile(file.getAbsolutePath.replaceFirst("\\.scala$", ".check"))
781+
if (checkFile.exists)
782+
checkFileTest(testSource.title, checkFile, reporterOutputLines(reporter :: Nil))
783+
}
784+
}
775785
if (reporter.compilerCrashed || actualErrors > 0)
776786
logReporterContents(reporter)
777787

@@ -788,14 +798,14 @@ trait ParallelTesting extends RunnerOrchestration { self =>
788798
if (actualErrors > 0)
789799
reporters.foreach(logReporterContents)
790800

801+
val checkFile = new JFile(dir.getAbsolutePath + ".check")
802+
if (checkFile.exists)
803+
checkFileTest(testSource.title, checkFile, reporterOutputLines(reporters))
804+
791805
(compilerCrashed, expectedErrors, actualErrors, () => getMissingExpectedErrors(errorMap, errors), errorMap)
792806
}
793807
}
794808

795-
def fail(msg: String): Unit = {
796-
echo(msg)
797-
failTestSource(testSource)
798-
}
799809

800810
if (compilerCrashed)
801811
fail(s"Compiler crashed when compiling: ${testSource.title}")
@@ -839,6 +849,22 @@ trait ParallelTesting extends RunnerOrchestration { self =>
839849
}
840850
}
841851

852+
def diffMessage(sourceTitle: String, outputLines: Seq[String], checkLines: Seq[String]): Option[String] = {
853+
def linesMatch =
854+
(outputLines, checkLines).zipped.forall(_ == _)
855+
856+
if (outputLines.length != checkLines.length || !linesMatch) {
857+
// Print diff to files and summary:
858+
val diff = DiffUtil.mkColoredLineDiff(checkLines :+ DiffUtil.EOF, outputLines :+ DiffUtil.EOF)
859+
860+
Some(
861+
s"""|Output from '$sourceTitle' did not match check file.
862+
|Diff (expected on the left, actual right):
863+
|""".stripMargin + diff + "\n")
864+
} else None
865+
866+
}
867+
842868
/** The `CompilationTest` is the main interface to `ParallelTesting`, it
843869
* can be instantiated via one of the following methods:
844870
*

tests/neg/classOf.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[181..202] in classOf.scala
2+
Test.C{I = String} is not a class type
3+
[116..117] in classOf.scala
4+
T is not a class type
5+
[72..73] in classOf.scala
6+
T is not a class type

tests/neg/i4382.check

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[199..207] in i4382.scala
2+
unreducible application of higher-kinded type App.HkAbs to wildcard arguments
3+
[149..155] in i4382.scala
4+
unreducible application of higher-kinded type App.HkU to wildcard arguments
5+
[97..103] in i4382.scala
6+
unreducible application of higher-kinded type App.HkL to wildcard arguments
7+
[46..51] in i4382.scala
8+
unreducible application of higher-kinded type App.Id to wildcard arguments

tests/neg/i5311.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<267..267> in i5311.scala
2+
Found: s.T[Int] => s.T[Int]
3+
Required: m.Foo

tests/neg/kinds2.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[123..124] in kinds2.scala
2+
missing type parameter(s) for C

tests/neg/multi-file-error.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[12..15] in A.scala
2+
Not found: foo
3+
[12..15] in B.scala
4+
Not found: bar

tests/neg/multi-file-error/A.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class A {
2+
foo() // error
3+
}

tests/neg/multi-file-error/B.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class B {
2+
bar() // error
3+
}

tests/neg/quote-error-2.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[48..51..58] in Test_2.scala
2+
foo cannot be called with false

tests/neg/quote-error.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[48..51..58] in Test_2.scala
2+
foo cannot be called with false

tests/neg/subtyping.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<230..230> in subtyping.scala
2+
Cannot prove that a.T <:< a.U..
3+
I found:
4+
5+
$conforms[Nothing]
6+
7+
But method $conforms in object Predef does not match type a.T <:< a.U.
8+
<106..106> in subtyping.scala
9+
Cannot prove that B#X <:< A#X..
10+
I found:
11+
12+
$conforms[Nothing]
13+
14+
But method $conforms in object Predef does not match type B#X <:< A#X.

tests/neg/t6663.check

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
t6663.scala:16: error: type mismatch;
2-
found : String
3-
required: Int
4-
var v = new C(42).foo[String].get :Int
5-
^
6-
one error found
1+
[473..495..498] in t6663.scala
2+
Found: String
3+
Required: Int

tests/pending/neg/kinds1.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[68..69] in kinds1.scala
2+
Type argument Test.C has not the same kind as its bound
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)