I am trying to setup running tests with type resol...
# detekt
d
I am trying to setup running tests with type resolution on detekt-rules-compose and looks like I'm stuck, need some ideas on what to try next. The process so far: 1. I need Compose to be in the classpath, so that test snippets can be correctly compiled by
compileAndLintWithContext
2. Using "native" android artifacts is not possible, because it required Android Gradle Plugin which I don't want to add (or should I try?) 3. Instead I started to use artifacts by Jetbrains's Compose Desktop, they do not require AGP 4. Now imports can be used, but if I compile a test snippet (see in thread), it fails with the "cannot inline "Box" method error" (see in thread) 5. If I a) add JB plugin to "plugins" block and b) write the same compose-code in the "Test.kt" file (not as snippet!) it compiles (without a) it gives the same "cannot-inline" error) So from 5 I can see that compiling compose code as part of the test project works, but compiling with
compileAndLintWithContext
doesn't work, it seems that compiler plugin gets applied in the first case and doesn't in second. Is there a way to make test rule aware of compiler plugins?
Compiling this snippet:
Copy code
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.foundation.layout.*

@Composable
fun Test(modifier: Modifier, value: Int) {
  Row {
    Column {
      Box(modifier = modifier.fillMaxSize()) { }
    }
  }
}
getting this error when running test:
Copy code
Back-end (JVM) Internal error: Couldn't inline method call: Box(modifier = modifier.fillMaxSize()) { }
Method: null
File being compiled: (12,7) in /Line_0.kts
google indicates that this generally happens when Compose compiler plugin is not applied.
b
Oh... This can be difficult to fix... The compiler that we use in the
compileAndLintWithContext
for sure doesn't have the compose plugin applied... And I'm not sure if that's even doable. Could you open an issue at detekt? This seems something that we should work on.
Meanwhile you could try if you run the rule "for real" you get some information. Developing code with println is far from optimal but maybe that un blocks you.
I didn't think of this before but maybe we are facing a limitation of detekt here.
d
👍 will try on "real code". But for now I devised a "workaround": I can simply define some functions right in the snippet which would mimic compose ones:
Copy code
fun Row(content: () -> Unit) {}

fun Test() {
  Row { ... }
}
etc This is a bit cumbersome in that all snippets will contain extra code, but this works too
Will create issue a bit later!
b
Yes, that have sense too.