|
| 1 | +// Copyright 2025 The Go Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +//go:build go1.24 |
| 6 | + |
| 7 | +package http3 |
| 8 | + |
| 9 | +import ( |
| 10 | + "bytes" |
| 11 | + "os" |
| 12 | + "strings" |
| 13 | + "testing" |
| 14 | +) |
| 15 | + |
| 16 | +// TestFiles checks that every file in this package has a build constraint on Go 1.24. |
| 17 | +// |
| 18 | +// Package tests rely on testing/synctest, added as an experiment in Go 1.24. |
| 19 | +// When moving internal/http3 to an importable location, we can decide whether |
| 20 | +// to relax the constraint for non-test files. |
| 21 | +// |
| 22 | +// Drop this test when the x/net go.mod depends on 1.24 or newer. |
| 23 | +func TestFiles(t *testing.T) { |
| 24 | + f, err := os.Open(".") |
| 25 | + if err != nil { |
| 26 | + t.Fatal(err) |
| 27 | + } |
| 28 | + names, err := f.Readdirnames(-1) |
| 29 | + if err != nil { |
| 30 | + t.Fatal(err) |
| 31 | + } |
| 32 | + for _, name := range names { |
| 33 | + if !strings.HasSuffix(name, ".go") { |
| 34 | + continue |
| 35 | + } |
| 36 | + b, err := os.ReadFile(name) |
| 37 | + if err != nil { |
| 38 | + t.Fatal(err) |
| 39 | + } |
| 40 | + // Check for copyright header while we're in here. |
| 41 | + if !bytes.Contains(b, []byte("The Go Authors.")) { |
| 42 | + t.Errorf("%v: missing copyright", name) |
| 43 | + } |
| 44 | + // doc.go doesn't need a build constraint. |
| 45 | + if name == "doc.go" { |
| 46 | + continue |
| 47 | + } |
| 48 | + if !bytes.Contains(b, []byte("//go:build go1.24")) { |
| 49 | + t.Errorf("%v: missing constraint on go1.24", name) |
| 50 | + } |
| 51 | + if bytes.Contains(b, []byte(`"testing/synctest"`)) && |
| 52 | + !bytes.Contains(b, []byte("//go:build go1.24 && goexperiment.synctest")) { |
| 53 | + t.Errorf("%v: missing constraint on go1.24 && goexperiment.synctest", name) |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments