update min supported version to 1.15 (#641)

This commit is contained in:
Cody Oss 2022-05-03 21:10:05 -06:00 коммит произвёл GitHub
Родитель 32e424a265
Коммит d8fb94763b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
17 изменённых файлов: 159 добавлений и 309 удалений

17
.github/workflows/test.yaml поставляемый
Просмотреть файл

@ -10,7 +10,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.11.x, 1.17.x]
go-version: [1.15.x, 1.18.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
@ -23,27 +23,18 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2
# Needed for versions <1.14 tests
- name: Install mock
run: |
GO111MODULE=off go get github.com/golang/mock | true
- name: Vet and build
run: |
go vet ./...
go build ./...
- name: Install tools
- name: Install mockgen
run: |
go install github.com/golang/mock/mockgen
GO111MODULE=off go get -u golang.org/x/lint/golint
- name: Run test scripts
- name: Run test script
run: |
./ci/check_go_fmt.sh
./ci/check_go_lint.sh
./ci/check_go_generate.sh
./ci/check_go_mod.sh
./ci/test.sh
./ci/check_panic_handling.sh
- name: Run Go tests

Просмотреть файл

@ -1,12 +0,0 @@
#!/bin/bash
# This script is used by the CI to check if the code is gofmt formatted.
set -euo pipefail
GOFMT_DIFF=$(IFS=$'\n'; gofmt -d $( find . -type f -name '*.go' ) )
if [[ -n "${GOFMT_DIFF}" ]]; then
echo "${GOFMT_DIFF}"
echo
echo "The go source files aren't gofmt formatted."
exit 1
fi

Просмотреть файл

@ -1,33 +0,0 @@
#!/bin/bash
# This script is used by the CI to check if 'go generate ./...' is up to date.
#
# Note: If the generated files aren't up to date then this script updates
# them despite printing an error message so running it the second time
# might not print any errors. This isn't very useful locally during development
# but it works well with the CI that downloads a fresh version of the repo
# each time before executing this script.
set -euo pipefail
BASE_DIR="$PWD"
TEMP_DIR=$( mktemp -d )
function cleanup() {
rm -rf "${TEMP_DIR}"
}
trap cleanup EXIT
cp -r . "${TEMP_DIR}/"
cd $TEMP_DIR
for i in $(find $PWD -name go.mod); do
pushd $(dirname $i)
go generate ./...
popd
done
if ! diff -r . "${BASE_DIR}"; then
echo
echo "The generated files aren't up to date."
echo "Update them with the 'go generate ./...' command."
exit 1
fi

Просмотреть файл

@ -1,17 +0,0 @@
#!/bin/bash
# This script is used by CI to check if the code passes golint.
set -u
if ! command -v golint >/dev/null; then
echo "error: golint not found; go get -u golang.org/x/lint/golint" >&2
exit 1
fi
GOLINT_OUTPUT=$(IFS=$'\n'; golint ./... | grep -v "mockgen/internal/.*\|sample/.*")
if [[ -n "${GOLINT_OUTPUT}" ]]; then
echo "${GOLINT_OUTPUT}"
echo
echo "The go source files aren't passing golint."
exit 1
fi

Просмотреть файл

@ -1,18 +0,0 @@
#!/bin/bash
# This script is used to ensure that the go.mod file is up to date.
set -euo pipefail
for i in $(find $PWD -name go.mod); do
pushd $(dirname $i)
go mod tidy
popd
done
if [ ! -z "$(git status --porcelain)" ]; then
git status
git diff
echo
echo "The go.mod is not up to date."
exit 1
fi

45
ci/test.sh Executable file
Просмотреть файл

@ -0,0 +1,45 @@
#!/bin/bash
# This script is used to ensure that the go.mod file is up to date.
set -euo pipefail
if [[ $(go version) != *"go1.18"* ]]; then
exit 0
fi
for i in $(find $PWD -name go.mod); do
pushd $(dirname $i)
go mod tidy
popd
done
if [ ! -z "$(git status --porcelain)" ]; then
git status
git diff
echo
echo "The go.mod is not up to date."
exit 1
fi
BASE_DIR="$PWD"
TEMP_DIR=$(mktemp -d)
function cleanup() {
rm -rf "${TEMP_DIR}"
}
trap cleanup EXIT
cp -r . "${TEMP_DIR}/"
cd $TEMP_DIR
for i in $(find $PWD -name go.mod); do
pushd $(dirname $i)
go generate ./...
popd
done
if ! diff -r . "${BASE_DIR}"; then
echo
echo "The generated files aren't up to date."
echo "Update them with the 'go generate ./...' command."
exit 1
fi

2
go.mod
Просмотреть файл

@ -5,4 +5,4 @@ require (
golang.org/x/tools v0.1.8
)
go 1.11
go 1.15

Просмотреть файл

@ -1,29 +0,0 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !go1.14
// +build !go1.14
package gomock_test
import "testing"
func TestDuplicateFinishCallFails(t *testing.T) {
rep, ctrl := createFixtures(t)
ctrl.Finish()
rep.assertPass("the first Finish call should succeed")
rep.assertFatal(ctrl.Finish, "Controller.Finish was called more than once. It has to be called exactly once.")
}

Просмотреть файл

@ -1,133 +0,0 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build go1.14
// +build go1.14
package gomock_test
import (
"testing"
"github.com/golang/mock/gomock"
)
func (e *ErrorReporter) Cleanup(f func()) {
e.t.Helper()
e.t.Cleanup(f)
}
func TestMultipleDefers(t *testing.T) {
reporter := NewErrorReporter(t)
reporter.Cleanup(func() {
reporter.assertPass("No errors for multiple calls to Finish")
})
ctrl := gomock.NewController(reporter)
ctrl.Finish()
}
// Equivalent to the TestNoRecordedCallsForAReceiver, but without explicitly
// calling Finish.
func TestDeferNotNeededFail(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
ctrl.Call(subject, "NotRecordedMethod", "argument")
}, "Unexpected call to", "there are no expected calls of the method \"NotRecordedMethod\" for that receiver")
})
ctrl = gomock.NewController(reporter)
}
func TestDeferNotNeededPass(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertPass("Expected method call made.")
})
ctrl = gomock.NewController(reporter)
ctrl.RecordCall(subject, "FooMethod", "argument")
ctrl.Call(subject, "FooMethod", "argument")
}
func TestOrderedCallsInCorrect(t *testing.T) {
reporter := NewErrorReporter(t)
subjectOne := new(Subject)
subjectTwo := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
gomock.InOrder(
ctrl.RecordCall(subjectOne, "FooMethod", "1").AnyTimes(),
ctrl.RecordCall(subjectTwo, "FooMethod", "2"),
ctrl.RecordCall(subjectTwo, "BarMethod", "3"),
)
ctrl.Call(subjectOne, "FooMethod", "1")
// FooMethod(2) should be called before BarMethod(3)
ctrl.Call(subjectTwo, "BarMethod", "3")
}, "Unexpected call to", "Subject.BarMethod([3])", "doesn't have a prerequisite call satisfied")
})
ctrl = gomock.NewController(reporter)
}
// Test that calls that are prerequisites to other calls but have maxCalls >
// minCalls are removed from the expected call set.
func TestOrderedCallsWithPreReqMaxUnbounded(t *testing.T) {
reporter := NewErrorReporter(t)
subjectOne := new(Subject)
subjectTwo := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
// Initially we should be able to call FooMethod("1") as many times as we
// want.
ctrl.Call(subjectOne, "FooMethod", "1")
ctrl.Call(subjectOne, "FooMethod", "1")
// But calling something that has it as a prerequite should remove it from
// the expected call set. This allows tests to ensure that FooMethod("1") is
// *not* called after FooMethod("2").
ctrl.Call(subjectTwo, "FooMethod", "2")
ctrl.Call(subjectOne, "FooMethod", "1")
})
})
ctrl = gomock.NewController(reporter)
}
func TestCallAfterLoopPanic(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
firstCall := ctrl.RecordCall(subject, "FooMethod", "1")
secondCall := ctrl.RecordCall(subject, "FooMethod", "2")
thirdCall := ctrl.RecordCall(subject, "FooMethod", "3")
gomock.InOrder(firstCall, secondCall, thirdCall)
defer func() {
err := recover()
if err == nil {
t.Error("Call.After creation of dependency loop did not panic.")
}
}()
// This should panic due to dependency loop.
firstCall.After(thirdCall)
})
ctrl = gomock.NewController(reporter)
}

