IllegalArgumentException from Matcher

65 views
Skip to first unread message

Michael Kebe

unread,
Jun 17, 2010, 7:07:40 AM6/17/10
to scalatest-users
// Testet with
// Scala 2.8.0.RC5
// ScalaTest 1.2-for-scala-2.8.0.RC5-SNAPSHOT
// sbt 0.7.4

import org.scalatest._
import org.scalatest.matchers.ShouldMatchers

class Test extends FlatSpec with ShouldMatchers {

// works
"Test" should "work with boolean property" in {
"" should be('empty)
}

// works
it should "say that there is no property named fooable" in {
val thrown = evaluating {
"" should be('fooable)
} should produce [TestFailedException]
thrown.getMessage should include ("has neither a fooable nor an
isFooable method")
}

// works
it should "work with other properties" in {
class Foo(val name: String)
new Foo("michael") should have ('name ("michael"))
}

// throws IllegalArgumentException: can't parse argument number:
{0} ({1})
// see Stacktrace below
it should "say that there is no property named name" in {
val thrown = evaluating {
class Bar
new Bar() should have ('name ("nobody"))
} should produce [TestFailedException]
thrown.getMessage should include ("has neither name or getName
method")
}

}



java.lang.IllegalArgumentException: can't parse argument number: {0}
({1})
at java.text.MessageFormat.makeFormat(MessageFormat.java:1356)
at java.text.MessageFormat.applyPattern(MessageFormat.java:475)
at java.text.MessageFormat.<init>(MessageFormat.java:367)
at org.scalatest.Resources$.makeString(Resources.scala:32)
at org.scalatest.Resources$.apply(Resources.scala:36)
at org.scalatest.matchers.Matchers$HavePropertyMatcherGenerator$$anon
$29.apply(Matchers.scala:2559)
at org.scalatest.matchers.Matchers$HaveWord$$anon$30$$anonfun
$5.apply(Matchers.scala:2729)
at org.scalatest.matchers.Matchers$HaveWord$$anon$30$$anonfun
$5.apply(Matchers.scala:2728)
at scala.collection.TraversableLike$$anonfun$map
$1.apply(TraversableLike.scala:206)
at scala.collection.TraversableLike$$anonfun$map
$1.apply(TraversableLike.scala:206)
at scala.collection.LinearSeqOptimized
$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:
206)
at scala.collection.immutable.List.map(List.scala:45)
at org.scalatest.matchers.Matchers$HaveWord$$anon
$30.apply(Matchers.scala:2728)
at org.scalatest.matchers.ShouldMatchers$ShouldMethodHelper
$.shouldMatcher(ShouldMatchers.scala:870)
at org.scalatest.matchers.ShouldMatchers
$AnyRefShouldWrapper.should(ShouldMatchers.scala:1489)
at Test$$anonfun$5.apply$mcV$sp(Test.scala:34)
at Test$$anonfun$5.apply(Test.scala:31)
at Test$$anonfun$5.apply(Test.scala:31)
at org.scalatest.FlatSpec$$anon$2.apply(FlatSpec.scala:2563)
at org.scalatest.Suite$class.withFixture(Suite.scala:1509)
at Test.withFixture(Test.scala:9)
at org.scalatest.FlatSpec$class.runTest(FlatSpec.scala:2560)
at Test.runTest(Test.scala:9)
at org.scalatest.FlatSpec$$anonfun$org$scalatest$FlatSpec$
$runTestsInBranch$1.apply(FlatSpec.scala:2485)
at org.scalatest.FlatSpec$$anonfun$org$scalatest$FlatSpec$
$runTestsInBranch$1.apply(FlatSpec.scala:2474)
at scala.collection.LinearSeqOptimized
$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at org.scalatest.FlatSpec$class.org$scalatest$FlatSpec$
$runTestsInBranch(FlatSpec.scala:2473)
at org.scalatest.FlatSpec$$anonfun$org$scalatest$FlatSpec$
$runTestsInBranch$1.apply(FlatSpec.scala:2493)
at org.scalatest.FlatSpec$$anonfun$org$scalatest$FlatSpec$
$runTestsInBranch$1.apply(FlatSpec.scala:2474)
at scala.collection.LinearSeqOptimized
$class.foreach(LinearSeqOptimized.scala:61)
at scala.collection.immutable.List.foreach(List.scala:45)
at org.scalatest.FlatSpec$class.org$scalatest$FlatSpec$
$runTestsInBranch(FlatSpec.scala:2473)
at org.scalatest.FlatSpec$class.runTests(FlatSpec.scala:2687)
at Test.runTests(Test.scala:9)
at org.scalatest.Suite$class.run(Suite.scala:1804)
at Test.org$scalatest$FlatSpec$$super$run(Test.scala:9)
at org.scalatest.FlatSpec$class.run(FlatSpec.scala:2758)
at Test.run(Test.scala:9)
at org.scalatest.tools.ScalaTestFramework
$ScalaTestRunner.run(ScalaTestFramework.scala:40)
at sbt.TestRunner.run(TestFramework.scala:52)
at sbt.TestRunner.runTest$1(TestFramework.scala:66)
at sbt.TestRunner.run(TestFramework.scala:75)
at sbt.TestFramework$$anonfun$9$$anonfun$apply$11.runTest
$2(TestFramework.scala:192)
at sbt.TestFramework$$anonfun$9$$anonfun$apply$11$$anonfun$apply
$12.apply(TestFramework.scala:203)
at sbt.TestFramework$$anonfun$9$$anonfun$apply$11$$anonfun$apply
$12.apply(TestFramework.scala:203)
at sbt.NamedTestTask.run(TestFramework.scala:91)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask
$1.apply(ScalaProject.scala:187)
at sbt.ScalaProject$$anonfun$sbt$ScalaProject$$toTask
$1.apply(ScalaProject.scala:187)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
at sbt.impl.RunTask.runTask(RunTask.scala:85)
at sbt.impl.RunTask.sbt$impl$RunTask$$runIfNotRoot(RunTask.scala:60)
at sbt.impl.RunTask$$anonfun$runTasksExceptRoot$2.apply(RunTask.scala:
48)
at sbt.impl.RunTask$$anonfun$runTasksExceptRoot$2.apply(RunTask.scala:
48)
at sbt.Distributor$Run$Worker$$anonfun$2.apply(ParallelRunner.scala:
131)
at sbt.Distributor$Run$Worker$$anonfun$2.apply(ParallelRunner.scala:
131)
at sbt.Control$.trapUnit(Control.scala:19)
at sbt.Distributor$Run$Worker.run(ParallelRunner.scala:131)

Michael Kebe

unread,
Jun 18, 2010, 8:24:15 AM6/18/10
to scalatest-users
There was a problem with the syntax of the MessageFormat. Here is a
patch that fixes the problem:

Index: src/test/scala/org/scalatest/matchers/
ShouldHavePropertiesSpec.scala
===================================================================
--- src/test/scala/org/scalatest/matchers/
ShouldHavePropertiesSpec.scala (revision 2218)
+++ src/test/scala/org/scalatest/matchers/
ShouldHavePropertiesSpec.scala (working copy)
@@ -39,6 +39,13 @@
book should have ('title ("A Tale of Two Cities"))
}

+ it("should throw TestFailedException if trying to check for a
non existent property") {
+ val thrown = evaluating {
+ new Object should have ('nonExistentProperty ("something"))
+ } should produce [TestFailedException]
+ thrown.getMessage should equal("have nonExistentProperty
(something) used with an object that had no public field or method
named nonExistentProperty or getNonExistentProperty")
+ }
+
it("should do nothing if all the properties match") {
book should have (
title ("A Tale of Two Cities"),
Index: src/main/resources/org/scalatest/ScalaTestBundle.properties
===================================================================
--- src/main/resources/org/scalatest/ScalaTestBundle.properties
(revision 2218)
+++ src/main/resources/org/scalatest/ScalaTestBundle.properties
(working copy)
@@ -296,7 +296,7 @@
midSentencePropertyHadExpectedValue=the {0} property had its expected
value {1}, on object {2}
propertyDidNotHaveExpectedValue=The {0} property had value {2},
instead of its expected value {1}, on object {3}
midSentencePropertyDidNotHaveExpectedValue=the {0} property had value
{2}, instead of its expected value {1}, on object {3}
-propertyNotFound=have { {0} ({1}) } used with an object that had no
public field or method named '{1}' or '{2}'
+propertyNotFound=have {0} ({1}) used with an object that had no
public field or method named {0} or {2}
lengthPropertyNotAnInteger=The length property was none of Byte,
Short, Int, or Long.
sizePropertyNotAnInteger=The size property was none of Byte, Short,
Int, or Long.
wasEqualTo={0} was equal to {1}

Bill Venners

unread,
Jun 19, 2010, 1:07:00 PM6/19/10
to scalate...@googlegroups.com
Hi Michael,

Thanks for the patch. I've fixed this in the latest snapshot for Scala
2.8.0.RC6. Not sure how this one slipped through, but clearly I forgot
to write a test. Instead I ended up using the popular
customer-test-first methodology.

Bill

> --
> You received this message because you are subscribed to the Google
> Groups "scalatest-users" group.
> To post to this group, send email to scalate...@googlegroups.com
> To unsubscribe from this group, send email to
> scalatest-use...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/scalatest-users?hl=en
> ScalaTest itself, and documentation, is available here:
> http://www.artima.com/scalatest
>

--
Bill Venners
Artima, Inc.
http://www.artima.com

Michael Kebe

unread,
Jun 19, 2010, 3:39:01 PM6/19/10
to scalatest-users
There is still a minor thing wrong.

https://scalatest.dev.java.net/source/browse/scalatest/branches/app/trunk-for-scala-2.8h/src/main/resources/org/scalatest/ScalaTestBundle.properties?rev=2225&r1=2220&r2=2225

As you can see, you left the 's (single quotes). If you want a single
quote from a MessageFormat, you have to type them twice. (Man, this
syntax is odd!) The generated messages ends something like this:
"have name (nobody) used with an object that had no public field or
method named {0} or {2}"
instead of
"have name (nobody) used with an object that had no public field or
method named 'name' or 'getName'"

Greetings
Michael

Bill Venners

unread,
Jun 19, 2010, 3:47:45 PM6/19/10
to scalate...@googlegroups.com
Hi Michael,

Oops. Weird thing is your test passed. I'll drop the single quotes
(though it is also likely technically correct that the object had no
property named {0}, just not helpful to know). I'll update the RC6
snapshot shortly.

Bill

Reply all
Reply to author
Forward
0 new messages