From b945cd13357ee986c934afa3a1d4d2d4f9f9f960 Mon Sep 17 00:00:00 2001 From: Andreas Steinbart Date: Sun, 9 Aug 2026 09:19:32 +0000 Subject: [PATCH] =?UTF-8?q?docs:=20restore=20the=20README=20shape=20CORELI?= =?UTF-8?q?B=5FPLAN=20=C2=A79=20prescribes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit §9 fixes the section list and its order for every corelib README — "do not change the section ordering and do not invent new top-level sections" — because that shared shape is what lets a reader who knows one port navigate any other. This README had drifted from it in three places: * `## Choosing between the two C++ corelibs` was a top-level section after `## Benchmarks`. §9.8 makes exactly this comparison the *final subsection* of Benchmarks when a language ships two corelibs for two use cases, so it is demoted to `###` (and its Callgrind table with it). Anchors are unchanged, so the links into it still resolve. * `## Feature flags` was an invented section covering one knob, `SOFAB_STRICT_UTF8`, already documented under Usage. Its content folds into that subsection: the knob is the only one, and the header always compiles the full wire format. * The §9.2 badge block carried Coverage and Docs only; §9.2 asks for CI, coverage and Docs. The x86_64 GCC build badge now opens the block, and the per-target table stays as the full matrix. The shape is a property of the document, so no C++ test can see it drift — the new `test_readme_structure` suite reads README.md and checks the §9.1 header block, the §9.2 badge block and its order, the exact §9 top-level section list, §9.4 (no API-documentation section) and the §9.8 placement of the two-corelib comparison. It fails on the previous README with exactly these four findings, skips when a tree carries no README, and runs under CTest beside the existing document-level check, `test_ci_workflows`. Closes #91 --- README.md | 43 +++++----- test/CMakeLists.txt | 12 +++ test/test_readme_structure.sh | 152 ++++++++++++++++++++++++++++++++++ 3 files changed, 188 insertions(+), 19 deletions(-) create mode 100755 test/test_readme_structure.sh diff --git a/README.md b/README.md index add2862..45436e8 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ## SofaBuffers C++ library +[![CI](https://github.com/sofa-buffers/corelib-cpp/actions/workflows/build-gcc-x86_64.yaml/badge.svg?branch=main)](https://github.com/sofa-buffers/corelib-cpp/actions/workflows/build-gcc-x86_64.yaml) [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/sofa-buffers/corelib-cpp/badges/coverage-cpp.json)](https://github.com/sofa-buffers/corelib-cpp/actions/workflows/coverage.yaml) [![Docs](https://img.shields.io/badge/docs-online-blue)](https://sofa-buffers.github.io/corelib-cpp/) @@ -44,7 +45,9 @@ C backend. Non-native targets are built and run under [QEMU](https://www.qemu.org/) user-mode emulation in CI, reproducible locally without the real hardware. Both x86_64 legs build and run the full suite twice — in `Debug` **and** in `Release` -(`-O3 -DNDEBUG`) — so a defect only the optimiser exposes cannot ship green. +(`-O3 -DNDEBUG`) — so a defect only the optimiser exposes cannot ship green. The +**CI** badge at the top of this section tracks the first row; the table is the +whole matrix. | Target | Status | | - | - | @@ -312,6 +315,15 @@ option is a validation *policy*, never a wire-format switch, so peers with different settings interoperate on all valid data; conformance and the shared vectors run with it **ON**. +`SOFAB_STRICT_UTF8` is also the **only** compile-time knob this library has: the +header always compiles the full wire format, with no `#ifdef` gating of wire +types and nothing else to configure. (The conformance harness recognises the +family's `SOFAB_DISABLE_*` names only so it can skip the matching vectors when +validating a feature-reduced profile; the defines do **not** change this +library.) For a strictly minimal binary, use the C corelib +[`corelib-c-cpp`](https://github.com/sofa-buffers/corelib-c-cpp), which does gate +wire features. + ### Code generator The usual way to drive the library is through **generated object code**: a schema @@ -648,21 +660,6 @@ These three types are deliberately identical, in name and behaviour, to `corelib-c-cpp`'s, so generated code for a bounded field is the same whichever C++ corelib it targets. -## Feature flags - -**Almost none.** This header-only C++20 port always compiles the full wire -format — there is no `#ifdef` gating of wire types and nothing to configure. (The -conformance harness recognises the family's `SOFAB_DISABLE_*` names only so it can -skip the matching vectors when validating a feature-reduced profile; the defines -do **not** change this library.) For a strictly minimal binary, use the C corelib -[`corelib-c-cpp`](https://github.com/sofa-buffers/corelib-c-cpp). - -The one compile-time knob is **`SOFAB_STRICT_UTF8`** (default `1`): the strict -UTF-8 validation policy documented under -[Strict UTF-8 validation](#strict-utf-8-validation-sofab_strict_utf8-default-on). -Define it to `0` for a non-strict build that stores `string` payloads verbatim -(raw, never lossy). It gates a validation policy only, never the wire format. - ## Build & test ```sh @@ -680,7 +677,7 @@ Run it in both configurations — `-DCMAKE_BUILD_TYPE=Debug` and (strict aliasing, UB the optimiser acts on, an uninitialised field) is invisible to a Debug-only run. -Four suites run under CTest: +Five suites run under CTest: - **`test_roundtrip`** — encode/decode/nested/chunked/skip checks plus the three-valued decode outcome (§7: COMPLETE / INCOMPLETE / INVALID), malformed-input @@ -728,6 +725,14 @@ Four suites run under CTest: strategy matrix sets `fail-fast: false`. `${{ matrix.build_type }}` is resolved against the workflow's own `build_type:` axis. Skipped in a source tree without `.github/workflows/`. +- **`test_readme_structure`** — the other document-level check: CORELIB_PLAN §9 + fixes this README's section list, their order and the badge block for the whole + corelib family, and nothing in the library can notice that shape drifting. It + reads `README.md` and requires the §9.1 header block, a §9.2 badge block + carrying CI, coverage and Docs in that order, exactly the §9 top-level sections + with no invented ones, no API-documentation section (§9.4), and the §9.8 + two-corelib comparison as a subsection of + [Benchmarks](#benchmarks). Skipped in a tree without a README. ### Coverage and API docs @@ -785,7 +790,7 @@ build/bench/bench encode_typical # one operation, then exit (Callgrind mode) `ctest -R test_bench_tools` guards that sharing. -## Choosing between the two C++ corelibs +### Choosing between the two C++ corelibs SofaBuffers ships **two** C++ implementations of the same wire format, tuned for opposite ends of the spectrum: @@ -810,7 +815,7 @@ porting between them is mostly mechanical. | Feature gating | Always full format (no `#ifdef`) | `SOFAB_DISABLE_*` compile out unused wire features | | Target | Desktop / server | Bare metal / embedded C and C++ | -### Instruction counts (Callgrind) +#### Instruction counts (Callgrind) Machine-independent instruction counts from the shared benchmark tooling, this library against the C corelib and its C++ wrapper on identical workloads (lower diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index cda70fc..cdc3401 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -37,6 +37,18 @@ add_test(NAME test_ci_workflows ${PROJECT_SOURCE_DIR}/.github/workflows) set_tests_properties(test_ci_workflows PROPERTIES SKIP_RETURN_CODE 77) +# CORELIB_PLAN §9 fixes the README's section list, their order, and the §9.2 +# badge block for the whole corelib family — the shared shape is what makes one +# port's README navigable to a reader who knows another. That is a property of +# the document, so no C++ test can notice it drifting: this check reads +# README.md and fails on an invented or reordered top-level section, a missing +# CI/coverage/Docs badge, or the §9.8 two-corelib comparison escaping from +# under `## Benchmarks`. +add_test(NAME test_readme_structure + COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/test_readme_structure.sh + ${PROJECT_SOURCE_DIR}/README.md) +set_tests_properties(test_readme_structure PROPERTIES SKIP_RETURN_CODE 77) + if(SOFAB_ENABLE_COVERAGE) target_link_libraries(test_roundtrip PRIVATE sofab_coverage) target_link_libraries(test_vectors PRIVATE sofab_coverage) diff --git a/test/test_readme_structure.sh b/test/test_readme_structure.sh new file mode 100755 index 0000000..73178bb --- /dev/null +++ b/test/test_readme_structure.sh @@ -0,0 +1,152 @@ +#!/usr/bin/env bash +# +# SofaBuffers pure-C++20 — guards README.md against CORELIB_PLAN §9. +# +# §9 fixes the README's shape for the whole corelib family: "Do not change the +# section ordering and do not invent new top-level sections; that shared shape +# is the point." A reader who knows one port's README navigates any other by +# looking in the same place. Nothing inside the library can notice when that +# shape drifts — a top-level section that exists in no other port, or a missing +# badge, is invisible to every C++ test — so the check has to read the document. +# +# What it enforces: +# +# 1. §9.1 the centered header block: logo, `# SofaBuffers`, tagline, org link. +# 2. §9.2 the badge block that opens the library section carries a CI badge, a +# coverage badge and a Docs badge, in that order, before any prose. +# 3. §9 the `## ` sections are exactly the prescribed list, in order: +# `## SofaBuffers library`, `## Why this design`, `## Usage`, +# `## Memory handling`, `## Build & test`, `## Benchmarks` — no extras. +# 4. §9.4 no API-documentation section at any heading level; the Docs badge is +# the only pointer to the generated reference. +# 5. §9.8 C++ is a language with two corelibs, so the comparison between them +# is a *subsection* of `## Benchmarks` — its final one — not a section of +# its own after it. +# +# Usage: test_readme_structure.sh +# +# SPDX-License-Identifier: MIT +set -uo pipefail + +README="${1:?usage: test_readme_structure.sh }" + +# CTest maps 77 to "skipped" (SKIP_RETURN_CODE): a consumer tree that vendored +# only the header has no README to check. +if [ ! -f "$README" ]; then + echo "SKIP: no README at $README" + exit 77 +fi + +fails=0 +fail() { echo "FAIL: $*" >&2; fails=$((fails + 1)); } +ok() { echo " ok: $*"; } + +# Headings are read from a copy with fenced code blocks blanked out: a shell +# comment inside a ```sh block is not a section, and the Build & test snippets +# are full of them. +PROSE="$(mktemp)" +trap 'rm -f "$PROSE"' EXIT +awk '/^```/ { fence = !fence; print ""; next } fence { print "" ; next } { print }' \ + "$README" > "$PROSE" + +# ---------------------------------------------------------------- §9.1 header + +grep -q '

