Source file src/simd/archsimd/_gen/cmd/specstats/invariants_test.go

     1  // Copyright 2026 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 main
     6  
     7  import (
     8  	"flag"
     9  	"strings"
    10  	"testing"
    11  
    12  	"simd/archsimd/_gen/gentools"
    13  )
    14  
    15  // TestInvariants checks the counts in the report that must stay at zero (see
    16  // [invariant]) against the checked-in tree, so that a change that breaks one
    17  // fails here instead of moving a number in the report that nobody rereads.
    18  //
    19  // Like specstats itself, it needs up-to-date generator output: run
    20  // "go run . -w" in _gen first if the generators' inputs changed.
    21  func TestInvariants(t *testing.T) {
    22  	if testing.Short() {
    23  		t.Skip("loads simd and archsimd for every build configuration")
    24  	}
    25  	genOpts := gentools.RegisterFlags(flag.NewFlagSet("specstats", flag.ContinueOnError))
    26  	m := load(genOpts)
    27  	for _, inv := range m.invariants() {
    28  		if len(inv.items) == 0 {
    29  			continue
    30  		}
    31  		const max = 20
    32  		items := inv.items
    33  		more := ""
    34  		if len(items) > max {
    35  			items, more = items[:max], "\n\t..."
    36  		}
    37  		t.Errorf("%s: %d, want 0 [%s]:\n\t%s%s", inv.name, len(inv.items), inv.tasks,
    38  			strings.Join(items, "\n\t"), more)
    39  	}
    40  }
    41  

View as plain text