-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from jaredpar/coverage
Coverage
- Loading branch information
Showing
8 changed files
with
278 additions
and
45 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
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,35 @@ | ||
|
||
using System.Security.Cryptography; | ||
using System.Text; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Xunit.Sdk; | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
public abstract class FixtureBase | ||
{ | ||
private int _processCount; | ||
|
||
protected IMessageSink MessageSink { get; } | ||
|
||
protected FixtureBase(IMessageSink messageSink) | ||
{ | ||
MessageSink = messageSink; | ||
} | ||
|
||
protected void RunDotnetCommand(string args, string workingDirectory) | ||
{ | ||
var start = DateTime.UtcNow; | ||
var diagnosticBuilder = new StringBuilder(); | ||
|
||
diagnosticBuilder.AppendLine($"Running: {_processCount++} {args} in {workingDirectory}"); | ||
var result = DotnetUtil.Command(args, workingDirectory); | ||
diagnosticBuilder.AppendLine($"Succeeded: {result.Succeeded}"); | ||
diagnosticBuilder.AppendLine($"Standard Output: {result.StandardOut}"); | ||
diagnosticBuilder.AppendLine($"Standard Error: {result.StandardError}"); | ||
diagnosticBuilder.AppendLine($"Finished: {(DateTime.UtcNow - start).TotalSeconds:F2}s"); | ||
MessageSink.OnMessage(new DiagnosticMessage(diagnosticBuilder.ToString())); | ||
Assert.True(result.Succeeded); | ||
} | ||
} |
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,107 @@ | ||
|
||
using System.Collections.Immutable; | ||
using Microsoft.CodeAnalysis; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Basic.CompilerLog.UnitTests; | ||
|
||
/// <summary> | ||
/// This fixture houses a solution with a variety of projects that have been built and | ||
/// contain an available binary log. | ||
/// </summary> | ||
public sealed class SolutionFixture : FixtureBase, IDisposable | ||
{ | ||
internal ImmutableArray<string> ProjectPaths { get; } | ||
|
||
/// <summary> | ||
/// Storage directory for all the generated artifacts and scatch directories | ||
/// </summary> | ||
internal string StorageDirectory { get; } | ||
|
||
internal string SolutionPath { get; } | ||
|
||
internal string SolutionBinaryLogPath { get; } | ||
|
||
internal string ConsoleProjectPath { get; } | ||
|
||
internal string ConsoleProjectName => Path.GetFileName(ConsoleProjectPath); | ||
|
||
internal string ClassLibProjectPath { get; } | ||
|
||
internal string RemovedBinaryLogPath { get; } | ||
|
||
/// <summary> | ||
/// This project is deleted off of disk after the binary log is created. This means subsequent calls | ||
/// to create a compiler log over it will fail. Useful for testing error cases. | ||
/// </summary> | ||
internal string RemovedConsoleProjectPath { get; } | ||
|
||
internal string RemovedConsoleProjectName => Path.GetFileName(RemovedConsoleProjectPath); | ||
|
||
public SolutionFixture(IMessageSink messageSink) | ||
: base(messageSink) | ||
{ | ||
StorageDirectory = Path.Combine(Path.GetTempPath(), nameof(CompilerLogFixture), Guid.NewGuid().ToString("N")); | ||
Directory.CreateDirectory(StorageDirectory); | ||
SolutionPath = Path.Combine(StorageDirectory, "Solution.sln"); | ||
var binlogDir = Path.Combine(StorageDirectory, "binlogs"); | ||
Directory.CreateDirectory(binlogDir); | ||
|
||
RunDotnetCommand("new globaljson --sdk-version 7.0.400", StorageDirectory); | ||
RunDotnetCommand("dotnet new sln -n Solution", StorageDirectory); | ||
|
||
var builder = ImmutableArray.CreateBuilder<string>(); | ||
|
||
ConsoleProjectPath = WithProject("console", string (string dir) => | ||
{ | ||
RunDotnetCommand("new console --name console -o .", dir); | ||
return Path.Combine(dir, "console.csproj"); | ||
}); | ||
|
||
ClassLibProjectPath = WithProject("classlib", string (string dir) => | ||
{ | ||
RunDotnetCommand("new classlib --name classlib -o .", dir); | ||
return Path.Combine(dir, "classlib.csproj"); | ||
}); | ||
|
||
string WithProject(string name, Func<string, string> func) | ||
{ | ||
var dir = Path.Combine(StorageDirectory, name); | ||
Directory.CreateDirectory(dir); | ||
var projectPath = func(dir); | ||
RunDotnetCommand($@"dotnet sln add ""{projectPath}""", StorageDirectory); | ||
builder.Add(projectPath); | ||
return projectPath; | ||
}; | ||
ProjectPaths = builder.ToImmutableArray(); | ||
SolutionBinaryLogPath = Path.Combine(binlogDir, "msbuild.binlog"); | ||
DotnetUtil.CommandOrThrow($"dotnet build -bl:{SolutionBinaryLogPath} -nr:false", StorageDirectory); | ||
(RemovedConsoleProjectPath, RemovedBinaryLogPath) = CreateRemovedProject(); | ||
|
||
(string, string) CreateRemovedProject() | ||
{ | ||
var dir = Path.Combine(StorageDirectory, "removed"); | ||
Directory.CreateDirectory(dir); | ||
RunDotnetCommand("new console --name removed-console -o .", dir); | ||
var projectPath = Path.Combine(dir, "removed-console.csproj"); | ||
var binlogFilePath = Path.Combine(binlogDir, "removed-console.binlog"); | ||
|
||
DotnetUtil.CommandOrThrow($"dotnet build -bl:{binlogFilePath} -nr:false", dir); | ||
Directory.Delete(dir, recursive: true); | ||
return (projectPath, binlogFilePath); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Directory.Delete(StorageDirectory, recursive: true); | ||
} | ||
} | ||
|
||
[CollectionDefinition(Name)] | ||
public sealed class SolutionFixtureCollection : ICollectionFixture<SolutionFixture> | ||
{ | ||
public const string Name = "Solution Collection"; | ||
} |
Oops, something went wrong.