Skip to content

Commit

Permalink
all: hide home directory in script tests (#605)
Browse files Browse the repository at this point in the history
As described in:

  #603 (comment)

we currently have a situation whereby the home directory sits within the
root directory of a script test. Given that most scripts also put files
in this root directory, i.e. the script root is also the main module
root, we have a situation where files in the home directory are
contained within the main module.

We do not set GOPATH explicitly as part of our tests, hence GOPATH
defaults to being a subdirectory within the home directory, i.e. also
part of the main module.

As we are now using goproxytest, this means modules we access end up
being expanded to $HOME/go/pkg/mod.

The file watcher that is part of govim is somewhat broken (#604) and we
end up watching changes to nested modules in $HOME/go/pkg/mod.

Whilst we have raised #604 in order to fix the file watching problem, we
can also fix this problem in the short term by defining HOME as:

  $script_root/.home

At the same time, we fix a bug in the watcher whereby we were not
correctly skipping hidden directories.

Fixes #603
  • Loading branch information
myitcv committed Dec 3, 2019
1 parent 4757564 commit 6f5e25a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/govim/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestScripts(t *testing.T) {
if err := os.MkdirAll(tmp, 0777); err != nil {
return fmt.Errorf("failed to create temp dir %v: %v", tmp, err)
}
home := filepath.Join(e.WorkDir, "home")
home := filepath.Join(e.WorkDir, ".home")
e.Vars = append(e.Vars,
"TMPDIR="+tmp,
"GOPROXY="+proxy.URL,
Expand All @@ -90,7 +90,7 @@ func TestScripts(t *testing.T) {
"PLUGIN_PATH="+govimPath,
"CURRENT_GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
)
testPluginPath := filepath.Join(e.WorkDir, "home", ".vim", "pack", "plugins", "start", "govim")
testPluginPath := filepath.Join(home, ".vim", "pack", "plugins", "start", "govim")

errLog := new(testdriver.LockingBuffer)
outputs := []io.Writer{
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (m *modWatcher) watch() {
// We have a dir
switch filepath.Base(path)[0] {
case '.', '_':
return nil
return filepath.SkipDir
}
if path != m.root {
// check we are not in a submodule
Expand Down
4 changes: 2 additions & 2 deletions govim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func TestScripts(t *testing.T) {
},
Condition: testdriver.Condition,
Setup: func(e *testscript.Env) error {
home := filepath.Join(e.WorkDir, "home")
home := filepath.Join(e.WorkDir, ".home")
e.Vars = append(e.Vars,
"HOME="+home,
)
testPluginPath := filepath.Join(e.WorkDir, "home", ".vim", "pack", "plugins", "start", "govim")
testPluginPath := filepath.Join(home, ".vim", "pack", "plugins", "start", "govim")

var vimDebugLogPath, govimDebugLogPath string

Expand Down

0 comments on commit 6f5e25a

Please sign in to comment.