package eio
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=ead3eea352dd3d7d11a81ffdbeee6ca94d5e6b3f46de264b4e59689360b3ef38
sha512=0543643da7861f533f9b7ebee8aa30a6868b48ae1e19211666a9b860e9ff8d8a9e135f214a4603d0329f2027277701f6ffd900b6fba3405a538eebc301edaf29
doc/eio.mock/Eio_mock/index.html
Module Eio_mock
Source
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
Pre-defined mocks
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.