|
1 | 1 |
|
2 |
| -import java.nio.file.{Files, Path, Paths} |
| 2 | +import java.nio.file.{ Files => JFiles, Path => JPath, Paths => JPaths } |
3 | 3 | import java.util.stream.{ Stream => JStream }
|
4 | 4 |
|
5 | 5 | import scala.collection.JavaConverters._
|
6 | 6 |
|
7 |
| -object Test { |
8 |
| - |
9 |
| - def main(args: Array[String]): Unit = checkIdempotency() |
10 |
| - |
| 7 | +object IdempotencyCheck { |
11 | 8 | val blacklisted = Set(
|
12 |
| - // Bridges on collections in different order. Second one in scala2 order. |
| 9 | + // No fix needed. Bridges on collections in different order. Second one in scala2 order. |
13 | 10 | "pos/Map/scala/collection/immutable/Map",
|
14 | 11 | "pos/Map/scala/collection/immutable/AbstractMap",
|
15 | 12 | "pos/t1203a/NodeSeq",
|
16 | 13 | "pos/i2345/Whatever"
|
17 | 14 | )
|
18 | 15 |
|
19 |
| - def checkIdempotency(): Unit = { |
| 16 | + def checkIdempotency(dirPrefix: String): Unit = { |
20 | 17 | var failed = 0
|
21 | 18 | var total = 0
|
22 | 19 |
|
23 |
| - val groupedBytecodeFiles: List[(Path, Path, Path, Path)] = { |
| 20 | + val groupedBytecodeFiles: List[(JPath, JPath, JPath, JPath)] = { |
24 | 21 | val bytecodeFiles = {
|
25 |
| - def bytecodeFiles(paths: JStream[Path]): List[Path] = { |
| 22 | + def bytecodeFiles(paths: JStream[JPath]): List[JPath] = { |
26 | 23 | def isBytecode(file: String) = file.endsWith(".class") || file.endsWith(".tasty")
|
27 | 24 | paths.iterator.asScala.filter(path => isBytecode(path.toString)).toList
|
28 | 25 | }
|
29 |
| - val compilerDir1 = Paths.get("../out/idempotency1") |
30 |
| - val compilerDir2 = Paths.get("../out/idempotency2") |
31 |
| - bytecodeFiles(Files.walk(compilerDir1)) ++ bytecodeFiles(Files.walk(compilerDir2)) |
| 26 | + val compilerDir1 = JPaths.get(dirPrefix + 1) |
| 27 | + val compilerDir2 = JPaths.get(dirPrefix + 2) |
| 28 | + bytecodeFiles(JFiles.walk(compilerDir1)) ++ bytecodeFiles(JFiles.walk(compilerDir2)) |
32 | 29 | }
|
33 |
| - val groups = bytecodeFiles.groupBy(f => f.toString.substring("../out/idempotencyN/".length, f.toString.length - 6)) |
| 30 | + val groups = bytecodeFiles.groupBy(f => f.toString.substring(dirPrefix.length + 1, f.toString.length - 6)) |
| 31 | + |
34 | 32 | groups.filterNot(x => blacklisted(x._1)).valuesIterator.flatMap { g =>
|
35 |
| - def pred(f: Path, i: Int, isTasty: Boolean) = |
36 |
| - f.toString.contains("idempotency" + i) && f.toString.endsWith(if (isTasty) ".tasty" else ".class") |
| 33 | + def pred(f: JPath, i: Int, isTasty: Boolean) = |
| 34 | + f.toString.contains(dirPrefix + i) && f.toString.endsWith(if (isTasty) ".tasty" else ".class") |
37 | 35 | val class1 = g.find(f => pred(f, 1, isTasty = false))
|
38 | 36 | val class2 = g.find(f => pred(f, 2, isTasty = false))
|
39 | 37 | val tasty1 = g.find(f => pred(f, 1, isTasty = true))
|
40 | 38 | val tasty2 = g.find(f => pred(f, 2, isTasty = true))
|
41 |
| - assert(class1.isDefined, "Could not find class in idempotency1 for " + class2) |
42 |
| - assert(class2.isDefined, "Could not find class in idempotency2 for " + class1) |
| 39 | + assert(class1.isDefined, s"Could not find class in ${dirPrefix + 1} for $class2") |
| 40 | + assert(class2.isDefined, s"Could not find class in ${dirPrefix + 2} for $class1") |
43 | 41 | if (tasty1.isEmpty || tasty2.isEmpty) Nil
|
44 | 42 | else List(Tuple4(class1.get, tasty1.get, class2.get, tasty2.get))
|
45 | 43 | }.toList
|
46 | 44 | }
|
47 | 45 |
|
48 | 46 | for ((class1, tasty1, class2, tasty2) <- groupedBytecodeFiles) {
|
49 | 47 | total += 1
|
50 |
| - val bytes1 = Files.readAllBytes(class1) |
51 |
| - val bytes2 = Files.readAllBytes(class2) |
| 48 | + val bytes1 = JFiles.readAllBytes(class1) |
| 49 | + val bytes2 = JFiles.readAllBytes(class2) |
52 | 50 | if (!java.util.Arrays.equals(bytes1, bytes2)) {
|
53 | 51 | failed += 1
|
54 |
| - val tastyBytes1 = Files.readAllBytes(tasty1) |
55 |
| - val tastyBytes2 = Files.readAllBytes(tasty2) |
| 52 | + val tastyBytes1 = JFiles.readAllBytes(tasty1) |
| 53 | + val tastyBytes2 = JFiles.readAllBytes(tasty2) |
56 | 54 | if (java.util.Arrays.equals(tastyBytes1, tastyBytes2))
|
57 | 55 | println(s"Idempotency test failed between $class1 and $class1 (same tasty)")
|
58 | 56 | else
|
59 | 57 | println(s"Idempotency test failed between $tasty1 and $tasty2")
|
60 | 58 | /* Dump bytes to console, could be useful if issue only appears in CI.
|
61 |
| - * Create the .class locally with Files.write(path, Array[Byte](...)) with the printed array |
| 59 | + * Create the .class locally with JFiles.write(path, Array[Byte](...)) with the printed array |
62 | 60 | */
|
63 | 61 | // println(bytes1.mkString("Array[Byte](", ",", ")"))
|
64 | 62 | // println(bytes2.mkString("Array[Byte](", ",", ")"))
|
|
0 commit comments