Skip to content

Commit 4f9d7c0

Browse files
committed
Code refactor
1 parent 43a76df commit 4f9d7c0

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

compiler/test/dotty/tools/dotc/printing/PrintingTest.scala

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,8 @@ class PrintingTest {
3535
e.printStackTrace()
3636
}
3737

38-
val actualLines = byteStream.toString("UTF-8").split("\\r?\\n")
39-
// 'options' includes option '-Xprint:typer' so the first output line
40-
// looks similar to "result of tests/printing/i620.scala after typer:";
41-
// check files use slashes as file separators (Unix) but running tests
42-
// on Windows produces backslashes.
43-
// NB. option '-Xprint:<..>' can specify several phases.
44-
val filteredLines =
45-
if (config.Properties.isWin)
46-
actualLines.map(line =>
47-
if (line.startsWith("result of")) line.replaceAll("\\\\", "/") else line
48-
)
49-
else
50-
actualLines
51-
52-
FileDiff.checkAndDump(path.toString, filteredLines.toIndexedSeq, checkFilePath)
38+
val actualLines = byteStream.toString("UTF-8").linesIterator
39+
FileDiff.checkAndDump(path.toString, actualLines.toIndexedSeq, checkFilePath)
5340
}
5441

5542
@Test

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,39 @@ class PatmatExhaustivityTest {
2020
// stop-after: patmatexhaust-huge.scala crash compiler
2121
val options = List("-color:never", "-Ystop-after:crossCast", "-Ycheck-all-patmat", "-classpath", TestConfiguration.basicClasspath)
2222

23-
private def compileFile(path: JPath): Boolean = {
23+
private def compile(files: Seq[String]): Seq[String] = {
2424
val stringBuffer = new StringWriter()
2525
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))
2626

2727
try {
28-
Main.process((path.toString::options).toArray, reporter, null)
28+
Main.process((options ++ files).toArray, reporter, null)
2929
} catch {
3030
case e: Throwable =>
31-
println(s"Compile $path exception:")
31+
println(s"Compile $files exception:")
3232
e.printStackTrace()
3333
}
3434

35-
val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
35+
stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
3636
case "" => Nil
37-
case s => s.split("\\r?\\n").toIndexedSeq
37+
case s => s.linesIterator.toSeq
3838
}
39-
val baseFilePath = path.toString.stripSuffix(".scala")
39+
}
40+
41+
private def compileFile(path: JPath): Boolean = {
42+
val actualLines = compile(path.toString :: Nil)
43+
val baseFilePath = path.toString.stripSuffix(".scala")
4044
val checkFilePath = baseFilePath + ".check"
4145

4246
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)
4347
}
4448

4549
/** A single test with multiple files grouped in a folder */
4650
private def compileDir(path: JPath): Boolean = {
47-
val stringBuffer = new StringWriter()
48-
val reporter = TestReporter.simplifiedReporter(new PrintWriter(stringBuffer))
49-
5051
val files = Directory(path).list.toList
5152
.filter(f => f.extension == "scala" || f.extension == "java" )
5253
.map(_.jpath.toString)
5354

54-
try {
55-
Main.process((options ++ files).toArray, reporter, null)
56-
} catch {
57-
case e: Throwable =>
58-
println(s"Compile $path exception:")
59-
e.printStackTrace()
60-
}
61-
62-
val actualLines: Seq[String] = stringBuffer.toString.trim.replaceAll("\\s+\n", "\n") match {
63-
case "" => Nil
64-
case s => s.split("\\r?\\n").toIndexedSeq
65-
}
66-
55+
val actualLines = compile(files)
6756
val checkFilePath = s"${path}${File.separator}expected.check"
6857

6958
FileDiff.checkAndDump(path.toString, actualLines, checkFilePath)

0 commit comments

Comments
 (0)