Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Roslyn source generator #200

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
27cce36
Add core implementation from PoC
Code-Grump Apr 26, 2024
9731e1a
Add test for .editorconfig setting
Code-Grump Apr 27, 2024
20c4551
Add tests for xUnit generation
Code-Grump Apr 27, 2024
675e969
Add initial XUnit syntax generation
Code-Grump Apr 29, 2024
e045f05
Add feature lifecycle to MSTest and xunit generator
Code-Grump May 2, 2024
1be4d4a
Add Rosyln flavor to specifications
Code-Grump May 5, 2024
35e2857
Add on/off switch for MSBuild generation.
Code-Grump May 5, 2024
435667d
Integrate FeatureSourceGenerator with SystemTests project
Code-Grump May 9, 2024
1dd161e
Add full MSBuild integration for generator
Code-Grump May 12, 2024
785e946
Make generator dependencies private
Code-Grump May 12, 2024
633ae40
Add target test-framework properties
Code-Grump May 12, 2024
1588b43
Fix ambuiguous syntax generation
Code-Grump May 12, 2024
fa5e031
Add language information
Code-Grump May 13, 2024
5b1320c
Add cleaner namespace generation
Code-Grump May 14, 2024
0f9b461
Add support for generating nullable references
Code-Grump May 14, 2024
46dce37
Remove long line from generator
Code-Grump May 14, 2024
f7080e0
Extend attribute descriptor as value-like object
Code-Grump May 29, 2024
3fdb30e
Shift to object-model-based generation approach
Code-Grump Jun 11, 2024
ffa4241
Refactor towards model-based generation
Code-Grump Jun 14, 2024
a280483
Add scenarios for MSTest generation
Code-Grump Jun 21, 2024
e1b03e4
Merge branch 'main' into feature/roslyn-generator
Code-Grump Jun 22, 2024
bb8face
Add MSTest support up-to 6/7 test cases
Code-Grump Jul 2, 2024
d7db694
Add StepInvocation to model for testing
Code-Grump Jul 2, 2024
c3fa1b0
Add omission of ignored examples by default with option to enable
Code-Grump Jul 3, 2024
100ce8a
Add readme placeholder
Code-Grump Jul 3, 2024
d97266e
Disable symbol packing for Feature Source Generator
Code-Grump Jul 4, 2024
d73ad56
Add syntax for expressing more type identifiers
Code-Grump Jul 8, 2024
cc53938
Add test for XUnit IClassFixture declaration
Code-Grump Jul 9, 2024
b1c057a
Add XUnit lifetime implementation
Code-Grump Jul 9, 2024
cf30365
Add test for xunit method attributes
Code-Grump Jul 9, 2024
5201675
Add xunit attributes to generation
Code-Grump Jul 9, 2024
50b6432
Add rendering of C# test fixture class interfaces
Code-Grump Jul 9, 2024
e92851f
Add XUnit implementation
Code-Grump Jul 10, 2024
acece94
Added NUnit generation with default emission of skipped scenarios
Code-Grump Jul 12, 2024
1aeb5ec
Merge branch 'main' into feature/roslyn-generator
Code-Grump Jul 12, 2024
e117f16
fix small typos and simple code things
gasparnagy Jul 27, 2024
0ca1181
Handle empty test-framework selector
Code-Grump Aug 1, 2024
24931b1
Fix nullability of MSTest test runner variable
Code-Grump Aug 1, 2024
1a0dbfe
Fix test-method equality comparisons
Code-Grump Aug 1, 2024
da7ebc0
Add column-markers to source-line mapping
Code-Grump Aug 4, 2024
f14fdfe
Merge branch 'main' into feature/roslyn-generator
Code-Grump Aug 5, 2024
24ed8a8
Add support for background steps at feature and rule level
Code-Grump Aug 5, 2024
36f9705
Fix location mapping
Code-Grump Aug 6, 2024
c8fa22f
Fix off-by-one line/column mapping
Code-Grump Aug 7, 2024
7ae843c
Fix handling of feature files in folders
Code-Grump Aug 10, 2024
6520617
Add "empty-string-is-null" convention to options
Code-Grump Aug 11, 2024
40be218
Add test for table arguments being passed to steps
Code-Grump Aug 24, 2024
610a7d1
Tighten up background handling assertions
Code-Grump Aug 25, 2024
b576966
Merge branch 'task/add-table-handling-system-tests' into feature/rosl…
Code-Grump Aug 25, 2024
90453e1
Add generation support for MSTest 3
Code-Grump Aug 25, 2024
312b793
Added support for DataTable and DocString arguments
Code-Grump Aug 25, 2024
498a7e6
Fix tests broken by adding compilation argument
Code-Grump Aug 26, 2024
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
@@ -1,5 +1,9 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="TaskFolder;TaskAssembly">

<PropertyGroup>
<ReqnrollTargetTestFramework>MsTest</ReqnrollTargetTestFramework>
</PropertyGroup>

<ItemGroup>
<ReqnrollGeneratorPlugins Include="$(_Reqnroll_MsTestGeneratorPluginPath)" />
<None Include="$(_Reqnroll_MsTestRuntimePluginPath)" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="TaskFolder;TaskAssembly">

<PropertyGroup>
<ReqnrollTargetTestFramework>NUnit</ReqnrollTargetTestFramework>
<ReqnrollEmitIgnoredExamples Condition="'$(ReqnrollEmitIgnoredExamples)' == ''" >true</ReqnrollEmitIgnoredExamples>
</PropertyGroup>

<ItemGroup>
<ReqnrollGeneratorPlugins Include="$(_Reqnroll_NUnitGeneratorPluginPath)" />
<None Include="$(_Reqnroll_NUnitRuntimePluginPath)" >
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" TreatAsLocalProperty="TaskFolder;TaskAssembly">

<PropertyGroup>
<ReqnrollTargetTestFramework>xunit</ReqnrollTargetTestFramework>
</PropertyGroup>

<ItemGroup>
<ReqnrollGeneratorPlugins Include="$(_Reqnroll_xUnitGeneratorPluginPath)" />
Expand Down
10 changes: 10 additions & 0 deletions Reqnroll.FeatureSourceGenerator/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[*]
insert_final_newline = true
indent_size = 4
indent_style = space

[*.cs]
csharp_style_namespace_declarations = file_scoped

[*.{csproj,targets,props}]
indent_size = 2
52 changes: 52 additions & 0 deletions Reqnroll.FeatureSourceGenerator/AnalyzerConfigOptionsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Microsoft.CodeAnalysis.Diagnostics;

namespace Reqnroll.FeatureSourceGenerator;

internal static class AnalyzerConfigOptionsExtensions
{
public static string? GetStringValue(this AnalyzerConfigOptions options, string name)
{
if (options.TryGetValue(name, out var value))
{
return string.IsNullOrEmpty(value) ? null : value;
}

return null;
}

public static string? GetStringValue(this AnalyzerConfigOptions options, string name1, string name2)
{
return GetStringValue(options, name1) ?? GetStringValue(options, name2);
}

public static string? GetStringValue(this AnalyzerConfigOptions options, string name1, string name2, string name3)
{
return GetStringValue(options, name1) ?? GetStringValue(options, name2) ?? GetStringValue(options, name3);
}

public static bool? GetBooleanValue(this AnalyzerConfigOptions options, string name)
{
if (options.TryGetValue(name, out var value) && !string.IsNullOrEmpty(value))
{
if (bool.TryParse(value, out bool result))
{
return result;
}

return false;
}

return null;
}

public static bool? GetBooleanValue(this AnalyzerConfigOptions options, string name1, string name2)
{
return GetBooleanValue(options, name1) ?? GetBooleanValue(options, name2);
}

public static bool? GetBooleanValue(this AnalyzerConfigOptions options, string name1, string name2, string name3)
{

return GetBooleanValue(options, name1) ?? GetBooleanValue(options, name2) ?? GetBooleanValue(options, name3);
}
}
26 changes: 26 additions & 0 deletions Reqnroll.FeatureSourceGenerator/BuiltInTestFrameworkHandlers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Reqnroll.FeatureSourceGenerator.MSTest;
using Reqnroll.FeatureSourceGenerator.NUnit;
using Reqnroll.FeatureSourceGenerator.XUnit;

namespace Reqnroll.FeatureSourceGenerator;

/// <summary>
/// Provides instances of the set of built-in handlers.
/// </summary>
internal static class BuiltInTestFrameworkHandlers
{
/// <summary>
/// Gets the handler instance for NUnit.
/// </summary>
public static NUnitHandler NUnit { get; } = new();

/// <summary>
/// Gets the handler instance for MSTest.
/// </summary>
public static MSTestHandler MSTest { get; } = new();

/// <summary>
/// Gets the handler instance for xUnit.
/// </summary>
public static XUnitHandler XUnit { get; } = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Microsoft.CodeAnalysis.CSharp;
using System.Collections.Immutable;

namespace Reqnroll.FeatureSourceGenerator.CSharp;

public record CSharpCompilationInformation(
string? AssemblyName,
ImmutableArray<AssemblyIdentity> ReferencedAssemblies,
LanguageVersion LanguageVersion,
bool HasNullableReferencesEnabled) : CompilationInformation(AssemblyName, ReferencedAssemblies)
{
public virtual bool Equals(CSharpCompilationInformation other)
{
if (!base.Equals(other))
{
return false;
}

return LanguageVersion.Equals(other.LanguageVersion) &&
HasNullableReferencesEnabled.Equals(other.HasNullableReferencesEnabled);
}

public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = base.GetHashCode();

hash = hash * 43 + LanguageVersion.GetHashCode();
hash = hash * 43 + HasNullableReferencesEnabled.GetHashCode();

return hash;
}
}
}
13 changes: 13 additions & 0 deletions Reqnroll.FeatureSourceGenerator/CSharp/CSharpRenderingContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Reqnroll.FeatureSourceGenerator.SourceModel;

namespace Reqnroll.FeatureSourceGenerator.CSharp;
public class CSharpRenderingContext(
FeatureInformation feature,
string outputHintName,
CSharpSourceTextWriter writer,
CSharpRenderingOptions renderingOptions) : TestFixtureSourceRenderingContext(feature, outputHintName)
{
public CSharpSourceTextWriter Writer { get; } = writer;

public CSharpRenderingOptions RenderingOptions { get; } = renderingOptions;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Reqnroll.FeatureSourceGenerator.CSharp;

/// <summary>
/// Defines the options which control the rendering of C# code.
/// </summary>
/// <param name="EnableLineMapping">Whether to include #line directives to map generated tests to lines in source feature files.</param>
/// <param name="UseNullableReferenceTypes">Whether to use nullable reference types in generated code.</param>
public record CSharpRenderingOptions(bool EnableLineMapping = true, bool UseNullableReferenceTypes = false);
Loading
Loading