Skip to content

Commit 2acb2e6

Browse files
findleyrgopherbot
authored andcommitted
gopls/internal/test/marker: minor clean up of marker test doc
Change-Id: Id5fd8592a207e8ade8aeb1521730e4f35514824e Reviewed-on: https://go-review.googlesource.com/c/tools/+/549120 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Robert Findley <[email protected]>
1 parent 28b92af commit 2acb2e6

File tree

2 files changed

+44
-32
lines changed

2 files changed

+44
-32
lines changed

gopls/internal/test/marker/doc.go

+21-32
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,14 @@ which is extracted to a temporary directory. The relative path to the .txt
3333
file is used as the subtest name. The preliminary section of the file
3434
(before the first archive entry) is a free-form comment.
3535
36-
These tests were inspired by (and in many places copied from) a previous
37-
iteration of the marker tests built on top of the packagestest framework.
38-
Key design decisions motivating this reimplementation are as follows:
39-
- The old tests had a single global session, causing interaction at a
40-
distance and several awkward workarounds.
41-
- The old tests could not be safely parallelized, because certain tests
42-
manipulated the server options
43-
- Relatedly, the old tests did not have a logic grouping of assertions into
44-
a single unit, resulting in clusters of files serving clusters of
45-
entangled assertions.
46-
- The old tests used locations in the source as test names and as the
47-
identity of golden content, meaning that a single edit could change the
48-
name of an arbitrary number of subtests, and making it difficult to
49-
manually edit golden content.
50-
- The old tests did not hew closely to LSP concepts, resulting in, for
51-
example, each marker implementation doing its own position
52-
transformations, and inventing its own mechanism for configuration.
53-
- The old tests had an ad-hoc session initialization process. The integration
54-
test environment has had more time devoted to its initialization, and has a
55-
more convenient API.
56-
- The old tests lacked documentation, and often had failures that were hard
57-
to understand. By starting from scratch, we can revisit these aspects.
58-
5936
# Special files
6037
6138
There are several types of file within the test archive that are given special
6239
treatment by the test runner:
40+
6341
- "skip": the presence of this file causes the test to be skipped, with
6442
the file content used as the skip message.
43+
6544
- "flags": this file is treated as a whitespace-separated list of flags
6645
that configure the MarkerTest instance. Supported flags:
6746
-min_go=go1.20 sets the minimum Go version for the test;
@@ -78,21 +57,28 @@ treatment by the test runner:
7857
-filter_keywords=false disables the filtering of keywords from
7958
completion results.
8059
TODO(rfindley): support flag values containing whitespace.
60+
8161
- "settings.json": this file is parsed as JSON, and used as the
8262
session configuration (see gopls/doc/settings.md)
63+
8364
- "capabilities.json": this file is parsed as JSON client capabilities,
8465
and applied as an overlay over the default editor client capabilities.
8566
see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#clientCapabilities
8667
for more details.
68+
8769
- "env": this file is parsed as a list of VAR=VALUE fields specifying the
8870
editor environment.
71+
8972
- Golden files: Within the archive, file names starting with '@' are
9073
treated as "golden" content, and are not written to disk, but instead are
9174
made available to test methods expecting an argument of type *Golden,
9275
using the identifier following '@'. For example, if the first parameter of
9376
Foo were of type *Golden, the test runner would convert the identifier a
9477
in the call @foo(a, "b", 3) into a *Golden by collecting golden file
95-
data starting with "@a/".
78+
data starting with "@a/". As a special case, for tests that only need one
79+
golden file, the data contained in the file "@a" is indexed in the *Golden
80+
value by the empty string "".
81+
9682
- proxy files: any file starting with proxy/ is treated as a Go proxy
9783
file. If present, these files are written to a separate temporary
9884
directory and GOPROXY is set to file://<proxy directory>.
@@ -309,11 +295,14 @@ parameter type pairs:
309295
310296
Here is a complete example:
311297
298+
This test checks hovering over constants.
299+
312300
-- a.go --
313301
package a
314302
315303
const abc = 0x2a //@hover("b", "abc", abc),hover(" =", "abc", abc)
316-
-- @abc/hover.md --
304+
305+
-- @abc --
317306
```go
318307
const abc untyped int = 42
319308
```
@@ -329,13 +318,13 @@ The first argument holds the test context, including fake editor with open
329318
files, and sandboxed directory.
330319
331320
Argument converters translate the "b" and "abc" arguments into locations by
332-
interpreting each one as a regular expression and finding the location of
333-
its first match on the preceding portion of the line, and the abc identifier
334-
into a dictionary of golden content containing "hover.md". Then the
335-
hoverMarker method executes a textDocument/hover LSP request at the src
336-
position, and ensures the result spans "abc", with the markdown content from
337-
hover.md. (Note that the markdown content includes the expect annotation as
338-
the doc comment.)
321+
interpreting each one as a substring (or as a regular expression, if of the
322+
form re"a|b") and finding the location of its first occurrence on the preceding
323+
portion of the line, and the abc identifier into a the golden content contained
324+
in the file @abc. Then the hoverMarker method executes a textDocument/hover LSP
325+
request at the src position, and ensures the result spans "abc", with the
326+
markdown content from @abc. (Note that the markdown content includes the expect
327+
annotation as the doc comment.)
339328
340329
The next hover on the same line asserts the same result, but initiates the
341330
hover immediately after "abc" in the source. This tests that we find the

gopls/internal/test/marker/marker_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ func TestMain(m *testing.M) {
5959
// Test runs the marker tests from the testdata directory.
6060
//
6161
// See package documentation for details on how marker tests work.
62+
//
63+
// These tests were inspired by (and in many places copied from) a previous
64+
// iteration of the marker tests built on top of the packagestest framework.
65+
// Key design decisions motivating this reimplementation are as follows:
66+
// - The old tests had a single global session, causing interaction at a
67+
// distance and several awkward workarounds.
68+
// - The old tests could not be safely parallelized, because certain tests
69+
// manipulated the server options
70+
// - Relatedly, the old tests did not have a logic grouping of assertions into
71+
// a single unit, resulting in clusters of files serving clusters of
72+
// entangled assertions.
73+
// - The old tests used locations in the source as test names and as the
74+
// identity of golden content, meaning that a single edit could change the
75+
// name of an arbitrary number of subtests, and making it difficult to
76+
// manually edit golden content.
77+
// - The old tests did not hew closely to LSP concepts, resulting in, for
78+
// example, each marker implementation doing its own position
79+
// transformations, and inventing its own mechanism for configuration.
80+
// - The old tests had an ad-hoc session initialization process. The integration
81+
// test environment has had more time devoted to its initialization, and has a
82+
// more convenient API.
83+
// - The old tests lacked documentation, and often had failures that were hard
84+
// to understand. By starting from scratch, we can revisit these aspects.
6285
func Test(t *testing.T) {
6386
// The marker tests must be able to run go/packages.Load.
6487
testenv.NeedsGoPackages(t)

0 commit comments

Comments
 (0)