Skip to content

Commit

Permalink
Move test artifacts to internal packages (golang#243)
Browse files Browse the repository at this point in the history
* gomock: moves mock_gomock to an internal directory

mock_gomock is a test artifact. Moving it to an internal directory to
avoid having it exported.

* mockgen: moves tests to an internal directory

tests is a test artifact. Moving it to an internal directory to avoid having it
exported.

fixes golang#242
  • Loading branch information
poy authored and balshetzer committed Dec 4, 2018
1 parent 362bc29 commit bcb66aa
Show file tree
Hide file tree
Showing 43 changed files with 24 additions and 24 deletions.
File renamed without changes.
2 changes: 0 additions & 2 deletions gomock/matchers.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:generate mockgen -destination mock_matcher/mock_matcher.go github.com/golang/mock/gomock Matcher

// Copyright 2010 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
4 changes: 3 additions & 1 deletion gomock/matchers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:generate mockgen -destination internal/mock_matcher/mock_matcher.go github.com/golang/mock/gomock Matcher

package gomock_test

import (
"errors"
"testing"

"github.com/golang/mock/gomock"
mock_matcher "github.com/golang/mock/gomock/mock_matcher"
mock_matcher "github.com/golang/mock/gomock/internal/mock_matcher"
)

func TestMatchers(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package bugreport
import (
"log"

"github.com/golang/mock/mockgen/tests/aux_imports_embedded_interface/faux"
"github.com/golang/mock/mockgen/internal/tests/aux_imports_embedded_interface/faux"
)

// Source is an interface w/ an embedded foreign interface
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

This directory contains test for mockgen generating mocks when imported package
name does not match import path suffix. For example, package with name "client"
is located under import path "github.com/golang/mock/mockgen/tests/custom_package_name/client/v1".
is located under import path "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1".

Prior to this patch:

$ go generate greeter/greeter.go
2018/03/05 22:44:52 Loading input failed: greeter.go:17:11: failed parsing returns: greeter.go:17:14: unknown package "client"
greeter/greeter.go:1: running "mockgen": exit status 1

This can be fixed by manually providing `-imports` flag, like `-imports client=github.com/golang/mock/mockgen/tests/custom_package_name/client/v1`.
This can be fixed by manually providing `-imports` flag, like `-imports client=github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1`.
But, mockgen should be able to automatically resolve package names in such situations.

With this patch applied:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"fmt"

// non-matching import suffix and package name
"github.com/golang/mock/mockgen/tests/custom_package_name/client/v1"
"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1"

// matching import suffix and package name
"github.com/golang/mock/mockgen/tests/custom_package_name/validator"
"github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator"
)

type InputMaker interface {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
"github.com/golang/mock/mockgen/tests/custom_package_name/client/v1"
"github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1"
)

func TestGreeter_Greet(t *testing.T) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go github.com/golang/mock/mockgen/tests/internal_pkg/subdir/internal/pkg Intf
//go:generate mockgen -destination subdir/internal/pkg/reflect_output/mock.go github.com/golang/mock/mockgen/internal/tests/internal_pkg/subdir/internal/pkg Intf
//go:generate mockgen -source subdir/internal/pkg/input.go -destination subdir/internal/pkg/source_output/mock.go
package test

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package vendor_dep

//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/tests/vendor_dep VendorsDep
//go:generate mockgen -package vendor_dep -destination mock.go github.com/golang/mock/mockgen/internal/tests/vendor_dep VendorsDep
//go:generate mockgen -destination source_mock_package/mock.go -source=vendor_dep.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions mockgen/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func TestFileParser_ParseFile(t *testing.T) {
fs := token.NewFileSet()
file, err := parser.ParseFile(fs, "tests/custom_package_name/greeter/greeter.go", nil, 0)
file, err := parser.ParseFile(fs, "internal/tests/custom_package_name/greeter/greeter.go", nil, 0)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand Down Expand Up @@ -40,7 +40,7 @@ func TestFileParser_ParseFile(t *testing.T) {

func TestFileParser_ParsePackage(t *testing.T) {
fs := token.NewFileSet()
_, err := parser.ParseFile(fs, "tests/custom_package_name/greeter/greeter.go", nil, 0)
_, err := parser.ParseFile(fs, "internal/tests/custom_package_name/greeter/greeter.go", nil, 0)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -51,7 +51,7 @@ func TestFileParser_ParsePackage(t *testing.T) {
importedInterfaces: make(map[string]map[string]*ast.InterfaceType),
}

err = p.parsePackage("github.com/golang/mock/mockgen/tests/custom_package_name/greeter")
err = p.parsePackage("github.com/golang/mock/mockgen/internal/tests/custom_package_name/greeter")
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -61,7 +61,7 @@ func TestFileParser_ParsePackage(t *testing.T) {

func TestImportsOfFile(t *testing.T) {
fs := token.NewFileSet()
file, err := parser.ParseFile(fs, "tests/custom_package_name/greeter/greeter.go", nil, 0)
file, err := parser.ParseFile(fs, "internal/tests/custom_package_name/greeter/greeter.go", nil, 0)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
Expand All @@ -85,7 +85,7 @@ func checkGreeterImports(t *testing.T, imports map[string]string) {
if validatorPackage, ok := imports["validator"]; !ok {
t.Errorf("Expected imports to have key \"fmt\"")
} else {
expectedValidatorPackage := "github.com/golang/mock/mockgen/tests/custom_package_name/validator"
expectedValidatorPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/validator"
if validatorPackage != expectedValidatorPackage {
t.Errorf("Expected validator key to have value %s but got %s", expectedValidatorPackage, validatorPackage)
}
Expand All @@ -95,7 +95,7 @@ func checkGreeterImports(t *testing.T, imports map[string]string) {
if clientPackage, ok := imports["client"]; !ok {
t.Errorf("Expected imports to have key \"client\"")
} else {
expectedClientPackage := "github.com/golang/mock/mockgen/tests/custom_package_name/client/v1"
expectedClientPackage := "github.com/golang/mock/mockgen/internal/tests/custom_package_name/client/v1"
if clientPackage != expectedClientPackage {
t.Errorf("Expected client key to have value %s but got %s", expectedClientPackage, clientPackage)
}
Expand Down

0 comments on commit bcb66aa

Please sign in to comment.