Due to function name format differences, code fails with GCCGO

Signed-off-by: Srini Brahmaroutu <srbrahma@us.ibm.com>
pull/221/head
Srini Brahmaroutu 2015-09-28 22:03:20 +00:00
parent bcd32dcc8b
commit 0df687d7a9
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]