Skip to content

Commit

Permalink
[Refactor]: Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
muqiuhan committed Mar 12, 2024
1 parent 027f2ce commit ef4724d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
Binary file modified .github/demo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 35 additions & 25 deletions README.md
Expand Up @@ -2,7 +2,7 @@

# Omtl

__OCaml Minimalist Testing Library__
__An OCaml minimalist testing framework with zero dependencies.__


![](https://github.com/muqiuhan/omtl/workflows/Linux/badge.svg)
Expand All @@ -18,54 +18,64 @@ minimum version

---

This is not a comprehensive test framework, just a library, about a hundred lines in size, containing only a few functions. The purpose is to provide an intuitive command line interface and write simple tests quickly.
> The purpose of this framework is to provide an intuitive command line interface and write simple tests quickly.
</div>

## Usage
[./test/test_omtl.ml](./test/test_omtl.ml)
```ocaml
open Omtl
(* A module with functions to test *)
module My_String = struct
let equal = String.equal
let capitalize = String.capitalize_ascii
let str_concat = String.concat ""
end
(* The tests *)
let test_equal () =
if My_String.equal "hello!" "hello!"
then ()
else fail "My_String.equal \"hello!\" = \"hello!\""
;;
if My_String.equal "hello!" "hello!" then
()
else
fail {| My_String.equal "hello!" = "hello!" |}
let test_capitalize () =
if String.equal "HELLO!" (My_String.capitalize "hELLO!")
then ()
else fail "My_String.capitalize \"hELLO!\" = \"HELLO!!\""
;;
if String.equal "HELLO!" (My_String.capitalize "hELLO!") then
()
else
fail {| My_String.capitalize "hELLO!" = "HELLO!!" |}
let test_str_concat () =
if String.equal "foobar" (My_String.str_concat [ "foo"; "bar" ])
then ()
else fail "My_String.str_concat [\"foo\"; \"bar\"] = \"foobar\""
;;
if String.equal "foobar" (My_String.str_concat ["foo"; "bar"]) then
()
else
fail {| My_String.str_concat ["foo"; "bar"] = "foobar" |}
let test_failure () = failwith "Take it easy, this is just an example of a failed test"
let test_exception () = raise Not_found
let test_failure () = fail "Take it easy, this is just an example of a failed test"
let test_undefined_exception () = raise Not_found
let test_function_running_time () = Unix.sleep 1
(* Run it *)
let _ =
"My_String withall"
+:> [ "equal" >== test_equal
; "capitalize" >== test_capitalize
; "str_concat" >== test_str_concat
; "Examples of test failures" >== test_failure
; "Examples of undefined exception" >== test_undefined_exception
; "Test function running time" >== test_function_running_time
"My_String"
+:> [
"equal" >== test_equal;
"capitalize" >== test_capitalize;
"str_concat" >== test_str_concat;
"Examples of test failures" >== test_failure;
"Examples of undefined exception" >== test_exception;
"Test function running time" >== test_function_running_time;
]
|> run ~color:true ~backtrace:true ~callstack:true
;;
|> run ~force:true ~backtrace:true ~callstack:true
```

## License
Expand Down

0 comments on commit ef4724d

Please sign in to comment.