Skip to content

Instantly share code, notes, and snippets.

@leepa leepa/gist:6610440
Created Sep 18, 2013

Embed
What would you like to do?
package main
import (
"fmt"
"runtime"
)
type AssertionError struct {
pc uintptr
file string
line int
}
func main() {
defer func() {
if r := recover(); r != nil {
err, _ := r.(*AssertionError)
fmt.Printf("Assertion failure at: %s:%d\n", err.file, err.line)
}
}()
test_func();
}
func assert(v bool) {
if !v {
pc, file, line, _ := runtime.Caller(1)
fmt.Printf("%d\n", line)
panic(&AssertionError{pc, file, line})
}
}
func test_func() {
assert(3 == 4)
}
@leepa

This comment has been minimized.

Copy link
Owner Author

leepa commented Sep 18, 2013

For Alex... see line 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.