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

Closer, but still problems with maven an scalatest

7 replies
Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.

The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:

[INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)

ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.

pom.xml:
------------

4.0.0
your.proj.gid
rex
1.0-SNAPSHOT
2008

2.8.0

scala-tools.org
Scala-Tools Maven2 Repository
http://scala-tools.org/repo-releases

snapshots.scala-tools.org
Scala-Tools Maven2 Repository - Snapshots
http://scala-tools.org/repo-snapshots

org.scala-lang
scala-library
${scala.version}

junit
junit
3.8.1
test

org.scalatest
scalatest
1.2
test

org.scala-tools
maven-scala-plugin
2.14.2-SNAPSHOT

org.scala-tools
maven-scala-plugin

compile
testCompile

${scala.version}

org.apache.maven.plugins
maven-eclipse-plugin

true

ch.epfl.lamp.sdt.core.scalabuilder

ch.epfl.lamp.sdt.core.scalanature

org.eclipse.jdt.launching.JRE_CONTAINER
ch.epfl.lamp.sdt.launching.SCALA_CONTAINER

org.apache.maven.plugins
maven-surefire-plugin
2.6

**/*Test.*
**/*Suite.*

org.scala-tools
maven-scala-plugin
2.14.2-SNAPSHOT

src/main/scala
src/test/scala

org.scala-tools
maven-scala-plugin
2.14.2-SNAPSHOT

org.scala-tools
maven-scala-plugin

${scala.version}

My test file (RexSuite.scala):
--------------------------------------

package ykken.testrex

import org.scalatest.junit.JUnitSuite

import ykken.rex._
import ykken.rex.patterns._
import ykken.rex.Implicits._
import scala._

class RexSuite extends JUnitSuite {
def testMatchingOperators() {
assert("Hello" ~~= "Hello")
// ~~= denotes exact match
assert (!(Lit("Hello")~~="Hey, Hello"))
// ~= denotes match within the target string
assert(Lit("ello")~="Hello")
}

def testEscaping() {
assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
}

def testCharSet() {
assert(CharSet("abc") ~= "cde")
assert(CharSet("abc") !~= "de")
// "Special" characters are internally escaped.
assert(CharSet("-") ~= "-")
assert((CharSet("abc") - CharSet("cde")) !~= "c")
assert((CharSet("abc") - "c") !~= "c")
assert((CharAny ** 0) ~~= "\na.,*")
assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
}

def testComplexFloatPat() {
// A complex is a float followed by a + or - followed by a float, followed by an "i"
// The two numeric parts and the sign are named for access.
val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
/* Match against a floating-point complex number and print the result. */
val result = complexMatcher.findFirst("3.2+4.5i") match {
case None => None
case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
}
assert(Some("3.2 + 4.5i") === result)
}

def testBoundaryObjects() {
assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
}

def testCatchMisusedPlus() {
intercept[RuntimeException] {
(BndryStringStart + "a") !~~= "aaa"
}
intercept[RuntimeException] {
(BndryStringStart + BndryStringEnd) !~~= "aaa"
}
//Unfortunately, this works
assert("a" + BndryStringEnd != "b")
}

def testHTMLTagPat() {
val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
assert(tagPat ~~= "")
val minFind:String = tagPat.findFirst("
") match {
case None => ""
case Some(m) => m.group("tag")
}
assert(minFind === "
")
}

def testFindAllIn() {
assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
}

def testReplaceAllIn() {
val tagPat = ""
val target = "HelloGoodbyeNow"
assert (tagPat.replaceAllIn(target, "") === "HelloGoodbyeNow")
}

def testGrouping() {
assert("abc".anonGroup.pattern === "abc")
assert((CharSet("abc").pattern === "[abc]"))
assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
assert("abc".lookahead.pattern === "(?=abc)")
assert(("a" & "bc" & "def").pattern === "(?:abc)def")

}

def testLookaheadLookbackPatterns {
assert(("a" & "b".|> & "b") ~~= "ab")
assert(("a" & "b".|> & "bb") !~~= "ab")
assert(("a" & "c".!|> & "b") ~~= "ab")
assert(("a" & "c".!|> & "c") !~~= "ac")

assert(("a" & "c".!<| & "b") ~~= "ab")
assert(("a" & "a".<| & "b") ~~= "ab")
assert(("a" & "a".!<| & "b") !~~= "ab")
}

def testCharClasses {
val alnum = CharAlpha \/ CharDigit
assert(alnum**0 ~~= "abc123")
val alpha = CharAlnum - CharDigit
assert(alpha**0 ~~= "abc")
assert(alpha**0 !~~= "abc123")
}

def testBoundaryPatterns {
assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
}
}

Thanks,
Ken

david.bernard
Joined: 2009-01-08,
User offline. Last seen 1 year 27 weeks ago.
Re: Closer, but still problems with maven an scalatest
first step cleanup the pom.xml* remove mulitple plugin declaration* remove multiple plugin version  declaration* scala-maven-plugin auto-detect version of scala-library, no need to tell explicitly * remove pluginManagement section usefull only for parent pom (iheritence of rules)* use junit 4.8.1 (compatible with ScalaTest)
=> something like below
then retry-----
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">   <modelVersion>4.0.0</modelVersion>  <groupId>your.proj.gid</groupId>  <artifactId>rex</artifactId>  <version>1.0-SNAPSHOT</version>   <inceptionYear>2010</inceptionYear>  <properties>    <scala.version>2.8.0</scala.version>  </properties>
  <repositories>     <repository>      <id>scala-tools.org</id>      <name>Scala-Tools Maven2 Repository</name>      <url>http://scala-tools.org/repo-releases</url>     </repository>  </repositories>
  <pluginRepositories>    <pluginRepository>      <id>snapshots.scala-tools.org</id>       <name>Scala-Tools Maven2 Repository - Snapshots</name>      <url>http://scala-tools.org/repo-snapshots</url>    </pluginRepository>   </pluginRepositories>
  <dependencies>    <dependency>      <groupId>org.scala-lang</groupId>      <artifactId>scala-library</artifactId>       <version>${scala.version}</version>    </dependency>    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>       <version>4.8.1</version>      <scope>test</scope>    </dependency>    <dependency>      <groupId>org.scalatest</groupId>       <artifactId>scalatest</artifactId>      <version>1.2</version>      <scope>test</scope>    </dependency>  </dependencies>
  <build>    <sourceDirectory>src/main/scala</sourceDirectory>    <testSourceDirectory>src/test/scala</testSourceDirectory>    <plugins>       <plugin>        <groupId>org.scala-tools</groupId>        <artifactId>maven-scala-plugin</artifactId>        <version>2.14.2-SNAPSHOT</version>         <executions>          <execution>            <goals>              <goal>compile</goal>              <goal>testCompile</goal>             </goals>          </execution>        </executions>      </plugin>      <plugin>        <groupId>org.apache.maven.plugins</groupId>         <artifactId>maven-surefire-plugin</artifactId>        <version>2.6</version>        <configuration>          <includes>            <include>**/*Test.*</include>             <include>**/*Suite.*</include>          </includes>        </configuration>      </plugin>    </plugins>  </build>   <reporting>    <plugins>      <plugin>        <groupId>org.scala-tools</groupId>        <artifactId>maven-scala-plugin</artifactId>         <version>2.14.2-SNAPSHOT</version>      </plugin>    </plugins>  </reporting></project>----
On Wed, Sep 22, 2010 at 19:09, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:

[INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
java.lang.NoClassDefFoundError: scala/ScalaObject
       at java.lang.ClassLoader.defineClass1(Native Method)
       at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
       at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
       at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
       at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)

ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.


pom.xml:
------------

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>your.proj.gid</groupId>
   <artifactId>rex</artifactId>
   <version>1.0-SNAPSHOT</version>
   <inceptionYear>2008</inceptionYear>
   <properties>
       <scala.version>2.8.0</scala.version>
   </properties>

   <repositories>
       <repository>
           <id>scala-tools.org</id>
           <name>Scala-Tools Maven2 Repository</name>
           <url>http://scala-tools.org/repo-releases</url>
       </repository>
   </repositories>

   <pluginRepositories>
       <pluginRepository>
           <id>snapshots.scala-tools.org</id>
           <name>Scala-Tools Maven2 Repository - Snapshots</name>
           <url>http://scala-tools.org/repo-snapshots</url>
       </pluginRepository>
   </pluginRepositories>

   <dependencies>
       <dependency>
           <groupId>org.scala-lang</groupId>
           <artifactId>scala-library</artifactId>
           <version>${scala.version}</version>
       </dependency>
       <dependency>
           <groupId>junit</groupId>
           <artifactId>junit</artifactId>
           <version>3.8.1</version>
           <scope>test</scope>
       </dependency>
       <dependency>
           <groupId>org.scalatest</groupId>
           <artifactId>scalatest</artifactId>
           <version>1.2</version>
           <scope>test</scope>
       </dependency>
   </dependencies>

   <build>
       <!-- To define the plugin version in your parent POM -->
       <pluginManagement>
           <plugins>
               <plugin>
                   <groupId>org.scala-tools</groupId>
                   <artifactId>maven-scala-plugin</artifactId>
                   <version>2.14.2-SNAPSHOT</version>
               </plugin>
               <plugin>
                   <groupId>org.scala-tools</groupId>
                   <artifactId>maven-scala-plugin</artifactId>
                   <executions>
                       <execution>
                           <goals>
                               <goal>compile</goal>
                               <goal>testCompile</goal>
                           </goals>
                       </execution>
                   </executions>
                   <configuration>
                       <scalaVersion>${scala.version}</scalaVersion>
                   </configuration>
               </plugin>
               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-eclipse-plugin</artifactId>
                   <configuration>
                       <downloadSources>true</downloadSources>
                       <buildcommands>
                           <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
                       </buildcommands>
                       <additionalProjectnatures>
                           <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
                       </additionalProjectnatures>
                       <classpathContainers>
                           <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
                           <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
                       </classpathContainers>
                   </configuration>
               </plugin>
               <plugin>
                   <groupId>org.apache.maven.plugins</groupId>
                   <artifactId>maven-surefire-plugin</artifactId>
                   <version>2.6</version>
                   <configuration>
                       <includes>
                           <include>**/*Test.*</include>
                           <include>**/*Suite.*</include>
                       </includes>
                   </configuration>
               </plugin>
           </plugins>
       </pluginManagement>
       <!-- To use the plugin goals in your POM or parent POM -->
       <plugins>
           <plugin>
               <groupId>org.scala-tools</groupId>
               <artifactId>maven-scala-plugin</artifactId>
               <version>2.14.2-SNAPSHOT</version>
           </plugin>
       </plugins>
       <!-- To use the report goals in your POM or parent POM -->
       <sourceDirectory>src/main/scala</sourceDirectory>
       <testSourceDirectory>src/test/scala</testSourceDirectory>
   </build>
   <reporting>
       <plugins>
           <plugin>
               <groupId>org.scala-tools</groupId>
               <artifactId>maven-scala-plugin</artifactId>
               <version>2.14.2-SNAPSHOT</version>
           </plugin>
           <plugin>
               <groupId>org.scala-tools</groupId>
               <artifactId>maven-scala-plugin</artifactId>
               <configuration>
                   <scalaVersion>${scala.version}</scalaVersion>
               </configuration>
           </plugin>
       </plugins>
   </reporting>
</project>


My test file (RexSuite.scala):
--------------------------------------

package ykken.testrex

import org.scalatest.junit.JUnitSuite

import ykken.rex._
import ykken.rex.patterns._
import ykken.rex.Implicits._
import scala._

class RexSuite extends JUnitSuite {
   def testMatchingOperators() {
       assert("Hello" ~~= "Hello")
       // ~~= denotes exact match
       assert (!(Lit("Hello")~~="Hey, Hello"))
       // ~= denotes match within the target string
       assert(Lit("ello")~="Hello")
   }

   def testEscaping() {
       assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
       assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
   }

   def testCharSet() {
       assert(CharSet("abc") ~= "cde")
       assert(CharSet("abc") !~= "de")
       // "Special" characters are internally escaped.
       assert(CharSet("-") ~= "-")
       assert((CharSet("abc") - CharSet("cde")) !~= "c")
       assert((CharSet("abc") - "c") !~= "c")
       assert((CharAny ** 0) ~~= "\na.,*")
       assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
   }

   def testComplexFloatPat() {
       // A complex is a float followed by a + or - followed by a float, followed by an "i"
       // The two numeric parts and the sign are named for access.
       val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
       /* Match against a floating-point complex number and print the result. */
       val result = complexMatcher.findFirst("3.2+4.5i") match {
           case None => None
           case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
       }
       assert(Some("3.2 + 4.5i") === result)
   }

   def testBoundaryObjects() {
       assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
       assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
   }

   def testCatchMisusedPlus() {
       intercept[RuntimeException] {
         (BndryStringStart + "a") !~~= "aaa"
       }
       intercept[RuntimeException] {
         (BndryStringStart + BndryStringEnd) !~~= "aaa"
       }
       //Unfortunately, this works
       assert("a" + BndryStringEnd != "b")
   }

   def testHTMLTagPat() {
       val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
       assert(tagPat ~~= "<a count=0>")
       val minFind:String = tagPat.findFirst("<a><b>") match {
           case None => ""
           case Some(m) => m.group("tag")
       }
       assert(minFind === "<a>")
   }

   def testFindAllIn() {
       assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
       assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
       assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
       assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
       assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
   }

   def testReplaceAllIn() {
       val tagPat = "<td" & PatMinChars & ">"
       val target = "Hello<td style='color:#000'>Goodbye<td >Now"
       assert (tagPat.replaceAllIn(target, "<td>") === "Hello<td>Goodbye<td>Now")
   }

   def testGrouping() {
       assert("abc".anonGroup.pattern === "abc")
       assert((CharSet("abc").pattern === "[abc]"))
       assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
       assert("abc".lookahead.pattern === "(?=abc)")
       assert(("a" & "bc" & "def").pattern === "(?:abc)def")

   }

   def testLookaheadLookbackPatterns {
       assert(("a" & "b".|> & "b") ~~= "ab")
       assert(("a" & "b".|> & "bb") !~~= "ab")
       assert(("a" & "c".!|> & "b") ~~= "ab")
       assert(("a" & "c".!|> & "c") !~~= "ac")

       assert(("a" & "c".!<| & "b") ~~= "ab")
       assert(("a" & "a".<| & "b") ~~= "ab")
       assert(("a" & "a".!<| & "b") !~~= "ab")
   }

   def testCharClasses {
       val alnum = CharAlpha \/ CharDigit
       assert(alnum**0 ~~= "abc123")
       val alpha = CharAlnum - CharDigit
       assert(alpha**0 ~~= "abc")
       assert(alpha**0 !~~= "abc123")
   }

   def testBoundaryPatterns {
       assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
       assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
   }
}



Thanks,
Ken


Mikko Peltonen
Joined: 2010-05-05,
User offline. Last seen 42 years 45 weeks ago.
Re: Closer, but still problems with maven an scalatest

Hi Ken,

Seems to work for me with two changes, one in pom and one in code:

- Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite...)
- Use @Test annotation in test methods, i.e.:

import org.junit.Test
import org.scalatest.junit.JUnitSuite

class MySuite extends JUnitSuite {
@Test def testOneIsOne() {
assert(1 == 1)
}
}

-Mikko-

2010/9/22 Kenneth McDonald :
> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>
> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
> java.lang.NoClassDefFoundError: scala/ScalaObject
>        at java.lang.ClassLoader.defineClass1(Native Method)
>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>
> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>
>
> pom.xml:
> ------------
>
>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>    4.0.0
>    your.proj.gid
>    rex
>    1.0-SNAPSHOT
>    2008
>    
>        2.8.0
>    
>
>    
>        
>            scala-tools.org
>            Scala-Tools Maven2 Repository
>            http://scala-tools.org/repo-releases
>        
>    
>
>    
>        
>            snapshots.scala-tools.org
>            Scala-Tools Maven2 Repository - Snapshots
>            http://scala-tools.org/repo-snapshots
>        
>    
>
>    
>        
>            org.scala-lang
>            scala-library
>            ${scala.version}
>        
>        
>            junit
>            junit
>            3.8.1
>            test
>        
>        
>            org.scalatest
>            scalatest
>            1.2
>            test
>        
>    
>
>    
>        
>        
>            
>                
>                    org.scala-tools
>                    maven-scala-plugin
>                    2.14.2-SNAPSHOT
>                
>                
>                    org.scala-tools
>                    maven-scala-plugin
>                    
>                        
>                            
>                                compile
>                                testCompile
>                            
>                        
>                    
>                    
>                        ${scala.version}
>                    
>                
>                
>                    org.apache.maven.plugins
>                    maven-eclipse-plugin
>                    
>                        true
>                        
>                            ch.epfl.lamp.sdt.core.scalabuilder
>                        
>                        
>                            ch.epfl.lamp.sdt.core.scalanature
>                        
>                        
>                            org.eclipse.jdt.launching.JRE_CONTAINER
>                            ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
>                        
>                    
>                
>                
>                    org.apache.maven.plugins
>                    maven-surefire-plugin
>                    2.6
>                    
>                        
>                            **/*Test.*
>                            **/*Suite.*
>                        
>                    
>                
>            
>        
>        
>        
>            
>                org.scala-tools
>                maven-scala-plugin
>                2.14.2-SNAPSHOT
>            
>        
>        
>        src/main/scala
>        src/test/scala
>    
>    
>        
>            
>                org.scala-tools
>                maven-scala-plugin
>                2.14.2-SNAPSHOT
>            
>            
>                org.scala-tools
>                maven-scala-plugin
>                
>                    ${scala.version}
>                
>            
>        
>    
>
>
>
> My test file (RexSuite.scala):
> --------------------------------------
>
> package ykken.testrex
>
> import org.scalatest.junit.JUnitSuite
>
> import ykken.rex._
> import ykken.rex.patterns._
> import ykken.rex.Implicits._
> import scala._
>
> class RexSuite extends JUnitSuite {
>    def testMatchingOperators() {
>        assert("Hello" ~~= "Hello")
>        // ~~= denotes exact match
>        assert (!(Lit("Hello")~~="Hey, Hello"))
>        // ~= denotes match within the target string
>        assert(Lit("ello")~="Hello")
>    }
>
>    def testEscaping() {
>        assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>        assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>    }
>
>    def testCharSet() {
>        assert(CharSet("abc") ~= "cde")
>        assert(CharSet("abc") !~= "de")
>        // "Special" characters are internally escaped.
>        assert(CharSet("-") ~= "-")
>        assert((CharSet("abc") - CharSet("cde")) !~= "c")
>        assert((CharSet("abc") - "c") !~= "c")
>        assert((CharAny ** 0) ~~= "\na.,*")
>        assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>    }
>
>    def testComplexFloatPat() {
>        // A complex is a float followed by a + or - followed by a float, followed by an "i"
>        // The two numeric parts and the sign are named for access.
>        val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>        /* Match against a floating-point complex number and print the result. */
>        val result = complexMatcher.findFirst("3.2+4.5i") match {
>            case None => None
>            case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>        }
>        assert(Some("3.2 + 4.5i") === result)
>    }
>
>    def testBoundaryObjects() {
>        assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>        assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>    }
>
>    def testCatchMisusedPlus() {
>        intercept[RuntimeException] {
>          (BndryStringStart + "a") !~~= "aaa"
>        }
>        intercept[RuntimeException] {
>          (BndryStringStart + BndryStringEnd) !~~= "aaa"
>        }
>        //Unfortunately, this works
>        assert("a" + BndryStringEnd != "b")
>    }
>
>    def testHTMLTagPat() {
>        val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>        assert(tagPat ~~= "")
>        val minFind:String = tagPat.findFirst("
") match {
>            case None => ""
>            case Some(m) => m.group("tag")
>        }
>        assert(minFind === "
")
>    }
>
>    def testFindAllIn() {
>        assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>        assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>        assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>    }
>
>    def testReplaceAllIn() {
>        val tagPat = ""
>        val target = "HelloGoodbyeNow"
>        assert (tagPat.replaceAllIn(target, "") === "HelloGoodbyeNow")
>    }
>
>    def testGrouping() {
>        assert("abc".anonGroup.pattern === "abc")
>        assert((CharSet("abc").pattern === "[abc]"))
>        assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>        assert("abc".lookahead.pattern === "(?=abc)")
>        assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>
>    }
>
>    def testLookaheadLookbackPatterns {
>        assert(("a" & "b".|> & "b") ~~= "ab")
>        assert(("a" & "b".|> & "bb") !~~= "ab")
>        assert(("a" & "c".!|> & "b") ~~= "ab")
>        assert(("a" & "c".!|> & "c") !~~= "ac")
>
>        assert(("a" & "c".!<| & "b") ~~= "ab")
>        assert(("a" & "a".<| & "b") ~~= "ab")
>        assert(("a" & "a".!<| & "b") !~~= "ab")
>    }
>
>    def testCharClasses {
>        val alnum = CharAlpha \/ CharDigit
>        assert(alnum**0 ~~= "abc123")
>        val alpha = CharAlnum - CharDigit
>        assert(alpha**0 ~~= "abc")
>        assert(alpha**0 !~~= "abc123")
>    }
>
>    def testBoundaryPatterns {
>        assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>        assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>    }
> }
>
>
>
> Thanks,
> Ken
>
>

Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Closer, but still problems with maven an scalatest

David and Mikko,

Thanks for the changes, things are cleaner now but I'm still getting the same error. More interestingly, I get it even when I try just to do a Lifecycle:package maven target. So it's not a test problem at all but probably something wrong in my config somewhere. The Maven window does show org.scala-lang:scala-library:2.8.0 as a dependency, so that's not a problem. A lifecycle:compile does work. Do I need to add any other of the scala packages to get 'package' to work? My understanding is that package is built into maven, so I don't need to fiddle with the pom file to get it to work.

Sorry for leaning on people so heavily here, I'm recovering from a bug and don't have a lot of energy to be reading tons of documentation, even though I know I should. I just really want to get back to documenting my package :-) (I'm more of a tech writer than a programmer.)

Thanks,
Ken

On Sep 22, 2010, at 12:39 PM, Mikko Peltonen wrote:

> Hi Ken,
>
> Seems to work for me with two changes, one in pom and one in code:
>
> - Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
> http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite...)
> - Use @Test annotation in test methods, i.e.:
>
> import org.junit.Test
> import org.scalatest.junit.JUnitSuite
>
> class MySuite extends JUnitSuite {
> @Test def testOneIsOne() {
> assert(1 == 1)
> }
> }
>
> -Mikko-
>
>
> 2010/9/22 Kenneth McDonald :
>> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>>
>> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
>> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
>> java.lang.NoClassDefFoundError: scala/ScalaObject
>> at java.lang.ClassLoader.defineClass1(Native Method)
>> at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>> at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>> at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>> at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>>
>> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>>
>>
>> pom.xml:
>> ------------
>>
>> > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>> 4.0.0
>> your.proj.gid
>> rex
>> 1.0-SNAPSHOT
>> 2008
>>
>> 2.8.0
>>
>>
>>
>>
>> scala-tools.org
>> Scala-Tools Maven2 Repository
>> http://scala-tools.org/repo-releases
>>
>>
>>
>>
>>
>> snapshots.scala-tools.org
>> Scala-Tools Maven2 Repository - Snapshots
>> http://scala-tools.org/repo-snapshots
>>
>>
>>
>>
>>
>> org.scala-lang
>> scala-library
>> ${scala.version}
>>
>>
>> junit
>> junit
>> 3.8.1
>> test
>>
>>
>> org.scalatest
>> scalatest
>> 1.2
>> test
>>
>>
>>
>>
>>
>>
>>
>>
>> org.scala-tools
>> maven-scala-plugin
>> 2.14.2-SNAPSHOT
>>
>>
>> org.scala-tools
>> maven-scala-plugin
>>
>>
>>
>> compile
>> testCompile
>>
>>
>>
>>
>> ${scala.version}
>>
>>
>>
>> org.apache.maven.plugins
>> maven-eclipse-plugin
>>
>> true
>>
>> ch.epfl.lamp.sdt.core.scalabuilder
>>
>>
>> ch.epfl.lamp.sdt.core.scalanature
>>
>>
>> org.eclipse.jdt.launching.JRE_CONTAINER
>> ch.epfl.lamp.sdt.launching.SCALA_CONTAINER
>>
>>
>>
>>
>> org.apache.maven.plugins
>> maven-surefire-plugin
>> 2.6
>>
>>
>> **/*Test.*
>> **/*Suite.*
>>
>>
>>
>>
>>
>>
>>
>>
>> org.scala-tools
>> maven-scala-plugin
>> 2.14.2-SNAPSHOT
>>
>>
>>
>> src/main/scala
>> src/test/scala
>>
>>
>>
>>
>> org.scala-tools
>> maven-scala-plugin
>> 2.14.2-SNAPSHOT
>>
>>
>> org.scala-tools
>> maven-scala-plugin
>>
>> ${scala.version}
>>
>>
>>
>>
>>
>>
>>
>> My test file (RexSuite.scala):
>> --------------------------------------
>>
>> package ykken.testrex
>>
>> import org.scalatest.junit.JUnitSuite
>>
>> import ykken.rex._
>> import ykken.rex.patterns._
>> import ykken.rex.Implicits._
>> import scala._
>>
>> class RexSuite extends JUnitSuite {
>> def testMatchingOperators() {
>> assert("Hello" ~~= "Hello")
>> // ~~= denotes exact match
>> assert (!(Lit("Hello")~~="Hey, Hello"))
>> // ~= denotes match within the target string
>> assert(Lit("ello")~="Hello")
>> }
>>
>> def testEscaping() {
>> assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>> assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>> }
>>
>> def testCharSet() {
>> assert(CharSet("abc") ~= "cde")
>> assert(CharSet("abc") !~= "de")
>> // "Special" characters are internally escaped.
>> assert(CharSet("-") ~= "-")
>> assert((CharSet("abc") - CharSet("cde")) !~= "c")
>> assert((CharSet("abc") - "c") !~= "c")
>> assert((CharAny ** 0) ~~= "\na.,*")
>> assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>> }
>>
>> def testComplexFloatPat() {
>> // A complex is a float followed by a + or - followed by a float, followed by an "i"
>> // The two numeric parts and the sign are named for access.
>> val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>> /* Match against a floating-point complex number and print the result. */
>> val result = complexMatcher.findFirst("3.2+4.5i") match {
>> case None => None
>> case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>> }
>> assert(Some("3.2 + 4.5i") === result)
>> }
>>
>> def testBoundaryObjects() {
>> assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>> assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>> }
>>
>> def testCatchMisusedPlus() {
>> intercept[RuntimeException] {
>> (BndryStringStart + "a") !~~= "aaa"
>> }
>> intercept[RuntimeException] {
>> (BndryStringStart + BndryStringEnd) !~~= "aaa"
>> }
>> //Unfortunately, this works
>> assert("a" + BndryStringEnd != "b")
>> }
>>
>> def testHTMLTagPat() {
>> val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>> assert(tagPat ~~= "")
>> val minFind:String = tagPat.findFirst("
") match {
>> case None => ""
>> case Some(m) => m.group("tag")
>> }
>> assert(minFind === "
")
>> }
>>
>> def testFindAllIn() {
>> assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>> assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>> assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>> assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>> assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>> }
>>
>> def testReplaceAllIn() {
>> val tagPat = ""
>> val target = "HelloGoodbyeNow"
>> assert (tagPat.replaceAllIn(target, "") === "HelloGoodbyeNow")
>> }
>>
>> def testGrouping() {
>> assert("abc".anonGroup.pattern === "abc")
>> assert((CharSet("abc").pattern === "[abc]"))
>> assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>> assert("abc".lookahead.pattern === "(?=abc)")
>> assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>>
>> }
>>
>> def testLookaheadLookbackPatterns {
>> assert(("a" & "b".|> & "b") ~~= "ab")
>> assert(("a" & "b".|> & "bb") !~~= "ab")
>> assert(("a" & "c".!|> & "b") ~~= "ab")
>> assert(("a" & "c".!|> & "c") !~~= "ac")
>>
>> assert(("a" & "c".!<| & "b") ~~= "ab")
>> assert(("a" & "a".<| & "b") ~~= "ab")
>> assert(("a" & "a".!<| & "b") !~~= "ab")
>> }
>>
>> def testCharClasses {
>> val alnum = CharAlpha \/ CharDigit
>> assert(alnum**0 ~~= "abc123")
>> val alpha = CharAlnum - CharDigit
>> assert(alpha**0 ~~= "abc")
>> assert(alpha**0 !~~= "abc123")
>> }
>>
>> def testBoundaryPatterns {
>> assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>> assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>> }
>> }
>>
>>
>>
>> Thanks,
>> Ken
>>
>>

david.bernard
Joined: 2009-01-08,
User offline. Last seen 1 year 27 weeks ago.
Re: Closer, but still problems with maven an scalatest
May be your  scala-library jar is corrupted.try to remove $HOME/.m2/repository/org/scala-lang/*

On Wed, Sep 22, 2010 at 22:29, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David and Mikko,

Thanks for the changes, things are cleaner now but I'm still getting the same error. More interestingly, I get it even when I try just to do a Lifecycle:package maven target. So it's not a test problem at all but probably something wrong in my config somewhere. The Maven window does show org.scala-lang:scala-library:2.8.0 as a dependency, so that's not a problem. A lifecycle:compile does work. Do I need to add any other of the scala packages to get 'package' to work? My understanding is that package is built into maven, so I don't need to fiddle with the pom file to get it to work.

Sorry for leaning on people so heavily here, I'm recovering from a bug and don't have a lot of energy to be reading tons of documentation, even though I know I should. I just really want to get back to documenting my package :-) (I'm more of a tech writer than a programmer.)

Thanks,
Ken

On Sep 22, 2010, at 12:39 PM, Mikko Peltonen wrote:

> Hi Ken,
>
> Seems to work for me with two changes, one in pom and one in code:
>
> - Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
> http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite.html)
> - Use @Test annotation in test methods, i.e.:
>
> import org.junit.Test
> import org.scalatest.junit.JUnitSuite
>
> class MySuite extends JUnitSuite {
>  @Test def testOneIsOne() {
>    assert(1 == 1)
>  }
> }
>
> -Mikko-
>
>
> 2010/9/22 Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net>:
>> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>>
>> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
>> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
>> java.lang.NoClassDefFoundError: scala/ScalaObject
>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>>
>> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>>
>>
>> pom.xml:
>> ------------
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>>    <modelVersion>4.0.0</modelVersion>
>>    <groupId>your.proj.gid</groupId>
>>    <artifactId>rex</artifactId>
>>    <version>1.0-SNAPSHOT</version>
>>    <inceptionYear>2008</inceptionYear>
>>    <properties>
>>        <scala.version>2.8.0</scala.version>
>>    </properties>
>>
>>    <repositories>
>>        <repository>
>>            <id>scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository</name>
>>            <url>http://scala-tools.org/repo-releases</url>
>>        </repository>
>>    </repositories>
>>
>>    <pluginRepositories>
>>        <pluginRepository>
>>            <id>snapshots.scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository - Snapshots</name>
>>            <url>http://scala-tools.org/repo-snapshots</url>
>>        </pluginRepository>
>>    </pluginRepositories>
>>
>>    <dependencies>
>>        <dependency>
>>            <groupId>org.scala-lang</groupId>
>>            <artifactId>scala-library</artifactId>
>>            <version>${scala.version}</version>
>>        </dependency>
>>        <dependency>
>>            <groupId>junit</groupId>
>>            <artifactId>junit</artifactId>
>>            <version>3.8.1</version>
>>            <scope>test</scope>
>>        </dependency>
>>        <dependency>
>>            <groupId>org.scalatest</groupId>
>>            <artifactId>scalatest</artifactId>
>>            <version>1.2</version>
>>            <scope>test</scope>
>>        </dependency>
>>    </dependencies>
>>
>>    <build>
>>        <!-- To define the plugin version in your parent POM -->
>>        <pluginManagement>
>>            <plugins>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <version>2.14.2-SNAPSHOT</version>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <executions>
>>                        <execution>
>>                            <goals>
>>                                <goal>compile</goal>
>>                                <goal>testCompile</goal>
>>                            </goals>
>>                        </execution>
>>                    </executions>
>>                    <configuration>
>>                        <scalaVersion>${scala.version}</scalaVersion>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-eclipse-plugin</artifactId>
>>                    <configuration>
>>                        <downloadSources>true</downloadSources>
>>                        <buildcommands>
>>                            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
>>                        </buildcommands>
>>                        <additionalProjectnatures>
>>                            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
>>                        </additionalProjectnatures>
>>                        <classpathContainers>
>>                            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
>>                            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
>>                        </classpathContainers>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-surefire-plugin</artifactId>
>>                    <version>2.6</version>
>>                    <configuration>
>>                        <includes>
>>                            <include>**/*Test.*</include>
>>                            <include>**/*Suite.*</include>
>>                        </includes>
>>                    </configuration>
>>                </plugin>
>>            </plugins>
>>        </pluginManagement>
>>        <!-- To use the plugin goals in your POM or parent POM -->
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>        </plugins>
>>        <!-- To use the report goals in your POM or parent POM -->
>>        <sourceDirectory>src/main/scala</sourceDirectory>
>>        <testSourceDirectory>src/test/scala</testSourceDirectory>
>>    </build>
>>    <reporting>
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <configuration>
>>                    <scalaVersion>${scala.version}</scalaVersion>
>>                </configuration>
>>            </plugin>
>>        </plugins>
>>    </reporting>
>> </project>
>>
>>
>> My test file (RexSuite.scala):
>> --------------------------------------
>>
>> package ykken.testrex
>>
>> import org.scalatest.junit.JUnitSuite
>>
>> import ykken.rex._
>> import ykken.rex.patterns._
>> import ykken.rex.Implicits._
>> import scala._
>>
>> class RexSuite extends JUnitSuite {
>>    def testMatchingOperators() {
>>        assert("Hello" ~~= "Hello")
>>        // ~~= denotes exact match
>>        assert (!(Lit("Hello")~~="Hey, Hello"))
>>        // ~= denotes match within the target string
>>        assert(Lit("ello")~="Hello")
>>    }
>>
>>    def testEscaping() {
>>        assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>>        assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>>    }
>>
>>    def testCharSet() {
>>        assert(CharSet("abc") ~= "cde")
>>        assert(CharSet("abc") !~= "de")
>>        // "Special" characters are internally escaped.
>>        assert(CharSet("-") ~= "-")
>>        assert((CharSet("abc") - CharSet("cde")) !~= "c")
>>        assert((CharSet("abc") - "c") !~= "c")
>>        assert((CharAny ** 0) ~~= "\na.,*")
>>        assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>>    }
>>
>>    def testComplexFloatPat() {
>>        // A complex is a float followed by a + or - followed by a float, followed by an "i"
>>        // The two numeric parts and the sign are named for access.
>>        val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>>        /* Match against a floating-point complex number and print the result. */
>>        val result = complexMatcher.findFirst("3.2+4.5i") match {
>>            case None => None
>>            case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>>        }
>>        assert(Some("3.2 + 4.5i") === result)
>>    }
>>
>>    def testBoundaryObjects() {
>>        assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>>        assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>>    }
>>
>>    def testCatchMisusedPlus() {
>>        intercept[RuntimeException] {
>>          (BndryStringStart + "a") !~~= "aaa"
>>        }
>>        intercept[RuntimeException] {
>>          (BndryStringStart + BndryStringEnd) !~~= "aaa"
>>        }
>>        //Unfortunately, this works
>>        assert("a" + BndryStringEnd != "b")
>>    }
>>
>>    def testHTMLTagPat() {
>>        val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>>        assert(tagPat ~~= "<a count=0>")
>>        val minFind:String = tagPat.findFirst("<a><b>") match {
>>            case None => ""
>>            case Some(m) => m.group("tag")
>>        }
>>        assert(minFind === "<a>")
>>    }
>>
>>    def testFindAllIn() {
>>        assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>>        assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>>    }
>>
>>    def testReplaceAllIn() {
>>        val tagPat = "<td" & PatMinChars & ">"
>>        val target = "Hello<td style='color:#000'>Goodbye<td >Now"
>>        assert (tagPat.replaceAllIn(target, "<td>") === "Hello<td>Goodbye<td>Now")
>>    }
>>
>>    def testGrouping() {
>>        assert("abc".anonGroup.pattern === "abc")
>>        assert((CharSet("abc").pattern === "[abc]"))
>>        assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>>        assert("abc".lookahead.pattern === "(?=abc)")
>>        assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>>
>>    }
>>
>>    def testLookaheadLookbackPatterns {
>>        assert(("a" & "b".|> & "b") ~~= "ab")
>>        assert(("a" & "b".|> & "bb") !~~= "ab")
>>        assert(("a" & "c".!|> & "b") ~~= "ab")
>>        assert(("a" & "c".!|> & "c") !~~= "ac")
>>
>>        assert(("a" & "c".!<| & "b") ~~= "ab")
>>        assert(("a" & "a".<| & "b") ~~= "ab")
>>        assert(("a" & "a".!<| & "b") !~~= "ab")
>>    }
>>
>>    def testCharClasses {
>>        val alnum = CharAlpha \/ CharDigit
>>        assert(alnum**0 ~~= "abc123")
>>        val alpha = CharAlnum - CharDigit
>>        assert(alpha**0 ~~= "abc")
>>        assert(alpha**0 !~~= "abc123")
>>    }
>>
>>    def testBoundaryPatterns {
>>        assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>>        assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>>    }
>> }
>>
>>
>>
>> Thanks,
>> Ken
>>
>>


Kenneth McDonald
Joined: 2009-01-11,
User offline. Last seen 42 years 45 weeks ago.
Re: Closer, but still problems with maven an scalatest
David,
Thanks, that's a neat trick and I'll have to remember it, but it didn't solve the problem :-(. Still getting:
[INFO] Nothing to compile - all classes are up to date[INFO] [surefire:test {execution: default-test}][INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reportsorg.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObjectjava.lang.NoClassDefFoundError: scala/ScalaObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197)...
Oops, hadn't noticed before that package does a call to test, so it probably is a test problem
Some googling revealed that in a previous release of Scala, people were also encountering this error in Maven builds, and that it seemed to have to do with binary incompatibilities between various versions of things. But AFAIK I'm using the recommended versions:
Scala 2.8.0junit 4.8.1scalatest 1.2maven-scala-plugin 2.14.2-SNAPSHOT //Maybe this is the problem? Should I be using a snapshot?maven-surefire-plugin 2.6
Anything look wrong there?
Yours confusedly :-(Ken

On Sep 22, 2010, at 3:53 PM, David Bernard wrote:
May be your  scala-library jar is corrupted.try to remove $HOME/.m2/repository/org/scala-lang/*

On Wed, Sep 22, 2010 at 22:29, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David and Mikko,

Thanks for the changes, things are cleaner now but I'm still getting the same error. More interestingly, I get it even when I try just to do a Lifecycle:package maven target. So it's not a test problem at all but probably something wrong in my config somewhere. The Maven window does show org.scala-lang:scala-library:2.8.0 as a dependency, so that's not a problem. A lifecycle:compile does work. Do I need to add any other of the scala packages to get 'package' to work? My understanding is that package is built into maven, so I don't need to fiddle with the pom file to get it to work.

Sorry for leaning on people so heavily here, I'm recovering from a bug and don't have a lot of energy to be reading tons of documentation, even though I know I should. I just really want to get back to documenting my package :-) (I'm more of a tech writer than a programmer.)

Thanks,
Ken

On Sep 22, 2010, at 12:39 PM, Mikko Peltonen wrote:

> Hi Ken,
>
> Seems to work for me with two changes, one in pom and one in code:
>
> - Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
> http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite.html)
> - Use @Test annotation in test methods, i.e.:
>
> import org.junit.Test
> import org.scalatest.junit.JUnitSuite
>
> class MySuite extends JUnitSuite {
>  @Test def testOneIsOne() {
>    assert(1 == 1)
>  }
> }
>
> -Mikko-
>
>
> 2010/9/22 Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net>:
>> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>>
>> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
>> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
>> java.lang.NoClassDefFoundError: scala/ScalaObject
>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>>
>> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>>
>>
>> pom.xml:
>> ------------
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>>    <modelVersion>4.0.0</modelVersion>
>>    <groupId>your.proj.gid</groupId>
>>    <artifactId>rex</artifactId>
>>    <version>1.0-SNAPSHOT</version>
>>    <inceptionYear>2008</inceptionYear>
>>    <properties>
>>        <scala.version>2.8.0</scala.version>
>>    </properties>
>>
>>    <repositories>
>>        <repository>
>>            <id>scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository</name>
>>            <url>http://scala-tools.org/repo-releases</url>
>>        </repository>
>>    </repositories>
>>
>>    <pluginRepositories>
>>        <pluginRepository>
>>            <id>snapshots.scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository - Snapshots</name>
>>            <url>http://scala-tools.org/repo-snapshots</url>
>>        </pluginRepository>
>>    </pluginRepositories>
>>
>>    <dependencies>
>>        <dependency>
>>            <groupId>org.scala-lang</groupId>
>>            <artifactId>scala-library</artifactId>
>>            <version>${scala.version}</version>
>>        </dependency>
>>        <dependency>
>>            <groupId>junit</groupId>
>>            <artifactId>junit</artifactId>
>>            <version>3.8.1</version>
>>            <scope>test</scope>
>>        </dependency>
>>        <dependency>
>>            <groupId>org.scalatest</groupId>
>>            <artifactId>scalatest</artifactId>
>>            <version>1.2</version>
>>            <scope>test</scope>
>>        </dependency>
>>    </dependencies>
>>
>>    <build>
>>        <!-- To define the plugin version in your parent POM -->
>>        <pluginManagement>
>>            <plugins>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <version>2.14.2-SNAPSHOT</version>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <executions>
>>                        <execution>
>>                            <goals>
>>                                <goal>compile</goal>
>>                                <goal>testCompile</goal>
>>                            </goals>
>>                        </execution>
>>                    </executions>
>>                    <configuration>
>>                        <scalaVersion>${scala.version}</scalaVersion>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-eclipse-plugin</artifactId>
>>                    <configuration>
>>                        <downloadSources>true</downloadSources>
>>                        <buildcommands>
>>                            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
>>                        </buildcommands>
>>                        <additionalProjectnatures>
>>                            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
>>                        </additionalProjectnatures>
>>                        <classpathContainers>
>>                            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
>>                            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
>>                        </classpathContainers>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-surefire-plugin</artifactId>
>>                    <version>2.6</version>
>>                    <configuration>
>>                        <includes>
>>                            <include>**/*Test.*</include>
>>                            <include>**/*Suite.*</include>
>>                        </includes>
>>                    </configuration>
>>                </plugin>
>>            </plugins>
>>        </pluginManagement>
>>        <!-- To use the plugin goals in your POM or parent POM -->
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>        </plugins>
>>        <!-- To use the report goals in your POM or parent POM -->
>>        <sourceDirectory>src/main/scala</sourceDirectory>
>>        <testSourceDirectory>src/test/scala</testSourceDirectory>
>>    </build>
>>    <reporting>
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <configuration>
>>                    <scalaVersion>${scala.version}</scalaVersion>
>>                </configuration>
>>            </plugin>
>>        </plugins>
>>    </reporting>
>> </project>
>>
>>
>> My test file (RexSuite.scala):
>> --------------------------------------
>>
>> package ykken.testrex
>>
>> import org.scalatest.junit.JUnitSuite
>>
>> import ykken.rex._
>> import ykken.rex.patterns._
>> import ykken.rex.Implicits._
>> import scala._
>>
>> class RexSuite extends JUnitSuite {
>>    def testMatchingOperators() {
>>        assert("Hello" ~~= "Hello")
>>        // ~~= denotes exact match
>>        assert (!(Lit("Hello")~~="Hey, Hello"))
>>        // ~= denotes match within the target string
>>        assert(Lit("ello")~="Hello")
>>    }
>>
>>    def testEscaping() {
>>        assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>>        assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>>    }
>>
>>    def testCharSet() {
>>        assert(CharSet("abc") ~= "cde")
>>        assert(CharSet("abc") !~= "de")
>>        // "Special" characters are internally escaped.
>>        assert(CharSet("-") ~= "-")
>>        assert((CharSet("abc") - CharSet("cde")) !~= "c")
>>        assert((CharSet("abc") - "c") !~= "c")
>>        assert((CharAny ** 0) ~~= "\na.,*")
>>        assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>>    }
>>
>>    def testComplexFloatPat() {
>>        // A complex is a float followed by a + or - followed by a float, followed by an "i"
>>        // The two numeric parts and the sign are named for access.
>>        val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>>        /* Match against a floating-point complex number and print the result. */
>>        val result = complexMatcher.findFirst("3.2+4.5i") match {
>>            case None => None
>>            case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>>        }
>>        assert(Some("3.2 + 4.5i") === result)
>>    }
>>
>>    def testBoundaryObjects() {
>>        assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>>        assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>>    }
>>
>>    def testCatchMisusedPlus() {
>>        intercept[RuntimeException] {
>>          (BndryStringStart + "a") !~~= "aaa"
>>        }
>>        intercept[RuntimeException] {
>>          (BndryStringStart + BndryStringEnd) !~~= "aaa"
>>        }
>>        //Unfortunately, this works
>>        assert("a" + BndryStringEnd != "b")
>>    }
>>
>>    def testHTMLTagPat() {
>>        val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>>        assert(tagPat ~~= "<a count=0>")
>>        val minFind:String = tagPat.findFirst("<a><b>") match {
>>            case None => ""
>>            case Some(m) => m.group("tag")
>>        }
>>        assert(minFind === "<a>")
>>    }
>>
>>    def testFindAllIn() {
>>        assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>>        assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>>    }
>>
>>    def testReplaceAllIn() {
>>        val tagPat = "<td" & PatMinChars & ">"
>>        val target = "Hello<td style='color:#000'>Goodbye<td >Now"
>>        assert (tagPat.replaceAllIn(target, "<td>") === "Hello<td>Goodbye<td>Now")
>>    }
>>
>>    def testGrouping() {
>>        assert("abc".anonGroup.pattern === "abc")
>>        assert((CharSet("abc").pattern === "[abc]"))
>>        assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>>        assert("abc".lookahead.pattern === "(?=abc)")
>>        assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>>
>>    }
>>
>>    def testLookaheadLookbackPatterns {
>>        assert(("a" & "b".|> & "b") ~~= "ab")
>>        assert(("a" & "b".|> & "bb") !~~= "ab")
>>        assert(("a" & "c".!|> & "b") ~~= "ab")
>>        assert(("a" & "c".!|> & "c") !~~= "ac")
>>
>>        assert(("a" & "c".!<| & "b") ~~= "ab")
>>        assert(("a" & "a".<| & "b") ~~= "ab")
>>        assert(("a" & "a".!<| & "b") !~~= "ab")
>>    }
>>
>>    def testCharClasses {
>>        val alnum = CharAlpha \/ CharDigit
>>        assert(alnum**0 ~~= "abc123")
>>        val alpha = CharAlnum - CharDigit
>>        assert(alpha**0 ~~= "abc")
>>        assert(alpha**0 !~~= "abc123")
>>    }
>>
>>    def testBoundaryPatterns {
>>        assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>>        assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>>    }
>> }
>>
>>
>>
>> Thanks,
>> Ken
>>
>>



david.bernard
Joined: 2009-01-08,
User offline. Last seen 1 year 27 weeks ago.
Re: Closer, but still problems with maven an scalatest
Kenneth,
could you try to run the attached project with "mvn clean test" ?It works (for me with maven 3.0-beta-3 and maven 2.2.1)
---Apache Maven 3.0-beta-3 (r990787; 2010-08-30 14:44:03+0200) Java version: 1.6.0_20Java home: /home/dwayne/bin/soft-linux-x86-64/jdk1.6.0_20/jreDefault locale: fr_FR, platform encoding: UTF-8OS name: "linux" version: "2.6.35-arch" arch: "amd64" Family: "unix" --Apache Maven 2.2.1 (r801777; 2009-08-06 21:16:01+0200)Java version: 1.6.0_21Java home: /opt/java/jreDefault locale: fr_FR, platform encoding: UTF-8OS name: "linux" version: "2.6.35-arch" arch: "amd64" Family: "unix" --
On Thu, Sep 23, 2010 at 00:52, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David,
Thanks, that's a neat trick and I'll have to remember it, but it didn't solve the problem :-(. Still getting:
[INFO] Nothing to compile - all classes are up to date [INFO] [surefire:test {execution: default-test}][INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reportsorg.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject java.lang.NoClassDefFoundError: scala/ScalaObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197)...
Oops, hadn't noticed before that package does a call to test, so it probably is a test problem
Some googling revealed that in a previous release of Scala, people were also encountering this error in Maven builds, and that it seemed to have to do with binary incompatibilities between various versions of things. But AFAIK I'm using the recommended versions:
Scala 2.8.0junit 4.8.1scalatest 1.2maven-scala-plugin 2.14.2-SNAPSHOT //Maybe this is the problem? Should I be using a snapshot?maven-surefire-plugin 2.6
Anything look wrong there?
Yours confusedly :-(Ken

On Sep 22, 2010, at 3:53 PM, David Bernard wrote:
May be your  scala-library jar is corrupted.try to remove $HOME/.m2/repository/org/scala-lang/*

On Wed, Sep 22, 2010 at 22:29, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David and Mikko,

Thanks for the changes, things are cleaner now but I'm still getting the same error. More interestingly, I get it even when I try just to do a Lifecycle:package maven target. So it's not a test problem at all but probably something wrong in my config somewhere. The Maven window does show org.scala-lang:scala-library:2.8.0 as a dependency, so that's not a problem. A lifecycle:compile does work. Do I need to add any other of the scala packages to get 'package' to work? My understanding is that package is built into maven, so I don't need to fiddle with the pom file to get it to work.

Sorry for leaning on people so heavily here, I'm recovering from a bug and don't have a lot of energy to be reading tons of documentation, even though I know I should. I just really want to get back to documenting my package :-) (I'm more of a tech writer than a programmer.)

Thanks,
Ken

On Sep 22, 2010, at 12:39 PM, Mikko Peltonen wrote:

> Hi Ken,
>
> Seems to work for me with two changes, one in pom and one in code:
>
> - Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
> http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite.html)
> - Use @Test annotation in test methods, i.e.:
>
> import org.junit.Test
> import org.scalatest.junit.JUnitSuite
>
> class MySuite extends JUnitSuite {
>  @Test def testOneIsOne() {
>    assert(1 == 1)
>  }
> }
>
> -Mikko-
>
>
> 2010/9/22 Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net>:
>> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>>
>> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
>> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
>> java.lang.NoClassDefFoundError: scala/ScalaObject
>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>>
>> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>>
>>
>> pom.xml:
>> ------------
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>>    <modelVersion>4.0.0</modelVersion>
>>    <groupId>your.proj.gid</groupId>
>>    <artifactId>rex</artifactId>
>>    <version>1.0-SNAPSHOT</version>
>>    <inceptionYear>2008</inceptionYear>
>>    <properties>
>>        <scala.version>2.8.0</scala.version>
>>    </properties>
>>
>>    <repositories>
>>        <repository>
>>            <id>scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository</name>
>>            <url>http://scala-tools.org/repo-releases</url>
>>        </repository>
>>    </repositories>
>>
>>    <pluginRepositories>
>>        <pluginRepository>
>>            <id>snapshots.scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository - Snapshots</name>
>>            <url>http://scala-tools.org/repo-snapshots</url>
>>        </pluginRepository>
>>    </pluginRepositories>
>>
>>    <dependencies>
>>        <dependency>
>>            <groupId>org.scala-lang</groupId>
>>            <artifactId>scala-library</artifactId>
>>            <version>${scala.version}</version>
>>        </dependency>
>>        <dependency>
>>            <groupId>junit</groupId>
>>            <artifactId>junit</artifactId>
>>            <version>3.8.1</version>
>>            <scope>test</scope>
>>        </dependency>
>>        <dependency>
>>            <groupId>org.scalatest</groupId>
>>            <artifactId>scalatest</artifactId>
>>            <version>1.2</version>
>>            <scope>test</scope>
>>        </dependency>
>>    </dependencies>
>>
>>    <build>
>>        <!-- To define the plugin version in your parent POM -->
>>        <pluginManagement>
>>            <plugins>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <version>2.14.2-SNAPSHOT</version>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <executions>
>>                        <execution>
>>                            <goals>
>>                                <goal>compile</goal>
>>                                <goal>testCompile</goal>
>>                            </goals>
>>                        </execution>
>>                    </executions>
>>                    <configuration>
>>                        <scalaVersion>${scala.version}</scalaVersion>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-eclipse-plugin</artifactId>
>>                    <configuration>
>>                        <downloadSources>true</downloadSources>
>>                        <buildcommands>
>>                            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
>>                        </buildcommands>
>>                        <additionalProjectnatures>
>>                            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
>>                        </additionalProjectnatures>
>>                        <classpathContainers>
>>                            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
>>                            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
>>                        </classpathContainers>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-surefire-plugin</artifactId>
>>                    <version>2.6</version>
>>                    <configuration>
>>                        <includes>
>>                            <include>**/*Test.*</include>
>>                            <include>**/*Suite.*</include>
>>                        </includes>
>>                    </configuration>
>>                </plugin>
>>            </plugins>
>>        </pluginManagement>
>>        <!-- To use the plugin goals in your POM or parent POM -->
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>        </plugins>
>>        <!-- To use the report goals in your POM or parent POM -->
>>        <sourceDirectory>src/main/scala</sourceDirectory>
>>        <testSourceDirectory>src/test/scala</testSourceDirectory>
>>    </build>
>>    <reporting>
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <configuration>
>>                    <scalaVersion>${scala.version}</scalaVersion>
>>                </configuration>
>>            </plugin>
>>        </plugins>
>>    </reporting>
>> </project>
>>
>>
>> My test file (RexSuite.scala):
>> --------------------------------------
>>
>> package ykken.testrex
>>
>> import org.scalatest.junit.JUnitSuite
>>
>> import ykken.rex._
>> import ykken.rex.patterns._
>> import ykken.rex.Implicits._
>> import scala._
>>
>> class RexSuite extends JUnitSuite {
>>    def testMatchingOperators() {
>>        assert("Hello" ~~= "Hello")
>>        // ~~= denotes exact match
>>        assert (!(Lit("Hello")~~="Hey, Hello"))
>>        // ~= denotes match within the target string
>>        assert(Lit("ello")~="Hello")
>>    }
>>
>>    def testEscaping() {
>>        assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>>        assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>>    }
>>
>>    def testCharSet() {
>>        assert(CharSet("abc") ~= "cde")
>>        assert(CharSet("abc") !~= "de")
>>        // "Special" characters are internally escaped.
>>        assert(CharSet("-") ~= "-")
>>        assert((CharSet("abc") - CharSet("cde")) !~= "c")
>>        assert((CharSet("abc") - "c") !~= "c")
>>        assert((CharAny ** 0) ~~= "\na.,*")
>>        assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>>    }
>>
>>    def testComplexFloatPat() {
>>        // A complex is a float followed by a + or - followed by a float, followed by an "i"
>>        // The two numeric parts and the sign are named for access.
>>        val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>>        /* Match against a floating-point complex number and print the result. */
>>        val result = complexMatcher.findFirst("3.2+4.5i") match {
>>            case None => None
>>            case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>>        }
>>        assert(Some("3.2 + 4.5i") === result)
>>    }
>>
>>    def testBoundaryObjects() {
>>        assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>>        assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>>    }
>>
>>    def testCatchMisusedPlus() {
>>        intercept[RuntimeException] {
>>          (BndryStringStart + "a") !~~= "aaa"
>>        }
>>        intercept[RuntimeException] {
>>          (BndryStringStart + BndryStringEnd) !~~= "aaa"
>>        }
>>        //Unfortunately, this works
>>        assert("a" + BndryStringEnd != "b")
>>    }
>>
>>    def testHTMLTagPat() {
>>        val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>>        assert(tagPat ~~= "<a count=0>")
>>        val minFind:String = tagPat.findFirst("<a><b>") match {
>>            case None => ""
>>            case Some(m) => m.group("tag")
>>        }
>>        assert(minFind === "<a>")
>>    }
>>
>>    def testFindAllIn() {
>>        assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>>        assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>>    }
>>
>>    def testReplaceAllIn() {
>>        val tagPat = "<td" & PatMinChars & ">"
>>        val target = "Hello<td style='color:#000'>Goodbye<td >Now"
>>        assert (tagPat.replaceAllIn(target, "<td>") === "Hello<td>Goodbye<td>Now")
>>    }
>>
>>    def testGrouping() {
>>        assert("abc".anonGroup.pattern === "abc")
>>        assert((CharSet("abc").pattern === "[abc]"))
>>        assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>>        assert("abc".lookahead.pattern === "(?=abc)")
>>        assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>>
>>    }
>>
>>    def testLookaheadLookbackPatterns {
>>        assert(("a" & "b".|> & "b") ~~= "ab")
>>        assert(("a" & "b".|> & "bb") !~~= "ab")
>>        assert(("a" & "c".!|> & "b") ~~= "ab")
>>        assert(("a" & "c".!|> & "c") !~~= "ac")
>>
>>        assert(("a" & "c".!<| & "b") ~~= "ab")
>>        assert(("a" & "a".<| & "b") ~~= "ab")
>>        assert(("a" & "a".!<| & "b") !~~= "ab")
>>    }
>>
>>    def testCharClasses {
>>        val alnum = CharAlpha \/ CharDigit
>>        assert(alnum**0 ~~= "abc123")
>>        val alpha = CharAlnum - CharDigit
>>        assert(alpha**0 ~~= "abc")
>>        assert(alpha**0 !~~= "abc123")
>>    }
>>
>>    def testBoundaryPatterns {
>>        assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>>        assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>>    }
>> }
>>
>>
>>
>> Thanks,
>> Ken
>>
>>




Stephen Tu
Joined: 2010-02-24,
User offline. Last seen 42 years 45 weeks ago.
Re: Closer, but still problems with maven an scalatest
kenneth:

several suggestions

(1) make sure you are doing clean tests. as in `mvn clean test`
(2) use maven.scala.displayCmd=true to have the maven-scala-plugin print the entire command used, so that you can see the classpaths are what you expect. also you can use the maven dependency plugin (http://maven.apache.org/plugins/maven-dependency-plugin/plugin-info.html) to analyze the dependencies of your project, to make sure you're not pulling in a version of scala that is incompatible

On Wed, Sep 22, 2010 at 3:52 PM, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David,
Thanks, that's a neat trick and I'll have to remember it, but it didn't solve the problem :-(. Still getting:
[INFO] Nothing to compile - all classes are up to date [INFO] [surefire:test {execution: default-test}][INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reportsorg.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject java.lang.NoClassDefFoundError: scala/ScalaObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197)...
Oops, hadn't noticed before that package does a call to test, so it probably is a test problem
Some googling revealed that in a previous release of Scala, people were also encountering this error in Maven builds, and that it seemed to have to do with binary incompatibilities between various versions of things. But AFAIK I'm using the recommended versions:
Scala 2.8.0junit 4.8.1scalatest 1.2maven-scala-plugin 2.14.2-SNAPSHOT //Maybe this is the problem? Should I be using a snapshot?maven-surefire-plugin 2.6
Anything look wrong there?
Yours confusedly :-(Ken

On Sep 22, 2010, at 3:53 PM, David Bernard wrote:
May be your  scala-library jar is corrupted.try to remove $HOME/.m2/repository/org/scala-lang/*

On Wed, Sep 22, 2010 at 22:29, Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net> wrote:
David and Mikko,

Thanks for the changes, things are cleaner now but I'm still getting the same error. More interestingly, I get it even when I try just to do a Lifecycle:package maven target. So it's not a test problem at all but probably something wrong in my config somewhere. The Maven window does show org.scala-lang:scala-library:2.8.0 as a dependency, so that's not a problem. A lifecycle:compile does work. Do I need to add any other of the scala packages to get 'package' to work? My understanding is that package is built into maven, so I don't need to fiddle with the pom file to get it to work.

Sorry for leaning on people so heavily here, I'm recovering from a bug and don't have a lot of energy to be reading tons of documentation, even though I know I should. I just really want to get back to documenting my package :-) (I'm more of a tech writer than a programmer.)

Thanks,
Ken

On Sep 22, 2010, at 12:39 PM, Mikko Peltonen wrote:

> Hi Ken,
>
> Seems to work for me with two changes, one in pom and one in code:
>
> - Use junit 4.8.1 (ScalaTest is compatble with junit 4, not 3:
> http://www.scalatest.org/scaladoc/doc-1.2/org/scalatest/junit/JUnitSuite.html)
> - Use @Test annotation in test methods, i.e.:
>
> import org.junit.Test
> import org.scalatest.junit.JUnitSuite
>
> class MySuite extends JUnitSuite {
>  @Test def testOneIsOne() {
>    assert(1 == 1)
>  }
> }
>
> -Mikko-
>
>
> 2010/9/22 Kenneth McDonald <kenneth [dot] m [dot] mcdonald [at] sbcglobal [dot] net>:
>> The many thanks to David Bernard, and encouragement from others, I've decided to continue on with Maven. It's making a bit more sense now (still seems very verbose :-) ), but I'm having a problem with my test run, which I suspect will be obvious to those In The Know. I've appended my pom.xml file, and RexSuite.scala test file below, for reference. The problem reported on the console is:
>>
>> [INFO] Surefire report directory: /Users/Ken/mvn_projects/rex/target/surefire-reports
>> org.apache.maven.surefire.booter.SurefireExecutionException: scala/ScalaObject; nested exception is java.lang.NoClassDefFoundError: scala/ScalaObject
>> java.lang.NoClassDefFoundError: scala/ScalaObject
>>        at java.lang.ClassLoader.defineClass1(Native Method)
>>        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
>>        at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
>>        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
>>        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
>>
>> ClassLoader stuff is black magic to me, but I'm guessing there's simply somewhere I need to let something know about scala. But I don't know if thats in the pom.xml, my test code, or elsewhere.
>>
>>
>> pom.xml:
>> ------------
>>
>> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>>    <modelVersion>4.0.0</modelVersion>
>>    <groupId>your.proj.gid</groupId>
>>    <artifactId>rex</artifactId>
>>    <version>1.0-SNAPSHOT</version>
>>    <inceptionYear>2008</inceptionYear>
>>    <properties>
>>        <scala.version>2.8.0</scala.version>
>>    </properties>
>>
>>    <repositories>
>>        <repository>
>>            <id>scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository</name>
>>            <url>http://scala-tools.org/repo-releases</url>
>>        </repository>
>>    </repositories>
>>
>>    <pluginRepositories>
>>        <pluginRepository>
>>            <id>snapshots.scala-tools.org</id>
>>            <name>Scala-Tools Maven2 Repository - Snapshots</name>
>>            <url>http://scala-tools.org/repo-snapshots</url>
>>        </pluginRepository>
>>    </pluginRepositories>
>>
>>    <dependencies>
>>        <dependency>
>>            <groupId>org.scala-lang</groupId>
>>            <artifactId>scala-library</artifactId>
>>            <version>${scala.version}</version>
>>        </dependency>
>>        <dependency>
>>            <groupId>junit</groupId>
>>            <artifactId>junit</artifactId>
>>            <version>3.8.1</version>
>>            <scope>test</scope>
>>        </dependency>
>>        <dependency>
>>            <groupId>org.scalatest</groupId>
>>            <artifactId>scalatest</artifactId>
>>            <version>1.2</version>
>>            <scope>test</scope>
>>        </dependency>
>>    </dependencies>
>>
>>    <build>
>>        <!-- To define the plugin version in your parent POM -->
>>        <pluginManagement>
>>            <plugins>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <version>2.14.2-SNAPSHOT</version>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.scala-tools</groupId>
>>                    <artifactId>maven-scala-plugin</artifactId>
>>                    <executions>
>>                        <execution>
>>                            <goals>
>>                                <goal>compile</goal>
>>                                <goal>testCompile</goal>
>>                            </goals>
>>                        </execution>
>>                    </executions>
>>                    <configuration>
>>                        <scalaVersion>${scala.version}</scalaVersion>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-eclipse-plugin</artifactId>
>>                    <configuration>
>>                        <downloadSources>true</downloadSources>
>>                        <buildcommands>
>>                            <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
>>                        </buildcommands>
>>                        <additionalProjectnatures>
>>                            <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
>>                        </additionalProjectnatures>
>>                        <classpathContainers>
>>                            <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
>>                            <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
>>                        </classpathContainers>
>>                    </configuration>
>>                </plugin>
>>                <plugin>
>>                    <groupId>org.apache.maven.plugins</groupId>
>>                    <artifactId>maven-surefire-plugin</artifactId>
>>                    <version>2.6</version>
>>                    <configuration>
>>                        <includes>
>>                            <include>**/*Test.*</include>
>>                            <include>**/*Suite.*</include>
>>                        </includes>
>>                    </configuration>
>>                </plugin>
>>            </plugins>
>>        </pluginManagement>
>>        <!-- To use the plugin goals in your POM or parent POM -->
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>        </plugins>
>>        <!-- To use the report goals in your POM or parent POM -->
>>        <sourceDirectory>src/main/scala</sourceDirectory>
>>        <testSourceDirectory>src/test/scala</testSourceDirectory>
>>    </build>
>>    <reporting>
>>        <plugins>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <version>2.14.2-SNAPSHOT</version>
>>            </plugin>
>>            <plugin>
>>                <groupId>org.scala-tools</groupId>
>>                <artifactId>maven-scala-plugin</artifactId>
>>                <configuration>
>>                    <scalaVersion>${scala.version}</scalaVersion>
>>                </configuration>
>>            </plugin>
>>        </plugins>
>>    </reporting>
>> </project>
>>
>>
>> My test file (RexSuite.scala):
>> --------------------------------------
>>
>> package ykken.testrex
>>
>> import org.scalatest.junit.JUnitSuite
>>
>> import ykken.rex._
>> import ykken.rex.patterns._
>> import ykken.rex.Implicits._
>> import scala._
>>
>> class RexSuite extends JUnitSuite {
>>    def testMatchingOperators() {
>>        assert("Hello" ~~= "Hello")
>>        // ~~= denotes exact match
>>        assert (!(Lit("Hello")~~="Hey, Hello"))
>>        // ~= denotes match within the target string
>>        assert(Lit("ello")~="Hello")
>>    }
>>
>>    def testEscaping() {
>>        assert(Lit("[]^$\\.{,}|+*?") ~~= "[]^$\\.{,}|+*?")
>>        assert(CharSet("[]-^&\\.{}")**0 ~~= "[]-^&\\.{}")
>>    }
>>
>>    def testCharSet() {
>>        assert(CharSet("abc") ~= "cde")
>>        assert(CharSet("abc") !~= "de")
>>        // "Special" characters are internally escaped.
>>        assert(CharSet("-") ~= "-")
>>        assert((CharSet("abc") - CharSet("cde")) !~= "c")
>>        assert((CharSet("abc") - "c") !~= "c")
>>        assert((CharAny ** 0) ~~= "\na.,*")
>>        assert("[\\s\\S&&[^\\p{ASCII}]]" === (CharAny - CharASCII).pattern)
>>    }
>>
>>    def testComplexFloatPat() {
>>        // A complex is a float followed by a + or - followed by a float, followed by an "i"
>>        // The two numeric parts and the sign are named for access.
>>        val complexMatcher = (PatFloat.group("re") & ("-"|"+").group("sign") & PatFloat.group("im") & "i").group("all")
>>        /* Match against a floating-point complex number and print the result. */
>>        val result = complexMatcher.findFirst("3.2+4.5i") match {
>>            case None => None
>>            case Some(m) => Some(m.group("re") + " " + m.group("sign") + " " + m.group("im") + "i")
>>        }
>>        assert(Some("3.2 + 4.5i") === result)
>>    }
>>
>>    def testBoundaryObjects() {
>>        assert(BndryStringStart & Lit("a")**0 & BndryStringEnd ~~= "aaa")
>>        assert(BndryStringStart & Lit("a")**(0,2) & BndryStringEnd !~~= "aaa")
>>    }
>>
>>    def testCatchMisusedPlus() {
>>        intercept[RuntimeException] {
>>          (BndryStringStart + "a") !~~= "aaa"
>>        }
>>        intercept[RuntimeException] {
>>          (BndryStringStart + BndryStringEnd) !~~= "aaa"
>>        }
>>        //Unfortunately, this works
>>        assert("a" + BndryStringEnd != "b")
>>    }
>>
>>    def testHTMLTagPat() {
>>        val tagPat = ("<" & CharAny *? 1 & ">").group("tag")
>>        assert(tagPat ~~= "<a count=0>")
>>        val minFind:String = tagPat.findFirst("<a><b>") match {
>>            case None => ""
>>            case Some(m) => m.group("tag")
>>        }
>>        assert(minFind === "<a>")
>>    }
>>
>>    def testFindAllIn() {
>>        assert( (for(m <- Lit("a").findAllIn("aabbaba")) yield m.string).mkString("") === "aabbaba")
>>        assert( (for(m <- Lit("a").findAllIn("babbaba")) yield m.string).mkString("") === "babbaba")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb")) yield m.string).mkString("") === "aabbabb")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (m.matched)) yield m.string).mkString("") === "aaa")
>>        assert( (for(m <- Lit("a").findAllIn("aabbabb") if (!m.matched)) yield m.string).mkString("") === "bbbb")
>>    }
>>
>>    def testReplaceAllIn() {
>>        val tagPat = "<td" & PatMinChars & ">"
>>        val target = "Hello<td style='color:#000'>Goodbye<td >Now"
>>        assert (tagPat.replaceAllIn(target, "<td>") === "Hello<td>Goodbye<td>Now")
>>    }
>>
>>    def testGrouping() {
>>        assert("abc".anonGroup.pattern === "abc")
>>        assert((CharSet("abc").pattern === "[abc]"))
>>        assert((CharRange('a','z') & "abc").pattern === "[a-z]abc")
>>        assert("abc".lookahead.pattern === "(?=abc)")
>>        assert(("a" & "bc" & "def").pattern === "(?:abc)def")
>>
>>    }
>>
>>    def testLookaheadLookbackPatterns {
>>        assert(("a" & "b".|> & "b") ~~= "ab")
>>        assert(("a" & "b".|> & "bb") !~~= "ab")
>>        assert(("a" & "c".!|> & "b") ~~= "ab")
>>        assert(("a" & "c".!|> & "c") !~~= "ac")
>>
>>        assert(("a" & "c".!<| & "b") ~~= "ab")
>>        assert(("a" & "a".<| & "b") ~~= "ab")
>>        assert(("a" & "a".!<| & "b") !~~= "ab")
>>    }
>>
>>    def testCharClasses {
>>        val alnum = CharAlpha \/ CharDigit
>>        assert(alnum**0 ~~= "abc123")
>>        val alpha = CharAlnum - CharDigit
>>        assert(alpha**0 ~~= "abc")
>>        assert(alpha**0 !~~= "abc123")
>>    }
>>
>>    def testBoundaryPatterns {
>>        assert(BndryStringStart & "a" & BndryStringEnd ~~= "a")
>>        assert(BndryStringStart & "a" & BndryStringEnd & "a" !~~= "aa")
>>    }
>> }
>>
>>
>>
>> Thanks,
>> Ken
>>
>>




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