💾 Archived View for gemini.rmf-dev.com › repo › Vaati › Gemigit › files › 3535e7cd7c86523abf4909a3b7… captured on 2023-11-14 at 08:22:58. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-09-08)
-=-=-=-=-=-=-
0 package test
1
2 import (
3 "testing"
4 "runtime"
5 "strings"
6 "strconv"
7 )
8
9 func fileAndLine() string {
10 _, file, no, ok := runtime.Caller(2)
11 if !ok {
12 return ""
13 }
14 path := strings.Split(file, "/")
15 return path[len(path) - 1] + ":" + strconv.Itoa(no) + ":"
16 }
17
18 func IsNil(t *testing.T, err error) {
19 if err != nil {
20 t.Fatal(fileAndLine(), err)
21 }
22 }
23
24 func IsNotNil(t *testing.T, err error, message string) {
25 if err == nil {
26 t.Fatal(fileAndLine(), message)
27 }
28 }
29
30 func IsEqual(t *testing.T, x interface{}, y interface{}) {
31 if x != y {
32 t.Fatal(fileAndLine(), x, " != ", y)
33 }
34 }
35
36 func IsNotEqual(t *testing.T, x interface{}, y interface{}) {
37 if x == y {
38 t.Fatal(fileAndLine(), x, " != ", y)
39 }
40 }
41
42 func FuncName(t *testing.T) string {
43 fpcs := make([]uintptr, 1)
44
45 n := runtime.Callers(2, fpcs)
46 if n == 0 {
47 t.Fatal("function name: no caller")
48 }
49
50 caller := runtime.FuncForPC(fpcs[0] - 1)
51 if caller == nil {
52 t.Fatal("function name: caller is nil")
53 }
54
55 name := caller.Name()
56 return name[strings.LastIndex(name, ".") + 1:]
57 }
58