Skip to content

Commit cb49437

Browse files
committed
Improves diagnostic generation tests
1 parent e1d1a31 commit cb49437

File tree

7 files changed

+134
-2
lines changed

7 files changed

+134
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Added
88

9+
- Added multiple unittests for diagnostic messages
910
- Added `pre-commit` hook to the project
1011
([#106](https://github.com/gnikit/fortls/issues/106))
1112
- Added Code of Conduct

test/test_server_diagnostics.py

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ def test_contains():
262262
"message": "CONTAINS statement without enclosing scope",
263263
"severity": 1,
264264
},
265+
{
266+
"range": {
267+
"start": {"line": 8, "character": 0},
268+
"end": {"line": 8, "character": 0},
269+
},
270+
"message": "Subroutine/Function definition before CONTAINS statement",
271+
"severity": 1,
272+
},
265273
]
266274

267275

@@ -277,10 +285,109 @@ def test_visibility():
277285
assert results[1]["diagnostics"] == [
278286
{
279287
"range": {
280-
"start": {"line": 3, "character": 0},
281-
"end": {"line": 3, "character": 0},
288+
"start": {"line": 5, "character": 0},
289+
"end": {"line": 5, "character": 0},
282290
},
283291
"message": "Visibility statement without enclosing scope",
284292
"severity": 1,
293+
},
294+
{
295+
"range": {
296+
"start": {"line": 1, "character": 8},
297+
"end": {"line": 1, "character": 26},
298+
},
299+
"message": 'Module "nonexisting_module" not found in project',
300+
"severity": 3,
301+
},
302+
{
303+
"range": {
304+
"start": {"line": 3, "character": 8},
305+
"end": {"line": 3, "character": 11},
306+
},
307+
"message": 'Module "mod" not found in project',
308+
"severity": 3,
309+
},
310+
{
311+
"range": {
312+
"start": {"line": 2, "character": 4},
313+
"end": {"line": 2, "character": 12},
314+
},
315+
"message": "USE statements after IMPLICIT statement",
316+
"severity": 1,
317+
},
318+
]
319+
320+
321+
def test_import():
322+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
323+
# Test module procedure in submodules importing scopes
324+
file_path = str(test_dir / "diag" / "test_import.f90")
325+
string += write_rpc_notification(
326+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
327+
)
328+
errcode, results = run_request(string)
329+
assert errcode == 0
330+
assert results[1]["diagnostics"] == [
331+
{
332+
"range": {
333+
"start": {"line": 1, "character": 0},
334+
"end": {"line": 1, "character": 0},
335+
},
336+
"message": "IMPORT statement outside of interface",
337+
"severity": 1,
338+
}
339+
]
340+
341+
342+
def test_variable():
343+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
344+
# Test module procedure in submodules importing scopes
345+
file_path = str(test_dir / "diag" / "test_variable.f90")
346+
string += write_rpc_notification(
347+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
348+
)
349+
errcode, results = run_request(string)
350+
assert errcode == 0
351+
assert results[1]["diagnostics"] == [
352+
{
353+
"range": {
354+
"start": {"line": 4, "character": 19},
355+
"end": {"line": 4, "character": 22},
356+
},
357+
"message": 'Variable "val" masks variable in parent scope',
358+
"severity": 2,
359+
"relatedInformation": [
360+
{
361+
"location": {
362+
"uri": path_to_uri(str(file_path)),
363+
"range": {
364+
"start": {"line": 1, "character": 0},
365+
"end": {"line": 1, "character": 0},
366+
},
367+
},
368+
"message": "First declaration",
369+
}
370+
],
371+
}
372+
]
373+
374+
375+
def test_function():
376+
string = write_rpc_request(1, "initialize", {"rootPath": str(test_dir)})
377+
# Test module procedure in submodules importing scopes
378+
file_path = str(test_dir / "diag" / "test_function.f90")
379+
string += write_rpc_notification(
380+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
381+
)
382+
errcode, results = run_request(string)
383+
assert errcode == 0
384+
assert results[1]["diagnostics"] == [
385+
{
386+
"range": {
387+
"start": {"line": 3, "character": 31},
388+
"end": {"line": 3, "character": 34},
389+
},
390+
"message": 'Variable "bar" with INTENT keyword not found in argument list',
391+
"severity": 1,
285392
}
286393
]

test/test_source/diag/test_contains.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ program test_contains
44
contains
55
end program test_contains
66
contains
7+
8+
module test_contains2
9+
subroutine foo() ! Err: before contains
10+
end subroutine
11+
contains
12+
end module test_contains2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module test_functions
2+
contains
3+
subroutine foo(val)
4+
integer, intent(in) :: bar
5+
end subroutine
6+
end module test_functions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
program test_diagnostic_import
2+
import some
3+
end program test_diagnostic_import
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
program test_variable
2+
integer :: val
3+
contains
4+
subroutine foo()
5+
integer :: val ! Warn: shadows parent
6+
end subroutine
7+
end program test_variable
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
program test_visibility
2+
use nonexisting_module ! Info: missing module
23
implicit none
4+
use mod
35
end program test_visibility
46
public

0 commit comments

Comments
 (0)