Commits

Oliver Gu committed 4c5e92c

Minor improvements of testing code

Comments (0)

Files changed (3)

lib_test/client_test.ml

         (module R : Response_intf.S with type t = R.t)
         ~expected:gen_server_time
         ~actual:server_time;
-      Log.Global.sexp ~level:`Debug server_time R.sexp_of_t)
+      Log.Global.sexp ~level:`Debug server_time R.sexp_of_t
+    )
   );
 
   "market-data" >:: (fun () ->
               ~expected:gen_tick
               ~actual:tick;
           Log.Global.sexp ~level:`Debug tick W.sexp_of_t)
-      ) ~finally:(fun _ -> Tws.cancel_market_data tws id))
+      ) ~finally:(fun _ -> Tws.cancel_market_data tws id)
+    )
   );
 
   "option-price" >:: (fun () ->
       >>| fun opt_price ->
       let gen_opt_price = Option.value_exn (R.option_price gen_tick_option) in
       assert (Price.(=.) gen_opt_price opt_price);
-      Log.Global.sexp ~level:`Debug opt_price Price.sexp_of_t)
+      Log.Global.sexp ~level:`Debug opt_price Price.sexp_of_t
+    )
   );
 
   "implied-volatility" >:: (fun () ->
       >>| fun implied_vol ->
       let gen_implied_vol = Option.value_exn (R.implied_volatility gen_tick_option) in
       assert (Float.(=.) gen_implied_vol implied_vol);
-      Log.Global.sexp ~level:`Debug implied_vol <:sexp_of< float >>)
+      Log.Global.sexp ~level:`Debug implied_vol <:sexp_of< float >>
+    )
   );
 
   "submit-orders" >:: (fun () ->
               ~expected:gen_order_state
               ~actual:order_state;
           Log.Global.sexp ~level:`Debug order_state R.sexp_of_t)
-      ) ~finally:(fun _ -> Tws.cancel_order_status tws oid))
+      ) ~finally:(fun _ -> Tws.cancel_order_status tws oid)
+    )
   );
 
   "filter-executions" >:: (fun () ->
             (module R : Response_intf.S with type t = R.t)
             ~expected:gen_execution_report
             ~actual:execution_report;
-        Log.Global.sexp ~level:`Debug execution_report R.sexp_of_t))
+        Log.Global.sexp ~level:`Debug execution_report R.sexp_of_t)
+    )
   );
 
   "contract-specs" >:: (fun () ->
         (module R : Response_intf.S with type t = R.t)
         ~expected:gen_contract_specs
         ~actual:contract_specs;
-      Log.Global.sexp ~level:`Debug contract_specs R.sexp_of_t)
+      Log.Global.sexp ~level:`Debug contract_specs R.sexp_of_t
+    )
   );
 
   "market-depth" >:: (fun () ->
               ~expected:gen_book_update
               ~actual:book_update;
             Log.Global.sexp ~level:`Debug book_update R.sexp_of_t)
-      ) ~finally:(fun _ -> Tws.cancel_market_depth tws id))
+      ) ~finally:(fun _ -> Tws.cancel_market_depth tws id)
+    )
   );
 
   "historical-data" >:: (fun () ->
         (module R : Response_intf.S with type t = R.t)
         ~expected:gen_historical_data
         ~actual:historical_data;
-      Log.Global.sexp ~level:`Debug historical_data R.sexp_of_t)
+      Log.Global.sexp ~level:`Debug historical_data R.sexp_of_t
+    )
   );
 
   "realtime-bars" >:: (fun () ->
               ~expected:gen_realtime_bar
               ~actual:realtime_bar;
             Log.Global.sexp ~level:`Debug realtime_bar R.sexp_of_t)
-      ) ~finally:(fun _ -> Tws.cancel_realtime_bars tws id))
+      ) ~finally:(fun _ -> Tws.cancel_realtime_bars tws id)
+    )
   );
 ]

lib_test/connection_test.ml

           try_handshake con
           >>= function
           | Ok _ -> assert false
