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 | |
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.
-rw-r--r-- | src/partest/scala/tools/partest/CompilerTest.scala | 2 | ||||
-rw-r--r-- | src/partest/scala/tools/partest/DirectTest.scala | 28 | ||||
-rw-r--r-- | test/files/run/t5527.check | 2 | ||||
-rw-r--r-- | test/files/run/t5603.check | 2 | ||||
-rw-r--r-- | test/files/run/t6028.check | 2 | ||||
-rw-r--r-- | test/files/run/t6288.check | 2 | ||||
-rw-r--r-- | test/files/run/t6440.check | 2 | ||||
-rw-r--r-- | test/files/run/t6555.check | 2 | ||||
-rw-r--r-- | test/files/run/typetags_without_scala_reflect_typetag_lookup.check | 2 | ||||
-rw-r--r-- | test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check | 2 |
10 files changed, 30 insertions, 16 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.") diff --git a/test/files/run/t5527.check b/test/files/run/t5527.check index 1518168c51..36bee9bb55 100644 --- a/test/files/run/t5527.check +++ b/test/files/run/t5527.check @@ -1,4 +1,4 @@ -[[syntax trees at end of parser]] // newSource1 +[[syntax trees at end of parser]] // newSource1.scala package <empty> { object UselessComments extends scala.AnyRef { def <init>() = { diff --git a/test/files/run/t5603.check b/test/files/run/t5603.check index 5127d3c1c7..3f19a0a4b1 100644 --- a/test/files/run/t5603.check +++ b/test/files/run/t5603.check @@ -1,4 +1,4 @@ -[[syntax trees at end of parser]] // newSource1 +[[syntax trees at end of parser]] // newSource1.scala [0:241]package [0:0]<empty> { [0:82]abstract trait Greeting extends [15:82][83]scala.AnyRef { [15]def $init$() = [15]{ diff --git a/test/files/run/t6028.check b/test/files/run/t6028.check index 94013efd36..613d25b075 100644 --- a/test/files/run/t6028.check +++ b/test/files/run/t6028.check @@ -1,4 +1,4 @@ -[[syntax trees at end of lambdalift]] // newSource1 +[[syntax trees at end of lambdalift]] // newSource1.scala package <empty> { class T extends Object { <paramaccessor> val T$$classParam: Int = _; diff --git a/test/files/run/t6288.check b/test/files/run/t6288.check index e6467edc95..e940975e44 100644 --- a/test/files/run/t6288.check +++ b/test/files/run/t6288.check @@ -1,4 +1,4 @@ -[[syntax trees at end of patmat]] // newSource1 +[[syntax trees at end of patmat]] // newSource1.scala [7]package [7]<empty> { [7]object Case3 extends [13][106]scala.AnyRef { [13]def <init>(): [13]Case3.type = [13]{ diff --git a/test/files/run/t6440.check b/test/files/run/t6440.check index 69c253eab4..806279fb74 100644 --- a/test/files/run/t6440.check +++ b/test/files/run/t6440.check @@ -1,4 +1,4 @@ -pos: source-newSource1,line-9,offset=109 bad symbolic reference. A signature in U.class refers to term pack1 +pos: source-newSource1.scala,line-9,offset=109 bad symbolic reference. A signature in U.class refers to term pack1 in package <root> which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling U.class. ERROR diff --git a/test/files/run/t6555.check b/test/files/run/t6555.check index 04117b7c2f..a18a8e8023 100644 --- a/test/files/run/t6555.check +++ b/test/files/run/t6555.check @@ -1,4 +1,4 @@ -[[syntax trees at end of specialize]] // newSource1 +[[syntax trees at end of specialize]] // newSource1.scala package <empty> { class Foo extends Object { def <init>(): Foo = { diff --git a/test/files/run/typetags_without_scala_reflect_typetag_lookup.check b/test/files/run/typetags_without_scala_reflect_typetag_lookup.check index 8c558ced60..84e5435afe 100644 --- a/test/files/run/typetags_without_scala_reflect_typetag_lookup.check +++ b/test/files/run/typetags_without_scala_reflect_typetag_lookup.check @@ -1,2 +1,2 @@ -pos: source-newSource1,line-9,offset=466 could not find implicit value for evidence parameter of type reflect.runtime.package.universe.TypeTag[Int] ERROR +pos: source-newSource1.scala,line-9,offset=466 could not find implicit value for evidence parameter of type reflect.runtime.package.universe.TypeTag[Int] ERROR diff --git a/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check index acfecce628..8c9d07d836 100644 --- a/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check +++ b/test/files/run/typetags_without_scala_reflect_typetag_manifest_interop.check @@ -1,2 +1,2 @@ -pos: source-newSource1,line-9,offset=479 No Manifest available for App.this.T. ERROR +pos: source-newSource1.scala,line-9,offset=479 No Manifest available for App.this.T. ERROR |