From 043387ec1442893d68bc31bbeac4940621bfc68d Mon Sep 17 00:00:00 2001 From: Galfour Date: Tue, 26 Mar 2019 07:28:01 +0000 Subject: [PATCH] better test --- src/ligo/ast_typed.ml | 7 +++++++ src/ligo/ligo.ml | 23 +++++++++++++++-------- src/ligo/test/integration_tests.ml | 16 +++++++++++++++- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/ligo/ast_typed.ml b/src/ligo/ast_typed.ml index afa880431..427336341 100644 --- a/src/ligo/ast_typed.ml +++ b/src/ligo/ast_typed.ml @@ -355,4 +355,11 @@ module Combinators = struct Record map let int n : expression = Literal (Int n) + + let a_int n = annotated_expression (int n) make_t_int + + let get_a_int (t:annotated_expression) = + match t.expression with + | Literal (Int n) -> ok n + | _ -> simple_fail "not an int" end diff --git a/src/ligo/ligo.ml b/src/ligo/ligo.ml index f2dd73fdc..6a795e0a3 100644 --- a/src/ligo/ligo.ml +++ b/src/ligo/ligo.ml @@ -91,29 +91,36 @@ let transpile_value ?(env:Mini_c.Environment.t = Mini_c.Environment.empty) let untranspile_value (v : Mini_c.value) (e:AST_Typed.type_value) : AST_Typed.annotated_expression result = Transpiler.untranspile v e -let easy_run_main (path:string) (input:string) : AST_Typed.annotated_expression result = +let type_file (path:string) : AST_Typed.program result = let%bind raw = parse_file path in let%bind simpl = simplify raw in let%bind typed = trace (simple_error "typing") @@ type_ simpl in + ok typed + +let easy_run_main_typed (program:AST_Typed.program) (input:AST_Typed.annotated_expression) : AST_Typed.annotated_expression result = let%bind mini_c_main = trace (simple_error "transpile mini_c main") @@ - transpile_entry typed "main" in - - let%bind raw_expr = parse_expression input in - let%bind simpl_expr = simplify_expr raw_expr in - let%bind typed_expr = type_expression simpl_expr in - let%bind mini_c_value = transpile_value typed_expr in + transpile_entry program "main" in + let%bind mini_c_value = transpile_value input in let%bind mini_c_result = trace (simple_error "run mini_c") @@ Mini_c.Run.run_entry mini_c_main mini_c_value in let%bind typed_result = let%bind main_result_type = - let%bind typed_main = Ast_typed.get_entry typed "main" in + let%bind typed_main = Ast_typed.get_entry program "main" in match (snd typed_main).type_value with | Type_function (_, result) -> ok result | _ -> simple_fail "main doesn't have fun type" in untranspile_value mini_c_result main_result_type in ok typed_result + +let easy_run_main (path:string) (input:string) : AST_Typed.annotated_expression result = + let%bind typed = type_file path in + + let%bind raw_expr = parse_expression input in + let%bind simpl_expr = simplify_expr raw_expr in + let%bind typed_expr = type_expression simpl_expr in + easy_run_main_typed typed typed_expr diff --git a/src/ligo/test/integration_tests.ml b/src/ligo/test/integration_tests.ml index e13f771b0..a272e5e45 100644 --- a/src/ligo/test/integration_tests.ml +++ b/src/ligo/test/integration_tests.ml @@ -26,7 +26,21 @@ let function_ () : unit result = ok () let declarations () : unit result = - let%bind _ = easy_run_main "./contracts/declarations.ligo" "2" in + let%bind program = type_file "./contracts/declarations.ligo" in + Format.printf "toto\n%!" ; + Printf.printf "toto\n%!" ; + let aux n = + let open AST_Typed.Combinators in + let input = a_int n in + let%bind result = easy_run_main_typed program input in + let%bind result' = + trace (simple_error "bad result") @@ + get_a_int result in + Assert.assert_equal_int result' (42 + n) + in + let%bind _ = bind_list + @@ List.map aux + @@ [0 ; 2 ; 42 ; 163 ; -1] in ok () let main = "Integration (End to End)", [