-
-
Notifications
You must be signed in to change notification settings - Fork 740
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented debugging support for roslyn script sessions
- Loading branch information
1 parent
d3346d2
commit f75166c
Showing
28 changed files
with
689 additions
and
39 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,47 @@ | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.Scripting; | ||
using Cake.Commands; | ||
using Cake.Diagnostics; | ||
using Cake.Scripting; | ||
using NSubstitute; | ||
|
||
namespace Cake.Tests.Fixtures | ||
{ | ||
internal sealed class DebugCommandFixture | ||
{ | ||
public IScriptRunner ScriptRunner { get; set; } | ||
public ICakeLog Log { get; set; } | ||
public IDebugger Debugger { get; set; } | ||
public CakeOptions Options { get; set; } | ||
|
||
public DebugCommandFixture() | ||
{ | ||
ScriptRunner = Substitute.For<IScriptRunner>(); | ||
Log = Substitute.For<ICakeLog>(); | ||
Debugger = Substitute.For<IDebugger>(); | ||
Options = new CakeOptions | ||
{ | ||
Script = "build.cake" | ||
}; | ||
} | ||
|
||
public DebugCommand CreateCommand() | ||
{ | ||
var context = Substitute.For<ICakeContext>(); | ||
var engine = Substitute.For<ICakeEngine>(); | ||
var printer = Substitute.For<ICakeReportPrinter>(); | ||
|
||
context.Log.Returns(Log); | ||
|
||
var host = new BuildScriptHost(engine, context, printer, Log); | ||
|
||
return new DebugCommand(ScriptRunner, Debugger, host); | ||
} | ||
|
||
public bool Execute() | ||
{ | ||
return CreateCommand().Execute(Options); | ||
} | ||
} | ||
} |
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,61 @@ | ||
using Cake.Core.Diagnostics; | ||
using Cake.Scripting; | ||
using Cake.Tests.Fixtures; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Cake.Tests.Unit.Scripting | ||
{ | ||
public sealed class DebugCommandTests | ||
{ | ||
public sealed class TheExecuteMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Options_Is_Null() | ||
{ | ||
// Given | ||
var fixture = new DebugCommandFixture(); | ||
fixture.Options = null; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Execute()); | ||
|
||
// Then | ||
Assert.IsArgumentNullException(result, "options"); | ||
} | ||
|
||
[Fact] | ||
public void Should_Proxy_Call_To_ScriptRunner() | ||
{ | ||
// Given | ||
var fixture = new DebugCommandFixture(); | ||
var runner = fixture.ScriptRunner; | ||
var options = fixture.Options; | ||
|
||
// When | ||
fixture.Execute(); | ||
|
||
// Then | ||
runner.Received(1).Run(Arg.Any<BuildScriptHost>(), options.Script, options.Arguments); | ||
} | ||
|
||
[Fact] | ||
public void Should_Report_Correct_Process_Id() | ||
{ | ||
// Given | ||
var fixture = new DebugCommandFixture(); | ||
var debugger = fixture.Debugger; | ||
var log = fixture.Log; | ||
var pid = 1234567; | ||
|
||
debugger.GetProcessId().Returns(pid); | ||
|
||
// When | ||
fixture.Execute(); | ||
|
||
// Then | ||
log.Received(1).Information(Verbosity.Quiet, Arg.Any<string>(), pid); | ||
} | ||
} | ||
} | ||
} |
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
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,52 @@ | ||
using System; | ||
using System.Threading; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.Scripting; | ||
using Cake.Diagnostics; | ||
using Cake.Scripting; | ||
|
||
namespace Cake.Commands | ||
{ | ||
/// <summary> | ||
/// A command that builds and debugs a build script. | ||
/// </summary> | ||
internal sealed class DebugCommand : ICommand | ||
{ | ||
private readonly IScriptRunner _scriptRunner; | ||
private readonly IDebugger _debugger; | ||
private readonly ICakeLog _log; | ||
private readonly BuildScriptHost _host; | ||
|
||
// Delegate factory used by Autofac. | ||
public delegate DebugCommand Factory(); | ||
|
||
public DebugCommand(IScriptRunner scriptRunner, IDebugger debugger, BuildScriptHost host) | ||
{ | ||
_scriptRunner = scriptRunner; | ||
_debugger = debugger; | ||
_host = host; | ||
_log = _host.Context.Log; | ||
} | ||
|
||
public bool Execute(CakeOptions options) | ||
{ | ||
if (options == null) | ||
{ | ||
throw new ArgumentNullException("options"); | ||
} | ||
|
||
var message = "Attach debugger to process {0} to continue"; | ||
var pid = _debugger.GetProcessId(); | ||
|
||
_log.Debug("Performing debug..."); | ||
_log.Information(Verbosity.Quiet, message, pid); | ||
|
||
_debugger.WaitForAttach(Timeout.InfiniteTimeSpan); | ||
|
||
_log.Debug("Debugger attached"); | ||
|
||
_scriptRunner.Run(_host, options.Script, options.Arguments); | ||
return true; | ||
} | ||
} | ||
} |
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.