Skip to content

Commit

Permalink
tests: establish known quickfix buffer number in testscripts tests (#613
Browse files Browse the repository at this point in the history
)

Before a test script starts, the files from the txtar archive are
extracted. Then govim (and gopls) are started. In some rare cases, gopls
can end up calculating diagnostics before the testscript has started.
Which means that it can be the case, because govim and Vim are already up
and running, that the first buffer actually gets used for quickfix as
opposed to, say, the first file we open.

Instead below we copen then cclose in vimrc to reserve and establish a
definite buffer number for the quickfix window. The quickfix buffer will
always be buffer number 2 (because vim creates a buffer when opening, a
buffer that is then used for the first file we open).

Update various tests to reflect this change.
  • Loading branch information
myitcv committed Dec 8, 2019
1 parent bf03210 commit 55677e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/govim/testdata/scenario_default/go_to_def_newtab.txt
Expand Up @@ -16,7 +16,7 @@ stdout '^\Q[1,2]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
stdout '^\Q"[3, 7]"\E$'
vim expr 'winlayout()'
stdout '^\Q["leaf",1001]\E$'
stdout '^\Q["leaf",1003]\E$'
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/testdata/scenario_default/go_to_def_split.txt
Expand Up @@ -16,7 +16,7 @@ stdout '^\Q[2,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
stdout '^\Q"[3, 7]"\E$'
vim expr 'winlayout()'
stdout '^\Q["col",[["leaf",1000],["leaf",1001]]]\E$'
stdout '^\Q["col",[["leaf",1000],["leaf",1003]]]\E$'
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/testdata/scenario_default/go_to_def_vsplit.txt
Expand Up @@ -16,7 +16,7 @@ stdout '^\Q[2,1]\E$'
vim expr 'string([getcurpos()[1], getcurpos()[2]])'
stdout '^\Q"[3, 7]"\E$'
vim expr 'winlayout()'
stdout '^\Q["row",[["leaf",1000],["leaf",1001]]]\E$'
stdout '^\Q["row",[["leaf",1000],["leaf",1003]]]\E$'
# Disabled pending resolution to https://github.com/golang/go/issues/34103
# errlogmatch -count=0 'LogMessage callback: &protocol\.LogMessageParams\{Type:(1|2), Message:".*'

Expand Down
4 changes: 2 additions & 2 deletions cmd/govim/testdata/scenario_default/signs_existing_diags.txt
Expand Up @@ -4,7 +4,7 @@ vim ex 'e main.go'
errlogmatch -wait 30s -start 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/main.go
errlogmatch -wait 30s -start 'PublishDiagnostics callback: &protocol.PublishDiagnosticsParams{\n\S+:\s+URI:\s+"file://'$WORK/other.go
vim ex 'e other.go'
errlogmatch -wait 30s 'sendJSONMsg: \[0,\[\d+,"call","s:batchCall",\[\["call","s:mustBeZero","sign_unplace","govim"\],\["call","s:mustNothing","sign_placelist",\[.*\{"buffer":2,"group":"govim"'
errlogmatch -wait 30s 'sendJSONMsg: \[0,\[\d+,"call","s:batchCall",\[\["call","s:mustBeZero","sign_unplace","govim"\],\["call","s:mustNothing","sign_placelist",\[.*\{"buffer":3,"group":"govim"'
vim -indent expr 'sign_getplaced(\"other.go\", {\"group\": \"*\"})'
! stderr .+
cmp stdout placed.golden
Expand Down Expand Up @@ -33,7 +33,7 @@ func foo() {
-- placed.golden --
[
{
"bufnr": 2,
"bufnr": 3,
"signs": [
{
"group": "govim",
Expand Down
28 changes: 26 additions & 2 deletions testdriver/testdriver.go
Expand Up @@ -131,8 +131,32 @@ func NewTestDriver(c *Config) (*TestDriver, error) {
return nil, fmt.Errorf("need to add vimrc behaviour for flavour %v", flav)
}

if err := copyFile(dstVimrc, srcVimrc); err != nil {
return nil, fmt.Errorf("failed to copy %v to %v: %v", srcVimrc, dstVimrc, err)
// We use the minimal srcVimrc, augmented with some testdriver specific
// commands.
//
// Before a test script starts, the files from the txtar archive are
// extracted. Then govim (and gopls) are started. In some rare cases, gopls
// can end up calculating diagnostics before the testscript has started.
// Which means that it can be the case, because govim and Vim are already up
// and running, that the first buffer actually gets used for quickfix as
// opposed to, say, the first file we open.
//
// Instead below we copen then cclose in vimrc to reserve and establish a
// definite buffer number for the quickfix window. The quickfix buffer will
// always be buffer number 2 (vim creates a buffer when opening, copen then
// creates a new window and buffer, the original buffer created when opening
// vim gets used for the first file we open, say)
vimrcBytes, err := ioutil.ReadFile(srcVimrc)
if err != nil {
return nil, fmt.Errorf("failed to read from src vimrc %v: %v", srcVimrc, err)
}
vimrc := bytes.NewBuffer(vimrcBytes)
vimrc.WriteString("\n")
vimrc.WriteString("copen\n")
vimrc.WriteString("cclose\n")

if err := ioutil.WriteFile(dstVimrc, vimrc.Bytes(), 0666); err != nil {
return nil, fmt.Errorf("failed to write to dst vimrc %v: %v", dstVimrc, err)
}

res.govimListener = gl
Expand Down

0 comments on commit 55677e1

Please sign in to comment.