Skip to content

Fix #5743: Add check files to neg tests #5852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -616,23 +616,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
else runMain(testSource.runClassPath) match {
case Success(_) if !checkFile.isDefined || !checkFile.get.exists => // success!
case Success(output) => {
val outputLines = output.linesIterator.toArray :+ DiffUtil.EOF
val checkLines: Array[String] = Source.fromFile(checkFile.get, "UTF-8").getLines().toArray :+ DiffUtil.EOF
val outputLines = output.linesIterator.toSeq
val checkLines: Seq[String] = Source.fromFile(checkFile.get, "UTF-8").getLines().toSeq
val sourceTitle = testSource.title

def linesMatch =
outputLines
.zip(checkLines)
.forall { case (x, y) => x == y }
diffMessage(sourceTitle, outputLines, checkLines).foreach { msg =>

if (outputLines.length != checkLines.length || !linesMatch) {
// Print diff to files and summary:
val diff = DiffUtil.mkColoredLineDiff(checkLines, outputLines)

val msg =
s"""|Output from '$sourceTitle' did not match check file.
|Diff (expected on the left, actual right):
|""".stripMargin + diff + "\n"
echo(msg)
addFailureInstruction(msg)

Expand Down Expand Up @@ -765,13 +754,34 @@ trait ParallelTesting extends RunnerOrchestration { self =>
}
}

def fail(msg: String): Unit = {
echo(msg)
failTestSource(testSource)
}

def reporterOutputLines(reporters: List[TestReporter]): List[String] = {
reporters.flatMap(_.allErrors).sortBy(_.pos.source.toString).flatMap { error =>
(error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().lines.toList
}
}
def checkFileTest(sourceName: String, checkFile: JFile, actual: List[String]) = {
val expexted = Source.fromFile(checkFile, "UTF-8").getLines().toList
diffMessage(sourceName, actual, expexted).foreach(fail)
}

val (compilerCrashed, expectedErrors, actualErrors, hasMissingAnnotations, errorMap) = testSource match {
case testSource @ JointCompilationSource(_, files, flags, outDir, fromTasty, decompilation) =>
val sourceFiles = testSource.sourceFiles
val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(sourceFiles)
val reporter = compile(sourceFiles, flags, true, outDir)
val actualErrors = reporter.errorCount

files.foreach { file =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourceFiles? => no special case for directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the way it works for pos and run tests.

if (!file.isDirectory) {
val checkFile = new JFile(file.getAbsolutePath.replaceFirst("\\.scala$", ".check"))
if (checkFile.exists)
checkFileTest(testSource.title, checkFile, reporterOutputLines(reporter :: Nil))
}
}
if (reporter.compilerCrashed || actualErrors > 0)
logReporterContents(reporter)

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

val checkFile = new JFile(dir.getAbsolutePath + ".check")
if (checkFile.exists)
checkFileTest(testSource.title, checkFile, reporterOutputLines(reporters))

(compilerCrashed, expectedErrors, actualErrors, () => getMissingExpectedErrors(errorMap, errors), errorMap)
}
}

def fail(msg: String): Unit = {
echo(msg)
failTestSource(testSource)
}

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

def diffMessage(sourceTitle: String, outputLines: Seq[String], checkLines: Seq[String]): Option[String] = {
def linesMatch =
(outputLines, checkLines).zipped.forall(_ == _)

if (outputLines.length != checkLines.length || !linesMatch) {
// Print diff to files and summary:
val diff = DiffUtil.mkColoredLineDiff(checkLines :+ DiffUtil.EOF, outputLines :+ DiffUtil.EOF)

Some(
s"""|Output from '$sourceTitle' did not match check file.
|Diff (expected on the left, actual right):
|""".stripMargin + diff + "\n")
} else None

}

/** The `CompilationTest` is the main interface to `ParallelTesting`, it
* can be instantiated via one of the following methods:
*
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/classOf.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[181..202] in classOf.scala
Test.C{I = String} is not a class type
[116..117] in classOf.scala
T is not a class type
[72..73] in classOf.scala
T is not a class type
8 changes: 8 additions & 0 deletions tests/neg/i4382.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[199..207] in i4382.scala
unreducible application of higher-kinded type App.HkAbs to wildcard arguments
[149..155] in i4382.scala
unreducible application of higher-kinded type App.HkU to wildcard arguments
[97..103] in i4382.scala
unreducible application of higher-kinded type App.HkL to wildcard arguments
[46..51] in i4382.scala
unreducible application of higher-kinded type App.Id to wildcard arguments
3 changes: 3 additions & 0 deletions tests/neg/i5311.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<267..267> in i5311.scala
Found: s.T[Int] => s.T[Int]
Required: m.Foo
2 changes: 2 additions & 0 deletions tests/neg/kinds2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[123..124] in kinds2.scala
missing type parameter(s) for C
4 changes: 4 additions & 0 deletions tests/neg/multi-file-error.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[12..15] in A.scala
Not found: foo
[12..15] in B.scala
Not found: bar
3 changes: 3 additions & 0 deletions tests/neg/multi-file-error/A.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class A {
foo() // error
}
3 changes: 3 additions & 0 deletions tests/neg/multi-file-error/B.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class B {
bar() // error
}
2 changes: 2 additions & 0 deletions tests/neg/quote-error-2.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[48..51..58] in Test_2.scala
foo cannot be called with false
2 changes: 2 additions & 0 deletions tests/neg/quote-error.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[48..51..58] in Test_2.scala
foo cannot be called with false
14 changes: 14 additions & 0 deletions tests/neg/subtyping.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<230..230> in subtyping.scala
Cannot prove that a.T <:< a.U..
I found:

$conforms[Nothing]

But method $conforms in object Predef does not match type a.T <:< a.U.
<106..106> in subtyping.scala
Cannot prove that B#X <:< A#X..
I found:

$conforms[Nothing]

But method $conforms in object Predef does not match type B#X <:< A#X.
9 changes: 3 additions & 6 deletions tests/neg/t6663.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
t6663.scala:16: error: type mismatch;
found : String
required: Int
var v = new C(42).foo[String].get :Int
^
one error found
[473..495..498] in t6663.scala
Found: String
Required: Int
2 changes: 2 additions & 0 deletions tests/pending/neg/kinds1.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[68..69] in kinds1.scala
Type argument Test.C has not the same kind as its bound
File renamed without changes.
File renamed without changes.
File renamed without changes.