Skip to content

Commit

Permalink
Fixed unification + lwt bugs, added tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
vbmithr committed Jun 10, 2013
1 parent 1939b23 commit f01e274
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0.1 (2013-06-09):
0.1 (2013-06-10):
* first alpha release
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
* Fix Lwt type unification bug (that renders it unusable)
* Async backend ?
4 changes: 2 additions & 2 deletions lib/smtp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ module Make (IO : IO) = struct

let finally f g =
try
let ret = f () in g (); ret
with exn -> g (); IO.fail exn
f () >>= fun ret -> g () >>= fun () -> IO.return ret
with exn -> g () >>= fun () -> IO.fail exn

let sendmail ?(host="") ?(port="smtp") ~name ~from ~to_ ~body () =
connect ~host ~port ~name () >>= fun h ->
Expand Down
2 changes: 1 addition & 1 deletion lwt/smtp_lwt.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module IO : Smtp.IO = struct
module IO = struct
type 'a t = 'a Lwt.t
let return = Lwt.return
let bind = Lwt.bind
Expand Down
14 changes: 13 additions & 1 deletion smtp.obuild
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,22 @@ library smtp

library smtp_unix
modules: Smtp_unix
builddepends: smtp
builddepends: smtp, unix
src-dir: unix

library smtp_lwt
modules: Smtp_lwt
builddepends: smtp, lwt, lwt.unix
src-dir: lwt

test test_lwt
mainis: test_lwt.ml
builddepends: smtp_lwt
src-dir: test
rundir: test

test test_unix
mainis: test_unix.ml
builddepends: smtp_unix
src-dir: test
rundir: test
11 changes: 11 additions & 0 deletions test/test_lwt.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Smtp_lwt

let () = match Lwt_main.run
(sendmail
~port:"2525"
~name:"localhost"
~from:Addr.(of_string "[email protected]")
~to_:[Addr.(of_string "[email protected]")]
~body:"Bleh" ()) with
| `Ok (code, msg) -> Printf.printf "OK %d %s\n" code msg
| `Failure (code, msg) -> Printf.eprintf "Failure %d %s\n" code msg
11 changes: 11 additions & 0 deletions test/test_unix.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
open Smtp_unix

let () = match
(sendmail
~port:"2525"
~name:"localhost"
~from:Addr.(of_string "[email protected]")
~to_:[Addr.(of_string "[email protected]")]
~body:"Bleh" ()) with
| `Ok (code, msg) -> Printf.printf "OK %d %s\n" code msg
| `Failure (code, msg) -> Printf.eprintf "Failure %d %s\n" code msg
2 changes: 1 addition & 1 deletion unix/smtp_unix.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module IO : Smtp.IO = struct
module IO = struct
type 'a t = 'a
let return v = v
let bind v f = f v
Expand Down

0 comments on commit f01e274

Please sign in to comment.