Skip to content

Commit

Permalink
Merge pull request #11 from percolate/fake_reset_method
Browse files Browse the repository at this point in the history
Small Fixes
  • Loading branch information
kevinbirch authored Dec 8, 2017
2 parents 99eec47 + 31b9f8a commit fcb2252
Show file tree
Hide file tree
Showing 18 changed files with 286 additions and 204 deletions.
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.4
0.9.5
6 changes: 5 additions & 1 deletion charlatan.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,9 @@ func main() {
log.Fatalf("error writing output: %s", err)
}

log.Printf("wrote %s\n", *outputPath)
out, err := filepath.Abs(*outputPath)
if err != nil {
out = *outputPath
}
log.Printf("wrote %s\n", out)
}
1 change: 1 addition & 0 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (i *Interface) addMethodFromField(field *ast.Field, imports *ImportSet) err
Name: field.Names[0].Name,
}

identSymGen.Reset()
// `Params.List` can be 0-length, but `Results` can be nil
for _, parameter := range functionType.Params.List {
identifiers, err := extractIdentifiersFromField(parameter, imports)
Expand Down
4 changes: 4 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func NewFake{{.Name}}DefaultError(t *testing.T) *Fake{{.Name}} {
}
}
func (f *Fake{{.Name}}) Reset() {
{{range .Methods}} f.{{.Name}}Calls = []*{{.Name}}Invocation{}
{{end}}}
{{range $m := .Methods}}
{{with $f := gensym}}func ({{$f}} *Fake{{$m.Interface}}) {{$m.Name}}({{$m.ParametersDeclaration}}) ({{$m.ResultsDeclaration}}) {
invocation := new({{$m.Name}}Invocation)
Expand Down
59 changes: 33 additions & 26 deletions testdata/array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ type ArrayParameterInvocation struct {
// ArrayReturnInvocation represents a single call of FakeArray.ArrayReturn
type ArrayReturnInvocation struct {
Results struct {
Ident2 [3]string
Ident1 [3]string
}
}

// SliceParameterInvocation represents a single call of FakeArray.SliceParameter
type SliceParameterInvocation struct {
Parameters struct {
Ident3 []string
Ident1 []string
}
}

// SliceReturnInvocation represents a single call of FakeArray.SliceReturn
type SliceReturnInvocation struct {
Results struct {
Ident4 []string
Ident1 []string
}
}

Expand Down Expand Up @@ -77,13 +77,13 @@ func NewFakeArrayDefaultPanic() *FakeArray {
ArrayParameterHook: func([3]string) {
panic("Unexpected call to Array.ArrayParameter")
},
ArrayReturnHook: func() (ident2 [3]string) {
ArrayReturnHook: func() (ident1 [3]string) {
panic("Unexpected call to Array.ArrayReturn")
},
SliceParameterHook: func([]string) {
panic("Unexpected call to Array.SliceParameter")
},
SliceReturnHook: func() (ident4 []string) {
SliceReturnHook: func() (ident1 []string) {
panic("Unexpected call to Array.SliceReturn")
},
}
Expand All @@ -96,15 +96,15 @@ func NewFakeArrayDefaultFatal(t *testing.T) *FakeArray {
t.Fatal("Unexpected call to Array.ArrayParameter")
return
},
ArrayReturnHook: func() (ident2 [3]string) {
ArrayReturnHook: func() (ident1 [3]string) {
t.Fatal("Unexpected call to Array.ArrayReturn")
return
},
SliceParameterHook: func([]string) {
t.Fatal("Unexpected call to Array.SliceParameter")
return
},
SliceReturnHook: func() (ident4 []string) {
SliceReturnHook: func() (ident1 []string) {
t.Fatal("Unexpected call to Array.SliceReturn")
return
},
Expand All @@ -118,21 +118,28 @@ func NewFakeArrayDefaultError(t *testing.T) *FakeArray {
t.Error("Unexpected call to Array.ArrayParameter")
return
},
ArrayReturnHook: func() (ident2 [3]string) {
ArrayReturnHook: func() (ident1 [3]string) {
t.Error("Unexpected call to Array.ArrayReturn")
return
},
SliceParameterHook: func([]string) {
t.Error("Unexpected call to Array.SliceParameter")
return
},
SliceReturnHook: func() (ident4 []string) {
SliceReturnHook: func() (ident1 []string) {
t.Error("Unexpected call to Array.SliceReturn")
return
},
}
}

func (f *FakeArray) Reset() {
f.ArrayParameterCalls = []*ArrayParameterInvocation{}
f.ArrayReturnCalls = []*ArrayReturnInvocation{}
f.SliceParameterCalls = []*SliceParameterInvocation{}
f.SliceReturnCalls = []*SliceReturnInvocation{}
}

func (_f1 *FakeArray) ArrayParameter(ident1 [3]string) {
invocation := new(ArrayParameterInvocation)

Expand Down Expand Up @@ -252,12 +259,12 @@ func (_f5 *FakeArray) AssertArrayParameterCalledOnceWith(t *testing.T, ident1 [3
}
}

func (_f6 *FakeArray) ArrayReturn() (ident2 [3]string) {
func (_f6 *FakeArray) ArrayReturn() (ident1 [3]string) {
invocation := new(ArrayReturnInvocation)

ident2 = _f6.ArrayReturnHook()
ident1 = _f6.ArrayReturnHook()

invocation.Results.Ident2 = ident2
invocation.Results.Ident1 = ident1

_f6.ArrayReturnCalls = append(_f6.ArrayReturnCalls, invocation)

Expand Down Expand Up @@ -316,12 +323,12 @@ func (f *FakeArray) AssertArrayReturnCalledN(t *testing.T, n int) {
}
}

func (_f7 *FakeArray) SliceParameter(ident3 []string) {
func (_f7 *FakeArray) SliceParameter(ident1 []string) {
invocation := new(SliceParameterInvocation)

invocation.Parameters.Ident3 = ident3
invocation.Parameters.Ident1 = ident1

_f7.SliceParameterHook(ident3)
_f7.SliceParameterHook(ident1)

_f7.SliceParameterCalls = append(_f7.SliceParameterCalls, invocation)

Expand Down Expand Up @@ -381,9 +388,9 @@ func (f *FakeArray) AssertSliceParameterCalledN(t *testing.T, n int) {
}

// SliceParameterCalledWith returns true if FakeArray.SliceParameter was called with the given values
func (_f8 *FakeArray) SliceParameterCalledWith(ident3 []string) (found bool) {
func (_f8 *FakeArray) SliceParameterCalledWith(ident1 []string) (found bool) {
for _, call := range _f8.SliceParameterCalls {
if reflect.DeepEqual(call.Parameters.Ident3, ident3) {
if reflect.DeepEqual(call.Parameters.Ident1, ident1) {
found = true
break
}
Expand All @@ -393,11 +400,11 @@ func (_f8 *FakeArray) SliceParameterCalledWith(ident3 []string) (found bool) {
}

// AssertSliceParameterCalledWith calls t.Error if FakeArray.SliceParameter was not called with the given values
func (_f9 *FakeArray) AssertSliceParameterCalledWith(t *testing.T, ident3 []string) {
func (_f9 *FakeArray) AssertSliceParameterCalledWith(t *testing.T, ident1 []string) {
t.Helper()
var found bool
for _, call := range _f9.SliceParameterCalls {
if reflect.DeepEqual(call.Parameters.Ident3, ident3) {
if reflect.DeepEqual(call.Parameters.Ident1, ident1) {
found = true
break
}
Expand All @@ -409,10 +416,10 @@ func (_f9 *FakeArray) AssertSliceParameterCalledWith(t *testing.T, ident3 []stri
}

// SliceParameterCalledOnceWith returns true if FakeArray.SliceParameter was called exactly once with the given values
func (_f10 *FakeArray) SliceParameterCalledOnceWith(ident3 []string) bool {
func (_f10 *FakeArray) SliceParameterCalledOnceWith(ident1 []string) bool {
var count int
for _, call := range _f10.SliceParameterCalls {
if reflect.DeepEqual(call.Parameters.Ident3, ident3) {
if reflect.DeepEqual(call.Parameters.Ident1, ident1) {
count++
}
}
Expand All @@ -421,11 +428,11 @@ func (_f10 *FakeArray) SliceParameterCalledOnceWith(ident3 []string) bool {
}

// AssertSliceParameterCalledOnceWith calls t.Error if FakeArray.SliceParameter was not called exactly once with the given values
func (_f11 *FakeArray) AssertSliceParameterCalledOnceWith(t *testing.T, ident3 []string) {
func (_f11 *FakeArray) AssertSliceParameterCalledOnceWith(t *testing.T, ident1 []string) {
t.Helper()
var count int
for _, call := range _f11.SliceParameterCalls {
if reflect.DeepEqual(call.Parameters.Ident3, ident3) {
if reflect.DeepEqual(call.Parameters.Ident1, ident1) {
count++
}
}
Expand All @@ -435,12 +442,12 @@ func (_f11 *FakeArray) AssertSliceParameterCalledOnceWith(t *testing.T, ident3 [
}
}

func (_f12 *FakeArray) SliceReturn() (ident4 []string) {
func (_f12 *FakeArray) SliceReturn() (ident1 []string) {
invocation := new(SliceReturnInvocation)

ident4 = _f12.SliceReturnHook()
ident1 = _f12.SliceReturnHook()

invocation.Results.Ident4 = ident4
invocation.Results.Ident1 = ident1

_f12.SliceReturnCalls = append(_f12.SliceReturnCalls, invocation)

Expand Down
Loading

0 comments on commit fcb2252

Please sign in to comment.