Skip to content

Commit 6aaf379

Browse files
authored
Fix dll detection in dotnet test (#50926)
1 parent a6c08bc commit 6aaf379

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,16 @@ internal static int RunArtifactPostProcessingIfNeeded(string testSessionCorrelat
298298

299299
private static bool ContainsBuiltTestSources(string[] args)
300300
{
301-
foreach (string arg in args)
301+
for (int i = 0; i < args.Length; i++)
302302
{
303-
if (!arg.StartsWith("-") &&
304-
(arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)))
303+
string arg = args[i];
304+
if (arg.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || arg.EndsWith(".exe", StringComparison.OrdinalIgnoreCase))
305305
{
306+
var previousArg = i > 0 ? args[i - 1] : null;
307+
if (previousArg != null && CommonOptions.PropertiesOption.Aliases.Contains(previousArg))
308+
{
309+
return false;
310+
}
306311
return true;
307312
}
308313
}

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,38 @@ public void ArgumentsEndWithDllOrExeShouldNotFail(string arg)
804804
}
805805
}
806806

807+
808+
[Theory]
809+
[InlineData("-p:ABC=C:\\my.dll")]
810+
[InlineData("/p:ABC=C:\\my.dll")]
811+
[InlineData("-property:ABC=C:\\my.dll")]
812+
public void PropertiesEndingWithDotDllShouldNotFail(string property)
813+
{
814+
var testProjectDirectory = CopyAndRestoreVSTestDotNetCoreTestApp([]);
815+
816+
// Call test
817+
// The test will complain about --property:VsTestUseMSBuildOutput=false but
818+
// it is the .dll parameter that is causing this. It forces the command to offload work
819+
// to vstest.console.exe directly, because it thinks there is some test .dll that we should run
820+
// directly, rather than a project file.
821+
// Vstest.console.exe will then complain just about the first unknown parameter.
822+
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: true)
823+
.WithWorkingDirectory(testProjectDirectory)
824+
.Execute(ConsoleLoggerOutputNormal.Concat([property]));
825+
826+
// Verify
827+
if (!TestContext.IsLocalized())
828+
{
829+
result.StdOut.Should().Contain("Total tests: 2");
830+
result.StdOut.Should().Contain("Passed: 1");
831+
result.StdOut.Should().Contain("Failed: 1");
832+
result.StdOut.Should().Contain("Passed VSTestPassTest");
833+
result.StdOut.Should().Contain("Failed VSTestFailTest");
834+
}
835+
836+
result.ExitCode.Should().Be(1);
837+
}
838+
807839
private string CopyAndRestoreVSTestDotNetCoreTestApp(object[] parameters, [CallerMemberName] string callingMethod = "")
808840
{
809841
// Copy VSTestCore project in output directory of project dotnet-vstest.Tests

0 commit comments

Comments
 (0)