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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
package frege.plugin
import org.gradle.testkit.runner.GradleRunner
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.Unroll
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
class FregePluginIntegTest extends Specification {
public static final String DEFAULT_FREGE_VERSION = "3.23.370-g898bc8c"
@Rule
final TemporaryFolder testProjectDir = new TemporaryFolder()
File buildFile
List<File> pluginClasspath
def setup() {
buildFile = testProjectDir.newFile('build.gradle')
buildFile << """
plugins {
id 'org.frege-lang'
}
repositories {
jcenter()
}
"""
def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")
if (pluginClasspathResource == null) {
// try again via file reference
pluginClasspathResource = new File("build/createClasspathManifest/plugin-classpath.txt")
if (pluginClasspathResource == null) {
throw new IllegalStateException("Did not find plugin classpath resource, run `integTestClasses` build task.")
}
}
pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) }
}
def "can handle non existing source directories"() {
given:
buildFile << """
dependencies {
compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION"
}
"""
when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('classes')
.withPluginClasspath(pluginClasspath)
.build()
then:
result.task(":compileFrege") != null
}
@Unroll
def "can compile and run frege code (gradle: #gradleVersion, frege: #fregeVersion)"() {
given:
buildFile << """
dependencies {
compile "org.frege-lang:frege:$fregeVersion"
}
${sayHelloTask()}
"""
testProjectDir.newFolder("src", "main", "frege", "org", "frege")
def fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr")
fregeSourceFile << """
module org.frege.HelloFrege where
greeting = "Hello Frege!"
main _ = do
println greeting
"""
when:
def result = GradleRunner.create()
.withGradleVersion(gradleVersion)
.withProjectDir(testProjectDir.root)
.withArguments('sayHello')
.withPluginClasspath(pluginClasspath)
.build()
then:
result.output.contains("Hello Frege!")
result.task(":sayHello").outcome == SUCCESS
where:
fregeVersion | gradleVersion
DEFAULT_FREGE_VERSION | "2.9"
DEFAULT_FREGE_VERSION | "2.8"
"3.22.367-g2737683" | "2.9"
"3.22.367-g2737683" | "2.8"
}
def "can reference java from frege"() {
given:
buildFile << """
dependencies {
compile "org.frege-lang:frege:$DEFAULT_FREGE_VERSION"
}
${sayHelloTask()}
"""
and:
testProjectDir.newFolder("src", "main", "frege", "org", "frege")
def fregeSourceFile = testProjectDir.newFile("src/main/frege/org/frege/HelloFrege.fr")
fregeSourceFile << """
module org.frege.HelloFrege where
data StaticHello = pure native org.frege.StaticHello where
pure native helloJava org.frege.StaticHello.helloJava :: () -> String
main _ = do
println(StaticHello.helloJava())
"""
testProjectDir.newFolder("src", "main", "java", "org", "frege")
def javaSourceFile = testProjectDir.newFile("src/main/java/org/frege/StaticHello.java")
javaSourceFile << """
package org.frege;
public class StaticHello {
public static String helloJava() {
return "hello from java";
}
}
"""
when:
def result = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withArguments('sayHello')
.withPluginClasspath(pluginClasspath)
.build()
then:
result.task(":compileJava").outcome == SUCCESS
result.task(":compileFrege").outcome == SUCCESS
result.output.contains("hello from java")
}
def sayHelloTask() {
return """task sayHello(type: JavaExec){
classpath = sourceSets.main.runtimeClasspath
main = 'org.frege.HelloFrege'
}"""
}
}
|