From: Russ Cox Date: Thu, 21 Nov 2024 13:46:57 +0000 (-0500) Subject: internal/copyright: add test that copyright notices exist X-Git-Tag: go1.24rc1~146 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=844426104a901b68f3a8c7a7ca96d910b03fb054;p=gostls13.git internal/copyright: add test that copyright notices exist 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 Reviewed-by: Sam Thanawalla --- diff --git a/src/cmd/go/internal/auth/gitauth_test.go b/src/cmd/go/internal/auth/gitauth_test.go index 335bff81ba..1ddd48fa7a 100644 --- a/src/cmd/go/internal/auth/gitauth_test.go +++ b/src/cmd/go/internal/auth/gitauth_test.go @@ -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 ( diff --git a/src/cmd/go/internal/web/intercept/intercept.go b/src/cmd/go/internal/web/intercept/intercept.go index 51c23c0130..dfdf6818c8 100644 --- a/src/cmd/go/internal/web/intercept/intercept.go +++ b/src/cmd/go/internal/web/intercept/intercept.go @@ -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 ( diff --git a/src/crypto/internal/fips140/check/checktest/asm.s b/src/crypto/internal/fips140/check/checktest/asm.s index 003b14e9de..cc74e56f98 100644 --- a/src/crypto/internal/fips140/check/checktest/asm.s +++ b/src/crypto/internal/fips140/check/checktest/asm.s @@ -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" diff --git a/src/crypto/tls/bogo_shim_test.go b/src/crypto/tls/bogo_shim_test.go index b29fe2c978..bb78c6459b 100644 --- a/src/crypto/tls/bogo_shim_test.go +++ b/src/crypto/tls/bogo_shim_test.go @@ -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 index 0000000000..4676f18a59 --- /dev/null +++ b/src/internal/copyright/copyright_test.go @@ -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 + }) +} diff --git a/src/internal/runtime/sys/dit_arm64.s b/src/internal/runtime/sys/dit_arm64.s index fcb44d6f22..c27dfc9af3 100644 --- a/src/internal/runtime/sys/dit_arm64.s +++ b/src/internal/runtime/sys/dit_arm64.s @@ -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 diff --git a/src/internal/types/errors/generrordocs.go b/src/internal/types/errors/generrordocs.go index 46343be3ef..613c774269 100644 --- a/src/internal/types/errors/generrordocs.go +++ b/src/internal/types/errors/generrordocs.go @@ -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. diff --git a/src/log/slog/example_discard_test.go b/src/log/slog/example_discard_test.go index a1aec65bcf..c0cc2a65aa 100644 --- a/src/log/slog/example_discard_test.go +++ b/src/log/slog/example_discard_test.go @@ -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 ( diff --git a/src/path/filepath/path_windows.go b/src/path/filepath/path_windows.go index d53f87f1ac..d0eb42c5f6 100644 --- a/src/path/filepath/path_windows.go +++ b/src/path/filepath/path_windows.go @@ -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 (