|
8 | 8 | using Microsoft.DotNet.Cli.Commands.Test.IPC; |
9 | 9 | using Microsoft.DotNet.Cli.Commands.Test.IPC.Models; |
10 | 10 | using Microsoft.DotNet.Cli.Commands.Test.IPC.Serializers; |
11 | | -using Microsoft.DotNet.Cli.Utils; |
12 | 11 |
|
13 | 12 | namespace Microsoft.DotNet.Cli.Commands.Test; |
14 | 13 |
|
@@ -54,12 +53,13 @@ public async Task<int> RunAsync(TestOptions testOptions) |
54 | 53 |
|
55 | 54 | private ProcessStartInfo CreateProcessStartInfo(TestOptions testOptions) |
56 | 55 | { |
57 | | - bool isDll = Module.RunProperties.RunCommand.HasExtension(CliConstants.DLLExtension); |
58 | | - |
59 | 56 | var processStartInfo = new ProcessStartInfo |
60 | 57 | { |
61 | | - FileName = GetFileName(testOptions, isDll), |
62 | | - Arguments = GetArguments(testOptions, isDll), |
| 58 | + // We should get correct RunProperties right away. |
| 59 | + // For the case of dotnet test --test-modules path/to/dll, the TestModulesFilterHandler is responsible |
| 60 | + // for providing the dotnet muxer as RunCommand, and `exec "path/to/dll"` as RunArguments. |
| 61 | + FileName = Module.RunProperties.RunCommand, |
| 62 | + Arguments = GetArguments(testOptions), |
63 | 63 | RedirectStandardOutput = true, |
64 | 64 | RedirectStandardError = true |
65 | 65 | }; |
@@ -87,23 +87,27 @@ private ProcessStartInfo CreateProcessStartInfo(TestOptions testOptions) |
87 | 87 | return processStartInfo; |
88 | 88 | } |
89 | 89 |
|
90 | | - private string GetFileName(TestOptions testOptions, bool isDll) |
91 | | - => isDll ? Environment.ProcessPath : Module.RunProperties.RunCommand; |
92 | | - |
93 | | - private string GetArguments(TestOptions testOptions, bool isDll) |
| 90 | + private string GetArguments(TestOptions testOptions) |
94 | 91 | { |
95 | | - if (testOptions.HasFilterMode || !isDll || !IsArchitectureSpecified(testOptions)) |
| 92 | + // Keep RunArguments first. |
| 93 | + // In the case of UseAppHost=false, RunArguments is set to `exec $(TargetPath)`: |
| 94 | + // https://github.com/dotnet/sdk/blob/333388c31d811701e3b6be74b5434359151424dc/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L1411 |
| 95 | + // So, we keep that first always. |
| 96 | + StringBuilder builder = new(Module.RunProperties.RunArguments); |
| 97 | + |
| 98 | + if (testOptions.IsHelp) |
96 | 99 | { |
97 | | - return BuildArgs(testOptions, isDll); |
| 100 | + builder.Append($" {TestingPlatformOptions.HelpOption.Name} "); |
98 | 101 | } |
99 | 102 |
|
100 | | - // If we reach here, that means we have a test project that doesn't produce an executable. |
101 | | - throw new InvalidOperationException($"A Microsoft.Testing.Platform test project should produce an executable. The file '{Module.RunProperties.RunCommand}' is dll."); |
102 | | - } |
| 103 | + var args = _buildOptions.UnmatchedTokens; |
| 104 | + builder.Append(args.Count != 0 |
| 105 | + ? args.Aggregate((a, b) => $"{a} {b}") |
| 106 | + : string.Empty); |
103 | 107 |
|
104 | | - private static bool IsArchitectureSpecified(TestOptions testOptions) |
105 | | - { |
106 | | - return !string.IsNullOrEmpty(testOptions.Architecture); |
| 108 | + builder.Append($" {CliConstants.ServerOptionKey} {CliConstants.ServerOptionValue} {CliConstants.DotNetTestPipeOptionKey} {_pipeNameDescription.Name}"); |
| 109 | + |
| 110 | + return builder.ToString(); |
107 | 111 | } |
108 | 112 |
|
109 | 113 | private void WaitOnTestApplicationPipeConnectionLoop() |
@@ -277,35 +281,6 @@ private bool ModulePathExists() |
277 | 281 | return true; |
278 | 282 | } |
279 | 283 |
|
280 | | - private string BuildArgs(TestOptions testOptions, bool isDll) |
281 | | - { |
282 | | - StringBuilder builder = new(); |
283 | | - |
284 | | - if (isDll) |
285 | | - { |
286 | | - builder.Append($"exec {Module.RunProperties.RunCommand} "); |
287 | | - } |
288 | | - |
289 | | - AppendCommonArgs(builder, testOptions); |
290 | | - |
291 | | - return builder.ToString(); |
292 | | - } |
293 | | - |
294 | | - private void AppendCommonArgs(StringBuilder builder, TestOptions testOptions) |
295 | | - { |
296 | | - if (testOptions.IsHelp) |
297 | | - { |
298 | | - builder.Append($" {TestingPlatformOptions.HelpOption.Name} "); |
299 | | - } |
300 | | - |
301 | | - var args = _buildOptions.UnmatchedTokens; |
302 | | - builder.Append(args.Count != 0 |
303 | | - ? args.Aggregate((a, b) => $"{a} {b}") |
304 | | - : string.Empty); |
305 | | - |
306 | | - builder.Append($" {CliConstants.ServerOptionKey} {CliConstants.ServerOptionValue} {CliConstants.DotNetTestPipeOptionKey} {_pipeNameDescription.Name} {Module.RunProperties.RunArguments}"); |
307 | | - } |
308 | | - |
309 | 284 | public void OnHandshakeMessage(HandshakeMessage handshakeMessage) |
310 | 285 | { |
311 | 286 | HandshakeReceived?.Invoke(this, new HandshakeArgs { Handshake = new Handshake(handshakeMessage.Properties) }); |
|
0 commit comments