Skip to content

Commit

Permalink
+semver:minor - Add .NET Standard 2.0 target (#1436)
Browse files Browse the repository at this point in the history
* Add .NET Standard 2.0 target

* .NET Framework Pipeline

* Fixes

* Tidy

* Tidy backport locks

* Fix

* Fix

* IsLibraryPackage

* Backport lock fix

* Fix

* Compilation fixes

* Fixes

* Source Gen tweaks

* Fixes

* Fixes

* Fixes

* Fixes

* Fix

* Fixes

* Fixes

* ContainingNamespace

* Fixes

* Fixes

* More net472

* IsLibraryTestProject

* Remove reference

* Fix

* Rework props

* MSBuildThisFileDirectory

* Fixes

* Fix

* Fix

* Fixes

* Tidy

* WIP

* Compilation fixes

* Compilation fixes

* Trim on .NET 8 upwards

* Fix

* Fixes

* Skip

* Environment.GetEnvironmentVariable("NET_VERSION")

* Fixes

* Fix

* Fix

* Source generate attribute invocations

* MethodInfoRetriever

* MethodInfoRetriever

* MethodInfoRetriever

* Enum fix

* Enum fix

* Remove dupe package versions

* Remove dupe package versions

* Remove calls to GetCustomAttributes

* Fix verify tests

* Fix

* Fix

* record

* IComparable

* IComparable

* Tweak

* Tweak

* IComparable

* Nullable

* TargetFrameworks

* return early

* IComparable

* New PriorityQueue implementation

* Remove C5

* Update TUnit.NugetTester.Library.csproj

* Update TUnit.NugetTester.csproj

---------

Co-authored-by: Tom Longhurst <[email protected]>
  • Loading branch information
AArnott and thomhurst authored Dec 26, 2024
1 parent 57d2218 commit 7266461
Show file tree
Hide file tree
Showing 223 changed files with 3,201 additions and 1,361 deletions.
7 changes: 6 additions & 1 deletion .github/actions/execute-pipeline/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ inputs:
description: 'Environment'
required: false
default: 'Development'
netversion:
description: 'Net version'
required: false
default: 'net9.0'

runs:
using: "composite"
Expand All @@ -33,4 +37,5 @@ runs:
GITHUB_TOKEN: ${{ github.token }}
DOTNET_ENVIRONMENT: ${{ inputs.environment }}
NuGet__ApiKey: ${{ inputs.nuget-apikey }}
NuGet__ShouldPublish: ${{ inputs.publish-packages }}
NuGet__ShouldPublish: ${{ inputs.publish-packages }}
NET_VERSION: ${{ inputs.netversion }}
34 changes: 34 additions & 0 deletions .github/workflows/dotnet-framework.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: .NET Framework

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
modularpipeline-netframework:
environment: ${{ github.ref == 'refs/heads/main' && 'Production' || 'Pull Requests' }}
runs-on: windows-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Setup .NET Framework
uses: microsoft/setup-msbuild@v2

- name: Build
run: dotnet build -c Release -p:TreatWarningsAsErrors=true

- name: Run Pipeline
uses: ./.github/actions/execute-pipeline
with:
environment: ${{ github.ref == 'refs/heads/main' && 'Production' || 'Development' }}
netversion: 'net472'
15 changes: 3 additions & 12 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!--suppress MsbuildTargetFrameworkTagInspection -->
<TargetFrameworks Condition="'$(SDK_VERSION)' == 'net8'">net8.0</TargetFrameworks>
<TargetFrameworks Condition="'$(SDK_VERSION)' == 'net9'">net8.0;net9.0</TargetFrameworks>

<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand All @@ -29,17 +29,8 @@
</PropertyGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TUnit.Core</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TUnit.Assertions</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TUnit.Engine</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TUnit</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
<_Parameter1>TUnit.UnitTests</_Parameter1>
Expand Down Expand Up @@ -84,5 +75,5 @@
<None Include="$(MSBuildThisFileDirectory)README.md" Pack="true" PackagePath="\" />
<None Include="$(MSBuildThisFileDirectory)assets/logo.png" Pack="true" PackagePath="\" />
</ItemGroup>
</Project>

</Project>
69 changes: 40 additions & 29 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,34 +1,45 @@
<Project>
<Import
Condition="('$(IsLibraryPackage)' == 'true' or '$(IsLibraryTestProject)' == 'true') and '$(EnablePolyfill)' != 'false'"
Project="$(MSBuildThisFileDirectory)Polyfill.props" />

<PropertyGroup>
<TargetFrameworks Condition="'$(IsLibraryPackage)' == 'true'">netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks Condition="'$(IsLibraryTestProject)' == 'true'">net472;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestingPlatformApplication)' == 'true'">
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="$(RoslynVersion) >= 4.7">$(DefineConstants);ROSLYN4_7_OR_GREATER</DefineConstants>
<EnableTrimAnalyzer Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">true</EnableTrimAnalyzer>
</PropertyGroup>
<PropertyGroup Condition="'$(IsTestingPlatformApplication)' == 'true'">
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<PropertyGroup>
<DefineConstants Condition="$(RoslynVersion) >= 4.7">$(DefineConstants);ROSLYN4_7_OR_GREATER</DefineConstants>
<EnableTrimAnalyzer Condition="'$(TargetFramework)' != 'netstandard2.0'">true</EnableTrimAnalyzer>
</PropertyGroup>

