tests build (but fail when running, as expected)

This commit is contained in:
Suzanne Dupéron 2019-10-11 17:22:43 -04:00
parent 3bbb8bfd8b
commit 38f9b0ba0b
6 changed files with 27 additions and 15 deletions

View File

@ -10,7 +10,8 @@ let get_program =
fun () -> match !s with fun () -> match !s with
| Some s -> ok s | Some s -> ok s
| None -> ( | None -> (
let%bind program = type_file "./contracts/coase.ligo" in let%bind (program , state) = type_file "./contracts/coase.ligo" in
let () = Typer.Solver.discard_state state in
s := Some program ; s := Some program ;
ok program ok program
) )

View File

@ -8,7 +8,8 @@ let get_program =
fun () -> match !s with fun () -> match !s with
| Some s -> ok s | Some s -> ok s
| None -> ( | None -> (
let%bind program = type_file "./contracts/heap-instance.ligo" in let%bind (program , state) = type_file "./contracts/heap-instance.ligo" in
let () = Typer.Solver.discard_state state in
s := Some program ; s := Some program ;
ok program ok program
) )

View File

@ -3,8 +3,14 @@ open Test_helpers
open Ast_simplified.Combinators open Ast_simplified.Combinators
let mtype_file ?debug_simplify ?debug_typed = Ligo.Compile.Of_source.type_file ?debug_simplify ?debug_typed (Syntax_name "cameligo") let mtype_file ?debug_simplify ?debug_typed f =
let type_file = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo") let%bind (typed , state) = Ligo.Compile.Of_source.type_file ?debug_simplify ?debug_typed (Syntax_name "cameligo") f in
let () = Typer.Solver.discard_state state in
ok typed
let type_file f =
let%bind (typed , state) = Ligo.Compile.Of_source.type_file (Syntax_name "pascaligo") f in
let () = Typer.Solver.discard_state state in
ok typed
let type_alias () : unit result = let type_alias () : unit result =
let%bind program = type_file "./contracts/type-alias.ligo" in let%bind program = type_file "./contracts/type-alias.ligo" in
@ -212,9 +218,9 @@ let bytes_arithmetic () : unit result =
let%bind () = expect_eq program "slice_op" tata at in let%bind () = expect_eq program "slice_op" tata at in
let%bind () = expect_fail program "slice_op" foo in let%bind () = expect_fail program "slice_op" foo in
let%bind () = expect_fail program "slice_op" ba in let%bind () = expect_fail program "slice_op" ba in
let%bind b1 = Run.Of_simplified.run_typed_program program "hasherman" foo in let%bind b1 = Run.Of_simplified.run_typed_program program Typer.Solver.initial_state "hasherman" foo in
let%bind () = expect_eq program "hasherman" foo b1 in let%bind () = expect_eq program "hasherman" foo b1 in
let%bind b3 = Run.Of_simplified.run_typed_program program "hasherman" foototo in let%bind b3 = Run.Of_simplified.run_typed_program program Typer.Solver.initial_state "hasherman" foototo in
let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in let%bind () = Assert.assert_fail @@ Ast_simplified.Misc.assert_value_eq (b3 , b1) in
ok () ok ()

View File

@ -38,7 +38,7 @@ let expect ?input_to_value ?options program entry_point input expecter =
let content () = Format.asprintf "Entry_point: %s" entry_point in let content () = Format.asprintf "Entry_point: %s" entry_point in
error title content in error title content in
trace run_error @@ trace run_error @@
Ligo.Run.Of_simplified.run_typed_program ?input_to_value ?options program entry_point input in Ligo.Run.Of_simplified.run_typed_program ?input_to_value ?options program Typer.Solver.initial_state entry_point input in
expecter result expecter result
let expect_fail ?options program entry_point input = let expect_fail ?options program entry_point input =
@ -49,7 +49,7 @@ let expect_fail ?options program entry_point input =
in in
trace run_error @@ trace run_error @@
Assert.assert_fail Assert.assert_fail
@@ Ligo.Run.Of_simplified.run_typed_program ?options program entry_point input @@ Ligo.Run.Of_simplified.run_typed_program ?options program Typer.Solver.initial_state entry_point input
let expect_eq ?input_to_value ?options program entry_point input expected = let expect_eq ?input_to_value ?options program entry_point input expected =

View File

@ -11,7 +11,9 @@ let int () : unit result =
let pre = e_int 32 in let pre = e_int 32 in
let open Typer in let open Typer in
let e = Environment.full_empty in let e = Environment.full_empty in
let%bind post = type_expression e pre in let state = Typer.Solver.initial_state in
let%bind (post , new_state) = type_expression e state pre in
let () = Typer.Solver.discard_state new_state in
let open! Typed in let open! Typed in
let open Combinators in let open Combinators in
let%bind () = assert_type_value_eq (post.type_annotation, t_int ()) in let%bind () = assert_type_value_eq (post.type_annotation, t_int ()) in
@ -19,12 +21,14 @@ let int () : unit result =
module TestExpressions = struct module TestExpressions = struct
let test_expression ?(env = Typer.Environment.full_empty) let test_expression ?(env = Typer.Environment.full_empty)
?(state = Typer.Solver.initial_state)
(expr : expression) (expr : expression)
(test_expected_ty : Typed.tv) = (test_expected_ty : Typed.tv) =
let pre = expr in let pre = expr in
let open Typer in let open Typer in
let open! Typed in let open! Typed in
let%bind post = type_expression env pre in let%bind (post , new_state) = type_expression env state pre in
let () = Typer.Solver.discard_state new_state in
let%bind () = assert_type_value_eq (post.type_annotation, test_expected_ty) in let%bind () = assert_type_value_eq (post.type_annotation, test_expected_ty) in
ok () ok ()

View File

@ -8,9 +8,9 @@ let get_program =
fun () -> match !s with fun () -> match !s with
| Some s -> ok s | Some s -> ok s
| None -> ( | None -> (
let%bind program = type_file "./contracts/vote.mligo" in let%bind (program , state) = type_file "./contracts/vote.mligo" in
s := Some program ; s := Some (program , state) ;
ok program ok (program , state)
) )
open Ast_simplified open Ast_simplified
@ -39,8 +39,8 @@ let vote str =
e_constructor "Vote" vote e_constructor "Vote" vote
let init_vote () = let init_vote () =
let%bind program = get_program () in let%bind (program , state) = get_program () in
let%bind result = Ligo.Run.Of_simplified.run_typed_program program "main" (e_pair (vote "Yes") (init_storage "basic")) in let%bind result = Ligo.Run.Of_simplified.run_typed_program program state "main" (e_pair (vote "Yes") (init_storage "basic")) in
let%bind (_ , storage) = extract_pair result in let%bind (_ , storage) = extract_pair result in
let%bind storage' = extract_record storage in let%bind storage' = extract_record storage in
let votes = List.assoc "candidates" storage' in let votes = List.assoc "candidates" storage' in