<commit_before>package com.github.blindpirate.gogradle

import com.github.blindpirate.gogradle.core.InjectionHelper
import com.github.blindpirate.gogradle.vcs.git.GitNotationDependency
import com.github.blindpirate.gogradle.core.dependency.LocalDirectoryNotationDependency
import org.gradle.api.Project
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import static com.github.blindpirate.gogradle.core.dependency.AbstractGolangDependency.*
import static com.github.blindpirate.gogradle.util.DependencyUtils.*

@RunWith(GogradleRunner)
@WithProject
class GolangPluginTest {

    Project project

    @Before
    void applyPlugin() {
        project.pluginManager.apply(GolangPlugin)
    }

    @Test
    void 'smoke test should succeed'() {
    }

    @Test
    void 'InjectionHelper.INJECTOR_INSTANCE should be assigned'() {
        assert InjectionHelper.INJECTOR_INSTANCE != null
    }

    @Test
    void 'build and test should be added to configurations'() {
        assert project.configurations.build
        assert project.configurations.test
    }

    @Test
    void 'adding a dependency to configuration should succeed'() {
        project.dependencies {
            build 'github.com/a/b'
        }

        assert project.configurations.build.dependencies.size() == 1

        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
    }

    @Test
    void 'adding a dependency in form of map should succeed'() {
        project.dependencies {
            build name: 'github.com/a/b', commit: 'commitId', tag: '1.0.0', version: 'commitId', vcs: 'git'
        }

        assert project.configurations.build.dependencies.size() == 1
        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
        assert dependency.commit == 'commitId'
        assert dependency.version == 'commitId'
        assert dependency instanceof GitNotationDependency
    }

    def findFirstInDependencies() {
        return project.configurations.build.dependencies.find { true }
    }

    def findFirstInDependencies(String name) {
        return project.configurations.build.dependencies.find { it.name == name }
    }

    @Test
    void 'adding some dependencies should succeed'() {
        project.dependencies {
            build 'github.com/a/b@1.0.0',
                    'github.com/c/d#2.0.0'

            build(
                    [name: 'github.com/e/f', commit: 'commitId'],
                    [name: 'github.com/g/h', commit: 'commitId', vcs: 'git']
            )
        }

        assert project.configurations.build.dependencies.size() == 4

        def ab = findFirstInDependencies('github.com/a/b')
        assert ab.tag == '1.0.0'
        assert !ab.version

        def cd = findFirstInDependencies('github.com/c/d')
        assert cd.commit == '2.0.0'

        def ef = findFirstInDependencies('github.com/e/f')
        assert ef.commit == 'commitId'

        def gh = findFirstInDependencies('github.com/g/h')
        assert gh.commit == 'commitId'
    }

    @Test
    void 'adding a directory dependency should succeed'() {
        project.dependencies {
            build name: 'github.com/a/b', dir: '${GOPATH}/a/b'
        }

        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
        assert dependency instanceof LocalDirectoryNotationDependency
    }

    @Test
    void 'adding and configuring a directory dependency should succeed'() {
        project.dependencies {
            build(name: 'github.com/a/b', dir: '${GOPATH}/a/b') {
                transitive = false
            }
        }

        def dependency = findFirstInDependencies()
        assert dependency instanceof LocalDirectoryNotationDependency
        assert !getExclusionSpecs(dependency).isEmpty()

    }

