Skip to content

Commit

Permalink
Fill out all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
333fred committed Dec 21, 2022
1 parent d12c1f3 commit 2327f50
Show file tree
Hide file tree
Showing 3 changed files with 627 additions and 52 deletions.
36 changes: 34 additions & 2 deletions src/Compilers/Test/Core/CommonTestBase.cs
Expand Up @@ -14,6 +14,7 @@
using System.Text;
using System.Xml.Linq;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Operations;
Expand Down Expand Up @@ -302,9 +303,33 @@ internal static MetadataReference GetILModuleReference(string ilSource, bool pre
IEnumerable<MetadataReference> referencedAssemblies = null,
IEnumerable<Compilation> referencedCompilations = null)
{
return CreateCSharpCompilation(assemblyName, assemblyIdentity: null, code, parseOptions, compilationOptions, referencedAssemblies, referencedCompilations);
}

protected CSharp.CSharpCompilation CreateCSharpCompilation(
AssemblyIdentity assemblyIdentity,
string code,
CSharp.CSharpParseOptions parseOptions = null,
CSharp.CSharpCompilationOptions compilationOptions = null,
IEnumerable<MetadataReference> referencedAssemblies = null,
IEnumerable<Compilation> referencedCompilations = null)
{
return CreateCSharpCompilation(assemblyName: null, assemblyIdentity, code, parseOptions, compilationOptions, referencedAssemblies, referencedCompilations);
}

private CSharp.CSharpCompilation CreateCSharpCompilation(
string assemblyName,
AssemblyIdentity assemblyIdentity,
string code,
CSharp.CSharpParseOptions parseOptions = null,
CSharp.CSharpCompilationOptions compilationOptions = null,
IEnumerable<MetadataReference> referencedAssemblies = null,
IEnumerable<Compilation> referencedCompilations = null)
{
Debug.Assert(assemblyName == null || assemblyIdentity == null || assemblyIdentity.Name == assemblyName);
if (assemblyName == null)
{
assemblyName = GetUniqueName();
assemblyName = assemblyIdentity?.Name ?? GetUniqueName();
}

if (parseOptions == null)
Expand Down Expand Up @@ -336,7 +361,14 @@ internal static MetadataReference GetILModuleReference(string ilSource, bool pre

var tree = CSharp.SyntaxFactory.ParseSyntaxTree(SourceText.From(code, encoding: null, SourceHashAlgorithms.Default), options: parseOptions);

return CSharp.CSharpCompilation.Create(assemblyName, new[] { tree }, references, compilationOptions);
var compilation = CSharp.CSharpCompilation.Create(assemblyName, new[] { tree }, references, compilationOptions);

if (assemblyIdentity != null)
{
((SourceAssemblySymbol)compilation.Assembly).lazyAssemblyIdentity = assemblyIdentity;
}

return compilation;
}

protected VisualBasic.VisualBasicCompilation CreateVisualBasicCompilation(
Expand Down
Expand Up @@ -947,7 +947,7 @@ Friend Module CompilationUtils
actualLine = actualReader.ReadLine()
End While

Assert.Equal(expectedPooledBuilder.ToStringAndFree(), actualPooledBuilder.ToStringAndFree())
AssertEx.Equal(expectedPooledBuilder.ToStringAndFree(), actualPooledBuilder.ToStringAndFree())
End Sub

' There are certain cases where multiple distinct errors are
Expand Down

0 comments on commit 2327f50

Please sign in to comment.