Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
name: Go Build
on: [push]
permissions:
contents: read

jobs:
linux:
runs-on: ubuntu-latest
steps:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.25
go-version: 1.26
cache: false

- name: Checkout code
Expand All @@ -31,7 +34,7 @@ jobs:
# - name: Set up Go
# uses: actions/setup-go@v5
# with:
# go-version: 1.25
# go-version: 1.26
# cache: false

# - name: Checkout code
Expand All @@ -53,7 +56,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: 1.25
go-version: 1.26

- name: Checkout code
uses: actions/checkout@v4
Expand Down
3 changes: 3 additions & 0 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ MD022:
lines_above: 2
# Blank lines below heading
lines_below: 1

# MD041/first-line-heading - First line does not need to be a top level heading.
MD041: false
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TMPDIR ?= /tmp
# Setup default go-make installation flags.
INSTALL_FLAGS ?= -mod=readonly -buildvcs=auto
# Setup go-make version to use desired build and config scripts.
GOMAKE_DEP ?= github.com/tkrop/go-make@v0.0.166
GOMAKE_DEP ?= github.com/tkrop/go-make@v0.2.6
# Request targets from go-make show-targets target.
TARGETS := $(shell command -v $(GOBIN)/go-make >/dev/null || \
$(GO) install $(INSTALL_FLAGS) $(GOMAKE_DEP) >&2 && \
Expand Down
3 changes: 3 additions & 0 deletions Makefile.ext
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#@ updates the mock tool installing the latest version
update-mock:: install-mock
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tkrop/go-testing

go 1.25.7
go 1.26.2

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
Expand All @@ -10,13 +10,13 @@ require (
github.com/stretchr/testify v1.11.1
go.uber.org/mock v0.6.0
golang.org/x/text v0.30.0
golang.org/x/tools v0.41.0
golang.org/x/tools v0.44.0
)

require (
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect
golang.org/x/mod v0.32.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/mod v0.35.0 // indirect
golang.org/x/sync v0.20.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM=
golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU=
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k=
golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM=
golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc=
golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg=
golang.org/x/tools v0.44.0 h1:UP4ajHPIcuMjT1GqzDWRlalUEoY+uzoZKnhOjbIPD2c=
golang.org/x/tools v0.44.0/go.mod h1:KA0AfVErSdxRZIsOVipbv3rQhVXTnlU6UhKxHd1seDI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
2 changes: 1 addition & 1 deletion internal/mock/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ func NewFiles(mocks []*Mock, imports ...*Import) []*File {
}
}

files := []*File{}
files := make([]*File, 0, len(builders))
for _, builder := range builders {
file := builder.AddImports(imports...).Build()
files = append(files, file)
Expand Down
2 changes: 1 addition & 1 deletion internal/reflect/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (r *random) newPrimitive(kind reflect.Kind) any {
case reflect.Uint64:
return uint64(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Uintptr:
return uintptr(r.rand.Intn(2<<r.length) + 1)
return uintptr(r.rand.Intn(2<<r.length) + 1) // #nosec G115 -- intentional use.
case reflect.Float32:
return float32(r.rand.Float64())
case reflect.Float64:
Expand Down
2 changes: 2 additions & 0 deletions reflect/reflect.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package reflect provides run-time reflection to manipulate complex test
// objects so that they match the expected values.
package reflect

import (
Expand Down
5 changes: 5 additions & 0 deletions revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ enableAllRules = true
[rule.package-comments]
disabled = true

# Reports on package names that use core library names.
# Rule prevents users from intentional creating drop in replacements.
[rule.package-naming]
disabled = true

# Reports on mismatches between directory names and package names.
# Rule prevents having a clearer hyphen readable directory name.
[rule.package-directory-mismatch]
Expand Down
8 changes: 4 additions & 4 deletions test/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ var parallelTestCases = map[string]ParallelParams{
},

"setenv-in-run-with-parallel": {
setup: test.Panic("testing: test using t.Setenv or t.Chdir" +
" can not use t.Parallel"),
setup: test.Panic("testing: test using t.Setenv, t.Chdir, or " +
"cryptotest.SetGlobalRandom can not use t.Parallel"),
parallel: true,
during: func(t test.Test) {
t.Setenv("TESTING", "during")
Expand All @@ -179,8 +179,8 @@ var parallelTestCases = map[string]ParallelParams{
},

"setenv-before-run-with-parallel": {
setup: test.Panic("testing: test using t.Setenv or t.Chdir" +
" can not use t.Parallel"),
setup: test.Panic("testing: test using t.Setenv, t.Chdir, or " +
"cryptotest.SetGlobalRandom can not use t.Parallel"),
parallel: true,
before: func(t test.Test) {
t.Setenv("TESTING", "before")
Expand Down
4 changes: 2 additions & 2 deletions test/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func First[T any](arg T, _ ...any) T { return arg }
// test failure if no panic occurred or the panic response does not match the
// expected value.
func Recover(t Test, expect any) {
// revive:disable-next-line:defer // caller is expected to use defer.
//revive:disable-next-line:defer // caller is expected to use defer.
if actual := recover(); actual != nil {
assert.Equal(t, expect, actual)
} else {
Expand Down Expand Up @@ -150,7 +150,7 @@ func Main(main func()) func(t Test, param MainParams) {
ctx = param.Ctx
}

// #nosec G204 -- secured by calling only the test instance.
// #nosec G204,G702 -- secured by calling only the dedicated test.
cmd := exec.CommandContext(ctx, os.Args[0],
"-test.run="+t.(*Context).t.Name())

Expand Down
4 changes: 2 additions & 2 deletions test/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ func TestSliceRunFiltered(t *testing.T) {
// tests. Currently, I have no idea hot to integrate the test using the above
// simplified test pattern that only works on `test.Test` and not `testing.T“.
func TestRunnerPanic(t *testing.T) {
defer test.Recover(t, "testing: test using t.Setenv or t.Chdir"+
" can not use t.Parallel")
defer test.Recover(t, "testing: test using t.Setenv, t.Chdir, or "+
"cryptotest.SetGlobalRandom can not use t.Parallel")
t.Setenv("TESTING", "before")

test.Any[ParamParams](t, []ParamParams{{expect: true}}).
Expand Down
Loading