Skip to content

Commit 8fdc98f

Browse files
committed
Improves coverage
- Adds `WHERE` block tests - Adds max line and max comment line diagnostic tests - Adds semicolon tests - Adds `ENUM` tests - Disables logging for debug calls and Python 2
1 parent 8d512de commit 8fdc98f

File tree

8 files changed

+125
-0
lines changed

8 files changed

+125
-0
lines changed

.coveragerc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
[run]
22
dynamic_context = test_function
33
omit = fortls/__init__.py
4+
5+
[report]
6+
exclude_lines =
7+
if debug:
8+
log.debug
9+
except:
10+
if not PY3K:

CHANGELOG.md

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

77
- Added coverage metric for Codecov
8+
- Added coverage for `WHERE`, `ENUM`, max line/comment diagnostics and multilines
89

910
## 2.0.1
1011

test/test_server.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ def check_return(result_dict):
4949
check_return(results[0])
5050

5151

52+
def test_logger():
53+
"""Test the logger"""
54+
string = write_rpc_request(1, "initialize", {"rootPath": test_dir})
55+
errcode, results = run_request(string, " --debug_log")
56+
assert errcode == 0
57+
assert results[1]["type"] == 3
58+
assert results[1]["message"] == "FORTLS debugging enabled"
59+
60+
5261
def test_open():
5362
string = write_rpc_request(1, "initialize", {"rootPath": test_dir})
5463
file_path = os.path.join(test_dir, "subdir", "test_free.f90")
@@ -178,13 +187,15 @@ def check_return(result_array):
178187
objs = (
179188
["test", 6, 7],
180189
["test_abstract", 2, 0],
190+
["test_enum", 2, 0],
181191
["test_external", 2, 0],
182192
["test_forall", 2, 0],
183193
["test_free", 2, 0],
184194
["test_gen_type", 5, 1],
185195
["test_generic", 2, 0],
186196
["test_inherit", 2, 0],
187197
["test_int", 2, 0],
198+
["test_lines", 2, 0],
188199
["test_mod", 2, 0],
189200
["test_nonint_mod", 2, 0],
190201
["test_preproc_keywords", 2, 0],
@@ -193,12 +204,14 @@ def check_return(result_array):
193204
["test_rename_sub", 6, 9],
194205
["test_select", 2, 0],
195206
["test_select_sub", 6, 16],
207+
["test_semicolon", 2, 0],
196208
["test_sig_Sub", 6, 67],
197209
["test_str1", 13, 5],
198210
["test_str2", 13, 5],
199211
["test_sub", 6, 8],
200212
["test_use_ordering", 2, 9],
201213
["test_vis_mod", 2, 0],
214+
["test_where", 2, 0],
202215
)
203216
assert len(result_array) == len(objs)
204217
for i, obj in enumerate(objs):
@@ -657,8 +670,37 @@ def check_return(results, ref_results):
657670
string += write_rpc_notification(
658671
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
659672
)
673+
# Test where blocks
674+
file_path = os.path.join(test_dir, "diag", "test_where.f90")
675+
string += write_rpc_notification(
676+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
677+
)
678+
# Test where semicolon (multi-line)
679+
file_path = os.path.join(test_dir, "diag", "test_semicolon.f90")
680+
string += write_rpc_notification(
681+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
682+
)
683+
# Test ENUM block
684+
file_path = os.path.join(test_dir, "diag", "test_enum.f90")
685+
string += write_rpc_notification(
686+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
687+
)
660688
errcode, results = run_request(string)
661689
assert errcode == 0
690+
691+
# Load a different config file
692+
# Test long lines
693+
root = os.path.join(test_dir, "diag")
694+
string = write_rpc_request(1, "initialize", {"rootPath": root})
695+
file_path = os.path.join(test_dir, "diag", "test_lines.f90")
696+
string += write_rpc_notification(
697+
"textDocument/didOpen", {"textDocument": {"uri": file_path}}
698+
)
699+
file_path = os.path.join(test_dir, "diag", "conf_long_lines.json")
700+
errcode, res = run_request(string, f" --config {file_path}")
701+
assert errcode == 0
702+
results.extend(res[1:])
703+
662704
root = Path(test_dir)
663705
ref_results = [
664706
[],
@@ -709,12 +751,36 @@ def check_return(results, ref_results):
709751
],
710752
[],
711753
[],
754+
[],
755+
[],
756+
[],
757+
[
758+
{
759+
"range": {
760+
"start": {"line": 2, "character": 100},
761+
"end": {"line": 2, "character": 155},
762+
},
763+
"message": 'Line length exceeds "max_line_length" (100)',
764+
"severity": 2,
765+
},
766+
{
767+
"range": {
768+
"start": {"line": 3, "character": 100},
769+
"end": {"line": 3, "character": 127},
770+
},
771+
"message": (
772+
'Comment line length exceeds "max_comment_line_length" (100)'
773+
),
774+
"severity": 2,
775+
},
776+
],
712777
]
713778
check_return(results[1:], ref_results)
714779

715780

716781
if __name__ == "__main__":
717782
test_init()
783+
test_logger()
718784
test_open()
719785
test_change()
720786
test_symbols()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"max_line_length": 100,
3+
"max_comment_line_length": 100
4+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
program test_enum
2+
implicit none
3+
enum, bind(c)
4+
5+
enumerator :: red =1, blue, black =5
6+
enumerator yellow
7+
enumerator gold, silver, bronze
8+
enumerator :: purple
9+
enumerator :: pink, lavender
10+
11+
endenum
12+
end program test_enum
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test_lines
2+
implicit none
3+
character(len=123) :: val = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sodales imperdiet dolor, sit amet venenatis magna dictum id."
4+
! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam sodales imperdiet dolor, sit amet venenatis magna dictum id.
5+
end program test_lines
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program test_semicolon
2+
implicit none
3+
integer :: a = 1; character(len=1) :: v; real, parameter :: p = 0.1E-4
4+
print*, a; print*, p
5+
end program test_semicolon
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
program test_where
2+
implicit none
3+
! Example variables
4+
real:: A(5),B(5),C(5)
5+
A = 0.0
6+
B = 1.0
7+
C = [0.0, 4.0, 5.0, 10.0, 0.0]
8+
9+
! Oneliner
10+
WHERE(B .GT. 0.0) B = SUM(A, DIM=1)
11+
12+
! Simple where construct use
13+
where (C/=0)
14+
A=B/C
15+
elsewhere
16+
A=0.0
17+
end where
18+
19+
! Named where construct
20+
named: where (C/=0)
21+
A=B/C
22+
elsewhere
23+
A=0.0
24+
end where named
25+
end program test_where

0 commit comments

Comments
 (0)