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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

namespace TUnit.Core.SourceGenerator;

[Generator]
public class LanguageVersionCheckGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var settings = context.CompilationProvider
.Select((c, _) =>
{
LanguageVersion? csharpVersion = c is CSharpCompilation comp
? comp.LanguageVersion
: null;

return csharpVersion;
});

context.RegisterSourceOutput(settings, static (sourceProductionContext, languageVersion) =>
{
if (languageVersion is null)
{
return;
}

if((int)languageVersion.Value < 1200)
{
sourceProductionContext.ReportDiagnostic(Diagnostic.Create(
new DiagnosticDescriptor(
"TUNIT_LANG_001",
"Language Version Check",
"TUnit requires C# 12 or higher when using Source Generation.",
"Usage",
DiagnosticSeverity.Error,
true),
Location.None));
}
});
}
}
1 change: 0 additions & 1 deletion TUnit.Engine/TUnit.Engine.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
Expand Down
8 changes: 6 additions & 2 deletions TUnit.Engine/TUnit.Engine.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>


<PropertyGroup>
<LangVersion Condition="'$(LangVersion)' == ''">latest</LangVersion>
</PropertyGroup>

<ItemGroup Condition="'$(TUnitImplicitUsings)' == 'true'">
<Using Include="TUnit.Core" />
</ItemGroup>
Expand All @@ -13,4 +17,4 @@
<AssemblyMetadata Include="TUnitReflectionScanner" Value="true" />
</ItemGroup>

</Project>
</Project>
4 changes: 4 additions & 0 deletions TUnit.TestProject.VB.NET/TUnit.TestProject.VB.NET.vbproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>

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

<PropertyGroup>
Expand Down
1 change: 0 additions & 1 deletion TUnit/TUnit.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
<TestingPlatformCaptureOutput>false</TestingPlatformCaptureOutput>
<LangVersion>latest</LangVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>

Expand Down
4 changes: 4 additions & 0 deletions TUnit/TUnit.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<LangVersion Condition="'$(LangVersion)' == ''">latest</LangVersion>
</PropertyGroup>

<ItemGroup Condition="'$(TUnitImplicitUsings)' == 'true'">
<Using Include="TUnit.Core" />
<Using Include="TUnit.Core.HookType" Static="True" />
Expand Down
Loading