diff options
author | Arya Asemanfar <arya@twitter.com> | 2011-06-17 11:45:01 -0700 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:38 -0500 |
commit | 45290fade6da61d24f304346468ce3d7058f53a1 (patch) | |
tree | baf800a50cad19326347f5b539ac03f80ab34208 /libraries | |
parent | eb3f2f886e7857ad0c08b2be9aeb52ae1605315a (diff) | |
download | cbt-45290fade6da61d24f304346468ce3d7058f53a1.tar.gz cbt-45290fade6da61d24f304346468ce3d7058f53a1.tar.bz2 cbt-45290fade6da61d24f304346468ce3d7058f53a1.zip |
[split] Squashed commit of the following:
commit 86a7f2fdac93924da81f4fe7542228f071dbe617
Author: Arya Asemanfar <arya@twitter.com>
Date: Fri Jun 17 11:42:44 2011 -0700
Added test for Eval.toSource
commit d13c269c39514b3a20812bc594cc67a0902d248b
Merge: 294e5d9 ede4550
Author: Arya Asemanfar <arya@twitter.com>
Date: Fri Jun 17 10:42:02 2011 -0700
Merge branch 'master' into tfe/config_post_processing
commit 294e5d982716ec31dddb18b71caea92580aaddb0
Author: Arya Asemanfar <arya@twitter.com>
Date: Thu Jun 16 16:22:41 2011 -0700
Make the config in the dashboard be post-processed config
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/eval/Eval.scala | 14 | ||||
-rw-r--r-- | libraries/eval/test/EvalTest.scala | 6 |
2 files changed, 19 insertions, 1 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index ebbf1da..9b205b3 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -96,6 +96,14 @@ class Eval { apply(Source.fromInputStream(stream).mkString) } + def toSource(file: File): String = { + toSource(scala.io.Source.fromFile(file).mkString) + } + + def toSource(code: String): String = { + compiler.sourceForString(code) + } + /** * Compile an entire source file into the virtual classloader. */ @@ -355,7 +363,7 @@ class Eval { * Compile scala code. It can be found using the above class loader. */ def apply(code: String) { - val processedCode = preprocessors.foldLeft(code) { case (c: String, p: Preprocessor) => p(c) } + val processedCode = sourceForString(code) if (Debug.enabled) Debug.printWithLineNumbers(processedCode) @@ -369,6 +377,10 @@ class Eval { } } + def sourceForString(code: String) = { + preprocessors.foldLeft(code) { case (c: String, p: Preprocessor) => p(c) } + } + /** * Compile a new class, load it, and return it. Thread-safe. */ diff --git a/libraries/eval/test/EvalTest.scala b/libraries/eval/test/EvalTest.scala index c16de43..a48c8ac 100644 --- a/libraries/eval/test/EvalTest.scala +++ b/libraries/eval/test/EvalTest.scala @@ -51,6 +51,12 @@ object EvalSpec extends Specification { derived.toString mustEqual "hello, joe" } + "toSource returns post-processed code" in { + val derived = Eval.toSource(TempFile.fromResourcePath("/DerivedWithInclude.scala")) + derived must include("hello, joe") + derived must include("new Base") + } + "throws a compilation error when Ruby is #included" in { Eval[() => String]( TempFile.fromResourcePath("RubyInclude.scala")) must throwA[Throwable] |