github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/must/pass.go (about)

     1  package must
     2  
     3  import (
     4  	"github.com/v2pro/plz/test"
     5  	"runtime"
     6  	"github.com/v2pro/plz/test/go-spew/spew"
     7  )
     8  
     9  //go:noinline
    10  func Assert(result bool, kv ...interface{}) {
    11  	if result {
    12  		return
    13  	}
    14  	t := test.CurrentT()
    15  	test.Helper()
    16  	_, file, line, ok := runtime.Caller(1)
    17  	if !ok {
    18  		t.Fatal("check failed")
    19  		return
    20  	}
    21  	t.Fatal(test.ExtractFailedLines(file, line))
    22  }
    23  
    24  //go:noinline
    25  func Pass(result bool, kv ...interface{}) {
    26  	if result {
    27  		return
    28  	}
    29  	t := test.CurrentT()
    30  	test.Helper()
    31  	_, file, line, ok := runtime.Caller(1)
    32  	if !ok {
    33  		t.Fatal("check failed")
    34  		return
    35  	}
    36  	for i := 0; i < len(kv); i+=2 {
    37  		key := kv[i].(string)
    38  		t.Errorf("%s: %s", key, spew.Sdump(kv[i+1]))
    39  	}
    40  	t.Fatal(test.ExtractFailedLines(file, line))
    41  }