Просмотреть файл

@ -843,3 +843,112 @@ func TestWithHelper(t *testing.T) {
t.Fatal("expected Helper to be invoked")
}
}
func (e *ErrorReporter) Cleanup(f func()) {
e.t.Helper()
e.t.Cleanup(f)
}
func TestMultipleDefers(t *testing.T) {
reporter := NewErrorReporter(t)
reporter.Cleanup(func() {
reporter.assertPass("No errors for multiple calls to Finish")
})
ctrl := gomock.NewController(reporter)
ctrl.Finish()
}
// Equivalent to the TestNoRecordedCallsForAReceiver, but without explicitly
// calling Finish.
func TestDeferNotNeededFail(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
ctrl.Call(subject, "NotRecordedMethod", "argument")
}, "Unexpected call to", "there are no expected calls of the method \"NotRecordedMethod\" for that receiver")
})
ctrl = gomock.NewController(reporter)
}
func TestDeferNotNeededPass(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertPass("Expected method call made.")
})
ctrl = gomock.NewController(reporter)
ctrl.RecordCall(subject, "FooMethod", "argument")
ctrl.Call(subject, "FooMethod", "argument")
}
func TestOrderedCallsInCorrect(t *testing.T) {
reporter := NewErrorReporter(t)
subjectOne := new(Subject)
subjectTwo := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
gomock.InOrder(
ctrl.RecordCall(subjectOne, "FooMethod", "1").AnyTimes(),
ctrl.RecordCall(subjectTwo, "FooMethod", "2"),
ctrl.RecordCall(subjectTwo, "BarMethod", "3"),
)
ctrl.Call(subjectOne, "FooMethod", "1")
// FooMethod(2) should be called before BarMethod(3)
ctrl.Call(subjectTwo, "BarMethod", "3")
}, "Unexpected call to", "Subject.BarMethod([3])", "doesn't have a prerequisite call satisfied")
})
ctrl = gomock.NewController(reporter)
}
// Test that calls that are prerequisites to other calls but have maxCalls >
// minCalls are removed from the expected call set.
func TestOrderedCallsWithPreReqMaxUnbounded(t *testing.T) {
reporter := NewErrorReporter(t)
subjectOne := new(Subject)
subjectTwo := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
reporter.assertFatal(func() {
// Initially we should be able to call FooMethod("1") as many times as we
// want.
ctrl.Call(subjectOne, "FooMethod", "1")
ctrl.Call(subjectOne, "FooMethod", "1")
// But calling something that has it as a prerequite should remove it from
// the expected call set. This allows tests to ensure that FooMethod("1") is
// *not* called after FooMethod("2").
ctrl.Call(subjectTwo, "FooMethod", "2")
ctrl.Call(subjectOne, "FooMethod", "1")
})
})
ctrl = gomock.NewController(reporter)
}
func TestCallAfterLoopPanic(t *testing.T) {
reporter := NewErrorReporter(t)
subject := new(Subject)
var ctrl *gomock.Controller
reporter.Cleanup(func() {
firstCall := ctrl.RecordCall(subject, "FooMethod", "1")
secondCall := ctrl.RecordCall(subject, "FooMethod", "2")
thirdCall := ctrl.RecordCall(subject, "FooMethod", "3")
gomock.InOrder(firstCall, secondCall, thirdCall)
defer func() {
err := recover()
if err == nil {
t.Error("Call.After creation of dependency loop did not panic.")
}
}()
// This should panic due to dependency loop.
firstCall.After(thirdCall)
})
ctrl = gomock.NewController(reporter)
}

Просмотреть файл

@ -1,5 +0,0 @@
module github.com/golang/mock/mockgen/internal/tests/overlapping_methods
go 1.14
require github.com/golang/mock v1.4.4

Просмотреть файл

@ -1,8 +0,0 @@
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=

Просмотреть файл

@ -1,6 +1,3 @@
//go:build go1.14
// +build go1.14
package overlap
type ReadCloser interface {

Просмотреть файл

@ -1,6 +1,3 @@
//go:build go1.14
// +build go1.14
package overlap
//go:generate mockgen -package overlap -destination mock.go -source overlap.go -aux_files github.com/golang/mock/mockgen/internal/tests/overlapping_methods=interfaces.go

Просмотреть файл

@ -1,6 +1,3 @@
//go:build go1.14
// +build go1.14
package overlap
import (

Просмотреть файл

@ -1,27 +0,0 @@
// Copyright 2019 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !go1.12
// +build !go1.12
package main
import (
"log"
)
func printModuleVersion() {
log.Printf("No version information is available for Mockgen compiled with " +
"version 1.11")
}

Просмотреть файл

@ -11,10 +11,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
//go:build go1.12
// +build go1.12
package main