aboutsummaryrefslogtreecommitdiff
path: root/test/make_checkTest.ml
diff options
context:
space:
mode:
Diffstat (limited to 'test/make_checkTest.ml')
-rw-r--r--test/make_checkTest.ml39
1 files changed, 31 insertions, 8 deletions
diff --git a/test/make_checkTest.ml b/test/make_checkTest.ml
index d428b45..d3ad358 100644
--- a/test/make_checkTest.ml
+++ b/test/make_checkTest.ml
@@ -15,27 +15,32 @@ module M (Check : Qsp_syntax.S.Analyzer) = struct
}
[@@deriving show, eq]
- let report : Qsp_syntax.Report.t list Alcotest.testable =
+ let report : t list Alcotest.testable =
Alcotest.list @@ Alcotest.testable Qsp_syntax.Report.pp equal
+ let report_global : (string * t) list Alcotest.testable =
+ Alcotest.list
+ @@ Alcotest.pair Alcotest.string
+ (Alcotest.testable Qsp_syntax.Report.pp equal)
+
let parse :
+ ?context:Check.context ->
string ->
- (Check.Location.t * Qsp_syntax.Report.t list, Qsp_syntax.Report.t) result
- =
- fun content ->
+ (Check.Location.t Qparser.Analyzer.result, t) result =
+ fun ?context content ->
let lexing =
Sedlexing.Latin1.from_string content |> Qparser.Lexbuf.from_lexbuf
in
- let context = Check.initialize () in
+ let context = Option.value context ~default:(Check.initialize ()) in
Qparser.Analyzer.parse (module Check) lexing context
let get_report :
- (Check.Location.t * Qsp_syntax.Report.t list, Qsp_syntax.Report.t) result ->
+ (Check.Location.t Qparser.Analyzer.result, Qsp_syntax.Report.t) result ->
Qsp_syntax.Report.t list = function
- | Ok (_, report) -> report
+ | Ok v -> v.report
| Error _ -> failwith "Error"
- let _test_instruction : string -> Qsp_syntax.Report.t list -> unit =
+ let _test_instruction : string -> t list -> unit =
fun literal expected ->
let _location = Printf.sprintf {|# Location
%s
@@ -43,4 +48,22 @@ module M (Check : Qsp_syntax.S.Analyzer) = struct
let actual = get_report @@ parse _location and msg = literal in
Alcotest.(check' report ~msg ~expected ~actual)
+
+ (** Run a test over the whole file.
+ The parsing of the content shall not report any error.
+ *)
+ let global_check : string -> (string * t) list -> unit =
+ fun literal expected ->
+ let _location = Printf.sprintf {|# Location
+%s
+------- |} literal in
+ let context = Check.initialize () in
+ let actual = get_report @@ parse ~context _location in
+ let () =
+ Alcotest.(
+ check' report ~msg:"Error reported during parsing" ~expected:[] ~actual)
+ in
+ let msg = literal in
+ let actual = Check.finalize context in
+ Alcotest.(check' report_global ~msg ~expected ~actual)
end