dave08
10/05/2021, 1:59 PMinline fun <reified T, R> Assertion.Builder<*>.getFromA(noinline function: T.() -> R): Assertion.Builder<R> =
isA<T>().get(function.describe(), function)
robfletcher
10/05/2021, 4:55 PMT
to being a subtype of whatever the current subject is?christophsturm
11/05/2021, 2:21 PMchristophsturm
11/20/2021, 1:13 PMexpectThat(listOf(A,B,C)) {
get {indexOf(A)}.isLowerThan(….)
}
robfletcher
01/25/2022, 6:08 PMexpectThat(data).dataAssertion()
robfletcher
02/01/2022, 4:07 PMEric
02/04/2022, 2:05 PMunwrap
? If so, is this ^ worth a PR?alightgoesout
02/07/2022, 2:59 PMFrank Coutinho
02/21/2022, 2:08 PMEric
03/01/2022, 1:51 PMexpect {
expectThat(foo) {
// ...
}
expectThat(bar) {
// ...
}
}
Eric
03/07/2022, 4:31 PMdave08
04/05/2022, 7:11 AMexpectThat(result) {
size.isEqualTo(4)
withElementAt(3) {
...
I get this:
Mapping 'element at index 3 %s' failed with: Index 3 out of bounds for length 3
Mapping 'element at index 3 %s' failed with: Index 3 out of bounds for length 3
at app//strikt.internal.AssertionBuilder.with(AssertionBuilder.kt:138)
at app//strikt.assertions.IterableKt.withElementAt(Iterable.kt:70)
Whereas I would have expected the size.isEqualTo(4)
would give me the size of the array BEFORE crashing on an out of bounds error... or even better, for soft-expectations, maybe not crash at all? Just give an x
just like any other failed assertion at the appropriate level?Eric
04/12/2022, 8:56 PMchristophsturm
05/18/2022, 4:19 PMRoukanken
05/19/2022, 1:56 PMI wonder if there’s a way to preventI don't think there is a way to prevent it compile time, but you can always just half-botch it by having the assert always fail whenif the generic type of the function has its own generic typeisA
T::class.typeParameters
is non-empty (eg, the reified class has some generic parameters on it's own)Eric
08/05/2022, 5:39 PMwithCaptured
(mockk) breaks assertion chaining if the slot has not been captured. It throws Mapping 'captured value %s' failed with: lateinit property captured has not been initialized
. Not sure if this is known or intentional. Would be nice if instead of throwing it would short circuit the block and fail.Eric
09/21/2022, 5:32 PMcompareTo
which is useful for things like BigDecimal
maybe add this?
fun <T : Comparable<T>> Assertion.Builder<T>.compareToEqual(expected: T) =
assert("is equal using compareTo to %s", expected) {
if (it.compareTo(expected) == 0) pass() else fail()
}
Eric
10/28/2022, 4:13 PMpropertiesAreEqualTo
that doesn’t require other
to be the same type as the subject. Just a couple minor tweaks.
fun <T : Any> Assertion.Builder<T>.reflectionEquals(
other: Any,
ignoredPropertyNames: List<String> = emptyList()
): Assertion.Builder<T> = compose("is equal field-by-field to %s", other) { subject ->
val otherBeanInfo = Introspector.getBeanInfo(other.javaClass)
val beanInfo = Introspector.getBeanInfo(subject.javaClass)
beanInfo.propertyDescriptors
.filter { it.name != "class" && it.name !in ignoredPropertyNames }
.forEach { property ->
val mappedAssertion = get("value of property ${property.name}") {
property.readMethod(this)
}
val otherProperty = otherBeanInfo.propertyDescriptors.firstOrNull { it.name == property.name }
val otherValue = otherProperty?.let { it.readMethod(other) }
// the rest is the same as propertiesAreEqualTo
dave08
12/08/2022, 2:36 PMBlock assertions do _not_ fail fast.
but if I use:
expectThat(result) {
get(Foo::prop1)...
get(Foo::prop2)...
}
It seems to only print out the first check's result... 🤔dave08
01/02/2023, 4:34 PMexpectThat(...)
was an inline fun
with reified type param, you could technically pass that type down to the assertions and it could be a great help for things like collections... currently if I pass a List<Foo>
to expectThat
I can pass a List<Baz>
that doesn't inherit from Foo
to contains
and that simply doesn't make sense... meaning refactoring to passing another type in the list could easily have the tests pass even though they shouldn't...robfletcher
01/06/2023, 4:36 PMdmcg
01/06/2023, 6:33 PMDan Rusu
01/08/2023, 3:12 AMArrayAssertions
but am getting strange failures where it's complaining about differing strings that appear to be equal so I wonder if I'm running into some sort of character encoding issue:
▼ Expect that "▼ Expect that ['f', 'n', 'o', 'r', 'd']:
| ✗ array content equals ['d', 'i', 's', 'c', 'o', 'r', 'd']":
✗ is equal to "▼ Expect that ['f', 'n', 'o', 'r', 'd']:
| ✗ array content equals ['d', 'i', 's', 'c', 'o', 'r', 'd']"
found "▼ Expect that ['f', 'n', 'o', 'r', 'd']:
| ✗ array content equals ['d', 'i', 's', 'c', 'o', 'r', 'd']"
The way the tests are written makes it very difficult (and frustrating) to deal with test failures because:
1. Double-clicking on a failed test in IntelliJ doesn't navigate to the failing test
2. Clicking the Rerun Failed Tests
button makes it seem like they all pass because it doesn't actually rerun any tests
I don't have these issues when I use Strikt for testing my own project so I wonder if this is caused by using contexts instead of a separate test method per scenarioDan Rusu
01/10/2023, 10:31 PMDan Rusu
01/11/2023, 11:30 PMDan Rusu
01/11/2023, 11:55 PMDan Rusu
01/13/2023, 11:25 PMline.separator
system property is anything other than \n
. This is because raw / triple-quoted strings are hard-coded to always be compiled with \n
line separators so they can't possibly match output that uses the line.separator
system property.
I didn't find any official documentation about this but found this:
https://stackoverflow.com/questions/48933641/kotlin-add-carriage-return-into-multiline-string#:~:text=Kotlin%20multiline%20strings%20are%20always,separator%22))%20.
and also found that the Kotlin standard library hardcoded \n
in the reindent
function (which is used by the trimIndent
& trimMargin
functions that are used throughout the tests):
https://github.com/JetBrains/kotlin/blob/master/libraries/stdlib/src/kotlin/text/Indent.kt#:~:text=.joinTo(StringBuild[…]eEstimate)%2C%20%22%5Cn%22)
So this brings up 2 issues:
1. The github action to run on windows doesn't seem to represent a regular windows environment. Perhaps something is overwriting the line.separator
system property.
2. Either the EOL
value in DefaultResultWriter
should be set to \n
(which makes the tests pass) or all the tests that assert against multi-line triple-quoted strings need to be fixed.Eric
05/31/2023, 2:11 PM.isA<Ok<Foo>>().get { value }
with .isSuccess<Foo>()
but I'm having trouble w/ the generic signatures.
fun <V> Assertion.Builder<Result<V, *>>.isSuccess(): Assertion.Builder<V> = isA<Ok<V>>().get { value }
fun <E> Assertion.Builder<Result<*, E>>.isFailure(): Assertion.Builder<E> = isA<Err<E>>().get { error }
IntelliJ is yelling at me. Any ideas on what these ext funs should look like? Thanks.Eric
06/08/2023, 1:01 PMpropertiesAreEqualToIgnoring
doesn't support nullable attributes as currently written
this should work, though
fun <T : Any> Assertion.Builder<T>.propertiesAreEqualToIgnoring(
other: T,
vararg ignoredProperties: KProperty1<T, Any?>,
): Assertion.Builder<T> = compareFieldByField(
other,
ignoredProperties.map(KProperty1<T, Any?>::name)
)
Just changed KProperty1<T, Any>
-> KProperty1<T, Any?>