-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
160 additions
and
72 deletions.
There are no files selected for viewing
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
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package stackpath | ||
|
||
import ( | ||
"fmt" | ||
"runtime/debug" | ||
"stackpath_lib" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var expectedSubdirTestFile string | ||
|
||
func TestStackPathSubdir(t *testing.T) { | ||
stack := stackpath_lib.Wrap(func() string { | ||
return string(debug.Stack()) | ||
}) | ||
for _, expectedFile := range []string{ | ||
expectedLibFile, | ||
expectedSubdirTestFile, | ||
} { | ||
if expectedFile == "" { | ||
t.Fatalf("Unexpected empty value. Looks like x_defs missed.") | ||
} | ||
|
||
expectedSubstring := fmt.Sprintf("\n\t%s:", expectedFile) | ||
if !strings.Contains(stack, expectedSubstring) { | ||
t.Fatalf("Stacktrace does not contains substring %q: %s", expectedSubstring, stack) | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package stackpath_default_lib | ||
|
||
func Wrap(cb func() string) string { | ||
return cb() | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,51 @@ | ||
package stackpath | ||
|
||
import ( | ||
"fmt" | ||
"runtime/debug" | ||
"stackpath_default_lib" | ||
"stackpath_lib" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
var expectedLibFile string | ||
var expectedTestFile string | ||
|
||
func TestStackPath(t *testing.T) { | ||
stack := stackpath_lib.Wrap(func() string { | ||
return string(debug.Stack()) | ||
}) | ||
// Stack example: | ||
// | ||
// goroutine 7 [running]: | ||
// runtime/debug.Stack() | ||
// GOROOT/src/runtime/debug/stack.go:24 +0x65 | ||
// tests/core/go_test/stackpath_test.TestStackPath.func1(...) | ||
// bar/stackpath_test.go:12 | ||
// stackpath_lib.Wrap(...) | ||
// foo/stackpath_lib.go:4 | ||
// tests/core/go_test/stackpath_test.TestStackPath(0xc00009a9c0) | ||
// bar/stackpath_test.go:11 +0x35 | ||
// testing.tRunner(0xc00009a9c0, 0x575e50) | ||
// GOROOT/src/testing/testing.go:1439 +0x102 | ||
// created by testing.(*T).Run | ||
// GOROOT/src/testing/testing.go:1486 +0x35f | ||
for _, expected := range []string{ | ||
"\tbar/stackpath_test.go:", | ||
"\tfoo/stackpath_lib.go:", | ||
for _, expectedFile := range []string{ | ||
expectedLibFile, | ||
expectedTestFile, | ||
} { | ||
if expectedFile == "" { | ||
t.Fatalf("Unexpected empty value. Looks like x_defs missed.") | ||
} | ||
|
||
expectedSubstring := fmt.Sprintf("\n\t%s:", expectedFile) | ||
if !strings.Contains(stack, expectedSubstring) { | ||
t.Fatalf("Stacktrace does not contains substring %q: %s", expectedSubstring, stack) | ||
} | ||
} | ||
} | ||
|
||
func TestStackDefaultPath(t *testing.T) { | ||
stack := stackpath_default_lib.Wrap(func() string { | ||
return string(debug.Stack()) | ||
}) | ||
for _, expectedFile := range []string{ | ||
"tests/core/go_test/stackpath_default_lib.go", | ||
expectedTestFile, | ||
} { | ||
if !strings.Contains(stack, expected) { | ||
t.Fatalf("Stacktrace does not contains substring %q", expected) | ||
if expectedFile == "" { | ||
t.Fatalf("Unexpected empty value. Looks like x_defs missed.") | ||
} | ||
|
||
expectedSubstring := fmt.Sprintf("\n\t%s:", expectedFile) | ||
if !strings.Contains(stack, expectedSubstring) { | ||
t.Fatalf("Stacktrace does not contains substring %q: %s", expectedSubstring, stack) | ||
} | ||
} | ||
} |