-          | Error _ -> Ib.Connection.closed con))
-        ~finally:(fun ()-> Writer.close w)
+          | Error _ -> Ib.Connection.closed con
+        )
+      ) ~finally:(fun ()-> Writer.close w)
     );
 
     "handshake-unexpected-eof" >:: (fun () ->
         >>= function
         | Error _ -> assert false
         | Ok handshake_result ->
-          begin
-            match handshake_result with
-            | H.Eof -> Ib.Connection.closed con
-            | H.Server_header _ -> assert false
-            | H.Version_failure _ -> assert false
-          end)
+          match handshake_result with
+          | H.Eof -> Ib.Connection.closed con
+          | H.Server_header _ -> assert false
+          | H.Version_failure _ -> assert false
+      )
     );
 
     "handshake-version-failure" >:: (fun () ->
           let too_small_version = Int.to_string (Ibx.Std.Config.server_version-1) in
           Writer.write w (too_small_version ^@ "20121107 18:08:49 CET" ^@ "");
           try_handshake con
-          >>| function
+          >>= function
           | Error _ -> assert false
           | Ok handshake_result->
-            begin
-              match handshake_result with
-              | H.Eof -> assert false
-              | H.Server_header _ -> assert false
-              | H.Version_failure version ->
-                assert_string_equal
-                  ~expected:too_small_version
-                  ~actual:(Int.to_string version)
-            end))
-        ~finally:(fun () -> Writer.close w)
+            match handshake_result with
+            | H.Eof -> assert false
+            | H.Server_header _ -> assert false
+            | H.Version_failure version ->
+              assert_string_equal
+                ~expected:too_small_version
+                ~actual:(Int.to_string version);
+              Ib.Connection.close con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "successful-handshake" >:: (fun () ->
           Writer.write w (server_version ^@ server_time ^@ "");
           Writer.write w ("15" ^@ "1" ^@ account_code ^@ "");
           try_handshake con
-          >>| function
+          >>= function
           | Error _ -> assert false
           | Ok handshake_result ->
-            begin
-              match handshake_result with
-              | H.Eof -> assert false
-              | H.Version_failure _ -> assert false
-              | H.Server_header (`Version version, time, name) ->
-                assert_string_equal
-                  ~expected:server_version
-                  ~actual:(Int.to_string version);
-                assert_string_equal
-                  ~expected:server_time
-                  ~actual:(Time.to_string time);
-                assert_string_equal
-                  ~expected:account_code
-                  ~actual:(Account_code.to_string name)
-            end))
-        ~finally:(fun () -> Writer.close w)
+            match handshake_result with
+            | H.Eof -> assert false
+            | H.Version_failure _ -> assert false
+            | H.Server_header (`Version version, time, name) ->
+              assert_string_equal
+                ~expected:server_version
+                ~actual:(Int.to_string version);
+              assert_string_equal
+                ~expected:server_time
+                ~actual:(Time.to_string time);
+              assert_string_equal
+                ~expected:account_code
+                ~actual:(Account_code.to_string name);
+              Ib.Connection.close con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
   ]
 end
             server_time con
             >>= function
             | Ok _ -> assert false
-            | Error _ -> Ib.Connection.closed con))
-          ~finally:(fun () -> Writer.close w))
+            | Error _ -> Ib.Connection.closed con
+          )
+        ) ~finally:(fun () -> Writer.close w))
     );
 
     "missing-response-handler" >:: (fun () ->
           >>= fun () ->
           Writer.write w ("49" ^@ "1" ^@ "1352386125" ^@ "");
           Ib.Request.dispatch buggy_req con (Query.Server_time.create ())
-          >>| function
+          >>= function
           | Ok _ -> assert false
-          | Error _ -> assert (Ib.Connection.is_closed con)))
-        ~finally:(fun () -> Writer.close w)
+          | Error _ -> Ib.Connection.closed con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "handler-parse-error" >:: (fun () ->
           server_time con
           >>= function
           | Ok _ -> assert false
-          | Error _ -> Ib.Connection.closed con))
-        ~finally:(fun () -> Writer.close w)
+          | Error _ -> Ib.Connection.closed con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "handler-no-input" >:: (fun () ->
         server_time con
         >>= function
         | Ok _ -> assert false
-        | Error _ -> Ib.Connection.closed con)
+        | Error _ -> Ib.Connection.closed con
+      )
     );
 
     "successful-dispatch" >:: (fun () ->
           | Error _ -> assert false
           | Ok _time ->
             assert (not (Ib.Connection.is_closed con));
-            Ib.Connection.close con))
-        ~finally:(fun () -> Writer.close w)
+            Ib.Connection.close con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
   ]
 end
             tick_size con
             >>= function
             | Ok _ -> assert false
