Source file src/internal/godebugs/godebugs_test.go

     1  // Copyright 2023 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  package godebugs_test
     6  
     7  import (
     8  	"internal/godebugs"
     9  	"internal/testenv"
    10  	"os"
    11  	"runtime"
    12  	"strings"
    13  	"testing"
    14  )
    15  
    16  func TestAll(t *testing.T) {
    17  	data, err := os.ReadFile("../../../doc/godebug.md")
    18  	if err != nil {
    19  		if os.IsNotExist(err) && (testenv.Builder() == "" || runtime.GOOS != "linux") {
    20  			t.Skip(err)
    21  		}
    22  		t.Fatal(err)
    23  	}
    24  	doc := string(data)
    25  
    26  	last := ""
    27  	for _, info := range godebugs.All {
    28  		if info.Name <= last {
    29  			t.Errorf("All not sorted: %s then %s", last, info.Name)
    30  		}
    31  		last = info.Name
    32  
    33  		if info.Package == "" {
    34  			t.Errorf("Name=%s missing Package", info.Name)
    35  		}
    36  		if info.Changed != 0 && info.Old == "" {
    37  			t.Errorf("Name=%s has Changed, missing Old", info.Name)
    38  		}
    39  		if info.Old != "" && info.Changed == 0 {
    40  			t.Errorf("Name=%s has Old, missing Changed", info.Name)
    41  		}
    42  		if !strings.Contains(doc, "`"+info.Name+"`") {
    43  			t.Errorf("Name=%s not documented in doc/godebug.md", info.Name)
    44  		}
    45  	}
    46  }
    47  

View as plain text