-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
ApiApprovalBase.cs
53 lines (47 loc) · 2.19 KB
/
ApiApprovalBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (c) 2023 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using PublicApiGenerator;
using VerifyTests;
using VerifyXunit;
/// <summary>
/// Tests for API approvals.
/// </summary>
[ExcludeFromCodeCoverage]
#pragma warning disable CA1050 // Declare types in namespaces
#pragma warning disable RCS1110 // Declare type inside namespace.
public abstract class ApiApprovalBase
#pragma warning restore RCS1110 // Declare type inside namespace.
#pragma warning restore CA1050 // Declare types in namespaces
{
/// <summary>
/// Checks the assembly to detect the public API. Generates a received/approved version of the API.
/// </summary>
/// <param name="assembly">The assembly to check.</param>
/// <param name="filePath">Auto populated file path.</param>
/// <returns>A task to monitor the progress.</returns>
protected static Task CheckApproval(Assembly assembly, [CallerFilePath]string? filePath = null)
{
if (filePath is null)
{
return Task.CompletedTask;
}
var generatorOptions = new ApiGeneratorOptions { AllowNamespacePrefixes = new[] { "ReactiveUI" } };
var apiText = assembly.GeneratePublicApi(generatorOptions);
var verifySettings = new VerifySettings();
return Verifier.Verify(apiText, verifySettings, filePath)
.UniqueForRuntimeAndVersion()
.ScrubEmptyLines()
.ScrubLines(l =>
l.StartsWith("[assembly: AssemblyVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyFileVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: AssemblyInformationalVersion(", StringComparison.InvariantCulture) ||
l.StartsWith("[assembly: System.Reflection.AssemblyMetadata(", StringComparison.InvariantCulture));
}
}