<ItemGroup Condition="'$(IsTestingPlatformApplication)' == 'true'">
<Using Include="TUnit.Core.HookType" Static="True" />
<Using Include="TUnit.Core" />
<ProjectReference Include="..\TUnit.Engine\TUnit.Engine.csproj" />
<ProjectReference Include="..\TUnit.Assertions\TUnit.Assertions.csproj" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" />

<ProjectReference Include="$(MSBuildThisFileDirectory)TUnit.Core.SourceGenerator\TUnit.Core.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(MSBuildThisFileDirectory)TUnit.Analyzers\TUnit.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(MSBuildThisFileDirectory)TUnit.Assertions.Analyzers\TUnit.Assertions.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<TestingPlatformBuilderHook Include="6ADF853A-6945-4A06-9A4B-D99BC1DC1094">
<DisplayName>TUnit</DisplayName>
<TypeFullName>TUnit.Engine.Framework.TestingPlatformBuilderHook</TypeFullName>
</TestingPlatformBuilderHook>
</ItemGroup>
<ItemGroup Condition="'$(IsTestingPlatformApplication)' == 'true'">
<Using Include="TUnit.Core.HookType" Static="True" />
<Using Include="TUnit.Core" />

<ProjectReference Include="..\TUnit.Engine\TUnit.Engine.csproj" />
<ProjectReference Include="..\TUnit.Assertions\TUnit.Assertions.csproj" />
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" />

<ProjectReference
Include="$(MSBuildThisFileDirectory)TUnit.Core.SourceGenerator\TUnit.Core.SourceGenerator.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="$(MSBuildThisFileDirectory)TUnit.Analyzers\TUnit.Analyzers.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference
Include="$(MSBuildThisFileDirectory)TUnit.Assertions.Analyzers\TUnit.Assertions.Analyzers.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />

