Merge branch 'parser-negative-tests' into 'dev'

[LIGO-339] Parser negative tests

See merge request ligolang/ligo!319
This commit is contained in:
Rémi Lesenechal 2020-01-09 22:17:30 +00:00
commit e67e2098c2
6 changed files with 110 additions and 4 deletions

View File

@ -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 )))

View File

@ -57,3 +57,28 @@
(preprocess
(pps bisect_ppx --conditional))
(flags (:standard -open Simple_utils -open Parser_shared -open Parser_pascaligo)))
;; Les deux directives (rule) qui suivent sont pour le dev local.
;; Il suffit de faire "dune build Parser.exe" pour avoir un Parser.exe dans le dossier.
;; Pour le purger, il faut faire "dune clean".
;(rule
; (targets Parser.exe)
; (deps ParserMain.exe)
; (action (copy ParserMain.exe Parser.exe))
; (mode promote-until-clean))
;(rule
; (targets Lexer.exe)
; (deps LexerMain.exe)
; (action (copy LexerMain.exe Lexer.exe))
; (mode promote-until-clean))
(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 )))

View File

@ -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 )))

View File

@ -1,7 +1,7 @@
(ocamllex md)
(executables
(names test doc_test)
(names test doc_test parser_negative_tests)
(libraries
simple-utils
ligo
@ -20,6 +20,15 @@
(deps (source_tree ../../gitlab-pages/docs))
)
(alias
(name parser-negative-tests)
(action (run ./parser_negative_tests.exe))
(deps
../passes/1-parser/pascaligo/all.ligo
../passes/1-parser/cameligo/all.ligo
../passes/1-parser/reasonligo/all.ligo
))
(alias
(name ligo-test)
(action (run ./test.exe))
@ -29,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

View File

@ -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 ;
]
] ;
()

View File

@ -78,6 +78,11 @@ while : ; do
;;
# Help
#
--concatenate*)
if test -n "$dir_opt"; then
fatal_error "Repeated option --concatenate."; fi
concatenate=yes
;;
--unlexer=*)
if test -n "$unlexer"; then
fatal_error "Repeated option --unlexer."; fi
@ -119,7 +124,7 @@ done
#
usage () {
cat <<EOF
Usage: $(basename $0) [-h|--help]
Usage: $(basename $0) [-h|--help] [--concatenate]
--par-tokens=<par_tokens>.mly
--lex-tokens=<lex_tokens>.mli
--messages=<parser>.msg
@ -136,6 +141,8 @@ generating the latter). The LIGO files will be numbered with their
corresponding state number in the automaton. The executable <binary>
reads a line on stdin of tokens and produces a line of corresponding
lexemes.
If option --concatenate is used a single file 'all.<extension>' will
be produced, containing the concatenation of all the erroneous expressions
The following options, if given, must be given only once.
@ -262,7 +269,11 @@ paste -d ':' $states $raw > $map
rm -f $dir/*.$ext
while read -r line; do
state=$(echo $line | sed -n 's/\(.*\):.*/\1/p')
filename=$(printf "$dir/%04d.$ext" $state)
if test "$concatenate" = "yes"; then
filename="$dir/all.$ext"
else
filename=$(printf "$dir/%04d.$ext" $state)
fi
sentence=$(echo $line | sed -n 's/.*:\(.*\)/\1/p')
echo $sentence | $unlexer >> $filename
done < $map