Skip to content

Commit

Permalink
Merge pull request #25 from mbarbin/split-tests
Browse files Browse the repository at this point in the history
Refactor test directory
  • Loading branch information
mbarbin authored Oct 27, 2024
2 parents 9ca19b7 + ff5c57c commit 03b2d74
Show file tree
Hide file tree
Showing 39 changed files with 495 additions and 200 deletions.
20 changes: 9 additions & 11 deletions .github/workflows/more-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ jobs:
# We exclude the combination already tested in the 'ci' workflow.
- os: ubuntu-latest
ocaml-compiler: 5.2.x
# We exclude windows-4.14 - this fails when building core.
- os: windows-latest
ocaml-compiler: 4.14.x

runs-on: ${{ matrix.os }}

Expand All @@ -52,16 +55,11 @@ jobs:
# janestreet-bleeding: https://github.com/janestreet/opam-repository.git
# janestreet-bleeding-external: https://github.com/janestreet/opam-repository.git#external-packages

# We build and run tests for a subset of packages. More tests are run in
# the development workflow and as part of the main CI job. These are the
# tests that are checked for every combination of os and ocaml-compiler.
- name: Install dependencies
run: opam install ./provider.opam --deps-only --with-test
run: opam install ./provider.opam ./provider-tests.opam --deps-only --with-test

- name: Build
run: opam exec -- dune build @all -p provider

# For now, we only run tests for the `provider` package. Effectively, this
# runs nothing because the tests are in the `provider-test` package. We
# configured this in preparation for running the tests for specific
# packages only in the future, once we have a dedicated test suite that
# can run on every matrix combination configured here.
- name: Run tests
run: opam exec -- dune build @runtest -p provider
- name: Build & Run tests
run: opam exec -- dune build @all @runtest -p provider,provider-tests
2 changes: 1 addition & 1 deletion doc/docs/reference/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(mdx
(package provider-tests)
(package provider-dev)
(deps
(package provider)
(glob_files *.txt))
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/tutorials/getting-started/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(mdx
(package provider-tests)
(package provider-dev)
(deps
(package provider)
(glob_files *.txt))
Expand Down
2 changes: 1 addition & 1 deletion doc/docs/tutorials/handler-explicit/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(mdx
(package provider-tests)
(package provider-dev)
(deps
(package provider)
(glob_files *.txt))
Expand Down
56 changes: 55 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,64 @@
(>= 4.14))
(sexplib0
(and
(>= v0.17)
(>= v0.16)
(< v0.18)))))

(package
(name provider-tests)
(synopsis "Tests for provider")
(depends
(ocaml
(>= 4.14))
(base
(and
(>= v0.16)
(< v0.18)))
(expect_test_helpers_core
(and
(>= v0.16)
(< v0.18)))
(ppx_compare
(and
(>= v0.16)
(< v0.18)))
(ppx_enumerate
(and
(>= v0.16)
(< v0.18)))
(ppx_expect
(and
(>= v0.16)
(< v0.18)))
(ppx_hash
(and
(>= v0.16)
(< v0.18)))
(ppx_here
(and
(>= v0.16)
(< v0.18)))
(ppx_let
(and
(>= v0.16)
(< v0.18)))
(ppx_sexp_conv
(and
(>= v0.16)
(< v0.18)))
(ppx_sexp_value
(and
(>= v0.16)
(< v0.18)))
(ppxlib
(>= 0.33))
(provider
(= :version))))

