nim-ffi/tests/e2e/cpp/README.md
Ivan FB a3e68333ab
refactor(codegen): reconcile C++ header names with the native/cbor convention
Aligns the C++ generators with the C generator and the symbol naming: the
native (zero-serialization, same-process) wrapper is the bare `<lib>.hpp` and
the CBOR (inter-process) wrapper carries the `_cbor` suffix — mirroring the C
headers (`<lib>.h` / `<lib>_cbor.h`) and the `<name>` / `<name>_cbor` exports.

Previously native was `<lib>_native.hpp` and CBOR was the bare `<lib>.hpp`,
which is backwards from the symbol convention and would collide on the native
`<lib>.h` when both ABIs emit into one dir (ffiMode=both). With the flip, a
single `genbindings_cpp` run now drops `<lib>.hpp` + `<lib>_cbor.hpp` side by
side, exactly like c_bindings holds both `.h` headers.

Consumers updated to match: the CBOR cpp_bindings driver and the C++ e2e suite
include `*_cbor.hpp`; the native example includes the bare `<lib>.hpp`.

Validated: native example runs on `my_timer.hpp`; C++ e2e suite 19/19 on the
`_cbor.hpp` headers; check_bindings_cpp regen is deterministic.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-05-31 19:31:39 +02:00

37 lines
1.4 KiB
Markdown

# C++ end-to-end tests
These tests validate that a Nim FFI library exported with `nim-ffi`'s C++
codegen is usable from a real C++ consumer. They drive the `my_timer` example
through its auto-generated `my_timer_cbor.hpp` bindings (constructor, sync method,
async methods, complex types with optional fields, multiple contexts, error
propagation, async pipelines, short-lived-thread stress, concurrent hammer)
and assert the round-tripped values. The `CrossLibrary` test additionally
loads `examples/echo`'s `echo_cbor.hpp` alongside the timer to prove two
independent nim-ffi libraries coexist in one process with no symbol clash
and no shared global state.
## Layout
The suite reuses the generated bindings instead of duplicating the Nim build
glue:
- `CMakeLists.txt``add_subdirectory`s both
`examples/timer/cpp_bindings` (compiles `libmy_timer`, exposes
`my_timer_headers`) and `examples/echo/cpp_bindings` (compiles
`libecho`, exposes `echo_headers`). Fetches GoogleTest and registers
tests with CTest via `gtest_discover_tests`.
- `test_timer_e2e.cpp` — the test cases.
## Running
```sh
# 1. Generate the C++ bindings for both example libraries
nimble genbindings_cpp # → examples/timer/cpp_bindings/
nimble genbindings_cpp_echo # → examples/echo/cpp_bindings/
# 2. Configure + build + run the tests
cmake -S tests/e2e/cpp -B tests/e2e/cpp/build
cmake --build tests/e2e/cpp/build
ctest --test-dir tests/e2e/cpp/build --output-on-failure
```