etorreborre/specs2

Referencing other specifications has no effect

Closed this issue · 8 comments

Hi,
I would like to have linked reference specification cases to be executed from a main specification, but this doesn't seem to work.
I try to follow the instructions of https://etorreborre.github.io/specs2/guide/SPECS2-3.8.6/org.specs2.guide.ReferenceOtherSpecifications.html and created same example as in page, but the linked reference specification cases are not being executed at all, only the main specification.

code example:

package com.akamai.csi.etp.automation.test

import org.specs2.Specification
import org.specs2.specification.core.Fragment

object FirstSpecification extends Specification { def is = s2"""
 We can consider one example
  ${ 1 must_== 1 }

  And all these examples are also important so we need to know if they all pass
  ${"important specification" ~ SecondSpecification}

  Finally it is worth having a look at ${"this specification" ~/ ThirdSpecification}.
"""
}

object SecondSpecification extends Specification { def is = s2"""
 This spec contains lots of examples
   ${ 1 must_== 2}
   ${ Fragment.foreach(1 to 100) { i => "example "+i ! ok } }
"""
}
object ThirdSpecification extends Specification { def is = s2"""
 This is the third specification with a simple example
   ${ 1 must_== 3 }
   this should pass $ok
"""
}

I execute FirstSpecification using mvn test in IntelliJ, these are the results i get:

[info] FirstSpecification
[info]  We can consider one example



` 1 must_== 1 `
[info]   + 1 must_== 1
[info] 
[info]   And all these examples are also important so we need to know if they all pass
[info]   * important specification

  Finally it is worth having a look at this specification.
[info] 
[info] Total for specification FirstSpecification
[info] Finished in 375 ms
1 example, 2 expectations, 0 failure, 0 error, 1 pending
[info] 

Screen Shot 2021-11-26 at 17 44 55

Expected behavior: Specification test cases of linked reference SecondSpecification will get executed when the first one FirstSpecification is.

Actual behavior: Only the cases of first specification FirstSpecification are being executed. Linked specification SecondSpecification` are not being executed at all.

I am running code from IntelliJ with specs2 4.13.1, scala 2.12.0 and jdk 1.8.0.
I observed same behaviour also with specs2 4.3.6 and scala 2.11.8.`

You need to pass the all argument in order to have linked specifications to execute.

When you execute a given specification you can pass the all argument to execute all the referenced specifications.

If you are running from Intellij you should be able to add a -Dspecs2.all=true property to your run to make this work.

It works! Thank you so much for your prompt response and great help. 🙏🏻

Hi @etorreborre, i've used the all argument for running the tests for a while, but sometimes i encounter a runtime error after tests specification is completed, that cause the run to hang with keep printing the error forever until i abort the run:

[info] Total for specification BatchDnsStatisticsAVC
[info] Finished in 41 seconds, 886 ms
39 examples, 0 failure, 0 error
[info] 
Exception in thread "specs2-7" java.lang.StackOverflowError
	at scala.collection.immutable.Vector.initFrom(Vector.scala:62)
	at scala.collection.immutable.VectorPointer$class.initFrom(Vector.scala:764)
	at scala.collection.immutable.Vector.initFrom(Vector.scala:62)
	at scala.collection.immutable.Vector.appendBack(Vector.scala:378)
	at scala.collection.immutable.Vector.$colon$plus(Vector.scala:153)
	at org.specs2.control.producer.Producers$$anonfun$runList$1.apply(Producer.scala:217)
	at org.specs2.control.producer.Producers$$anonfun$runList$1.apply(Producer.scala:217)
	at org.specs2.fp.Foldable$$anonfun$foldLeftM$2$$anonfun$apply$10.apply(Foldable.scala:24)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)
	at org.specs2.fp.Foldable$$anonfun$foldLeftM$2$$anonfun$apply$10.apply(Foldable.scala:24)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)
	at org.specs2.fp.Foldable$$anonfun$foldLeftM$2$$anonfun$apply$10.apply(Foldable.scala:24)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)
	at org.specs2.fp.Foldable$$anonfun$foldLeftM$2$$anonfun$apply$10.apply(Foldable.scala:24)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)
	at org.specs2.fp.Foldable$$anonfun$foldLeftM$2$$anonfun$apply$10.apply(Foldable.scala:24)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:163)
	at org.specs2.control.eff.EffImplicits$$anon$1.bind(Eff.scala:141)

... and so on.

I see the issue only when using the argument, either if executing a specification with linked references or not.
I use specs2 4.3.6 and scala 2.11.8.

Do you have an idea if this bug was resolved in later versions of specs2, or it is a newly reported issue?

Thanks in advance for your support.

I suppose it is out of question to ask you to try with the latest version 5.0.0-RC-23 (soon to be released as 5.0.0) because it is using Scala 3 :-)?

Can you then try to reproduce on a small sample project that I could run and debug on my side?

As my project runs on 2.11.8, it will be hard to try and run it with latest version and Scala 3 - The project has a lots of dependencies and so it won't be easy to upgrade unfortunately. The most i can do is to to run it with scala 2.12.0 that still supports specs2 version 4.13.1, can it help?

You can try that but if that does not work I'm going to need something that I can reproduce. Maybe the base of the stacktrace could also help if you can paste it.

Hi @etorreborre , i found how to deal with the issue i have here - increase the JDK stack solved it for me.
So i close the ticket again.
Thanks for your support!

Ok, good to know :-)