<commit_before>package org.gosulang.gradle.functional

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.VersionNumber
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Specification
import spock.lang.Unroll

import java.util.stream.Collectors

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

/**
 * Gradle 2.9 introduced a withGradleVersion() method to the testkit's GradleRunner API
 * This is very useful for testing iteratively against older Gradle versions.
 *  - however - 
 * All of our functional tests use the GradleRunner#withPluginClasspath method, introduced in Gradle 2.8
 *
 * Instead of reverting all functional tests to the pre-2.8 API, where the plugin classpath is substituted
 * into the buildscript, this test will use the Gradle 2.7-style GradleRunner, which should allow us to run a basic
 * sanity test against many older versions of Gradle.
 */
@Unroll
class SimpleGosuBuildWIthLegacyTestKitApiTest extends Specification {

    protected static final String LF = System.lineSeparator
    protected static final String FS = File.separator

    @Rule
    final TemporaryFolder testProjectDir = new TemporaryFolder()

    protected final URL _pluginClasspathResource = this.class.classLoader.getResource("plugin-classpath.txt")
    protected final URL _gosuVersionResource = this.class.classLoader.getResource("gosuVersion.txt")

    File buildScript
    File simplePogo, simpleTestPogo

    def setup() {
        testProjectDir.create()
        buildScript = testProjectDir.newFile('build.gradle')
        buildScript << 
            """
            buildscript {
                dependencies {
                    classpath files(${getClasspath()})
                }
            }
            apply plugin: 'org.gosu-lang.gosu'
            repositories {
                mavenLocal()
                mavenCentral()
                maven {
                    url 'https://oss.sonatype.org/content/repositories/snapshots' //for Gosu snapshot builds
                }
            }
    
            dependencies {
                compile group: 'org.gosu-lang.gosu', name: 'gosu-core-api', version: '$gosuVersion'
                testCompile group: 'junit', name: 'junit', version: '4.11'
            }
            """
    }

    def 'End-to-end classpath test [Gradle #gradleVersion]'() {
        
        given:
        simplePogo = new File(testProjectDir.root, asPath('src', 'main', 'gosu', 'SimplePogo.gs'))
        simplePogo.getParentFile().mkdirs()
        simplePogo << 
            """
            public class SimplePogo {
          
              function sayHi() : String {
                return "Hello there"
              }
            }
            """
        
        simpleTestPogo = new File(testProjectDir.root, asPath('src', 'test', 'gosu', 'SimpleTestPogo.gs'))
        simpleTestPogo.getParentFile().mkdirs()
        simpleTestPogo <<   
            """
            uses org.junit.Assert
            uses org.junit.Test
            
            public class SimpleTestPogo {
            
              @Test
              function sayHiTest() {
                var x = new SimplePogo()
                Assert.assertNotNull(x)
                Assert.assertEquals("Hello there", x.sayHi())
              }
            }
            """

        when:
        GradleRunner runner = GradleRunner.create()
                .withProjectDir(testProjectDir.root)
                .withArguments('build', '-is', '--no-daemon')
                .withGradleVersion(gradleVersion)
                .forwardOutput()

        BuildResult result
        result = knownBreak ? runner.buildAndFail() 
                            : runner.build()<commit_msg>What a shame - I can't seem to disable the daemon for functional tests<commit_after>package org.gosulang.gradle.functional

import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.util.VersionNumber
import org.junit.Rule
import org.junit.rules.TemporaryFolder
import spock.lang.Ignore
import spock.lang.Specification
import spock.lang.Unroll

import java.util.stream.Collectors

import static org.gradle.testkit.runner.TaskOutcome.SUCCESS

/**
 * Gradle 2.9 introduced a withGradleVersion() method to the testkit's GradleRunner API
 * This is very useful for testing iteratively against older Gradle versions.
 *  - however - 
 * All of our functional tests use the GradleRunner#withPluginClasspath method, introduced in Gradle 2.8
 *
 * Instead of reverting all functional tests to the pre-2.8 API, where the plugin classpath is substituted
 * into the buildscript, this test will use the Gradle 2.7-style GradleRunner, which should allow us to run a basic
 * sanity test against many older versions of Gradle.
 */
@Unroll
class SimpleGosuBuildWIthLegacyTestKitApiTest extends Specification {

    protected static final String LF = System.lineSeparator
    protected static final String FS = File.separator

    @Rule
    final TemporaryFolder testProjectDir = new TemporaryFolder()

    protected final URL _pluginClasspathResource = this.class.classLoader.getResource("plugin-classpath.txt")
    protected final URL _gosuVersionResource = this.class.classLoader.getResource("gosuVersion.txt")

    File buildScript
    File simplePogo, simpleTestPogo

    def setup() {
        testProjectDir.create()
        buildScript = testProjectDir.newFile('build.gradle')
        buildScript << 
            """
            buildscript {
                dependencies {
                    classpath files(${getClasspath()})
                }
            }
            apply plugin: 'org.gosu-lang.gosu'
            repositories {
                mavenLocal()
                mavenCentral()
                maven {
                    url 'https://oss.sonatype.org/content/repositories/snapshots' //for Gosu snapshot builds
                }
            }
    
            dependencies {
                compile group: 'org.gosu-lang.gosu', name: 'gosu-core-api', version: '$gosuVersion'
                testCompile group: 'junit', name: 'junit', version: '4.11'
            }
            """
    }

    @Ignore('Must be run locally. As of Gradle 2.9, no way to prevent TestKit from spawning many daemons, which causes OOME on CircleCI')
    def 'End-to-end classpath test [Gradle #gradleVersion]'() {
        
        given:
        simplePogo = new File(testProjectDir.root, asPath('src', 'main', 'gosu', 'SimplePogo.gs'))
        simplePogo.getParentFile().mkdirs()
        simplePogo << 
            """
            public class SimplePogo {
          
              function sayHi() : String {
                return "Hello there"
              }
            }
            """
        
        simpleTestPogo = new File(testProjectDir.root, asPath('src', 'test', 'gosu', 'SimpleTestPogo.gs'))
        simpleTestPogo.getParentFile().mkdirs()
        simpleTestPogo <<   
            """
            uses org.junit.Assert
            uses org.junit.Test
            
            public class SimpleTestPogo {
            
              @Test
              function sayHiTest() {
                var x = new SimplePogo()
                Assert.assertNotNull(x)
                Assert.assertEquals("Hello there", x.sayHi())
              }
            }
            """

        when:
        GradleRunner runner = GradleRunner.create()
                .withProjectDir(testProjectDir.root)
                .withArguments('build', '-is')
                .withGradleVersion(gradleVersion)
                .forwardOutput()

        BuildResult result
        result = knownBreak ? runner.buildAndFail() 
                            : runner.build()
{'fraction_non_alphanumeric': 0.08726384783446858, 'fraction_numerical': 0.0030844364477573575, 'mean_word_length': 2.0104448742746617, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3145915', 'n_tokens_mistral': 2100, 'n_tokens_neox': 1982, 'n_words': 522}