diff options
author | Dierk König <dierk.koenig@canoo.com> | 2015-11-18 15:07:09 +0100 |
---|---|---|
committer | Dierk König <dierk.koenig@canoo.com> | 2015-11-18 15:07:09 +0100 |
commit | fa6dce676590c83bc84d130e1241cf585f88a469 (patch) | |
tree | 5a6227a8f7417a4cca0a522fe3e9ecf83bcc469a | |
parent | 59e5aa6a100ad84dd16545d8ef35a80b0af35195 (diff) | |
parent | da9a1b100639e7eb5a7986952f5a1f3ba0d675e6 (diff) | |
download | frege-gradle-plugin-fa6dce676590c83bc84d130e1241cf585f88a469.tar.gz frege-gradle-plugin-fa6dce676590c83bc84d130e1241cf585f88a469.tar.bz2 frege-gradle-plugin-fa6dce676590c83bc84d130e1241cf585f88a469.zip |
Merge pull request #27 from breskeby/integ-test-infra
Add infrastructure for having integration tests
-rw-r--r-- | build.gradle | 48 | ||||
-rw-r--r-- | gradle/integTest.gradle | 50 | ||||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.jar | bin | 53636 -> 53636 bytes | |||
-rw-r--r-- | gradle/wrapper/gradle-wrapper.properties | 4 | ||||
-rwxr-xr-x | gradlew | 10 | ||||
-rw-r--r-- | src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy | 77 |
6 files changed, 160 insertions, 29 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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differindex fd7e590..9411448 100644 --- a/gradle/wrapper/gradle-wrapper.jar +++ b/gradle/wrapper/gradle-wrapper.jar diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6e80329..2aae013 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Thu Sep 03 23:57:28 CEST 2015 +#Wed Nov 18 11:44:20 WET 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip @@ -42,11 +42,6 @@ case "`uname`" in ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" @@ -61,9 +56,9 @@ while [ -h "$PRG" ] ; do fi done SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -114,6 +109,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 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 |