Structured Objects For Anyone
' "$README" \ + && ok "§9.1 tagline" || fail "§9.1 tagline missing" +grep -q 'https://github.com/sofa-buffers' "$README" \ + && ok "§9.1 organization link" || fail "§9.1 link back to the organization missing" + +# ------------------------------------------------------- §9 top-level sections + +# The section list §9 prescribes, in order. The first is the only one whose +# wording varies per port (`## SofaBuffers library`). +expected="## SofaBuffers C++ library +## Why this design +## Usage +## Memory handling +## Build & test +## Benchmarks" + +actual="$(grep -E '^## ' "$PROSE")" + +if [ "$actual" = "$expected" ]; then + ok "§9 top-level sections are the prescribed list, in order" +else + fail "§9 top-level sections differ from the prescribed list (no invented sections, no reordering)" + diff <(printf '%s\n' "$expected") <(printf '%s\n' "$actual") \ + | sed 's/^/ /' >&2 +fi + +# --------------------------------------------------------- §9.2 badge block + +# Everything between the library heading and the first blank line after it: §9.2 +# puts the badges first in the section, ahead of the GitHub link and the summary. +badges="$(awk ' + /^## SofaBuffers .* library$/ { inside = 1; next } + inside && /^[[:space:]]*$/ { if (seen) exit; next } + inside { seen = 1; print } +' "$PROSE")" + +if [ -z "$badges" ]; then + fail "§9.2 the library section opens with no badge block" +else + # Badge alt texts, in document order: "[![CI](…)](…)" -> "CI". + order="$(printf '%s\n' "$badges" | grep -oE '^\[!\[[^]]*\]' | sed 's/^\[!\[//; s/\]$//')" + for want in CI Coverage Docs; do + printf '%s\n' "$order" | grep -qi "^${want}\$" \ + && ok "§9.2 badge block carries a $want badge" \ + || fail "§9.2 badge block carries no $want badge (it has:$(printf ' %s' $order))" + done + # …and in the order §9.2 lists them: CI, coverage, Docs. + ranked="$(printf '%s\n' "$order" | grep -iE '^(CI|Coverage|Docs)$' | tr 'A-Z' 'a-z')" + if [ "$ranked" = "$(printf 'ci\ncoverage\ndocs')" ]; then + ok "§9.2 badges are in the CI / coverage / Docs order" + else + fail "§9.2 badges out of order: expected CI, coverage, Docs — got$(printf ' %s' $ranked)" + fi +fi + +# ------------------------------------------------ §9.4 no API-doc section + +if grep -qiE '^#+ +(source documentation|api reference|api documentation|api docs)[[:space:]]*$' "$PROSE"; then + fail "§9.4 an API-documentation section exists; the Docs badge is the only pointer" +else + ok "§9.4 no API-documentation section" +fi + +# ------------------------------------- §9.8 two-corelib comparison placement + +# C++ ships two corelibs for two use cases, so §9.8 requires the comparison as a +# final *subsection* of `## Benchmarks`. +compare_heading="$(grep -nE '^#+ +Choosing between the two' "$PROSE" | head -1)" +if [ -z "$compare_heading" ]; then + fail "§9.8 no subsection comparing the two C++ corelibs" +else + level="${compare_heading#*:}" + level="${level%% *}" + if [ "$level" = "###" ]; then + ok "§9.8 the two-corelib comparison is a subsection" + else + fail "§9.8 the two-corelib comparison is a '$level' heading; §9.8 makes it a '###' subsection of ## Benchmarks" + fi + # …and it must sit under Benchmarks, which is therefore the last section. + owner="$(awk -F: -v n="${compare_heading%%:*}" ' + NR < n && /^## / { last = $0 } + END { print last } + ' "$PROSE")" + if [ "$owner" = "## Benchmarks" ]; then + ok "§9.8 the comparison sits under ## Benchmarks" + else + fail "§9.8 the comparison sits under '$owner', not under ## Benchmarks" + fi +fi + +if [ "$fails" -ne 0 ]; then + echo "test_readme_structure: $fails failure(s)" >&2 + exit 1 +fi +echo "test_readme_structure: all checks passed"