@@ -20,63 +20,48 @@ import org.gradle.testkit.runner.TaskOutcome
20
20
import org.slf4j.Logger
21
21
import org.slf4j.LoggerFactory
22
22
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()
76
59
}
60
+ it.validate(file)
77
61
}
78
- },
79
- ) {
62
+ }
63
+ }
64
+ }) {
80
65
companion object {
81
66
val log: Logger = LoggerFactory .getLogger(Tests ::class .java)
82
67
0 commit comments