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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
This commit is contained in:
Russ Cox 2024-11-21 08:46:57 -05:00
parent c1a0ee3764
commit 844426104a
9 changed files with 99 additions and 2 deletions

View 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 (

View 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 (

View 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"

View 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 (

View File

@ -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
})
}

View 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

View 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.

View 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 (

View 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 (