(package
(name provider-dev)
(synopsis
"Package to regroup dev targets for the provider project, documentation, etc.")
(depends
(ocaml
(>= 5.2))
Expand Down Expand Up @@ -101,6 +153,8 @@
(>= 0.33))
(provider
(= :version))
(provider-tests
(= :version))
(sherlodoc
(and
:with-doc
Expand Down
51 changes: 51 additions & 0 deletions provider-dev.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# This file is generated by dune, edit dune-project instead
opam-version: "2.0"
synopsis:
"Package to regroup dev targets for the provider project, documentation, etc."
maintainer: ["Mathieu Barbin <opensource@mbarbin.org>"]
authors: ["Mathieu Barbin"]
license: "ISC"
homepage: "https://github.com/mbarbin/provider"
doc: "https://mbarbin.github.io/provider/"
bug-reports: "https://github.com/mbarbin/provider/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"ocamlformat" {with-dev-setup & = "0.26.2"}
"base" {>= "v0.17" & < "v0.18"}
"bisect_ppx" {with-dev-setup & >= "2.8.3"}
"eio" {>= "1.0"}
"eio_main" {>= "1.0"}
"expect_test_helpers_core" {>= "v0.17" & < "v0.18"}
"higher_kinded" {>= "v0.17" & < "v0.18"}
"mdx" {>= "2.4"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_expect" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
"ppx_here" {>= "v0.17" & < "v0.18"}
"ppx_js_style" {with-dev-setup & >= "v0.17" & < "v0.18"}
"ppx_let" {>= "v0.17" & < "v0.18"}
"ppx_sexp_conv" {>= "v0.17" & < "v0.18"}
"ppx_sexp_value" {>= "v0.17" & < "v0.18"}
"ppxlib" {>= "0.33"}
"provider" {= version}
"provider-tests" {= version}
"sherlodoc" {with-doc & >= "0.2"}
"odoc" {with-doc}
]
build: [
["dune" "subst"] {dev}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]
dev-repo: "git+https://github.com/mbarbin/provider.git"
30 changes: 11 additions & 19 deletions provider-tests.opam
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,19 @@ doc: "https://mbarbin.github.io/provider/"
bug-reports: "https://github.com/mbarbin/provider/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "5.2"}
"ocamlformat" {with-dev-setup & = "0.26.2"}
"base" {>= "v0.17" & < "v0.18"}
"bisect_ppx" {with-dev-setup & >= "2.8.3"}
"eio" {>= "1.0"}
"eio_main" {>= "1.0"}
"expect_test_helpers_core" {>= "v0.17" & < "v0.18"}
"higher_kinded" {>= "v0.17" & < "v0.18"}
"mdx" {>= "2.4"}
"ppx_compare" {>= "v0.17" & < "v0.18"}
"ppx_enumerate" {>= "v0.17" & < "v0.18"}
"ppx_expect" {>= "v0.17" & < "v0.18"}
"ppx_hash" {>= "v0.17" & < "v0.18"}
"ppx_here" {>= "v0.17" & < "v0.18"}
"ppx_js_style" {with-dev-setup & >= "v0.17" & < "v0.18"}
"ppx_let" {>= "v0.17" & < "v0.18"}
"ppx_sexp_conv" {>= "v0.17" & < "v0.18"}
"ppx_sexp_value" {>= "v0.17" & < "v0.18"}
"ocaml" {>= "4.14"}
"base" {>= "v0.16" & < "v0.18"}
"expect_test_helpers_core" {>= "v0.16" & < "v0.18"}
"ppx_compare" {>= "v0.16" & < "v0.18"}
"ppx_enumerate" {>= "v0.16" & < "v0.18"}
"ppx_expect" {>= "v0.16" & < "v0.18"}
"ppx_hash" {>= "v0.16" & < "v0.18"}
"ppx_here" {>= "v0.16" & < "v0.18"}
"ppx_let" {>= "v0.16" & < "v0.18"}
"ppx_sexp_conv" {>= "v0.16" & < "v0.18"}
"ppx_sexp_value" {>= "v0.16" & < "v0.18"}
"ppxlib" {>= "0.33"}
"provider" {= version}
"sherlodoc" {with-doc & >= "0.2"}
"odoc" {with-doc}
]
build: [
Expand Down
2 changes: 1 addition & 1 deletion provider.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bug-reports: "https://github.com/mbarbin/provider/issues"
depends: [
"dune" {>= "3.16"}
"ocaml" {>= "4.14"}
"sexplib0" {>= "v0.17" & < "v0.18"}
"sexplib0" {>= "v0.16" & < "v0.18"}
"odoc" {with-doc}
]
build: [
Expand Down
6 changes: 2 additions & 4 deletions test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
Expect_test_helpers_base)
(libraries
base
eio
eio_main
expect_test_helpers_core.expect_test_helpers_base
provider
test_interfaces
test_providers
unix)
(instrumentation
(backend bisect_ppx))
Expand All @@ -34,5 +34,3 @@
ppx_let
ppx_sexp_conv
ppx_sexp_value)))

