Skip to content

Commit 7b739f5

Browse files
committed
Adjust tests accordingly.
1 parent 2363be7 commit 7b739f5

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

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+
IEnumerable<KeyValuePair<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, IEnumerable<KeyValuePair<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, IEnumerable<KeyValuePair<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/TestAssemblyLoaderFactory.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ 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, (string, string)[] assemblyTexts, IEnumerable<KeyValuePair<string, ReportDiagnostic>>? diagnosticOptions = null, bool respectInternals = false, bool allowUnsafe = false)
1515
{
1616
if (assemblyTexts.Length == 0)
1717
{
18-
return (new AssemblySymbolLoader(log, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals), new Dictionary<string, IAssemblySymbol>());
18+
return (new AssemblySymbolLoader(log, diagnosticOptions, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals),
19+
new Dictionary<string, IAssemblySymbol>());
1920
}
2021

21-
AssemblySymbolLoader loader = new(log, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals);
22+
AssemblySymbolLoader loader = new(log, diagnosticOptions, resolveAssemblyReferences: true, includeInternalSymbols: respectInternals);
2223
loader.AddReferenceSearchPaths(typeof(object).Assembly!.Location!);
2324
loader.AddReferenceSearchPaths(typeof(DynamicAttribute).Assembly!.Location!);
2425

2526
Dictionary<string, IAssemblySymbol> assemblySymbols = new();
2627
foreach ((string assemblyName, string assemblyText) in assemblyTexts)
2728
{
28-
using Stream assemblyStream = SymbolFactory.EmitAssemblyStreamFromSyntax(assemblyText, enableNullable: true, allowUnsafe: allowUnsafe, assemblyName: assemblyName);
29+
using Stream assemblyStream = SymbolFactory.EmitAssemblyStreamFromSyntax(assemblyText, diagnosticOptions, enableNullable: true, allowUnsafe: allowUnsafe, assemblyName: assemblyName);
2930
if (loader.LoadAssembly(assemblyName, assemblyStream) is IAssemblySymbol assemblySymbol)
3031
{
3132
assemblySymbols.Add(assemblyName, assemblySymbol);

0 commit comments

Comments
 (0)