did the thing where if you have no tests at all gr...
# community-support
c
did the thing where if you have no tests at all gradle test will error make it into gradle 9? wondering if I can delete my custom code that did that
v
Just tested with 9.0.0:
Execution failed for task ':test'.
> There are test sources present and no filters are applied, but the test task did not discover any tests to execute. This is likely due to a misconfiguration. Please check your test configuration. If this is not a misconfiguration, this error can be disabled by setting the 'failOnNoDiscoveredTests' property to false.
👍 1
c
sweet, finally some code reduction 😛
v
If you have no test sources at all, it will not fail though, but be skipped for
NO-SOURCE
c
well.. progress is ... uh, progress?
baby steps?
v
I don't think that this will (or should) change. A task with no sources is skipped, this is just consistent.
c
I disagree vehemently 😉
v
If you use
--tests
or similar filtering and no test is found it also fails
c
other build systems are sane
v
But if there are no source files, there are no source files. The failure on not found tests is for capturing misconfigurations like having source files for one test engine but only execution other test engines which most probable is a configuration error, or telling to execute X while there is no X.
c
maybe tasks in general should fail if they need inputs and have none
v
They do
Unless configured differently
c
no source files should mean a task fails 😉
v
And the Test task is configured as
@SkipWhenEmpty
if there are no files to test
c
then that should be removed 😉
v
No it should not
But feel free to post a feature request
c
disagree vehemently 😉
v
Just don't expect it to be accepted 🙂
c
I don't ever expect anything to be accepted
I expect gradle to not make progress
this one surprises me
that any progress was made at all
v
Don't use Gradle if you are that unhappy with it, but use one of the build tools you consider "sane" 🙂
c
ther aren't any sane build tools in java 😉
we need a new one (tm)
all of our cli tooling seems stuck in the '00s
v
Btw. you can simply do
maybe tasks in general should fail if they need inputs and have none
using
Copy code
tasks.configureEach {
    inputs.file(buildFile).skipWhenEmpty()
}
because a task is only skipped for
NO-SOURCE
if all
@SkipWhenEmpty
inputs are empty.
c
I have some kind of logic around this now... but I'll see if that's improved later
still means I should be able to remove some logic. I believe currently my logic is, no sources, and no tests executed
v
Of course my snippet only works if the
buildFile
actually exists
c
heh
v
To not depend on the build script file to exist, you could instead do
Copy code
tasks.configureEach {
    val fakeFke = Files.createTempFile("fake", ".fke")
    fakeFke.toFile().deleteOnExit()
    inputs.file(fakeFke).skipWhenEmpty()
}
for example
c
I'll figure out how to keep this stuff up later
Copy code
val available =
  tasks.register("tests available") {
    val java: Provider<FileCollection> = sourceSets.test.map { it.java }
    doLast {
      if (java.get().isEmpty) throw RuntimeException("no tests found")
    }
  }
Copy code
inputs.dir(rootProject.file("buildSrc/src/main"))
  finalizedBy(available)

  afterSuite(
    KotlinClosure2<TestDescriptor, TestResult, Unit>(
      { descriptor, result ->
        if (descriptor.parent == null) {
          logger.lifecycle("Tests run: ${result.testCount}, Failures: ${result.failedTestCount}, Skipped: ${result.skippedTestCount}")
          if (result.testCount == 0L) throw IllegalStateException("You cannot have 0 tests")
        }
        Unit
      },
    ),
  )
v
I'll figure out how to keep this stuff up later
Uhm, didn't I just tell you how?
c
yeah, but I have to do it accross 5 projects that aren't building 😉
so, not the problem in the next 5 seconds
👌 1