aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/list_json_fields.txt
blob: 9b8edc6d7f6029e8297eb315c732cdb9337b3ba8 (plain)
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
49
50
51
52
53
54
55
56
57
# Test using -json flag to specify specific fields.

# Test -json produces "full" output by looking for multiple fields present.
go list -json .
stdout '"Name": "a"'
stdout '"Stale": true'
# Same thing for -json=true
go list -json=true .
stdout '"Name": "a"'
stdout '"Stale": true'

# Test -json=false produces non-json output.
go list -json=false
cmp stdout want-non-json.txt

# Test -json=<field> keeps only that field.
go list -json=Name
cmp stdout want-json-name.txt

# Test -json=<field> with multiple fields.
go list -json=ImportPath,Name,GoFiles,Imports
cmp stdout want-json-multiple.txt

# Test -json=<field> with Deps outputs the Deps field.
go list -json=Deps
stdout '"Deps": \['
stdout '"errors",'

-- go.mod --
module example.com/a

go 1.18
-- a.go --
package a

import "fmt"

func F() {
    fmt.Println("hey there")
}
-- want-non-json.txt --
example.com/a
-- want-json-name.txt --
{
	"Name": "a"
}
-- want-json-multiple.txt --
{
	"ImportPath": "example.com/a",
	"Name": "a",
	"GoFiles": [
		"a.go"
	],
	"Imports": [
		"fmt"
	]
}