    @Test
    void 'configuring a dependency should succeed'() {
        project.dependencies {
            build('github.com/a/b@1.0.0-RELEASE') {
                transitive = true
                exclude module: 'github.com/c/d'
            }

            build(name: 'github.com/c/d', url: '<EMAIL>:a/b.git') {
                transitive = false
            }
        }

        def ab = findFirstInDependencies('github.com/a/b')
        assert ab.tag == '1.0.0-RELEASE'
        assert getExclusionSpecs(ab).size() == 1
        assert getExclusionSpecs(ab).first() instanceof PropertiesExclusionSpec

        def cd = findFirstInDependencies('github.com/c/d')
        assert cd.url == 'git<EMAIL>:a/b.git'
        assert !getExclusionSpecs(cd).isEmpty()<commit_msg>use real directories instead of fake ones<commit_after>package com.github.blindpirate.gogradle

import com.github.blindpirate.gogradle.core.InjectionHelper
import com.github.blindpirate.gogradle.core.pack.LocalDirectoryDependency
import com.github.blindpirate.gogradle.vcs.git.GitNotationDependency
import org.gradle.api.Project
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith

import static com.github.blindpirate.gogradle.core.dependency.AbstractGolangDependency.PropertiesExclusionSpec
import static com.github.blindpirate.gogradle.util.DependencyUtils.getExclusionSpecs

@RunWith(GogradleRunner)
@WithProject
class GolangPluginTest {

    Project project

    @Before
    void applyPlugin() {
        project.pluginManager.apply(GolangPlugin)
    }

    @Test
    void 'smoke test should succeed'() {
    }

    @Test
    void 'InjectionHelper.INJECTOR_INSTANCE should be assigned'() {
        assert InjectionHelper.INJECTOR_INSTANCE != null
    }

    @Test
    void 'build and test should be added to configurations'() {
        assert project.configurations.build
        assert project.configurations.test
    }

    @Test
    void 'adding a dependency to configuration should succeed'() {
        project.dependencies {
            build 'github.com/a/b'
        }

        assert project.configurations.build.dependencies.size() == 1

        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
    }

    @Test
    void 'adding a dependency in form of map should succeed'() {
        project.dependencies {
            build name: 'github.com/a/b', commit: 'commitId', tag: '1.0.0', version: 'commitId', vcs: 'git'
        }

        assert project.configurations.build.dependencies.size() == 1
        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
        assert dependency.commit == 'commitId'
        assert dependency.version == 'commitId'
        assert dependency instanceof GitNotationDependency
    }

    def findFirstInDependencies() {
        return project.configurations.build.dependencies.find { true }
    }

    def findFirstInDependencies(String name) {
        return project.configurations.build.dependencies.find { it.name == name }
    }

    @Test
    void 'adding some dependencies should succeed'() {
        project.dependencies {
            build 'github.com/a/b@1.0.0',
                    'github.com/c/d#2.0.0'

            build(
                    [name: 'github.com/e/f', commit: 'commitId'],
                    [name: 'github.com/g/h', commit: 'commitId', vcs: 'git']
            )
        }

        assert project.configurations.build.dependencies.size() == 4

        def ab = findFirstInDependencies('github.com/a/b')
        assert ab.tag == '1.0.0'
        assert !ab.version

        def cd = findFirstInDependencies('github.com/c/d')
        assert cd.commit == '2.0.0'

        def ef = findFirstInDependencies('github.com/e/f')
        assert ef.commit == 'commitId'

        def gh = findFirstInDependencies('github.com/g/h')
        assert gh.commit == 'commitId'
    }

    @Test
    void 'adding a directory dependency should succeed'() {
        project.dependencies {
            build name: 'github.com/a/b', dir: project.rootDir.absolutePath
        }

        def dependency = findFirstInDependencies()
        assert dependency.name == 'github.com/a/b'
        assert dependency instanceof LocalDirectoryDependency
    }

    @Test
    void 'adding and configuring a directory dependency should succeed'() {
        project.dependencies {
            build(name: 'github.com/a/b', dir: project.rootDir.absolutePath) {
                transitive = false
            }
        }

        def dependency = findFirstInDependencies()
        assert dependency instanceof LocalDirectoryDependency
        assert !getExclusionSpecs(dependency).isEmpty()

    }

    @Test
    void 'configuring a dependency should succeed'() {
        project.dependencies {
            build('github.com/a/b@1.0.0-RELEASE') {
                transitive = true
                exclude module: 'github.com/c/d'
            }

            build(name: 'github.com/c/d', url: 'git<EMAIL>:a/b.git') {
                transitive = false
            }
        }

        def ab = findFirstInDependencies('github.com/a/b')
        assert ab.tag == '1.0.0-RELEASE'
        assert getExclusionSpecs(ab).size() == 1
        assert getExclusionSpecs(ab).first() instanceof PropertiesExclusionSpec

        def cd = findFirstInDependencies('github.com/c/d')
        assert cd.url == 'git@github.com:a/b.git'
        assert !getExclusionSpecs(cd).isEmpty()
{'fraction_non_alphanumeric': 0.10810232259445575, 'fraction_numerical': 0.005351600128438403, 'mean_word_length': 2.4077315827862873, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '6542666', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2607, 'n_words': 561}