dead_end.ml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module Check = Make_checkTest.M (Qsp_syntax.Dead_end)
  2. let _position = (Lexing.dummy_pos, Lexing.dummy_pos)
  3. let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
  4. Check._test_instruction
  5. (** This one is OK because act provide a solution in any case *)
  6. let ok () =
  7. _test_instruction {|
  8. if 0:
  9. act '': gt ''
  10. if 1:
  11. act '': gt ''
  12. end
  13. end
  14. |}
  15. []
  16. (** Ignore top level dead end*)
  17. let toplevel () =
  18. _test_instruction {|
  19. act 1:
  20. act '': gt ''
  21. end
  22. if 1: act '': gt ''
  23. |} []
  24. let else_branch () =
  25. _test_instruction
  26. {|
  27. if 0:
  28. if 1:
  29. act '': gt ''
  30. else
  31. act '': ''
  32. end
  33. end
  34. |}
  35. [
  36. {
  37. level = Warn;
  38. loc = _position;
  39. message = "Possible dead end (unmatched path)";
  40. };
  41. ]
  42. let elseif_branch () =
  43. _test_instruction
  44. {|
  45. if 0:
  46. if 1:
  47. act '': ''
  48. elseif 0:
  49. act '': gt ''
  50. end
  51. end
  52. |}
  53. [
  54. {
  55. level = Debug;
  56. loc = _position;
  57. message = "Possible dead end (no else fallback)";
  58. };
  59. ]
  60. let missing_else () =
  61. _test_instruction {|
  62. if 0:
  63. if 1: act '': gt ''
  64. end
  65. |}
  66. [
  67. {
  68. level = Debug;
  69. loc = _position;
  70. message = "Possible dead end (no else fallback)";
  71. };
  72. ]
  73. let nothing () = _test_instruction {|
  74. if 0:
  75. if 1: 0
  76. end
  77. |} []
  78. let test =
  79. ( "Dead end",
  80. [
  81. Alcotest.test_case "No dead_end" `Quick ok;
  82. Alcotest.test_case "top level" `Quick toplevel;
  83. Alcotest.test_case "Else branch" `Quick else_branch;
  84. Alcotest.test_case "ElseIf branch" `Quick elseif_branch;
  85. Alcotest.test_case "Missing else" `Quick missing_else;
  86. Alcotest.test_case "nothing" `Quick nothing;
  87. ] )