Skip to content
Permalink
Browse files

#945 Shows missing element in failure message of shouldContainAll. (#980

)

* #945 Shows missing element in failure message of shouldContainAll.

* #945 Fixes failing test

* #973 Adds a samples type Gen which repeatably gives given samples

* Revert "#973 Adds a samples type Gen which repeatably gives given samples"

This reverts commit 7942978
  • Loading branch information...
ashishkujoy authored and sksamuel committed Sep 10, 2019
1 parent bbc3a19 commit 45d871fb0cff9ebd9045e4dcb35c95ee73380b9a
@@ -28,7 +28,8 @@ fun <T> containAll(vararg ts: T) = containAll(ts.asList())
fun <T> containAll(ts: Collection<T>): Matcher<Collection<T>> = object : Matcher<Collection<T>> {
override fun test(value: Collection<T>) = MatcherResult(
ts.all { value.contains(it) },
{ "Collection should contain all of ${ts.joinToString(", ", limit = 10) { stringRepr(it) }}" },
{ "Collection should contain all of ${ts.joinToString(", ", limit = 10) { stringRepr(it) }} " +
"but missing ${ts.filter { !value.contains(it) }.joinToString(", ", limit = 10) { stringRepr(it) }}" },
{ "Collection should not contain all of ${ts.joinToString(", ", limit = 10) { stringRepr(it) }}" }
)
}
@@ -1,12 +1,6 @@
package io.kotlintest.properties

import io.kotlintest.properties.shrinking.ChooseShrinker
import io.kotlintest.properties.shrinking.DoubleShrinker
import io.kotlintest.properties.shrinking.FloatShrinker
import io.kotlintest.properties.shrinking.IntShrinker
import io.kotlintest.properties.shrinking.ListShrinker
import io.kotlintest.properties.shrinking.Shrinker
import io.kotlintest.properties.shrinking.StringShrinker
import io.kotlintest.properties.shrinking.*
import kotlin.jvm.JvmOverloads
import kotlin.math.abs
import kotlin.random.Random
@@ -664,10 +664,10 @@ class CollectionMatchersTest : WordSpec() {
col should containAll(3, 2, 0)
}
}
"print errors unambiguously" {
"print errors unambiguously" {
shouldThrow<AssertionError> {
listOf<Number>(1, 2).shouldContainAll(listOf<Number>(1L, 2L))
}.message shouldBe "Collection should contain all of 1L, 2L"
}.message shouldBe "Collection should contain all of 1L, 2L but missing 1L, 2L"
}
}

@@ -2,67 +2,33 @@

package com.sksamuel.kotlintest.properties

import io.kotlintest.*
import io.kotlintest.inspectors.forAll
import io.kotlintest.matchers.comparables.beGreaterThan
import io.kotlintest.matchers.booleans.shouldBeTrue
import io.kotlintest.matchers.collections.contain
import io.kotlintest.matchers.collections.shouldContain
import io.kotlintest.matchers.collections.shouldContainAll
import io.kotlintest.matchers.collections.shouldHaveAtMostSize
import io.kotlintest.matchers.comparables.beGreaterThan
import io.kotlintest.matchers.comparables.gte
import io.kotlintest.matchers.comparables.lt
import io.kotlintest.matchers.doubles.shouldBeGreaterThanOrEqual
import io.kotlintest.matchers.doubles.shouldBeLessThanOrEqual
import io.kotlintest.matchers.floats.shouldBeGreaterThanOrEqual
import io.kotlintest.matchers.floats.shouldBeLessThanOrEqual
import io.kotlintest.matchers.comparables.gte
import io.kotlintest.matchers.comparables.lt
import io.kotlintest.matchers.ints.shouldBeLessThanOrEqual
import io.kotlintest.matchers.string.include
import io.kotlintest.properties.Gen
import io.kotlintest.properties.assertAll
import io.kotlintest.properties.bind
import io.kotlintest.properties.choose
import io.kotlintest.properties.constant
import io.kotlintest.properties.create
import io.kotlintest.properties.default
import io.kotlintest.properties.double
import io.kotlintest.properties.duration
import io.kotlintest.properties.forAll
import io.kotlintest.properties.forClassName
import io.kotlintest.properties.from
import io.kotlintest.properties.generateInfiniteSequence
import io.kotlintest.properties.int
import io.kotlintest.properties.list
import io.kotlintest.properties.localDate
import io.kotlintest.properties.localDateTime
import io.kotlintest.properties.localTime
import io.kotlintest.properties.map
import io.kotlintest.properties.negativeIntegers
import io.kotlintest.properties.next
import io.kotlintest.properties.nextPrintableString
import io.kotlintest.properties.numericDoubles
import io.kotlintest.properties.numericFloats
import io.kotlintest.properties.oneOf
import io.kotlintest.properties.period
import io.kotlintest.properties.positiveIntegers
import io.kotlintest.properties.set
import io.kotlintest.properties.take
import io.kotlintest.properties.*
import io.kotlintest.shouldBe
import io.kotlintest.shouldHave
import io.kotlintest.shouldNotBe
import io.kotlintest.shouldThrow
import io.kotlintest.specs.WordSpec
import io.kotlintest.tables.headers
import io.kotlintest.tables.row
import io.kotlintest.tables.table
import java.time.*
import java.util.Random
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.List
import kotlin.collections.Set
import kotlin.collections.last
import kotlin.collections.listOf
import kotlin.collections.mutableSetOf
import kotlin.collections.plusAssign
import kotlin.collections.setOf
import kotlin.collections.toList
import kotlin.collections.toSet

class GenTest : WordSpec() {
init {
@@ -32,7 +32,7 @@ class ExposeTest : WordSpec() {
shouldThrowAny {
extracting(persons) { name }
.shouldContainAll("<Some name that is wrong>")
}.message shouldBe "Collection should contain all of \"<Some name that is wrong>\""
}.message shouldBe "Collection should contain all of \"<Some name that is wrong>\" but missing \"<Some name that is wrong>\""
}

}

0 comments on commit 45d871f

Please sign in to comment.
You can’t perform that action at this time.