enhance doc

This commit is contained in:
jichangjun 2020-07-26 17:46:35 +08:00
parent 6d0160ad2a
commit 51dad73b05
5 changed files with 19 additions and 11 deletions

View File

@ -110,7 +110,7 @@ func (b *Build) Build() error {
// the binary name is always same as the directory name of current directory
func (b *Build) determineOutputDir(outputDir string) (string, error) {
if b.TmpDir == "" {
return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrWrongCallSequence)
return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrEmptyTempWorkingDir)
}
// fix #43

View File

@ -70,7 +70,7 @@ func TestCheckParameters(t *testing.T) {
func TestDetermineOutputDir(t *testing.T) {
b := &Build{}
_, err := b.determineOutputDir("")
assert.Equal(t, errors.Is(err, ErrWrongCallSequence), true, "called before Build.MvProjectsToTmp() should fail")
assert.Equal(t, errors.Is(err, ErrEmptyTempWorkingDir), true, "called before Build.MvProjectsToTmp() should fail")
b.TmpDir = "fake"
_, err = b.determineOutputDir("xx")

View File

@ -5,12 +5,20 @@ import (
)
var (
ErrShouldNotReached = errors.New("should never be reached")
ErrGocShouldExecInProject = errors.New("goc not executed in project directory")
// ErrShouldNotReached represents the logic should not be reached in normal flow
ErrShouldNotReached = errors.New("should never be reached")
// ErrGocShouldExecInProject represents goc currently not support for the project
ErrGocShouldExecInProject = errors.New("goc not support for such project directory")
// ErrWrongPackageTypeForInstall represents goc install command only support limited arguments
ErrWrongPackageTypeForInstall = errors.New("packages only support \".\" and \"./...\"")
ErrWrongPackageTypeForBuild = errors.New("packages only support \".\"")
ErrTooManyArgs = errors.New("too many args")
ErrInvalidWorkingDir = errors.New("the working directory is invalid")
ErrWrongCallSequence = errors.New("function should be called in a specified sequence")
ErrNoplaceToInstall = errors.New("dont know where to install")
// ErrWrongPackageTypeForBuild represents goc build command only support limited arguments
ErrWrongPackageTypeForBuild = errors.New("packages only support \".\"")
// ErrTooManyArgs represents goc CLI only support limited arguments
ErrTooManyArgs = errors.New("too many args")
// ErrInvalidWorkingDir represents the working directory is invalid
ErrInvalidWorkingDir = errors.New("the working directory is invalid")
// ErrEmptyTempWorkingDir represent the error that temporary working directory is empty
ErrEmptyTempWorkingDir = errors.New("temporary working directory is empty")
// ErrNoPlaceToInstall represents the err that no place to install the generated binary
ErrNoPlaceToInstall = errors.New("don't know where to install")
)

View File

@ -172,7 +172,7 @@ func (b *Build) findWhereToInstall() (string, error) {
if false == b.IsMod {
if b.Root == "" {
return "", ErrNoplaceToInstall
return "", ErrNoPlaceToInstall
}
return filepath.Join(b.Root, "bin"), nil
}

View File

@ -133,7 +133,7 @@ func TestFindWhereToInstall(t *testing.T) {
Root: "",
}
_, err := b.findWhereToInstall()
assert.EqualError(t, err, ErrNoplaceToInstall.Error())
assert.EqualError(t, err, ErrNoPlaceToInstall.Error())
// if $GOBIN not found
// and if $GOPATH not found