Code Monkey home page Code Monkey logo

specs2's Introduction

Build Status Join the chat at https://gitter.im/etorreborre/specs2

Go to specs2.org to learn more about specs2!

Installation instructions

You need to download and install sbt. Then execute the following command:

sbt update publishLocal

Then you can generate the User Guide with:

sbt "testOnly org.specs2.guide.UserGuide -- html html.nostats all"

This should create html files in the target/specs2-reports directory.

specs2's People

Contributors

2m avatar alexeyr avatar alissapajer avatar armanbilge avatar asflierl avatar backuitist avatar cchantep avatar dekelatwix avatar edmundnoble avatar emma-burrows avatar etorreborre avatar gitter-badger avatar hmemcpy avatar jilen avatar kaatzee avatar keirlawson avatar lolgab avatar mdedetrich avatar noam-almog avatar retronym avatar rossabaker avatar scala-steward avatar sethtisue avatar symbiont-eric-torreborre avatar taisukeoe avatar tek avatar tmccombs avatar xuwei-k avatar ymasory avatar zaneli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

specs2's Issues

Title not displaying

def is =
"a title of some such".title ^

  • Works with v1.4, does not work with v1.6.
  • I was unable to test with v1.7 SNAPSHOT
  • I could not see that it had been deprecated

Nicer message when doing ^^(... aka("..."))

Suppose the following spec:

class DataPoints extends Specification {
  val objectUnderTest: Int => Int = _ + 2

  val testCases = 1 :: 2 :: 3 :: 4 :: Nil

  def is: Fragments = 
    (objectUnderTest must multiplyByTwo((_: Int))).foreach(testCases)    

  def multiplyByTwo(i: Int): Matcher[(Int) => Int] = 
    (=== (i * 2)) ^^ 
      ((f: Int => Int) => f(i) aka "result of applying %s to %d".format(f, i))
}

This produces the following output:

result of applying <function1> to 1 '3' is not equal to '2'; ...

I find the aka string does not go well with the '3'. Maybe put the '3' in parenthesis; or write '3' (aka result of applying ...); or write a : after the aka string.

But as it is now it's not nice to read.

Color codes in HTML report

Hi,

it seems that if a row of a data table results in a failure, the description of the failure in the genererated HTML report will contain the terminal color codes and be very unformatted.

The console output looks like this:

[info] The solution to problem 98 should
[error] x match numbers and words correctly
[error]       |number|word|do they match?|
[error] + |1|A|true|
[error] + |0|X|false|
[error] + |1||false|
[error] + |123|ABC|true|
[error] + |7557|ABBA|true|
[error] + |7567|ABBA|false|
[error] + |9449|ABCA|false|
[error] x |1296|CARES|true| the value is not equal to 'true' (Problem0098Spec.scala:53)

And the generated HTML is really not very informative :)

The solution to problem 98 should
match numbers and words correctly
|number|word|do they match?| [32m+[0m |1|A|true| [32m+[0m |0|X|false| [32m+[0m |1||false| [32m+[0m |123|ABC|true| [32m+[0m |7557|ABBA|true| [32m+[0m |7567|ABBA|false| [32m+[0m |9449|ABCA|false| [33mx[0m |1296|CARES|true| the value is not equal to 'true' (Problem0098Spec.scala:53)

property specs2.outDir not evaluated

Hi,

I am using the current 1.5-SNAPSHOT with sbt 0.10 and try to set the output of the HTML report to a different directory (instead of target/specs2-reports) using the following in the build.sbt file:

testOptions <+= crossTarget map { ct =>
  Tests.Setup { () => System.setProperty("specs2.outDir", new File(ct, "specs2").getAbsolutePath)) }
}

crossTarget is a SettingsKey pointing to target/scala-2.9.0.1/

Now, instead of writing the HTML to target/scala-2.9.0.1/specs2 it instead writes to a directory literally named specs2.outDir in the project's root directory.

I've tried this code to see if the property is set correctly

testOptions <+= crossTarget map { ct =>
  Tests.Setup { () => {
    System.setProperty("specs2.outDir", new File(ct, "specs2").getAbsolutePath)
    println(System.getProperty("specs2.outDir"))
  }}
}

and it looks alright.

This functionality used to work with specs2 1.4 and sbt 0.7.x so I am a bit at loss here. Sorry if this is not really a specs2 issue.

Even with logBuffered := false, Long Delay on Printing

I have a specification that takes between 40 and 50 seconds to run on my machine, comprising 186 examples. I'm running it against the latest snapshot with logBuffered := false. Even with this though, there is quite a delay before any test output appears. By "quite a delay", I mean on the order of 20-30 seconds. Once the output starts appearing, it does print out incrementally.

Consistent Cross-Builds

Would it be possible to get a consistent cross-build across (at least) the following Scala versions:

  • 2.8.1
  • 2.9.0
  • 2.9.0-1
  • 2.9.1(.RC*)?

Right now, it looks like the only version available for the 2.9.1 series is 1.6-SNAPSHOT. That wouldn't be a problem, except 1.6-SNAPSHOT is not available for either 2.9.0 or 2.8.1. Right away, this means a version split in cross-build dependencies. Unfortunately, there isn't even a single other version that we can go down to. 1.5 is pretty universal…with the exception of 2.9.0. I would almost have to downgrade all the way to 1.3 for versions other than 2.9.1, and use 1.6-SNAPSHOT for the latest and greatest Scala.

This is a bit of a mess. :-) Is there any way we can get a consistent cross-build of some version (any version)? If Specs2 is actually going to drop compatibility with a particular version of Scala, then that's something I can work with, but I would at least expect the entire 2.9.x series to be supported with a consistent cross-build until the release of 2.10.

My preference would be for the latest stable and the latest snapshot of Specs2 to be cross-built against all supported versions of Scala. A version of Scala should not be considered "unsupported" until Specs2 actually hard-depends on something which is not in that release.

Integration with scalacheck in 2.9.0_1-1.3

Before moving to 2.9.0-1-1.3 I used 2.8.1_1.6.7. My test code with specs and scalacheck looked like this:

object MySpec extends Specification with ScalaCheck {

val generator:Gen[String] = Gen{
prms =>
Some("this is stub implementation of generator")
}

"my spec" should{
"check something" in{
generator must pass{
str => str must beEqualTo ("this is stub implementation of generator")
}
}
}
}

After migrating to 2.9.0_1-1.3 I got compilation errors like this: MySpec.scala:17: not found: value pass

JUnitRunner, Maven, and Mockito crash

Maven's Surefire/JUnit test runner chokes and dies with specs2 1.4:

[INFO] --- maven-surefire-plugin:2.8.1:test (default-test) @ specs2-bug-repro ---
[INFO] Surefire report directory: /Users/coda/Projects/scala/specs2-bug-repro/target/surefire-reports
java.lang.reflect.UndeclaredThrowableException
    at $Proxy0.invoke(Unknown Source)
    at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:150)
    at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:91)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
    ... 4 more
Caused by: java.lang.ClassFormatError: Unknown constant tag 66 in class file org/specs2/mock/mockito/CapturedArgument$ArgumentCapture
    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)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
    at java.lang.Class.getMethod0(Class.java:2670)
    at java.lang.Class.getMethod(Class.java:1603)
    at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:57)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:65)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:60)
    at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:55)
    at org.apache.maven.surefire.common.junit4.JUnit4TestChecker.accept(JUnit4TestChecker.java:52)
    at org.apache.maven.surefire.util.DefaultDirectoryScanner.locateTestClasses(DefaultDirectoryScanner.java:80)
    at org.apache.maven.surefire.junit4.JUnit4Provider.scanClassPath(JUnit4Provider.java:168)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:88)
    ... 9 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.916s
[INFO] Finished at: Sat Jun 04 00:57:11 PDT 2011
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------

I've got a full repro project here: http://codahale.com/specs2-bug-repro.tar.bz2

SBT works just fine, but for whatever reason Surefire is profoundly unhappy.

Specification stop when a text for ("text" in {}) contains \n

Hello,
When I write specification with a "\n" in the comment, the full specification stop at that point.

For example,

class Foo extends Specification {
  "a test" should {
    "have a first comment \n on two lines" in { ... }
    "a second test" in { ... }
  }
}

Will never execute "a second test".

That is not a really big issue as it is quite easy to work around it, but at least it would be great to document it in the use guide (I missed it if it is already).

Thanks for the great framework,

Parser matchers that must consume the whole input

Currently there is no way of forcing a parser matcher to consume the whole input (using parseAll). The following test fails even if number correctly parses only numbers.

number must failOn("3b")

If there is such functionality, at least it is not described in the documentation.

Maybe this behaviour should even be the default.

Erroneously Interleaved Test Output

When running 1.7-SNAPSHOT under SBT with logBuffered := false, it is actually possible to get test output to interleave so long as you have multiple separate specifications. This appears to be some sort of interaction between the concurrent evaluation of examples and the concurrent evaluation of specifications (all of which is otherwise awesome, btw).

Adding an exclude argument runs nothing

Hi, I've ran into a small problem with specs2. I've found that when I've added to my project/build/project.scala

override def testOptions = super.testOptions ++ Seq(TestArgument("exclude", "slow"))

And in only one of my specs:

class UnitSpec extends Specification with org.specs2.mutable.Tags {
  section("slow")

   ....

Specs2 won't run any of my specs.

I would expect specs2 to run the rest of my specs that aren't tagged "slow"
I've forked the specs2-test repo and was able to recreate it:
https://github.com/rubbish/specs2-test/tree/exclude-runs-nothing

Iterable compile exception when assertion if empty.

Given the following in a Unit Specification:

"have iterable matchers" in {
      Nil must be empty
      List(1, 2, 3) must not be empty
      List(1, 2, 3) must not contain (5)
      List(4, 5, 6) must not contain(7, 8, 9)
      List(1, 2, 3, 4, 5, 6) must contain(3, 4, 5).inOrder
}

A compiler exception is thrown

14. Waiting for source changes... (press enter to interrupt)
[info] Compiling 1 Scala source to /home/danno/testing_scala_book.git/testingscala/target/scala-2.9.0-1/test-classes...
[error] /home/danno/testing_scala_book.git/testingscala/src/test/scala/com/oreilly/testingscala/MatchersUnitSpec.scala:77: type mismatch;
[error]  found   : List[Int]
[error]  required: org.specs2.matcher.Matcher[scala.collection.immutable.Nil.type]
[error]       List(1, 2, 3) must not be empty
[error]           ^
[error] one error found
[error] {file:/home/danno/testing_scala_book.git/testingscala/}default-cef86a/test:compile: Compilation failed
[error] Total time: 1 s, completed Dec 15, 2011 1:59:17 PM

Where as the following rectifies the compiler error :

"have iterable matchers" in {
    (Nil must be).empty
      List(1, 2, 3) must not be empty
      List(1, 2, 3) must not contain (5)
      List(4, 5, 6) must not contain(7, 8, 9)
      List(1, 2, 3, 4, 5, 6) must contain(3, 4, 5).inOrder
}

Yellow Reporting Color Unreadable on Light Terminals

Currently, Specs2 reports failed tests with a yellow coloration in order to distinguish from specs which produced errors (which are reported in red). This works well on dark terminals, but becomes almost unreadable if the terminal has a light background color. I'm not sure exactly which color would be preferable, but yellow definitely isn't working.

generated html in sbt 0.10 using specs2 1.4 is missing graphic(s)

Just started using specs2 1.4 with a new project in sbt 0.10. Followed the examples and ran my first spec with the results being generated in HTML. Unfortunately there were missing graphics in the webpage, looks like icon_success_sml.gif is missing. Listing of the target/specs2-reports/images directory:

  • bluedot.gif
  • bluedots.psd
  • bluedotsel.gif
  • cyandot.gif
  • cyandots.psd
  • cyandotsel.gif
  • dots.psd
  • graydot.gif
  • graydots.psd
  • graydotsel.gif
  • greendot.gif
  • greendots.psd
  • greendotsel.gif
  • purpledot.gif
  • purpledots.psd
  • purpledotsel.gif
  • reddot.gif
  • reddots.psd
  • reddotsel.gif
  • yellowdot.gif
  • yellowdots.psd
  • yellowdotsel.gif

Unsatisfied dependencies

Using sbt and the specs2 1.0, some dependencies cannot be resolved:

[warn]      ::::::::::::::::::::::::::::::::::::::::::::::
[warn]      ::          UNRESOLVED DEPENDENCIES         ::
[warn]      ::::::::::::::::::::::::::::::::::::::::::::::
[warn]      :: org.pegdown#pegdown;0.8.5.4: not found
[warn]      :: org.parboiled#parboiled4j;0.9.9.0: not found
[warn]      ::::::::::::::::::::::::::::::::::::::::::::::

Is there anything to add in addition to what is specified on http://etorreborre.github.com/specs2/ for sbt?

Release pom has dependency on scalaz 5.1-SNAPSHOT

The 1.1 released pom declares a dependency on 5.1-SNAPSHOT of scalaz:

http://scala-tools.org/repo-releases/org/specs2/specs2_2.8.1/1.1/specs2_2.8.1-1.1.pom

Release poms should not have a dependency on a SNAPSHOT build as it can not guarantee reproducibility.

Skipped, pending and todo repeat themselves in HTML report

Hi,

this simple spec

import org.specs2._

object PendingSpec extends Specification { def is =
  "Some title" ^
    "success only once"   ! success^
    "failure only once"   ! failure^
    "anError only once"   ! anError^
    "skipped is repeated" ! skipped^
    "pending is repeated" ! pending^
    "done only once"      !    done^
    "todo is repeated"    !    todo
}

with this build.sbt

name := "pending"

scalaVersion := "2.9.1"

testOptions := Seq(
  Tests.Filter(_ == "PendingSpec"), 
  Tests.Argument("html", "console", "junitxml"))

libraryDependencies ++= Seq(
  "org.specs2" %% "specs2" % "1.6-SNAPSHOT" % "test",
  "org.pegdown" % "pegdown" % "1.0.2" % "test",
  "junit" % "junit" % "4.7" % "test"
)

resolvers ++= Seq(
  "snapshots" at "http://scala-tools.org/repo-snapshots",
  "releases" at "http://scala-tools.org/repo-releases"
)

yields the following output in the HTML report:

Some title
 success only once
 failure only once
 failure (PendingSpec.scala:6)
 anError only once
 error (PendingSpec.scala:7)
 skipped is repeated
 skipped
 skipped
 pending is repeated
 PENDING
 pending is repeated
 PENDING
 done only once
 todo is repeated
 TODO
 todo is repeated
 TODO

As you can see, "pending" and "todo" are repeated with their description, "skipped" without. Console and JUnit-XML-Output are OK, i.e. each example/result appears only once.

Parser macher produces wrong error message (and maybe result)

Notice the debugging statements I have inserted. First I parse the file manually and check the parse result.

  "parse uai file" ! {
    val myParse = parseAll(parseProblem, StreamReader(new FileReader("res/uai/examples/grid3x3.uai")))
    println(myParse)
    val source: CharSequence = myParse.next.source
    println(source.length())
    println(source)
    parseProblem must succeedOn(StreamReader(new FileReader("res/uai/examples/grid3x3.uai")))
  }

Here is the ouput:

[90.1] parsed: UAIProblem(<snip>)
0

'[88.36] parsed: UAIProblem(<snip>)' is a Success but the input was not completely parsed: 0.00041451 2412.5 2412.5 0.00041451

The pointer after the manual parse is at 90.1 and there are no bytes left as input. Also parseAll succeeds. But inside the message from specs2 you see the cursor is at 88.36, with presumably the displayed string left to parse, although the correct AST has been produced, which definately had to read the printed numbers.

Weird Before / After behaivor

So I've been using contexts to isolate variables and state for each of my tests like it's described in http://etorreborre.github.com/specs2/guide/org.specs2.guide.SpecStructure.html#Contexts . It works great and I'm pretty happy with it so far.

However, I've ran into an issue that runs against what is said in the UserGuide. When I have a context/scope that also extends the Before trait, I would expect the before method to be kicked off. But it isn't. See https://gist.github.com/1042813 It works for a singleton object however.

The UserGuide also has code like this:

   class ContextSpec extends mutable.Specification {
     "this is the first example" in new trees {
       tree.removeNodes(2, 3) must have size(2)
     }
     "this is the first example" in new trees {
       tree.removeNodes(2, 3, 4) must have size(1)
     }
   }

   trait trees extends Scope with Before {
     val tree = getATreeWith4NodesFromTheDatabase
     def before = setupDB
   }

Ideas?

Cannot access Failure through Notifier API

The IntelliJ Specs and Specs2 runners now support a text diff popup for test failures. It's a bit ugly: I have to parse the text '123' is not equal to '456'.

Can you pass a FailureException rather than a generic Exception to the Notifier#exampleFailure? I would expect this code to extract the actual and expected strings.

public static String actualExpectedAttrsSpecs2(String message, Throwable f) {
  String actualExpectedAttrs = "";
  if (f instanceof FailureException) {
    Details details = ((FailureException) f).f().details();
    if (details instanceof FailureDetails) {
      FailureDetails details1 = (FailureDetails) details;
      String actual = details1.actual();
      String expected = details1.expected();
      actualExpectedAttrs = actualExpectedAttrs(actual, expected);
    }
  }    
  return actualExpectedAttrs;
}

ArgumentCapture should expose all values captured

A Mockito ArgumentCaptor can capture multiple invocations and provide all captured values as a list. In Specs2, only the last value can be obtained from ArgumentCapture. This can be worked around my using Mockito's classes directly instead of the syntax sugar.

Suggested fix:
Provide a "values" accessor.

java.lang.IndexOutOfBoundsException on running Spec

Running the following spec:

@RunWith(classOf[JUnitRunner])
class TestSpec extends Specification {
def is = {
("Hello world" must have size(11)) ^
("Hello world" must startWith("Hello")) ^
("Hello world" must endWith("world"))
}}

...via JUnit in Eclipse/ScalaIDE results in the following output to console:

java.lang.IndexOutOfBoundsException: 18

...and the following message displayed in Eclipse JUnit view:

No source file found at src/test/scala/com/playscapegames/math/vector/NuVectorSpec.scala(1)

This report is not about the validity, or lack of, the spec code itself (Im new to Specs and are experimenting), but concerns how Specs2 handled & reported the failure case:

  1. The "No source file found..." error message is misleading. There is Scala source at the reported path. In org.specs2.io.FromSource, method getCodeFromToWithLocation has made a incorrect guess about the likely cause of the caught exception.
  2. I think that getCodeFromToWithLocation() should print a stack trace of the exception if its going to swallow it. As a user, getting a message "java.lang.IndexOutOfBoundsException: 18" with no further clues unnecessarily obstructs diagnosis of the problem. I had to run Specs in a debugger in order to discover where the real source of the problem was.
  3. Im still guessing that the IndexOutOfBounds should not have happened. Here is a stack trace of where it originated:

Vector.checkRangeConvert(int) line: 113
Vector.apply(int) line: 103
Vector.apply(Object) line: 36
TraversableLike$$anonfun$map$1.apply(A) line: 194
TraversableLike$$anonfun$map$1.apply(Object) line: 194
Range$Inclusive(Range).foreach(Function1<Object,U>) line: 75
TraversableLike$class.map(TraversableLike, Function1, CanBuildFrom) line: 194
Range$Inclusive(Range).map(Function1<Object,B>, CanBuildFrom<IndexedSeq,B,That>) line: 43
FromSource$$anonfun$getCodeFromToWithLocation$1.apply() line: 51
FromSource$$anonfun$getCodeFromToWithLocation$1.apply() line: 49
Exceptions$class.trye(Exceptions, Function0, Function1) line: 80
Exceptions$.trye(Function0, Function1<Exception,S>) line: 96
Exceptions$class.tryOr(Exceptions, Function0, Function1) line: 42
Exceptions$.tryOr(Function0, Function1<Exception,T>) line: 96
FromSource$class.getCodeFromToWithLocation(FromSource, int, int, TraceLocation) line: 52
FromSource$.getCodeFromToWithLocation(int, int, TraceLocation) line: 64
FromSource$class.getCodeFromTo(FromSource, int, int) line: 45
FromSource$.getCodeFromTo(int, int) line: 64
AutoExamples$class.getSourceCode(AutoExamples, int, int) line: 58
TestSpec.getSourceCode(int, int) line: 13
AutoExamples$class.booleanFragments(AutoExamples, Function0) line: 42
TestSpec.booleanFragments(Function0) line: 13
TestSpec.is() line: 16
SpecificationStructure$$anonfun$content$1.apply() line: 39
SpecificationStructure$$anonfun$content$1.apply() line: 39
SpecificationStructure$class.map(SpecificationStructure, Function0) line: 33
TestSpec.map(Function0) line: 13
SpecificationStructure$class.content(SpecificationStructure) line: 39
TestSpec.content() line: 13
JUnitRunner.content() line: 33
JUnitRunner.x$1() line: 39
JUnitRunner.desc() line: 39
JUnitRunner.getDescription() line: 41
JUnitRunner(Runner).testCount() line: 38
JUnit4TestClassReference.countTestCases() line: 30
RemoteTestRunner.countTests(ITestReference[]) line: 487
RemoteTestRunner.runTests(String[], String, TestExecution) line: 455
RemoteTestRunner.runTests(TestExecution) line: 683
RemoteTestRunner.run() line: 390
RemoteTestRunner.main(String[]) line: 197

Multiple Scalacheck fragments do not compile if Start and End "bookend" fragments omitted.

Related to issue 30, Scalacheck fragments do not compile if Start and End "bookend" fragments omitted.

Not sure if this is intended to be supported, but note it does compile for a 1 Scalacheck fragment, but not for > 1..

Error: value ^ is not a member of org.scalacheck.Prop

def is = {
check((i: Int) => i+i == 2*i) ^
check((i: Int) => i-i == 0)
}

Compiles OK:

def is = {
"examples" ^
check((i: Int) => i+i == 2*i) ^
check((i: Int) => i-i == 0) ^
end
}

def is = {
check((i: Int) => i+i == 2*i)
}

Tested in Eclipse Scala IDE, latest nightly with Scala 2.9.1

Test succeeds (but should fail) with 1.7-SNAPSHOT

Using the SNAPSHOT of today, the bug is a succeeding spec that fails (as intended) with 1.6.1 but succeeds with 1.7-SNAPSHOT .

I have a custom matcher for comparing objects of type DiscreteMarginal[V]. They're basically partial functions that map a variable of type V and an Int to a Double with funciton marginal:

  /** Compare the marginals of two given MarginalInferer objects up to a given tolerance.
    */
  def beCloseMarginals[V <: DiscreteVariable](reference: DiscreteMarginals[V],
                                              tolerance: Double,
                                              variables: Set[V]): Matcher[DiscreteMarginals[V]] =
    variables.map(beCloseMarginalsOnVariable(reference, tolerance, _)).reduce(_ and _)

  def beCloseMarginalsOnVariable[V <: DiscreteVariable](reference: DiscreteMarginals[V],
                                                        tolerance: Double,
                                                        variable: V): Matcher[DiscreteMarginals[V]] =
    variable.getRange.map(beCloseMarginalsOnVariableWithValue(reference, tolerance, variable, (_: Int))).reduce(_ and _)

  def beCloseMarginalsOnVariableWithValue[V <: DiscreteVariable](reference: DiscreteMarginals[V],
                                                                 tolerance: Double,
                                                                 variable: V,
                                                                 value: Int): Matcher[DiscreteMarginals[V]] =
    beCloseTo(reference.marginal(variable, value), tolerance) ^^ {(_: DiscreteMarginals[V]).marginal(variable,     value)}

I use this matcher like this:

mcSatInferer.infer(buggyMLN) must TestUtils.beCloseMarginals (JunctionTreeInference.infer(buggyMLN), 0.03, buggyMLN.variables)

If I print out the values for both marginals I get the following, which obviously should fail.

Marginals of edu.uulm.scbayes.inference.sampling.MutableMCMCStepper$$anon$1@3f357ede:
    P(at(6,A) = 0) = 0,000000
    P(at(6,A) = 1) = 0,000000
    P(at(6,A) = 2) = 0,000000
    P(at(6,A) = 3) = 0,000000
    P(at(6,A) = 4) = 0,015997
    P(at(6,A) = 5) = 0,019796
    P(at(6,A) = 6) = 0,069186
    P(at(6,A) = 7) = 0,089182
    P(at(6,A) = 8) = 0,802440
    P(at(6,A) = 9) = 0,003399
    P(at(6,B) = 0) = 0,000000
    P(at(6,B) = 1) = 0,005999
    P(at(6,B) = 2) = 0,002999
    P(at(6,B) = 3) = 0,002400
    P(at(6,B) = 4) = 0,000400
    P(at(6,B) = 5) = 0,058988
    P(at(6,B) = 6) = 0,057189
    P(at(6,B) = 7) = 0,062188
    P(at(6,B) = 8) = 0,805239
    P(at(6,B) = 9) = 0,004599
    P(at(7,A) = 0) = 0,099180
    P(at(7,A) = 1) = 0,087782
    P(at(7,A) = 2) = 0,083383
    P(at(7,A) = 3) = 0,086983
    P(at(7,A) = 4) = 0,092581
    P(at(7,A) = 5) = 0,121576
    P(at(7,A) = 6) = 0,089182
    P(at(7,A) = 7) = 0,137772
    P(at(7,A) = 8) = 0,123975
    P(at(7,A) = 9) = 0,077584
    P(at(7,B) = 0) = 0,084383
    P(at(7,B) = 1) = 0,068186
    P(at(7,B) = 2) = 0,075585
    P(at(7,B) = 3) = 0,089782
    P(at(7,B) = 4) = 0,065587
    P(at(7,B) = 5) = 0,075585
    P(at(7,B) = 6) = 0,152969
    P(at(7,B) = 7) = 0,130974
    P(at(7,B) = 8) = 0,151770
    P(at(7,B) = 9) = 0,105179
Marginals of edu.uulm.scbayes.inference.junctiontree.JunctionTreeInference$$anon$1@2288e718:
    P(at(6,A) = 0) = 0,000055
    P(at(6,A) = 1) = 0,411777
    P(at(6,A) = 2) = 0,225696
    P(at(6,A) = 3) = 0,225696
    P(at(6,A) = 4) = 0,007790
    P(at(6,A) = 5) = 0,013290
    P(at(6,A) = 6) = 0,013290
    P(at(6,A) = 7) = 0,013290
    P(at(6,A) = 8) = 0,088452
    P(at(6,A) = 9) = 0,000665
    P(at(6,B) = 0) = 0,000055
    P(at(6,B) = 1) = 0,007790
    P(at(6,B) = 2) = 0,225696
    P(at(6,B) = 3) = 0,225696
    P(at(6,B) = 4) = 0,411777
    P(at(6,B) = 5) = 0,013290
    P(at(6,B) = 6) = 0,013290
    P(at(6,B) = 7) = 0,013290
    P(at(6,B) = 8) = 0,088452
    P(at(6,B) = 9) = 0,000665
    P(at(7,A) = 0) = 0,043545
    P(at(7,A) = 1) = 0,043545
    P(at(7,A) = 2) = 0,318816
    P(at(7,A) = 3) = 0,178694
    P(at(7,A) = 4) = 0,178694
    P(at(7,A) = 5) = 0,036646
    P(at(7,A) = 6) = 0,052036
    P(at(7,A) = 7) = 0,052036
    P(at(7,A) = 8) = 0,052036
    P(at(7,A) = 9) = 0,043951
    P(at(7,B) = 0) = 0,043545
    P(at(7,B) = 1) = 0,043545
    P(at(7,B) = 2) = 0,036646
    P(at(7,B) = 3) = 0,178694
    P(at(7,B) = 4) = 0,178694
    P(at(7,B) = 5) = 0,318816
    P(at(7,B) = 6) = 0,052036
    P(at(7,B) = 7) = 0,052036
    P(at(7,B) = 8) = 0,052036
    P(at(7,B) = 9) = 0,043951

Sorry that I didn't reduce this to a smaller example. Inserting a println near the beCloseTo, I see that this line gets evaluated for every variable/value combination which seems correct. Maybe the beCloseTo matcher is broken? But this seems unlikely.

sealing violation: package scalaz is sealed

Using scala 2.9.0.RC4 test run from within sbt, but within Intellij I get the following exception:

Scala 2.9.0.RC4
Intellij IU-107.18
Scala plugin 0.4.993

An error occurred. Please create an issue on the http://specs2.org website with the stacktrace below. Thanks.
java.lang.SecurityException: sealing violation: package scalaz is sealed
at java.net.URLClassLoader.defineClass(URLClassLoader.java:234)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.specs2.runner.NotifierRunner$$anon$1.(NotifierRunner.scala:10)
at org.specs2.runner.NotifierRunner.reporter(NotifierRunner.scala:10)
at org.specs2.runner.ClassRunner$$anonfun$apply$1$$anonfun$apply$2.apply(ClassRunner.scala:56)
at org.specs2.runner.ClassRunner$$anonfun$apply$1$$anonfun$apply$2.apply(ClassRunner.scala:56)
at org.specs2.control.Exceptions$class.trye(Exceptions.scala:80)
at org.specs2.control.Exceptions$.trye(Exceptions.scala:96)
at org.specs2.runner.ClassRunner$$anonfun$apply$1.apply(ClassRunner.scala:56)
at org.specs2.runner.ClassRunner$$anonfun$apply$1.apply(ClassRunner.scala:55)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:194)
at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:34)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:33)
at scala.collection.TraversableLike$class.map(TraversableLike.scala:194)
at scala.collection.mutable.WrappedArray.map(WrappedArray.scala:33)
at org.specs2.runner.ClassRunner.apply(ClassRunner.scala:55)
at org.specs2.runner.ClassRunner.start(ClassRunner.scala:33)
at org.specs2.runner.ClassRunner.main(ClassRunner.scala:27)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Exception in thread "main" java.lang.SecurityException: sealing violation: package scalaz is sealed
at java.net.URLClassLoader.defineClass(URLClassLoader.java:234)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at org.specs2.runner.NotifierRunner$$anon$1.(NotifierRunner.scala:10)
at org.specs2.runner.NotifierRunner.reporter(NotifierRunner.scala:10)
at org.specs2.runner.ClassRunner.apply(ClassRunner.scala:58)
at org.specs2.runner.ClassRunner.start(ClassRunner.scala:33)
at org.specs2.runner.ClassRunner.main(ClassRunner.scala:27)
at org.jetbrains.plugins.scala.testingSupport.specs2.JavaSpecs2Runner.main(JavaSpecs2Runner.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

StackOverflowError for all Specs in 2.9.0

Specs2 1.6-SNAPSHOT, Scala 2.9.0.

Running the HelloWorldSpec straight off the website (and any other specs2's, immutable or mutable):

Could not run test HelloWorldSpec: java.lang.StackOverflowError

Don't get a stack trace from the sbt console, but I get one out of Jenkins. (Not a Specs2 problem, but why?):

java.lang.StackOverflowError
    at scala.collection.TraversableViewLike$class.groupBy(TraversableViewLike.scala:170)
    at scala.collection.SeqViewLike$$anon$3.groupBy(SeqViewLike.scala:77)
    at scala.collection.TraversableViewLike$class.groupBy(TraversableViewLike.scala:170)
    [...]
    at scala.collection.SeqViewLike$$anon$3.groupBy(SeqViewLike.scala:77)
    at scala.collection.TraversableViewLike$class.groupBy(TraversableViewLike.scala:170)
    at scala.collection.SeqViewLike$$anon$3.groupBy(SeqViewLike.scala:77)

Entire stack trace is inside scala.collection. Specs1 and ScalaTest run fine.

DataTable prints table messed

Shouldn't the table entries be padded to the longest row in the corresponding column?

See the following example taken from the output in Intellij IDEA.

  |formula|assignment|
+ |a v b|a|
! |a v (!b ^ c)|!b,c| No result when parsing failed

The following would be better to read.

  |formula     |assignment|
+ |a v b       |a         |
! |a v (!b ^ c)|!b,c      | No result when parsing failed

Problems with sbt and HTML output

Hi,

I have 2 problems when running my spec from sbt 0.7.5. The project's Scala version is 2.9.0.RC1 and specs2 is setup like this:

val specs2 = "org.specs2" %% "specs2" % "1.2-SNAPSHOT" % "test"
def specs2Framework = new TestFramework("org.specs2.runner.SpecsFramework")
override def testFrameworks = super.testFrameworks ++ Seq(specs2Framework)
override def includeTest(s: String) = s equals "ecidice.EcidiceSpec"
system[String]("specs2.outDir") update (outputPath / "specs2").toString 
override def testOptions = super.testOptions ++ Seq(TestArgument("html"))

where the "EcidiceSpec" is something like a "suite" spec including all the other sub-specs.

  1. The runner only creates HTML output. On the sbt console there's only the following:

    [info] == test-finish ==
    [info] Passed: : Total 0, Failed 0, Errors 0, Passed 0, Skipped 0
    [info]
    [info] All tests PASSED.
    [info] == test-finish ==

whereas the HTML report says:

Total for specification EcidiceSpec
Finished in 952 ms
Results 76 examples, 274 expectations, 0 failure, 0 error
  1. All resources (CSS/JavaScript/Images) referenced from the HTML report are missing. I assume they should have been copied to the outDir but they haven't.

The same happens with the current 1.1 release.

Kind regards
Andreas

Contradictory documentation

In the matchers guide the following is written:

The beEqualTo matcher is using the regular == Scala equality. However in the case of Arrays, Scala == is just using reference equality, eq, for Arrays. So the beEqualTo matcher has been adapted to transform Arrays to Seqs before checking for equality, so that Array(1, 2, 3) === Array(1, 2, 3) (despite the fact that Array(1, 2, 3) != Array(1, 2, 3)).

So is the bET matcher using == or has it been adapted? The above states both.

For me, both === and must beEqualTo don't work when using an array as the expectable.

I'm using version 2.9.0-1-1.5

scalaz dependency should be opaque

Ironically, we can't upgrade to specs2 in the scalaz test suite, because it depends on scalaz.

Similar issues exist for other projects that want to use a different version of scalaz than the one that specs2 is compiled against.

I suggest to repack scalaz with proguard or jarjar directly into the specs2 jar under a different package name.

Link to pending spec is missing an icon

Hi again,

using these two specs

import org.specs2._

object LinkingSpec extends Specification { def is =
  "Some title" ^
    "a pending spec" ~ PendingSpec
}
import org.specs2._

object PendingSpec extends Specification { def is =
  "The implementation of this spec is" ! pending
}

and this build.sbt

name := "pending again"

scalaVersion := "2.9.1"

testOptions := Seq(
  Tests.Filter(_ == "LinkingSpec"), 
  Tests.Argument("html", "console", "junitxml"))

libraryDependencies ++= Seq(
  "org.specs2" %% "specs2" % "1.6" % "test",
  "org.pegdown" % "pegdown" % "1.0.2" % "test",
  "junit" % "junit" % "4.7" % "test"
)

resolvers ++= Seq(
  "snapshots" at "http://scala-tools.org/repo-snapshots",
  "releases" at "http://scala-tools.org/repo-releases"
)

the generated HTML for LinkingSpec shows a missing image where the icon for pending (or is it "info"?) should be.

Incremental SBT Print-Out

Is there any way we can get the SBT Specs2 runner to print out examples as they pass/fail, rather than waiting until the entire specification has run? I have several specifications that take on the order of several minutes to run, and it's a little annoying having to constantly remind myself that "no, SBT isn't stuck, it's just waiting for Specs".

I don't know if this is an SBT issue or a Specs2 issue. I suspect SBT since I've seen this with other tasks before, but I figured I'd file here first since you are generally quicker to respond to issues. :-)

Example Failure Line Number

Back in Specs, when an example failed, the output was something of the form " (File.scala:123)", where "123" was the location of the assertion that failed. Unfortunately, Specs2 has taken a slight step backwards in that department: the line number is now the location of the example that failed. If you have an example with a large number of assertions (which I do!), it can be nearly impossible to figure out exactly which assertion is failing, just from this output. Usually, it requires some more trial-and-error fiddling with the assertions to locate the exact failure point, and that just seems unnecessary.

Could we get the line number to point at the assertion failure, rather than the example failure? (at least for mutable specifications)

Enhancement request: additional implicits

Hi,

I have three suggestions for additional implicits that helped me migrating from specs to specs2.

  1. The "include"-Methods in the SpecificationInclusion trait could be implicit, removing a lot of noise:

    Without implicit
    "ecidice is specified by" ^
      include(BoardSpec) ^
      include(DiceSpec) ^
      include(DiceMatcherSpec) ^
      include(SpaceSpec) ^
      include(TileSpec) ^
      // etc.
    With implicit
    "ecidice is specified by" ^
      BoardSpec ^
      DiceSpec ^
      DiceMatcherSpec ^
      SpaceSpec ^
      TileSpec ^
      // etc.
  2. An implicit to automatically combine match results:

    implicit def combineMatchResults[A](things: Iterable[A]): MatchResultCombination[A] = MatchResultCombination(things)
    
    case class MatchResultCombination[A](things: Iterable[A]) {
      def each[B](matcher: A => MatchResult[B]) = things map matcher reduceLeft (_ and _)
    }
    

Usage example in line 78 in:
https://bitbucket.org/asflierl/ecidice/src/659df30ebf21/src/test/scala/ecidice/model/mode/AnyModeWithMovementSpec.scala

  1. An implicit to use a sequence of test values as a one-column data table:
    implicit def stringToOneColumnHeader(name: String): OneColumnHeader = OneColumnHeader(name)
  
    case class OneColumnHeader(name: String) {
      def ||>[A](xs: Iterable[A]) = Table1(List(name), xs.toList.map(toDataRow), true)
    } 

Usage example in line 126 in:
https://bitbucket.org/asflierl/ecidice/src/659df30ebf21/src/test/scala/ecidice/model/mode/AnyModeWithMovementSpec.scala

Hopefull you find these suggestions worthwhile.

Kind regards
Andreas

execution blocked

I have written a mutable spec, it gets compiled but execution blocks -- sbt debug output shows

[debug] Running Test scalawt.AlignmentSpec : subclass(false, org.specs2.specification.SpecificationStructure) with arguments

but never finishes, CPU is not used by the sbt java vm process anymore

versions:

Linux mob 2.6.39.3 #1 SMP PREEMPT Mon Jul 11 14:49:51 CEST 2011 x86_64 x86_64 x86_64 GNU/Linux
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)
scala 2.9.0.1
sbt 0.10.1
specs2 1.5

you can find the code here:
git clone git://github.com/wookietreiber/scalawt.git

scalawt / src / test / scala / scalawt / AlignmentSpec.scala

other specs are working on this box so it might very well depend on how I have written the spec

if you need more information to fix this issue please don't hesitate to contact me

best regards
wookietreiber

specs2.outDir + junitxml

Hi,

using specs2 % 1.6-SNAPSHOT and sbt 0.10.1, it seems that the "junitxml" output is always written to target/test-reports instead of wherever specs2.outDir points to.

My build.sbt looks like this:

testOptions := Seq(
  Tests.Filter(_ == "eu.flierl.specs2tour.TourSpec"), 
  Tests.Argument("html", "console", "junitxml"))

testOptions <+= crossTarget map { ct =>
  Tests.Setup { () => System.setProperty("specs2.outDir", new File(ct, "specs2").getAbsolutePath) }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.