Skip to content

Commit

Permalink
- disable stack on verify
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksiyp committed Apr 19, 2020
1 parent 4e65812 commit 1ff44ee
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -1037,6 +1037,7 @@ How to use:
relaxed=true|false
relaxUnitFun=true|false
recordPrivateCalls=true|false
stackTracesOnVerify=true|false
```

## DSL tables
Expand Down
2 changes: 2 additions & 0 deletions dsl/common/src/main/kotlin/io/mockk/MockKSettings.kt
Expand Up @@ -6,4 +6,6 @@ expect object MockKSettings {
val relaxUnitFun: Boolean

val recordPrivateCalls: Boolean

val stackTracesOnVerify: Boolean
}
3 changes: 3 additions & 0 deletions dsl/js/src/main/kotlin/io/mockk/MockKSettings.kt
Expand Up @@ -9,4 +9,7 @@ actual object MockKSettings {

actual val recordPrivateCalls: Boolean
get() = js("global.io_mockk_settings_recordPrivateCalls || false") as Boolean

actual val stackTracesOnVerify: Boolean
get() = js("global.io_mockk_settings_stackTracesOnVerify || false") as Boolean
}
3 changes: 3 additions & 0 deletions dsl/jvm/src/main/kotlin/io/mockk/MockKSettings.kt
Expand Up @@ -27,6 +27,9 @@ actual object MockKSettings {
actual val recordPrivateCalls: Boolean
get() = booleanProperty("recordPrivateCalls", "false")

actual val stackTracesOnVerify: Boolean
get() = booleanProperty("stackTracesOnVerify", "true")


fun setRelaxed(value: Boolean) {
properties.setProperty("relaxed", value.toString());
Expand Down
Expand Up @@ -4,6 +4,7 @@ import io.mockk.InternalPlatformDsl.toStr
import io.mockk.Invocation
import io.mockk.InvocationMatcher
import io.mockk.MockKGateway.*
import io.mockk.MockKSettings
import io.mockk.RecordedCall
import io.mockk.impl.InternalPlatform
import io.mockk.impl.Ref
Expand Down Expand Up @@ -58,8 +59,11 @@ open class UnorderedCallVerifier(
"$callIdxMsg should not be called" +
"\n\nCalls:\n" +
formatCalls(allCallsForMockMethod) +
"\n\nStack traces:\n" +
stackTraces(allCallsForMockMethod)
"\n" +
if (MockKSettings.stackTracesOnVerify)
"\n\nStack traces:\n" + stackTraces(allCallsForMockMethod)
else
""
)
}
} else when (allCallsForMockMethod.size) {
Expand All @@ -73,8 +77,11 @@ open class UnorderedCallVerifier(
"$callIdxMsg was not called." +
"\n\nCalls to same mock:\n" +
formatCalls(allCallsForMock) +
"\n\nStack traces:\n" +
stackTraces(allCallsForMock)
"\n" +
if (MockKSettings.stackTracesOnVerify)
"\n\nStack traces:\n" + stackTraces(allCallsForMock)
else
""
})
}
}
Expand Down Expand Up @@ -113,17 +120,23 @@ open class UnorderedCallVerifier(
"$callIdxMsg. No matching calls found." +
"\n\nCalls to same method:\n" +
formatCalls(allCallsForMockMethod) +
"\n\nStack traces:\n" +
stackTraces(allCallsForMockMethod)
"\n" +
if (MockKSettings.stackTracesOnVerify)
"\n\nStack traces:\n" + stackTraces(allCallsForMockMethod)
else
""
})
} else {
VerificationResult.Failure(
"$callIdxMsg. $n matching calls found, " +
"but needs at least $min${atMostMsg(max)} calls" +
"\nCalls:\n" +
formatCalls(allCallsForMock) +
"\n\nStack traces:\n" +
stackTraces(allCallsForMock)
"\n" +
if (MockKSettings.stackTracesOnVerify)
"\n\nStack traces:\n" + stackTraces(allCallsForMock)
else
""
)
}
}
Expand Down
@@ -1,6 +1,7 @@
package io.mockk.impl.verify

import io.mockk.Invocation
import io.mockk.MockKSettings
import io.mockk.RecordedCall
import io.mockk.StackElement
import io.mockk.impl.InternalPlatform
Expand Down Expand Up @@ -56,8 +57,11 @@ object VerificationHelpers {
return "\n\nMatchers: \n" + calls.map { it.matcher.toString() }.joinToString("\n") +
"\n\nCalls:\n" +
formatCalls(allCalls) +
"\n\nStack traces:\n" +
stackTraces(allCalls)
"\n" +
if (MockKSettings.stackTracesOnVerify)
"\nStack traces:\n" + stackTraces(allCalls)
else
""
}
}

0 comments on commit 1ff44ee

Please sign in to comment.