diff options
author | Chimrod <> | 2024-02-05 09:32:10 +0100 |
---|---|---|
committer | Chimrod <> | 2024-02-08 14:16:41 +0100 |
commit | 916d37b93c8ad0e2fbe98377093726baf051b708 (patch) | |
tree | e8c6b77368fb8971af11a425ac61e0b3e2014beb /test/make_checkTest.ml | |
parent | d7a13b0e5d6e746993e67a291376bd79766e0ed1 (diff) |
Ignore the global checkers if there is a syntax error; ignore error during recovery after a syntax error
Diffstat (limited to 'test/make_checkTest.ml')
-rw-r--r-- | test/make_checkTest.ml | 39 |
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 |