Skip to content

Commit 442d6be

Browse files
committed
gopls/internal/test/marker: document named parameters
Update our marker test documentation to discuss the recently added support for named parameters. Also, make a few other superficial doc improvements (notably, adding missing documentation for -{min,max}_go_command). Change-Id: Ib210443fc4afbb1420345a17ec5b1eed75687c04 Reviewed-on: https://go-review.googlesource.com/c/tools/+/630138 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent ae39b13 commit 442d6be

File tree

1 file changed

+33
-20
lines changed
  • gopls/internal/test/marker

1 file changed

+33
-20
lines changed

gopls/internal/test/marker/doc.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,26 @@ Use this command to run the tests, from the gopls module:
1010
1111
$ go test ./internal/test/marker [-update]
1212
13-
A marker test uses the '//@' marker syntax of the x/tools/internal/expect package
14-
to annotate source code with various information such as locations and
15-
arguments of LSP operations to be executed by the test. The syntax following
16-
'@' is parsed as a comma-separated list of ordinary Go function calls, for
17-
example
13+
A marker test uses the '//@' syntax of the x/tools/internal/expect package to
14+
annotate source code with various information such as locations and arguments
15+
of LSP operations to be executed by the test. The syntax following '@' is
16+
parsed as a comma-separated list of Go-like function calls, which we refer to
17+
as 'markers' (or sometimes 'marks'), for example
1818
19-
//@foo(a, "b", 3),bar(0)
19+
//@ foo(a, "b", 3), bar(0)
2020
21-
and delegates to a corresponding function to perform LSP-related operations.
22-
See the Marker types documentation below for a list of supported markers.
21+
Unlike ordinary Go, the marker syntax also supports optional named arguments
22+
using the syntax name=value. If provided, named arguments must appear after all
23+
positional arguments, though their ordering with respect to other named
24+
arguments does not matter. For example
25+
26+
//@ foo(a, "b", d=4, c=3)
27+
28+
Each marker causes a corresponding function to be called in the test. Some
29+
markers are declarations; for example, @loc declares a name for a source
30+
location. Others have effects, such as executing an LSP operation and asserting
31+
that it behaved as expected. See the Marker types documentation below for the
32+
list of all supported markers.
2333
2434
Each call argument is converted to the type of the corresponding parameter of
2535
the designated function. The conversion logic may use the surrounding context,
@@ -39,26 +49,30 @@ There are several types of file within the test archive that are given special
3949
treatment by the test runner:
4050
4151
- "skip": the presence of this file causes the test to be skipped, with
42-
the file content used as the skip message.
52+
its content used as the skip message.
4353
4454
- "flags": this file is treated as a whitespace-separated list of flags
4555
that configure the MarkerTest instance. Supported flags:
46-
-{min,max}_go=go1.20 sets the {min,max}imum Go version for the test
47-
(inclusive)
48-
-cgo requires that CGO_ENABLED is set and the cgo tool is available
56+
57+
-{min,max}_go=go1.20 sets the {min,max}imum Go runtime version for the test
58+
(inclusive).
59+
-{min,max}_go_command=go1.20 sets the {min,max}imum Go command version for
60+
the test (inclusive).
61+
-cgo requires that CGO_ENABLED is set and the cgo tool is available.
4962
-write_sumfile=a,b,c instructs the test runner to generate go.sum files
5063
in these directories before running the test.
5164
-skip_goos=a,b,c instructs the test runner to skip the test for the
5265
listed GOOS values.
5366
-skip_goarch=a,b,c does the same for GOARCH.
54-
-ignore_extra_diags suppresses errors for unmatched diagnostics
5567
TODO(rfindley): using build constraint expressions for -skip_go{os,arch} would
5668
be clearer.
69+
-ignore_extra_diags suppresses errors for unmatched diagnostics
5770
-filter_builtins=false disables the filtering of builtins from
5871
completion results.
5972
-filter_keywords=false disables the filtering of keywords from
6073
completion results.
6174
-errors_ok=true suppresses errors for Error level log entries.
75+
6276
TODO(rfindley): support flag values containing whitespace.
6377
6478
- "settings.json": this file is parsed as JSON, and used as the
@@ -106,11 +120,10 @@ The following markers are supported within marker tests:
106120
107121
If end is set, the location is defined to be between start.Start and end.End.
108122
109-
Exactly one of edit, result, or err must be set.
110-
If edit is set, it is a golden reference to the edits resulting from the code action.
111-
If result is set, it is a golden reference to the full set of changed files
112-
resulting from the code action.
113-
If err is set, it is the code action error.
123+
Exactly one of edit, result, or err must be set. If edit is set, it is a
124+
golden reference to the edits resulting from the code action. If result is
125+
set, it is a golden reference to the full set of changed files resulting
126+
from the code action. If err is set, it is the code action error.
114127
115128
- codelens(location, title): specifies that a codelens is expected at the
116129
given location, with given title. Must be used in conjunction with
@@ -131,8 +144,8 @@ The following markers are supported within marker tests:
131144
The specified location must match the start position of the diagnostic,
132145
but end positions are ignored unless exact=true.
133146
134-
TODO(adonovan): in the older marker framework, the annotation asserted
135-
two additional fields (source="compiler", kind="error"). Restore them using
147+
TODO(adonovan): in the older marker framework, the annotation asserted two
148+
additional fields (source="compiler", kind="error"). Restore them using
136149
optional named arguments.
137150
138151
- def(src, dst location): performs a textDocument/definition request at

0 commit comments

Comments
 (0)