@@ -24,7 +24,7 @@ Usage: go run ci.go <command> <command flags/arguments>
24
24
Available commands are:
25
25
26
26
install [-arch architecture] [ packages... ] -- builds packages and executables
27
- test [ -coverage ] [ -vet ] [ packages... ] -- runs the tests
27
+ test [ -coverage ] [ -vet ] [ -misspell] [ packages... ] -- runs the tests
28
28
archive [-arch architecture] [ -type zip|tar ] [ -signer key-envvar ] [ -upload dest ] -- archives build artefacts
29
29
importkeys -- imports signing keys from env
30
30
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
@@ -262,6 +262,7 @@ func goToolArch(arch string, subcmd string, args ...string) *exec.Cmd {
262
262
func doTest (cmdline []string ) {
263
263
var (
264
264
vet = flag .Bool ("vet" , false , "Whether to run go vet" )
265
+ misspell = flag .Bool ("misspell" , false , "Whether to run the spell checker" )
265
266
coverage = flag .Bool ("coverage" , false , "Whether to record code coverage" )
266
267
)
267
268
flag .CommandLine .Parse (cmdline )
@@ -287,7 +288,29 @@ func doTest(cmdline []string) {
287
288
if * vet {
288
289
build .MustRun (goTool ("vet" , packages ... ))
289
290
}
291
+ if * misspell {
292
+ // The spell checker doesn't work on packages, gather all .go files for it
293
+ sources := []string {}
294
+ for _ , pkg := range packages {
295
+ // Gather all the source files of the package
296
+ out , err := goTool ("list" , "-f" , "{{.Dir}}{{range .GoFiles}}\n {{.}}{{end}}{{range .CgoFiles}}\n {{.}}{{end}}{{range .TestGoFiles}}\n {{.}}{{end}}" , pkg ).CombinedOutput ()
297
+ if err != nil {
298
+ log .Fatalf ("source file listing failed: %v\n %s" , err , string (out ))
299
+ }
300
+ // Retrieve the folder and assemble the source list
301
+ lines := strings .Split (string (out ), "\n " )
290
302
303
+ root := lines [0 ]
304
+ for _ , line := range lines [1 :] {
305
+ if line = strings .TrimSpace (line ); line != "" {
306
+ sources = append (sources , filepath .Join (root , line ))
307
+ }
308
+ }
309
+ }
310
+ // Download the spell checker tool and run on all source files
311
+ build .MustRun (goTool ("get" , "github.com/client9/misspell/cmd/misspell" ))
312
+ build .MustRunCommand (filepath .Join (GOBIN , "misspell" ), append ([]string {"-error" }, sources ... )... )
313
+ }
291
314
// Run the actual tests.
292
315
gotest := goTool ("test" )
293
316
// Test a single package at a time. CI builders are slow
0 commit comments