From da5c2f0414ba7270ae9db6634df6fd063cc4a3dc Mon Sep 17 00:00:00 2001 From: Anant Vyas Date: Wed, 11 Jul 2018 14:41:45 -0700 Subject: [PATCH 1/2] Move regexp compilation outside of the function --- mock/mock.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index cc4f642b5..ccb7d27e7 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -16,6 +16,9 @@ import ( "github.com/stretchr/testify/assert" ) +// regex for GCCGO functions +var gccgoRE = regexp.MustCompile("\\.pN\\d+_") + // TestingT is an interface wrapper around *testing.T type TestingT interface { Logf(format string, args ...interface{}) @@ -324,9 +327,8 @@ func (m *Mock) Called(arguments ...interface{}) Arguments { //For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock //uses interface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree //With GCCGO we need to remove interface information starting from pN
. - re := regexp.MustCompile("\\.pN\\d+_") - if re.MatchString(functionPath) { - functionPath = re.Split(functionPath, -1)[0] + if gccgoRE.MatchString(functionPath) { + functionPath = gccgoRE.Split(functionPath, -1)[0] } parts := strings.Split(functionPath, ".") functionName := parts[len(parts)-1] From 17c185c97f3d701887a8caf618fbfd5cea5adba0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 31 Jul 2023 20:29:00 +0200 Subject: [PATCH 2/2] mock: review fixed in Called --- mock/mock.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 66b30eef2..85c972d09 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -19,7 +19,7 @@ import ( ) // regex for GCCGO functions -var gccgoRE = regexp.MustCompile("\\.pN\\d+_") +var gccgoRE = regexp.MustCompile(`\.pN\d+_`) // TestingT is an interface wrapper around *testing.T type TestingT interface { @@ -459,7 +459,7 @@ func (m *Mock) Called(arguments ...interface{}) Arguments { // uses interface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree // With GCCGO we need to remove interface information starting from pN
. if gccgoRE.MatchString(functionPath) { - functionPath = re.Split(functionPath, -1)[0] + functionPath = gccgoRE.Split(functionPath, -1)[0] } parts := strings.Split(functionPath, ".") functionName := parts[len(parts)-1]