Last active
August 9, 2021 21:19
-
-
Save blast-hardcheese/e6790efa23c3b2ffbd14e5650f6a4875 to your computer and use it in GitHub Desktop.
scala/scalatest bug reproduction for https://github.com/scala/bug/issues/12441 and https://github.com/scalatest/scalatest/issues/2056
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bug.example | |
import org.scalatest.funsuite.AnyFunSuite | |
class SetSuite extends AnyFunSuite { | |
test("An empty Set should have size 0") { | |
// Option.empty[String].contains(1234) // WARNS | |
assert(Set.empty.size == 0) | |
} | |
test("Invoking head on an empty Set should produce NoSuchElementException") { | |
assertThrows[NoSuchElementException] { | |
// Option.empty[String].contains(1234) // WARNS | |
Set.empty.head | |
} | |
} | |
} | |
import org.scalatest.flatspec.AnyFlatSpec | |
class SetFlatSpec extends AnyFlatSpec { | |
"An empty Set" should "have size 0" in { | |
Option.empty[String].contains(1234) | |
assert(Set.empty.size == 0) | |
} | |
it should "produce NoSuchElementException when head is invoked" in { | |
assertThrows[NoSuchElementException] { | |
Option.empty[String].contains(1234) | |
Set.empty.head | |
} | |
} | |
} | |
import org.scalatest.funspec.AnyFunSpec | |
class SetFunSpec extends AnyFunSpec { | |
describe("A Set") { | |
describe("when empty") { | |
it("should have size 0") { | |
// Option.empty[String].contains(1234) // WARNS | |
assert(Set.empty.size == 0) | |
} | |
it("should produce NoSuchElementException when head is invoked") { | |
assertThrows[NoSuchElementException] { | |
// Option.empty[String].contains(1234) // WARNS | |
Set.empty.head | |
} | |
} | |
} | |
} | |
} | |
import org.scalatest.wordspec.AnyWordSpec | |
class SetWordSpec extends AnyWordSpec { | |
"A Set" when { | |
"empty" should { | |
"have size 0" in { | |
Option.empty[String].contains(1234) | |
assert(Set.empty.size == 0) | |
} | |
"produce NoSuchElementException when head is invoked" in { | |
assertThrows[NoSuchElementException] { | |
Option.empty[String].contains(1234) | |
Set.empty.head | |
} | |
} | |
} | |
} | |
} | |
import org.scalatest.freespec.AnyFreeSpec | |
class SetFreeSpec extends AnyFreeSpec { | |
"A Set" - { | |
"when empty" - { | |
"should have size 0" in { | |
Option.empty[String].contains(1234) | |
assert(Set.empty.size == 0) | |
} | |
"should produce NoSuchElementException when head is invoked" in { | |
assertThrows[NoSuchElementException] { | |
Option.empty[String].contains(1234) | |
Set.empty.head | |
} | |
} | |
} | |
} | |
} | |
import org.scalatest._ | |
import org.scalatest.propspec._ | |
import matchers._ | |
import prop._ | |
import scala.collection.immutable._ | |
class SetPropSpec extends AnyPropSpec with TableDrivenPropertyChecks with should.Matchers { | |
val examples = | |
Table[AbstractSet[Int]]( | |
"set", | |
BitSet.empty, | |
HashSet.empty[Int], | |
TreeSet.empty[Int] | |
) | |
property("an empty Set should have size 0") { | |
forAll(examples) { set => | |
// Option.empty[String].contains(1234) // WARNS | |
set.size should be (0) | |
} | |
} | |
property("invoking head on an empty set should produce NoSuchElementException") { | |
forAll(examples) { set => | |
a [NoSuchElementException] should be thrownBy { | |
Option.empty[String].contains(1234) | |
set.head | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment