diff options
author | Paul Phillips <paulp@improving.org> | 2013-04-26 13:30:59 -0700 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2013-04-26 14:54:35 -0700 |
commit | fbb13630d3c1dc9b8fdc503538d4ace5873f31c9 (patch) | |
tree | 766961e50ba7386ed23878adf71f8f1bd6a62361 /src | |
parent | 403ba8938f115215700e677523d91710c20b6be4 (diff) | |
download | scala-fbb13630d3c1dc9b8fdc503538d4ace5873f31c9.tar.gz scala-fbb13630d3c1dc9b8fdc503538d4ace5873f31c9.tar.bz2 scala-fbb13630d3c1dc9b8fdc503538d4ace5873f31c9.zip |
Refactor DirectTest so java can be tested.
There was no way to make a java compilation unit.
Now there is.
Diffstat (limited to 'src')
-rw-r--r-- | src/partest/scala/tools/partest/CompilerTest.scala | 2 | ||||
-rw-r--r-- | src/partest/scala/tools/partest/DirectTest.scala | 28 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/partest/scala/tools/partest/CompilerTest.scala b/src/partest/scala/tools/partest/CompilerTest.scala index d73d99bc89..848deef8c5 100644 --- a/src/partest/scala/tools/partest/CompilerTest.scala +++ b/src/partest/scala/tools/partest/CompilerTest.scala @@ -19,7 +19,7 @@ abstract class CompilerTest extends DirectTest { def check(source: String, unit: global.CompilationUnit): Unit lazy val global: Global = newCompiler() - lazy val units = compilationUnits(global)(sources: _ *) + lazy val units: List[global.CompilationUnit] = compilationUnits(global)(sources: _ *) import global._ import definitions._ diff --git a/src/partest/scala/tools/partest/DirectTest.scala b/src/partest/scala/tools/partest/DirectTest.scala index 483cb491a1..e2dac2fd55 100644 --- a/src/partest/scala/tools/partest/DirectTest.scala +++ b/src/partest/scala/tools/partest/DirectTest.scala @@ -7,7 +7,7 @@ package scala.tools.partest import scala.tools.nsc._ import io.Directory -import util.{BatchSourceFile, CommandLineParser} +import util.{ SourceFile, BatchSourceFile, CommandLineParser } import reporters.{Reporter, ConsoleReporter} /** A class for testing code which is embedded as a string. @@ -49,18 +49,32 @@ abstract class DirectTest extends App { def reporter(settings: Settings): Reporter = new ConsoleReporter(settings) - def newSources(sourceCodes: String*) = sourceCodes.toList.zipWithIndex map { - case (src, idx) => new BatchSourceFile("newSource" + (idx + 1), src) - } + private def newSourcesWithExtension(ext: String)(codes: String*): List[BatchSourceFile] = + codes.toList.zipWithIndex map { + case (src, idx) => new BatchSourceFile(s"newSource${idx + 1}.$ext", src) + } + + def newJavaSources(codes: String*) = newSourcesWithExtension("java")(codes: _*) + def newSources(codes: String*) = newSourcesWithExtension("scala")(codes: _*) + def compileString(global: Global)(sourceCode: String): Boolean = { withRun(global)(_ compileSources newSources(sourceCode)) !global.reporter.hasErrors } - def compilationUnits(global: Global)(sourceCodes: String*): List[global.CompilationUnit] = { - val units = withRun(global) { run => - run compileSources newSources(sourceCodes: _*) + + def javaCompilationUnits(global: Global)(sourceCodes: String*) = { + sourceFilesToCompiledUnits(global)(newJavaSources(sourceCodes: _*)) + } + + def sourceFilesToCompiledUnits(global: Global)(files: List[SourceFile]) = { + withRun(global) { run => + run compileSources files run.units.toList } + } + + def compilationUnits(global: Global)(sourceCodes: String*): List[global.CompilationUnit] = { + val units = sourceFilesToCompiledUnits(global)(newSources(sourceCodes: _*)) if (global.reporter.hasErrors) { global.reporter.flush() sys.error("Compilation failure.") |