Skip to content

Commit 00f0a74

Browse files
committed
add function TestDataContent for package gdebug
1 parent 232751e commit 00f0a74

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

debug/gdebug/gdebug_caller.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Caller(skip ...int) (function string, path string, line int) {
5252
// CallerWithFilter returns the function name and the absolute file path along with
5353
// its line number of the caller.
5454
//
55-
// The parameter <filter> is used to filter the path of the caller.
55+
// The parameter `filter` is used to filter the path of the caller.
5656
func CallerWithFilter(filter string, skip ...int) (function string, path string, line int) {
5757
var (
5858
number = 0
@@ -166,12 +166,12 @@ func CallerFileLineShort() string {
166166
return fmt.Sprintf(`%s:%d`, filepath.Base(path), line)
167167
}
168168

169-
// FuncPath returns the complete function path of given <f>.
169+
// FuncPath returns the complete function path of given `f`.
170170
func FuncPath(f interface{}) string {
171171
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
172172
}
173173

174-
// FuncName returns the function name of given <f>.
174+
// FuncName returns the function name of given `f`.
175175
func FuncName(f interface{}) string {
176176
path := FuncPath(f)
177177
if path == "" {

debug/gdebug/gdebug_stack.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ func Stack(skip ...int) string {
2828
// StackWithFilter returns a formatted stack trace of the goroutine that calls it.
2929
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
3030
//
31-
// The parameter <filter> is used to filter the path of the caller.
31+
// The parameter `filter` is used to filter the path of the caller.
3232
func StackWithFilter(filter string, skip ...int) string {
3333
return StackWithFilters([]string{filter}, skip...)
3434
}
3535

3636
// StackWithFilters returns a formatted stack trace of the goroutine that calls it.
3737
// It calls runtime.Stack with a large enough buffer to capture the entire trace.
3838
//
39-
// The parameter <filters> is a slice of strings, which are used to filter the path of the
39+
// The parameter `filters` is a slice of strings, which are used to filter the path of the
4040
// caller.
4141
//
4242
// TODO Improve the performance using debug.Stack.

debug/gdebug/gdebug_testdata.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
package gdebug
88

99
import (
10+
"io/ioutil"
1011
"path/filepath"
1112
)
1213

1314
// TestDataPath retrieves and returns the testdata path of current package,
1415
// which is used for unit testing cases only.
15-
// The optional parameter <names> specifies the its sub-folders/sub-files,
16+
// The optional parameter `names` specifies the sub-folders/sub-files,
1617
// which will be joined with current system separator and returned with the path.
1718
func TestDataPath(names ...string) string {
1819
path := CallerDirectory() + string(filepath.Separator) + "testdata"
@@ -21,3 +22,15 @@ func TestDataPath(names ...string) string {
2122
}
2223
return path
2324
}
25+
26+
// TestDataContent retrieves and returns the file content for specified testdata path of current package
27+
func TestDataContent(names ...string) string {
28+
path := TestDataPath(names...)
29+
if path != "" {
30+
data, err := ioutil.ReadFile(path)
31+
if err == nil {
32+
return string(data)
33+
}
34+
}
35+
return ""
36+
}

0 commit comments

Comments
 (0)