No description
Find a file
Thunder 8ae07677cf
All checks were successful
CI / build (push) Successful in 39s
Release / build (push) Successful in 41s
Release / push-nuget (push) Successful in 30s
Release / deploy-docs (push) Successful in 1m0s
Release / merge-to-main (push) Successful in 4s
release: v0.1.0 — Thunder.DocSnippets stable
Phase 1 (Foundation) complete. 134 tests GREEN.

Highlights:
- Roslyn incremental source generator for XML doc <code> snippets
- Four inline assertion patterns: // =>, // result:, // VARNAME:, bare literals
- Declaration-aware splitting (var x = f(); // => 3 works on one line)
- NUnit / xUnit / MSTest auto-detection
- #line diagnostics pointing to original source
- MSBuild auto-wiring via shipped .targets
- opt-out default; opt-in override via docsnippets.json
- DocFX docs site + sample project

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-26 06:16:07 -05:00
.forgejo/workflows Update .forgejo/workflows/release.yml 2026-04-24 23:06:38 -05:00
api feat(m7-s3): sample project + bug fixes (TC-99, TC-18, TC-101) — 116 tests GREEN 2026-04-25 21:23:54 -05:00
docs docs(phase1): phase review, known limitations, ideas.md completed section, STATUS.md v0.1.0 2026-04-26 06:15:57 -05:00
samples feat(m7.1-s1): GREEN — TransformLines with inline assertion patterns (TC-102–TC-119) 2026-04-25 22:50:52 -05:00
src/Thunder.DocSnippets feat(m7.1-s1): GREEN — TransformLines with inline assertion patterns (TC-102–TC-119) 2026-04-25 22:50:52 -05:00
tests/Thunder.DocSnippets.Tests test(m7.1-s1): RED — TransformLines API + TC-102–TC-119 2026-04-25 22:49:11 -05:00
.gitignore docs(m7-s2): DocFX config, site scaffolding 2026-04-25 18:47:02 -05:00
Directory.Build.props chore: enable TreatWarningsAsErrors across all projects 2026-04-25 13:44:57 -05:00
docfx.json docs(m7-s2): DocFX config, site scaffolding 2026-04-25 18:47:02 -05:00
README.md docs(m7-s1): repo README + NuGet README updates 2026-04-25 13:46:30 -05:00
Thunder.DocSnippets.sln feat(m7-s3): sample project + bug fixes (TC-99, TC-18, TC-101) — 116 tests GREEN 2026-04-25 21:23:54 -05:00
toc.yml docs(m7-s2): DocFX config, site scaffolding 2026-04-25 18:47:02 -05:00

Thunder.DocSnippets

NuGet

Make your C# XML doc <code> examples runnable as unit tests — the Rust doctest experience for .NET.

DocSnippets is a Roslyn source generator. Add the package to your test project, and every <code> block in your library's XML documentation becomes a compiled, executable NUnit/xUnit/MSTest test. No extra tooling, no checked-in generated files.


Quick start

  1. Add DocSnippets to your test project (.Tests.csproj or similar):

    <PackageReference Include="Thunder.DocSnippets" Version="..." />
    
  2. Run dotnet test. Done.

DocSnippets automatically picks up the adjacent source project's .cs files via its shipped MSBuild .targets file — no manual <AdditionalFiles> configuration required.


Writing snippets

Any <code> block in an XML doc comment is picked up automatically in opt-out mode (the default):

/// <summary>Adds two integers.</summary>
/// <example>
/// <code>
/// var result = calculator.Add(1, 2); // => 3
/// </code>
/// </example>
public int Add(int a, int b) => a + b;

The // => 3 assertion becomes a framework-appropriate equality check at generation time. No assertion library is needed in the snippet itself.

Excluding a snippet

Add // doctest-ignore on the first line of any <code> block to skip it:

/// <code>
/// // doctest-ignore
/// // This example is illustrative — not executable.
/// var x = SomeExternalCall();
/// </code>

Opt-in mode

By default all blocks run. To run only explicitly marked blocks, add docsnippets.json to the adjacent source project and set snippetMode to "opt-in", then mark each runnable snippet with // doctest:

/// <code>
/// // doctest
/// var result = calculator.Add(1, 2); // => 3
/// </code>

Configuration (docsnippets.json)

Drop a docsnippets.json file alongside the source files:

{
  "snippetMode": "opt-out",
  "assertionStyle": "NUnit",
  "implicitUsings": ["MyLib", "MyLib.Models"]
}
Key Values Default Description
snippetMode "opt-out", "opt-in" "opt-out" opt-out: all <code> blocks run. opt-in: only blocks marked // doctest run.
assertionStyle "NUnit", "XUnit", "MSTest" (auto-detect) Override the auto-detected test framework.
implicitUsings Array of namespace strings [] Namespaces added as using to every generated test class.

InternalsVisibleTo

If your snippets reference internal types, add this to your source project:

[assembly: InternalsVisibleTo("YourTestProject")]

Without it, snippets referencing internal members produce CS0122 errors.


Documentation

Full docs at docs.thundersizzle.tech/public/Thunder/thunder-docsnippets/.


Licence

MIT — see LICENCE.