Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Make sure breakpoints on scenario source are active in debugging
Browse files Browse the repository at this point in the history
Previously, because we were loading the CS files from the output directory, the breakpoints set in the actual scenario source were not being picked-up by VS. By loading them from the actual source location in the project, breakpoints Just Work :D
  • Loading branch information
kzu committed Nov 4, 2020
1 parent b5448df commit 69737ff
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/Avatar.UnitTests/.Scenarios.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class Scenarios
[MemberData(nameof(GetScenarios))]
public void Run(string path)
{
var (diagnostics, compilation) = GetGeneratedOutput(path);
var (diagnostics, compilation) = GetGeneratedOutput(
Path.IsPathRooted(path) ? path :
Path.Combine(ThisAssembly.Project.MSBuildProjectDirectory, path));

Assert.Empty(diagnostics);

Expand All @@ -37,8 +39,8 @@ public void Run(string path)
}

public static IEnumerable<object[]> GetScenarios()
=> Directory.EnumerateFiles("Scenarios", "*.cs")
.Select(file => new object[] { file });
=> Directory.EnumerateFiles(Path.Combine(ThisAssembly.Project.MSBuildProjectDirectory, "Scenarios"), "*.cs")
.Select(file => new object[] { Path.Combine("Scenarios", Path.GetFileName(file)) });

static (ImmutableArray<Diagnostic>, Compilation) GetGeneratedOutput(string path)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Avatar.UnitTests/Avatar.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<ItemGroup>
<None Include="CodeAnalysis\ST*\**\*.NoBuild.cs" CopyToOutputDirectory="PreserveNewest" />
<Compile Remove="CodeAnalysis\ST*\**\*.NoBuild.cs" />
<Compile Update="CodeAnalysis\ST*\**\*.cs;Scenarios\**\*.cs" CopyToOutputDirectory="PreserveNewest" />
<Compile Update="CodeAnalysis\ST*\**\*.cs" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

<ItemGroup>
Expand Down
24 changes: 11 additions & 13 deletions src/Avatar.UnitTests/CodeAnalysis/Helpers/WorkspaceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,19 @@ public static Document AddDocument(this AdhocWorkspace workspace, Project projec

public static Assembly Emit(this Compilation compilation, bool symbols = true)
{
using (var stream = new MemoryStream())
{
var options = symbols ?
new EmitOptions(debugInformationFormat: DebugInformationFormat.Embedded) :
new EmitOptions();
using var stream = new MemoryStream();
var options = symbols ?
new EmitOptions(debugInformationFormat: DebugInformationFormat.Embedded) :
new EmitOptions();

var cts = new CancellationTokenSource(10000);
var result = compilation.Emit(stream,
options: options,
cancellationToken: cts.Token);
result.AssertSuccess();
var cts = new CancellationTokenSource(10000);
var result = compilation.Emit(stream,
options: options,
cancellationToken: cts.Token);
result.AssertSuccess();

stream.Seek(0, SeekOrigin.Begin);
return Assembly.Load(stream.ToArray());
}
stream.Seek(0, SeekOrigin.Begin);
return Assembly.Load(stream.ToArray());
}

public static void AssertSuccess(this EmitResult result)
Expand Down

0 comments on commit 69737ff

Please sign in to comment.