mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
200a7fc844
This moves a few things from script/ to a new directory meta/, and makes them real Go tests. These are the authors, copyright, metalint and gofmt checks. That means that they can now be run by go test -v ./meta and optionally filtered by the usual -run thing to go test. Also -short will cut down on the metalint stuff and exclude the authors check (which is slow because it runs git lots of times). Mainly this makes everything easier on things like build servers where we can now just run tests instead of do a bunch of scripting. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/4252
46 lines
1.0 KiB
Go
46 lines
1.0 KiB
Go
// Copyright (C) 2015 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
// Checks for authors that are not mentioned in AUTHORS
|
|
package meta
|
|
|
|
import (
|
|
"os"
|
|
"os/exec"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
var gofmtCheckDirs = []string{".", "../cmd", "../lib", "../test", "../script"}
|
|
|
|
func TestCheckGoFmt(t *testing.T) {
|
|
for _, dir := range gofmtCheckDirs {
|
|
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if path == ".git" {
|
|
return filepath.SkipDir
|
|
}
|
|
if filepath.Ext(path) != ".go" {
|
|
return nil
|
|
}
|
|
cmd := exec.Command("gofmt", "-s", "-d", path)
|
|
bs, err := cmd.CombinedOutput()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if len(bs) != 0 {
|
|
t.Errorf("File %s is not formatted correctly:\n\n%s", path, string(bs))
|
|
}
|
|
return nil
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
}
|