From 20c9de038028914c325a5c4756fed50f8178ce13 Mon Sep 17 00:00:00 2001 From: Lesenechal Remi Date: Thu, 9 Jan 2020 16:41:21 +0100 Subject: [PATCH] parset negative tests for all syntaxes --- src/passes/1-parser/cameligo/dune | 10 +++++++ src/passes/1-parser/reasonligo/dune | 10 +++++++ src/test/dune | 10 ++++--- src/test/parser_negative_tests.ml | 41 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 src/test/parser_negative_tests.ml diff --git a/src/passes/1-parser/cameligo/dune b/src/passes/1-parser/cameligo/dune index e9f496034..63f695550 100644 --- a/src/passes/1-parser/cameligo/dune +++ b/src/passes/1-parser/cameligo/dune @@ -43,3 +43,13 @@ (preprocess (pps bisect_ppx --conditional)) (modules Unlexer)) + +(rule + (targets Parser.msg) + (deps (:script_messages ../../../../vendors/ligo-utils/simple-utils/messages.sh) Parser.mly LexToken.mli ParToken.mly) + (action (run %{script_messages} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly Parser.mly ))) + +(rule + (targets all.ligo) + (deps (:script_cover ../../../../vendors/ligo-utils/simple-utils/cover.sh) Parser.mly LexToken.mli ParToken.mly Parser.msg Unlexer.exe) + (action (run %{script_cover} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly --ext=ligo --unlexer=./Unlexer.exe --messages=Parser.msg --dir=. --concatenate Parser.mly ))) \ No newline at end of file diff --git a/src/passes/1-parser/reasonligo/dune b/src/passes/1-parser/reasonligo/dune index e59426b63..a38f523db 100644 --- a/src/passes/1-parser/reasonligo/dune +++ b/src/passes/1-parser/reasonligo/dune @@ -47,3 +47,13 @@ (preprocess (pps bisect_ppx --conditional)) (modules Unlexer)) + +(rule + (targets Parser.msg) + (deps (:script_messages ../../../../vendors/ligo-utils/simple-utils/messages.sh) Parser.mly LexToken.mli ParToken.mly) + (action (run %{script_messages} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly Parser.mly ))) + +(rule + (targets all.ligo) + (deps (:script_cover ../../../../vendors/ligo-utils/simple-utils/cover.sh) Parser.mly LexToken.mli ParToken.mly Parser.msg Unlexer.exe) + (action (run %{script_cover} --lex-tokens=LexToken.mli --par-tokens=ParToken.mly --ext=ligo --unlexer=./Unlexer.exe --messages=Parser.msg --dir=. --concatenate Parser.mly ))) diff --git a/src/test/dune b/src/test/dune index 8ddbde16b..128e0a654 100644 --- a/src/test/dune +++ b/src/test/dune @@ -1,7 +1,7 @@ (ocamllex md) (executables - (names test doc_test) + (names test doc_test parser_negative_tests) (libraries simple-utils ligo @@ -23,7 +23,11 @@ (alias (name parser-negative-tests) (action (run ./parser_negative_tests.exe)) - (deps ../passes/1-parser/pascaligo/all.ligo)) + (deps + ../passes/1-parser/pascaligo/all.ligo + ../passes/1-parser/cameligo/all.ligo + ../passes/1-parser/reasonligo/all.ligo + )) (alias (name ligo-test) @@ -34,7 +38,7 @@ (alias (name runtest) - (deps (alias ligo-test) (alias doc-test)) + (deps (alias ligo-test) (alias doc-test) (alias parser-negative-tests)) ) (alias diff --git a/src/test/parser_negative_tests.ml b/src/test/parser_negative_tests.ml new file mode 100644 index 000000000..2125bbef5 --- /dev/null +++ b/src/test/parser_negative_tests.ml @@ -0,0 +1,41 @@ +open Test_helpers +open Trace + +type 'a sdata = { erroneous_source_file : string ; parser : string -> 'a result } +let pascaligo_sdata = { + erroneous_source_file = "../passes/1-parser/pascaligo/all.ligo" ; + parser = Parser.Pascaligo.parse_expression } +let cameligo_sdata = { + erroneous_source_file = "../passes/1-parser/cameligo/all.ligo" ; + parser = Parser.Cameligo.parse_expression } +let reasonligo_sdata = { + erroneous_source_file = "../passes/1-parser/reasonligo/all.ligo" ; + parser = Parser.Reasonligo.parse_expression } + +let get_exp_as_string filename = + let lines = ref [] in + let chan = open_in filename in + try + while true; do + lines := input_line chan :: !lines + done; !lines + with End_of_file -> + close_in chan; + List.rev !lines ;; + +let assert_syntax_error sdata () = + let%bind _l = bind_iter_list + (fun entry -> Assert.assert_fail @@ sdata.parser entry) + (get_exp_as_string sdata.erroneous_source_file) in + ok () + +let () = + Printexc.record_backtrace true ; + run_test @@ test_suite "LIGO" [ + test_suite "Parser negative tests" [ + test "pascaligo" @@ assert_syntax_error pascaligo_sdata ; + test "cameligo" @@ assert_syntax_error cameligo_sdata ; + test "reasonligo" @@ assert_syntax_error reasonligo_sdata ; + ] + ] ; + ()