|
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,10 @@ 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 | + FileName = Module.RunProperties.RunCommand, |
| 59 | + Arguments = GetArguments(testOptions), |
63 | 60 | RedirectStandardOutput = true,
|
64 | 61 | RedirectStandardError = true
|
65 | 62 | };
|
@@ -87,23 +84,27 @@ private ProcessStartInfo CreateProcessStartInfo(TestOptions testOptions)
|
87 | 84 | return processStartInfo;
|
88 | 85 | }
|
89 | 86 |
|
90 |
| - private string GetFileName(TestOptions testOptions, bool isDll) |
91 |
| - => isDll ? Environment.ProcessPath : Module.RunProperties.RunCommand; |
92 |
| - |
93 |
| - private string GetArguments(TestOptions testOptions, bool isDll) |
| 87 | + private string GetArguments(TestOptions testOptions) |
94 | 88 | {
|
95 |
| - if (testOptions.HasFilterMode || !isDll || !IsArchitectureSpecified(testOptions)) |
| 89 | + // Keep RunArguments first. |
| 90 | + // In the case of UseAppHost=false, RunArguments is set to `exec $(TargetPath)`: |
| 91 | + // https://github.com/dotnet/sdk/blob/333388c31d811701e3b6be74b5434359151424dc/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets#L1411 |
| 92 | + // So, we keep that first always. |
| 93 | + StringBuilder builder = new(Module.RunProperties.RunArguments); |
| 94 | + |
| 95 | + if (testOptions.IsHelp) |
96 | 96 | {
|
97 |
| - return BuildArgs(testOptions, isDll); |
| 97 | + builder.Append($" {TestingPlatformOptions.HelpOption.Name} "); |
98 | 98 | }
|
99 | 99 |
|
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 |
| - } |
| 100 | + var args = _buildOptions.UnmatchedTokens; |
| 101 | + builder.Append(args.Count != 0 |
| 102 | + ? args.Aggregate((a, b) => $"{a} {b}") |
| 103 | + : string.Empty); |
103 | 104 |
|
104 |
| - private static bool IsArchitectureSpecified(TestOptions testOptions) |
105 |
| - { |
106 |
| - return !string.IsNullOrEmpty(testOptions.Architecture); |
| 105 | + builder.Append($" {CliConstants.ServerOptionKey} {CliConstants.ServerOptionValue} {CliConstants.DotNetTestPipeOptionKey} {_pipeNameDescription.Name}"); |
| 106 | + |
| 107 | + return builder.ToString(); |
107 | 108 | }
|
108 | 109 |
|
109 | 110 | private void WaitOnTestApplicationPipeConnectionLoop()
|
@@ -277,35 +278,6 @@ private bool ModulePathExists()
|
277 | 278 | return true;
|
278 | 279 | }
|
279 | 280 |
|
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 | 281 | public void OnHandshakeMessage(HandshakeMessage handshakeMessage)
|
310 | 282 | {
|
311 | 283 | HandshakeReceived?.Invoke(this, new HandshakeArgs { Handshake = new Handshake(handshakeMessage.Properties) });
|
|
0 commit comments