Skip to content

Commit 953b272

Browse files
committed
Allow setting -toml=latest
1 parent ea080a1 commit 953b272

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

cmd/toml-test/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func parseFlags() (tomltest.Runner, []string, int, string, bool, bool, bool) {
2727
var (
2828
help = f.Bool(false, "help", "h")
2929
versionFlag = f.IntCounter(0, "version", "V")
30-
tomlVersion = f.String("1.0.0", "toml")
30+
tomlVersion = f.String(tomltest.DefaultVersion, "toml")
3131
encoder = f.Bool(false, "encoder")
3232
testDir = f.String("", "testdir")
3333
showAll = f.IntCounter(0, "v")
@@ -49,6 +49,9 @@ func parseFlags() (tomltest.Runner, []string, int, string, bool, bool, bool) {
4949
fmt.Printf(usage, filepath.Base(os.Args[0]))
5050
zli.Exit(0)
5151
}
52+
if tomlVersion.String() == "latest" {
53+
*tomlVersion.Pointer() = tomltest.DefaultVersion
54+
}
5255
if versionFlag.Int() > 0 {
5356
zli.PrintVersion(versionFlag.Int() > 1)
5457
zli.Exit(0)
@@ -209,6 +212,7 @@ func main() {
209212
if tests.Skipped > 0 {
210213
fmt.Printf(", %2d skipped", tests.Skipped)
211214
}
215+
212216
if printSkip && (tests.FailedValid > 0 || tests.FailedInvalid > 0) {
213217
fmt.Print("\n\n #!/usr/bin/env bash\n # Also compatible with zsh.\n skip=(\n")
214218
for _, f := range tests.Tests {
@@ -332,7 +336,7 @@ func doCat(fsys fs.FS, tomlVersion string, size int, run, skip []string) {
332336
f, err := fs.ReadFile(fsys, "files-toml-"+tomlVersion)
333337
zli.F(err)
334338

335-
var useFiles = make([]string, 0, 8)
339+
useFiles := make([]string, 0, 8)
336340
outer1:
337341
for _, line := range strings.Split(string(f), "\n") {
338342
if strings.HasPrefix(line, "valid/") && strings.HasSuffix(line, ".toml") {

cmd/toml-test/usage.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ Flags:
4444
4545
-toml Select TOML version to run tests for. Supported versions are
4646
"1.0" and "1.1" (which isn't released yet and may change).
47-
Defaults to 1.0.
47+
Use "latest" to use the latest published TOML version.
48+
Default is latest.
4849
4950
-timeout Maximum time for a single test run, to detect infinite loops
5051
or pathological cases. Defaults to "1s".

runner.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const (
2929
TypeInvalid
3030
)
3131

32+
const DefaultVersion = "1.0.0"
33+
3234
//go:embed tests/*
3335
var embeddedTests embed.FS
3436

@@ -124,6 +126,8 @@ func (r Runner) List() ([]string, error) {
124126
r.Version = "1.0.0"
125127
} else if r.Version == "1.1" {
126128
r.Version = "1.1.0"
129+
} else if r.Version == "latest" {
130+
r.Version = DefaultVersion
127131
}
128132
if _, ok := versions[r.Version]; !ok {
129133
v := make([]string, 0, len(versions))

0 commit comments

Comments
 (0)