From fdc7b27d69b22e0ffa151d56c8f3812dcd229555 Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Sun, 22 Nov 2015 00:50:45 +0000 Subject: some more work on coverage and some cleanup - get packages for integ tests right - introduce common AbstractFregeIntegrationSpec - first stab of unit test coverage for FregeCompile - minor cleanup on FregeCompile - configure fregePath as part as part of base plugin convention --- .../fixtures/AbstractFregeIntegrationSpec.groovy | 68 ++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy (limited to 'src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy') diff --git a/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy new file mode 100644 index 0000000..6bcd339 --- /dev/null +++ b/src/integTest/groovy/frege/gradle/integtest/fixtures/AbstractFregeIntegrationSpec.groovy @@ -0,0 +1,68 @@ +package frege.gradle.integtest.fixtures + +import org.gradle.testkit.runner.GradleRunner +import org.gradle.testkit.runner.BuildResult +import org.junit.Rule +import org.junit.rules.TemporaryFolder +import spock.lang.Specification + +class AbstractFregeIntegrationSpec extends Specification { + public static final String DEFAULT_FREGE_VERSION = "3.23.370-g898bc8c" + List pluginClasspath + + @Rule + final TemporaryFolder testProjectDir = new TemporaryFolder() + File buildFile + + def setup() { + buildFile = testProjectDir.newFile('build.gradle') + + + testProjectDir.newFolder("src", "main", "java", "org", "frege") + testProjectDir.newFolder("src", "main", "frege", "org", "frege") + + 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) } + } + + + BuildResult run(String task) { + run(null, task); + } + + BuildResult run(String gradleVersion, String task) { + def writer = new StringWriter(); + GradleRunner runner = newRunner(task, writer, gradleVersion) + def result = runner.build() + println writer; + return result; + } + + BuildResult fail(String task) { + def writer = new StringWriter(); + GradleRunner runner = newRunner(task, writer, null) + def result = runner.buildAndFail() + println writer; + return result; + } + + private GradleRunner newRunner(String task, StringWriter writer, String gradleVersion) { + def runner = GradleRunner.create() + .withProjectDir(testProjectDir.root) + .withArguments(task) + .withPluginClasspath(pluginClasspath) + .forwardStdOutput(writer) + if (gradleVersion) { + runner.withGradleVersion(gradleVersion) + } + runner + } + +} -- cgit