chainsaw icon indicating copy to clipboard operation
chainsaw copied to clipboard

Include other language's sourceSets in tests

Open renatoathaydes opened this issue 7 years ago • 9 comments

Issue based on https://github.com/gradle/gradle/issues/5303#issuecomment-387312957

When trying to run Kotlin or Groovy tests, this error occurs:

> Task :test FAILED

example.MyGroovyTest > initializationError FAILED
    java.lang.ClassNotFoundException

The stack-trace is not helpful as it just shows it can't find the class when running tests... but as @oehme pointed out in the original issue, looks like this line is to blame: it should add the source directories of all test tasks, not only Java's test task.

renatoathaydes avatar May 08 '18 11:05 renatoathaydes

it should add the source directories of all test tasks, not only Java's test task.

Not quite. It should add all classes as module patches, not just the classes compiled from Java. It should use test.classesDirs instead of test.java.outputDir.

oehme avatar May 08 '18 11:05 oehme

testClassesDirs returns a FileCollection with only the root directories, but it seems we need each and every file path. How do you get that (hoping there's a way without manually walking the file tree)?

renatoathaydes avatar May 08 '18 14:05 renatoathaydes

Oh well, I found out that this seems to give every class file:

"$moduleName=" + test.getTestClassesDirs().asFileTree.asPath

But the tests still do not run :( any ideas?

renatoathaydes avatar May 08 '18 14:05 renatoathaydes

You don't need the files, the root directories are just fine. Make sure you got the syntax right. I haven't checked what separator --patch-module expects.

oehme avatar May 08 '18 15:05 oehme

@oehme Using all files, or just the directories, it still doesn't run any tests.

The syntax is correct. I printed the option:

Using --patch-module com.athaydes.rawhttp.core=/Users/renato/programming/projects/rawhttp/rawhttp-core/build/classes/java/test:/Users/renato/programming/projects/rawhttp/rawhttp-core/build/classes/kotlin/test

The kotlin/test dir contains all the test class files, as expected... it just won't run the tests.

What else can control what tests should run (the names are correct as they worked on Java 8)???

renatoathaydes avatar May 08 '18 15:05 renatoathaydes

Looks like by adding a single Java test to the project, things go further...

But Gradle is just totally broken, now I get some other random error:

> Task :rawhttp-core:test FAILED
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.lang.ClassCastException: [email protected]/org.slf4j.helpers.NOPLoggerFactory cannot be cast to org.gradle.internal.logging.slf4j.OutputEventListenerBackedLoggerContext
        at org.gradle.internal.logging.slf4j.Slf4jLoggingConfigurer.configure(Slf4jLoggingConfigurer.java:42)
        at org.gradle.internal.logging.config.LoggingSystemAdapter.startCapture(LoggingSystemAdapter.java:54)
        at org.gradle.internal.logging.services.DefaultLoggingManager$StartableLoggingSystem.start(DefaultLoggingManager.java:324)
        at org.gradle.internal.logging.services.DefaultLoggingManager.start(DefaultLoggingManager.java:78)
        at org.gradle.internal.logging.services.DefaultLoggingManager.start(DefaultLoggingManager.java:37)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:83)
        at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:64)
        at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:62)
<=============> 100% EXECUTING [1m 57s]ternal.worker.GradleWorkerMain.main(GradleWorkerMain.java:67)

It just hangs there forever after that.

renatoathaydes avatar May 08 '18 15:05 renatoathaydes

Having SLF4j on the module path will break Gradle's test executors. That's a known bug.

I don't think adding a Java test fixed anything, it's just trying to run the Java class first. You'll still get the same error for the Groovy class later.

I don't know why it won't load that class, I'm afraid you'll have to debug that issue with gradle test --debug-jvm.

oehme avatar May 08 '18 16:05 oehme

Can you get Gradle to run any tests in Groovy or Kotlin?? I created a hello-world project to try and it just doesn't work no matter what I do.

renatoathaydes avatar May 08 '18 16:05 renatoathaydes

I don't have time to look into this atm, please try using a debugger to understand why the JVM won't load the class.

oehme avatar May 09 '18 07:05 oehme