Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
Merge branch 'master' into trace-context
Browse files Browse the repository at this point in the history
  • Loading branch information
drodriguezhdez committed Mar 24, 2020
2 parents d624e51 + cd8fc09 commit 357af70
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type (
)

var (
version = "0.1.14-pre1"
version = "0.1.15-pre1"

testingModeFrequency = time.Second
nonTestingModeFrequency = time.Minute
Expand Down
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

0 comments on commit 357af70

Please sign in to comment.