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

Fix inconsistencies for record types across NET 6.x.x SDK #247

Merged
merged 12 commits into from
Dec 30, 2022
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@ jobs:
fail-fast: false
matrix:
runs-on: [ubuntu-latest, windows-latest]
name: ${{ matrix.runs-on }}
sdk: ["6.0.301", "6.0.302", "6.0.303", "6.0.400"]
stakx marked this conversation as resolved.
Show resolved Hide resolved
name: ${{ matrix.runs-on }}-${{ matrix.sdk }}
runs-on: ${{ matrix.runs-on }}
steps:
- name: Setup .NET Core 3.1 SDK # should always be installed for 3.1 runtime
uses: actions/setup-dotnet@v2
with:
dotnet-version: 3.1.422
- name: Setup .NET Core SDK
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ matrix.sdk }}
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
- run: dotnet --info
- uses: actions/checkout@af513c7a016048ae468971c52ed77d9562c7c819
- if: contains(matrix.runs-on, 'windows')
Expand All @@ -24,4 +33,4 @@ jobs:
- uses: actions/upload-artifact@master
with:
name: nugets
path: nugets/
path: nugets/
5 changes: 5 additions & 0 deletions src/PublicApiGenerator/ApiGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ static bool ShouldIncludeType(TypeDefinition t)

static bool ShouldIncludeMember(IMemberDefinition m, string[] whitelistedNamespacePrefixes)
{
// https://github.com/PublicApiGenerator/PublicApiGenerator/issues/245
bool isRecord = m.DeclaringType.GetMethods().Any(m => m.Name == "<Clone>$");
if (isRecord && m.Name == "EqualityContract")
return false;

return !m.IsCompilerGenerated() && !IsDotNetTypeMember(m, whitelistedNamespacePrefixes) && !(m is FieldDefinition);
}

Expand Down
15 changes: 13 additions & 2 deletions src/PublicApiGeneratorTests/ApiGeneratorTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ private static void AssertPublicApi(Assembly assembly, string expectedOutput, A

var actualOutput = assembly.GeneratePublicApi(options);
actualOutput = StripEmptyLines.Replace(actualOutput, string.Empty);
Assert.Equal(expectedOutput, actualOutput, ignoreCase: false, ignoreLineEndingDifferences: true,
ignoreWhiteSpaceDifferences: true);
try
{
Assert.Equal(expectedOutput, actualOutput, ignoreCase: false, ignoreLineEndingDifferences: true,
ignoreWhiteSpaceDifferences: true);
}
catch
{
Console.WriteLine("Full expected output:");
Console.WriteLine(expectedOutput);
Console.WriteLine("Full actual output:");
Console.WriteLine(actualOutput);
throw;
}
stakx marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
20 changes: 19 additions & 1 deletion src/PublicApiGeneratorTests/Assembly_attributes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Runtime.InteropServices;
using PublicApiGenerator;
using PublicApiGeneratorTests.Examples;
Expand All @@ -21,6 +21,23 @@ public class Assembly_attributes : ApiGeneratorTestsBase
[Fact]
public void Attributes()
{
#if NET6_0
var api = @"[assembly: PublicApiGeneratorTests.Examples.AttributeWithMultiplePositionalParameters(42, ""Hello"")]
[assembly: PublicApiGeneratorTests.Examples.AttributeWithNamedParameter(IntValue=42, StringValue=""Hello"")]
[assembly: PublicApiGeneratorTests.Examples.AttributeWithPositionalParameters1(""Hello"")]
[assembly: PublicApiGeneratorTests.Examples.AttributeWithPositionalParameters2(42)]
[assembly: PublicApiGeneratorTests.Examples.Simple]
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Runtime.InteropServices.Guid(""3B8D506A-5247-47FF-B053-D29A51A97C33"")]
[assembly: System.Runtime.Versioning.TargetFramework("".NETCoreApp,Version=v6.0"", FrameworkDisplayName="""")]
sungam3r marked this conversation as resolved.
Show resolved Hide resolved
namespace PublicApiGeneratorTests.Examples
{
public class NotImportant
{
public NotImportant() { }
}
}";
#else
var api = @"[assembly: PublicApiGeneratorTests.Examples.AttributeWithMultiplePositionalParameters(42, ""Hello"")]
[assembly: PublicApiGeneratorTests.Examples.AttributeWithNamedParameter(IntValue=42, StringValue=""Hello"")]
[assembly: PublicApiGeneratorTests.Examples.AttributeWithPositionalParameters1(""Hello"")]
Expand All @@ -36,6 +53,7 @@ public class NotImportant
public NotImportant() { }
}
}";
#endif

AssertPublicApi<NotImportant>(api, new ApiGeneratorOptions { IncludeAssemblyAttributes = true });
}
Expand Down
17 changes: 17 additions & 0 deletions src/PublicApiGeneratorTests/IsExternalInit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#if !NET5_0_OR_GREATER

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
/// <summary>
/// Reserved to be used by the compiler for tracking metadata.
/// This class should not be used by developers in source code.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class IsExternalInit
{
}
}

#endif
2 changes: 1 addition & 1 deletion src/PublicApiGeneratorTests/PublicApiGeneratorTests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand Down
28 changes: 28 additions & 0 deletions src/PublicApiGeneratorTests/Record.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using PublicApiGeneratorTests.Examples;
using Xunit;

namespace PublicApiGeneratorTests
{
public class Record : ApiGeneratorTestsBase
{
[Fact]
public void Should_output_simple_record()
{
AssertPublicApi<User>(
@"namespace PublicApiGeneratorTests.Examples
{
public class User : System.IEquatable<PublicApiGeneratorTests.Examples.User>
{
public User(string login, string password) { }
public string login { get; set; }
public string password { get; set; }
}
}");
}
}

namespace Examples
{
public record User(string login, string password);
}
}