Permalink
Browse files

Add some test for ocamlbuild. Make ocamlbuild_test test function hand…

…le optional parameters and support expected failures

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13191 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  • Loading branch information...
1 parent 7cae1f0 commit 0ff66b8b9c71c47b871b87bdd4d3d995a92ab85b meyer committed Jan 1, 2013
Showing with 37 additions and 19 deletions.
  1. +12 −7 ocamlbuild/testsuite/level0.ml
  2. +25 −12 ocamlbuild/testsuite/ocamlbuild_test.ml
@@ -1,5 +1,4 @@
-#use "topfind";;
-#require "unix";;
+#load "unix.cma";;
let ocamlbuild = try Sys.getenv "OCAMLBUILD" with Not_found -> "ocamlbuild";;
@@ -25,7 +24,7 @@ test "BasicNativeTree"
"dummy.native";
"dummy.o";
"_log"]))]
- ~targets:("dummy.native",[]);;
+ ~targets:("dummy.native",[]) ();;
test "BasicByteTree"
~description:"Output tree for byte compilation"
@@ -40,13 +39,13 @@ test "BasicByteTree"
"dummy.ml.depends";
"dummy.byte";
"_log"]))]
- ~targets:("dummy.byte",[]);;
+ ~targets:("dummy.byte",[]) ();;
test "SeveralTargets"
~description:"Several targets"
~tree:[T.f "dummy.ml"]
~matching:[_build (M.lf ["dummy.byte"; "dummy.native"])]
- ~targets:("dummy.byte",["dummy.native"]);;
+ ~targets:("dummy.byte",["dummy.native"]) ();;
let alt_build_dir = "BuIlD2";;
@@ -55,14 +54,20 @@ test "BuildDir"
~description:"Different build directory"
~tree:[T.f "dummy.ml"]
~matching:[M.d alt_build_dir (M.lf ["dummy.byte"])]
- ~targets:("dummy.byte",[]);;
+ ~targets:("dummy.byte",[]) ();;
test "camlp4.opt"
~description:"Fixes PR#5652"
~options:[`use_ocamlfind; `package "camlp4.macro";`tags ["camlp4o.opt"; "syntax\\(camp4o\\)"];
`ppflag "camlp4o.opt"; `ppflag "-parser"; `ppflag "macro"; `ppflag "-DTEST"]
~tree:[T.f "dummy.ml" ~content:"IFDEF TEST THEN\nprint_endline \"Hello\";;\nENDIF;;"]
~matching:[M.x "dummy.native" ~output:"Hello"]
- ~targets:("dummy.native",[]);;
+ ~targets:("dummy.native",[]) ();;
+
+test "TagsErrorMessage"
+ ~description:"Confirm relevance of an error message due to erronous _tags"
+ ~failing_msg:"Failure: lexing: empty token."
+ ~tree:[T.f "_tags" ~content:"* : not_hygienic"]
+ ~targets:("none.native",[]) ();;
run ~root:"_test";;
@@ -374,17 +374,19 @@ type test = { name : string
; options : Option.t list
; targets : string * string list
; pre_cmd : string option
+ ; failing_msg : string option
; run : run list }
let tests = ref []
-let test ?(options=[]) ?(run=[]) ?pre_cmd
- name
+let test name
~description
- ~tree
- ~matching
- ~targets =
- tests := !tests @ [{ name; description; tree; matching; options; targets; pre_cmd; run }]
+ ?(options=[]) ?(run=[]) ?pre_cmd ?failing_msg
+ ?(tree=[])
+ ?(matching=[])
+ ~targets ()
+ =
+ tests := !tests @ [{ name; description; tree; matching; options; targets; pre_cmd; failing_msg; run }]
let run ~root =
@@ -403,6 +405,7 @@ let run ~root =
; matching
; options
; targets
+ ; failing_msg
; pre_cmd
; run } =
@@ -421,16 +424,26 @@ let run ~root =
let log_name = name ^ ".log" in
let cmd = command options (fst targets :: snd targets) in
+ let allow_failure = failing_msg <> None in
Unix.(match execute cmd with
| WEXITED n,lines
| WSIGNALED n,lines
- | WSTOPPED n,lines when n <> 0 ->
- let ch = open_out log_name in
- List.iter (fun l -> output_string ch l; output_string ch "\n") lines;
- close_out ch;
- Printf.printf "\x1b[0;31m\x1b[1m[FAILED]\x1b[0m \x1b[1m%-20s\x1b[0;33m%s.\n" name
- (Printf.sprintf "Command '%s' with error code %n output written to %s" cmd n log_name);
+ | WSTOPPED n,lines when allow_failure || n <> 0 ->
+ begin match failing_msg with
+ | None ->
+ let ch = open_out log_name in
+ List.iter (fun l -> output_string ch l; output_string ch "\n") lines;
+ close_out ch;
+ Printf.printf "\x1b[0;31m\x1b[1m[FAILED]\x1b[0m \x1b[1m%-20s\x1b[0;33m%s.\n" name
+ (Printf.sprintf "Command '%s' with error code %n output written to %s" cmd n log_name);
+ | Some failing_msg ->
+ let msg = String.concat "\n" lines in
+ if failing_msg = msg then
+ Printf.printf "\x1b[0;32m\x1b[1m[PASSED]\x1b[0m \x1b[1m%-20s\x1b[0;36m%s.\n" name description
+ else
+ Printf.printf "\x1b[0;31m\x1b[1m[FAILED]\x1b[0m \x1b[1m%-20s\x1b[0;33m%s.\n" name ((Printf.sprintf "Failure with not matching message: %s") msg)
+ end;
Unix.chdir dir;
| _ ->
Unix.chdir dir;

0 comments on commit 0ff66b8

Please sign in to comment.