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
13 changes: 12 additions & 1 deletion src/TUnit.Assertions.Should/TUnit.Assertions.Should.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk" TreatAsLocalProperty="PackageVersion">

<Import Project="..\..\eng\Library.props" />
<Import Project="..\..\eng\SourceGenerationDebug.props" />

<PropertyGroup>
<!-- Package is still in beta, so its version carries a "-beta" suffix. Stamp it here
rather than passing PackageVersion=x-beta to the pack command: that global property
flows into the referenced TUnit.Assertions project too, so the emitted dependency
would read "TUnit.Assertions >= x-beta" - a version that is never published, and one
that outranks plain "x" whenever the build version is itself a prerelease (PR builds),
which fails consumer restores with NU1605. -->
<PackageVersion Condition="'$(PackageVersion)' != ''">$(PackageVersion)-beta</PackageVersion>
<PackageVersion Condition="'$(PackageVersion)' == ''">$(Version)-beta</PackageVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\TUnit.Assertions\TUnit.Assertions.csproj" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ public static void WritePropertyMetadata(ICodeWriter writer, IPropertySymbol pro
{
var safeTypeNameForReflection = containingType.GloballyQualified();
// For type parameters, we need to use typeof(object) instead of typeof(T)
var safePropertyTypeName = CodeGenerationHelpers.ContainsTypeParameter(property.Type) ? "object" : property.Type.GloballyQualified();
var containsTypeParameter = CodeGenerationHelpers.ContainsTypeParameter(property.Type);
var safePropertyTypeName = containsTypeParameter ? "object" : property.Type.GloballyQualified();

writer.AppendLine("new global::TUnit.Core.PropertyMetadata");
writer.AppendLine("{");
Expand All @@ -310,7 +311,11 @@ public static void WritePropertyMetadata(ICodeWriter writer, IPropertySymbol pro
var currentIndent = writer.IndentLevel;
writer.SetIndentLevel(currentIndent + 1);

writer.AppendLine($"ReflectionInfo = typeof({safeTypeNameForReflection}).GetProperty(\"{property.Name}\"),");
var reflectionInfo = containsTypeParameter
? $"typeof({safeTypeNameForReflection}).GetProperty(\"{property.Name}\")"
: $"typeof({safeTypeNameForReflection}).GetProperty(\"{property.Name}\", typeof({safePropertyTypeName}))";
Comment thread
thomhurst marked this conversation as resolved.

writer.AppendLine($"ReflectionInfo = {reflectionInfo},");
writer.AppendLine($"Type = typeof({safePropertyTypeName}),");
writer.AppendLine($"Name = \"{property.Name}\",");
writer.AppendLine($"IsStatic = {property.IsStatic.ToString().ToLower()},");
Expand Down
13 changes: 13 additions & 0 deletions tests/TUnit.Core.SourceGenerator.Tests/Bugs/6657/Tests6657.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TUnit.Core.SourceGenerator.Tests;

internal class Tests6657 : TestsBase
{
[Test]
public Task Test() => RunTest(Path.Combine(
Git.TestsDirectory.FullName,
"TUnit.TestProject",
"Bugs",
"6657",
"Tests.cs"),
_ => Task.CompletedTask);
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class TUnit_TestProject_ClassConstructorTest__TestSource
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.ClassConstructorTest).GetProperty("DummyReferenceTypeClass"),
ReflectionInfo = typeof(global::TUnit.TestProject.ClassConstructorTest).GetProperty("DummyReferenceTypeClass", typeof(global::TUnit.TestProject.DummyReferenceTypeClass)),
Type = typeof(global::TUnit.TestProject.DummyReferenceTypeClass),
Name = "DummyReferenceTypeClass",
IsStatic = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal static class TUnit_TestProject_ClassTupleDataSourceDrivenTests__TestSou
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property1"),
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property1", typeof(global::System.ValueTuple<int, string, bool>)),
Type = typeof(global::System.ValueTuple<int, string, bool>),
Name = "Property1",
IsStatic = false,
Expand All @@ -45,7 +45,7 @@ internal static class TUnit_TestProject_ClassTupleDataSourceDrivenTests__TestSou
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property2"),
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property2", typeof(global::System.ValueTuple<int, string, bool>)),
Type = typeof(global::System.ValueTuple<int, string, bool>),
Name = "Property2",
IsStatic = false,
Expand All @@ -56,7 +56,7 @@ internal static class TUnit_TestProject_ClassTupleDataSourceDrivenTests__TestSou
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property3"),
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property3", typeof(global::System.ValueTuple<int, string, bool>)),
Type = typeof(global::System.ValueTuple<int, string, bool>),
Name = "Property3",
IsStatic = false,
Expand All @@ -67,7 +67,7 @@ internal static class TUnit_TestProject_ClassTupleDataSourceDrivenTests__TestSou
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property4"),
ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetProperty("Property4", typeof(global::System.ValueTuple<int, string, bool>)),
Type = typeof(global::System.ValueTuple<int, string, bool>),
Name = "Property4",
IsStatic = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class TUnit_TestProject_CustomDisplayNameTests__TestSource
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetProperty("Order"),
ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetProperty("Order", typeof(int)),
Type = typeof(int),
Name = "Order",
IsStatic = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ internal static class TUnit_TestProject_Bugs__4431_GenericClassWithClassDataSour
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>).GetProperty("DataSource"),
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassWithClassDataSource<>).GetProperty("DataSource", typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource)),
Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource),
Name = "DataSource",
IsStatic = false,
Expand Down Expand Up @@ -1240,7 +1240,7 @@ internal static class TUnit_TestProject_Bugs__4431_GenericClassGenericMethodWith
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource"),
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._4431.GenericClassGenericMethodWithDataSources<>).GetProperty("DataSource", typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource)),
Type = typeof(global::TUnit.TestProject.Bugs._4431.TestDataSource),
Name = "DataSource",
IsStatic = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property1"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property1", typeof(string)),
Type = typeof(string),
Name = "Property1",
IsStatic = false,
Expand All @@ -44,7 +44,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property2"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property2", typeof(string)),
Type = typeof(string),
Name = "Property2",
IsStatic = false,
Expand All @@ -55,7 +55,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property3"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property3", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property3",
IsStatic = false,
Expand All @@ -66,7 +66,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property4"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property4", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property4",
IsStatic = false,
Expand All @@ -77,7 +77,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property5"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property5", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property5",
IsStatic = false,
Expand All @@ -88,7 +88,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property6"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property6", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property6",
IsStatic = false,
Expand All @@ -99,7 +99,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property7"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property7", typeof(string)),
Type = typeof(string),
Name = "Property7",
IsStatic = false,
Expand All @@ -110,7 +110,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("StaticProperty"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("StaticProperty", typeof(global::TUnit.TestProject.PropertySetterTests.StaticInnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.StaticInnerModel),
Name = "StaticProperty",
IsStatic = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static class TUnit_TestProject_Bugs__1924_None_BaseClass__TestSource
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetProperty("Data"),
ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetProperty("Data", typeof(global::TUnit.TestProject.Bugs._1924.DataClass)),
Type = typeof(global::TUnit.TestProject.Bugs._1924.DataClass),
Name = "Data",
IsStatic = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
{
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property1"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property1", typeof(string)),
Type = typeof(string),
Name = "Property1",
IsStatic = false,
Expand All @@ -44,7 +44,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property2"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property2", typeof(string)),
Type = typeof(string),
Name = "Property2",
IsStatic = false,
Expand All @@ -55,7 +55,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property3"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property3", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property3",
IsStatic = false,
Expand All @@ -66,7 +66,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property4"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property4", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property4",
IsStatic = false,
Expand All @@ -77,7 +77,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property5"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property5", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property5",
IsStatic = false,
Expand All @@ -88,7 +88,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property6"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property6", typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.InnerModel),
Name = "Property6",
IsStatic = false,
Expand All @@ -99,7 +99,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property7"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("Property7", typeof(string)),
Type = typeof(string),
Name = "Property7",
IsStatic = false,
Expand All @@ -110,7 +110,7 @@ internal static class TUnit_TestProject_PropertySetterTests__TestSource
},
new global::TUnit.Core.PropertyMetadata
{
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("StaticProperty"),
ReflectionInfo = typeof(global::TUnit.TestProject.PropertySetterTests).GetProperty("StaticProperty", typeof(global::TUnit.TestProject.PropertySetterTests.StaticInnerModel)),
Type = typeof(global::TUnit.TestProject.PropertySetterTests.StaticInnerModel),
Name = "StaticProperty",
IsStatic = true,
Expand Down
Loading
Loading