@@ -2,6 +2,7 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
+ _ "embed"
5
6
"encoding/json"
6
7
"fmt"
7
8
"io"
@@ -12,6 +13,7 @@ import (
12
13
"sort"
13
14
"strconv"
14
15
"strings"
16
+ "text/template"
15
17
"time"
16
18
17
19
"github.com/BurntSushi/toml"
@@ -22,33 +24,42 @@ import (
22
24
23
25
var hlErr = zli .Color256 (224 ).Bg () | zli .Color256 (0 ) | zli .Bold
24
26
27
+ //go:embed script.gotxt
28
+ var script []byte
29
+
30
+ var scriptTemplate = template .Must (template .New ("" ).Option ("missingkey=error" ).Parse (string (script )))
31
+
25
32
func parseFlags () (tomltest.Runner , []string , int , string , bool , bool , bool ) {
26
33
f := zli .NewFlags (os .Args )
27
34
var (
28
- help = f .Bool (false , "help" , "h" )
29
- versionFlag = f .IntCounter (0 , "version" , "V" )
30
- tomlVersion = f .String (tomltest .DefaultVersion , "toml" )
31
- encoder = f .Bool (false , "encoder" )
32
- testDir = f .String ("" , "testdir" )
33
- showAll = f .IntCounter (0 , "v" )
34
- color = f .String ("always" , "color" )
35
- skip = f .StringList (nil , "skip" )
36
- run = f .StringList (nil , "run" )
37
- listFiles = f .Bool (false , "list-files" )
38
- cat = f .Int (0 , "cat" )
39
- copyFiles = f .Bool (false , "copy" )
40
- parallel = f .Int (runtime .NumCPU (), "parallel" )
41
- printSkip = f .Bool (false , "print-skip" )
42
- intAsFloat = f .Bool (false , "int-as-float" )
43
- errors = f .String ("" , "errors" )
44
- timeout = f .String ("1s" , "timeout" )
45
- noNumber = f .Bool (false , "no-number" , "no_number" )
35
+ help = f .Bool (false , "help" , "h" )
36
+ versionFlag = f .IntCounter (0 , "version" , "V" )
37
+ tomlVersion = f .String (tomltest .DefaultVersion , "toml" )
38
+ encoder = f .Bool (false , "encoder" )
39
+ testDir = f .String ("" , "testdir" )
40
+ showAll = f .IntCounter (0 , "v" )
41
+ color = f .String ("always" , "color" )
42
+ skip = f .StringList (nil , "skip" )
43
+ run = f .StringList (nil , "run" )
44
+ listFiles = f .Bool (false , "list-files" )
45
+ cat = f .Int (0 , "cat" )
46
+ copyFiles = f .Bool (false , "copy" )
47
+ parallel = f .Int (runtime .NumCPU (), "parallel" )
48
+ script = f .Bool (false , "script" , "print-skip" ) // -print-skip is the old name
49
+ intAsFloat = f .Bool (false , "int-as-float" )
50
+ errors = f .String ("" , "errors" )
51
+ timeout = f .String ("1s" , "timeout" )
52
+ noNumber = f .Bool (false , "no-number" , "no_number" )
53
+ skipMustError = f .Bool (false , "skip-error" )
46
54
)
47
55
zli .F (f .Parse ())
48
56
if help .Bool () {
49
57
fmt .Printf (usage , filepath .Base (os .Args [0 ]))
50
58
zli .Exit (0 )
51
59
}
60
+ if script .Bool () && encoder .Bool () {
61
+ zli .Fatalf ("cannot use -script and -encoder; generate a script without -encoder and fill in the encoder binary" )
62
+ }
52
63
if tomlVersion .String () == "latest" {
53
64
* tomlVersion .Pointer () = tomltest .DefaultVersion
54
65
}
@@ -85,16 +96,17 @@ func parseFlags() (tomltest.Runner, []string, int, string, bool, bool, bool) {
85
96
}
86
97
87
98
r := tomltest.Runner {
88
- Encoder : encoder .Bool (),
89
- RunTests : run .StringsSplit ("," ),
90
- SkipTests : skip .StringsSplit ("," ),
91
- Version : tomlVersion .String (),
92
- Parallel : parallel .Int (),
93
- Files : fsys ,
94
- Parser : tomltest .NewCommandParser (fsys , f .Args ),
95
- Timeout : dur ,
96
- IntAsFloat : intAsFloat .Bool (),
97
- Errors : errs ,
99
+ Encoder : encoder .Bool (),
100
+ RunTests : run .StringsSplit ("," ),
101
+ SkipTests : skip .StringsSplit ("," ),
102
+ Version : tomlVersion .String (),
103
+ Parallel : parallel .Int (),
104
+ Files : fsys ,
105
+ Parser : tomltest .NewCommandParser (fsys , f .Args ),
106
+ Timeout : dur ,
107
+ IntAsFloat : intAsFloat .Bool (),
108
+ SkipMustError : skipMustError .Bool (),
109
+ Errors : errs ,
98
110
}
99
111
if intAsFloat .Bool () {
100
112
r .SkipTests = append (r .SkipTests , "valid/integer/long" )
@@ -132,7 +144,7 @@ func parseFlags() (tomltest.Runner, []string, int, string, bool, bool, bool) {
132
144
}
133
145
}
134
146
135
- return r , f .Args , showAll .Int (), testDir .String (), listFiles .Bool (), printSkip .Bool (), noNumber .Bool ()
147
+ return r , f .Args , showAll .Int (), testDir .String (), listFiles .Bool (), script .Bool (), noNumber .Bool ()
136
148
}
137
149
138
150
func getFS (testDir string , set bool ) fs.FS {
@@ -181,7 +193,7 @@ func getList(r tomltest.Runner) []string {
181
193
}
182
194
183
195
func main () {
184
- runner , cmd , showAll , testDir , listFiles , printSkip , noNumber := parseFlags ()
196
+ runner , cmd , showAll , testDir , listFiles , script , noNumber := parseFlags ()
185
197
186
198
if listFiles {
187
199
l := getList (runner )
@@ -194,6 +206,28 @@ func main() {
194
206
tests , err := runner .Run ()
195
207
zli .F (err )
196
208
209
+ //if script && (tests.FailedValid > 0 || tests.FailedInvalid > 0) {
210
+ if script {
211
+ var failedValid , failedInvalid []string
212
+ for _ , f := range tests .Tests {
213
+ if f .Failed () {
214
+ if f .Type () == tomltest .TypeValid {
215
+ failedValid = append (failedValid , f .Path )
216
+ } else {
217
+ failedInvalid = append (failedInvalid , f .Path )
218
+ }
219
+ }
220
+ }
221
+ err := scriptTemplate .Execute (os .Stdout , struct {
222
+ Decoder string
223
+ TOML string
224
+ FailedValid []string
225
+ FailedInvalid []string
226
+ }{strings .Join (cmd , " " ), runner .Version , failedValid , failedInvalid })
227
+ zli .F (err )
228
+ return
229
+ }
230
+
197
231
for _ , t := range tests .Tests {
198
232
if t .Failed () || showAll > 1 {
199
233
fmt .Print (detailed (runner , t , noNumber ))
@@ -213,21 +247,6 @@ func main() {
213
247
fmt .Printf (", %2d skipped" , tests .Skipped )
214
248
}
215
249
216
- if printSkip && (tests .FailedValid > 0 || tests .FailedInvalid > 0 ) {
217
- fmt .Print ("\n \n #!/usr/bin/env bash\n # Also compatible with zsh.\n skip=(\n " )
218
- for _ , f := range tests .Tests {
219
- if f .Failed () {
220
- fmt .Printf (" -skip '%s'\n " , f .Path )
221
- }
222
- }
223
- fmt .Println (" )" )
224
- fmt .Printf (" toml-test -toml=%s ${skip[@]} %s" , runner .Version , strings .Join (cmd , " " ))
225
- if runner .Encoder {
226
- fmt .Print (" -encoder" )
227
- }
228
- fmt .Println ()
229
- }
230
-
231
250
fmt .Println ()
232
251
if runner .Encoder {
233
252
fmt .Printf ("encoder tests: %3d passed, %2d failed\n " , tests .PassedValid , tests .FailedValid )
0 commit comments