mirror of
https://github.com/magefile/mage.git
synced 2026-10-24 06:19:18 +03:00
93 lines
1.9 KiB
Go
93 lines
1.9 KiB
Go
package parse
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestParse(t *testing.T) {
|
|
info, err := Package("./testdata", []string{"func.go", "command.go", "alias.go", "repeating_synopsis.go", "subcommands.go"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
expected := []Function{
|
|
{
|
|
Name: "ReturnsNilError",
|
|
IsError: true,
|
|
Comment: "Synopsis for \"returns\" error. And some more text.",
|
|
Synopsis: `Synopsis for "returns" error.`,
|
|
},
|
|
{
|
|
Name: "ReturnsVoid",
|
|
},
|
|
{
|
|
Name: "TakesContextReturnsError",
|
|
IsError: true,
|
|
IsContext: true,
|
|
},
|
|
{
|
|
Name: "TakesContextReturnsVoid",
|
|
IsError: false,
|
|
IsContext: true,
|
|
},
|
|
{
|
|
Name: "RepeatingSynopsis",
|
|
IsError: true,
|
|
Comment: "RepeatingSynopsis chops off the repeating function name. Some more text.",
|
|
Synopsis: "chops off the repeating function name.",
|
|
},
|
|
{
|
|
Name: "Foobar",
|
|
Receiver: "Build",
|
|
IsError: true,
|
|
},
|
|
{
|
|
Name: "Baz",
|
|
Receiver: "Build",
|
|
IsError: false,
|
|
},
|
|
}
|
|
|
|
// DefaultIsError
|
|
if info.DefaultFunc.IsError != true {
|
|
t.Fatalf("expected DefaultIsError to be true")
|
|
}
|
|
|
|
// DefaultName
|
|
if info.DefaultFunc.Name != "ReturnsNilError" {
|
|
t.Fatalf("expected DefaultName to be ReturnsNilError")
|
|
}
|
|
|
|
if info.Aliases["void"].Name != "ReturnsVoid" {
|
|
t.Fatalf("expected alias of void to be ReturnsVoid")
|
|
}
|
|
|
|
f, ok := info.Aliases["baz"]
|
|
if !ok {
|
|
t.Fatal("missing alias baz")
|
|
}
|
|
if f.Name != "Baz" || f.Receiver != "Build" {
|
|
t.Fatalf("expected alias of void to be Build.Baz")
|
|
}
|
|
|
|
if len(info.Aliases) != 2 {
|
|
t.Fatalf("expected to only have two aliases, but have %#v", info.Aliases)
|
|
}
|
|
|
|
for _, fn := range expected {
|
|
found := false
|
|
for _, infoFn := range info.Funcs {
|
|
if reflect.DeepEqual(fn, *infoFn) {
|
|
found = true
|
|
break
|
|
} else {
|
|
t.Logf("%#v", infoFn)
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("expected:\n%#v\n\nto be in:\n%#v", fn, info.Funcs)
|
|
}
|
|
}
|
|
}
|