Debian Codegraph @

gopls/internal/test/integration/watch/setting_test.go

raw symbols SCIP
1 // Copyright 2023 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package watch
6
7 import (
8 "fmt"
9 "testing"
10
11 . "golang.org/x/tools/gopls/internal/test/integration"
12 )
13
14 func TestSubdirWatchPatterns(t *testing.T) {
15 const files = `
16 -- go.mod --
17 module mod.test
18
19 go 1.18
20 -- subdir/subdir.go --
21 package subdir
22 `
23
24 tests := []struct {
25 clientName string
26 subdirWatchPatterns string
27 wantWatched bool
28 }{
29 {"other client", "on", true},
30 {"other client", "off", false},
31 {"other client", "auto", false},
32 {"Visual Studio Code", "auto", true},
33 }
34
35 for _, test := range tests {
36 t.Run(fmt.Sprintf("%s_%s", test.clientName, test.subdirWatchPatterns), func(t *testing.T) {
37 WithOptions(
38 ClientName(test.clientName),
39 Settings{
40 "subdirWatchPatterns": test.subdirWatchPatterns,
41 },
42 ).Run(t, files, func(t *testing.T, env *Env) {
43 var expectation Expectation
44 if test.wantWatched {
45 expectation = FileWatchMatching("subdir")
46 } else {
47 expectation = NoFileWatchMatching("subdir")
48 }
49 env.OnceMet(
50 InitialWorkspaceLoad,
51 expectation,
52 )
53 })
54 })
55 }
56 }
57
58 // This test checks that we surface errors for invalid subdir watch patterns,
59 // as the triple of ("off"|"on"|"auto") may be confusing to users inclined to
60 // use (true|false) or some other truthy value.
61 func TestSubdirWatchPatterns_BadValues(t *testing.T) {
62 tests := []struct {
63 badValue any
64 wantMessage string
65 }{
66 {true, "invalid type bool (want string)"},
67 {false, "invalid type bool (want string)"},
68 {"yes", `invalid option "yes"`},
69 }
70
71 for _, test := range tests {
72 t.Run(fmt.Sprint(test.badValue), func(t *testing.T) {
73 WithOptions(
74 Settings{
75 "subdirWatchPatterns": test.badValue,
76 },
77 ).Run(t, "", func(t *testing.T, env *Env) {
78 env.OnceMet(
79 InitialWorkspaceLoad,
80 ShownMessage(test.wantMessage),
81 )
82 })
83 })
84 }
85 }