Skip to content

Commit

Permalink
Add unit tests for get-activity-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetiot committed Mar 7, 2024
1 parent 0433303 commit 2769646
Show file tree
Hide file tree
Showing 10 changed files with 540 additions and 0 deletions.
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
(name get-activity-lib)
(synopsis "Collect activity as markdown")
(depends
(alcotest :with-test)
cohttp
cohttp-lwt
cohttp-lwt-unix
Expand Down
1 change: 1 addition & 0 deletions get-activity-lib.opam
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ homepage: "https://github.com/tarides/get-activity"
bug-reports: "https://github.com/tarides/get-activity/issues"
depends: [
"dune" {>= "2.8"}
"alcotest" {with-test}
"cohttp"
"cohttp-lwt"
"cohttp-lwt-unix"
Expand Down
47 changes: 47 additions & 0 deletions test/lib/alcotest_ext.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
open Alcotest

module Msg = struct
type 'a t = [ `Msg of 'a ]

let pp f fs (`Msg s : 'a t) = Format.fprintf fs "%a" f s
let eq f (`Msg s1 : 'a t) (`Msg s2 : 'a t) = f s1 s2

let testable t =
let pp = pp (Alcotest.pp t) in
let eq = eq (Alcotest.equal t) in
testable pp eq
end

let msg = Msg.testable
let string_msg = msg string
let or_msg x = result x string_msg

module Lwt = struct
type 'a t = 'a Lwt.t

let pp f fs (x : 'a t) =
let x = Lwt_main.run x in
Format.fprintf fs "%a" f x

let eq f (x : 'a t) (y : 'a t) =
let x = Lwt_main.run x in
let y = Lwt_main.run y in
f x y

let testable (t : 'a testable) : 'a t testable =
let pp = pp (Alcotest.pp t) in
let eq = eq (Alcotest.equal t) in
testable pp eq
end

let lwt = Lwt.testable

module Yojson = struct
type t = Yojson.Safe.t

let pp = Yojson.Safe.pp
let eq = Yojson.Safe.equal
let testable : t testable = testable pp eq
end

let yojson = Yojson.testable
8 changes: 8 additions & 0 deletions test/lib/alcotest_ext.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
val msg : 'a Alcotest.testable -> [ `Msg of 'a ] Alcotest.testable
val string_msg : [ `Msg of string ] Alcotest.testable

val or_msg :
'a Alcotest.testable -> ('a, [ `Msg of string ]) result Alcotest.testable

val lwt : 'a Alcotest.testable -> 'a Lwt.t Alcotest.testable
val yojson : Yojson.Safe.t Alcotest.testable
4 changes: 4 additions & 0 deletions test/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(test
(name main)
(package get-activity-lib)
(libraries get-activity-lib alcotest))
8 changes: 8 additions & 0 deletions test/lib/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
let () =
Alcotest.run "get-activity-lib"
[
Test_token.suite;
Test_period.suite;
Test_graphql.suite;
Test_contributions.suite;
]
Loading

0 comments on commit 2769646

Please sign in to comment.