Skip to content

Commit d401120

Browse files
committed
Adjust tests accordingly.
1 parent 07308ff commit d401120

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

test/Microsoft.DotNet.ApiCompatibility.Tests/Microsoft.DotNet.ApiCompatibility.Tests.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
<ItemGroup>
1919
<ProjectReference Include="$(RepoRoot)src\Compatibility\ApiCompat\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" />
20+
<ProjectReference Include="$(RepoRoot)src\Compatibility\GenAPI\Microsoft.DotNet.GenAPI\Microsoft.DotNet.GenAPI.csproj" />
21+
<ProjectReference Include="$(RepoRoot)src\Compatibility\Microsoft.DotNet.ApiSymbolExtensions\Microsoft.DotNet.ApiSymbolExtensions.csproj" />
2022
<ProjectReference Include="..\Microsoft.NET.TestFramework\Microsoft.NET.TestFramework.csproj" />
21-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" />
2223
</ItemGroup>
24+
2325
</Project>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ public static string EmitAssemblyFromSyntax(string syntax,
3131
}
3232

3333
public static Stream EmitAssemblyStreamFromSyntax(string syntax,
34+
Dictionary<string, ReportDiagnostic> diagnosticOptions = null,
3435
bool enableNullable = false,
3536
byte[] publicKey = null,
3637
[CallerMemberName] string assemblyName = "",
3738
bool allowUnsafe = false)
3839
{
39-
CSharpCompilation compilation = CreateCSharpCompilationFromSyntax(syntax, assemblyName, enableNullable, publicKey, allowUnsafe);
40+
CSharpCompilation compilation = CreateCSharpCompilationFromSyntax(syntax, assemblyName, enableNullable, publicKey, allowUnsafe, diagnosticOptions);
4041

4142
Assert.Empty(compilation.GetDiagnostics());
4243

@@ -76,9 +77,9 @@ public static IAssemblySymbol GetAssemblyFromSyntaxWithReferences(string syntax,
7677
return compilation.Assembly;
7778
}
7879

79-
private static CSharpCompilation CreateCSharpCompilationFromSyntax(string syntax, string name, bool enableNullable, byte[] publicKey, bool allowUnsafe)
80+
private static CSharpCompilation CreateCSharpCompilationFromSyntax(string syntax, string name, bool enableNullable, byte[] publicKey, bool allowUnsafe, Dictionary<string, ReportDiagnostic> diagnosticOptions = null)
8081
{
81-
CSharpCompilation compilation = CreateCSharpCompilation(name, enableNullable, publicKey, allowUnsafe);
82+
CSharpCompilation compilation = CreateCSharpCompilation(name, enableNullable, publicKey, allowUnsafe, diagnosticOptions);
8283
return compilation.AddSyntaxTrees(GetSyntaxTree(syntax));
8384
}
8485

@@ -94,15 +95,15 @@ private static SyntaxTree GetSyntaxTree(string syntax)
9495
return CSharpSyntaxTree.ParseText(syntax, ParseOptions);
9596
}
9697

97-
private static CSharpCompilation CreateCSharpCompilation(string name, bool enableNullable, byte[] publicKey, bool allowUnsafe)
98+
private static CSharpCompilation CreateCSharpCompilation(string name, bool enableNullable, byte[] publicKey, bool allowUnsafe, Dictionary<string, ReportDiagnostic> diagnosticOptions = null)
9899
{
99100
bool publicSign = publicKey != null ? true : false;
100101
var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary,
101102
publicSign: publicSign,
102103
cryptoPublicKey: publicSign ? publicKey.ToImmutableArray() : default,
103104
nullableContextOptions: enableNullable ? NullableContextOptions.Enable : NullableContextOptions.Disable,
104105
allowUnsafe: allowUnsafe,
105-
specificDiagnosticOptions: DiagnosticOptions);
106+
specificDiagnosticOptions: diagnosticOptions ?? DiagnosticOptions);
106107

