more explicit workdir check for builder, closes #139
Этот коммит содержится в:
родитель
ea9eeaa197
коммит
5ed33995bd
2 изменённых файлов: 51 добавлений и 19 удалений
40
builder.go
40
builder.go
|
@ -85,30 +85,42 @@ func Build(bin string) error {
|
|||
return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
|
||||
}
|
||||
|
||||
// let go do the dirty work and compile test
|
||||
// package with it's dependencies. Older go
|
||||
// versions does not accept existing file output
|
||||
// so we create a temporary executable which will
|
||||
// removed.
|
||||
temp := fmt.Sprintf(filepath.Join("%s", "temp-%d.test"), os.TempDir(), time.Now().UnixNano())
|
||||
|
||||
// builds and compile the tested package.
|
||||
// build and compile the tested package.
|
||||
// generated test executable will be removed
|
||||
// since we do not need it for godog suite.
|
||||
// we also print back the temp WORK directory
|
||||
// go has built. We will reuse it for our suite workdir.
|
||||
out, err = exec.Command("go", "test", "-c", "-work", "-o", temp).CombinedOutput()
|
||||
out, err = exec.Command("go", "test", "-c", "-work", "-o", os.DevNull).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compile tested package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
|
||||
}
|
||||
defer os.Remove(temp)
|
||||
|
||||
// extract go-build temporary directory as our workdir
|
||||
workdir = strings.TrimSpace(string(out))
|
||||
if !strings.HasPrefix(workdir, "WORK=") {
|
||||
return fmt.Errorf("expected WORK dir path, but got: %s", workdir)
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
// it may have some compilation warnings, in the output, but these are not
|
||||
// considered to be errors, since command exit status is 0
|
||||
for _, ln := range lines {
|
||||
if !strings.HasPrefix(ln, "WORK=") {
|
||||
continue
|
||||
}
|
||||
workdir = strings.Replace(ln, "WORK=", "", 1)
|
||||
break
|
||||
}
|
||||
|
||||
// may not locate it in output
|
||||
if workdir == testdir {
|
||||
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(out))
|
||||
}
|
||||
|
||||
// check whether workdir exists
|
||||
stats, err := os.Stat(workdir)
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("expected WORK dir: %s to be available", workdir)
|
||||
}
|
||||
|
||||
if !stats.IsDir() {
|
||||
return fmt.Errorf("expected WORK dir: %s to be directory", workdir)
|
||||
}
|
||||
workdir = strings.Replace(workdir, "WORK=", "", 1)
|
||||
testdir = filepath.Join(workdir, pkg.ImportPath, "_test")
|
||||
} else {
|
||||
// still need to create temporary workdir
|
||||
|
|
|
@ -87,7 +87,7 @@ func Build(bin string) error {
|
|||
return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
|
||||
}
|
||||
|
||||
// builds and compile the tested package.
|
||||
// build and compile the tested package.
|
||||
// generated test executable will be removed
|
||||
// since we do not need it for godog suite.
|
||||
// we also print back the temp WORK directory
|
||||
|
@ -98,11 +98,31 @@ func Build(bin string) error {
|
|||
}
|
||||
|
||||
// extract go-build temporary directory as our workdir
|
||||
workdir = strings.TrimSpace(string(out))
|
||||
if !strings.HasPrefix(workdir, "WORK=") {
|
||||
return fmt.Errorf("expected WORK dir path, but got: %s", workdir)
|
||||
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
|
||||
// it may have some compilation warnings, in the output, but these are not
|
||||
// considered to be errors, since command exit status is 0
|
||||
for _, ln := range lines {
|
||||
if !strings.HasPrefix(ln, "WORK=") {
|
||||
continue
|
||||
}
|
||||
workdir = strings.Replace(ln, "WORK=", "", 1)
|
||||
break
|
||||
}
|
||||
|
||||
// may not locate it in output
|
||||
if workdir == testdir {
|
||||
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(out))
|
||||
}
|
||||
|
||||
// check whether workdir exists
|
||||
stats, err := os.Stat(workdir)
|
||||
if os.IsNotExist(err) {
|
||||
return fmt.Errorf("expected WORK dir: %s to be available", workdir)
|
||||
}
|
||||
|
||||
if !stats.IsDir() {
|
||||
return fmt.Errorf("expected WORK dir: %s to be directory", workdir)
|
||||
}
|
||||
workdir = strings.Replace(workdir, "WORK=", "", 1)
|
||||
testdir = filepath.Join(workdir, "b001")
|
||||
} else {
|
||||
// still need to create temporary workdir
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче