blob: fba978bfd6b7e78c3570ab920bdb5b0c699517bb (
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
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
|
module Check = Make_checkTest.M (Qsp_checks.Dead_end)
let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
Check._test_instruction
(** This one is OK because act provide a solution in any case *)
let ok () =
_test_instruction {|
if 0:
act '': gt ''
if 1:
act '': gt ''
end
end
|}
[]
(** Ignore top level dead end*)
let toplevel () =
_test_instruction {|
act 1:
act '': gt ''
end
if 1: act '': gt ''
|} []
let else_branch () =
_test_instruction
{|
if 0:
if 1:
act '': gt ''
else
act '': ''
end
end
|}
[
{
level = Warn;
loc = _position;
message = "Possible dead end (unmatched path)";
};
]
let elseif_branch () =
_test_instruction
{|
if 0:
if 1:
act '': ''
elseif 0:
act '': gt ''
end
end
|}
[
{
level = Debug;
loc = _position;
message = "Possible dead end (no else fallback)";
};
]
let missing_else () =
_test_instruction {|
if 0:
if 1: act '': gt ''
end
|}
[
{
level = Debug;
loc = _position;
message = "Possible dead end (no else fallback)";
};
]
let nothing () = _test_instruction {|
if 0:
if 1: 0
end
|} []
let test =
( "Dead end",
[
Alcotest.test_case "No dead_end" `Quick ok;
Alcotest.test_case "top level" `Quick toplevel;
Alcotest.test_case "Else branch" `Quick else_branch;
Alcotest.test_case "ElseIf branch" `Quick elseif_branch;
Alcotest.test_case "Missing else" `Quick missing_else;
Alcotest.test_case "nothing" `Quick nothing;
] )
|