Skip to content

Commit

Permalink
#337 - output fixed in case of an incorrect arguments count in th cus… (
Browse files Browse the repository at this point in the history
#338)

Output fixed in case of an incorrect arguments count in the custom scenario DSL
  • Loading branch information
avpotapov00 authored Jul 9, 2024
1 parent 11eefac commit df8d638
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
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) { "Invalid number of the operation ${f.name} parameters: $requiredArgsCount expected, ${args.size} provided." }
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("Invalid number of the operation operation parameters: 1 expected, 0 provided.", exception.message)
}

@Test
fun testTooMany() {
val exception = Assert.assertThrows(IllegalArgumentException::class.java) {
ModelCheckingOptions()
.addCustomScenario {
parallel { thread { actor(::operation, 1, 2) } }
}
}
assertEquals("Invalid number of the operation operation parameters: 1 expected, 2 provided.", exception.message)
}

}

0 comments on commit df8d638

Please sign in to comment.