Jonathan Graveline pushed to branch graveline at Stefan / Typer
Commits: d63644ec by Jonathan Graveline at 2018-08-03T19:12:23Z samples/tuple_test.typer: Test written in Typer for tuple
Changed warning, info and fatal output in unit test primitive
- - - - -
2 changed files:
- + samples/tuple_test.typer - src/util.ml
Changes:
===================================== samples/tuple_test.typer ===================================== @@ -0,0 +1,73 @@ + +tupx = (0,1,2,3,4); + +(a,b,c,d,e) <- tupx; + +tupy = (true,false,some true, some false); + +(f,g,h,i) <- tupy; + +tupz = ((true,some true),(false,some false)); + +(j,k) <- tupz; + +(l,m) <- j; + +(n,o) <- k; + +test-int = do { + Test_info "TUPLE" "Int"; + + r0 <- Test_eq "a = 0" a 0; + r1 <- Test_eq "b = 1" b 1; + r2 <- Test_eq "c = 2" c 2; + r3 <- Test_eq "d = 3" d 3; + r4 <- Test_eq "e = 4" e 4; + + if (and r0 (and r1 (and r2 (and r3 r4)))) then + (Test_info "TUPLE" "test on Int succeeded") + else + (Test_warning "TUPLE" "test on Int failed"); +}; + +test-datatype = do { + Test_info "TUPLE" "datatype"; + + r0 <- Test_eq "f = true" f true; + r1 <- Test_eq "g = false" g false; + r2 <- Test_eq "h = (some true)" h (some true); + r3 <- Test_eq "i = (some false)" i (some false); + + if (and r0 (and r1 (and r2 r3))) then + (Test_info "TUPLE" "test on datatype succeeded") + else + (Test_warning "TUPLE" "test on datatype failed"); +}; + +test-tuple = do { + Test_info "TUPLE" "tuple"; + + r0 <- Test_eq "l = true" l true; + r1 <- Test_eq "m = (some true)" m (some true); + r2 <- Test_eq "n = false" n false; + r3 <- Test_eq "o = (some false)" o (some false); + + %% + %% Here is a problem with tuple's definition + %% each tuple has in fact a different type! + %% + %% r4 <- Test_eq "j = (true, some true)" j (true, some true); + %% r5 <- Test_eq "k = (false, some false)" k (false, some false); + %% + %% But those value are tested within `r0` to `r3` + %% + + if (and r0 (and r1 (and r2 r3))) then + (Test_info "TUPLE" "test on tuple succeeded") + else + (Test_warning "TUPLE" "test on tuple failed"); +}; + +u = (IO_run test-int) (); +u = (IO_run test-datatype) (); +u = (IO_run test-tuple) ();
===================================== src/util.ml ===================================== @@ -141,13 +141,13 @@ let msg_warning = msg_message false 2 "Warning:" let msg_info = msg_message false 3 "Info:"
let msg_user_fatal s l m = - msg_message true 1 "Unit test (fatal):" s l m; + msg_message true 1 "(Unit test fatal):" s l m; flush stdout; reset_error_log (); user_error "User Fatal Error"
-let msg_user_warning = msg_message false 2 "Unit test (warning):" -let msg_user_info = msg_message false 3 "Unit test (info):" +let msg_user_warning = msg_message false 2 "(Unit test warning):" +let msg_user_info = msg_message false 3 "(Unit test info):"
(* Compiler Internal Debug print *) let debug_msg expr =
View it on GitLab: https://gitlab.com/monnier/typer/commit/d63644ece795190ad8cd3d7e7691beb16aa1...
Afficher les réponses par date