Skip to content

Instantly share code, notes, and snippets.

View emptyland's full-sized avatar
😰

Carl Johnson emptyland

😰
View GitHub Profile
package main
import (
"log"
"net"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
var _ = Describe("Book", func() {
var (
longBook Book
shortBook Book
)
BeforeEach(func() {
longBook = Book{
Title: "Les Miserables",
Author: "Victor Hugo",
package books_test
import (
. "/path/to/books"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Book", func() {
package books_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"testing"
)
func TestBooks(t *testing.T) {
package demo
import "testing"
import "fmt"
var _ = &testing.T{}
func Foo() {
fmt.Println("Hello");
}
// 普通单元测试用例
func TestFoo(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode.")
}
// ...
}
// 性能测试用例
func nakedRecover() {
defer recover() // 这样无法捕捉到panic,panic会到达最顶层,导致程序失败退出。
panic("error")
}
func calleeRecover() {
defer func() {
// recover使用比较诡异,必须在defer中一个被调用的函数内被调用。
type bar struct {
id int
name string
}
func fooEsc(id int, name string) *bar {
return &bar { id: id, name: name } // 发生逃逸
}
package main
import "fmt"
func main() {
fmt.Println("Go to die!")
}
@emptyland
emptyland / gist:2986337
Created June 25, 2012 03:28
Git colored log
# Display colored log
git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --
# Create a alias for colored log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --"
# Use it
git lg