Merge pull request #221 from brahmaroutu/gccgo_functionname_issue

Due to function name format differences, code fails with GCCGO
pull/223/head
Ernesto Jiménez 2015-09-29 19:35:40 +01:00
commit 2b15294402
1 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package mock
import (
"fmt"
"reflect"
"regexp"
"runtime"
"strings"
"sync"
@ -265,6 +266,14 @@ func (m *Mock) Called(arguments ...interface{}) Arguments {
panic("Couldn't get the caller information")
}
functionPath := runtime.FuncForPC(pc).Name()
//Next four lines are required to use GCCGO function naming conventions.
//For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock
//uses inteface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree
//With GCCGO we need to remove interface information starting from pN<dd>.
re := regexp.MustCompile("\\.pN\\d+_")
if re.MatchString(functionPath) {
functionPath = re.Split(functionPath, -1)[0]
}
parts := strings.Split(functionPath, ".")
functionName := parts[len(parts)-1]