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

testing scalac plugins in sbt

2 replies
Yuvi Masory
Joined: 2010-12-22,
User offline. Last seen 1 year 27 weeks ago.
Hi all,
I'm developing a scalac plugin using sbt for development.How can I test the plugin I'm developing?Right now I'm putting sample files to be compiled in src/tests/resources and putting tests in src/tests/scala that use Runtime.exec to call "scalac -Xplugin..." using the plugin "target/scala_2.8.1/plugin.jar". I then parse stdout and compare it to what I was expecting. For about a million obvious reasons, this setup is less than ideal.Is there something better?

Yuvi

rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: testing scalac plugins in sbt
I use partest, the testing tool we use for the Scala distribution. It basically doeswhat you did yourself: compile files, run them, compare the output (or compare theerror messages for files that don't compile).
It's also a bit of a handicraft to set it up, I had to change the runner script a bit.See here: https://github.com/soundrabbit/effects/tree/master/test
Lukas


On Sun, Mar 6, 2011 at 20:19, Yuvi Masory <ymasory [at] gmail [dot] com> wrote:
Hi all,
I'm developing a scalac plugin using sbt for development.How can I test the plugin I'm developing? Right now I'm putting sample files to be compiled in src/tests/resources and putting tests in src/tests/scala that use Runtime.exec to call "scalac -Xplugin..." using the plugin "target/scala_2.8.1/plugin.jar". I then parse stdout and compare it to what I was expecting. For about a million obvious reasons, this setup is less than ideal.Is there something better?

Yuvi


Yuvi Masory
Joined: 2010-12-22,
User offline. Last seen 1 year 27 weeks ago.
Re: testing scalac plugins in sbt
Thanks Lukas.pfurla on #scala had another suggestion.
In the tests in src/tests/scala one could invoke the compiler in-process using scala.nsc.Global.That would remove the need to fork a separate process and would guarantee the scala version of the sbt plugin project is the same that's used in testing the plugin. I just need to figure out how to manually create a compiler starting with new Global(...). At that point I think i can get a reference to the Reporting object, capture what the compiler normally outputs to stdout. I'll still have to parse that, but it's better than what I'm doing now.

Yuvi



On Sun, Mar 6, 2011 at 5:31 PM, Lukas Rytz <lukas [dot] rytz [at] epfl [dot] ch> wrote:
I use partest, the testing tool we use for the Scala distribution. It basically doeswhat you did yourself: compile files, run them, compare the output (or compare theerror messages for files that don't compile).
It's also a bit of a handicraft to set it up, I had to change the runner script a bit.See here: https://github.com/soundrabbit/effects/tree/master/test
Lukas


On Sun, Mar 6, 2011 at 20:19, Yuvi Masory <ymasory [at] gmail [dot] com> wrote:
Hi all,
I'm developing a scalac plugin using sbt for development.How can I test the plugin I'm developing? Right now I'm putting sample files to be compiled in src/tests/resources and putting tests in src/tests/scala that use Runtime.exec to call "scalac -Xplugin..." using the plugin "target/scala_2.8.1/plugin.jar". I then parse stdout and compare it to what I was expecting. For about a million obvious reasons, this setup is less than ideal.Is there something better?

Yuvi



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