diff --git a/.github/PULL_REQUEST_TEMPLATE/new_helper.md b/.github/PULL_REQUEST_TEMPLATE/new_helper.md index 341ab35..97a0ece 100644 --- a/.github/PULL_REQUEST_TEMPLATE/new_helper.md +++ b/.github/PULL_REQUEST_TEMPLATE/new_helper.md @@ -10,14 +10,21 @@ - [ ] ๐Ÿงช This helper is tested - [ ] ๐ŸŽ๏ธ My code limits memory allocation and is fast - [ ] ๐Ÿงžโ€โ™‚๏ธ This helper is immutable and my tests prove it -- [ ] โœ๏ธ I implemented the parallel and mutable variants -- [ ] ๐Ÿ“– My helper has been added to README -- [ ] ๐Ÿ”ฌ An example has been added to xxxxx_example_test.go -- [ ] โ›น๏ธ An example has been created on https://go.dev/play +- [ ] โœ๏ธ I implemented the parallel, iterator and mutable variants +- [ ] ๐Ÿ”ฌ An example has been added to lo_example_test.go +- [ ] โ›น๏ธ An example has been created on https://go.dev/play and added in comments +- [ ] ๐Ÿ“– My helper has been added to documentation + - [ ] in README.md + - [ ] in docs/data/*.md + - [ ] in docs/static/llms.txt ## Conventions - Returning `(ok bool)` is often better than `(err error)` - `panic(...)` must be limited -- Helpers should allow batching (eg: receive variadic arguments) -- Use an index at the end of the helper name to declare variants (eg: `lo.Must0`, `lo.Must1`, `lo.Must2`...) +- Helpers should receive variadic arguments when relevent +- Add variants of your helper when relevant: + - Variable number of arguments: `lo.Must0`, `lo.Must1`, `lo.Must2`, ... + - Predicate with index: `lo.SliceToMap` vs `lo.SliceToMapI` + - With lazy callback: `lo.Ternary` vs `lo.TernaryF` + - ... diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1e98b9..9a47dd7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,8 +35,9 @@ jobs: - name: Test run: make test - - name: Test + - name: Test coverage run: make coverage + if: matrix.go == '1.18' - name: Codecov uses: codecov/codecov-action@v5 diff --git a/lo_test.go b/lo_test.go index 1ca6667..8e3b71a 100644 --- a/lo_test.go +++ b/lo_test.go @@ -1,6 +1,9 @@ package lo import ( + "fmt" + "runtime" + "strconv" "testing" "time" @@ -18,14 +21,34 @@ func testWithTimeout(t *testing.T, timeout time.Duration) { t.Helper() testFinished := make(chan struct{}) - t.Cleanup(func() { close(testFinished) }) - go func() { //nolint:staticcheck + 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): - t.Errorf("test timed out after %s", timeout) - t.FailNow() //nolint:govet,staticcheck + 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) } }() } diff --git a/retry_example_test.go b/retry_example_test.go index 1c08a00..ae71b17 100644 --- a/retry_example_test.go +++ b/retry_example_test.go @@ -1,5 +1,4 @@ //go:build !race -// +build !race package lo