Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #329 from samoht/better-tests
Remove oUnit, use alcotest properly
- Loading branch information
Showing
13 changed files
with
168 additions
and
142 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
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 |
---|---|---|
@@ -1,43 +1,24 @@ | ||
let (>>=) = Lwt.(>>=) | ||
open Lwt.Infix | ||
|
||
let fail fmt = Printf.ksprintf OUnit.assert_failure fmt | ||
let failf fmt = Fmt.kstrf Alcotest.fail fmt | ||
|
||
let or_error name fn t = | ||
fn t >>= function | ||
| Error _ -> fail "or_error starting %s" name | ||
| Error _ -> failf "or_error starting %s" name | ||
| Ok t -> Lwt.return t | ||
|
||
let expect_error error name fn t = | ||
fn t >>= function | ||
| Error error2 when error2 = error -> Lwt.return t | ||
| _ -> fail "expected error on %s" name | ||
| _ -> failf "expected error on %s" name | ||
|
||
let assert_string msg a b = | ||
let cmp a b = String.compare a b = 0 in | ||
OUnit.assert_equal ~msg ~printer:(fun x -> x) ~cmp a b | ||
|
||
let cstruct = | ||
let module M = struct | ||
type t = Cstruct.t | ||
let pp = Cstruct.hexdump_pp | ||
let equal = Cstruct.equal | ||
end in | ||
(module M : Alcotest.TESTABLE with type t = M.t) | ||
|
||
let ipv4_packet = (module Ipv4_packet : Alcotest.TESTABLE with type t = Ipv4_packet.t) | ||
let udp_packet = (module Udp_packet : Alcotest.TESTABLE with type t = Udp_packet.t) | ||
let tcp_packet = (module Tcp.Tcp_packet : Alcotest.TESTABLE with type t = Tcp.Tcp_packet.t) | ||
let ipv4_packet = Alcotest.testable Ipv4_packet.pp Ipv4_packet.equal | ||
let udp_packet = Alcotest.testable Udp_packet.pp Udp_packet.equal | ||
let tcp_packet = Alcotest.testable Tcp.Tcp_packet.pp Tcp.Tcp_packet.equal | ||
let cstruct = Alcotest.testable Cstruct.hexdump_pp Cstruct.equal | ||
|
||
let sequence = | ||
let module M = struct | ||
type t = Tcp.Sequence.t | ||
let pp = Tcp.Sequence.pp | ||
let equal x y = (=) 0 @@ Tcp.Sequence.compare x y | ||
end in | ||
(module M : Alcotest.TESTABLE with type t = M.t) | ||
|
||
let assert_bool msg a b = | ||
OUnit.assert_equal ~msg ~printer:string_of_bool a b | ||
let eq x y = Tcp.Sequence.compare x y = 0 in | ||
Alcotest.testable Tcp.Sequence.pp eq | ||
|
||
let assert_int msg a b = | ||
OUnit.assert_equal ~msg ~printer:string_of_int a b | ||
let options = Alcotest.testable Tcp.Options.pp Tcp.Options.equal |
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
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
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
Oops, something went wrong.