@@ -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,9 @@ func doTest(cmdline []string) {
287
288
if * vet {
288
289
build .MustRun (goTool ("vet" , packages ... ))
289
290
}
290
-
291
+ if * misspell {
292
+ spellcheck (packages )
293
+ }
291
294
// Run the actual tests.
292
295
gotest := goTool ("test" )
293
296
// Test a single package at a time. CI builders are slow
@@ -300,6 +303,34 @@ func doTest(cmdline []string) {
300
303
build .MustRun (gotest )
301
304
}
302
305
306
+ // spellcheck runs the client9/misspell spellchecker package on all Go, Cgo and
307
+ // test files in the requested packages.
308
+ func spellcheck (packages []string ) {
309
+ // Ensure the spellchecker is available
310
+ build .MustRun (goTool ("get" , "github.com/client9/misspell/cmd/misspell" ))
311
+
312
+ // Windows chokes on long argument lists, check packages individualy
313
+ for _ , pkg := range packages {
314
+ // The spell checker doesn't work on packages, gather all .go files for it
315
+ out , err := goTool ("list" , "-f" , "{{.Dir}}{{range .GoFiles}}\n {{.}}{{end}}{{range .CgoFiles}}\n {{.}}{{end}}{{range .TestGoFiles}}\n {{.}}{{end}}" , pkg ).CombinedOutput ()
316
+ if err != nil {
317
+ log .Fatalf ("source file listing failed: %v\n %s" , err , string (out ))
318
+ }
319
+ // Retrieve the folder and assemble the source list
320
+ lines := strings .Split (string (out ), "\n " )
321
+ root := lines [0 ]
322
+
323
+ sources := make ([]string , 0 , len (lines )- 1 )
324
+ for _ , line := range lines [1 :] {
325
+ if line = strings .TrimSpace (line ); line != "" {
326
+ sources = append (sources , filepath .Join (root , line ))
327
+ }
328
+ }
329
+ // Run the spell checker for this particular package
330
+ build .MustRunCommand (filepath .Join (GOBIN , "misspell" ), append ([]string {"-error" }, sources ... )... )
331
+ }
332
+ }
333
+
303
334
// Release Packaging
304
335
305
336
func doArchive (cmdline []string ) {
0 commit comments