-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinternal_refs_test.go
More file actions
67 lines (63 loc) · 1.93 KB
/
Copy pathinternal_refs_test.go
File metadata and controls
67 lines (63 loc) · 1.93 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package ifc_test
import (
"io/fs"
"os"
"path/filepath"
"strings"
"testing"
)
// internalRefs are Blox-internal artifacts that must not appear anywhere in
// this library's source. goifc is a public Go module; a reader outside Blox
// cannot open import_emit.py, does not run Temporal, and has never heard of
// the service called "flow". References to ifcopenshell are deliberately NOT
// listed — that is a public project this library ports from, and naming it is
// how a reader checks our behaviour against the reference.
var internalRefs = []string{
"import_emit",
"semantic_oracle",
"_qto_quantities",
"Temporal",
"flow's",
"flow import contract",
"flow workflow",
}
// thisFile is skipped: it necessarily contains every banned string above.
// This is the root-relative path the walk (starting at ".") produces for
// this file, not just its basename — a same-named file in a subpackage
// must not be exempted.
const thisFile = "internal_refs_test.go"
func TestNoInternalReferences(t *testing.T) {
err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
// Nothing under .git, testdata, or vendor is published
// documentation — vendored code is not this project's, so it
// must not be able to fail this check on our behalf.
if name := d.Name(); name == ".git" || name == "testdata" || name == "vendor" {
return filepath.SkipDir
}
return nil
}
if !strings.HasSuffix(path, ".go") || path == thisFile {
return nil
}
src, err := os.ReadFile(path)
if err != nil {
return err
}
for i, line := range strings.Split(string(src), "\n") {
for _, ref := range internalRefs {
if strings.Contains(line, ref) {
t.Errorf("%s:%d: Blox-internal reference %q in a public library:\n\t%s",
path, i+1, ref, strings.TrimSpace(line))
}
}
}
return nil
})
if err != nil {
t.Fatalf("walking the module: %v", err)
}
}