Skip to content

Commit f6115a4

Browse files
authored
Fix dotnet test detection for dlls (#51309)
1 parent ffb7660 commit f6115a4

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public static int Run(ParseResult parseResult)
4646

4747
// Fix for https://github.com/Microsoft/vstest/issues/1453
4848
// Run dll/exe directly using the VSTestForwardingApp
49-
if (ContainsBuiltTestSources(args))
49+
if (ContainsBuiltTestSources(parseResult))
5050
{
5151
return ForwardToVSTestConsole(parseResult, args, settings, testSessionCorrelationId);
5252
}
@@ -295,18 +295,14 @@ internal static int RunArtifactPostProcessingIfNeeded(string testSessionCorrelat
295295
}
296296
}
297297

298-
private static bool ContainsBuiltTestSources(string[] args)
298+
private static bool ContainsBuiltTestSources(ParseResult parseResult)
299299
{
300-
for (int i = 0; i < args.Length; i++)
300+
for (int i = 0; i < parseResult.UnmatchedTokens.Count; i++)
301301
{
302-
string arg = args[i];
303-
if (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
302+
string arg = parseResult.UnmatchedTokens[i];
303+
if (!arg.StartsWith("-") &&
304+
(arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)))
304305
{
305-
var previousArg = i > 0 ? args[i - 1] : null;
306-
if (previousArg != null && CommonOptions.PropertiesOption.Aliases.Contains(previousArg))
307-
{
308-
return false;
309-
}
310306
return true;
311307
}
312308
}

test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,28 @@ public void PropertiesEndingWithDotDllShouldNotFail(string property)
836836
result.ExitCode.Should().Be(1);
837837
}
838838

839+
[Fact]
840+
public void DistributedLoggerEndingWithDotDllShouldBePassedToMSBuild()
841+
{
842+
var testProjectDirectory = CopyAndRestoreVSTestDotNetCoreTestApp([]);
843+
844+
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: true)
845+
.WithWorkingDirectory(testProjectDirectory)
846+
.Execute(ConsoleLoggerOutputNormal.Concat(["-dl:my.dll"]));
847+
848+
if (!TestContext.IsLocalized())
849+
{
850+
// This ensures that this was passed to MSBuild and not vstest.console.
851+
result.StdOut.Should().Contain("error MSB1021: Cannot create an instance of the logger my.dll.");
852+
}
853+
else
854+
{
855+
result.StdOut.Should().Contain("MSB1021");
856+
}
857+
858+
result.ExitCode.Should().Be(1);
859+
}
860+
839861
private string CopyAndRestoreVSTestDotNetCoreTestApp(object[] parameters, [CallerMemberName] string callingMethod = "")
840862
{
841863
// Copy VSTestCore project in output directory of project dotnet-vstest.Tests

0 commit comments

Comments
 (0)