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
51 changes: 0 additions & 51 deletions .github/workflows/testandvet.yml

This file was deleted.

56 changes: 56 additions & 0 deletions .github/workflows/testandvet_go_directive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Test and Vet (go directive version)

env:
GOTOOLCHAIN: local

"on":
push:
branches:
- main
pull_request:
branches:
- main
release:
types:
- published
- created
- edited

defaults:
run:
shell: bash

jobs:
test:
runs-on: ubuntu-24.04

steps:

- name: Checkout code
uses: actions/checkout@v4.2.2

- name: Install Go
uses: actions/setup-go@v5.3.0
with:
go-version-file: 'go.mod'

- name: Cache Go module and build cache
uses: actions/cache@v4.2.2
with:
key: go-${{ hashFiles('**/go.sum') }}
path: |
~/go/pkg/mod
restore-keys: |
go-

- name: Install tennvet
run: |
GOBIN=$(pwd) go install github.com/tenntenn/tennvet@latest

- name: Test and vet
run: |
go version
go vet ./...
go vet -vettool=$(pwd)/tennvet ./...
go test -v -race ./...
62 changes: 62 additions & 0 deletions .github/workflows/testandvet_toolchain_directive.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
name: Test and Vet (toolchain directive version)

env:
GOTOOLCHAIN: local

"on":
push:
branches:
- main
pull_request:
branches:
- main
release:
types:
- published
- created
- edited

defaults:
run:
shell: bash

jobs:
test:
runs-on: ubuntu-24.04

steps:

- name: Checkout code
uses: actions/checkout@v4.2.2

- name: Parse toolchain directive
# see: https://github.com/actions/setup-go/issues/457
id: toolchain
run: |
echo "version=$(sed -ne '/^toolchain /s/^toolchain go//p' go.mod)" >> "$GITHUB_OUTPUT"

- name: Install Go
uses: actions/setup-go@v5.3.0
with:
go-version: ${{ steps.toolchain.outputs.version }}

- name: Cache Go module and build cache
uses: actions/cache@v4.2.2
with:
key: go-${{ hashFiles('**/go.sum') }}
path: |
~/go/pkg/mod
restore-keys: |
go-

- name: Install tennvet
run: |
GOBIN=$(pwd) go install github.com/tenntenn/tennvet@latest

- name: Test and vet
run: |
go version
go vet ./...
go vet -vettool=$(pwd)/tennvet ./...
go test -v -race ./...
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ module github.com/gostaticanalysis/testutil

go 1.23.7

toolchain go1.24.1

