Skip to content

test: split TestGetVersion; remove toolchain #1303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
fail-fast: false
matrix:
go-version:
- 1.22
- oldstable
- stable
steps:
Expand Down
14 changes: 14 additions & 0 deletions cli/main_go123_test.go
Copy link
Contributor

Choose a reason for hiding this comment

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

🎨

I wouldn't prefix them with main_

It leads to some confusions with possible build tag available via file suffix. Like main_386_test.go

I initially thought main_test.go file wasn't used.

Maybe you could rename these files with a common prefix that is not main_

Copy link
Collaborator Author

@alexandear alexandear Apr 9, 2025

Choose a reason for hiding this comment

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

Renamed main_go123_test.go to main_pre_go124_test.go (similar to pre_go120.go https://github.com/golang/sync/tree/10739b037d369c748d671b216356d7e04ce68da1/errgroup)

The prefix main_ is expected by Go convention https://pkg.go.dev/cmd/go#hdr-Test_packages:

  • main_test.go contains tests for main.go

  • main_pre_go124_test.go contains tests for main.go, but only for Go 1.23 and below

  • main_go124_test.go contains tests for main.go, but only for Go 1.24 and above

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !go1.24

package cli

import "testing"

func TestGetDevelopmentVersion(t *testing.T) {
got := getVersion(defaultBuilder, defaultDate, defaultCommit, defaultVersion)
want := "version \n"

if got != want {
t.Errorf("getVersion() = %q, want %q", got, want)
}
}
14 changes: 14 additions & 0 deletions cli/main_go124_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build go1.24

package cli

import "testing"

func TestGetDevelopmentVersion(t *testing.T) {
got := getVersion(defaultBuilder, defaultDate, defaultCommit, defaultVersion)
want := "version (devel)\n"

if got != want {
t.Errorf("getVersion() = %q, want %q", got, want)
}
}
27 changes: 6 additions & 21 deletions cli/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cli

import (
goversion "go/version"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -96,28 +95,14 @@ func TestXDGConfigDirNoFile(t *testing.T) {
}
}

func TestGetVersion(t *testing.T) {
t.Run("Development version", func(t *testing.T) {
got := getVersion(defaultBuilder, defaultDate, defaultCommit, defaultVersion)
want := "version (devel)\n"
if goversion.Compare(runtime.Version(), "go1.24") < 0 {
want = "version \n"
}

if got != want {
t.Errorf("getVersion() = %q, want %q", got, want)
}
})

t.Run("Release version", func(t *testing.T) {
got := getVersion("builder", "2024-11-15 10:52 UTC", "7ee4500e125e2d1b12653b2c8e140fec380919b4", "v1.5.0-12-g7ee4500-dev")
want := `Version: v1.5.0-12-g7ee4500-dev
func TestGetReleaseVersion(t *testing.T) {
got := getVersion("builder", "2024-11-15 10:52 UTC", "7ee4500e125e2d1b12653b2c8e140fec380919b4", "v1.5.0-12-g7ee4500-dev")
want := `Version: v1.5.0-12-g7ee4500-dev
Commit: 7ee4500e125e2d1b12653b2c8e140fec380919b4
Built 2024-11-15 10:52 UTC by builder
`

if got != want {
t.Errorf("getVersion() = %q, want %q", got, want)
}
})
if got != want {
t.Errorf("getVersion() = %q, want %q", got, want)
}
}
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module github.com/mgechev/revive

go 1.23.0

toolchain go1.24.2

require (
github.com/BurntSushi/toml v1.5.0
github.com/chavacava/garif v0.1.0
Expand Down