Bump Ginkgo to support building on riscv64 arch

This commit is contained in:
Carlos de Paula
2019-12-06 15:23:15 -05:00
parent 641d0290e4
commit ecfd30d251
38 changed files with 226 additions and 73 deletions

View File

@@ -1,10 +1,12 @@
package main
import (
"bytes"
"flag"
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"text/template"
)
@@ -158,11 +160,90 @@ func formatSubject(name string) string {
return name
}
// moduleName returns module name from go.mod from given module root directory
func moduleName(modRoot string) string {
modFile, err := os.Open(filepath.Join(modRoot, "go.mod"))
if err != nil {
return ""
}
mod := make([]byte, 128)
_, err = modFile.Read(mod)
if err != nil {
return ""
}
slashSlash := []byte("//")
moduleStr := []byte("module")
for len(mod) > 0 {
line := mod
mod = nil
if i := bytes.IndexByte(line, '\n'); i >= 0 {
line, mod = line[:i], line[i+1:]
}
if i := bytes.Index(line, slashSlash); i >= 0 {
line = line[:i]
}
line = bytes.TrimSpace(line)
if !bytes.HasPrefix(line, moduleStr) {
continue
}
line = line[len(moduleStr):]
n := len(line)
line = bytes.TrimSpace(line)
if len(line) == n || len(line) == 0 {
continue
}
if line[0] == '"' || line[0] == '`' {
p, err := strconv.Unquote(string(line))
if err != nil {
return "" // malformed quoted string or multiline module path
}
return p
}
return string(line)
}
return "" // missing module path
}
func findModuleRoot(dir string) (root string) {
dir = filepath.Clean(dir)
// Look for enclosing go.mod.
for {
if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !fi.IsDir() {
return dir
}
d := filepath.Dir(dir)
if d == dir {
break
}
dir = d
}
return ""
}
func getPackageImportPath() string {
workingDir, err := os.Getwd()
if err != nil {
panic(err.Error())
}
// Try go.mod file first
modRoot := findModuleRoot(workingDir)
if modRoot != "" {
modName := moduleName(modRoot)
if modName != "" {
cd := strings.Replace(workingDir, modRoot, "", -1)
return modName + cd
}
}
// Fallback to GOPATH structure
sep := string(filepath.Separator)
paths := strings.Split(workingDir, sep+"src"+sep)
if len(paths) == 1 {

View File

@@ -5,6 +5,7 @@ import (
"fmt"
"math/rand"
"os"
"regexp"
"strings"
"time"
@@ -163,17 +164,27 @@ func (r *SpecRunner) combineCoverprofiles(runners []*testrunner.TestRunner) erro
fmt.Println("path is " + path)
combined, err := os.OpenFile(filepath.Join(path, r.getCoverprofile()),
os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
combined, err := os.OpenFile(
filepath.Join(path, r.getCoverprofile()),
os.O_WRONLY|os.O_CREATE,
0666,
)
if err != nil {
fmt.Printf("Unable to create combined profile, %v\n", err)
return nil // non-fatal error
}
for _, runner := range runners {
modeRegex := regexp.MustCompile(`^mode: .*\n`)
for index, runner := range runners {
contents, err := ioutil.ReadFile(runner.CoverageFile)
// remove the cover mode line from every file
// except the first one
if index > 0 {
contents = modeRegex.ReplaceAll(contents, []byte{})
}
if err != nil {
fmt.Printf("Unable to read coverage file %s to combine, %v\n", runner.CoverageFile, err)
return nil // non-fatal error