-
-
Notifications
You must be signed in to change notification settings - Fork 939
Expand file tree
/
Copy pathlo_test.go
More file actions
62 lines (50 loc) · 1.08 KB
/
lo_test.go
File metadata and controls
62 lines (50 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package lo
import (
"fmt"
"runtime"
"strconv"
"testing"
"time"
"github.com/samber/lo/internal/xtime"
"go.uber.org/goleak"
)
func TestMain(m *testing.M) {
xtime.SetClock(xtime.NewFakeClock())
goleak.VerifyTestMain(m)
}
// https://github.com/stretchr/testify/issues/1101
func testWithTimeout(t *testing.T, timeout time.Duration) {
t.Helper()
testFinished := make(chan struct{})
t.Cleanup(func() {
close(testFinished)
})
line := ""
funcName := ""
var pc [1]uintptr
n := runtime.Callers(2, pc[:])
if n > 0 {
frames := runtime.CallersFrames(pc[:])
frame, _ := frames.Next()
line = frame.File + ":" + strconv.Itoa(frame.Line)
funcName = frame.Function
}
go func() {
select {
case <-testFinished:
case <-time.After(timeout):
if line == "" || funcName == "" {
panic(fmt.Sprintf("Test timed out after: %v", timeout))
}
panic(fmt.Sprintf("%s: Test timed out after: %v\n%s", funcName, timeout, line))
// t.Errorf("Test timed out after: %v", timeout)
// os.Exit(1)
}
}()
}
type foo struct {
bar string
}
func (f foo) Clone() foo {
return foo{f.bar}
}