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

Exception message when no operations defined impoved #233

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/LinChecker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.jetbrains.kotlinx.lincheck

import org.jetbrains.kotlinx.lincheck.annotations.*
import org.jetbrains.kotlinx.lincheck.annotations.Operation
import org.jetbrains.kotlinx.lincheck.execution.*
import org.jetbrains.kotlinx.lincheck.strategy.*
import org.jetbrains.kotlinx.lincheck.verifier.*
Expand Down Expand Up @@ -60,6 +61,7 @@ class LinChecker (private val testClass: Class<*>, options: Options<*, *>?) {
val failure = scenario.run(this, verifier)
if (failure != null) return failure
}
checkAtLeastOneMethodIsMarkedAsOperation(testClass)
var verifier = createVerifier()
repeat(iterations) { i ->
// For performance reasons, verifier re-uses LTS from previous iterations.
Expand Down Expand Up @@ -130,6 +132,12 @@ class LinChecker (private val testClass: Class<*>, options: Options<*, *>?) {
RandomProvider::class.java
).newInstance(this, testStructure, randomProvider)

private fun checkAtLeastOneMethodIsMarkedAsOperation(testClass: Class<*>) {
require (testClass.methods.any { it.isAnnotationPresent(Operation::class.java) }) {
"At least one method in a tested class should be marked as @Operation to make random scenarios generation possible. Please see official guide for more details."
avpotapov00 marked this conversation as resolved.
Show resolved Hide resolved
}
}

// This companion object is used for backwards compatibility.
companion object {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2023 JetBrains s.r.o.
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.jetbrains.kotlinx.lincheck_test.representation

import org.jetbrains.kotlinx.lincheck.check
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.ModelCheckingOptions
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import java.lang.IllegalArgumentException

/**
* This class is used to test the exception message when no operations are defined in a tested class.
*/
class NoOperationsDefinedTest {

@Test
fun test() {
val exception = assertThrows(IllegalArgumentException::class.java) { ModelCheckingOptions().check(this::class) }
avpotapov00 marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(
"At least one method in a tested class should be marked as @Operation to make random scenarios generation possible. Please see official guide for more details.",
avpotapov00 marked this conversation as resolved.
Show resolved Hide resolved
exception.message
)
}

}