Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In_channel: Generate and shrink bytes only on length #375

Merged
merged 3 commits into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/io/lin_tests_spec_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@
(* Tests of in and out channels *)
(* ********************************************************************** *)

(* Try to find a text file rather than a binary to test In_channel, so
that input_line makes more sense *)
let in_file =
let path0 = Filename.dirname Sys.executable_name
and up p = Filename.concat p Filename.parent_dir_name
and candidate p = Filename.concat p "dune" in
let path1 = up path0 in
let path2 = up path1 in
let path3 = up path2 in
let path4 = up path3 in
let candidates = List.map candidate [ path0; path1; path2; path3; path4 ] in
let existing = List.filter Sys.file_exists candidates in
match existing with
| [] -> Sys.executable_name
| f :: _ -> f

module ICConf : Lin.Spec = struct
type t = In_channel.t

let init () = In_channel.open_bin Sys.argv.(0)
let init () = In_channel.open_bin in_file
let cleanup = In_channel.close

open Lin
let int,int64,bytes = nat_small,nat64_small,bytes_small
let int,int64 = nat_small,nat64_small

let bytes =
let open QCheck in
let zeroed_bytes n = Bytes.make n '\000' in
let shrink b = Iter.map zeroed_bytes (Shrink.int (Bytes.length b))
and gen = Gen.map zeroed_bytes Gen.small_nat in
let bytes = make ~shrink ~small:Bytes.length ~print:Print.bytes gen in
gen_deconstructible bytes (print Lin.bytes) Bytes.equal

let api = [
(* Only one t is tested, so skip stdin and opening functions *)
Expand Down