-
Notifications
You must be signed in to change notification settings - Fork 34
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
Instantiate testClass
taking into account its enclosing class
#466
Conversation
@ivandev0, please create a separate PR for the migration to JUnit 5. Also, let's keep using imports with |
Let's maybe drop JUnit 5 commit from this PR for now? It looks like migration to JUnit 5 might take some time due to the problem mentioned in #467 (comment) |
Unfortunately, the migration is required because I am using |
Lincheck does not force you to use JUnit test classes. You can rewrite the test to achieve the same goal: class OuterClass {
inner class InnerClass {
@Operation
fun zero() = 0
}
}
class InnerClassTest {
@Test
fun someTest() {
StressOptions()
.invocationsPerIteration(1)
.iterations(1)
.check(OuterClass.InnerClass::class)
}
} BTW, I renamed the test to |
41d2947
to
7c84a77
Compare
return constructor.newInstance() | ||
} | ||
|
||
if (this.enclosingClass != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we check if enclosingClass != null
as a first step, and only then look for default constructor with zero arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. Class can have a default constructor even if enclosingClass != null
. For example
package org.example
class A {
inner class B
}
class C {
class D
}
fun main() {
println(A.B::class.java.enclosingClass) // class org.example.A
println(C.D::class.java.enclosingClass) // class org.example.C
// But
A().B() // requires A object
C.D() // doesn't require C object
}
I can probably add such a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see, thanks.
Yes, it would be nice to add another test case for nested non-inner class (static nested in Java terminology).
@@ -329,3 +329,20 @@ internal inline fun <R> runOutsideIgnoredSection(descriptor: ThreadDescriptor?, | |||
|
|||
internal const val LINCHECK_PACKAGE_NAME = "org.jetbrains.kotlinx.lincheck." | |||
internal const val LINCHECK_RUNNER_PACKAGE_NAME = "org.jetbrains.kotlinx.lincheck.runner." | |||
|
|||
internal fun <T> Class<T>.newInstanceRecursive(): T { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name newInstanceRecursive
is a bit misleading IMO.
We just want to create some "default" instance of the class. We do not really care if it is inner or not, it is mostly an implementation detail.
So maybe rename to something like newDefaultInstance()
?
No description provided.