-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #158
- Loading branch information
Showing
10 changed files
with
165 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
using Basic.CompilerLog.Util; | ||
using Xunit; | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
public class CompilerCallTests | ||
{ | ||
[Fact] | ||
public void GetDiagnosticNameNoTargetFramework() | ||
{ | ||
var compilerCall = new CompilerCall( | ||
compilerFilePath: null, | ||
"test.csproj", | ||
CompilerCallKind.Regular, | ||
targetFramework: null, | ||
isCSharp: true, | ||
arguments: new (() => [])); | ||
Assert.Null(compilerCall.TargetFramework); | ||
Assert.Equal(compilerCall.ProjectFileName, compilerCall.GetDiagnosticName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
using System.Text; | ||
using Basic.Reference.Assemblies; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
/// <summary> | ||
/// Class that builds helper libraries that are useful in tests | ||
/// </summary> | ||
internal static class LibraryUtil | ||
{ | ||
internal static (string FileName, MemoryStream Image) GetSimplePia() | ||
{ | ||
var content1 = """ | ||
using System.Runtime.InteropServices; | ||
|
||
[Guid("E8E4B023-7408-4A71-B3F6-ADEDE0A8FE11")] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] | ||
public interface ICalculator | ||
{ | ||
[DispId(1)] // COM method identifiers | ||
int Add(int x, int y); | ||
|
||
[DispId(2)] | ||
int Subtract(int x, int y); | ||
} | ||
|
||
"""; | ||
|
||
var content2 = """ | ||
using System.Reflection; | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: ComVisible(true)] | ||
[assembly: Guid("12345678-90AB-CDEF-1234-567890ABCDEF")] | ||
[assembly: PrimaryInteropAssembly(1, 0)] | ||
"""; | ||
|
||
var compilation = CSharpCompilation.Create( | ||
"SimplePia", | ||
[ CSharpSyntaxTree.ParseText(content1), CSharpSyntaxTree.ParseText(content2) ], | ||
Net60.References.All, | ||
new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); | ||
|
||
var peStream = new MemoryStream(); | ||
var emitResult = compilation.Emit(peStream); | ||
if (!emitResult.Success) | ||
{ | ||
throw new Exception(GetMessage(emitResult.Diagnostics)); | ||
} | ||
|
||
peStream.Position = 0; | ||
return ("SimplePia.dll", peStream); | ||
|
||
string GetMessage(IEnumerable<Diagnostic> diagnostics) | ||
{ | ||
var builder = new StringBuilder(); | ||
builder.AppendLine("Compilation failed with the following errors:"); | ||
foreach (var d in diagnostics) | ||
{ | ||
builder.AppendLine(d.ToString()); | ||
} | ||
return builder.ToString(); | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters