title: How to use Scalatest to develop a compiler-plugin in Scala
body: <p>Actually I'm developing a compiler plugin for Scala according to the article on <a href="http://www.scala-lang.org/node/140" rel="nofollow">http://www.scala-lang.org/node/140</a>.</p>
  
  <p>Here is the code of the plugin:</p>
  
  <pre><code>package localhost
  
  import scala.tools.nsc
  import nsc.Global
  import nsc.Phase
  import nsc.plugins.Plugin
  import nsc.plugins.PluginComponent
  
  class DivByZero(val global: Global) extends Plugin {
    import global._
  
    val name = "divbyzero"
    val description = "checks for division by zero"
    val components = List[PluginComponent](Component)
  
    private object Component extends PluginComponent {
      val global: DivByZero.this.global.type = DivByZero.this.global
      val runsAfter = "refchecks"
      // Using the Scala Compiler 2.8.x the runsAfter should be written as below
      // val runsAfter = List[String]("refchecks");
      val phaseName = DivByZero.this.name
      def newPhase(_prev: Phase) = new DivByZeroPhase(_prev)    
  
      class DivByZeroPhase(prev: Phase) extends StdPhase(prev) {
        override def name = DivByZero.this.name
        def apply(unit: CompilationUnit) {
          for ( tree @ Apply(Select(rcvr, nme.DIV), List(Literal(Constant(0)))) &lt;- unit.body;
               if rcvr.tpe &lt;:&lt; definitions.IntClass.tpe) 
            {
              unit.error(tree.pos, "definitely division by zero")
            }
        }
      }
    }
  }
  </code></pre>
  
  <p>I'm doing the things mentioned there and wrote some makefile which compiles everything and then creates a jar-file. Then I'm loading the the plugin jar file with the testfile with the following command:</p>
  
  <pre><code>scalac -Xplugin:myplugin.jar test.scala
  </code></pre>
  
  <p>and see what the output is. I don't like this way because I knew from ruby how to do tdd and bdd. I installed Scalatest <a href="http://www.scalatest.org/" rel="nofollow">http://www.scalatest.org/</a>. Is it in someway possible to test the jar-file or the class divbyzero? I know the plugin will first be load when executes with a file. I'm very wired in my head and don't know if it is possible to directly test the plugin class without creating the jar file (or is it even possible to test some functions and classes of the jar file)?</p>
  
  <p>If no one can help me, I can keep on developing like in the good old days</p>
  
  <p>Thanks for your time and help
  Matthias</p>