What's the configuration to be able to use Power A...
# power-assert
c
What's the configuration to be able to use Power Assert in
commonMain
? I have a module that contains fixtures. I have
Copy code
powerAssert {
	functions = listOf("kotlin.check")
	includedSourceSets = listOf("commonMain", "jvmMain", "jsMain", "nativeMain")
}
but I still get
Copy code
Check failed.
java.lang.IllegalStateException: Check failed.
	at opensavvy.ktmongo.bson.raw.TimestampTestKt.timestamp$lambda$9$lambda$5(TimestampTest.kt:69)
without Power Assert's message
b
Could you try running the suggested task here and see if it matches what you are specifying for
includedSourceSets
? https://youtrack.jetbrains.com/issue/KT-68534/Power-Assert-Android-sources-support#focus=Comments-27-10015561.0-0
Or, rather, you need to add
commonTest
,
jvmTest
,
jsTest
, etc to your included source sets. Once you override the default, you need to specify everything.
c
Copy code
> Task :bson-tests:printSourceSets
iosArm64Main
iosArm64Test
iosSimulatorArm64Main
iosSimulatorArm64Test
iosX64Main
iosX64Test
jsMain
jsTest
jvmMain
jvmTest
linuxArm64Main
linuxArm64Test
linuxX64Main
linuxX64Test
macosArm64Main
macosArm64Test
macosX64Main
macosX64Test
appleMain
commonMain
iosMain
linuxMain
macosMain
commonMain
nativeMain
tvosMain
watchosMain
mingwX64Main
mingwX64Test
tvosArm64Main
tvosArm64Test
tvosSimulatorArm64Main
tvosSimulatorArm64Test
tvosX64Main
tvosX64Test
wasmJsMain
wasmJsTest
watchosArm32Main
watchosArm32Test
watchosArm64Main
watchosArm64Test
watchosSimulatorArm64Main
watchosSimulatorArm64Test
watchosX64Main
watchosX64Test
In that module, there is only code in
commonMain
image.png
b
Hmm... Without more context,
jvmMain
looks like it should be enough for tests running on JVM, for example.
c
…and yet 😅
I don't know what more context I can give, but the project is public
b
Yeah, I was just about to ask. A link to the project would be great.
c
thank you color 1
I use that convention plugin extensively in other modules (where power assert is used only in the test sources) without any issues, so I don't think the problem is there
but maybe one of the
powerAssert
blocks erases the other?
b
That seems possible for
functions
since you have it defined in both locations, but I wouldn't suspect that for
includedSourceSets
since it's only in your
bson-tests
module.
Have you tried a check call in a main function or something in the
commonTest
module at all?
c
I have not, no. I run
./gradlew check
globally,
:bson-official
and
:bson-multiplatform
call the functions declared in
:bson-tests
I just did, and there the power assert plugin does work
Copy code
Exception in thread "main" java.lang.IllegalStateException: 
check(1 == 2)
        |
        false
So, why doesn't it work when depending on another module?
b
Could it be a gradle cache problem? I'm running the tests locally and it seems to be working without any changes?
Copy code
java.lang.IllegalStateException: 
check(read("a")?.readTimestamp()?.counter == 4294967294u)
      |          |                |       |
      |          |                |       false
      |          |                4294967295
      |          Timestamp(2106-02-07T06:28:15Z, #4294967295)
      Timestamp{value=-1, seconds=-1, inc=-1}
      {"a": {"$timestamp": {"t": 4294967295, "i": 4294967295}}}

        at opensavvy.ktmongo.bson.raw.TimestampTestKt.timestamp$lambda$15$lambda$9(TimestampTest.kt:69)
Or at least
:bson-official:check
worked.
:bson-multiplatform:check
worked (mostly) as I would expect as well. JVM and JS tests showed power-assert enhanced failures while the native tests did not. This is expected because power-assert
includedSourceSets
need to be the final compiled source set and not intermediate ones. If you add
macosArm64Main
and others instead of
nativeMain
, then it seems to work there as well.
c
Just tested it on another device, and I get the same results as you, so it's indeed probably a caching issue 😕
Thanks!
Is there a simple way to configure Power Assert for all source sets of a given module?
b
Nothing simple, no. I'd like to add a
defaultSourceSets
option to the Gradle DSL, configurable to
ALL | TEST_ONLY | NONE
or something like that. In the meantime, something like the following might work?
Copy code
includedSourceSets.set(provider {
	kotlin.targets.flatMap { target ->
		target.compilations.map { compilation ->
			compilation.defaultSourceSet.name
		}
	}
})