diff options
-rw-r--r-- | build.gradle | 48 | ||||
-rw-r--r-- | gradle/integTest.gradle | 50 | ||||
-rw-r--r-- | src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy | 77 |
3 files changed, 155 insertions, 20 deletions
diff --git a/build.gradle b/build.gradle index fcca969..a3114ee 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,9 @@ - apply plugin: "groovy" apply plugin: "maven" apply plugin: "signing" +apply plugin: "idea" + +apply from: 'gradle/integTest.gradle' defaultTasks "build" @@ -20,8 +22,8 @@ ext { fregeVersion = "$fregeBaseVersion$fregeClassifier" // work around https://issues.gradle.org/browse/GRADLE-3281 - def home = new File(System.getProperty("user.home")) - def propfile = new File(home, ".gradle/gradle.properties") + def home = new File(System.getProperty("user.home")) + def propfile = new File(home, ".gradle/gradle.properties") if (propfile.exists()) { props = new Properties() propfile.withReader { @@ -59,21 +61,27 @@ dependencies { compile "$projectGroup:frege-repl-core:1.2" compile "$projectGroup:frege-native-gen:1.3" compile "org.functionaljava:functionaljava:4.4" + compile gradleApi() compile localGroovy() + testCompile gradleTestKit() + + testCompile('org.spockframework:spock-core:1.0-groovy-2.4') { + exclude module: 'groovy-all' + } } // using the publishing plugin buildscript { - repositories { - maven { - url "https://plugins.gradle.org/m2/" + repositories { + maven { + url "https://plugins.gradle.org/m2/" + } + } + dependencies { + classpath "com.gradle.publish:plugin-publish-plugin:0.9.1" } - } - dependencies { - classpath "com.gradle.publish:plugin-publish-plugin:0.9.1" - } } // Details on how to publish to the gradle plugin portal @@ -86,15 +94,15 @@ apply plugin: "com.gradle.plugin-publish" // The configuration example below shows the minimum required properties // configured to publish your plugin to the plugin portal pluginBundle { - website = 'https://github.com/Frege/frege-gradle-plugin' - vcsUrl = 'https://github.com/Frege/frege-gradle-plugin' - description = 'Enabling Frege for compilation, testing, documentation, and supporting tools.' - tags = ['frege', 'haskell', 'java'] - - plugins { - fregePlugin { - id = 'org.frege-lang' - displayName = 'Frege plugin' + website = 'https://github.com/Frege/frege-gradle-plugin' + vcsUrl = 'https://github.com/Frege/frege-gradle-plugin' + description = 'Enabling Frege for compilation, testing, documentation, and supporting tools.' + tags = ['frege', 'haskell', 'java'] + + plugins { + fregePlugin { + id = 'org.frege-lang' + displayName = 'Frege plugin' + } } - } } diff --git a/gradle/integTest.gradle b/gradle/integTest.gradle new file mode 100644 index 0000000..07b0743 --- /dev/null +++ b/gradle/integTest.gradle @@ -0,0 +1,50 @@ +sourceSets { + integTest { + compileClasspath += main.output + test.output + runtimeClasspath += main.output + test.output + } +} + +configurations { + integTestCompile.extendsFrom testCompile + integTestRuntime.extendsFrom testRuntime +} + +task integTest(type: Test) { + shouldRunAfter 'test' + testClassesDir = sourceSets.integTest.output.classesDir + classpath = sourceSets.integTest.runtimeClasspath + +} +check.dependsOn(integTest) + +plugins.withType(org.gradle.plugins.ide.idea.IdeaPlugin) { + idea { + module { + testSourceDirs += sourceSets.integTest.groovy.srcDirs + testSourceDirs += sourceSets.integTest.resources.srcDirs + scopes.TEST.plus.add(configurations.integTestCompile) + scopes.TEST.plus.add(configurations.integTestRuntime) + } + } +} + + +// START SNIPPET test-logic-classpath +// Write the plugin's classpath to a file to share with the tests +task createClasspathManifest { + def outputDir = file("$buildDir/$name") + + inputs.files sourceSets.main.runtimeClasspath + outputs.dir outputDir + + doLast { + outputDir.mkdirs() + file("$outputDir/plugin-classpath.txt").text = sourceSets.main.runtimeClasspath.join("\n") + } +} + +// Add the classpath file to the test runtime classpath +dependencies { + integTestRuntime files(createClasspathManifest) +}
\ No newline at end of file diff --git a/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy new file mode 100644 index 0000000..5c985e8 --- /dev/null +++ b/src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy @@ -0,0 +1,77 @@ +package frege.plugin + +import org.gradle.testkit.runner.GradleRunner +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import spock.lang.Specification + +import static org.gradle.testkit.runner.TaskOutcome.SUCCESS + +class FregePluginIntegTest extends Specification { + + @Rule + final TemporaryFolder testProjectDir = new TemporaryFolder() + File buildFile + + List<File> pluginClasspath + + def setup() { + buildFile = testProjectDir.newFile('build.gradle') + + 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 compile frege production code"() { + given: + buildFile << """ + plugins { + id 'org.frege-lang' + } + + repositories { + jcenter() + } + + dependencies { + compile "org.frege-lang:frege:3.22.367-g2737683" + } + + task sayHello(type: JavaExec){ + classpath = sourceSets.main.runtimeClasspath + main = 'HelloFrege' + } + + """ + + testProjectDir.newFolder("src", "main", "frege") + def fregeSourceFile = testProjectDir.newFile("src/main/frege/HelloFrege.fr") + + fregeSourceFile << """ +module HelloFrege where + +greeting = "Hello Frege!" + +main _ = do + println greeting +""" + + when: + def result = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments('sayHello') + .withPluginClasspath(pluginClasspath) + .build() + + then: + result.output.contains("Hello Frege!") + result.task(":sayHello").outcome == SUCCESS + } +}
\ No newline at end of file |