Skip to content

Commit

Permalink
v0.11.117.17+10
Browse files Browse the repository at this point in the history
  • Loading branch information
xclerc committed Aug 7, 2018
1 parent 341221a commit 74c79dd
Show file tree
Hide file tree
Showing 24 changed files with 130 additions and 428 deletions.
38 changes: 38 additions & 0 deletions bench/bin/bench_nano_mutex.ml
@@ -0,0 +1,38 @@
open Core

module Bench = Core_bench.Bench

module type Mutex = sig
type t
val create : unit -> t
val lock : t -> unit
val unlock : t -> unit
end

let concat = String.concat

let make ~name (m : (module Mutex)) =
let module M = (val m : Mutex) in
[ concat [ name; " create"], (fun () -> ignore (M.create ()));
concat [ name; " lock/unlock"],
let l = M.create () in
(fun () -> M.lock l; M.unlock l);
]
;;

module Nano_mutex : Mutex = struct
include Core.Nano_mutex

let lock = lock_exn
let unlock t = unlock_exn t
end

let () =
Bench.bench
(List.map ~f:(fun (name, thunk) -> Bench.Test.create ~name thunk)
(
make ~name:"Caml.Mutex" (module Caml.Mutex : Mutex)
@ make ~name:"Core.Mutex" (module Core.Mutex : Mutex)
@ make ~name:"Nano_mutex" (module Nano_mutex : Mutex)
))
;;
1 change: 1 addition & 0 deletions bench/bin/jbuild
Expand Up @@ -3,6 +3,7 @@
bench_hashtbl
bench_heap
bench_map
bench_nano_mutex
core_stack
core_string_search_pattern
dequeue
Expand Down
2 changes: 1 addition & 1 deletion example/quickcheck/from_comments.ml
Expand Up @@ -5,7 +5,7 @@ type 'a bst = Leaf | Node of 'a bst * 'a * 'a bst

let bst_obs key_obs =
fixed_point (fun bst_of_key_obs ->
unmap (Either.obs Unit.obs (tuple3 bst_of_key_obs key_obs bst_of_key_obs))
unmap (Either.quickcheck_observer Unit.quickcheck_observer (tuple3 bst_of_key_obs key_obs bst_of_key_obs))
~f:(function
| Leaf -> First ()
| Node (l, k, r) -> Second (l, k, r)))
84 changes: 42 additions & 42 deletions example/quickcheck/from_docs.ml
Expand Up @@ -5,7 +5,7 @@ module Initial_example = struct

let%test_unit "fold_left vs fold_right" =
Quickcheck.test
(List.gen Int.gen)
(List.quickcheck_generator Int.quickcheck_generator)
~sexp_of:[%sexp_of: int list]
~f:(fun list ->
[%test_eq: int]
Expand All @@ -19,11 +19,11 @@ module Generator_examples = struct
let (_ : _ Generator.t) =
Generator.singleton "An arbitrary value."
let (_ : _ Generator.t) =
String.gen (* any string, including weird strings like "\000" *)
String.quickcheck_generator (* any string, including weird strings like "\000" *)
let (_ : _ Generator.t) =
Int.gen (* any int, from [min_value] to [max_value] *)
Int.quickcheck_generator (* any int, from [min_value] to [max_value] *)
let (_ : _ Generator.t) =
Float.gen (* any float, from [neg_infinity] to [infinity] plus [nan] *)
Float.quickcheck_generator (* any float, from [neg_infinity] to [infinity] plus [nan] *)
let (_ : _ Generator.t) =
Generator.small_non_negative_int
let (_ : _ Generator.t) =
Expand All @@ -37,29 +37,29 @@ module Generator_examples = struct
let (_ : _ Generator.t) =
Float.gen_finite
let (_ : _ Generator.t) =
Generator.tuple2 Int.gen Float.gen
Generator.tuple2 Int.quickcheck_generator Float.quickcheck_generator
let (_ : _ Generator.t) =
List.gen (Generator.tuple2 Int.gen Float.gen)
List.quickcheck_generator (Generator.tuple2 Int.quickcheck_generator Float.quickcheck_generator)
let (_ : _ Generator.t) =
List.gen_with_length 12 (Generator.tuple2 Int.gen Float.gen)
List.gen_with_length 12 (Generator.tuple2 Int.quickcheck_generator Float.quickcheck_generator)
let (_ : _ Generator.t) =
Either.gen Int.gen Float.gen
Either.quickcheck_generator Int.quickcheck_generator Float.quickcheck_generator
let (_ : _ Generator.t) =
Option.gen String.gen
Option.quickcheck_generator String.quickcheck_generator
let (_ : _ Generator.t) =
Generator.map Char.gen ~f:Char.to_int
Generator.map Char.quickcheck_generator ~f:Char.to_int
let (_ : _ Generator.t) =
Generator.filter Float.gen ~f:Float.is_finite (* use [filter] sparingly! *)
Generator.filter Float.quickcheck_generator ~f:Float.is_finite (* use [filter] sparingly! *)
let (_ : _ Generator.t) =
Generator.fn Int.obs Bool.gen
Generator.fn Int.quickcheck_observer Bool.quickcheck_generator
let (_ : _ Generator.t) =
Generator.(union [ singleton (Ok ()) ; singleton (Or_error.error_string "fail") ])

module Monadic = struct

let (_ : _ Generator.t) =
let open Generator in
String.gen
String.quickcheck_generator
>>= fun str ->
Int.gen_incl 0 (String.length str - 1)
>>| fun i ->
Expand All @@ -72,8 +72,8 @@ module Generator_examples = struct
let (_ : _ Generator.t) =
Generator.(fixed_point (fun self ->
size >>= function
| 0 -> String.gen >>| fun atom -> Sexp.Atom atom
| _ -> List.gen self >>| fun list -> Sexp.List list))
| 0 -> String.quickcheck_generator >>| fun atom -> Sexp.Atom atom
| _ -> List.quickcheck_generator self >>| fun list -> Sexp.List list))

