<commit_before>package com.github.blindpirate.gogradle

import com.github.blindpirate.gogradle.support.AccessWeb
import com.github.blindpirate.gogradle.support.IntegrationTestSupport
import com.github.blindpirate.gogradle.support.WithProject
import com.github.blindpirate.gogradle.support.WithResource
import com.github.blindpirate.gogradle.util.IOUtils
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Go code in this test is from
 * https://github.com/golang/example/blob/master/hello/hello.go
 */
@RunWith(GogradleRunner)
@WithResource('')
@WithProject
class StringReverse extends IntegrationTestSupport {
    @Before
    void setUp() {
        IOUtils.write(resource, 'hello.go', helloDotGo)
        writeBuildAndSettingsDotGradle(buildDotGradle)
    }

    @Test
    @AccessWeb
    void 'build string reverse example should succeed'() {
        newBuild { build ->
            build.forTasks('dependencies build')
        }

        assertDependencyOutput()

        buildAgain()

        buildAgainAndAgain()
    }

    void buildAgain() {
        initStdoutStderr()

        newBuild { build ->
            build.forTasks('dependencies')
        }

        assertDependencyOutput()

        assert stdout.toString().contains(":resolveBuildDependencies UP-TO-DATE")
    }

    void buildAgainAndAgain() {
        initStdoutStderr()

        IOUtils.write(resource, 'hello.go', helloDotGo + " ")

        newBuild { build ->
            build.forTasks('dependencies')
        }

        assertDependencyOutput()

        assert !stdout.toString().contains(":resolveBuildDependencies UP-TO-DATE")
    }

    void assertDependencyOutput() {
        // "golang.org/x/tools:0d047c8 √" -> "golang.org/x/tools √"
        assert stdout.toString().replaceAll(/:[a-fA-F0-9]{7}/, '').contains('''
sample
└── github.com/golang/example √
    └── golang.org/x/tools √
''')
    }


    String helloDotGo = '''
package main

import (
    "fmt"

    "github.com/golang/example/stringutil"
)

func main() {
    fmt.Println(stringutil.Reverse("!selpmaxe oG ,olleH"))
}
'''
    String buildDotGradle = """
${buildDotGradleBase}
golang {
    packagePath='sample'
}
dependencies {
    build 'github.com/golang/example'
}
"""
<commit_msg>Fix failed tests<commit_after>package com.github.blindpirate.gogradle

import com.github.blindpirate.gogradle.support.AccessWeb
import com.github.blindpirate.gogradle.support.IntegrationTestSupport
import com.github.blindpirate.gogradle.support.WithProject
import com.github.blindpirate.gogradle.support.WithResource
import com.github.blindpirate.gogradle.util.IOUtils
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Go code in this test is from
 * https://github.com/golang/example/blob/master/hello/hello.go
 */
@RunWith(GogradleRunner)
@WithResource('')
@WithProject
class StringReverse extends IntegrationTestSupport {
    @Before
    void setUp() {
        String buildDotGradle = """
${buildDotGradleBase}
golang {
    packagePath='sample'
}
dependencies {
    build 'github.com/golang/example'
}
"""
        IOUtils.write(resource, 'hello.go', helloDotGo)
        writeBuildAndSettingsDotGradle(buildDotGradle)
    }

    @Test
    @AccessWeb
    void 'build string reverse example should succeed'() {
        newBuild { build ->
            build.forTasks('dependencies', 'build')
        }

        assertDependencyOutput()

        buildAgain()

        buildAgainAndAgain()
    }

    void buildAgain() {
        initStdoutStderr()

        newBuild { build ->
            build.forTasks('dependencies')
        }

        assertDependencyOutput()

        assert stdout.toString().contains(":resolveBuildDependencies UP-TO-DATE")
    }

    void buildAgainAndAgain() {
        initStdoutStderr()

        IOUtils.write(resource, 'hello.go', helloDotGo + " ")

        newBuild { build ->
            build.forTasks('dependencies')
        }

        assertDependencyOutput()

        assert !stdout.toString().contains(":resolveBuildDependencies UP-TO-DATE")
    }

    void assertDependencyOutput() {
        // "golang.org/x/tools:0d047c8 √" -> "golang.org/x/tools √"
        assert stdout.toString().replaceAll(/:[a-fA-F0-9]{7}/, '').contains('''
sample
└── github.com/golang/example √
    └── golang.org/x/tools √
''')
    }


    String helloDotGo = '''
package main

import (
    "fmt"

    "github.com/golang/example/stringutil"
)

func main() {
    fmt.Println(stringutil.Reverse("!selpmaxe oG ,olleH"))
}
'''


{'fraction_non_alphanumeric': 0.12789927104042412, 'fraction_numerical': 0.0035343494588027393, 'mean_word_length': 3.0141843971631204, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, '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': '5455005', 'n_tokens_mistral': 1518, 'n_tokens_neox': 1402, 'n_words': 232}