Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,38 @@ The relevant files are at `docs > docs > tutorials-[basics|extras|assertions]`

If want to provide sample code for complicated or useful different test suite set-ups, that's also very welcome, as this can help other users get started a lot quicker!

## Building TUnit Locally

TUnit ships several solution files. Pick the right one for your task — the
full `TUnit.slnx` is large enough that a cold build can take 20+ minutes,
which is rarely what contributors actually need:

| Solution | Projects | When to use |
| ---------------- | -------- | -------------------------------------------------------------------------------------------------------------- |
| `TUnit.Dev.slnx` | 44 | **Recommended for contributors.** Drops the per-Roslyn-version generator variants and example projects. Open this in Visual Studio / Rider for day-to-day work. |
| `TUnit.CI.slnx` | 73 | What CI builds. Use only when you're verifying CI-specific changes. |
| `TUnit.slnx` | 96 | Full shipping graph including all per-Roslyn-version analyzer/generator variants. Slow; rarely needed locally. |

### Faster repeat builds

Set `MSBUILDUSESERVER=1` in your shell to keep the MSBuild process alive
between invocations — significant speedup on warm/incremental builds.

```bash
export MSBUILDUSESERVER=1 # bash/zsh
$env:MSBUILDUSESERVER = '1' # PowerShell
```

### Inspecting generated source

Source-generated files are not written to disk by default (saves significant
disk I/O on every build). To dump them under each test project's
`SourceGeneratedViewer\` folder, build with:

```bash
dotnet build -p:EmitCompilerGeneratedFiles=true
```

### Code Contributions

When contributing code to TUnit, please keep these important requirements in mind:
Expand Down
4 changes: 3 additions & 1 deletion Library.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- XML doc generation is only needed when producing NuGet packages or running on CI.
Skipping it on local incremental builds saves 3-8% Roslyn time per TFM. -->
<GenerateDocumentationFile Condition="'$(IsPacking)' == 'true' or '$(GeneratePackageOnBuild)' == 'true' or '$(ContinuousIntegrationBuild)' == 'true'">true</GenerateDocumentationFile>
<!-- Suppress XML doc warnings — not all public APIs are documented yet,
and some existing comments have minor formatting issues -->
<NoWarn>$(NoWarn);CS1591;CS1570;CS1572;CS1573;CS1574;CS1584;CS1587;CS1658;CS1734;CS0419</NoWarn>
Expand Down
29 changes: 0 additions & 29 deletions Playground/GenericTestExample.cs

This file was deleted.

31 changes: 0 additions & 31 deletions Playground/Playground.csproj

This file was deleted.

56 changes: 0 additions & 56 deletions Playground/Program.cs

This file was deleted.

40 changes: 0 additions & 40 deletions Playground/TestConstructorDemo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Multi-target to verify generator output across consumer TFMs (snapshot tests). -->
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\TestProject.props" />

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Multi-target to verify generator output across consumer TFMs (snapshot tests). -->
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\TestProject.props" />

<PropertyGroup>
Expand Down
7 changes: 6 additions & 1 deletion TUnit.PublicAPI/TUnit.PublicAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<!-- Multi-target so public API snapshots cover every supported consumer TFM. -->
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>
</PropertyGroup>

<Import Project="..\TestProject.props" />

<PropertyGroup>
<Configuration>Release</Configuration>
</PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion TUnit.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@

<!-- Examples and playground projects -->
<Folder Name="/Examples/">
<Project Path="Playground/Playground.csproj" />
<Project Path="TUnit.Example.Asp.Net/TUnit.Example.Asp.Net.csproj" />
<Project Path="TUnit.Example.Asp.Net.TestProject/TUnit.Example.Asp.Net.TestProject.csproj" />
<Project Path="TUnit.Example.FsCheck.TestProject/TUnit.Example.FsCheck.TestProject.csproj" />
Expand Down
37 changes: 26 additions & 11 deletions TestProject.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
Condition="'$(MSBuildProjectExtension)' == '.fsproj'" />

<PropertyGroup>
<TargetFrameworks>net472;net8.0;net9.0;net10.0</TargetFrameworks>
<!-- Default test projects to net10.0 only. Multi-targeting (net472;net8;net9) is
expensive (4x compile work) and only matters for projects that snapshot output
across consumer TFMs (e.g. TUnit.PublicAPI, TUnit.Core.SourceGenerator.Tests).
Those projects set <TargetFrameworks> explicitly before this import. -->
<TargetFrameworks Condition="'$(TargetFrameworks)' == '' and '$(TargetFramework)' == ''">net10.0</TargetFrameworks>

<OutputType>Exe</OutputType>

Expand All @@ -25,24 +29,35 @@

</PropertyGroup>

<Target Name="CleanSourceGeneratedViewer" BeforeTargets="BeforeBuild"
Condition="'$(ContinuousIntegrationBuild)' != 'true' AND Exists('$(ProjectDir)SourceGeneratedViewer')">
<ItemGroup>
<FilesToDelete Include="$(ProjectDir)SourceGeneratedViewer\**\*" />
</ItemGroup>
<Delete Files="@(FilesToDelete)" ContinueOnError="true" />
</Target>

<!-- Default off: emitting generator output to disk costs significant I/O per build. -->
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>SourceGeneratedViewer</CompilerGeneratedFilesOutputPath>
<EmitCompilerGeneratedFiles Condition="'$(EmitCompilerGeneratedFiles)' == ''">false</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath Condition="'$(EmitCompilerGeneratedFiles)' == 'true'">SourceGeneratedViewer</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<!-- Compile Remove must stay unconditional: a stale folder from a previous opt-in build
would otherwise be picked up by the implicit C# glob and produce CS0111 / CS0579
duplicate-member errors alongside the in-memory generator output. -->
<ItemGroup>
<Compile Remove="SourceGeneratedViewer\**" />
</ItemGroup>

<ItemGroup Condition="'$(EmitCompilerGeneratedFiles)' == 'true'">
<None Include="SourceGeneratedViewer\**" />
</ItemGroup>

<!-- Always clean SourceGeneratedViewer\ on local builds when the folder exists.
When EmitCompilerGeneratedFiles=true, this gives a fresh dump per build.
When EmitCompilerGeneratedFiles=false (the default), this clears stale files
left over from a prior opt-in build. CI runners are ephemeral, so skip. -->
<Target Name="CleanSourceGeneratedViewer" BeforeTargets="BeforeBuild"
Condition="'$(ContinuousIntegrationBuild)' != 'true' AND Exists('$(ProjectDir)SourceGeneratedViewer')">
<ItemGroup>
<FilesToDelete Include="$(ProjectDir)SourceGeneratedViewer\**\*" />
</ItemGroup>
<Delete Files="@(FilesToDelete)" ContinueOnError="true" />
</Target>

<!-- Enable VSCode test discovery integration -->
<ItemGroup>
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" />
Expand Down
Loading