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

Make it optional for parameter names to match named generators #360

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ kotlin {

val test by compilations.getting {
kotlinOptions.jvmTarget = "11"
kotlinOptions.options.javaParameters = true
}
}

Expand Down
17 changes: 11 additions & 6 deletions src/jvm/main/org/jetbrains/kotlinx/lincheck/CTestStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,17 @@ private static ParameterGenerator<?> getOrCreateGenerator(Method m,
Param paramAnn = p.getAnnotation(Param.class);
// If this annotation not presented use named generator based on name presented in @Operation or parameter name.
if (paramAnn == null) {
// If name in @Operation is presented, return the generator with this name,
// otherwise return generator with parameter's name
String name = nameInOperation != null ? nameInOperation :
(p.isNamePresent() ? p.getName() : null);
if (name != null)
return checkAndGetNamedGenerator(namedGens, name);
// If name in @Operation is presented, return the generator with this name
if (nameInOperation != null)
return checkAndGetNamedGenerator(namedGens, nameInOperation);

// Otherwise, if the parameter name matches a named generator, use that one
if (p.isNamePresent()) {
ParameterGenerator<?> generator = namedGens.get(p.getName());
if (generator != null)
return generator;
}

// Parameter generator is not specified, try to create a default one
ParameterGenerator<?> defaultGenerator = defaultGens.get(p.getType());
if (defaultGenerator != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ class MethodParameterGenerationTestWithSecondParameterAnnotated {

}

/**
* Test checks that a named generator matching a parameter name is applied.
*
* This relies on the parameter name being available (i.e. by being compiled with `-java-parameters`).
*/
@Param(name = "key", gen = IntGen::class, conf = "0:10")
class MethodParameterGenerationTestWithParameterNameMatchingGenerator {
@Operation
fun operation(key: Int) {
if (key < 0 || key > 10) {
throw InternalLincheckTestUnexpectedException
}
}

@Test
fun test() = ModelCheckingOptions().check(this::class)
}

/**
* Test checks that method with both parameters of the same type won't receive same values all the time
*/
Expand Down