gopkg.in/hedzr/errors.v3@v3.3.1/stack_test.go (about)

     1  package errors
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"testing"
     7  )
     8  
     9  func TestFuncname(t *testing.T) {
    10  	fn := funcname("/home/fine/app.TestFuncname()")
    11  	t.Log(fn)
    12  }
    13  
    14  func TestStack_StackTrace(t *testing.T) {
    15  	s := callers(0)
    16  	t.Log(s.StackTrace())
    17  
    18  	fmt.Printf("%+v\n", s)
    19  	fmt.Printf("%#v\n", s)
    20  	fmt.Printf("%v\n", s)
    21  	fmt.Printf("%s\n", s)
    22  	fmt.Printf("%q\n", s)
    23  
    24  	fmt.Printf("%+v\n", s.StackTrace())
    25  	fmt.Printf("%#v\n", s.StackTrace())
    26  	fmt.Printf("%v\n", s.StackTrace())
    27  	fmt.Printf("%s\n", s.StackTrace())
    28  	fmt.Printf("%q\n", s.StackTrace())
    29  
    30  	for _, frame := range s.StackTrace() {
    31  		fmt.Printf("%+v\n", frame)
    32  		fmt.Printf("%#v\n", frame)
    33  		fmt.Printf("%v\n", frame)
    34  		fmt.Printf("%s\n", frame)
    35  		fmt.Printf("%q\n", frame)
    36  		fmt.Printf("%n\n", frame)
    37  	}
    38  }
    39  
    40  func TestWithStack(t *testing.T) {
    41  	err := WithStack(nil)
    42  	t.Logf("failed: %+v", err)
    43  
    44  	err = WithStack(io.EOF)
    45  	t.Logf("failed: %+v", err)
    46  }
    47  
    48  func TestWithStackInfo(t *testing.T) {
    49  	err := &WithStackInfo{}
    50  	err.WithErrors(io.EOF).
    51  		WithCode(Internal).
    52  		WithMessage("").
    53  		WithMessage("%v", "").
    54  		WithSkip(1).
    55  		WithData(1, 2, io.ErrShortWrite).
    56  		WithTaggedData(TaggedData{"1": 1}).
    57  		End()
    58  	err.WithCause(io.ErrNoProgress).End()
    59  	t.Logf(" err is: %+v", err)
    60  	t.Logf(" err.Cause() is: %v", err.Cause())
    61  	t.Logf(" err.Causes() are: %v", err.Causes())
    62  
    63  	fmt.Printf("v: %v\n", err)
    64  	fmt.Printf("s: %s\n", err)
    65  	fmt.Printf("q: %q\n", err)
    66  	fmt.Printf("n: %n\n", err)
    67  
    68  	fmt.Printf("+v: %+v\n", err)
    69  	fmt.Printf("#v: %#v\n", err)
    70  }