@@ -22,6 +22,7 @@ import compiletime.uninitialized
22
22
import dotty .tools .io .{JarArchive , AbstractFile }
23
23
import dotty .tools .dotc .printing .OutlinePrinter
24
24
import scala .annotation .constructorOnly
25
+ import java .nio .charset .StandardCharsets
25
26
26
27
object Pickler {
27
28
val name : String = " pickler"
@@ -304,14 +305,33 @@ class Pickler extends Phase {
304
305
| diff before-pickling.txt after-pickling.txt """ )
305
306
end testSame
306
307
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
312
310
output(" after-printing.txt" , printed)
313
311
report.error(em """ TASTy printer difference for $cls in ${cls.source}, for details:
314
312
|
315
313
| 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
+ }
317
337
}
0 commit comments