Skip to content

Commit 23e3a63

Browse files
som-snyttlrytz
authored andcommitted
Issue #25 use filtered check for git diff
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 ```
1 parent c827629 commit 23e3a63

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

src/partest/scala/tools/partest/nest/FileManager.scala

+15-8
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,9 @@ package nest
1010

1111
import java.io.{
1212
File,
13-
FilenameFilter,
1413
IOException,
15-
StringWriter,
16-
FileInputStream,
17-
FileOutputStream,
18-
BufferedReader,
19-
FileReader,
20-
PrintWriter,
21-
FileWriter
14+
OutputStreamWriter,
15+
FileOutputStream
2216
}
2317
import java.net.URI
2418
import scala.reflect.io.AbstractFile
@@ -98,6 +92,19 @@ object FileManager {
9892
if (diff.getDeltas.isEmpty) ""
9993
else difflib.DiffUtils.generateUnifiedDiff(originalName, revisedName, original.asJava, diff, 1).asScala.mkString("\n")
10094
}
95+
96+
def withTempFile[A](outFile: File, fileBase: String, lines: Seq[String])(body: File => A): A = {
97+
val prefix = s"tmp-$fileBase"
98+
val suffix = ".check"
99+
val f = File.createTempFile(prefix, suffix, outFile)
100+
try {
101+
import scala.reflect.io.{ File => Feil }
102+
Feil(f).writeAll(lines map (line => f"$line%n"): _*)
103+
body(f)
104+
} finally {
105+
f.delete()
106+
}
107+
}
101108
}
102109

103110
class FileManager(val testClassLoader: URLClassLoader) {

src/partest/scala/tools/partest/nest/Runner.scala

+7-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ import scala.reflect.internal.util.ScalaClassLoader
1818
import scala.sys.process.{ Process, ProcessLogger }
1919
import scala.tools.nsc.Properties.{ envOrNone, isWin, jdkHome, javaHome, propOrEmpty, setProp, versionMsg, javaVmName, javaVmVersion, javaVmInfo }
2020
import scala.tools.nsc.{ Settings, CompilerCommand, Global }
21-
import scala.tools.nsc.io.{ AbstractFile }
2221
import scala.tools.nsc.reporters.ConsoleReporter
2322
import scala.tools.nsc.util.{ Exceptional, stackTraceString }
2423
import scala.util.{ Try, Success, Failure }
2524
import ClassPath.{ join, split }
2625
import TestState.{ Pass, Fail, Crash, Uninitialized, Updated }
2726

28-
import FileManager.{compareFiles, compareContents, joinPaths}
27+
import FileManager.{ compareFiles, compareContents, joinPaths, withTempFile }
2928

3029
class TestTranscript {
3130
import NestUI.color._
@@ -375,13 +374,13 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
375374
genUpdated()
376375
case Some(false) =>
377376
// Get a word-highlighted diff from git if we can find it
378-
val bestDiff = if (updating.isEmpty) "" else {
379-
if (checkFile.canRead)
380-
gitDiff(logFile, checkFile) getOrElse {
381-
s"diff $logFile $checkFile\n$diff"
377+
val bestDiff =
378+
if (updating.isEmpty) ""
379+
else if (checkFile.canRead)
380+
withTempFile(outFile, fileBase, filteredCheck) { f =>
381+
gitDiff(logFile, f) getOrElse f"diff $logFile $checkFile%n$diff"
382382
}
383383
else diff
384-
}
385384
_transcript append bestDiff
386385
genFail("output differs")
387386
// TestState.fail("output differs", "output differs",
@@ -606,7 +605,7 @@ class Runner(val testFile: File, val suiteRunner: SuiteRunner) {
606605
val prompt = "\nnsc> "
607606
val (swr, wr) = newTestWriters()
608607

609-
NestUI.verbose(this+" running test "+fileBase)
608+
NestUI.verbose(s"$this running test $fileBase")
610609
val dir = parentFile
611610
val resFile = new File(dir, fileBase + ".res")
612611

0 commit comments

Comments
 (0)