Skip to content

[WIP] IFrameworkHandle.LaunchProcessWithDebuggerAttached allows null for workingDirectory in signature but throws #15091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public FrameworkHandle(ITestCaseEventsHandler? testCaseEventsHandler, ITestRunCa
/// Launch the specified process with the debugger attached.
/// </summary>
/// <param name="filePath">File path to the exe to launch.</param>
/// <param name="workingDirectory">Working directory that process should use.</param>
/// <param name="workingDirectory">Working directory that process should use. If null, the current directory will be used.</param>
/// <param name="arguments">Command line arguments the process should be launched with.</param>
/// <param name="environmentVariables">Environment variables to be set in target process</param>
/// <returns>Process ID of the started process.</returns>
Expand All @@ -89,7 +89,7 @@ public int LaunchProcessWithDebuggerAttached(string filePath, string? workingDir
Arguments = arguments,
EnvironmentVariables = environmentVariables,
FileName = filePath,
WorkingDirectory = workingDirectory
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory
};

return _testRunEventsHandler.LaunchProcessWithDebuggerAttached(processInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface IFrameworkHandle : ITestExecutionRecorder, IMessageLogger
/// Launch the specified process with the debugger attached.
/// </summary>
/// <param name="filePath">File path to the exe to launch.</param>
/// <param name="workingDirectory">Working directory that process should use.</param>
/// <param name="workingDirectory">Working directory that process should use. If null, the current directory will be used.</param>
/// <param name="arguments">Command line arguments the process should be launched with.</param>
/// <param name="environmentVariables">Environment variables to be set in target process</param>
/// <returns>Process ID of the started process.</returns>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,57 @@ public void LaunchProcessWithDebuggerAttachedShouldCallRunEventsHandler()
mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()), Times.Once);
}

[TestMethod]
public void LaunchProcessWithDebuggerAttachedShouldSetCurrentDirectoryWhenWorkingDirectoryIsNull()
{
var tec = GetTestExecutionContext();
tec.IsDebug = true;
var mockTestRunEventsHandler = new Mock<IInternalTestRunEventsHandler>();
TestProcessStartInfo? capturedProcessInfo = null;

mockTestRunEventsHandler
.Setup(mt => mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()))
.Callback<TestProcessStartInfo>(info => capturedProcessInfo = info)
.Returns(1234);

var frameworkHandle = new FrameworkHandle(
null,
new TestRunCache(100, TimeSpan.MaxValue, (s, r, ip) => { }),
tec,
mockTestRunEventsHandler.Object);

frameworkHandle.LaunchProcessWithDebuggerAttached("test.exe", null, null, null);

Assert.IsNotNull(capturedProcessInfo);
Assert.AreEqual(Environment.CurrentDirectory, capturedProcessInfo.WorkingDirectory);
}

[TestMethod]
public void LaunchProcessWithDebuggerAttachedShouldUseProvidedWorkingDirectory()
{
var tec = GetTestExecutionContext();
tec.IsDebug = true;
var mockTestRunEventsHandler = new Mock<IInternalTestRunEventsHandler>();
TestProcessStartInfo? capturedProcessInfo = null;
var expectedWorkingDirectory = "/custom/path";

mockTestRunEventsHandler
.Setup(mt => mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()))
.Callback<TestProcessStartInfo>(info => capturedProcessInfo = info)
.Returns(1234);

var frameworkHandle = new FrameworkHandle(
null,
new TestRunCache(100, TimeSpan.MaxValue, (s, r, ip) => { }),
tec,
mockTestRunEventsHandler.Object);

frameworkHandle.LaunchProcessWithDebuggerAttached("test.exe", expectedWorkingDirectory, null, null);

Assert.IsNotNull(capturedProcessInfo);
Assert.AreEqual(expectedWorkingDirectory, capturedProcessInfo.WorkingDirectory);
}

private static TestExecutionContext GetTestExecutionContext()
{
var tec = new TestExecutionContext(
Expand Down