|
| 1 | +# Tests as mcpp states them: programs, parts, cases, live results, metrics and history |
| 2 | + |
| 3 | +Status, 2026-11-10: implemented in mcpp-ide 1.3.0 (mcpp-ide#8), with the client side of mcpp#917; the backend's own tests are mtest's. |
| 4 | + |
| 5 | +## Scope and principle |
| 6 | + |
| 7 | +The editors show tests as `mcpp test` states them. mcpp builds and runs the programs. mtest's protocol |
| 8 | +is how a program's cases report to mcpp. mtest's store (spec P12) is the form in which mcpp keeps a run |
| 9 | +(`target/mtest`). The backend reads three inputs: |
| 10 | + |
| 11 | +- the records of `mcpp test --message-format json`; |
| 12 | +- the listings of `--list` and `--cases`; |
| 13 | +- the store. |
| 14 | + |
| 15 | +It does not drive mtest's engine. A program that only mtest's own runner runs (a `[discover]` script of |
| 16 | +`mtest.toml`) is outside `mcpp test`, and the editors do not show it. |
| 17 | + |
| 18 | +Each editor presents the same data in its own idiom: |
| 19 | + |
| 20 | +- VS Code uses the Testing view, test messages, and editor decorations. |
| 21 | +- CLion uses the SMRunner test tree and its comparison view. |
| 22 | +- Neovim uses buffers, signs, virtual text, and the quickfix list. |
| 23 | + |
| 24 | +An editor shows only what the project's mcpp provides. A missing input removes the view that needs it. |
| 25 | +It does not remove the views that do not need it. |
| 26 | + |
| 27 | +## What mcpp provides, by version |
| 28 | + |
| 29 | +| mcpp | Provides | The editors show | |
| 30 | +|---|---|---| |
| 31 | +| before 2026.11.8.1 | one record per program | programs and their results | |
| 32 | +| 2026.11.8.1 (`test-protocol`) | `listed` and `cases` of a protocol program | cases, their results at the program's end, their failures' places, `kind`, `tags`, `expect` and `expected`/`actual` | |
| 33 | +| 2026.11.9.1 | a protocol program of several files runs as one process per file (`<program>/<file>`); the run is kept in `target/mtest` | a program of several files with its files as children; results of a part attach to its program; history, trends of durations, and the schedule from the store | |
| 34 | +| `test-parts` (mcpp#917) | `files`, `parts`, `main: null`, `part_of` | the same tree, from mcpp's statement instead of the backend's derivation | |
| 35 | +| `test-case-stream` (mcpp#917) | `case` records as cases begin and end | live results per case | |
| 36 | +| `test-metrics` (mcpp#917) | `metrics`, `bounds`, `usage`; the store's P12 fields | metrics beside their bounds, their trends, and a case-level schedule | |
| 37 | + |
| 38 | +A view that needs an input names the missing feature in `capabilities/explain` (`tests.parts`, |
| 39 | +`tests.live`, `tests.metrics`). |
| 40 | + |
| 41 | +## The model |
| 42 | + |
| 43 | +A **program** is what `mcpp test --list` names: `unit` for the directory `tests/unit/` under |
| 44 | +`[test] programs = "directory"`, and `00-a/0` for one file. Its fields are: |
| 45 | + |
| 46 | +- `files`: its own sources; |
| 47 | +- `main`: the file that defines `main`, if one does; |
| 48 | +- `layout`: `file` or `directory`; |
| 49 | +- `parts`: the processes a run divides it into, each `{name, file}`. |
| 50 | + |
| 51 | +With `test-parts`, these fields are mcpp's. Without it, the backend derives them from what mcpp |
| 52 | +2026.11.9.1 states (docs/08): |
| 53 | + |
| 54 | +- A program whose `main` file lies in a directory whose path below the test root is the program's name |
| 55 | + is of layout `directory`. |
| 56 | +- Its files are the C++ sources directly in that directory. |
| 57 | +- Its parts are `<program>/<stem>`, one per file. |
| 58 | +- `main` is the file whose source defines `main`, found by the scanner; otherwise it is absent. |
| 59 | + |
| 60 | +A **case** belongs to a program and a file. Its fields are `id`, `file`, `line`, `kind`, `tags`, |
| 61 | +`expect` and, with `test-metrics`, `bounds`. Static cases are read from each file with mtest's manifest. |
| 62 | +A listing (`--cases`) replaces them case by case. |
| 63 | + |
| 64 | +A result names the program it belongs to: |
| 65 | + |
| 66 | +- `part_of` when mcpp states it; |
| 67 | +- else the longest listed program whose name is the record's name or a prefix of it followed by `/`; |
| 68 | +- else the record's name. |
| 69 | + |
| 70 | +## The backend's protocol (protocol 2, additions only) |
| 71 | + |
| 72 | +- `test/list`: each test gains `files`, `layout`, `parts`, and `main` as described above. |
| 73 | +- `source/entries`: a file of a directory program answers `test` (the program) and `part` (its own |
| 74 | + part). |
| 75 | +- `test/cases`: reads every file of the program. Each case gains `file`, `kind`, `tags`, `expect` and |
| 76 | + `bounds`. |
| 77 | +- `test/result` gains: |
| 78 | + - `program` and `part`; |
| 79 | + - `cases`, each with `id`, `status`, `durationMs`, `reason`, `failures` (`path`, `line`, `message`, |
| 80 | + `expected`, `actual`), `metrics`, `bounds`, `kind` and `tags`. |
| 81 | + |
| 82 | + A case's status is mapped as follows: |
| 83 | + |
| 84 | + | mcpp | protocol | |
| 85 | + |---|---| |
| 86 | + | `pass` | `passed` | |
| 87 | + | `fail` | `failed` | |
| 88 | + | `skip` | `skipped` | |
| 89 | + | `xfail` | `passed` with `expectedFailure` | |
| 90 | + | `xpass` | `failed` with `unexpectedPass` | |
| 91 | + | `invalid` | `errored` | |
| 92 | + |
| 93 | + A whole-program run therefore marks every case. |
| 94 | +- `test/caseResult`: gains the fields of a case above. It is sent for every record of the job, not |
| 95 | + only the last one; a run of a directory program writes one record per part. |
| 96 | +- `test/caseEvent` (new): `{jobId, root, program, part, case, event: "begin" | "end", tMs, ...}` with |
| 97 | + the fields of a case on `end`. It is sent as mcpp writes a `case` record (`test-case-stream`). |
| 98 | +- `test/history {root, program?, case?, runs?}` (new): the store's last runs (20 by default) and each |
| 99 | + selected case's results across them. |
| 100 | +- `test/insights {root, runs?}` (new): |
| 101 | + - the last run: its counts and its counts by kind; |
| 102 | + - its failures, each with the run since which it has failed; |
| 103 | + - the slowest cases, with their median over the window; |
| 104 | + - the cases whose status changed within the window (flaky); |
| 105 | + - each metric's series, its bounds, its last value and its margin; |
| 106 | + - the schedule: one lane per worker, each process with its start, duration and build, and the |
| 107 | + critical path (the chain of processes on one worker that ends last, with the build before it). |
| 108 | +- `capabilities/explain` gains `tests.parts`, `tests.live` and `tests.metrics`. |
| 109 | + |
| 110 | +The store is read from `[test] store` when the manifest sets it, else from `target/mtest`. The backend |
| 111 | +reads it as P12 specifies it. It reads `index.ndjson`, then the last N runs' files, and keeps them by |
| 112 | +run id. A run already read is not read again. A store that is absent is not an error: the history and |
| 113 | +insights are empty and say so. |
| 114 | + |
| 115 | +## Each editor |
| 116 | + |
| 117 | +**VS Code.** |
| 118 | + |
| 119 | +- The Testing view shows each project, then its programs, then the files of a directory program, then |
| 120 | + the cases. |
| 121 | +- Each case carries the test tags `kind:<kind>` and its own tags, so `@kind:bench` filters the view. |
| 122 | +- Results arrive per case as they happen (`test/caseEvent`), else per part. |
| 123 | +- A failure with `expected` and `actual` is a `TestMessage.diff`, and VS Code's diff view compares them. |
| 124 | +- After a run, a case's line ends with a dim decoration: its duration, and its metrics against their |
| 125 | + bounds (`ready 4.2 s ≤ 15 s`). |
| 126 | +- "mcpp: Test Insights" is a webview with these sections: |
| 127 | + - the run's summary; |
| 128 | + - its failures, each opening its place; |
| 129 | + - the slowest cases; |
| 130 | + - the flaky cases; |
| 131 | + - each metric's trend against its bounds; |
| 132 | + - the schedule, with its critical path. |
| 133 | + |
| 134 | + It refreshes when a run ends. |
| 135 | + |
| 136 | +**CLion.** |
| 137 | + |
| 138 | +- The SMRunner tree shows a program as a suite, the files of a directory program as nested suites, and |
| 139 | + the cases as tests, each located at its line. |
| 140 | +- Live case events start and finish tests as they come. |
| 141 | +- A failure with `expected` and `actual` is a comparison failure, whose "Click to see difference" opens |
| 142 | + the IDE's diff. |
| 143 | +- Metrics appear in a case's output beside their bounds. |
| 144 | +- The mcpp tool window gains a Tests tab: the same insights in JCEF (`webui/tests.html`), as the graph |
| 145 | + page is drawn. |
| 146 | + |
| 147 | +**Neovim.** |
| 148 | + |
| 149 | +- `mcpp://tests` gains sections per program, part and case as results arrive, live with |
| 150 | + `test-case-stream`. |
| 151 | +- A failure's `expected` and `actual` appear as two lines under it, and in its quickfix text. |
| 152 | +- A case's line carries its sign (✓, ✗) and, as virtual text, its duration and its metrics against |
| 153 | + their bounds. |
| 154 | +- `:Mcpp testInsights` opens the insights as text in a floating window. A metric's trend is drawn with |
| 155 | + block characters (▁▂▃▅▇), and the schedule as bars. |
| 156 | + |
| 157 | +## Performance |
| 158 | + |
| 159 | +- The suite types of a project's tests are read once and kept with a signature of the files: their |
| 160 | + count, their largest modification time, and their total size, from a walk that only stats. |
| 161 | + `source/entries` and `test/cases` no longer read every file of `tests/` on each call. |
| 162 | +- Live results are sent as they come. VS Code and CLion apply them as their test APIs do. |
| 163 | +- Neovim redraws the results buffer at most every 100 ms. |
| 164 | +- The store is read incrementally: only runs not read before. |
| 165 | +- The insights window is bounded: 20 runs by default, 50 at most. |
| 166 | + |
| 167 | +## Tests |
| 168 | + |
| 169 | +- Backend: |
| 170 | + - the derivation of parts from a 2026.11.9.1 listing; |
| 171 | + - the attribution of part records to their program; |
| 172 | + - the mapping of the protocol's statuses; |
| 173 | + - `expected`/`actual`; |
| 174 | + - `case` records into `test/caseEvent`; |
| 175 | + - the store reader, and the insights (the window, flaky, the critical path, the margins); |
| 176 | + - the schema of the new methods and notifications. |
| 177 | +- The mock mcpp gains the fixtures of a directory program, with and without the #917 shapes. A |
| 178 | + directory's `.mock-mcpp-tests` selects them, as `.mock-mcpp-features` selects the features. |
| 179 | +- VS Code: the tree of a directory program; part results attributed to it; the diff message; the |
| 180 | + decorations' text. |
| 181 | +- Neovim: the smoke test covers live results, the virtual text and `:Mcpp testInsights`. |
| 182 | +- CLion: the comparison failure and the nested suites, in the plugin's unit tests. |
| 183 | +- The insights page is rendered by a Chromium test, as the graph page is. |
0 commit comments