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

Output fixed in case of an incorrect arguments count in custom scenarios #338

Merged
Show file tree
Hide file tree
Changes from 3 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ fun scenario(block: DSLScenarioBuilder.() -> Unit): ExecutionScenario =
internal fun actor(f: KFunction<*>, vararg args: Any?, cancelOnSuspension: Boolean = false): Actor {
val method = f.javaMethod ?: throw IllegalStateException("The function is a constructor or cannot be represented by a Java Method")
require(method.exceptionTypes.all { Throwable::class.java.isAssignableFrom(it) }) { "Not all declared exceptions are Throwable" }
val requiredArgsCount = method.parameters.size - if (f.isSuspend) 1 else 0
require(requiredArgsCount == args.size) { "The count of the supplied parameters for the ${f.name} method is incorrect: ${f.parameters.size} arguments expected, ${args.size} supplied." }
return Actor(
method = method,
arguments = args.toList(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Lincheck
*
* Copyright (C) 2019 - 2024 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.annotations.Operation
import org.jetbrains.kotlinx.lincheck.strategy.managed.modelchecking.ModelCheckingOptions
import org.jetbrains.kotlinx.lincheck_test.util.checkFailsWithException
import org.junit.Assert
import org.junit.Assert.assertEquals
import org.junit.Test

class IncorrectArgumentsCountInCustomScenarioActorTest {

@Operation
fun operation(value: Int) = Unit

@Test
fun testTooFew() {
val exception = Assert.assertThrows(IllegalArgumentException::class.java) {
ModelCheckingOptions()
.addCustomScenario {
parallel { thread { actor(::operation) } }
}
}
assertEquals("The count of the supplied parameters for the operation method is incorrect: 1 arguments expected, 0 supplied.", exception.message)
avpotapov00 marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
fun testTooMany() {
val exception = Assert.assertThrows(IllegalArgumentException::class.java) {
ModelCheckingOptions()
.addCustomScenario {
parallel { thread { actor(::operation, 1, 2) } }
}
}
assertEquals("The count of the supplied parameters for the operation method is incorrect: 1 arguments expected, 2 supplied.", exception.message)
}

}