Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 0800f9a

Browse files
authoredJan 12, 2020
refactor method names for reflect/source (#376)
The reflect method should be renamed so it does not collide with the reflect package name. As is, it makes import reflect in the code non-idiomatic. Also renamed sourceMode to stay consistent. Noticed this here: #371 Also, refactor slice equals method
1 parent 1b95bd9 commit 0800f9a

File tree

5 files changed

+9
-26
lines changed

5 files changed

+9
-26
lines changed
 

‎mockgen/mockgen.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func main() {
6262
var pkg *model.Package
6363
var err error
6464
if *source != "" {
65-
pkg, err = parseFile(*source)
65+
pkg, err = sourceMode(*source)
6666
} else {
6767
if flag.NArg() != 2 {
6868
usage()
6969
log.Fatal("Expected exactly two arguments")
7070
}
71-
pkg, err = reflect(flag.Arg(0), strings.Split(flag.Arg(1), ","))
71+
pkg, err = reflectMode(flag.Arg(0), strings.Split(flag.Arg(1), ","))
7272
}
7373
if err != nil {
7474
log.Fatalf("Loading input failed: %v", err)

‎mockgen/mockgen_test.go

+2-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"reflect"
56
"regexp"
67
"strings"
78
"testing"
@@ -327,29 +328,9 @@ func TestGetArgNames(t *testing.T) {
327328
g := generator{}
328329

329330
result := g.getArgNames(testCase.method)
330-
if !testEqSliceStr(t, result, testCase.expected) {
331+
if !reflect.DeepEqual(result, testCase.expected) {
331332
t.Fatalf("expected %s, got %s", result, testCase.expected)
332333
}
333334
})
334335
}
335336
}
336-
337-
func testEqSliceStr(t *testing.T, a, b []string) bool {
338-
t.Helper()
339-
340-
if a == nil || b == nil {
341-
return false
342-
}
343-
344-
if len(a) != len(b) {
345-
return false
346-
}
347-
348-
for i := range a {
349-
if a[i] != b[i] {
350-
return false
351-
}
352-
}
353-
354-
return true
355-
}

‎mockgen/parse.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ var (
4141

4242
// TODO: simplify error reporting
4343

44-
func parseFile(source string) (*model.Package, error) {
44+
// sourceMode generates mocks via source file.
45+
func sourceMode(source string) (*model.Package, error) {
4546
srcDir, err := filepath.Abs(filepath.Dir(source))
4647
if err != nil {
4748
return nil, fmt.Errorf("failed getting source directory: %v", err)

‎mockgen/parse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,6 @@ func checkGreeterImports(t *testing.T, imports map[string]string) {
110110
func Benchmark_parseFile(b *testing.B) {
111111
source := "internal/tests/performance/big_interface/big_interface.go"
112112
for n := 0; n < b.N; n++ {
113-
parseFile(source)
113+
sourceMode(source)
114114
}
115115
}

‎mockgen/reflect.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ func runInDir(program []byte, dir string) (*model.Package, error) {
132132
return run(filepath.Join(tmpDir, progBinary))
133133
}
134134

135-
func reflect(importPath string, symbols []string) (*model.Package, error) {
135+
// reflectMode generates mocks via reflection on an interface.
136+
func reflectMode(importPath string, symbols []string) (*model.Package, error) {
136137
// TODO: sanity check arguments
137138

138139
if *execOnly != "" {

0 commit comments

Comments
 (0)
This repository has been archived.