Skip to content

Commit cdcfb7f

Browse files
Copilotnohwnd
andauthored
[WIP] IFrameworkHandle.LaunchProcessWithDebuggerAttached allows null for workingDirectory in signature but throws (#15091)
* Initial plan for issue * Fix LaunchProcessWithDebuggerAttached to handle null workingDirectory Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com> * Update documentation for workingDirectory parameter to clarify null behavior Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nohwnd <5735905+nohwnd@users.noreply.github.com>
1 parent c049523 commit cdcfb7f

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

src/Microsoft.TestPlatform.CrossPlatEngine/Adapter/FrameworkHandle.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public FrameworkHandle(ITestCaseEventsHandler? testCaseEventsHandler, ITestRunCa
6565
/// Launch the specified process with the debugger attached.
6666
/// </summary>
6767
/// <param name="filePath">File path to the exe to launch.</param>
68-
/// <param name="workingDirectory">Working directory that process should use.</param>
68+
/// <param name="workingDirectory">Working directory that process should use. If null, the current directory will be used.</param>
6969
/// <param name="arguments">Command line arguments the process should be launched with.</param>
7070
/// <param name="environmentVariables">Environment variables to be set in target process</param>
7171
/// <returns>Process ID of the started process.</returns>
@@ -89,7 +89,7 @@ public int LaunchProcessWithDebuggerAttached(string filePath, string? workingDir
8989
Arguments = arguments,
9090
EnvironmentVariables = environmentVariables,
9191
FileName = filePath,
92-
WorkingDirectory = workingDirectory
92+
WorkingDirectory = workingDirectory ?? Environment.CurrentDirectory
9393
};
9494

9595
return _testRunEventsHandler.LaunchProcessWithDebuggerAttached(processInfo);

src/Microsoft.TestPlatform.ObjectModel/Adapter/Interfaces/IFrameworkHandle.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface IFrameworkHandle : ITestExecutionRecorder, IMessageLogger
2323
/// Launch the specified process with the debugger attached.
2424
/// </summary>
2525
/// <param name="filePath">File path to the exe to launch.</param>
26-
/// <param name="workingDirectory">Working directory that process should use.</param>
26+
/// <param name="workingDirectory">Working directory that process should use. If null, the current directory will be used.</param>
2727
/// <param name="arguments">Command line arguments the process should be launched with.</param>
2828
/// <param name="environmentVariables">Environment variables to be set in target process</param>
2929
/// <returns>Process ID of the started process.</returns>

test/Microsoft.TestPlatform.CrossPlatEngine.UnitTests/Adapter/FrameworkHandleTests.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,57 @@ public void LaunchProcessWithDebuggerAttachedShouldCallRunEventsHandler()
8787
mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()), Times.Once);
8888
}
8989

90+
[TestMethod]
91+
public void LaunchProcessWithDebuggerAttachedShouldSetCurrentDirectoryWhenWorkingDirectoryIsNull()
92+
{
93+
var tec = GetTestExecutionContext();
94+
tec.IsDebug = true;
95+
var mockTestRunEventsHandler = new Mock<IInternalTestRunEventsHandler>();
96+
TestProcessStartInfo? capturedProcessInfo = null;
97+
98+
mockTestRunEventsHandler
99+
.Setup(mt => mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()))
100+
.Callback<TestProcessStartInfo>(info => capturedProcessInfo = info)
101+
.Returns(1234);
102+
103+
var frameworkHandle = new FrameworkHandle(
104+
null,
105+
new TestRunCache(100, TimeSpan.MaxValue, (s, r, ip) => { }),
106+
tec,
107+
mockTestRunEventsHandler.Object);
108+
109+
frameworkHandle.LaunchProcessWithDebuggerAttached("test.exe", null, null, null);
110+
111+
Assert.IsNotNull(capturedProcessInfo);
112+
Assert.AreEqual(Environment.CurrentDirectory, capturedProcessInfo.WorkingDirectory);
113+
}
114+
115+
[TestMethod]
116+
public void LaunchProcessWithDebuggerAttachedShouldUseProvidedWorkingDirectory()
117+
{
118+
var tec = GetTestExecutionContext();
119+
tec.IsDebug = true;
120+
var mockTestRunEventsHandler = new Mock<IInternalTestRunEventsHandler>();
121+
TestProcessStartInfo? capturedProcessInfo = null;
122+
var expectedWorkingDirectory = "/custom/path";
123+
124+
mockTestRunEventsHandler
125+
.Setup(mt => mt.LaunchProcessWithDebuggerAttached(It.IsAny<TestProcessStartInfo>()))
126+
.Callback<TestProcessStartInfo>(info => capturedProcessInfo = info)
127+
.Returns(1234);
128+
129+
var frameworkHandle = new FrameworkHandle(
130+
null,
131+
new TestRunCache(100, TimeSpan.MaxValue, (s, r, ip) => { }),
132+
tec,
133+
mockTestRunEventsHandler.Object);
134+
135+
frameworkHandle.LaunchProcessWithDebuggerAttached("test.exe", expectedWorkingDirectory, null, null);
136+
137+
Assert.IsNotNull(capturedProcessInfo);
138+
Assert.AreEqual(expectedWorkingDirectory, capturedProcessInfo.WorkingDirectory);
139+
}
140+
90141
private static TestExecutionContext GetTestExecutionContext()
91142
{
92143
var tec = new TestExecutionContext(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy