dup_cases.ml 1.9 KB

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