This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Anyway to evaluate a string as Scala code

3 replies
John Ky
Joined: 2009-10-06,
User offline. Last seen 42 years 45 weeks ago.
Hi,

I'm writing a tool that generates Scala code and I'm wanting to unit test it.  I'm currently using JUnit.

Ideally, I'd like to generate Scala code in my JUnit test and send it to a Scala interpreter to run and then be able to determine if there are any errors in the generated code from my JUnit test case.

What's the best way to go about this?

Thanks,

-John

ounos
Joined: 2008-12-29,
User offline. Last seen 3 years 44 weeks ago.
Re: Anyway to evaluate a string as Scala code

As a starting point you might want to check this:

http://old.nabble.com/Compiler-API-to12050645.html#a12050645

Dimitris

2009/12/9 John Ky :
> Hi,
>
> I'm writing a tool that generates Scala code and I'm wanting to unit test
> it.  I'm currently using JUnit.
>
> Ideally, I'd like to generate Scala code in my JUnit test and send it to a
> Scala interpreter to run and then be able to determine if there are any
> errors in the generated code from my JUnit test case.
>
> What's the best way to go about this?
>
> Thanks,
>
> -John
>
>

Tony Sloane
Joined: 2009-01-07,
User offline. Last seen 2 years 32 weeks ago.
Re: Anyway to evaluate a string as Scala code

On 09/12/2009, at 11:13 AM, John Ky wrote:

> I'm writing a tool that generates Scala code and I'm wanting to unit test it. I'm currently using JUnit.
>
> Ideally, I'd like to generate Scala code in my JUnit test and send it to a Scala interpreter to run and then be able to determine if there are any errors in the generated code from my JUnit test case.
>
> What's the best way to go about this?

Specs has support for this kind of thing. For starters, check out:

http://stackoverflow.com/questions/1857999/static-testing-for-scala

cheers,
Tony

John Ky
Joined: 2009-10-06,
User offline. Last seen 42 years 45 weeks ago.
Re: Anyway to evaluate a string as Scala code
Cool!  Thanks!

On Wed, Dec 9, 2009 at 1:36 PM, Tony Sloane <inkytonik@gmail.com> wrote:
On 09/12/2009, at 11:13 AM, John Ky wrote:

> I'm writing a tool that generates Scala code and I'm wanting to unit test it.  I'm currently using JUnit.
>
> Ideally, I'd like to generate Scala code in my JUnit test and send it to a Scala interpreter to run and then be able to determine if there are any errors in the generated code from my JUnit test case.
>
> What's the best way to go about this?

Specs has support for this kind of thing.  For starters, check out:

http://stackoverflow.com/questions/1857999/static-testing-for-scala

cheers,
Tony


Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland