]> Cypherpunks repositories - gostls13.git/commitdiff
internal/copyright: add test that copyright notices exist
authorRuss Cox <rsc@golang.org>
Thu, 21 Nov 2024 13:46:57 +0000 (08:46 -0500)
committerRuss Cox <rsc@golang.org>
Thu, 21 Nov 2024 16:12:09 +0000 (16:12 +0000)
We shouldn't spend human code review time checking this.
Let the computer check.

Change-Id: I6de9d733c128d833b958b0e43a52b564e8f82dd3
Reviewed-on: https://go-review.googlesource.com/c/go/+/630417
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
src/cmd/go/internal/auth/gitauth_test.go
src/cmd/go/internal/web/intercept/intercept.go
src/crypto/internal/fips140/check/checktest/asm.s
src/crypto/tls/bogo_shim_test.go
src/internal/copyright/copyright_test.go [new file with mode: 0644]
src/internal/runtime/sys/dit_arm64.s
src/internal/types/errors/generrordocs.go
src/log/slog/example_discard_test.go
src/path/filepath/path_windows.go

index 335bff81ba628797be089ef0fd6da2c627f9b108..1ddd48fa7a889a17b879ab17b2de85168b836d34 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 package auth
 
 import (
index 51c23c0130251660f0cc4cd3c0c11d27034f8b05..dfdf6818c866110c4d0f6eaa81a7af9856bc2555 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 package intercept
 
 import (
index 003b14e9dee6bfc10cc352c365b0e9f3f8c2fba4..cc74e56f9814b11ff3c16106e34482a44099054b 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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 !purego && !wasm
 
 #include "textflag.h"
index b29fe2c978b790bb9dfe04e9b44e13c3d2fe66bc..bb78c6459b6d2fb5d0a755ce54f4d58856eebdbc 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 package tls
 
 import (
diff --git a/src/internal/copyright/copyright_test.go b/src/internal/copyright/copyright_test.go
new file mode 100644 (file)
index 0000000..4676f18
--- /dev/null
@@ -0,0 +1,69 @@
+// Copyright 2024 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.
+
+package copyright
+
+import (
+       "bytes"
+       "internal/testenv"
+       "io"
+       "io/fs"
+       "os"
+       "path/filepath"
+       "testing"
+)
+
+var copyright = []byte("Copyright")
+
+var permitted = [][]byte{
+       []byte("// Code generated by "),
+       []byte("// Code generated from "),
+       []byte("// Created by cgo -cdefs"),
+       []byte("// DO NOT EDIT\n// generated by:"),
+       []byte("// Empty assembly file"),
+       []byte("// Generated using cgo"),
+       []byte("// Original source:\n//\thttp://www.zorinaq.com/papers/md5-amd64.html"), // public domain crypto/md5
+       []byte("// created by cgo -cdefs"),
+       []byte("// go run mkasm.go"),
+       []byte("// mkerrors"),
+       []byte("// mksys"),
+       []byte("// run\n// Code generated by"), // cmd/compile/internal/test/constFold_test.go
+}
+
+func TestCopyright(t *testing.T) {
+       buf := make([]byte, 2048)
+       filepath.WalkDir(filepath.Join(testenv.GOROOT(t), "src"), func(path string, d fs.DirEntry, err error) error {
+               if d.Name() == "testdata" || d.Name() == "vendor" {
+                       return filepath.SkipDir
+               }
+               switch filepath.Ext(d.Name()) {
+               default:
+                       return nil
+               case ".s", ".go":
+                       // check
+               }
+
+               f, err := os.Open(path)
+               if err != nil {
+                       t.Error(err)
+                       return nil
+               }
+               n, err := f.Read(buf)
+               if err != nil && err != io.EOF {
+                       t.Error(err)
+                       return nil
+               }
+               b := buf[:n]
+               if bytes.Contains(b, copyright) {
+                       return nil
+               }
+               for _, ok := range permitted {
+                       if bytes.HasPrefix(b, ok) {
+                               return nil
+                       }
+               }
+               t.Errorf("%s: missing copyright notice", path)
+               return nil
+       })
+}
index fcb44d6f22e034543726b0e5882f8da45030500d..c27dfc9af3c1ec8b3813c0fc160e0956eec9e877 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 #include "textflag.h"
 
 TEXT ·EnableDIT(SB),$0-1
index 46343be3ef08bc45ca445cb54c5487908837a55a..613c77426928dee4e8177abf68bb43413e7b06c3 100644 (file)
@@ -1,9 +1,9 @@
-//go:build ignore
-
 // 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 ignore
+
 // generrordocs creates a Markdown file for each (compiler) error code
 // and its associated documentation.
 // Note: this program must be run in this directory.
index a1aec65bcf103e044ed31bc05b72c81129ceec2a..c0cc2a65aaf8c734ac9f74c17c43709024f21182 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 package slog_test
 
 import (
index d53f87f1ac1a369a9c566a77a1d039dff24bfd3c..d0eb42c5f6db2a9a73c1238101c2fdcebcba42b1 100644 (file)
@@ -1,3 +1,7 @@
+// Copyright 2024 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.
+
 package filepath
 
 import (