From a23f5db2248ffcdd752b23c8c7b0dcc18dce0d27 Mon Sep 17 00:00:00 2001 From: Anant Vyas Date: Tue, 1 Aug 2023 02:07:29 -0600 Subject: [PATCH] mock: move regexp compilation outside of Called (#631) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Olivier Mengué --- mock/mock.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index a143ce5be..85c972d09 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -18,6 +18,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{}) @@ -455,9 +458,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]