Selaa lähdekoodia

Add some format checks for Stack().

Gabriel Falkenberg 7 vuotta sitten
vanhempi
commit
eb62800744
1 muutettua tiedostoa jossa 15 lisäystä ja 2 poistoa
  1. 15 2
      error_test.go

+ 15 - 2
error_test.go

@@ -10,7 +10,7 @@ import (
 	"testing"
 )
 
-func TestStackFormatMatches(t *testing.T) {
+func TestStackFormat(t *testing.T) {
 
 	defer func() {
 		err := recover()
@@ -18,12 +18,25 @@ func TestStackFormatMatches(t *testing.T) {
 			t.Fatal(err)
 		}
 
-		bs := [][]uintptr{Errorf("hi").stack, callers()}
+		e, expected := Errorf("hi"), callers()
+
+		bs := [][]uintptr{e.stack, expected}
 
 		if err := compareStacks(bs[0], bs[1]); err != nil {
 			t.Errorf("Stack didn't match")
 			t.Errorf(err.Error())
 		}
+
+		stack := string(e.Stack())
+
+		if !strings.Contains(stack, "a: b(5)") {
+			t.Errorf("Stack trace does not contain source line: 'a: b(5)'")
+			t.Errorf(stack)
+		}
+		if !strings.Contains(stack, "error_test.go:") {
+			t.Errorf("Stack trace does not contain file name: 'error_test.go:'")
+			t.Errorf(stack)
+		}
 	}()
 
 	a()