Skip to content

Commit 3adcf86

Browse files
committed
check lines not whole file
1 parent 090b647 commit 3adcf86

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

compiler/src/dotty/tools/dotc/transform/Pickler.scala

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import compiletime.uninitialized
2222
import dotty.tools.io.{JarArchive, AbstractFile}
2323
import dotty.tools.dotc.printing.OutlinePrinter
2424
import scala.annotation.constructorOnly
25+
import java.nio.charset.StandardCharsets
2526

2627
object Pickler {
2728
val name: String = "pickler"
@@ -304,14 +305,33 @@ class Pickler extends Phase {
304305
| diff before-pickling.txt after-pickling.txt""")
305306
end testSame
306307

307-
private def testSamePrinted(printed: String, checkContents: String, cls: ClassSymbol, check: AbstractFile)(using Context) =
308-
import java.nio.charset.StandardCharsets.UTF_8
309-
def normal(s: String) = new String(s.getBytes(UTF_8), UTF_8)
310-
val unequal = printed.length() != checkContents.length() || normal(printed) != normal(checkContents)
311-
if unequal then
308+
private def testSamePrinted(printed: String, checkContents: String, cls: ClassSymbol, check: AbstractFile)(using Context): Unit = {
309+
if hasDiff(printed, checkContents) then
312310
output("after-printing.txt", printed)
313311
report.error(em"""TASTy printer difference for $cls in ${cls.source}, for details:
314312
|
315313
| diff ${check.toString} after-printing.txt""")
316-
end testSamePrinted
314+
}
315+
316+
/** Reuse diff logic from compiler/test/dotty/tools/vulpix/FileDiff.scala */
317+
private def hasDiff(actual: String, expect: String): Boolean =
318+
import scala.util.Using
319+
import scala.io.Source
320+
val actualLines = Using(Source.fromString(actual))(_.getLines().toList).get
321+
val expectLines = Using(Source.fromString(expect))(_.getLines().toList).get
322+
!matches(actualLines, expectLines)
323+
324+
private def matches(actual: String, expect: String): Boolean = {
325+
import java.io.File
326+
val actual1 = actual.stripLineEnd
327+
val expect1 = expect.stripLineEnd
328+
329+
// handle check file path mismatch on windows
330+
actual1 == expect1 || File.separatorChar == '\\' && actual1.replace('\\', '/') == expect1
331+
}
332+
333+
private def matches(actual: Seq[String], expect: Seq[String]): Boolean = {
334+
actual.length == expect.length
335+
&& actual.lazyZip(expect).forall(matches)
336+
}
317337
}

0 commit comments

Comments
 (0)