Merge branch 'parser-negative-tests' into 'dev'
[LIGO-339] Parser negative tests See merge request ligolang/ligo!319
This commit is contained in:
commit
e67e2098c2
@ -43,3 +43,13 @@
|
|||||||
(preprocess
|
(preprocess
|
||||||
(pps bisect_ppx --conditional))
|
(pps bisect_ppx --conditional))
|
||||||
(modules Unlexer))
|
(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 )))
|
@ -57,3 +57,28 @@
|
|||||||
(preprocess
|
(preprocess
|
||||||
(pps bisect_ppx --conditional))
|
(pps bisect_ppx --conditional))
|
||||||
(flags (:standard -open Simple_utils -open Parser_shared -open Parser_pascaligo)))
|
(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 )))
|
||||||
|
@ -47,3 +47,13 @@
|
|||||||
(preprocess
|
(preprocess
|
||||||
(pps bisect_ppx --conditional))
|
(pps bisect_ppx --conditional))
|
||||||
(modules Unlexer))
|
(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 )))
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
(ocamllex md)
|
(ocamllex md)
|
||||||
|
|
||||||
(executables
|
(executables
|
||||||
(names test doc_test)
|
(names test doc_test parser_negative_tests)
|
||||||
(libraries
|
(libraries
|
||||||
simple-utils
|
simple-utils
|
||||||
ligo
|
ligo
|
||||||
@ -20,6 +20,15 @@
|
|||||||
(deps (source_tree ../../gitlab-pages/docs))
|
(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
|
(alias
|
||||||
(name ligo-test)
|
(name ligo-test)
|
||||||
(action (run ./test.exe))
|
(action (run ./test.exe))
|
||||||
@ -29,7 +38,7 @@
|
|||||||
|
|
||||||
(alias
|
(alias
|
||||||
(name runtest)
|
(name runtest)
|
||||||
(deps (alias ligo-test) (alias doc-test))
|
(deps (alias ligo-test) (alias doc-test) (alias parser-negative-tests))
|
||||||
)
|
)
|
||||||
|
|
||||||
(alias
|
(alias
|
||||||
|
41
src/test/parser_negative_tests.ml
Normal file
41
src/test/parser_negative_tests.ml
Normal 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 ;
|
||||||
|
]
|
||||||
|
] ;
|
||||||
|
()
|
15
vendors/ligo-utils/simple-utils/cover.sh
vendored
15
vendors/ligo-utils/simple-utils/cover.sh
vendored
@ -78,6 +78,11 @@ while : ; do
|
|||||||
;;
|
;;
|
||||||
# Help
|
# Help
|
||||||
#
|
#
|
||||||
|
--concatenate*)
|
||||||
|
if test -n "$dir_opt"; then
|
||||||
|
fatal_error "Repeated option --concatenate."; fi
|
||||||
|
concatenate=yes
|
||||||
|
;;
|
||||||
--unlexer=*)
|
--unlexer=*)
|
||||||
if test -n "$unlexer"; then
|
if test -n "$unlexer"; then
|
||||||
fatal_error "Repeated option --unlexer."; fi
|
fatal_error "Repeated option --unlexer."; fi
|
||||||
@ -119,7 +124,7 @@ done
|
|||||||
#
|
#
|
||||||
usage () {
|
usage () {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
Usage: $(basename $0) [-h|--help]
|
Usage: $(basename $0) [-h|--help] [--concatenate]
|
||||||
--par-tokens=<par_tokens>.mly
|
--par-tokens=<par_tokens>.mly
|
||||||
--lex-tokens=<lex_tokens>.mli
|
--lex-tokens=<lex_tokens>.mli
|
||||||
--messages=<parser>.msg
|
--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>
|
corresponding state number in the automaton. The executable <binary>
|
||||||
reads a line on stdin of tokens and produces a line of corresponding
|
reads a line on stdin of tokens and produces a line of corresponding
|
||||||
lexemes.
|
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.
|
The following options, if given, must be given only once.
|
||||||
|
|
||||||
@ -262,7 +269,11 @@ paste -d ':' $states $raw > $map
|
|||||||
rm -f $dir/*.$ext
|
rm -f $dir/*.$ext
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
state=$(echo $line | sed -n 's/\(.*\):.*/\1/p')
|
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')
|
sentence=$(echo $line | sed -n 's/.*:\(.*\)/\1/p')
|
||||||
echo $sentence | $unlexer >> $filename
|
echo $sentence | $unlexer >> $filename
|
||||||
done < $map
|
done < $map
|
||||||
|
Loading…
Reference in New Issue
Block a user