(include_subdirs qualified)
39 changes: 39 additions & 0 deletions test/eio/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
(library
(name provider_test_eio)
(public_name provider-dev.provider_test_eio)
(inline_tests)
(flags
:standard
-w
+a-4-40-41-42-44-45-48-66
-warn-error
+a
-open
Base
-open
Expect_test_helpers_base)
(libraries
base
eio
eio_main
eio_test_providers
expect_test_helpers_core.expect_test_helpers_base
provider
test_interfaces
test_providers
unix)
(instrumentation
(backend bisect_ppx))
(lint
(pps ppx_js_style -check-doc-comments))
(preprocess
(pps
-unused-code-warnings=force
ppx_compare
ppx_enumerate
ppx_expect
ppx_hash
ppx_here
ppx_let
ppx_sexp_conv
ppx_sexp_value)))
20 changes: 11 additions & 9 deletions test/test__reader.ml → test/eio/test__reader.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ let with_temp_dir ~env ~path ~f =
let print_all_text_files t ~path =
print_s
[%sexp
(Interface.Directory_reader.find_files_with_extension t ~path ~ext:".txt"
(Test_interfaces.Directory_reader.find_files_with_extension t ~path ~ext:".txt"
: string list)]
;;

(* This function requires both [Directory_reader] and [File_reader]
capabilities. *)
let print_all_text_files_with_lines t ~path =
List.iter
(Interface.Directory_reader.find_files_with_extension t ~path ~ext:".txt")
(Test_interfaces.Directory_reader.find_files_with_extension t ~path ~ext:".txt")
~f:(fun file ->
let lines =
let contents = Interface.File_reader.load t ~path:(path ^ "/" ^ file) in
let contents = Test_interfaces.File_reader.load t ~path:(path ^ "/" ^ file) in
List.sum (module Int) (String.split_lines contents) ~f:(Fn.const 1)
in
print_s [%sexp { file : string; lines : int }])
Expand All @@ -47,14 +47,14 @@ let print_all_text_files_with_lines t ~path =
requiring it. *)
let print_all_text_files_with_lines_if_available t ~path =
List.iter
(Interface.Directory_reader.find_files_with_extension t ~path ~ext:".txt")
(Test_interfaces.Directory_reader.find_files_with_extension t ~path ~ext:".txt")
~f:(fun file ->
let lines =
let (Provider.T { t; handler }) = t in
match
Provider.Handler.lookup_opt
handler
~trait:Interface.File_reader.Provider_interface.File_reader
~trait:Test_interfaces.File_reader.Provider_interface.File_reader
with
| None -> "not-available"
| Some (module File_reader) ->
Expand All @@ -67,16 +67,18 @@ let print_all_text_files_with_lines_if_available t ~path =

(* Now let's put it all together in a test. *)
let%expect_test "test" =
let unix_reader = Providers.Unix_reader.make () in
let unix_reader = Test_providers.Unix_reader.make () in
Eio_main.run
@@ fun env ->
let eio_reader = Providers.Eio_reader.make ~env in
let eio_reader = Eio_test_providers.Eio_reader.make ~env in
with_temp_dir ~env ~path:"test" ~f:(fun dir ->
print_s
[%sexp (Interface.Directory_reader.readdir unix_reader ~path:dir : string list)];
[%sexp
(Test_interfaces.Directory_reader.readdir unix_reader ~path:dir : string list)];
[%expect {| () |}];
print_s
[%sexp (Interface.Directory_reader.readdir eio_reader ~path:dir : string list)];
[%sexp
(Test_interfaces.Directory_reader.readdir eio_reader ~path:dir : string list)];
[%expect {| () |}];
print_all_text_files unix_reader ~path:dir;
[%expect {| () |}];
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions test/eio/test_providers/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(library
(name eio_test_providers)
(public_name provider-dev.eio_test_providers)
(inline_tests)
(flags
:standard
-w
+a-4-40-41-42-44-45-48-66
-warn-error
+a
-open
Base
-open
Expect_test_helpers_base)
(libraries
base
eio
expect_test_helpers_core.expect_test_helpers_base
test_interfaces
provider
unix)
(instrumentation
(backend bisect_ppx))
(lint
(pps ppx_js_style -check-doc-comments))
(preprocess
(pps
-unused-code-warnings=force
ppx_compare
ppx_enumerate
ppx_expect
ppx_hash
ppx_here
ppx_let
ppx_sexp_conv
ppx_sexp_value)))
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ let make ~env : [ `Directory_reader | `File_reader ] Provider.t =
; handler =
Provider.Handler.make
[ Provider.Trait.implement
Interface.Directory_reader.Provider_interface.Directory_reader
Test_interfaces.Directory_reader.Provider_interface.Directory_reader
~impl:(module Impl)
; Provider.Trait.implement
Interface.File_reader.Provider_interface.File_reader
Test_interfaces.File_reader.Provider_interface.File_reader
~impl:(module Impl)
]
}
Expand Down
Loading

0 comments on commit 03b2d74

Please sign in to comment.