github.com/matrixorigin/matrixone@v1.2.0/pkg/util/stack/stack_test.go (about)

     1  // Copyright 2022 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package stack
    16  
    17  import (
    18  	"fmt"
    19  	"testing"
    20  
    21  	"github.com/stretchr/testify/require"
    22  )
    23  
    24  func TestCaller(t *testing.T) {
    25  	type args struct {
    26  		depth int
    27  	}
    28  	tests := []struct {
    29  		name string
    30  		args args
    31  		want string
    32  	}{
    33  		{name: "depth_0", args: args{depth: 0}, want: "stack_test.go:37"},
    34  	}
    35  	for _, tt := range tests {
    36  		t.Run(tt.name, func(t *testing.T) {
    37  			if got := Caller(tt.args.depth); fmt.Sprintf("%v", got) != tt.want {
    38  				t.Errorf("Caller() = %v, want %v", got, tt.want)
    39  			}
    40  		})
    41  	}
    42  }
    43  
    44  func TestCallers(t *testing.T) {
    45  	type args struct {
    46  		depth int
    47  	}
    48  	tests := []struct {
    49  		name string
    50  		args args
    51  		want string
    52  	}{
    53  		{name: "depth_0", args: args{depth: 0}, want: "\n\tstack_test.go\n\ttesting.go\n\tasm_amd64.s"},
    54  	}
    55  	for _, tt := range tests {
    56  		t.Run(tt.name, func(t *testing.T) {
    57  			got := Callers(tt.args.depth)
    58  			t.Logf("Callers() = %s", got)
    59  			t.Logf("Callers(%%+s) = %+s", got)
    60  			t.Logf("Callers(%%v) = %v", got)
    61  			t.Logf("Callers(%%+v) = %+v", got)
    62  			require.Equal(t, fmt.Sprintf("%+v", got.StackTrace()), fmt.Sprintf("%+v", got))
    63  		})
    64  	}
    65  }