chore(build): use the qtest backend in dune

This commit is contained in:
Simon Cruanes 2018-02-27 21:02:15 -06:00
parent 9e105a3fbc
commit ac8aa89c4a
9 changed files with 16 additions and 93 deletions

View file

@ -1,30 +0,0 @@
(executable
((name make)
(modules (make))
))
(rule
((targets (run_qtest.ml))
(deps (make.bc (files_recursively_in ../src)))
;(libraries (qtest qcheck))
(action
(run ./make.bc -target ${@}))
))
(executable
((name run_qtest)
(modes (native))
(modules (run_qtest))
(flags (:standard -nolabels))
(libraries (sequence gen qcheck containers containers.unix
containers.data containers.thread containers.iter
containers.sexp uutf))
))
(alias
((name runtest)
(deps (run_qtest.exe))
(action (run ${<}))
))

View file

@ -1,63 +0,0 @@
let str_sub ?(offset=0) ~sub:s' s =
let open String in
let rec aux i =
i<length s && (aux_sub i 0 || aux (i+1))
and aux_sub i j =
if j = length s' then true
else if i+j >= length s then false
else get s (i+j) = get s' j && aux_sub i (j+1)
in
aux offset
let is_suffix ~sub s =
str_sub ~offset:(String.length s - String.length sub) ~sub s
let is_code file = is_suffix ~sub:".ml" file || is_suffix ~sub:".mli" file
let do_not_test file =
assert (not (is_suffix ~sub:"make.ml" file));
is_suffix ~sub:"containers.ml" file ||
is_suffix ~sub:"containers_top.ml" file ||
is_suffix ~sub:"mkflags.ml" file ||
is_suffix ~sub:"utop.ml" file
let prefix = "src"
let dirs = List.map (fun s-> Filename.concat prefix s)
let list_files dir : string list =
let rec f ~prefix acc file =
let file = Filename.concat prefix file in
if Sys.is_directory file then (
Array.fold_left (f ~prefix:file) acc (Sys.readdir file)
) else (
if is_code file && not (do_not_test file) then file :: acc else acc
)
in
f ~prefix:"" [] dir
let run_qtest target =
let files =
list_files "../src/"
|> List.map (Printf.sprintf "'%s'")
|> String.concat " "
in
let cmd =
Printf.sprintf "qtest extract --preamble 'open CCFun;;' -o %S %s 2>/dev/null"
target files
in
exit (Sys.command cmd)
let () =
let target = ref "" in
Arg.parse ["-target", Arg.Set_string target, " set target"]
(fun _ -> ()) "make.ml -target file";
if !target="" then failwith "please specify a target";
if Sys.command "which qtest > /dev/null" <> 0 then (
(* create empty file *)
let out = open_out !target in
output_string out "";
close_out out;
) else (
run_qtest !target
)

View file

@ -3,6 +3,10 @@
(** {1 Basic String Utils} *) (** {1 Basic String Utils} *)
(*$inject
open CCFun;;
*)
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist] type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]

View file

@ -6,4 +6,6 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels -open CCMonomorphic)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string -nolabels -open CCMonomorphic))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (result uchar containers.monomorphic)) (libraries (result uchar containers.monomorphic))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen uutf))))
)) ))

View file

@ -6,4 +6,6 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (result)) (libraries (result))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen containers))))
)) ))

View file

@ -6,4 +6,6 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (result)) (libraries (result))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen containers))))
)) ))

View file

@ -6,6 +6,8 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (result)) (libraries (result))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen containers))))
)) ))
(ocamllex (CCSexp_lex)) (ocamllex (CCSexp_lex))

View file

@ -7,5 +7,7 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (containers threads)) (libraries (containers threads))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen containers threads))))
)) ))

View file

@ -7,4 +7,6 @@
(flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string)) (flags (:standard -w +a-4-42-44-48-50-58-32-60@8 -safe-string))
(ocamlopt_flags (:standard (:include ../flambda.flags))) (ocamlopt_flags (:standard (:include ../flambda.flags)))
(libraries (result unix)) (libraries (result unix))
(inline_tests ((backend qtest.lib)
(libraries (sequence gen containers unix threads))))
)) ))