From 87b30c986be145806591c16445ec90a8a54dcee0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 8 Mar 2016 18:08:22 +0100 Subject: Rewrite test Test rewritings that were implemented so far. --- test/dotc/tests.scala | 2 ++ test/test/CompilerTest.scala | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 2d4ed289c..457116feb 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -104,6 +104,8 @@ class tests extends CompilerTest { @Test def pos_scala2_all = compileFiles(posScala2Dir, scala2mode) + @Test def rewrites = compileFile(posScala2Dir, "rewrites", "-rewrite" :: scala2mode) + @Test def pos_859 = compileFile(posSpecialDir, "i859", scala2mode)(allowDeepSubtypes) @Test def new_all = compileFiles(newDir, twice) diff --git a/test/test/CompilerTest.scala b/test/test/CompilerTest.scala index 678ef74b1..739bba46d 100644 --- a/test/test/CompilerTest.scala +++ b/test/test/CompilerTest.scala @@ -10,6 +10,7 @@ import scala.reflect.io.{ Path, Directory, File => SFile, AbstractFile } import scala.tools.partest.nest.{ FileManager, NestUI } import scala.annotation.tailrec import java.io.{ RandomAccessFile, File => JFile } +import dotty.tools.io.PlainFile import org.junit.Test @@ -89,7 +90,20 @@ abstract class CompilerTest { if (!generatePartestFiles || !partestableFile(prefix, fileName, extension, args ++ defaultOptions)) { if (runTest) log(s"WARNING: run tests can only be run by partest, JUnit just verifies compilation: $prefix$fileName$extension") - compileArgs((s"$filePath" :: args).toArray, expErrors) + if (args.contains("-rewrite")) { + val file = new PlainFile(filePath) + val data = file.toByteArray + val cs = data.map(_.toChar) + println(s"data = ${cs.mkString}") + compileArgs((filePath :: args).toArray, expErrors) + val plainArgs = args.filter(arg => arg != "-rewrite" && arg != "-language:Scala2") + println(s"plainArgs = $plainArgs") + compileFile(prefix, fileName, plainArgs, extension, runTest) + val out = file.output + out.write(data) + out.close() + } + else compileArgs((filePath :: args).toArray, expErrors) } else { val kind = testKind(prefix, runTest) log(s"generating partest files for test file: $prefix$fileName$extension of kind $kind") @@ -191,6 +205,8 @@ abstract class CompilerTest { } } + + // ========== HELPERS ============= private def expectedErrors(filePaths: List[String]): List[ErrorsInFile] = if (filePaths.exists(isNegTest(_))) filePaths.map(getErrors(_)) else Nil -- cgit v1.2.3