let rec binary_subtree lower_bound upper_bound =
let open Generator in
Expand Down Expand Up @@ -108,15 +108,15 @@ end
module Observer_examples = struct

let (_ : _ Observer.t) = Observer.singleton ()
let (_ : _ Observer.t) = String.obs
let (_ : _ Observer.t) = Int.obs
let (_ : _ Observer.t) = Float.obs
let (_ : _ Observer.t) = Observer.tuple2 Int.obs Float.obs
let (_ : _ Observer.t) = List.obs (Observer.tuple2 Int.obs Float.obs)
let (_ : _ Observer.t) = Either.obs Int.obs Float.obs
let (_ : _ Observer.t) = Option.obs String.obs
let (_ : _ Observer.t) = Observer.fn Int.gen Bool.obs
let (_ : _ Observer.t) = Observer.unmap Char.obs ~f:Char.of_int_exn
let (_ : _ Observer.t) = String.quickcheck_observer
let (_ : _ Observer.t) = Int.quickcheck_observer
let (_ : _ Observer.t) = Float.quickcheck_observer
let (_ : _ Observer.t) = Observer.tuple2 Int.quickcheck_observer Float.quickcheck_observer
let (_ : _ Observer.t) = List.quickcheck_observer (Observer.tuple2 Int.quickcheck_observer Float.quickcheck_observer)
let (_ : _ Observer.t) = Either.quickcheck_observer Int.quickcheck_observer Float.quickcheck_observer
let (_ : _ Observer.t) = Option.quickcheck_observer String.quickcheck_observer
let (_ : _ Observer.t) = Observer.fn Int.quickcheck_generator Bool.quickcheck_observer
let (_ : _ Observer.t) = Observer.unmap Char.quickcheck_observer ~f:Char.of_int_exn

end

Expand Down Expand Up @@ -146,20 +146,20 @@ module Example_1_functional = struct
List.fold list ~init:Functional_stack.empty ~f:Functional_stack.push

let stack elt =
Generator.map (List.gen elt) ~f:of_list
Generator.map (List.quickcheck_generator elt) ~f:of_list

open Functional_stack

let%test_unit "push + is_empty" =
Quickcheck.test (Generator.tuple2 Int.gen (stack Int.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Int.quickcheck_generator (stack Int.quickcheck_generator)) ~f:(fun (x, t) ->
[%test_result: bool] (is_empty (push t x)) ~expect:false)

let%test_unit "push + top_exn" =
Quickcheck.test (Generator.tuple2 Int.gen (stack Int.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Int.quickcheck_generator (stack Int.quickcheck_generator)) ~f:(fun (x, t) ->
[%test_result: int] (top_exn (push t x)) ~expect:x)

let%test_unit "push + pop_exn" =
Quickcheck.test (Generator.tuple2 Int.gen (stack Int.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Int.quickcheck_generator (stack Int.quickcheck_generator)) ~f:(fun (x, t) ->
[%test_result: int t] (pop_exn (push t x)) ~expect:t)

end
Expand Down Expand Up @@ -189,7 +189,7 @@ module Example_2_imperative = struct

let stack elt =
let open Generator in
List.gen elt
List.quickcheck_generator elt
>>| fun xs ->
let t = Imperative_stack.create () in
List.iter xs ~f:(fun x -> Imperative_stack.push t x);
Expand All @@ -198,32 +198,32 @@ module Example_2_imperative = struct
open Imperative_stack

let%test_unit "push + is_empty" =
Quickcheck.test (Generator.tuple2 String.gen (stack String.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 String.quickcheck_generator (stack String.quickcheck_generator)) ~f:(fun (x, t) ->
[%test_result: bool] (push t x; is_empty t) ~expect:false)

let%test_unit "push + pop_exn" =
Quickcheck.test (Generator.tuple2 String.gen (stack String.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 String.quickcheck_generator (stack String.quickcheck_generator)) ~f:(fun (x, t) ->
push t x;
let y = pop_exn t in
[%test_result: string] y ~expect:x)

let%test_unit "push + to_list" =
Quickcheck.test (Generator.tuple2 String.gen (stack String.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 String.quickcheck_generator (stack String.quickcheck_generator)) ~f:(fun (x, t) ->
let list1 = to_list t in
push t x;
let list2 = to_list t in
[%test_result: string list] list2 ~expect:(x :: list1))

let%test_unit "push + pop_exn + to_list" =
Quickcheck.test (Generator.tuple2 String.gen (stack String.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 String.quickcheck_generator (stack String.quickcheck_generator)) ~f:(fun (x, t) ->
let list1 = to_list t in
push t x;
let _ = pop_exn t in
let list2 = to_list t in
[%test_result: string list] list2 ~expect:list1)

let%test_unit "iter" =
Quickcheck.test (stack String.gen) ~f:(fun t ->
Quickcheck.test (stack String.quickcheck_generator) ~f:(fun t ->
let q = Queue.create () in
iter t ~f:(fun x -> Queue.enqueue q x);
[%test_result: string list] (Queue.to_list q) ~expect:(to_list t))
Expand Down Expand Up @@ -285,7 +285,7 @@ module Example_3_asynchronous = struct

let stack elt =
let open Generator in
List.gen elt
List.quickcheck_generator elt
>>| fun xs ->
let t = Async_stack.create () in
List.iter xs ~f:(fun x -> don't_wait_for (Async_stack.push t x));
Expand All @@ -294,32 +294,32 @@ module Example_3_asynchronous = struct
open Async_stack

let%test_unit "push + is_empty" =
Quickcheck.test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
don't_wait_for (push t x);
[%test_result: bool] (is_empty t) ~expect:false)

let%test_unit "push + to_list" =
Quickcheck.test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
let list1 = to_list t in
don't_wait_for (push t x);
let list2 = to_list t in
[%test_result: char list] list2 ~expect:(x :: list1))

let%test_unit "push + pushback" =
Quickcheck.test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
let pushback = push t x in
[%test_result: bool] (Deferred.is_determined pushback) ~expect:false)

let%test_unit "push + pop" =
Thread_safe.block_on_async_exn (fun () ->
Quickcheck.async_test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.async_test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
don't_wait_for (push t x);
pop t >>| fun y ->
[%test_result: char] y ~expect:x))

let%test_unit "push + pop + to_list" =
Thread_safe.block_on_async_exn (fun () ->
Quickcheck.async_test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.async_test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
let list1 = to_list t in
don't_wait_for (push t x);
pop t >>| fun _ ->
Expand All @@ -328,15 +328,15 @@ module Example_3_asynchronous = struct

let%test_unit "iter" =
Thread_safe.block_on_async_exn (fun () ->
Quickcheck.async_test (stack Char.gen) ~f:(fun t ->
Quickcheck.async_test (stack Char.quickcheck_generator) ~f:(fun t ->
let q = Queue.create () in
iter t ~f:(fun x -> Queue.enqueue q x; Deferred.unit)
>>| fun () ->
[%test_result: char list] (Queue.to_list q) ~expect:(to_list t)))

let%test_unit "push + pop + pushback" =
Thread_safe.block_on_async_exn (fun () ->
Quickcheck.async_test (Generator.tuple2 Char.gen (stack Char.gen)) ~f:(fun (x, t) ->
Quickcheck.async_test (Generator.tuple2 Char.quickcheck_generator (stack Char.quickcheck_generator)) ~f:(fun (x, t) ->
let pushback = push t x in
pop t >>| fun _ ->
[%test_result: bool] (Deferred.is_determined pushback) ~expect:(is_empty t)))
Expand Down
4 changes: 2 additions & 2 deletions example/quickcheck/from_wiki.ml
Expand Up @@ -6,7 +6,7 @@ let%test_unit "count vs length" =
(* (\* Initial example that fails on NaN: *\)
* (List.gen Float.gen) *)
(* Working example that filters out NaN: *)
(List.gen (Generator.filter Float.gen ~f:(Fn.non Float.is_nan)))
(List.quickcheck_generator (Generator.filter Float.quickcheck_generator ~f:(Fn.non Float.is_nan)))
(* (\* Simplest version: *\)
* (List.gen Float.gen_without_nan) *)
~sexp_of:[%sexp_of: float list]
Expand All @@ -28,5 +28,5 @@ let sexp_gen =
guarantees that the recursion will eventually bottom out. *)
Generator.(fixed_point (fun self ->
size >>= function
| 0 -> String.gen >>| fun atom -> Sexp.Atom atom
| 0 -> String.quickcheck_generator >>| fun atom -> Sexp.Atom atom
| _ -> list_gen self >>| fun list -> Sexp.List list))
12 changes: 6 additions & 6 deletions example/quickcheck/shrinker_example.ml
Expand Up @@ -13,18 +13,18 @@ module Sorted_list = struct

let to_list t = t

let gen elt =
let quickcheck_generator elt =
let open Generator.Monad_infix in
List.gen elt >>| of_list
List.quickcheck_generator elt >>| of_list

let custom_int_shrinker =
Shrinker.create (fun n ->
if n = 0
then Sequence.empty
else Sequence.singleton (n / 2))

let shrinker =
let list_shrinker = List.shrinker custom_int_shrinker in
let quickcheck_shrinker =
let list_shrinker = List.quickcheck_shrinker custom_int_shrinker in
Shrinker.map list_shrinker ~f:of_list ~f_inverse:to_list

let invariant t =
Expand All @@ -45,11 +45,11 @@ let%test_module "sorted list" =

let sorted_list_tuple_gen =
let int_gen = Int.gen_incl (-100) 100 in
let sorted_list_gen = Sorted_list.gen int_gen in
let sorted_list_gen = Sorted_list.quickcheck_generator int_gen in
Generator.tuple2 sorted_list_gen sorted_list_gen

let sorted_list_tuple_shrinker =
Shrinker.tuple2 Sorted_list.shrinker Sorted_list.shrinker
Shrinker.tuple2 Sorted_list.quickcheck_shrinker Sorted_list.quickcheck_shrinker

let test f (a,b) =
f a b |> Sorted_list.invariant
Expand Down
2 changes: 1 addition & 1 deletion src/command.ml
Expand Up @@ -208,7 +208,7 @@ module Arg_type = struct

let bool = of_alist_exn [("true", true); ("false", false)]

let comma_separated ~allow_empty ?key ?(strip_whitespace = false)
let comma_separated ?(allow_empty = false) ?key ?(strip_whitespace = false)
?(unique_values = false) t =
let strip =
if strip_whitespace
Expand Down
20 changes: 12 additions & 8 deletions src/command.mli
Expand Up @@ -67,15 +67,19 @@ module Arg_type : sig
-> (string -> 'a)
-> 'a t

(** [comma_separated t] accepts comma-separated lists of arguments parsed by [t]. If
[strip_whitespace = true], whitespace is stripped from each comma-separated string
before it is parsed by [t]. If [allow_empty = true] then the empty string (or just
whitespace, if [strip_whitespace = true]) results in an empty list, and if
[allow_empty = false] then the empty string will fail. If [unique_values = true] no
autocompletion will be offered for arguments already supplied in the fragment to
complete. *)
(** [comma_separated t] accepts comma-separated lists of arguments parsed by [t].
If [strip_whitespace = true], whitespace is stripped from each comma-separated
string before it is parsed by [t].
If [allow_empty = true] then the empty string (or just whitespace, if
[strip_whitespace = true]) results in an empty list, and if [allow_empty = false]
then the empty string will fail to parse.
If [unique_values = true] no autocompletion will be offered for arguments already
supplied in the fragment to complete. *)
val comma_separated
: allow_empty : bool
: ?allow_empty : bool (** default: [false] *)
-> ?key : 'a list Univ_map.Multi.Key.t
-> ?strip_whitespace : bool (** default: [false] *)
-> ?unique_values : bool (** default: [false] *)
Expand Down

0 comments on commit 74c79dd

Please sign in to comment.