107108
return CSharpCompilation.Create(name, options: compilationOptions, references: DefaultReferences);
108109
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
using Microsoft.DotNet.ApiSymbolExtensions;
1010
using Microsoft.DotNet.ApiSymbolExtensions.Filtering;
1111
using Microsoft.DotNet.ApiSymbolExtensions.Logging;
12-
using Microsoft.DotNet.ApiSymbolExtensions.Tests;
13-
using Moq;
1412

1513
namespace Microsoft.DotNet.GenAPI.Tests
1614
{
1715
public class CSharpFileBuilderTests
1816
{
17+
private readonly ILog _logger = new ConsoleLog(MessageImportance.High);
18+
1919
class AllowAllFilter : ISymbolFilter
2020
{
2121
public bool Include(ISymbol symbol) => true;
@@ -40,7 +40,7 @@ private void RunTest(string original,
4040
Mock<ILog> log = new();
4141

4242
(IAssemblySymbolLoader loader, Dictionary<string, IAssemblySymbol> assemblySymbols) = TestAssemblyLoaderFactory
43-
.CreateFromTexts(log.Object, assemblyTexts: [(assemblyName, original)], respectInternals: includeInternalSymbols, allowUnsafe);
43+
.CreateFromTexts(log.Object, assemblyTexts: [(assemblyName, original)], respectInternals: includeInternalSymbols, allowUnsafe: allowUnsafe);
4444

4545
ISymbolFilter symbolFilter = SymbolFilterFactory.GetFilterFromList([], null, includeInternalSymbols, includeEffectivelyPrivateSymbols, includeExplicitInterfaceImplementationSymbols);
4646
ISymbolFilter attributeDataSymbolFilter = SymbolFilterFactory.GetFilterFromList(excludedAttributeList, null, includeInternalSymbols, includeEffectivelyPrivateSymbols, includeExplicitInterfaceImplementationSymbols);

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,27 @@ namespace Microsoft.DotNet.GenAPI.Tests;
1111

1212
public class TestAssemblyLoaderFactory
1313
{
14-
public static (IAssemblySymbolLoader, Dictionary<string, IAssemblySymbol>) CreateFromTexts(ILog log, (string, string)[] assemblyTexts, bool respectInternals = false, bool allowUnsafe = false)
14+
public static (IAssemblySymbolLoader, Dictionary<string, IAssemblySymbol>) CreateFromTexts(ILog log,
15+
(string, string)[] assemblyTexts,
16+
Dictionary<string, ReportDiagnostic>? diagnosticOptions = null,
17+
bool respectInternals = false,
18+
bool allowUnsafe = false)
1519
{
20+
AssemblySymbolLoader loader;
1621
if (assemblyTexts.Length == 0)
1722
{
18-
return (new AssemblySymbolLoader(log, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals), new Dictionary<string, IAssemblySymbol>());
23+
loader = new AssemblySymbolLoader(log, diagnosticOptions, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals);
24+
return (loader, new Dictionary<string, IAssemblySymbol>());
1925
}
2026

21-
AssemblySymbolLoader loader = new(log, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals);
27+
loader = new AssemblySymbolLoader(log, diagnosticOptions, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals);
2228
loader.AddReferenceSearchPaths(typeof(object).Assembly!.Location!);
2329
loader.AddReferenceSearchPaths(typeof(DynamicAttribute).Assembly!.Location!);
2430

2531
Dictionary<string, IAssemblySymbol> assemblySymbols = new();
2632
foreach ((string assemblyName, string assemblyText) in assemblyTexts)
2733
{
28-
using Stream assemblyStream = SymbolFactory.EmitAssemblyStreamFromSyntax(assemblyText, enableNullable: true, allowUnsafe: allowUnsafe, assemblyName: assemblyName);
34+
using Stream assemblyStream = SymbolFactory.EmitAssemblyStreamFromSyntax(assemblyText, diagnosticOptions, enableNullable: true, allowUnsafe: allowUnsafe, assemblyName: assemblyName);
2935
if (loader.LoadAssembly(assemblyName, assemblyStream) is IAssemblySymbol assemblySymbol)
3036
{
3137
assemblySymbols.Add(assemblyName, assemblySymbol);

0 commit comments

Comments
 (0)