<commit_before>package glide.gradle

import directree.DirTree
import org.gradle.testkit.runner.GradleRunner
import spock.lang.Specification


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

// Help with Spock:
// - http://spockframework.github.io/spock/docs/1.0/spock_primer.html
// - http://spockframework.github.io/spock/docs/1.0/data_driven_testing.html
// - http://spockframework.github.io/spock/docs/1.0/extensions.html

class GlidePluginIntgTests extends Specification {

    //TODO  following is not great option - https://discuss.gradle.org/t/testkit-downloading-dependencies/12305
    public static final File testKitGradleHome = new File(System.getProperty('user.home'), '.gradle-testkit')

    public static final File testProjectDir = new File("build", "test-project")

    List<File> pluginClasspath

    def setup() {
        def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")

        if (pluginClasspathResource == null) {
            throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
        }

        this.pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) }

        DirTree.create(testProjectDir.absolutePath) {
            dir "app", {
                file "index.groovy", "println 'home'"
                file "index.html", "<h1>hello world</h1>"
            }
            file "build.gradle", """\
                   plugins {
                    id 'com.appspot.glide-gae'
                   }
                   appengine {
                        daemon = true
                   }
                """.stripIndent()
        }

    }

    def cleanup() {
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('appengineStop', '--debug' ,"--stacktrace")
                .build()



    }        // teardown
    def setupSpec() {}      // before-class
    def cleanupSpec() {}    // after-class

    def "prints glide version"() {
        when:
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('glideVersion', '--info')
                .build()

        then:
        result.output.contains('SNAPSHOT')
        result.task(":glideVersion").outcome == SUCCESS
    }

    def "syncs glide app"() {
        when:
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('glideSync', '--info')
                .build()

        def buildDir = new File(testProjectDir, "build")

        then:
        buildDir.isDirectory()
        new File(buildDir, "exploded-app/index.html").isFile()
        new File(buildDir, "exploded-app/index.groovy").isFile()<commit_msg>check realistic version, snapshot fails on non-snapshot builds<commit_after>package glide.gradle

import directree.DirTree
import org.gradle.testkit.runner.GradleRunner
import spock.lang.IgnoreRest
import spock.lang.Specification


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

// Help with Spock:
// - http://spockframework.github.io/spock/docs/1.0/spock_primer.html
// - http://spockframework.github.io/spock/docs/1.0/data_driven_testing.html
// - http://spockframework.github.io/spock/docs/1.0/extensions.html

class GlidePluginIntgTests extends Specification {

    //TODO  following is not great option - https://discuss.gradle.org/t/testkit-downloading-dependencies/12305
    public static final File testKitGradleHome = new File(System.getProperty('user.home'), '.gradle-testkit')

    public static final File testProjectDir = new File("build", "test-project")

    List<File> pluginClasspath

    def setup() {
        def pluginClasspathResource = getClass().classLoader.findResource("plugin-classpath.txt")

        if (pluginClasspathResource == null) {
            throw new IllegalStateException("Did not find plugin classpath resource, run `testClasses` build task.")
        }

        this.pluginClasspath = pluginClasspathResource.readLines().collect { new File(it) }

        DirTree.create(testProjectDir.absolutePath) {
            dir "app", {
                file "index.groovy", "println 'home'"
                file "index.html", "<h1>hello world</h1>"
            }
            file "build.gradle", """\
                   plugins {
                    id 'com.appspot.glide-gae'
                   }
                   appengine {
                        daemon = true
                   }
                """.stripIndent()
        }

    }

    def cleanup() {
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('appengineStop', '--debug' ,"--stacktrace")
                .build()



    }        // teardown
    def setupSpec() {}      // before-class
    def cleanupSpec() {}    // after-class

    def "prints glide version"() {
        File resourcesDir = pluginClasspath.find { it.isDirectory() && new File(it, "versions.properties").isFile() }
        Properties properties = new Properties()
        properties.load(new File(resourcesDir, "versions.properties").newInputStream())

        when:
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('glideVersion', '--info')
                .build()

        then:
        result.output.contains(properties.get("selfVersion"))
        result.task(":glideVersion").outcome == SUCCESS
    }

    def "syncs glide app"() {
        when:
        def result = GradleRunner.create()
                .withProjectDir(testProjectDir)
                .withTestKitDir(testKitGradleHome)
                .withPluginClasspath(pluginClasspath)
                .withArguments('glideSync', '--info')
                .build()

        def buildDir = new File(testProjectDir, "build")

        then:
        buildDir.isDirectory()
        new File(buildDir, "exploded-app/index.html").isFile()
        new File(buildDir, "exploded-app/index.groovy").isFile()
{'fraction_non_alphanumeric': 0.11381132075471698, 'fraction_numerical': 0.0039245283018867925, 'mean_word_length': 2.1093383388080715, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '983137', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1779, 'n_words': 330}