Skip to content

Instantly share code, notes, and snippets.

@leepa
Created September 18, 2013 15:00
Show Gist options
  • Select an option

  • Save leepa/6610440 to your computer and use it in GitHub Desktop.

Select an option

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

leepa commented Sep 18, 2013

Copy link
Copy Markdown
Author

For Alex... see line 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment