@@ -10,7 +10,10 @@ import io.kotest.matchers.shouldBe
10
10
import io.kotest.matchers.string.shouldContain
11
11
import io.kotest.matchers.string.shouldNotContain
12
12
import java.io.File
13
- import org.gradle.internal.impldep.org.junit.rules.TemporaryFolder
13
+ import java.nio.file.Path
14
+ import kotlin.io.path.absolutePathString
15
+ import kotlin.io.path.createTempDirectory
16
+ import kotlin.io.path.writeText
14
17
import org.gradle.testkit.runner.BuildResult
15
18
import org.gradle.testkit.runner.GradleRunner
16
19
import org.gradle.testkit.runner.TaskOutcome
@@ -24,61 +27,54 @@ class Tests :
24
27
checkNotNull(testkitProperties) {
25
28
" No file testkit-gradle.properties was generated"
26
29
}
27
- val scan =
28
- ClassGraph ()
29
- .enableAllInfo()
30
- .acceptPackages(Tests ::class .java.`package`.name)
31
- .scan()
32
- scan
33
- .getResourcesWithLeafName(" test.yaml" )
34
- .flatMap { resource ->
35
- log.debug(" Found test list in {}" , resource)
36
- val yamlFile = File (resource.classpathElementFile.absolutePath + " /" + resource.path)
37
- val testConfiguration =
38
- Config {
39
- addSpec(Root )
40
- }.from.yaml.inputStream(resource.open())
41
- testConfiguration[Root .tests].map { it to yamlFile.parentFile }
42
- }.forEach { (test, location) ->
43
- log.debug(" Test to be executed: {} from {}" , test, location)
44
- val testFolder =
45
- folder {
46
- location.copyRecursively(this .root)
47
- }
48
- log.debug(" Test has been copied into {} and is ready to get executed" , testFolder)
49
- test.description {
50
- File (testFolder.root, " gradle.properties" ).writeText(testkitProperties)
51
- val result =
52
- GradleRunner
53
- .create()
54
- .withProjectDir(testFolder.root)
55
- .withPluginClasspath()
56
- .withArguments(test.configuration.tasks + test.configuration.options)
57
- .run { if (test.expectation.failure.isEmpty()) build() else buildAndFail() }
58
- println (result.tasks)
59
- println (result.output)
60
- test.expectation.output_contains.forEach {
61
- result.output shouldContain it
62
- }
63
- test.expectation.output_doesnt_contain.forEach {
64
- result.output shouldNotContain it
65
- }
66
- test.expectation.success.forEach {
67
- result.outcomeOf(it) shouldBe TaskOutcome .SUCCESS
68
- }
69
- test.expectation.failure.forEach {
70
- result.outcomeOf(it) shouldBe TaskOutcome .FAILED
71
- }
72
- test.expectation.file_exists.forEach {
73
- val file =
74
- File (" ${testFolder.root.absolutePath} /${it.name} " ).apply {
75
- shouldExist()
76
- shouldBeAFile()
77
- }
78
- it.validate(file)
79
- }
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)
80
75
}
81
76
}
77
+ }
82
78
},
83
79
) {
84
80
companion object {
@@ -88,9 +84,6 @@ class Tests :
88
84
" Task $name was not present among the executed tasks"
89
85
}
90
86
91
- private fun folder (closure : TemporaryFolder .() -> Unit ) = TemporaryFolder ().apply {
92
- create()
93
- closure()
94
- }
87
+ private fun folder (closure : Path .() -> Unit ) = createTempDirectory(" plugin-test" ).apply (closure)
95
88
}
96
89
}
0 commit comments