package eio

  1. Overview
  2. Docs
Effect-based direct-style IO API for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

eio-1.2.tbz
sha256=3792e912bd8d494bb2e38f73081825e4d212b1970cf2c1f1b2966caa9fd6bc40
sha512=4a80dbcf8cf2663bdad0f2970871844f37bd293c56bd1ce602910e0a613754945f1f942719f9630906453be7c73c1732dc97526c6c90b0b36100d04fd5e871e4

doc/eio.mock/Eio_mock/index.html

Module Eio_mockSource

Mocks for testing.

When testing an Eio program it is often convenient to use mock resources rather than real OS-provided ones. This allows precise control over the test, such as adding delays or simulated faults. You can always just implement the various Eio types directly, but this module provides some convenient pre-built mocks, and some helpers for creating your own mocks.

Mocks typically use Eio.traceln to record how they were used. This output can be recorded and compared against a known-good copy using e.g. ocaml-mdx.

Mocks may require configuration. For example, a source flow needs to know what data to return when the application reads from it. This can be done using the various on_* functions. For example:

  let stdin = Eio_mock.Flow.make "stdin" in
  let stdout = Eio_mock.Flow.make "stdout" in
  Eio_mock.Flow.on_read stdin [
    `Return "chunk1";
    `Return "chunk2";
    `Raise End_of_file
  ];
  Eio.Flow.copy stdin stdout

This will produce:

  +stdin: read "chunk1"
  +stdout: wrote "chunk1"
  +stdin: read "chunk2"
  +stdout: wrote "chunk2"

Configuration

Sourcemodule Action : sig ... end

Actions that can be performed by mock handlers.

Sourcemodule Handler : sig ... end

Control how a mock responds.

Pre-defined mocks

Sourcemodule Flow : sig ... end

Mock Eio.Flow sources and sinks.

Sourcemodule Net : sig ... end

Mock Eio.Net networks and sockets.

Sourcemodule Clock : sig ... end

A mock Eio.Time clock for testing timeouts.

Sourcemodule Domain_manager : sig ... end

A mock Eio.Domain_manager that runs everything in a single domain.

Backend for mocks

The mocks can be used with any backend, but if you don't need any IO then you can use this one to avoid a dependency on eio_main.

Sourcemodule Backend : sig ... end

A dummy Eio backend with no actual IO.

Mock errors

Sourcetype Eio.Exn.Backend.t +=
  1. | Simulated_failure
    (*

    A fake error code you can use for simulated faults.

    *)
OCaml

Innovation. Community. Security.