From da9a1b100639e7eb5a7986952f5a1f3ba0d675e6 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Wed, 18 Nov 2015 12:48:31 +0000 Subject: Add infrastructure for adding integration tests using testkit --- .../frege/plugin/FregePluginIntegTest.groovy | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy (limited to 'src/integTest/groovy/frege/plugin/FregePluginIntegTest.groovy') 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 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 -- cgit