diff options
Diffstat (limited to 'test/test')
-rw-r--r-- | test/test/CompilerTest.scala | 41 | ||||
-rw-r--r-- | test/test/DottyTest.scala | 1 | ||||
-rw-r--r-- | test/test/InterfaceEntryPointTest.scala | 2 | ||||
-rw-r--r-- | test/test/OtherEntryPointsTest.scala | 4 | ||||
-rw-r--r-- | test/test/ParserTest.scala | 3 | ||||
-rw-r--r-- | test/test/ScannerTest.scala | 5 | ||||
-rw-r--r-- | test/test/TestREPL.scala | 4 |
7 files changed, 45 insertions, 15 deletions
diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 56b9e1099..dea6a30b1 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -228,7 +228,7 @@ abstract class CompilerTest { private def expectedErrors(filePath: String): List[ErrorsInFile] = expectedErrors(List(filePath)) - private def isNegTest(testPath: String) = testPath.contains(JFile.separator + "neg" + JFile.separator) + private def isNegTest(testPath: String) = testPath.contains("/neg/") private def compileArgs(args: Array[String], expectedErrorsPerFile: List[ErrorsInFile]) (implicit defaultOptions: List[String]): Unit = { @@ -413,7 +413,8 @@ abstract class CompilerTest { val flags = oldFlags.map(f => if (f == oldOutput) partestOutput else f) ++ List(s"-classpath $partestOutput") // Required for separate compilation tests - getExisting(dest).isDifferent(source, flags, nerr) match { + val difference = getExisting(dest).isDifferent(source, flags, nerr) + difference match { case NotExists => copyFiles(source, dest, partestOutput, flags, nerr, kind) case ExistsSame => // nothing else to do case ExistsDifferent => @@ -449,11 +450,37 @@ abstract class CompilerTest { /** Recursively copy over source files and directories, excluding extensions * that aren't in extensionsToCopy. */ private def recCopyFiles(sourceFile: Path, dest: Path): Unit = { - processFileDir(sourceFile, { sf => + + def copyfile(file: SFile, bytewise: Boolean): Unit = { + if (bytewise) { + val in = file.inputStream() + val out = SFile(dest).outputStream() + val buffer = new Array[Byte](1024) + def loop(available: Int):Unit = { + if (available < 0) {()} + else { + out.write(buffer, 0, available) + val read = in.read(buffer) + loop(read) + } + } + loop(0) + in.close() + out.close() + } else { + try { + SFile(dest)(scala.io.Codec.UTF8).writeAll((s"/* !!!!! WARNING: DO NOT MODIFY. Original is at: $file !!!!! */").replace("\\", "/"), file.slurp("UTF-8")) + } catch { + case unmappable: java.nio.charset.MalformedInputException => + copyfile(file, true) //there are bytes that can't be mapped with UTF-8. Bail and just do a straight byte-wise copy without the warning header. + } + } + } + + processFileDir(sourceFile, { sf => if (extensionsToCopy.contains(sf.extension)) { dest.parent.jfile.mkdirs - dest.toFile.writeAll("/* !!!!! WARNING: DO NOT MODIFY. Original is at: $sf !!!!! */", - sf.slurp()) + copyfile(sf, false) } else { log(s"WARNING: ignoring $sf") } @@ -465,7 +492,7 @@ abstract class CompilerTest { /** Reads the existing files for the given test source if any. */ private def getExisting(dest: Path): ExistingFiles = { - val content: Option[Option[String]] = processFileDir(dest, f => f.safeSlurp, d => Some("")) + val content: Option[Option[String]] = processFileDir(dest, f => try Some(f.slurp("UTF8")) catch {case io: java.io.IOException => Some(io.toString())}, d => Some("")) if (content.isDefined && content.get.isDefined) { val flags = (dest changeExtension "flags").toFile.safeSlurp val nerr = (dest changeExtension "nerr").toFile.safeSlurp @@ -479,7 +506,7 @@ abstract class CompilerTest { if (!genSrc.isDefined) { NotExists } else { - val source = processFileDir(sourceFile, { f => f.safeSlurp }, { d => Some("") }, + val source = processFileDir(sourceFile, { f => try Some(f.slurp("UTF8")) catch {case _: java.io.IOException => None} }, { d => Some("") }, Some("DPCompilerTest sourceFile doesn't exist: " + sourceFile)).get if (source == genSrc) { nerr match { diff --git a/test/test/DottyTest.scala b/test/test/DottyTest.scala index 15d82c208..4b767b318 100644 --- a/test/test/DottyTest.scala +++ b/test/test/DottyTest.scala @@ -23,6 +23,7 @@ class DottyTest /*extends ContextEscapeDetection*/ { import base.settings._ val ctx = base.initialCtx.fresh base.initialize()(ctx) + ctx.setSetting(ctx.settings.encoding, "UTF8") ctx } /* diff --git a/test/test/InterfaceEntryPointTest.scala b/test/test/InterfaceEntryPointTest.scala index b193b5f64..438a9fa47 100644 --- a/test/test/InterfaceEntryPointTest.scala +++ b/test/test/InterfaceEntryPointTest.scala @@ -18,7 +18,7 @@ import scala.collection.mutable.ListBuffer */ class InterfaceEntryPointTest { @Test def runCompilerFromInterface = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val mainClass = Class.forName("dotty.tools.dotc.Main") diff --git a/test/test/OtherEntryPointsTest.scala b/test/test/OtherEntryPointsTest.scala index 0186b357b..5f8681d38 100644 --- a/test/test/OtherEntryPointsTest.scala +++ b/test/test/OtherEntryPointsTest.scala @@ -17,7 +17,7 @@ import scala.collection.mutable.ListBuffer */ class OtherEntryPointsTest { @Test def runCompiler = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val reporter = new CustomReporter @@ -31,7 +31,7 @@ class OtherEntryPointsTest { } @Test def runCompilerWithContext = { - val sources = List("./tests/pos/HelloWorld.scala") + val sources = List("./tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) val args = sources ++ List("-d", "./out/") val reporter = new CustomReporter diff --git a/test/test/ParserTest.scala b/test/test/ParserTest.scala index 524be272d..f66dbf55d 100644 --- a/test/test/ParserTest.scala +++ b/test/test/ParserTest.scala @@ -4,6 +4,7 @@ import scala.reflect.io._ import dotty.tools.dotc.util._ import dotty.tools.dotc.core._ import dotty.tools.dotc.parsing._ +import scala.io.Codec import Tokens._, Parsers._ import dotty.tools.dotc.ast.untpd._ import org.junit.Test @@ -23,7 +24,7 @@ class ParserTest extends DottyTest { def parse(file: PlainFile): Tree = { //println("***** parsing " + file) - val source = new SourceFile(file) + val source = new SourceFile(file, Codec.UTF8) val parser = new Parser(source) val tree = parser.parse() parsed += 1 diff --git a/test/test/ScannerTest.scala b/test/test/ScannerTest.scala index f8f09ff6f..5ff9bba0c 100644 --- a/test/test/ScannerTest.scala +++ b/test/test/ScannerTest.scala @@ -1,6 +1,7 @@ package test import scala.reflect.io._ +import scala.io.Codec import dotty.tools.dotc.util._ import dotty.tools.dotc.parsing._ import Tokens._, Scanners._ @@ -16,8 +17,8 @@ class ScannerTest extends DottyTest { def scan(name: String): Unit = scan(new PlainFile(name)) def scan(file: PlainFile): Unit = { - println("***** scanning " + file) - val source = new SourceFile(file) + //println("***** scanning " + file) + val source = new SourceFile(file, Codec.UTF8) val scanner = new Scanner(source) var i = 0 while (scanner.token != EOF) { diff --git a/test/test/TestREPL.scala b/test/test/TestREPL.scala index 1ba456ce2..9867cb4ec 100644 --- a/test/test/TestREPL.scala +++ b/test/test/TestREPL.scala @@ -34,7 +34,7 @@ class TestREPL(script: String) extends REPL { while (lines.hasNext && lines.head.startsWith(continuationPrompt)) { val continued = lines.next output.println(continued) - buf append "\n" + buf append System.lineSeparator() buf append continued.drop(continuationPrompt.length) } buf.toString @@ -49,7 +49,7 @@ class TestREPL(script: String) extends REPL { out.close() val printed = out.toString val transcript = printed.drop(printed.indexOf(config.prompt)) - if (transcript.toString != script) { + if (transcript.toString.lines.toList != script.lines.toList) { println("input differs from transcript:") println(transcript) assert(false) |