@@ -304,14 +304,33 @@ class Pickler extends Phase {
304304 | diff before-pickling.txt after-pickling.txt """ )
305305 end testSame
306306
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
307+ private def testSamePrinted (printed : String , checkContents : String , cls : ClassSymbol , check : AbstractFile )(using Context ): Unit = {
308+ if hasDiff(printed, checkContents) then
312309 output(" after-printing.txt" , printed)
313310 report.error(em """ TASTy printer difference for $cls in ${cls.source}, for details:
314311 |
315312 | diff ${check.toString} after-printing.txt """ )
316- end testSamePrinted
313+ }
314+
315+ /** Reuse diff logic from compiler/test/dotty/tools/vulpix/FileDiff.scala */
316+ private def hasDiff (actual : String , expect : String ): Boolean =
317+ import scala .util .Using
318+ import scala .io .Source
319+ val actualLines = Using (Source .fromString(actual))(_.getLines().toList).get
320+ val expectLines = Using (Source .fromString(expect))(_.getLines().toList).get
321+ ! matches(actualLines, expectLines)
322+
323+ private def matches (actual : String , expect : String ): Boolean = {
324+ import java .io .File
325+ val actual1 = actual.stripLineEnd
326+ val expect1 = expect.stripLineEnd
327+
328+ // handle check file path mismatch on windows
329+ actual1 == expect1 || File .separatorChar == '\\ ' && actual1.replace('\\ ' , '/' ) == expect1
330+ }
331+
332+ private def matches (actual : Seq [String ], expect : Seq [String ]): Boolean = {
333+ actual.length == expect.length
334+ && actual.lazyZip(expect).forall(matches)
335+ }
317336}
0 commit comments