-
Notifications
You must be signed in to change notification settings - Fork 40
/
main_test.go
53 lines (40 loc) · 2.06 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestIsGovvvDirective(t *testing.T) {
for directive := range govvvDirectives {
require.True(t, isGovvvDirective(directive))
}
require.False(t, isGovvvDirective("-o"))
}
func TestScrubGovvvDirectives(t *testing.T) {
require.Equal(t, []string{}, []string{}, "scrubGovvvDirectives should be fine with an empty arg array")
require.Equal(t, []string{"build", "-o", "a.out"}, scrubGovvvDirectives([]string{"build", "-o", "a.out"}),
"scrubGovvvDirectives should not touch normal go args")
require.Equal(t, []string{}, scrubGovvvDirectives([]string{"-flags"}),
"scrubGovvvDirectives should scrub -flags")
require.Equal(t, []string{"build", "-o", "a.out"}, scrubGovvvDirectives([]string{"build", "-o", "a.out", "-print"}),
"scrubGovvvDirectives should scrub -print")
require.Equal(t, []string{"build", "-o", "a.out"},
scrubGovvvDirectives([]string{"build", "-o", "a.out", "-pkg", "github.com/ahmetb/govvv"}),
"scrubGovvvDirectives should scrub -pkg and its argument")
}
func TestCollectGovvvDirective(t *testing.T) {
argument, ok := collectGovvvDirective([]string{}, flDryRun)
require.False(t, ok)
require.Equal(t, "", argument, "collectGovvvDirective should be fine with an empty arg array")
argument, ok = collectGovvvDirective([]string{"build", "-o", "a.out", "-print"}, flDryRun)
require.True(t, ok)
require.Equal(t, "", argument, "collectGovvvDirective should find -print")
argument, ok = collectGovvvDirective([]string{"-flags"}, flDryRunPrintLdFlags)
require.True(t, ok)
require.Equal(t, "", argument, "collectGovvvDirective should find -flags")
argument, ok = collectGovvvDirective([]string{"build", "-o", "a.out", "-pkg", "github.com/ahmetb/govvv"}, flPackage)
require.True(t, ok)
require.Equal(t, "github.com/ahmetb/govvv", argument, "collectGovvvDirective should find -pkg")
argument, ok = collectGovvvDirective([]string{"build", "-o", "a.out", "-pkg"}, flPackage)
require.False(t, ok)
require.Equal(t, "", argument, "collectGovvvDirective should catch missing argument for -pkg")
}