-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathall_test.go
45 lines (40 loc) · 977 Bytes
/
all_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.17 && !windows
// +build go1.17,!windows
package main
import (
"bufio"
"io/fs"
"os"
"regexp"
"strings"
"testing"
)
var goHeader = regexp.MustCompile(`^// Copyright 20\d\d The Go Authors\. All rights reserved\.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file\.`)
func TestHeaders(t *testing.T) {
sfs := os.DirFS(".")
fs.WalkDir(sfs, ".", func(path string, d fs.DirEntry, _ error) error {
if d.IsDir() {
if d.Name() == "testdata" {
return fs.SkipDir
}
return nil
}
if !strings.HasSuffix(path, ".go") {
return nil
}
f, err := sfs.Open(path)
if err != nil {
return err
}
defer f.Close()
if !goHeader.MatchReader(bufio.NewReader(f)) {
t.Errorf("%v: incorrect go header", path)
}
return nil
})
}