Skip to content

Commit 143ecf4

Browse files
committed
go.mod: declare goimports as a tool, for use in cover.sh
Add 'goimports' (the command) as a tool: $ go get -tool golang.org/x/tools/cmd/goimports@v0.38.0 Now we can use it for testing the -goimports option from cover.sh via 'go tool goimports' and its version is aligned with the package.
1 parent 474ab5e commit 143ecf4

3 files changed

Lines changed: 20 additions & 8 deletions

File tree

cover.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ go=go
88
goeval=./goeval.cover
99
goeval_offline=./goeval-offline.cover
1010

11-
if ! command -v goimports >/dev/null; then
12-
echo "goimports: command not found." >&2
13-
exit 1
14-
fi
15-
1611
if [[ ! -d "$GOCOVERDIR" ]]; then
1712
mkdir -p "$GOCOVERDIR"
1813
else
@@ -26,6 +21,11 @@ echo Building...
2621
$go build -covermode=set -coverpkg=./... -buildvcs=true -o=$goeval .
2722
$go build -covermode=set -coverpkg=./... -buildvcs=true -tags=goeval.offline -o=$goeval_offline .
2823

24+
# Ensure that goimports (declared as tool in go.mod) is built
25+
$go tool goimports -h >/dev/null || :
26+
# Show goimports version
27+
$go version -m $($go tool -n goimports)
28+
2929
export GOCOVERDIR
3030

3131
echo Running tests...
@@ -67,7 +67,8 @@ $goeval -goimports=goimports -E 'fmt.Println("Hello, world")'
6767
$goeval -goimports= -E 'fmt.Println("Hello, world")'
6868

6969
# With goimports as external command
70-
$goeval -goimports="$(command -v goimports)" -E 'fmt.Println("Hello, world")'
70+
# We are using the one declared as a tool in go.mod
71+
$goeval -goimports="$($go tool -n goimports)" -E 'fmt.Println("Hello, world")'
7172

7273

7374
# GOPATH mode with external package

go.mod

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ require (
77
golang.org/x/tools v0.38.0
88
)
99

10-
require golang.org/x/sync v0.17.0 // indirect
10+
require (
11+
golang.org/x/sync v0.17.0 // indirect
12+
golang.org/x/sys v0.37.0 // indirect
13+
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 // indirect
14+
)
1115

12-
tool github.com/dolmen-go/goeval
16+
tool (
17+
github.com/dolmen-go/goeval
18+
golang.org/x/tools/cmd/goimports
19+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
44
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
55
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
66
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
7+
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
8+
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
9+
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8 h1:LvzTn0GQhWuvKH/kVRS3R3bVAsdQWI7hvfLHGgh9+lU=
10+
golang.org/x/telemetry v0.0.0-20251008203120-078029d740a8/go.mod h1:Pi4ztBfryZoJEkyFTI5/Ocsu2jXyDr6iSdgJiYE/uwE=
711
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
812
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=

0 commit comments

Comments
 (0)