-            | Error _ -> Ib.Connection.closed con))
-          ~finally:(fun () -> Writer.close w))
+            | Error _ -> Ib.Connection.closed con
+          )
+        ) ~finally:(fun () -> Writer.close w))
     );
 
     "handler-parse-error" >:: (fun () ->
           tick_size con
           >>= function
           | Ok _ -> assert false
-          | Error _ ->
-            Ib.Connection.closed con))
-        ~finally:(fun () -> Writer.close w)
+          | Error _ -> Ib.Connection.closed con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "update-parse-error" >:: (fun () ->
           >>= function
           | Ok (pipe_r, _id) ->
             Ib.Connection.closed con
-            >>| fun () ->
-            assert (Pipe.is_closed pipe_r);
-          | Error _ -> assert false))
-        ~finally:(fun () -> Writer.close w)
+            >>= fun () ->
+            Pipe.closed pipe_r
+          | Error _ -> assert false
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "cancel-streaming" >:: (fun () ->
             assert (Pipe.is_closed pipe_r);
             Ib.Connection.close con
             >>= fun () ->
-            Ib.Connection.closed con))
-        ~finally:(fun () -> Writer.close w)
+            Ib.Connection.closed con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
 
     "unpickler-mismatch" >:: (fun () ->
           Ib.Streaming_request.dispatch buggy_req con (Rg.Q.market_data_g ())
           >>= function
           | Ok _ -> assert false
-          | Error _ -> Ib.Connection.closed con))
-        ~finally:(fun () -> Writer.close w)
+          | Error _ -> Ib.Connection.closed con
+        )
+      ) ~finally:(fun () -> Writer.close w)
     );
   ]
 

lib_test/test_runner.ml

 open Core.Std
 open Async.Std
 
-let run_cmd = Command.async_basic
-  ~summary:"Run test suite."
-  Command.Spec.(
-    empty
-    +> flag "-d" no_arg ~doc:" log debug messages"
-  )
-  (fun debug () ->
-    let cwd = Core.Std.Unix.getcwd () in
-    let logfile = cwd ^/ "ibx.log" in
-    Log.Global.set_output [Log.Output.file `Text ~filename:logfile];
-    if debug then Log.Global.set_level `Debug;
-    Test_lib.run "ibx" [
-      Pickle_test.suite;
-      Connection_test.Handshake.suite;
-      Connection_test.Request.suite;
-      Connection_test.Streaming_request.suite;
-      Client_test.suite;
-    ] >>| fun exit_code -> shutdown exit_code
-  )
-
-let () = Command.run run_cmd
+let command =
+  Command.async_basic ~summary:"Run test suite."
+    Command.Spec.(
+      empty
+      +> flag "-d" no_arg ~doc:" log debug messages"
+    )
+    (fun debug () ->
+      let cwd = Core.Std.Unix.getcwd () in
+      let logfile = cwd ^/ "ibx.log" in
+      Log.Global.set_output [Log.Output.file `Text ~filename:logfile];
+      if debug then Log.Global.set_level `Debug;
+      Test_lib.run "ibx" [
+        Pickle_test.suite;
+        Connection_test.Handshake.suite;
+        Connection_test.Request.suite;
+        Connection_test.Streaming_request.suite;
+        Client_test.suite;
+      ] >>| fun exit_code -> shutdown exit_code
+    )
+
+let () = Command.run command
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.