1// Copyright 2022 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
5package runtime_test
6
7import (
8	"bytes"
9	"internal/testenv"
10	"os"
11	"os/exec"
12	"testing"
13)
14
15// Test that the generated code for the lock rank graph is up-to-date.
16func TestLockRankGenerated(t *testing.T) {
17	testenv.MustHaveGoRun(t)
18	cmd := testenv.CleanCmdEnv(testenv.Command(t, testenv.GoToolPath(t), "run", "mklockrank.go"))
19	want, err := cmd.Output()
20	if err != nil {
21		if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 {
22			t.Fatalf("%v: %v\n%s", cmd, err, ee.Stderr)
23		}
24		t.Fatalf("%v: %v", cmd, err)
25	}
26	got, err := os.ReadFile("lockrank.go")
27	if err != nil {
28		t.Fatal(err)
29	}
30	if !bytes.Equal(want, got) {
31		t.Fatalf("lockrank.go is out of date. Please run go generate.")
32	}
33}
34