forked from ben-manes/gradle-versions-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KotlinDslUsageSpec.groovy
120 lines (103 loc) · 3.13 KB
/
KotlinDslUsageSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package com.github.benmanes.gradle.versions
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.Unroll
final class KotlinDslUsageSpec extends Specification {
@Rule final TemporaryFolder testProjectDir = new TemporaryFolder()
private File buildFile
def 'setup'() {
def mavenRepoUrl = getClass().getResource('/maven/').toURI()
buildFile = testProjectDir.newFile('build.gradle.kts')
buildFile <<
"""
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
plugins {
java
id("com.github.ben-manes.versions")
}
apply(plugin = "com.github.ben-manes.versions")
repositories {
maven(url = "${mavenRepoUrl}")
}
dependencies {
implementation("com.google.inject:guice:2.0")
}
""".stripIndent()
}
@Unroll
def "user friendly kotlin-dsl with #gradleVersion"() {
given:
buildFile << '''
tasks.named<DependencyUpdatesTask>("dependencyUpdates") {
checkForGradleUpdate = true
outputFormatter = "json"
outputDir = "build/dependencyUpdates"
reportfileName = "report"
resolutionStrategy {
componentSelection {
all {
if (candidate.version == "3.1" && currentVersion != "") {
reject("Guice 3.1 not allowed")
}
}
}
}
}
'''
when:
def result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withPluginClasspath()
.withProjectDir(testProjectDir.root)
.withArguments('dependencyUpdates')
.build()
then:
result.output.contains('''com.google.inject:guice [2.0 -> 3.0]''')
result.task(':dependencyUpdates').outcome == SUCCESS
where:
gradleVersion << ['5.6']
}
@Unroll
def "user friendly kotlin-dsl with #outputFormatter produces #expectedOutput"() {
given:
buildFile << """
tasks.named<DependencyUpdatesTask>("dependencyUpdates") {
checkForGradleUpdate = true
$outputFormatter
outputDir = "build/dependencyUpdates"
reportfileName = "report"
resolutionStrategy {
componentSelection {
all {
if (candidate.version == "3.1" && currentVersion != "") {
reject("Guice 3.1 not allowed")
}
}
}
}
}
"""
when:
def result = GradleRunner.create()
.withGradleVersion('5.6')
.withPluginClasspath()
.withProjectDir(testProjectDir.root)
.withArguments('dependencyUpdates')
.build()
then:
result.output.contains(expectedOutput)
result.task(':dependencyUpdates').outcome == SUCCESS
where:
outputFormatter << [
'outputFormatter = "json"',
'outputFormatter { print("Custom report") }'
]
expectedOutput << [
'com.google.inject:guice [2.0 -> 3.0]',
'Custom report'
]
}
}