require (
github.com/google/go-cmp v0.7.0
github.com/josharian/txtarfs v0.0.0-20240408113805-5dc76b8fe6bf
github.com/newmo-oss/gotestingmock v0.1.1
github.com/otiai10/copy v1.14.1
github.com/tenntenn/golden v0.5.4
github.com/tenntenn/modver v1.0.1
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3
golang.org/x/mod v0.24.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/otiai10/copy v1.14.1 h1:5/7E6qsUMBaH5AnQ0sSLzzTg1oTECmcCmT6lvF45Na8=
github.com/otiai10/copy v1.14.1/go.mod h1:oQwrEDDOci3IM8dJF0d8+jnbfPDllW6vUjNc3DoZm9I=
github.com/otiai10/mint v1.6.3 h1:87qsV/aw1F5as1eH1zS/yqHY85ANKVMgkDrf9rcxbQs=
github.com/otiai10/mint v1.6.3/go.mod h1:MJm72SBthJjz8qhefc4z1PYEieWmy8Bku7CjcAqyUSM=
github.com/tenntenn/golden v0.5.4 h1:laddoKuzbzGYVinsSZyEPavPh4muyKd2SMhJTKH3F3s=
github.com/tenntenn/golden v0.5.4/go.mod h1:0xI/4lpoHR65AUTmd1RKR9S1Uv0JR3yR2Q1Ob2bKqQA=
github.com/tenntenn/modver v1.0.1 h1:2klLppGhDgzJrScMpkj9Ujy3rXPUspSjAcev9tSEBgA=
github.com/tenntenn/modver v1.0.1/go.mod h1:bePIyQPb7UeioSRkw3Q0XeMhYZSMx9B8ePqg6SAMGH0=
github.com/tenntenn/text/transform v0.0.0-20200319021203-7eef512accb3 h1:f+jULpRQGxTSkNYKJ51yaw6ChIqO+Je8UqsTKN/cDag=
Expand Down
27 changes: 27 additions & 0 deletions go124.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//go:build go1.24

package testutil

import (
"encoding/json"
"testing"
)

// Remove tool directive from go.mod.
func removeToolDirective(tb testing.TB, dir string) {
tb.Helper()

r := execCmd(tb, dir, "go", "mod", "edit", "-json")
var modfile struct {
Tool []struct {
Path string
}
}
if err := json.NewDecoder(r).Decode(&modfile); err != nil {
tb.Fatal("unexpected error:", err)
}

for _, tool := range modfile.Tool {
execCmd(tb, dir, "go", "mod", "edit", "-droptool", tool.Path)
}
}
32 changes: 32 additions & 0 deletions issuetest/issue00023_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//go:build go1.24

package issuetest

import (
"flag"
"path/filepath"
"testing"

"github.com/tenntenn/golden"
Copy link
Collaborator

@Arupaka1152 Arupaka1152 Mar 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the golden module is directly imported in this file, but it's listed as an indirect dependency in the go.mod file. Is this intentional?

"golang.org/x/tools/go/analysis/analysistest"

"github.com/gostaticanalysis/testutil"
)

var flagGoldenUpdate bool

func init() {
flag.BoolVar(&flagGoldenUpdate, "update-golden", false, "update golden files")
}

func TestIssue00023(t *testing.T) {
t.Parallel()

testdata := analysistest.TestData()
target := filepath.Join(testdata, "target")
tmpdir := testutil.WithModules(t, target, nil)
got := golden.Txtar(t, tmpdir)
if diff := golden.Check(t, flagGoldenUpdate, testdata, t.Name(), got); diff != "" {
t.Errorf("golden file mismatch: (-want, +got) = %s", diff)
}
}
12 changes: 12 additions & 0 deletions issuetest/testdata/TestIssue00023.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- src/issue00023/go.mod --
module example.com/issue00023

go 1.24.1
-- src/issue00023/go.sum --
-- src/issue00023/issue00023.go --
//line issue00023.go:1

//go:build go1.24

// see https://github.com/gostaticanalysis/testutil/blob/main/go.mod
package issue00023
59 changes: 59 additions & 0 deletions issuetest/testdata/target/src/issue00023/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module example.com/issue00023

go 1.24.1

require (
cel.dev/expr v0.18.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/antlr4-go/antlr/v4 v4.13.1 // indirect
github.com/cubicdaiya/gonp v1.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/google/cel-go v0.22.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.2 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pganalyze/pg_query_go/v5 v5.1.0 // indirect
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb // indirect
github.com/pingcap/failpoint v0.0.0-20240528011301-b51a646c7c86 // indirect
github.com/pingcap/log v1.1.0 // indirect
github.com/pingcap/tidb/pkg/parser v0.0.0-20241203170126-9812d85d0d25 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/riza-io/grpc-go v0.2.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/sqlc-dev/sqlc v1.28.0 // indirect
github.com/stoewer/go-strcase v1.2.0 // indirect
github.com/tetratelabs/wazero v1.8.2 // indirect
github.com/wasilibs/go-pgquery v0.0.0-20240606042535-c0843d6592cc // indirect
github.com/wasilibs/wazero-helpers v0.0.0-20240604052452-61d7981e9a38 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc v1.69.4 // indirect
google.golang.org/protobuf v1.36.3 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.55.3 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.8.0 // indirect
modernc.org/sqlite v1.34.5 // indirect
)

tool github.com/sqlc-dev/sqlc/cmd/sqlc
Loading
Loading