Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@leepa
Created September 18, 2013 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leepa/6610440 to your computer and use it in GitHub Desktop.
Save leepa/6610440 to your computer and use it in GitHub Desktop.
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
Copy link
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