forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verible-verilog-ls_test.sh
executable file
·183 lines (158 loc) · 5.67 KB
/
verible-verilog-ls_test.sh
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# Copyright 2021 The Verible Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -u
[[ "$#" == 2 ]] || {
echo "Expecting 2 positional arguments: lsp-server json-rpc-expect"
exit 1
}
LSP_SERVER="$(rlocation ${TEST_WORKSPACE}/$1)"
JSON_RPC_EXPECT="$(rlocation ${TEST_WORKSPACE}/$2)"
TMP_IN=${TEST_TMPDIR:-/tmp/}/test-lsp-in.txt
JSON_EXPECTED=${TEST_TMPDIR:-/tmp/}/test-lsp-json-expect.txt
MSG_OUT=${TEST_TMPDIR:-/tmp/}/test-lsp-out-msg.txt
# One message per line, converted by the awk script to header/body.
# Starting up server, sending two files, a file with a parse error and
# a file that parses, but has a EOF newline linting diagnostic.
#
# We get the diagnostic messages for both of these files, one reporting
# a syntax error, one reporting a lint error.
#
# We then modify the second file and edit the needed newline at the end of
# the buffer, and then get an update with zero diagnostic errors back.
#
# TODO: maybe this awk-script should be replaced with something that allows
# multi-line input with comment.
awk '/^{/ { printf("Content-Length: %d\r\n\r\n%s", length($0), $0)}' > ${TMP_IN} <<EOF
{"jsonrpc":"2.0", "id":1, "method":"initialize","params":null}
# Testing a file with syntax errors: this should output some diagnostic
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://syntaxerror.sv","text":"brokenfile\n"}}}
# A file with a lint error (no newline at EOF). Then editing it and watching diagnostic go away.
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://mini.sv","text":"module mini();\nendmodule"}}}
{"jsonrpc":"2.0", "id":10, "method":"textDocument/codeAction","params":{"textDocument":{"uri":"file://mini.sv"},"range":{"start":{"line":0,"character":0},"end":{"line":2,"character":0}}}}
{"jsonrpc":"2.0","method":"textDocument/didChange","params":{"textDocument":{"uri":"file://mini.sv"},"contentChanges":[{"range":{"start":{"character":9,"line":1},"end":{"character":9,"line":1}},"text":"\n"}]}}
{"jsonrpc":"2.0", "id":11, "method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file://mini.sv"}}}
{"jsonrpc":"2.0","method":"textDocument/didClose","params":{"textDocument":{"uri":"file://mini.sv"}}}
# Attempt to query closed file should gracefully return an empty response.
{"jsonrpc":"2.0", "id":12, "method":"textDocument/documentSymbol","params":{"textDocument":{"uri":"file://mini.sv"}}}
# Highlight, but only symbols not highlighting 'assign' non-symbol.
{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"file://sym.sv","text":"module sym();\nassign a=1;assign b=a+1;endmodule\n"}}}
{"jsonrpc":"2.0", "id":20, "method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file://sym.sv"},"position":{"line":1,"character":7}}}
{"jsonrpc":"2.0", "id":21, "method":"textDocument/documentHighlight","params":{"textDocument":{"uri":"file://sym.sv"},"position":{"line":1,"character":2}}}
{"jsonrpc":"2.0", "id":100, "method":"shutdown","params":{}}
EOF
# TODO: change json rpc expect to allow comments in the input.
cat > "${JSON_EXPECTED}" <<EOF
[
{
"json_contains": {
"id":1,
"result": {
"serverInfo": {"name" : "Verible Verilog language server."}
}
}
},
{
"json_contains": {
"method":"textDocument/publishDiagnostics",
"params": {
"uri": "file://syntaxerror.sv",
"diagnostics":[{"message":"syntax error"}]
}
}
},
{
"json_contains": {
"method":"textDocument/publishDiagnostics",
"params": {
"uri": "file://mini.sv",
"diagnostics":[{"message":"File must end with a newline."}]
}
}
},
{
"json_contains": {
"id":10,
"result": [
{"edit": {"changes": {"file://mini.sv":[{"newText":"\n"}]}}}
]
}
},
{
"json_contains": {
"method":"textDocument/publishDiagnostics",
"params": {
"uri": "file://mini.sv",
"diagnostics":[]
}
}
},
{
"json_contains": {
"id":11,
"result": [
{"kind":6, "name":"mini"}
]
}
},
{
"json_contains":{
"id":12 ,
"result": []
}
},
{
"json_contains": {
"method":"textDocument/publishDiagnostics",
"params": {
"uri": "file://sym.sv",
"diagnostics":[]
}
}
},
{
"json_contains":{
"id":20,
"result": [
{"range":{"start":{"line":1, "character": 7}, "end":{"line":1, "character": 8}}},
{"range":{"start":{"line":1, "character":20}, "end":{"line":1, "character":21}}}
]
}
},
{
"json_contains":{
"id":21,
"result": []
}
},
{
"json_contains": { "id":100 }
}
]
EOF
"${LSP_SERVER}" < ${TMP_IN} 2> "${MSG_OUT}" \
| ${JSON_RPC_EXPECT} ${JSON_EXPECTED}
JSON_RPC_EXIT=$?
echo "-- stderr messages --"
cat ${MSG_OUT}
if [ $JSON_RPC_EXIT -ne 0 ]; then
# json-rpc-expect outputs the entry, where the mismatch occured, in exit code
echo "Exit code of json rpc expect; first error at $JSON_RPC_EXIT"
exit 1
fi
grep "shutdown request" "${MSG_OUT}" > /dev/null
if [ $? -ne 0 ]; then
echo "Didn't get shutdown feedback"
exit 1
fi