From 589f1e2a44999b5810bdde9a51647bcc12ccf4a0 Mon Sep 17 00:00:00 2001 From: Brendan Long Date: Thu, 7 May 2020 08:35:18 -0600 Subject: [PATCH] Opam improvements (#44) * Add odoc dependency * Add GitHub pages documentation * Skip the tests if environment variables are not set * Add documentation badge --- README.md | 1 + dune-project | 3 ++ mssql.opam | 2 ++ test/test_mssql.ml | 87 +++++++++++++++++++++++++++------------------- 4 files changed, 58 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 12ed9b2..6f6d703 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![CircleCI](https://circleci.com/gh/arenadotio/ocaml-mssql.svg?style=shield)](https://circleci.com/gh/arenadotio/ocaml-mssql) [![Coverage Status](https://coveralls.io/repos/github/arenadotio/ocaml-mssql/badge.svg?branch=master)](https://coveralls.io/github/arenadotio/ocaml-mssql?branch=master) +[![Documentation](https://img.shields.io/badge/documentation-odoc-blue)](https://arenadotio.github.io/ocaml-mssql/mssql/index.html) **Mssql** is an [Async](https://github.com/janestreet/async) OCaml SQL Server library, currently using [FreeTDS](https://github.com/kennknowles/ocaml-freetds). diff --git a/dune-project b/dune-project index efa8994..8bdf757 100644 --- a/dune-project +++ b/dune-project @@ -12,6 +12,8 @@ (authors "Arena Developers ") +(documentation "https://arenadotio.github.io/ocaml-mssql") + (source (github arenadotio/ocaml-mssql)) @@ -36,6 +38,7 @@ (>= 1.2)) (ocaml (>= 4.06.1)) + (odoc :with-doc) logs (text (>= 0.8.0)) diff --git a/mssql.opam b/mssql.opam index f2a1717..d457376 100644 --- a/mssql.opam +++ b/mssql.opam @@ -7,6 +7,7 @@ maintainer: ["Arena Developers "] authors: ["Arena Developers "] license: "Apache-2.0" homepage: "https://github.com/arenadotio/ocaml-mssql" +doc: "https://arenadotio.github.io/ocaml-mssql" bug-reports: "https://github.com/arenadotio/ocaml-mssql/issues" depends: [ "alcotest" {with-test & >= "1.0.1"} @@ -16,6 +17,7 @@ depends: [ "ppx_jane" "iter" {>= "1.2"} "ocaml" {>= "4.06.1"} + "odoc" {with-doc} "logs" "text" {>= "0.8.0"} "freetds" {>= "0.7"} diff --git a/test/test_mssql.ml b/test/test_mssql.ml index 5f6a940..62fe2a9 100644 --- a/test/test_mssql.ml +++ b/test/test_mssql.ml @@ -3,6 +3,19 @@ open Async_kernel open Async_unix module Row = Mssql.Row +exception Environment_variables_not_set + +let () = + Caml.Printexc.register_printer (function + | Environment_variables_not_set -> + Some + "Environment_variables_not_set. The following environment variables must be \ + set to run the Mssql tests: MSSQL_TEST_SERVER, MSSQL_TEST_DATABASE, \ + MSSQL_TEST_USERNAME, MSSQL_TEST_PASSWORD. Optionally, you can also set \ + MSSQL_TEST_PORT but it is not required." + | _ -> None) +;; + let params = lazy ([ "MSSQL_TEST_SERVER" @@ -15,7 +28,7 @@ let params = |> function | [ Some host; Some db; Some user; Some password; port ] -> host, db, user, password, Option.map ~f:Int.of_string port - | _ -> failwith "MSSQL_TEST_* environment not set") + | _ -> raise Environment_variables_not_set) ;; let with_test_conn f = @@ -603,38 +616,42 @@ let test_execute_pipe_error () = ;; let () = - Thread_safe.block_on_async_exn - @@ fun () -> - [ ( "all" - , [ "select and convert", test_select_and_convert - ; "multiple queries in execute", test_multiple_queries_in_execute - ; ( "multiple queries in execute_multi_result" - , test_multiple_queries_in_execute_multi_result ) - ; "test_not_result_queries_don't_count", test_not_result_queries_don't_count - ; "test_empty_result_sets_still_count", test_empty_result_sets_still_count - ; "execute_unit", test_execute_unit - ; "execute_unit fail", test_execute_unit_fail - ; "execute_single", test_execute_single - ; "execute_single fail", test_execute_single_fail - ; "test list order", test_order - ; "test params", test_param_parsing - ; "test param out of range", test_param_out_of_range - ; "test execute many", test_execute_many - ; "test concurrent queries", test_concurrent_queries - ; "test rollback", test_rollback - ; "test auto rollback", test_auto_rollback - ; "test commit", test_commit - ; "test auto commit", test_auto_commit - ; "test other execute during transaction", test_other_execute_during_transaction - ; "test prevent transaction deadlock", test_prevent_transaction_deadlock - ; "test exception in callback", test_exception_thrown_in_callback - ; "test exception with multiple results", test_exception_with_multiple_results - ; "test execute_pipe", test_execute_pipe - ; "test execute_pipe_error", test_execute_pipe_error - ] - @ round_trip_tests - @ recoding_tests - |> List.map ~f:(fun (name, f) -> Alcotest_async.test_case name `Quick f) ) - ] - |> Alcotest_async.run "mssql" + try + Lazy.force params |> ignore; + Thread_safe.block_on_async_exn + @@ fun () -> + [ ( "all" + , [ "select and convert", test_select_and_convert + ; "multiple queries in execute", test_multiple_queries_in_execute + ; ( "multiple queries in execute_multi_result" + , test_multiple_queries_in_execute_multi_result ) + ; "test_not_result_queries_don't_count", test_not_result_queries_don't_count + ; "test_empty_result_sets_still_count", test_empty_result_sets_still_count + ; "execute_unit", test_execute_unit + ; "execute_unit fail", test_execute_unit_fail + ; "execute_single", test_execute_single + ; "execute_single fail", test_execute_single_fail + ; "test list order", test_order + ; "test params", test_param_parsing + ; "test param out of range", test_param_out_of_range + ; "test execute many", test_execute_many + ; "test concurrent queries", test_concurrent_queries + ; "test rollback", test_rollback + ; "test auto rollback", test_auto_rollback + ; "test commit", test_commit + ; "test auto commit", test_auto_commit + ; "test other execute during transaction", test_other_execute_during_transaction + ; "test prevent transaction deadlock", test_prevent_transaction_deadlock + ; "test exception in callback", test_exception_thrown_in_callback + ; "test exception with multiple results", test_exception_with_multiple_results + ; "test execute_pipe", test_execute_pipe + ; "test execute_pipe_error", test_execute_pipe_error + ] + @ round_trip_tests + @ recoding_tests + |> List.map ~f:(fun (name, f) -> Alcotest_async.test_case name `Quick f) ) + ] + |> Alcotest_async.run "mssql" + with + | Environment_variables_not_set as e -> Caml.Printexc.to_string e |> Caml.print_endline ;;