<TestingPlatformBuilderHook Include="6ADF853A-6945-4A06-9A4B-D99BC1DC1094">
<DisplayName>TUnit</DisplayName>
<TypeFullName>TUnit.Engine.Framework.TestingPlatformBuilderHook</TypeFullName>
</TestingPlatformBuilderHook>
</ItemGroup>
</Project>
6 changes: 4 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="AutoFixture" Version="4.18.1" />
<PackageVersion Include="Backport.System.Threading.Lock" Version="3.1.1" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
<PackageVersion Include="CliWrap" Version="3.7.0" />
Expand All @@ -27,6 +26,7 @@
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.2" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.12.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.7.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageVersion Include="Microsoft.Playwright" Version="1.49.0" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
Expand All @@ -44,14 +44,16 @@
<PackageVersion Include="NUnit.Analyzers" Version="4.5.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="PolySharp" Version="1.15.0" />
<PackageVersion Include="Polyfill" Version="7.8.0" />
<PackageVersion Include="Sourcy.DotNet" Version="0.0.66" />
<PackageVersion Include="Sourcy.Git" Version="0.0.66" />
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Text.Json" Version="9.0.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
<PackageVersion Include="Testcontainers.PostgreSql" Version="4.1.0" />
<PackageVersion Include="trxparser" Version="0.5.0" />
<PackageVersion Include="Verify.NUnit" Version="28.7.0" />
<PackageVersion Include="TUnit" Version="0.5.32" />
<PackageVersion Include="TUnit.Core" Version="0.5.32" />
<PackageVersion Include="TUnit.Assertions" Version="0.5.32" />
Expand Down
13 changes: 13 additions & 0 deletions Polyfill.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>
<ItemGroup>
<PackageReference Include="Polyfill">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)'!='.NETCoreApp'">
<PackageReference Include="System.Text.Json" />
<PackageReference Include="System.Threading.Tasks.Extensions" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion TUnit.Analyzers.Roslyn44/TUnit.Analyzers.Roslyn44.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
<PackageReference Include="PolySharp">
<PackageReference Include="Polyfill">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Analyzers.Roslyn47/TUnit.Analyzers.Roslyn47.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Common" VersionOverride="$(RoslynVersion).*"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" VersionOverride="$(RoslynVersion).*"/>
<PackageReference Include="PolySharp">
<PackageReference Include="Polyfill">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Analyzers/TUnit.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.Common" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
<PackageReference Include="PolySharp">
<PackageReference Include="Polyfill">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
3 changes: 2 additions & 1 deletion TUnit.Assertions.Tests/TUnit.Assertions.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsLibraryTestProject>true</IsLibraryTestProject>
<LangVersion>preview</LangVersion>
<IsTestingPlatformApplication>true</IsTestingPlatformApplication>
<IsPackable>false</IsPackable>
Expand Down
8 changes: 4 additions & 4 deletions TUnit.Assertions.UnitTests/AsyncTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public async Task Func_Awaited_Task_Is_Callable()
[Test]
public async Task Func_Awaited_ValueTask_Is_Callable()
{
await TUnitAssert.That(async () => await ValueTask.FromResult("Hello")).IsNotNullOrEmpty().And.IsEqualTo("Hello");
await TUnitAssert.That(async () => await new ValueTask<string>(Task.FromResult("Hello"))).IsNotNullOrEmpty().And.IsEqualTo("Hello");
}

[Test]
public async Task ValueTask_Is_Callable()
{
await TUnitAssert.That(ValueTask.FromResult("Hello")).IsNotNullOrEmpty().And.IsEqualTo("Hello");
await TUnitAssert.That(new ValueTask<string>(Task.FromResult("Hello"))).IsNotNullOrEmpty().And.IsEqualTo("Hello");
}

[Test]
Expand All @@ -52,7 +52,7 @@ public async Task Func_Throws_Awaited_Task_Is_Callable()
[Test]
public async Task Func_Throws_Awaited_ValueTask_Is_Callable()
{
await TUnitAssert.ThrowsAsync(async () => await ValueTask.FromException(new DivideByZeroException()));
await TUnitAssert.ThrowsAsync(async () => await new ValueTask(Task.FromException(new DivideByZeroException())));
}

