Skip to content

Commit e4181a7

Browse files
committed
travis, appveyor, build: add source spell checking
1 parent c5df37c commit e4181a7

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ install:
9090
- go get golang.org/x/tools/cmd/cover
9191
script:
9292
- go run build/ci.go install
93-
- go run build/ci.go test -coverage -vet
93+
- go run build/ci.go test -coverage -vet -misspell
9494

9595
notifications:
9696
webhooks:

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ after_build:
3636

3737
test_script:
3838
- set CGO_ENABLED=1
39-
- go run build\ci.go test -vet -coverage
39+
- go run build\ci.go test -vet -coverage -misspell

build/ci.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Usage: go run ci.go <command> <command flags/arguments>
2424
Available commands are:
2525
2626
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
2828
archive [-arch architecture] [ -type zip|tar ] [ -signer key-envvar ] [ -upload dest ] -- archives build artefacts
2929
importkeys -- imports signing keys from env
3030
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 {
262262
func doTest(cmdline []string) {
263263
var (
264264
vet = flag.Bool("vet", false, "Whether to run go vet")
265+
misspell = flag.Bool("misspell", false, "Whether to run the spell checker")
265266
coverage = flag.Bool("coverage", false, "Whether to record code coverage")
266267
)
267268
flag.CommandLine.Parse(cmdline)
@@ -287,7 +288,29 @@ func doTest(cmdline []string) {
287288
if *vet {
288289
build.MustRun(goTool("vet", packages...))
289290
}
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")
290302

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+
}
291314
// Run the actual tests.
292315
gotest := goTool("test")
293316
// Test a single package at a time. CI builders are slow

0 commit comments

Comments
 (0)