Skip to content

Commit

Permalink
tests: fix diagnostic assertions in our tests
Browse files Browse the repository at this point in the history
This uber PR contains a number of changes to our testscript tests:

* Drop all errlogmatch's looking for assertions where we really should
  not need them. Historically we needed these because the threading
  model of gopls was a bit broken. i.e. despite us notifying of a change
  to a file, unless we waited for diagnostics to be available then we
  couldn't guarantee that, for example, completions would be correct
* Fix up all go.mod files to include go directives so that we don't fall
  foul of golang/go#36144
* Where we do require errlogmatch's, make sure we follow the existing
  semantics per golang/go#36243 and
  golang/go#36340
* Fix up some scripts so that we don't have initial errors in the file
  and hence don't need to soak up initial diagnostics
* Use sleep $DEFAULT_ERRLOGMATCH_WAIT where we expect there to be no
  diagnostic errors
* Only use errlogmatch on diagnostic publications where we need to
  know that a file has been opened, e.g. file watching, or where we
  need to soak up initial diagnostic notifications (see
  golang/go#36243)
* Move all commented-out errlogmatch commands matching on the number of
  errors to the end of each script. We still can't enable these

Add some initial tests that help to verify our expectations around
diagnostics being published by gopls.

Set GOPATH and GOCACHE consistently for the install testscript scripts
to speed them up.

Call t.Parallel in a couple of places to speed up the entire test run.

Add a test (that is skipped) which capture the essence of
golang/go#36144.
  • Loading branch information
myitcv committed Jan 6, 2020
1 parent 78caf5a commit 6cef7ca
Show file tree
Hide file tree
Showing 54 changed files with 313 additions and 150 deletions.
8 changes: 5 additions & 3 deletions cmd/govim/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ func TestScripts(t *testing.T) {
"GONOSUMDB=*",
"HOME="+home,
"PLUGIN_PATH="+govimPath,
"CURRENT_GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
)
if workdir != "" {
e.Vars = append(e.Vars, "GOVIM_LOGFILE_TMPL=%v")
Expand Down Expand Up @@ -244,6 +243,7 @@ func TestScripts(t *testing.T) {
}

func TestInstallScripts(t *testing.T) {
t.Parallel()
if os.Getenv(EnvInstallScripts) != "true" {
t.Skipf("Skipping install scripts; %v != true", EnvInstallScripts)
}
Expand All @@ -264,7 +264,8 @@ func TestInstallScripts(t *testing.T) {
Setup: func(e *testscript.Env) error {
e.Vars = append(e.Vars,
"PLUGIN_PATH="+govimPath,
"CURRENT_GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
"GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
"GOCACHE="+strings.TrimSpace(runCmd(t, "go", "env", "GOCACHE")),
testsetup.EnvLoadTestAPI+"=true",
)
return nil
Expand Down Expand Up @@ -292,7 +293,8 @@ func TestInstallScripts(t *testing.T) {
e.Vars = append(e.Vars,
"PATH="+path,
"PLUGIN_PATH="+govimPath,
"CURRENT_GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
"GOPATH="+strings.TrimSpace(runCmd(t, "go", "env", "GOPATH")),
"GOCACHE="+strings.TrimSpace(runCmd(t, "go", "env", "GOCACHE")),
string(config.EnvVarUseGoplsFromPath)+"=true",
testsetup.EnvLoadTestAPI+"=true",
)
Expand Down
1 change: 0 additions & 1 deletion cmd/govim/testdata/install/install_pathogen.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[!net] skip

env HOME=$WORK/home
env GOPATH=$CURRENT_GOPATH

exec git clone -q $PLUGIN_PATH $HOME/.vim/bundle/govim

Expand Down
1 change: 0 additions & 1 deletion cmd/govim/testdata/install/install_vim-plug.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[!net] skip

env HOME=$WORK/home
env GOPATH=$CURRENT_GOPATH

exec git clone -q $PLUGIN_PATH $WORK/plugin

Expand Down
1 change: 0 additions & 1 deletion cmd/govim/testdata/install/install_vim8_packages.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[!net] skip

env HOME=$WORK/home
env GOPATH=$CURRENT_GOPATH

exec git clone -q $PLUGIN_PATH $HOME/.vim/pack/plugins/start/govim

Expand Down
1 change: 0 additions & 1 deletion cmd/govim/testdata/install/install_vundle.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[!net] skip

env HOME=$WORK/home
env GOPATH=$CURRENT_GOPATH

exec git clone -q $PLUGIN_PATH $WORK/plugin

Expand Down
29 changes: 12 additions & 17 deletions cmd/govim/testdata/scenario_caseinsensitivecompletion/complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,66 @@
# already has the relevant import required for the completion.

vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go

# lower completed from lo
vim ex 'call cursor(7,1)'
vim normal Slo
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lower
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER completed from UP
vim ex 'call cursor(7,1)'
vim normal SUP
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.upper
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# lower completed from LO
vim ex 'call cursor(7,1)'
vim normal SLO
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lower
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER completed from up
vim ex 'call cursor(7,1)'
vim normal Sup
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.upper

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
# errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

go 1.12
-- main.go --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
//
}
-- main.go.lower --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
lower
}
-- main.go.upper --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
UPPER
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# Test that deep fuzzy complete does not work.

cp main.go.orig main.go
cp main.go main.go.orig
vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go
vim ex 'call cursor(11,1)'
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.orig

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
# errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

-- main.go.orig --
go 1.12
-- main.go --
package main

func main() {
Expand Down
41 changes: 18 additions & 23 deletions cmd/govim/testdata/scenario_casesensitivecompletion/complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,89 +2,84 @@
# already has the relevant import required for the completion.

vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go

# lower from lo
vim ex 'call cursor(7,1)'
vim normal Slo
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lowercomplete
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER from UP
vim ex 'call cursor(7,1)'
vim normal SUP
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.uppercomplete
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# lower from LO
vim ex 'call cursor(7,1)'
vim normal SLO
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.lowermiss
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# UPPER from up
vim ex 'call cursor(7,1)'
vim normal Sup
vim ex 'execute \"normal A\\<C-X>\\<C-O>\"'
vim ex 'w'
cmp main.go main.go.uppermiss

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
# errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

go 1.12
-- main.go --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
//
}
-- main.go.lowercomplete --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
lower
}
-- main.go.uppercomplete --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
UPPER
}
-- main.go.lowermiss --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
LO
}
-- main.go.uppermiss --
package main

func main() {
var lower int
var UPPER int
var lower int
var UPPER int

func main() {
up
}
5 changes: 3 additions & 2 deletions cmd/govim/testdata/scenario_completeunimported/complete.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Test that completing of unimported std library packages works.

vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go

# lower from lo
vim ex 'call cursor(4,1)'
vim normal Sfmt.Pr
vim ex 'execute \"normal A\\<C-X>\\<C-O>\\<C-N>\\<C-N>\"'
vim ex 'noau w'
cmp main.go main.go.golden

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
# errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

go 1.12
-- main.go --
package main

Expand Down
22 changes: 0 additions & 22 deletions cmd/govim/testdata/scenario_default/bad_complete.txt

This file was deleted.

26 changes: 26 additions & 0 deletions cmd/govim/testdata/scenario_default/bug_gopls_36144.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# A test that causes a failure similar to the scenario described by:
# https://github.com/golang/go/issues/36144. This is marked as "skip" because
# otherwise we would continually break the govim build. The issue has been
# reported, its implications and severity are known, so there is no value in
# having a red CI build.
#
# What's critical here is that the go.mod file is incomplete; it is missing
# the go directive. Hence on the initial load that file gets changed, which
# triggers a file watcher event in govim, which triggers a recalculation of
# diagnostics when the go.mod file is changed, which sometimes causes a
# cancellation of the initial diagnostics for the package, or the diagnostics
# that are sent when a file is opened.

skip 'Known issue reported as https://github.com/golang/go/issues/36144'

vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go

-- go.mod --
module mod.com

-- main.go --
package main

func main() {
}
5 changes: 2 additions & 3 deletions cmd/govim/testdata/scenario_default/command.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ vim ex 'GOVIMHello'
vim expr 'v:statusmsg'
stdout '^\Q"Hello from command"\E$'
! stderr .+
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

# Test that we can pass args
vim ex 'GOVIMHello goodbye'
Expand All @@ -17,5 +15,6 @@ vim ex 'GOVIMHello goodbye'
vim expr 'v:statusmsg'
stdout '^\Q"Hello from command; special note: goodbye"\E$'
! stderr .+

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
# errlogmatch -start -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'
3 changes: 2 additions & 1 deletion cmd/govim/testdata/scenario_default/complete.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
# already has the relevant import required for the completion.

vim ex 'e main.go'
errlogmatch 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go
vim ex 'call cursor(11,17)'
vim ex 'call feedkeys(\"i\\<C-X>\\<C-O>\\<C-N>\\<ESC>\", \"xt\")'
vim ex 'w'
cmp main.go main.go.golden

# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

-- go.mod --
module mod.com

go 1.12
-- main.go --
package main

Expand Down
Loading

0 comments on commit 6cef7ca

Please sign in to comment.