-
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.
* Code coverage * Code coverage * Code coverage * Code coverage * Code coverage * More * Code coverage * Code coverage * Code coverage
- Loading branch information
Showing
36 changed files
with
630 additions
and
129 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
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
31 changes: 31 additions & 0 deletions
31
src/Basic.CompilerLog.UnitTests/BasicAnalyzerHostOptionsTests.cs
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,31 @@ | ||
using Basic.CompilerLog.Util; | ||
using Basic.CompilerLog.Util.Impl; | ||
using Microsoft.CodeAnalysis.Text; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
#if NETCOREAPP | ||
using System.Runtime.Loader; | ||
#endif | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
public sealed class BasicAnalyzerHostOptionsTests | ||
{ | ||
#if NETCOREAPP | ||
[Fact] | ||
public void CustomAssemblyLoadContext() | ||
{ | ||
var alc = new AssemblyLoadContext("Custom", isCollectible: true); | ||
var options = new BasicAnalyzerHostOptions(alc, BasicAnalyzerKind.Default, cacheable: true); | ||
Assert.Same(alc, options.CompilerLoadContext); | ||
alc.Unload(); | ||
} | ||
#endif | ||
} |
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,76 @@ | ||
using Basic.CompilerLog.Util; | ||
using Basic.CompilerLog.Util.Impl; | ||
using Microsoft.Build.Logging.StructuredLogger; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.Text; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Immutable; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
#if NETCOREAPP | ||
using System.Runtime.Loader; | ||
#endif | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
public sealed class BinaryLogUtilTests | ||
{ | ||
[Theory] | ||
[InlineData("dotnet exec csc.dll a.cs", "a.cs")] | ||
[InlineData("dotnet not what we expect a.cs", "")] | ||
[InlineData("csc.exe a.cs b.cs", "a.cs b.cs")] | ||
public void SkipCompilerExecutableTests(string args, string expected) | ||
{ | ||
var realArgs = BinaryLogUtil.SkipCompilerExecutable(ToArray(args), "csc.exe", "csc.dll"); | ||
Assert.Equal(ToArray(expected), realArgs); | ||
static string[] ToArray(string arg) => arg.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); | ||
} | ||
} | ||
|
||
public sealed class MSBuildProjectDataTests | ||
{ | ||
[Fact] | ||
public void MSBuildProjectDataToString() | ||
{ | ||
var data = new BinaryLogUtil.MSBuildProjectData(@"example.csproj"); | ||
Assert.NotEmpty(data.ToString()); | ||
} | ||
} | ||
|
||
public sealed class CompilationTaskDataTests | ||
{ | ||
internal BinaryLogUtil.MSBuildProjectData ProjectData { get; } = new BinaryLogUtil.MSBuildProjectData(@"example.csproj"); | ||
|
||
[Fact] | ||
public void TryCreateCompilerCallBadArguments() | ||
{ | ||
var data = new BinaryLogUtil.CompilationTaskData(ProjectData, 1) | ||
{ | ||
CommandLineArguments = "dotnet not a compiler call", | ||
}; | ||
|
||
var diagnostics = new List<string>(); | ||
Assert.Null(data.TryCreateCompilerCall(diagnostics)); | ||
Assert.NotEmpty(diagnostics); | ||
} | ||
|
||
[Fact] | ||
public void TryCreateCompilerNoArguments() | ||
{ | ||
var data = new BinaryLogUtil.CompilationTaskData(ProjectData, 1) | ||
{ | ||
CommandLineArguments = null, | ||
}; | ||
|
||
var diagnostics = new List<string>(); | ||
Assert.Null(data.TryCreateCompilerCall(diagnostics)); | ||
|
||
// This is a normal non-compile case so no diagnostics are emitted | ||
Assert.Empty(diagnostics); | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
src/Basic.CompilerLog.UnitTests/CompilerLogBuilderTests.cs
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,59 @@ | ||
using Basic.CompilerLog.Util; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
[Collection(SolutionFixtureCollection.Name)] | ||
public sealed class CompilerLogBuilderTests : TestBase | ||
{ | ||
public SolutionFixture Fixture { get; } | ||
|
||
public CompilerLogBuilderTests(ITestOutputHelper testOutputHelper, SolutionFixture fixture) | ||
: base(testOutputHelper, nameof(CompilerLogBuilderTests)) | ||
{ | ||
Fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public void AddMissingFile() | ||
{ | ||
using var stream = new MemoryStream(); | ||
using var builder = new CompilerLogBuilder(stream, new()); | ||
using var binlogStream = new FileStream(Fixture.ConsoleWithDiagnosticsBinaryLogPath, FileMode.Open, FileAccess.Read, FileShare.Read); | ||
|
||
var compilerCall = BinaryLogUtil.ReadAllCompilerCalls(binlogStream, new()).First(x => x.IsCSharp); | ||
compilerCall = new CompilerCall( | ||
compilerCall.ProjectFilePath, | ||
CompilerCallKind.Regular, | ||
compilerCall.TargetFramework, | ||
isCSharp: true, | ||
new Lazy<string[]>(() => ["/sourcelink:does-not-exist.txt"]), | ||
null); | ||
builder.Add(compilerCall); | ||
} | ||
|
||
[Fact] | ||
public void PortablePdbMissing() | ||
{ | ||
RunDotNet("new console -o ."); | ||
RunDotNet("build -bl:msbuild.binlog"); | ||
|
||
Directory | ||
.EnumerateFiles(RootDirectory, "*.pdb", SearchOption.AllDirectories) | ||
.ForEach(File.Delete); | ||
|
||
using var complogStream = new MemoryStream(); | ||
using var binlogStream = new FileStream(Path.Combine(RootDirectory, "msbuild.binlog"), FileMode.Open, FileAccess.Read, FileShare.Read); | ||
var diagnostics = CompilerLogUtil.ConvertBinaryLog(binlogStream, complogStream); | ||
Assert.Contains(diagnostics, x => x.Contains("Can't find portable pdb")); | ||
} | ||
|
||
[Fact] | ||
public void CloseTwice() | ||
{ | ||
var builder = new CompilerLogBuilder(new MemoryStream(), []); | ||
builder.Close(); | ||
Assert.Throws<InvalidOperationException>(() => builder.Close()); | ||
} | ||
} |
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
Oops, something went wrong.