Skip to content

Commit

Permalink
Add support for partitions in dune
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo Heuzard committed Mar 1, 2023
1 parent 5f85f88 commit c8e5d74
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(lang dune 1.10)
(lang dune 3.8)
38 changes: 34 additions & 4 deletions libname/ppx_inline_test_libname.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ open Ppxlib

let libname = ref None

let partition = ref None

let () =
Driver.add_arg
"-inline-test-lib"
Expand All @@ -20,11 +22,39 @@ let () =
| Some lib -> libname := Some lib)
;;

let () =
Driver.add_arg
"-partition"
(Arg.String (fun s -> partition := Some s))
~doc:
" A partition name to be used by ppx_inline_test allowing to split tests into partitions for parallel executions. "
;;


let () =
Driver.Cookies.add_simple_handler
"inline-test-partition"
Ast_pattern.(estring __)
~f:(function
| None -> ()
| Some p -> partition := Some p)
;;

let get () =
match !libname with
| None -> None
| Some lib ->
(match String.index lib ':' with
| exception Not_found -> Some (lib, "")
| i -> Some (String.sub lib 0 i, String.sub lib (i + 1) (String.length lib - i - 1)))
| Some lib ->
(match String.index_opt lib ':' with
| None -> Some (lib, match !partition with None -> "" | Some p -> p)
| Some i ->
let libname = String.sub lib 0 i in
let partition0 = String.sub lib (i + 1) (String.length lib - i - 1) in
match !partition with
| None -> Some (libname, partition0)
| Some partition1 ->
if String.equal partition0 partition1
then Some (libname, partition0)
else failwith
"ppx_inline_test: [library-name] and [inline-test-partition] disagree."
)
;;
5 changes: 4 additions & 1 deletion runner/lib/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
(library (name ppx_inline_test_runner_lib)
(public_name ppx_inline_test.runner.lib)
(js_of_ocaml (flags --no-sourcemap) (javascript_files runtime.js))
(c_names am_testing) (libraries base) (preprocess no_preprocessing))
(foreign_stubs
(language c)
(names am_testing))
(libraries base) (preprocess no_preprocessing))
3 changes: 2 additions & 1 deletion src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
(preprocess (pps ppxlib.metaquot))
(inline_tests.backend (runner_libraries ppx_inline_test.runner.lib)
(generate_runner (echo "let () = Ppx_inline_test_lib.Runtime.exit ();;"))
(flags "inline-test-runner" %{library-name} -source-tree-root
(list_partitions_flags "inline-test-runner" %{library-name} -list-partitions)
(flags "inline-test-runner" %{library-name} -partition %{partition} -source-tree-root
%{workspace_root} -diff-cmd -)))
2 changes: 1 addition & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
\n"))
(mode fallback))

(alias (name runtest)
(rule (alias runtest)
(deps test.expected test.output test-inlining.expected test-inlining.output)
(action
(bash
Expand Down

0 comments on commit c8e5d74

Please sign in to comment.