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

Add Lin tests for Base.Buffer #323

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/base/buffer/BaseOrNoBase.fallback.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Buffer = Stdlib.Buffer

let _ = failwith "This is using a placeholder for compilation, do not run!"
1 change: 1 addition & 0 deletions src/base/buffer/BaseOrNoBase.passthrough.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module Buffer = Base.Buffer
12 changes: 12 additions & 0 deletions src/base/buffer/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(executable
(name lin_tests_dsl)
(libraries qcheck-lin.domain
(select BaseOrNoBase.ml from
(base -> BaseOrNoBase.passthrough.ml)
(-> BaseOrNoBase.fallback.ml))))

(rule
(alias runtest)
(package multicoretests)
(enabled_if %{lib-available:base})
(action (run %{dep:lin_tests_dsl.exe} --verbose)))
48 changes: 48 additions & 0 deletions src/base/buffer/lin_tests_dsl.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
module Buffer = BaseOrNoBase.Buffer

module BBConf = struct
type t = Buffer.t

let init () = Buffer.create 8
let cleanup _ = ()

open Lin
let int = nat_small
let char = char_printable
let string = string_small_printable

let api =
[
(* val_ "Buffer.sexp_of_t" Buffer.sexp_of_t (t @-> returning Sexplib0.Sexp.t); *)
(* Disabled due to missing Sexplib0.Sexp.t *)
(* val_ "Buffer.create" Buffer.create (int @-> returning t); *)
(* Disabled as returning t *)

val_ "Buffer.contents" Buffer.contents (t @-> returning_or_exc string);

(* val_ "Buffer.contents_bytes" Buffer.contents_bytes (t @-> returning bytes); *)
(* Disabled due to missing bytes *)

val_ "Buffer.nth" Buffer.nth (t @-> int @-> returning_or_exc char);
val_ "Buffer.length" Buffer.length (t @-> returning int);
val_ "Buffer.clear" Buffer.clear (t @-> returning unit);
val_ "Buffer.reset" Buffer.reset (t @-> returning unit);
val_ "Buffer.add_char" Buffer.add_char (t @-> char @-> returning_or_exc unit);
val_ "Buffer.add_string" Buffer.add_string (t @-> string @-> returning_or_exc unit);

(* val_ "Buffer.add_substring" Buffer.add_substring (t @-> string @-> int @-> int @-> returning_or_exc unit); *)
(* Disabled due to missing labels *)

(* val_ "Buffer.add_bytes" Buffer.add_bytes (t @-> bytes @-> returning unit); *)
(* val_ "Buffer.add_subbytes" Buffer.add_subbytes (t @-> bytes @-> int @-> int @-> returning unit); *)
(* Disabled due to missing bytes *)

(* val_ "Buffer.add_buffer" Buffer.add_buffer (t @-> t @-> unit); *)
]
end

module BBT_domain = Lin_domain.Make(BBConf)

let _ =
QCheck_base_runner.run_tests_main
[ BBT_domain.neg_lin_test ~count:1000 ~name:"Lin DSL Base Buffer test with Domain" ]