diff options
author | David Helder <david@twitter.com> | 2011-04-29 09:55:04 -0700 |
---|---|---|
committer | Christopher Vogt <oss.nsp@cvogt.org> | 2016-11-07 02:08:38 -0500 |
commit | 46ef4635b75aa6735b72b52508637265e4c0ed70 (patch) | |
tree | 93a873a108b897636571c952e22f7bd7105d4d13 /libraries/eval/Eval.scala | |
parent | 3633a472678506b7fed3ba27b130dfe33e34e813 (diff) | |
download | cbt-46ef4635b75aa6735b72b52508637265e4c0ed70.tar.gz cbt-46ef4635b75aa6735b72b52508637265e4c0ed70.tar.bz2 cbt-46ef4635b75aa6735b72b52508637265e4c0ed70.zip |
[split] Eval.scala: Add Eval.check
EvalSpec.scala:
Rename, update for new API. Note one test fails (commented out)
Future.scala, ScribeHandlerSpec.scala:
Fix warnings
Diffstat (limited to 'libraries/eval/Eval.scala')
-rw-r--r-- | libraries/eval/Eval.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index c752eba..2b22bcb 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -96,6 +96,34 @@ class Eval { apply[T](code, false) } + /** + * Check if code is Eval-able. + * @throw CompilerException if not Eval-able. + */ + def check(code: String) { + val id = uniqueId(code) + val className = "Evaluator__" + id + val wrappedCode = wrapCodeInClass(className, code) + compile(wrappedCode) // may throw CompilerException + } + + /** + * Check if files are Eval-able. + * @throw CompilerException if not Eval-able. + */ + def check(files: File*) { + val code = files.map { scala.io.Source.fromFile(_).mkString }.mkString("\n") + check(code) + } + + /** + * Check if stream is Eval-able. + * @throw CompilerException if not Eval-able. + */ + def check(stream: InputStream) { + check(scala.io.Source.fromInputStream(stream).mkString) + } + private def uniqueId(code: String): String = { val digest = MessageDigest.getInstance("SHA-1").digest(code.getBytes()) val sha = new BigInteger(1, digest).toString(16) |