[Test]
Expand All @@ -64,6 +64,6 @@ public async Task Throws_Task_Is_Callable()
[Test]
public async Task Throws_ValueTask_Is_Callable()
{
await TUnitAssert.ThrowsAsync(ValueTask.FromException(new DivideByZeroException()));
await TUnitAssert.ThrowsAsync(new ValueTask(Task.FromException(new DivideByZeroException())));
}
}
6 changes: 4 additions & 2 deletions TUnit.Assertions.UnitTests/DateOnlyEqualToAssertionTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TUnit.Assertions.Extensions;
#if NET
using TUnit.Assertions.Extensions;

namespace TUnit.Assertions.UnitTests;

Expand Down Expand Up @@ -41,4 +42,5 @@ public void EqualsTo__With_Tolerance_Failure()

NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(value1).IsEqualTo(value2).WithinDays(1));
}
}
}
#endif
2 changes: 2 additions & 0 deletions TUnit.Assertions.UnitTests/DecimalEqualsToAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Decimal_EqualsTo_Failure()
NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(double1).IsEqualTo(double2));
}

#if NET
[Test]
public async Task Decimal_EqualsTo__With_Tolerance_Success()
{
Expand All @@ -39,4 +40,5 @@ public void Decimal_EqualsTo__With_Tolerance_Failure()

NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(double1).IsEqualTo(double2).Within(0.0001));
}
#endif
}
4 changes: 3 additions & 1 deletion TUnit.Assertions.UnitTests/DoubleEqualsToAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Double_EqualsTo_Failure()
NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(double1).IsEqualTo(double2));
}

#if NET
[Test]
public async Task Double_EqualsTo__With_Tolerance_Success()
{
Expand All @@ -30,7 +31,7 @@ public async Task Double_EqualsTo__With_Tolerance_Success()

await TUnitAssert.That(double1).IsEqualTo(double2).Within(0.1);
}

[Test]
public void Double_EqualsTo__With_Tolerance_Failure()
{
Expand All @@ -39,4 +40,5 @@ public void Double_EqualsTo__With_Tolerance_Failure()

NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(double1).IsEqualTo(double2).Within(0.1));
}
#endif
}
2 changes: 2 additions & 0 deletions TUnit.Assertions.UnitTests/IntegerEqualsToAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Integer_EqualsTo_Failure()
NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(value1).IsEqualTo(value2));
}

#if NET
[Test]
public async Task Integer_EqualsTo__With_Tolerance_Success()
{
Expand All @@ -39,4 +40,5 @@ public void Integer_EqualsTo__With_Tolerance_Failure()

NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(value1).IsEqualTo(value2).Within(1));
}
#endif
}
2 changes: 2 additions & 0 deletions TUnit.Assertions.UnitTests/LongEqualsToAssertionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void Long_EqualsTo_Failure()
NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(value1).IsEqualTo(value2));
}

#if NET
[Test]
public async Task Long_EqualsTo__With_Tolerance_Success()
{
Expand All @@ -39,4 +40,5 @@ public void Long_EqualsTo__With_Tolerance_Failure()

NUnitAssert.ThrowsAsync<TUnitAssertionException>(async () => await TUnitAssert.That(value1).IsEqualTo(value2).Within(1));
}
#endif
}
11 changes: 9 additions & 2 deletions TUnit.Assertions.UnitTests/TUnit.Assertions.UnitTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<IsLibraryTestProject>true</IsLibraryTestProject>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<LangVersion>preview</LangVersion>
Expand All @@ -16,7 +17,13 @@
<PackageReference Include="coverlet.collector" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TUnit.Assertions.Analyzers\TUnit.Assertions.Analyzers.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\TUnit.Assertions.Analyzers\TUnit.Assertions.Analyzers.csproj"
OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\TUnit.Assertions\TUnit.Assertions.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\TUnit.Engine\PolyfillExtensions.cs">
<Link>PolyfillExtensions.cs</Link>
</Compile>
</ItemGroup>
</Project>
Loading

0 comments on commit 7266461

Please sign in to comment.