blob: 133b39aee9fcbb5a1d24ce175f57e5012603bd12 [file] [log] [blame]
package build
import (
"flag"
"testing"
"github.com/google/go-cmp/cmp"
)
func TestFlags(t *testing.T) {
cases := []struct {
args []string
want Options
}{{
// Defaults
args: []string{},
want: Options{},
}, {
args: []string{"-index", "/tmp"},
want: Options{
IndexDir: "/tmp",
},
}, {
// single large file pattern
args: []string{"-large_file", "*.md"},
want: Options{
LargeFiles: []string{"*.md"},
},
}, {
// multiple large file pattern
args: []string{"-large_file", "*.md", "-large_file", "*.yaml"},
want: Options{
LargeFiles: []string{"*.md", "*.yaml"},
},
}}
for _, c := range cases {
c.want.SetDefaults()
// depends on $PATH setting.
c.want.CTags = ""
got := Options{}
fs := flag.NewFlagSet("", flag.ContinueOnError)
got.Flags(fs)
if err := fs.Parse(c.args); err != nil {
t.Errorf("failed to parse args %v: %v", c.args, err)
} else if !cmp.Equal(got, c.want) {
t.Errorf("mismatch for %v (-want +got):\n%s", c.args, cmp.Diff(c.want, got))
}
}
}