-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain_test.go
More file actions
48 lines (41 loc) · 948 Bytes
/
Copy pathmain_test.go
File metadata and controls
48 lines (41 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"os"
"testing"
"time"
)
// vscode-languageclient auto-appends the -stdio flag when using TransportKind.stdio,
// so bqls must accept and ignore it.
func TestRun_StdioFlag(t *testing.T) {
origStdin := os.Stdin
origStdout := os.Stdout
t.Cleanup(func() {
os.Stdin = origStdin
os.Stdout = origStdout
})
inR, inW, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
inW.Close() // trigger an immediate EOF so the jsonrpc2 connection disconnects right away
outR, outW, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { outR.Close() })
os.Stdin = inR
os.Stdout = outW
done := make(chan exitCode, 1)
go func() {
done <- run([]string{"-stdio"})
}()
select {
case got := <-done:
outW.Close()
if got != exitCodeOK {
t.Errorf("run([]string{\"-stdio\"}) = %v, want %v", got, exitCodeOK)
}
case <-time.After(5 * time.Second):
t.Fatal("run did not return within timeout")
}
}