<commit_before>package com.github.blindpirate.gogradle.task

import com.github.blindpirate.gogradle.Go
import com.github.blindpirate.gogradle.GogradleRunner
import com.github.blindpirate.gogradle.util.ReflectionUtils
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor

import java.util.function.Consumer

import static org.mockito.ArgumentMatchers.any
import static org.mockito.ArgumentMatchers.isNull
import static org.mockito.Mockito.verify

@RunWith(GogradleRunner)
class GoTest extends TaskTest {

    Go task

    @Before
    void setUp() {
        task = buildTask(Go)
    }

    @Test
    void 'go command on ToolTask should succeed'() {
        // when
        task.go('build -o "output name"')
        // then
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List)
        verify(buildManager).go(captor.capture(), isNull(), any(Consumer), any(Consumer), isNull())
        assert captor.getValue() == ['build', '-o', 'output name']
    }

    @Test(expected = MissingMethodException)
    void 'exception should be thrown if args number of go is more than 1'() {
        task.go('a', 'b')
    }

    @Test
    void 'run command on ToolTask should succeed'() {
        // when
        task.run('golint -v -a')
        // then
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List)
        verify(buildManager).run(captor.capture(), isNull(), any(Consumer), any(Consumer), isNull())
        assert captor.getValue() == ['golint', '-v', '-a']
    }

    @Test(expected = MissingMethodException)
    void 'exception should be thrown if args number of run is more than 1'() {
        task.run('a', 'b')
    }

    @Test
    void 'invoking doAddDefaultAction should succeed'() {
        task.doAddDefaultAction()
    }

    @Test
    void 'setting continueWhenFail should succeed'() {
        task.continueWhenFail = true
        assert ReflectionUtils.getField(task, 'continueWhenFail')
    }

    @Test
    void 'consuming stdout and stderr should succeed'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.run('golint -v -a', { stdout, stderr ->
            stdoutIsVisited = true
            stderrIsVisited = true
        })

        assert stderrIsVisited
        assert stdoutIsVisited
    }

    @Test
    void 'consuming stdout should succeed'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.run('golint -v -a', { stdout ->
            stdoutIsVisited = true
        })

        assert !stderrIsVisited
        assert stdoutIsVisited
    }

    @Test
    void 'closure with more than 2 args should be ignored'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.run('golint -v -a', { a, b, c ->
            stdoutIsVisited = true
            stderrIsVisited = true
        })

        assert !stderrIsVisited
        assert !stdoutIsVisited
    }<commit_msg>Improve test coverage of Go<commit_after>package com.github.blindpirate.gogradle.task

import com.github.blindpirate.gogradle.Go
import com.github.blindpirate.gogradle.GogradleRunner
import com.github.blindpirate.gogradle.util.ReflectionUtils
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor

import java.util.function.Consumer

import static org.mockito.ArgumentMatchers.any
import static org.mockito.ArgumentMatchers.anyList
import static org.mockito.ArgumentMatchers.isNull
import static org.mockito.Mockito.verify

@RunWith(GogradleRunner)
class GoTest extends TaskTest {

    Go task

    @Before
    void setUp() {
        task = buildTask(Go)
    }

    @Test
    void 'do-nothing-consumer should succeed'() {
        Consumer c = ReflectionUtils.getStaticField(Go, 'DO_NOTHING')
        c.accept(1)
    }

    @Test
    void 'go command on ToolTask should succeed'() {
        // when
        task.go('build -o "output name"')
        // then
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List)
        verify(buildManager).go(captor.capture(), isNull(), any(Consumer), any(Consumer), isNull())
        assert captor.getValue() == ['build', '-o', 'output name']
    }

    @Test(expected = MissingMethodException)
    void 'exception should be thrown if args number of go is more than 1'() {
        task.go('a', 'b')
    }

    @Test
    void 'run command on ToolTask should succeed'() {
        // when
        task.run('golint -v -a')
        // then
        ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List)
        verify(buildManager).run(captor.capture(), isNull(), any(Consumer), any(Consumer), isNull())
        assert captor.getValue() == ['golint', '-v', '-a']
    }

    @Test(expected = MissingMethodException)
    void 'exception should be thrown if args number of run is more than 1'() {
        task.run('a', 'b')
    }

    @Test
    void 'invoking doAddDefaultAction should succeed'() {
        task.doAddDefaultAction()
    }

    @Test
    void 'setting continueWhenFail should succeed'() {
        // given
        task.continueWhenFail = true
        // when
        task.go('test -v github.com/my/package')
        // then
        ArgumentCaptor<Consumer> captor = ArgumentCaptor.forClass(Consumer)
        verify(buildManager).go(anyList(), isNull(), any(Consumer), any(Consumer), captor.capture())
        assert captor.getValue().is(ReflectionUtils.getStaticField(Go,'DO_NOTHING'))
    }

    @Test
    void 'consuming stdout and stderr should succeed'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.go('test -v github.com/my/package', { stdout, stderr ->
            stdoutIsVisited = true
            stderrIsVisited = true
        })

        assert stderrIsVisited
        assert stdoutIsVisited
    }

    @Test
    void 'consuming stdout should succeed'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.go('test -v github.com/my/package', { stdout ->
            stdoutIsVisited = true
        })

        assert !stderrIsVisited
        assert stdoutIsVisited
    }

    @Test
    void 'closure with more than 2 args should be ignored'() {
        boolean stdoutIsVisited, stderrIsVisited
        task.run('golint -v -a', { a, b, c ->
            stdoutIsVisited = true
            stderrIsVisited = true
        })

        assert !stderrIsVisited
        assert !stdoutIsVisited
    }
{'fraction_non_alphanumeric': 0.10808684707363121, 'fraction_numerical': 0.0011013215859030838, 'mean_word_length': 2.611931818181818, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 14, 'https://': 0, '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': '4670201', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1874, 'n_words': 466}