Skip to content

Commit

Permalink
Improve error message 'not in workspace' for MacOS (exercism#968)
Browse files Browse the repository at this point in the history
* Improve error message 'not in workspace' for MacOS

Default installation of MacOS allows user to change directory
insensitive of case. This commit wraps a supplemental error message for
Mac users, including prints of the workspace and submit path.

* go fmt

* Update go version in travis.yml

Authored-by: Shirley Leu <[email protected]>
  • Loading branch information
Shirley Leu authored Feb 9, 2021
1 parent ba48dcd commit 01cb5bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ language: go
sudo: false

go:
- "1.11.x"
- "1.12.x"
- "1.15.x"
- tip

matrix:
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/exercism/cli

go 1.15

require (
github.com/blang/semver v3.5.1+incompatible
github.com/davecgh/go-spew v1.1.0
Expand Down
9 changes: 8 additions & 1 deletion workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package workspace

import (
"errors"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
)

Expand Down Expand Up @@ -121,7 +123,12 @@ func (ws Workspace) Exercises() ([]Exercise, error) {
// This is the directory that contains the exercise metadata file.
func (ws Workspace) ExerciseDir(s string) (string, error) {
if !strings.HasPrefix(s, ws.Dir) {
return "", errors.New("not in workspace")
var err = fmt.Errorf("not in workspace")
if runtime.GOOS == "darwin" {
err = fmt.Errorf("%w: directory location may be case sensitive: workspace directory: %s, "+
"submit path: %s", err, ws.Dir, s)
}
return "", err
}

path := s
Expand Down
25 changes: 25 additions & 0 deletions workspace/workspace_darwin_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package workspace

import (
"fmt"
"github.com/stretchr/testify/assert"
"path/filepath"
"runtime"
"strings"
"testing"
)

func TestExerciseDir_case_insensitive(t *testing.T) {
_, cwd, _, _ := runtime.Caller(0)
root := filepath.Join(cwd, "..", "..", "fixtures", "solution-dir")
// configuration file was set with "workspace" - the directory that exists
configured := Workspace{Dir: filepath.Join(root, "workspace")}
// user changes into directory with "bad" case - "Workspace"
userPath := strings.Replace(configured.Dir, "workspace", "Workspace", 1)

_, err := configured.ExerciseDir(filepath.Join(userPath, "exercise", "file.txt"))

assert.Error(t, err)
assert.Equal(t, fmt.Sprintf("not in workspace: directory location may be case sensitive: "+
"workspace directory: %s, submit path: %s/exercise/file.txt", configured.Dir, userPath), err.Error())
}

0 comments on commit 01cb5bc

Please sign in to comment.