Skip to content

Commit

Permalink
Issue scala#25 use filtered check for git diff
Browse files Browse the repository at this point in the history
Unlike normal diff, the git diff feature wasn't using the filtered
check file under `--show-diff`.

Now the sample displays just the bad line.

```
!! 1 - neg/t7494-no-options                      [output differs]
% diff /home/apm/projects/snytt/test/files/neg/t7494-no-options-neg.log /home/apm/projects/snytt/test/files/neg/t7494-no-options.check
@@ -1,7 +1,7 @@
 error: Error: ploogin takes no options
     phase name  id  description
     ----------  --  -----------
-        parser   1  parse source into ASTs, perform simple desugaring
+        parser   0  parse source into ASTs, perform simple desugaring
          namer   2  resolve names, attach symbols to named trees
 packageobjects   3  load package objects
          typer   4  the meat and potatoes: type the trees
```
  • Loading branch information
som-snytt authored and lrytz committed May 9, 2018
1 parent c827629 commit 23e3a63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
23 changes: 15 additions & 8 deletions src/partest/scala/tools/partest/nest/FileManager.scala
Expand Up @@ -10,15 +10,9 @@ package nest

import java.io.{
File,
FilenameFilter,
IOException,
StringWriter,
FileInputStream,
FileOutputStream,
BufferedReader,
FileReader,
PrintWriter,
FileWriter
OutputStreamWriter,
FileOutputStream
}
import java.net.URI
import scala.reflect.io.AbstractFile
Expand Down Expand Up @@ -98,6 +92,19 @@ object FileManager {
if (diff.getDeltas.isEmpty) ""
else difflib.DiffUtils.generateUnifiedDiff(originalName, revisedName, original.asJava, diff, 1).asScala.mkString("\n")
}

def withTempFile[A](outFile: File, fileBase: String, lines: Seq[String])(body: File => A): A = {
val prefix = s"tmp-$fileBase"
val suffix = ".check"
val f = File.createTempFile(prefix, suffix, outFile)
try {
import scala.reflect.io.{ File => Feil }
Feil(f).writeAll(lines map (line => f"$line%n"): _*)
body(f)
} finally {
f.delete()
}
}
}

class FileManager(val testClassLoader: URLClassLoader) {
Expand Down
15 changes: 7 additions & 8 deletions src/partest/scala/tools/partest/nest/Runner.scala
Expand Up @@ -18,14 +18,13 @@ import scala.reflect.internal.util.ScalaClassLoader
import scala.sys.process.{ Process, ProcessLogger }
import scala.tools.nsc.Properties.{ envOrNone, isWin, jdkHome, javaHome, propOrEmpty, setProp, versionMsg, javaVmName, javaVmVersion, javaVmInfo }
import scala.tools.nsc.{ Settings, CompilerCommand, Global }
import scala.tools.nsc.io.{ AbstractFile }
import scala.tools.nsc.reporters.ConsoleReporter
import scala.tools.nsc.util.{ Exceptional, stackTraceString }
import scala.util.{ Try, Success, Failure }
import ClassPath.{ join, split }
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }

import FileManager.{compareFiles, compareContents, joinPaths}
import FileManager.{ compareFiles, compareContents, joinPaths, withTempFile }

class TestTranscript {
import NestUI.color._
Expand Down Expand Up @@ -375,13 +374,13 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
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"
val bestDiff =
if (updating.isEmpty) ""
else if (checkFile.canRead)
withTempFile(outFile, fileBase, filteredCheck) { f =>
gitDiff(logFile, f) getOrElse f"diff $logFile $checkFile%n$diff"
}
else diff
}
_transcript append bestDiff
genFail("output differs")
// TestState.fail("output differs", "output differs",
Expand Down Expand Up @@ -606,7 +605,7 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
val prompt = "\nnsc> "
val (swr, wr) = newTestWriters()

NestUI.verbose(this+" running test "+fileBase)
NestUI.verbose(s"$this running test $fileBase")
val dir = parentFile
val resFile = new File(dir, fileBase + ".res")

Expand Down

0 comments on commit 23e3a63

Please sign in to comment.