mirror of
https://github.com/magefile/mage.git
synced 2026-10-24 06:19:18 +03:00
* * Removed stale type declarations in parse. * Updated parse and mg to make better use of types package. * Added function to types package to test for valid function. * Added function to to types package to wrap a valid FuncType as the * most greedy of FuncType * renamed IsFuncType and refactored to return error instead of bool. Made the return value of FuncTypeWrap more clear. * removed unused type func declarations
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package types
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestFuncCheck(t *testing.T) {
|
|
if FuncCheck(func() {}) != nil {
|
|
t.Errorf("expected func() to be a valid FuncType")
|
|
}
|
|
if FuncCheck(func() error { return nil }) != nil {
|
|
t.Errorf("expected func() error to be a valid FuncType")
|
|
}
|
|
if FuncCheck(func(context.Context) {}) != nil {
|
|
t.Errorf("expected func(context.Context) to be a valid FuncType")
|
|
}
|
|
if FuncCheck(func(context.Context) error { return nil }) != nil {
|
|
t.Errorf("expected func(context.Context) error to be a valid FuncType")
|
|
}
|
|
|
|
// Test the Invalid case
|
|
if err := FuncCheck(func(int) error { return nil }); err == nil {
|
|
t.Errorf("expected func(int) error to not be a valid FuncType\n\tgot error: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestFuncTypeWrap(t *testing.T) {
|
|
if FuncTypeWrap(func(i int) {}) != nil {
|
|
t.Errorf("expected func(int) to return nil")
|
|
}
|
|
|
|
if FuncTypeWrap(func() {}) == nil {
|
|
t.Errorf("expected func() to return a function")
|
|
}
|
|
|
|
if FuncTypeWrap(func() error { return nil }) == nil {
|
|
t.Errorf("expected func() error to return a function")
|
|
}
|
|
|
|
if FuncTypeWrap(func(context.Context) {}) == nil {
|
|
t.Errorf("expected func(context.Context) to return a function")
|
|
}
|
|
|
|
if FuncTypeWrap(func(context.Context) error { return nil }) == nil {
|
|
t.Errorf("expected func(context.Context) error to return a function")
|
|
}
|
|
}
|