зеркало из https://github.com/golang/dep.git
Revert "Merge pull request #825 from grepory/dep-ensure-errors"
This reverts commit6343e90dfd
, reversing changes made tobea8fe3176
.
This commit is contained in:
Родитель
6343e90dfd
Коммит
1f26a1c477
|
@ -304,23 +304,27 @@ func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstrai
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkErrors(m map[string]pkgtree.PackageOrErr) error {
|
func checkErrors(m map[string]pkgtree.PackageOrErr) error {
|
||||||
var buildErrors, noGoErrors []string
|
noGoErrors, pkgErrors := 0, 0
|
||||||
|
for _, poe := range m {
|
||||||
for importPath, poe := range m {
|
|
||||||
if poe.Err != nil {
|
if poe.Err != nil {
|
||||||
switch poe.Err.(type) {
|
switch poe.Err.(type) {
|
||||||
case *build.NoGoError:
|
case *build.NoGoError:
|
||||||
noGoErrors = append(noGoErrors, fmt.Sprintf("%s: no go code", importPath))
|
noGoErrors++
|
||||||
default:
|
default:
|
||||||
buildErrors = append(buildErrors, poe.Err.Error())
|
pkgErrors++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if len(m) == 0 || len(m) == noGoErrors {
|
||||||
|
return errors.New("all dirs lacked any go code")
|
||||||
|
}
|
||||||
|
|
||||||
buildErrors = append(buildErrors, noGoErrors...)
|
if len(m) == pkgErrors {
|
||||||
|
return errors.New("all dirs had go code with errors")
|
||||||
|
}
|
||||||
|
|
||||||
if len(buildErrors) > 0 {
|
if len(m) == pkgErrors+noGoErrors {
|
||||||
return errors.Errorf("Found %d errors:\n\n%s", len(buildErrors), strings.Join(buildErrors, "\n"))
|
return errors.Errorf("%d dirs had errors and %d had no go code", pkgErrors, noGoErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -1,47 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"go/build"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/golang/dep/internal/gps/pkgtree"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCheckErrors(t *testing.T) {
|
|
||||||
tt := []struct {
|
|
||||||
name string
|
|
||||||
hasErrs bool
|
|
||||||
pkgOrErrMap map[string]pkgtree.PackageOrErr
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "noErrors",
|
|
||||||
hasErrs: false,
|
|
||||||
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
|
|
||||||
"mypkg": {
|
|
||||||
P: pkgtree.Package{},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "hasErrors",
|
|
||||||
hasErrs: true,
|
|
||||||
pkgOrErrMap: map[string]pkgtree.PackageOrErr{
|
|
||||||
"github.com/me/pkg": {
|
|
||||||
Err: &build.NoGoError{},
|
|
||||||
},
|
|
||||||
"github.com/someone/pkg": {
|
|
||||||
Err: errors.New("code is busted"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range tt {
|
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
|
||||||
if hasErrs := checkErrors(tc.pkgOrErrMap) != nil; hasErrs != tc.hasErrs {
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -3,6 +3,6 @@
|
||||||
["init", "-no-examples", "-skip-tools"],
|
["init", "-no-examples", "-skip-tools"],
|
||||||
["ensure", "-update"]
|
["ensure", "-update"]
|
||||||
],
|
],
|
||||||
"error-expected": "Found 1 errors:\n\ngithub.com/golang/notexist: no go code",
|
"error-expected": "all dirs lacked any go code",
|
||||||
"vendor-final": []
|
"vendor-final": []
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче