Skip to content
This repository was archived by the owner on Aug 17, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions instrumentation/testing/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ func UnpatchTestingLogger() {

func patchError() {
patch("Error", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
args := getArgs(argsValues[0])
test.Error(args...)
})
}

func patchErrorf() {
patch("Errorf", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
format := argsValues[0].String()
args := getArgs(argsValues[1])
test.Errorf(format, args...)
Expand All @@ -68,13 +70,15 @@ func patchErrorf() {

func patchFatal() {
patch("Fatal", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
args := getArgs(argsValues[0])
test.Fatal(args...)
})
}

func patchFatalf() {
patch("Fatalf", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
format := argsValues[0].String()
args := getArgs(argsValues[1])
test.Fatalf(format, args...)
Expand All @@ -83,13 +87,15 @@ func patchFatalf() {

func patchLog() {
patch("Log", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
args := getArgs(argsValues[0])
test.Log(args...)
})
}

func patchLogf() {
patch("Logf", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
format := argsValues[0].String()
args := getArgs(argsValues[1])
test.Logf(format, args...)
Expand All @@ -98,13 +104,15 @@ func patchLogf() {

func patchSkip() {
patch("Skip", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
args := getArgs(argsValues[0])
test.Skip(args...)
})
}

func patchSkipf() {
patch("Skipf", func(test *Test, argsValues []reflect.Value) {
test.t.Helper()
format := argsValues[0].String()
args := getArgs(argsValues[1])
test.Skipf(format, args...)
Expand Down Expand Up @@ -141,6 +149,13 @@ func patch(methodName string, methodBody func(test *Test, argsValues []reflect.V
instrumentation.Logger().Println("testing.T is nil")
return nil
}

t.Helper()
reflection.AddToHelpersMap(t, []string{
"reflect.callReflect",
"reflect.makeFuncStub",
})

test := GetTest(t)
if test == nil {
instrumentation.Logger().Printf("test struct for %v doesn't exist\n", t.Name())
Expand Down
19 changes: 19 additions & 0 deletions reflection/reflect.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ func GetTestMutex(t *testing.T) *sync.RWMutex {
return nil
}

func AddToHelpersMap(t *testing.T, frameFnNames []string) {
t.Helper()
mu := GetTestMutex(t)
if mu != nil {
mu.Lock()
defer mu.Unlock()
}

pointer, err := GetFieldPointerOf(t, "helpers")
if err != nil {
return
}

helpers := *(*map[string]struct{})(pointer)
for _, fnName := range frameFnNames {
helpers[fnName] = struct{}{}
}
}

func GetIsParallel(t *testing.T) bool {
mu := GetTestMutex(t)
if mu != nil {
Expand Down