Created
September 18, 2013 15:00
-
-
Save leepa/6610440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Alex... see line 19.