Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stacktrace lost when using custom matcher with should #3925

Open
kirillzh opened this issue Mar 11, 2024 · 3 comments
Open

Stacktrace lost when using custom matcher with should #3925

kirillzh opened this issue Mar 11, 2024 · 3 comments
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. waiting-for-clarification ❔ Issues with this tag are waiting on the user to provide more information

Comments

@kirillzh
Copy link

kirillzh commented Mar 11, 2024

Which version of Kotest are you using
5.8.0

I have a matcher like this:

fun beEnabled(buttonModel: ButtonModel) =
  Matcher<ButtonModel> { model ->
    MatcherResult(
      buttonModel.isEnabled,
      { "expected $model to be enabled" },
      { "expected $model to not be enabled" }
    )
  }

fun ButtonModel.shouldBeEnabled(): ButtonModel =
  apply {
    this should beEnabled(this)
  }

On failure shouldBeEnabled throws assertion error without full stacktrace which makes it hard to figure out where that assertion failed exactly:

java.lang.AssertionError: ....
expected ButtonModel(text=Continue, isEnabled=false, isLoading=false, leadingIcon=null, treatment=Primary, size=Footer, testTag=null, onClick=StandardClick(onClick=() -> kotlin.Unit)) to be enabled
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.internal.ScopeCoroutine.afterResume(Scopes.kt:32)
	at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)

When I change shouldBeEnabled implementation to this, I get the full stacktrace on failure, am I implementing a custom matcher wrong?

fun ButtonModel.shouldBeEnabled(): ButtonModel =
  apply {
    this.isEnabled.shouldBeTrue()
  }
@sksamuel
Copy link
Member

Is this the exact copy n paste from what you're using, because I can't see why this would be wrong.

@LeoColman
Copy link
Member

I think it's missing the class that the exception ocurred, and that's what they're pointing out

@LeoColman LeoColman added assertions 🔍 Related to the assertion mechanisms within the testing framework. waiting-for-clarification ❔ Issues with this tag are waiting on the user to provide more information labels Mar 11, 2024
@sksamuel
Copy link
Member

Yeah but when I try it I get the full stack trace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assertions 🔍 Related to the assertion mechanisms within the testing framework. waiting-for-clarification ❔ Issues with this tag are waiting on the user to provide more information
Projects
None yet
Development

No branches or pull requests

3 participants