Skip to content

Commit 7e6b7d9

Browse files
committed
test: add -Dorg.gradle.kotlin.dsl.scriptCompilationAvoidance=false to work around gradle/gradle#34115
1 parent 36f2fdf commit 7e6b7d9

File tree

1 file changed

+40
-55
lines changed
  • src/test/kotlin/org/danilopianini/gradle/test

1 file changed

+40
-55
lines changed

src/test/kotlin/org/danilopianini/gradle/test/Tests.kt

Lines changed: 40 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -20,63 +20,48 @@ import org.gradle.testkit.runner.TaskOutcome
2020
import org.slf4j.Logger
2121
import org.slf4j.LoggerFactory
2222

23-
class Tests :
24-
StringSpec(
25-
{
26-
val testkitProperties = javaClass.classLoader.getResource("testkit-gradle.properties")?.readText()
27-
checkNotNull(testkitProperties) {
28-
"No file testkit-gradle.properties was generated"
29-
}
30-
val scan = ClassGraph().enableAllInfo()
31-
.acceptPackages(Tests::class.java.`package`.name)
32-
.scan()
33-
scan.getResourcesWithLeafName("test.yaml").flatMap { resource ->
34-
log.debug("Found test list in {}", resource)
35-
val yamlFile = File(resource.classpathElementFile.absolutePath + "/" + resource.path)
36-
val testConfiguration =
37-
Config {
38-
addSpec(Root)
39-
}.from.yaml.inputStream(resource.open())
40-
testConfiguration[Root.tests].map { it to yamlFile.parentFile }
41-
}.forEach { (test, location) ->
42-
log.debug("Test to be executed: {} from {}", test, location)
43-
val testFolder = folder { location.copyRecursively(toFile()) }
44-
log.debug("Test has been copied into {} and is ready to get executed", testFolder)
45-
test.description {
46-
testFolder.resolve("gradle.properties").writeText(testkitProperties)
47-
val result =
48-
GradleRunner
49-
.create()
50-
.withProjectDir(testFolder.toFile())
51-
.withPluginClasspath()
52-
.withArguments(test.configuration.tasks + test.configuration.options)
53-
.run { if (test.expectation.failure.isEmpty()) build() else buildAndFail() }
54-
println(result.tasks)
55-
println(result.output)
56-
test.expectation.output_contains.forEach {
57-
result.output shouldContain it
58-
}
59-
test.expectation.output_doesnt_contain.forEach {
60-
result.output shouldNotContain it
61-
}
62-
test.expectation.success.forEach {
63-
result.outcomeOf(it) shouldBe TaskOutcome.SUCCESS
64-
}
65-
test.expectation.failure.forEach {
66-
result.outcomeOf(it) shouldBe TaskOutcome.FAILED
67-
}
68-
test.expectation.file_exists.forEach {
69-
val file =
70-
File("${testFolder.absolutePathString()}/${it.name}").apply {
71-
shouldExist()
72-
shouldBeAFile()
73-
}
74-
it.validate(file)
75-
}
23+
class Tests : StringSpec({
24+
val testkitProperties = javaClass.classLoader.getResource("testkit-gradle.properties")?.readText()
25+
checkNotNull(testkitProperties) {
26+
"No file testkit-gradle.properties was generated"
27+
}
28+
val scan = ClassGraph().enableAllInfo().acceptPackages(Tests::class.java.`package`.name).scan()
29+
scan.getResourcesWithLeafName("test.yaml").flatMap { resource ->
30+
log.debug("Found test list in {}", resource)
31+
val yamlFile = File(resource.classpathElementFile.absolutePath + "/" + resource.path)
32+
val testConfiguration = Config { addSpec(Root) }.from.yaml.inputStream(resource.open())
33+
testConfiguration[Root.tests].map { it to yamlFile.parentFile }
34+
}.forEach { (test, location) ->
35+
log.debug("Test to be executed: {} from {}", test, location)
36+
val testFolder = folder { location.copyRecursively(toFile()) }
37+
log.debug("Test has been copied into {} and is ready to get executed", testFolder)
38+
test.description {
39+
testFolder.resolve("gradle.properties").writeText(testkitProperties)
40+
val result = GradleRunner.create()
41+
.withProjectDir(testFolder.toFile())
42+
.withPluginClasspath()
43+
.withArguments(
44+
test.configuration.tasks +
45+
test.configuration.options +
46+
"-Dorg.gradle.kotlin.dsl.scriptCompilationAvoidance=false",
47+
)
48+
.run { if (test.expectation.failure.isEmpty()) build() else buildAndFail() }
49+
println(result.tasks)
50+
println(result.output)
51+
test.expectation.output_contains.forEach { result.output shouldContain it }
52+
test.expectation.output_doesnt_contain.forEach { result.output shouldNotContain it }
53+
test.expectation.success.forEach { result.outcomeOf(it) shouldBe TaskOutcome.SUCCESS }
54+
test.expectation.failure.forEach { result.outcomeOf(it) shouldBe TaskOutcome.FAILED }
55+
test.expectation.file_exists.forEach {
56+
val file = File("${testFolder.absolutePathString()}/${it.name}").apply {
57+
shouldExist()
58+
shouldBeAFile()
7659
}
60+
it.validate(file)
7761
}
78-
},
79-
) {
62+
}
63+
}
64+
}) {
8065
companion object {
8166
val log: Logger = LoggerFactory.getLogger(Tests::class.java)
8267

0 commit comments

Comments
 (0)