Skip to content

Commit

Permalink
cmd/govim: ensure go-to-def tests have stable go.mod files (#736)
Browse files Browse the repository at this point in the history
golang.org/issues/36772 uncovered the fact the go-to-def tests were
making changes to go.mod files as part of the test. Whilst this
shouldn't be a problem per se, because gopls does not currently handle
cmd/go instances racing on go.mod, it makes sense to avoid this and
instead write a specific test that checks gopls behaves in the correct
way in the presence of multiple cmd/go instanes racing on go.mod.

This commit moves go-to-def tests to have stable go.mod files and
simplifies them in the process by using a module cache definition.

We also switch away from using bufname("") to the more precise
expand('%:p').
  • Loading branch information
myitcv committed Jan 30, 2020
1 parent 11bcb81 commit e5653c8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ vim ex 'set splitright'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(5,18)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[getcurpos()[1], getcurpos()[2]]'
stdout '^\Q[3,7]\E$'
vim ex 'GOVIMGoToPrevDef'
vim expr 'bufname(\"\")'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/p.go"\E$'
vim expr '[getcurpos()[1], getcurpos()[2]]'
stdout '^\Q[5,18]\E$'
Expand Down
23 changes: 6 additions & 17 deletions cmd/govim/testdata/scenario_default/go_to_def_newtab.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ vim ex 'set splitright'
# Definition in unopened buffer; newtab
vim ex 'set switchbuf=newtab'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(5,17)'
vim ex 'call cursor(5,20)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout '^\Q"'$WORK'/q/q.go"\E$'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,2]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
Expand All @@ -27,24 +27,13 @@ module mod.com/p

go 1.12

replace mod.com/q => ./q

require example.com/blah v1.0.0
-- p.go --
package p

import "mod.com/q"
import "example.com/blah"

const Name1 = q.Name
const Name1 = blah.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"
12 changes: 1 addition & 11 deletions cmd/govim/testdata/scenario_default/go_to_def_same_file.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vim ex 'set splitright'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(6,15)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/p.go"\E$'
vim expr '[getcurpos()[1], getcurpos()[2]]'
stdout '^\Q[8,7]\E$'
Expand All @@ -33,13 +33,3 @@ const Name1 = q.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"
23 changes: 6 additions & 17 deletions cmd/govim/testdata/scenario_default/go_to_def_split.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ vim ex 'set splitright'
# Definition in unopened buffer; split
vim ex 'set switchbuf=split'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(5,17)'
vim ex 'call cursor(5,20)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout '^\Q"'$WORK'/q/q.go"\E$'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[2,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
Expand All @@ -27,24 +27,13 @@ module mod.com/p

go 1.12

replace mod.com/q => ./q

require example.com/blah v1.0.0
-- p.go --
package p

import "mod.com/q"
import "example.com/blah"

const Name1 = q.Name
const Name1 = blah.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"
4 changes: 2 additions & 2 deletions cmd/govim/testdata/scenario_default/go_to_def_std_lib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ vim ex 'set splitright'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(5,18)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
vim expr 'expand(''%:p'')'

# Check that we end up somewhere in GOROOT/src/time
stdout '^\Q"'$GOROOT'/src/time/'

# Now jump back and check we are where we started
vim ex 'GOVIMGoToPrevDef'
vim expr 'bufname(\"\")'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/p.go"\E$'
vim expr '[getcurpos()[1], getcurpos()[2]]'
stdout '^\Q[5,18]\E$'
Expand Down
28 changes: 10 additions & 18 deletions cmd/govim/testdata/scenario_default/go_to_def_useopen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
vim ex 'set splitbelow'
vim ex 'set splitright'

# Ensure the module cache is populated
go mod download

# Definition in an open window in current tab
vim ex 'set switchbuf=useopen'
vim ex 'e '$WORK/q/q.go
vim ex 'e '$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,1]\E$'
vim ex 'split '$WORK/p.go
vim ex 'call cursor(5,17)'
vim ex 'call cursor(5,20)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout '^\Q"'$WORK'/q/q.go"\E$'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
Expand All @@ -28,24 +31,13 @@ module mod.com/p

go 1.12

replace mod.com/q => ./q

require example.com/blah v1.0.0
-- p.go --
package p

import "mod.com/q"
import "example.com/blah"

const Name1 = q.Name
const Name1 = blah.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"
28 changes: 10 additions & 18 deletions cmd/govim/testdata/scenario_default/go_to_def_usetab.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
vim ex 'set splitbelow'
vim ex 'set splitright'

# Ensure the module cache is populated
go mod download

# Definition in an open window in non-current tab
vim ex 'set switchbuf=usetab'
vim ex 'e '$WORK/q/q.go
vim ex 'e '$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,1]\E$'
vim ex 'tabnew '$WORK/p.go
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,2]\E$'
vim ex 'call cursor(5,17)'
vim ex 'call cursor(5,20)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout '^\Q"'$WORK'/q/q.go"\E$'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[1,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
Expand All @@ -30,24 +33,13 @@ module mod.com/p

go 1.12

replace mod.com/q => ./q

require example.com/blah v1.0.0
-- p.go --
package p

import "mod.com/q"
import "example.com/blah"

const Name1 = q.Name
const Name1 = blah.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"
23 changes: 6 additions & 17 deletions cmd/govim/testdata/scenario_default/go_to_def_vsplit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ vim ex 'set splitright'
# Definition in unopened buffer; vsplit
vim ex 'set switchbuf=vsplit'
vim ex 'e '$WORK/p.go
vim ex 'call cursor(5,17)'
vim ex 'call cursor(5,20)'
vim ex 'GOVIMGoToDef'
vim expr 'bufname(\"\")'
stdout '^\Q"'$WORK'/q/q.go"\E$'
vim expr 'expand(''%:p'')'
stdout '^\Q"'$WORK'/.home/gopath/pkg/mod/example.com/blah@v1.0.0/main.go"\E$'
vim expr '[winnr(), tabpagenr()]'
stdout '^\Q[2,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
Expand All @@ -27,24 +27,13 @@ module mod.com/p

go 1.12

replace mod.com/q => ./q

require example.com/blah v1.0.0
-- p.go --
package p

import "mod.com/q"
import "example.com/blah"

const Name1 = q.Name
const Name1 = blah.Name
const Name2 = SameFile

const SameFile = "samefile"

-- q/go.mod --
module mod.com/q

go 1.12

-- q/q.go --
package q

const Name = "package q"

0 comments on commit e5653c8

Please sign in to comment.