Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle failure of runtime.Caller #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lazysegtree
Copy link

Issue - #2

@lazysegtree
Copy link
Author

Testcase run

➜  ~/Workspace/kuknitin/assert-go git:(main) [9:42:05] git log --oneline | head -n 2
152c645 Handle failure of runtime.Caller
1e10074 docs(readme): add personal perspective about assertions in Go
➜  ~/Workspace/kuknitin/assert-go git:(main) [9:42:15] go test
PASS
ok  	github.com/nikoksr/assert-go	0.263s
➜  ~/Workspace/kuknitin/assert-go git:(main) [9:42:22]

@lazysegtree
Copy link
Author

Testing the failure scenario code flow by locally updating the skip value to 10. Thats the only way I have for now to make runtime.Caller() fail deterministically

➜  ~/Workspace/kuknitin/assert-go git:(main) ✗ [9:54:17] cat assert.go | grep -n runtime.Caller
42:	_, file, line, ok := runtime.Caller(10) //nolint:mnd // Explained in comment
➜  ~/Workspace/kuknitin/assert-go git:(main) ✗ [9:54:22]

# Using locally changed module
(.venv) ➜  ~/Workspace/kuknitin/shared/Misc/Go/Learning/basics/assert git:(main) ✗ [9:50:50] go mod edit -replace "github.com/nikoksr/assert-go"=/Users/kuknitin/Workspace/kuknitin/assert-go
(.venv) ➜  ~/Workspace/kuknitin/shared/Misc/Go/Learning/basics/assert git:(main) ✗ [10:02:22] go run main.go     
panic: Assertion failed (Runtime caller info is not available)
        Message: Failing assertion


goroutine 1 [running]:
github.com/nikoksr/assert-go.assert(0x68?, {0x104ac80be, 0x11}, {0x0, 0x0, 0x0})
        /Users/kuknitin/Workspace/kuknitin/assert-go/assert.go:46 +0x32c
github.com/nikoksr/assert-go.Assert(...)
        /Users/kuknitin/Workspace/kuknitin/assert-go/assert.go:30
main.main()
        /Users/kuknitin/Workspace/kuknitin/shared/Misc/Go/Learning/basics/assert/main.go:6 +0x3c
exit status 2
(.venv) ➜  ~/Workspace/kuknitin/shared/Misc/Go/Learning/basics/assert git:(main) ✗ [10:02:24] 

main.go

package main 
import (
	"github.com/nikoksr/assert-go"
)
func main() {
	assert.Assert(false, "Failing assertion")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant