Source file src/cmd/link/internal/benchmark/bench_test.go

     1  // Copyright 2020 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 benchmark
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestMakeBenchString(t *testing.T) {
    12  	tests := []struct {
    13  		have, want string
    14  	}{
    15  		{"foo", "BenchmarkFoo"},
    16  		{"  foo  ", "BenchmarkFoo"},
    17  		{"foo bar", "BenchmarkFooBar"},
    18  	}
    19  	for i, test := range tests {
    20  		if v := makeBenchString(test.have); test.want != v {
    21  			t.Errorf("test[%d] makeBenchString(%q) == %q, want %q", i, test.have, v, test.want)
    22  		}
    23  	}
    24  }
    25  
    26  func TestPProfFlag(t *testing.T) {
    27  	tests := []struct {
    28  		name string
    29  		want bool
    30  	}{
    31  		{"", false},
    32  		{"foo", true},
    33  	}
    34  	for i, test := range tests {
    35  		b := New(GC, test.name)
    36  		if v := b.shouldPProf(); test.want != v {
    37  			t.Errorf("test[%d] shouldPProf() == %v, want %v", i, v, test.want)
    38  		}
    39  	}
    40  }
    41  
    42  func TestPProfNames(t *testing.T) {
    43  	want := "foo_BenchmarkTest.cpuprof"
    44  	if v := makePProfFilename("foo", "test", "cpuprof"); v != want {
    45  		t.Errorf("makePProfFilename() == %q, want %q", v, want)
    46  	}
    47  }
    48  
    49  // Ensure that public APIs work with a nil Metrics object.
    50  func TestNilBenchmarkObject(t *testing.T) {
    51  	var b *Metrics
    52  	b.Start("TEST")
    53  	b.Report(nil)
    54  }
    55  

View as plain text