Skip to content

Commit b5dd360

Browse files
committed
Rename logger to log, use mock logger where needed.
1 parent c0d9028 commit b5dd360

File tree

10 files changed

+52
-53
lines changed

10 files changed

+52
-53
lines changed

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/CSharpFileBuilder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace Microsoft.DotNet.GenAPI
2525
/// </summary>
2626
public sealed class CSharpFileBuilder : IAssemblySymbolWriter, IDisposable
2727
{
28-
private readonly ILog _logger;
28+
private readonly ILog _log;
2929
private readonly TextWriter _textWriter;
3030
private readonly ISymbolFilter _symbolFilter;
3131
private readonly ISymbolFilter _attributeDataSymbolFilter;
@@ -35,15 +35,15 @@ public sealed class CSharpFileBuilder : IAssemblySymbolWriter, IDisposable
3535
private readonly SyntaxGenerator _syntaxGenerator;
3636
private readonly IEnumerable<MetadataReference> _metadataReferences;
3737

38-
public CSharpFileBuilder(ILog logger,
38+
public CSharpFileBuilder(ILog log,
3939
ISymbolFilter symbolFilter,
4040
ISymbolFilter attributeDataSymbolFilter,
4141
TextWriter textWriter,
4242
string? exceptionMessage,
4343
bool includeAssemblyAttributes,
4444
IEnumerable<MetadataReference> metadataReferences)
4545
{
46-
_logger = logger;
46+
_log = log;
4747
_textWriter = textWriter;
4848
_symbolFilter = symbolFilter;
4949
_attributeDataSymbolFilter = attributeDataSymbolFilter;
@@ -293,7 +293,7 @@ private SyntaxNode GenerateForwardedTypeAssemblyAttributes(IAssemblySymbol assem
293293
}
294294
else
295295
{
296-
_logger.LogWarning(string.Format(
296+
_log.LogWarning(string.Format(
297297
Resources.ResolveTypeForwardFailed,
298298
symbol.ToDisplayString(),
299299
$"{symbol.ContainingAssembly.Name}.dll"));

src/Compatibility/GenAPI/Microsoft.DotNet.GenAPI/GenAPIApp.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static class GenAPIApp
2121
/// <summary>
2222
/// Initialize and run Roslyn-based GenAPI tool.
2323
/// </summary>
24-
public static void Run(ILog logger,
24+
public static void Run(ILog log,
2525
string[] assemblies,
2626
string[]? assemblyReferences,
2727
string? outputPath,
@@ -35,7 +35,7 @@ public static void Run(ILog logger,
3535
bool resolveAssemblyReferences = assemblyReferences?.Length > 0;
3636

3737
// Create, configure and execute the assembly loader.
38-
AssemblySymbolLoader loader = new(logger, resolveAssemblyReferences, respectInternals);
38+
AssemblySymbolLoader loader = new(log, resolveAssemblyReferences, respectInternals);
3939
if (assemblyReferences is not null)
4040
{
4141
loader.AddReferenceSearchPaths(assemblyReferences);
@@ -75,7 +75,7 @@ public static void Run(ILog logger,
7575
using TextWriter textWriter = GetTextWriter(outputPath, assemblySymbol.Name);
7676
textWriter.Write(headerFileText);
7777

78-
using CSharpFileBuilder fileBuilder = new(logger,
78+
using CSharpFileBuilder fileBuilder = new(log,
7979
symbolFilter,
8080
attributeDataSymbolFilter,
8181
textWriter,

src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoader.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Microsoft.DotNet.ApiSymbolExtensions
1616
/// </summary>
1717
public class AssemblySymbolLoader : IAssemblySymbolLoader
1818
{
19-
private readonly ILog _logger;
19+
private readonly ILog _log;
2020
// Dictionary that holds the paths to help loading dependencies. Keys will be assembly name and
2121
// value are the containing folder.
2222
private readonly Dictionary<string, string> _referencePathFiles = new(StringComparer.OrdinalIgnoreCase);
@@ -39,12 +39,12 @@ public class AssemblySymbolLoader : IAssemblySymbolLoader
3939
/// <summary>
4040
/// Creates a new instance of the <see cref="AssemblySymbolLoader"/> class.
4141
/// </summary>
42-
/// <param name="logger">A logger instance for logging message.</param>
42+
/// <param name="log">A logger instance for logging message.</param>
4343
/// <param name="resolveAssemblyReferences">True to attempt to load references for loaded assemblies from the locations specified with <see cref="AddReferenceSearchPaths(string[])"/>. Default is false.</param>
4444
/// <param name="includeInternalSymbols">True to include all internal metadata for assemblies loaded. Default is false which only includes public and some internal metadata. <seealso cref="MetadataImportOptions"/></param>
45-
public AssemblySymbolLoader(ILog logger, bool resolveAssemblyReferences = false, bool includeInternalSymbols = false)
45+
public AssemblySymbolLoader(ILog log, bool resolveAssemblyReferences = false, bool includeInternalSymbols = false)
4646
{
47-
_logger = logger;
47+
_log = log;
4848
_loadedAssemblies = [];
4949
CSharpCompilationOptions compilationOptions = new(OutputKind.DynamicallyLinkedLibrary, nullableContextOptions: NullableContextOptions.Enable,
5050
metadataImportOptions: includeInternalSymbols ? MetadataImportOptions.Internal : MetadataImportOptions.Public);
@@ -398,12 +398,12 @@ public void LogAllDiagnostics(string? headerMessage = null)
398398
{
399399
if (!string.IsNullOrEmpty(headerMessage))
400400
{
401-
_logger.LogWarning(headerMessage!);
401+
_log.LogWarning(headerMessage!);
402402
}
403403

404404
foreach (Diagnostic warning in roslynDiagnostics)
405405
{
406-
_logger.LogWarning(warning.Id, warning.ToString());
406+
_log.LogWarning(warning.Id, warning.ToString());
407407
}
408408
}
409409
}
@@ -415,12 +415,12 @@ public void LogAllWarnings(string? headerMessage = null)
415415
{
416416
if (!string.IsNullOrEmpty(headerMessage))
417417
{
418-
_logger.LogWarning(headerMessage!);
418+
_log.LogWarning(headerMessage!);
419419
}
420420

421421
foreach (AssemblyLoadWarning warning in loadWarnings)
422422
{
423-
_logger.LogWarning(warning.DiagnosticId, warning.Message);
423+
_log.LogWarning(warning.DiagnosticId, warning.Message);
424424
}
425425
}
426426
}

src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/AssemblySymbolLoaderFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ namespace Microsoft.DotNet.ApiSymbolExtensions
88
/// <summary>
99
/// Factory to create an AssemblySymbolLoader
1010
/// </summary>
11-
/// <param name="logger">A logger instance used for logging messages.</param>
11+
/// <param name="log">A logger instance used for logging messages.</param>
1212
/// <param name="includeInternalSymbols">True to include internal API when reading assemblies from the <see cref="AssemblySymbolLoader"/> created.</param>
13-
public sealed class AssemblySymbolLoaderFactory(ILog logger, bool includeInternalSymbols = false) : IAssemblySymbolLoaderFactory
13+
public sealed class AssemblySymbolLoaderFactory(ILog log, bool includeInternalSymbols = false) : IAssemblySymbolLoaderFactory
1414
{
1515
/// <inheritdoc />
1616
public IAssemblySymbolLoader Create(bool shouldResolveReferences) =>
17-
new AssemblySymbolLoader(logger, shouldResolveReferences, includeInternalSymbols);
17+
new AssemblySymbolLoader(log, shouldResolveReferences, includeInternalSymbols);
1818
}
1919
}

test/Microsoft.DotNet.ApiCompatibility.Tests/Rules/AssemblyIdentityMustMatchTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
using Microsoft.CodeAnalysis.CSharp;
88
using Microsoft.DotNet.ApiCompatibility.Tests;
99
using Microsoft.DotNet.ApiSymbolExtensions;
10-
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
1110
using Microsoft.DotNet.ApiSymbolExtensions.Tests;
1211

1312
namespace Microsoft.DotNet.ApiCompatibility.Rules.Tests
1413
{
1514
public class AssemblyIdentityMustMatchTests
1615
{
17-
private static readonly TestRuleFactory s_ruleFactory = new((settings, context) => new AssemblyIdentityMustMatch(new SuppressibleTestLog(), settings, context));
16+
private static readonly SuppressibleTestLog s_log = new();
17+
private static readonly TestRuleFactory s_ruleFactory = new((settings, context) => new AssemblyIdentityMustMatch(s_log, settings, context));
1818

1919
private static readonly byte[] _publicKey = new byte[]
2020
{
@@ -197,10 +197,8 @@ public void RetargetableFlagSet(bool strictMode)
197197
string leftAssembly = SymbolFactory.EmitAssemblyFromSyntax(syntax, publicKey: _publicKey);
198198
string rightAssembly = SymbolFactory.EmitAssemblyFromSyntax(syntax);
199199

200-
ILog logger = new ConsoleLog(MessageImportance.High);
201-
202-
IAssemblySymbol leftSymbol = new AssemblySymbolLoader(logger).LoadAssembly(leftAssembly);
203-
IAssemblySymbol rightSymbol = new AssemblySymbolLoader(logger).LoadAssembly(rightAssembly);
200+
IAssemblySymbol leftSymbol = new AssemblySymbolLoader(s_log).LoadAssembly(leftAssembly);
201+
IAssemblySymbol rightSymbol = new AssemblySymbolLoader(s_log).LoadAssembly(rightAssembly);
204202

205203
Assert.True(leftSymbol.Identity.IsRetargetable);
206204
Assert.True(rightSymbol.Identity.IsRetargetable);

test/Microsoft.DotNet.ApiCompatibility.Tests/SuppressibleTestLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Microsoft.DotNet.ApiCompatibility.Tests
88
{
9-
internal class SuppressibleTestLog : ISuppressibleLog
9+
public class SuppressibleTestLog : ISuppressibleLog
1010
{
1111
public List<string> info = [];
1212
public List<string> errors = [];

test/Microsoft.DotNet.ApiSymbolExtensions.Tests/AssemblySymbolLoaderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
using System.Collections.Concurrent;
77
using System.Reflection;
88
using Microsoft.CodeAnalysis;
9-
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
9+
using Microsoft.DotNet.ApiCompatibility.Tests;
1010
using Microsoft.DotNet.Cli.Utils;
1111

1212
namespace Microsoft.DotNet.ApiSymbolExtensions.Tests
1313
{
1414
public class AssemblySymbolLoaderTests : SdkTest
1515
{
16-
private readonly ILog _logger = new ConsoleLog(MessageImportance.High);
16+
private readonly SuppressibleTestLog _logger = new();
1717

1818
public AssemblySymbolLoaderTests(ITestOutputHelper log) : base(log) { }
1919

test/Microsoft.DotNet.ApiSymbolExtensions.Tests/Microsoft.DotNet.ApiSymbolExtensions.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10+
<ProjectReference Include="$(RepoRoot)test\Microsoft.DotNet.ApiCompatibility.Tests\Microsoft.DotNet.ApiCompatibility.Tests.csproj" />
1011
<ProjectReference Include="$(RepoRoot)src\Compatibility\Microsoft.DotNet.ApiSymbolExtensions\Microsoft.DotNet.ApiSymbolExtensions.csproj" />
1112
<ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" />
1213
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />

test/Microsoft.DotNet.GenAPI.Tests/CSharpFileBuilderTests.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using Microsoft.CodeAnalysis.CSharp;
99
using Microsoft.DotNet.ApiSymbolExtensions;
1010
using Microsoft.DotNet.ApiSymbolExtensions.Filtering;
11-
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
11+
using Microsoft.DotNet.ApiCompatibility.Tests;
1212
using Microsoft.DotNet.ApiSymbolExtensions.Tests;
1313
using Microsoft.DotNet.GenAPI.Filtering;
1414

@@ -54,10 +54,10 @@ private void RunTest(string original,
5454
}
5555
attributeDataSymbolFilter.Add(accessibilitySymbolFilter);
5656

57-
ILog logger = new ConsoleLog(MessageImportance.Low);
57+
SuppressibleTestLog log = new();
5858

5959
IAssemblySymbolWriter csharpFileBuilder = new CSharpFileBuilder(
60-
logger,
60+
log,
6161
symbolFilter,
6262
attributeDataSymbolFilter,
6363
stringWriter,
@@ -66,7 +66,7 @@ private void RunTest(string original,
6666
MetadataReferences);
6767

6868
using Stream assemblyStream = SymbolFactory.EmitAssemblyStreamFromSyntax(original, enableNullable: true, allowUnsafe: allowUnsafe, assemblyName: assemblyName);
69-
AssemblySymbolLoader assemblySymbolLoader = new(logger, resolveAssemblyReferences: true, includeInternalSymbols: includeInternalSymbols);
69+
AssemblySymbolLoader assemblySymbolLoader = new(log, resolveAssemblyReferences: true, includeInternalSymbols: includeInternalSymbols);
7070
assemblySymbolLoader.AddReferenceSearchPaths(typeof(object).Assembly!.Location!);
7171
assemblySymbolLoader.AddReferenceSearchPaths(typeof(DynamicAttribute).Assembly!.Location!);
7272
IAssemblySymbol assemblySymbol = assemblySymbolLoader.LoadAssembly(assemblyName, assemblyStream);
@@ -233,7 +233,7 @@ public void TestRecordDeclaration()
233233
{
234234
RunTest(original: """
235235
namespace Foo
236-
{
236+
{
237237
public record RecordClass;
238238
public record RecordClass1(int i);
239239
public record RecordClass2(string s, int i);
@@ -242,7 +242,7 @@ public record DerivedRecord2(string x, int i, double d) : RecordClass2(default(s
242242
public record DerivedRecord3(string x, int i, double d) : RecordClass2(default(string)!, i);
243243
public record DerivedRecord4(double d) : RecordClass2(default(string)!, default);
244244
public record DerivedRecord5() : RecordClass2(default(string)!, default);
245-
245+
246246
public record RecordClassWithMethods(int i)
247247
{
248248
public void DoSomething() { }
@@ -347,11 +347,11 @@ public void TestRecordStructDeclaration()
347347
RunTest(original: """
348348
namespace Foo
349349
{
350-
351-
public record struct RecordStruct;
350+
351+
public record struct RecordStruct;
352352
public record struct RecordStruct1(int i);
353353
public record struct RecordStruct2(string s, int i);
354-
354+
355355
public record struct RecordStructWithMethods(int i)
356356
{
357357
public void DoSomething() { }
@@ -369,10 +369,10 @@ public record struct RecordStructWithConstructors(int i)
369369
public RecordStructWithConstructors() : this(1) { }
370370
public RecordStructWithConstructors(string s) : this(int.Parse(s)) { }
371371
}
372-
372+
373373
}
374374
""",
375-
expected: """
375+
expected: """
376376
namespace Foo
377377
{
378378
public partial struct RecordStruct : System.IEquatable<RecordStruct>
@@ -1646,12 +1646,12 @@ public class B
16461646
{
16471647
public B(int i) {}
16481648
}
1649-
1649+
16501650
public class C : B
16511651
{
16521652
internal C() : base(0) {}
16531653
}
1654-
1654+
16551655
public class D : B
16561656
{
16571657
internal D(int i) : base(i) {}
@@ -1674,7 +1674,7 @@ public partial class B
16741674
{
16751675
public B(int i) {}
16761676
}
1677-
1677+
16781678
public partial class C : B
16791679
{
16801680
internal C() : base(default) {}
@@ -1704,12 +1704,12 @@ public class B
17041704
{
17051705
public B(int i) {}
17061706
}
1707-
1707+
17081708
public class C : B
17091709
{
17101710
internal C() : base(0) {}
17111711
}
1712-
1712+
17131713
public class D : B
17141714
{
17151715
internal D(int i) : base(i) {}
@@ -1783,8 +1783,8 @@ namespace A
17831783
public partial class B
17841784
{
17851785
protected B() {}
1786-
}
1787-
1786+
}
1787+
17881788
public partial class C : B
17891789
{
17901790
internal C() {}
@@ -1937,7 +1937,7 @@ public class B : A
19371937
public class D { }
19381938
19391939
public class Id { }
1940-
1940+
19411941
public class V { }
19421942
}
19431943
""",
@@ -2830,7 +2830,7 @@ public class Foo<T> : System.Collections.ICollection, System.Collections.Generic
28302830
28312831
}
28322832
}
2833-
2833+
28342834
""",
28352835
// https://github.com/dotnet/sdk/issues/32195 tracks interface expansion
28362836
expected: """
@@ -2911,7 +2911,7 @@ namespace N {
29112911
public ref struct C<T>
29122912
where T : unmanaged
29132913
{
2914-
public required (string? k, dynamic v, nint n) X { get; init; }
2914+
public required (string? k, dynamic v, nint n) X { get; init; }
29152915
}
29162916
29172917
public static class E
@@ -2920,7 +2920,7 @@ public static void M<T>(this object c, scoped System.ReadOnlySpan<T> values) { }
29202920
}
29212921
}
29222922
""",
2923-
expected: """
2923+
expected: """
29242924
namespace N
29252925
{
29262926
public ref partial struct C<T>
@@ -2984,7 +2984,7 @@ public void TestExplicitInterfaceNonGenericCollections()
29842984
namespace a
29852985
{
29862986
#pragma warning disable CS8597
2987-
2987+
29882988
public partial class MyStringCollection : ICollection, IEnumerable, IList
29892989
{
29902990
public int Count { get { throw null; } }
@@ -3008,7 +3008,7 @@ public void RemoveAt(int index) { }
30083008
void ICollection.CopyTo(Array array, int index) { }
30093009
IEnumerator IEnumerable.GetEnumerator() { throw null; }
30103010
int IList.Add(object? value) { throw null; }
3011-
bool IList.Contains(object? value) { throw null; }
3011+
bool IList.Contains(object? value) { throw null; }
30123012
int IList.IndexOf(object? value) { throw null; }
30133013
void IList.Insert(int index, object? value) { }
30143014
void IList.Remove(object? value) { }
@@ -3017,7 +3017,7 @@ void IList.Remove(object? value) { }
30173017
#pragma warning restore CS8597
30183018
}
30193019
""",
3020-
expected: """
3020+
expected: """
30213021
namespace a
30223022
{
30233023
public partial class MyStringCollection : System.Collections.ICollection, System.Collections.IEnumerable, System.Collections.IList

test/Microsoft.DotNet.GenAPI.Tests/Microsoft.DotNet.GenAPI.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212

1313
<ItemGroup>
1414
<Compile Include="..\Microsoft.DotNet.ApiSymbolExtensions.Tests\SymbolFactory.cs" />
15-
<Compile Include="..\Microsoft.DotNet.ApiSymbolExtensions.Tests\TempDirectory.cs" />
1615
</ItemGroup>
1716

1817
<ItemGroup>
18+
<ProjectReference Include="$(RepoRoot)test\Microsoft.DotNet.ApiCompatibility.Tests\Microsoft.DotNet.ApiCompatibility.Tests.csproj" />
1919
<ProjectReference Include="$(RepoRoot)src\Compatibility\GenAPI\Microsoft.DotNet.GenAPI\Microsoft.DotNet.GenAPI.csproj" />
2020
<ProjectReference Include="$(RepoRoot)src\Compatibility\Microsoft.DotNet.ApiSymbolExtensions\Microsoft.DotNet.ApiSymbolExtensions.csproj" />
2121
<ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" />

0 commit comments

Comments
 (0)