dup_cases.ml 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. module Check = Make_checkTest.M (Qsp_syntax.Dup_test)
  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. (** Two differents test shall not report error *)
  6. let ok () =
  7. _test_instruction {|
  8. if 1:
  9. 0
  10. elseif 2:
  11. 0
  12. end
  13. if 3:
  14. 0
  15. end
  16. |} []
  17. (** The rnd function can generate different result, this is not a warning *)
  18. let ok_rnd () =
  19. _test_instruction {|
  20. if rnd():
  21. 0
  22. elseif rnd():
  23. 0
  24. end
  25. |} []
  26. (** The same test in two differents block shall be considered as a duplicate.
  27. *)
  28. let ok_act () =
  29. _test_instruction
  30. {|
  31. act "action":
  32. if 1:
  33. 0
  34. end
  35. end
  36. act "action":
  37. if 1:
  38. 0
  39. end
  40. end
  41. |}
  42. []
  43. let duplicate_case () =
  44. _test_instruction
  45. {|
  46. if 0 = '1':
  47. 0
  48. elseif 0 = '1':
  49. 0
  50. end
  51. |}
  52. [
  53. {
  54. level = Error;
  55. loc = _position;
  56. message = "This case is duplicated line(s) 5";
  57. };
  58. ]
  59. let duplicate_root_test () =
  60. _test_instruction
  61. {|
  62. if args[0] = 1:
  63. 0
  64. end
  65. if args[0] = 1:
  66. 0
  67. elseif 1:
  68. 0
  69. end
  70. |}
  71. [
  72. {
  73. level = Error;
  74. loc = _position;
  75. message = "This case is duplicated line(s) 6";
  76. };
  77. ]
  78. let duplicate_nonroot_test () =
  79. _test_instruction
  80. {|
  81. act 0:
  82. if 1:
  83. 0
  84. end
  85. if 1:
  86. 0
  87. end
  88. end
  89. if 0:
  90. if 1:
  91. 0
  92. end
  93. if 1:
  94. 0
  95. end
  96. else
  97. if 1:
  98. 0
  99. end
  100. if 1:
  101. 0
  102. end
  103. end
  104. |}
  105. []
  106. let test =
  107. ( "Duplicates predicates checker",
  108. [
  109. Alcotest.test_case "Ok" `Quick ok;
  110. Alcotest.test_case "Ok rnd" `Quick ok_rnd;
  111. Alcotest.test_case "Ok_act" `Quick ok_act;
  112. Alcotest.test_case "duplicate_cases" `Quick duplicate_case;
  113. Alcotest.test_case "duplicate_root" `Quick duplicate_root_test;
  114. Alcotest.test_case "duplicate_nonroottest" `Quick duplicate_nonroot_test;
  115. ] )