forked from gersonmoraes/dryunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
245a279
commit 992a4e0
Showing
11 changed files
with
477 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ clean: | |
@jbuilder clean | ||
|
||
test: | ||
@#NOCOLORS=1 jbuilder runtest | ||
@jbuilder runtest | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
(* Monad type placeholder *) | ||
type 'a m = 'a | ||
|
||
(* Placeholder for the one parameter all test functions should have *) | ||
type arg = unit | ||
|
||
(* Signature for test functions in this test framework *) | ||
type callback = | ||
| Fun : (arg -> unit) -> callback | ||
| Opt : (arg -> 'a option) -> callback | ||
| Res : (arg -> ('ok, 'err) result) -> callback | ||
| Async_fun : (arg -> unit m) -> callback | ||
| Async_opt : (arg -> 'a option m) -> callback | ||
| Async_res : (arg -> ('ok, 'err) result m) -> callback | ||
|
||
(* Internals of a test *) | ||
type test = | ||
{ test_name : string | ||
; test_loc : string | ||
; test_fqdn : string | ||
; test_callback : callback | ||
; test_long : bool | ||
} | ||
|
||
type suite_ctx = | ||
{ ctx_name : string | ||
; ctx_title : string | ||
; ctx_path : string | ||
} | ||
|
||
(* Internals of a test suite *) | ||
type suite = | ||
{ suite_name : string | ||
; suite_path : string | ||
; tests : test list | ||
; mutable has_errors : bool | ||
} | ||
|
||
(* Creating a new test *) | ||
let test ~loc ~fqdn | ||
~(f:callback) test_name | ||
: test | ||
= | ||
{ test_name | ||
; test_loc = loc | ||
; test_fqdn = fqdn | ||
; test_callback = f | ||
; test_long = false | ||
} | ||
|
||
let suite ~tests ~path suite_name : suite = | ||
{ suite_name | ||
; suite_path = path | ||
; tests = tests | ||
; has_errors = false | ||
} | ||
|
||
let suite_ctx ~name ~title ~path = | ||
{ ctx_name = name | ||
; ctx_title = title | ||
; ctx_path = path | ||
} | ||
|
||
(* XXX: | ||
This is the Api used to wrap test functions with the matching modifiers. | ||
By default, all modifiers should be inactive. | ||
*) | ||
|
||
let wrap_fun f : callback = Fun f | ||
let wrap_opt f : callback = Opt f | ||
let wrap_res f : callback = Res f | ||
|
||
let wrap_async_fun f : callback = Async_fun f | ||
let wrap_async_opt f : callback = Async_opt f | ||
let wrap_async_res f : callback = Async_res f | ||
|
||
|
||
|
||
let suite ~ctx:info ~(tests:test list) : suite = | ||
{ suite_name = info.ctx_title | ||
; suite_path = info.ctx_path | ||
; tests | ||
; has_errors = false | ||
} | ||
|
||
let test | ||
test_desc | ||
~ctx | ||
~name:test_name | ||
~f | ||
~loc | ||
: test | ||
= | ||
let _ : suite_ctx = ctx in | ||
{ test_name = test_desc | ||
; test_long = true | ||
; test_callback = f | ||
; test_loc = loc | ||
; test_fqdn = (Printf.sprintf "%s.%s" ctx.ctx_name test_name) | ||
} | ||
|
||
let run (suites: suite list) = | ||
failwith "DRYUNIT FRAMEWORK IS NOT READY TO RUN" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
let next_int ~pos ~buf s : int = | ||
let is_digit c = | ||
( match c with | ||
| '0' .. '9' -> true | ||
| _ -> false | ||
) in | ||
while not (is_digit s.[!pos]) do | ||
incr pos; | ||
done; | ||
Buffer.clear buf; | ||
while is_digit s.[!pos] do | ||
Buffer.add_char buf s.[!pos]; | ||
incr pos; | ||
done; | ||
int_of_string (Buffer.contents buf) | ||
|
||
|
||
let parse_loc loc = | ||
let buf, pos = Buffer.create 3, ref 1 in | ||
let next () = next_int ~pos ~buf loc in | ||
let line = next () in | ||
let start = | ||
let _ = next () in | ||
next () in | ||
let length = | ||
let _ = next (), next () in | ||
next () - start in | ||
line, start, length |
Oops, something went wrong.