Skip to content

Commit f812c43

Browse files
CopilotYoussef1313
authored andcommitted
Add test
1 parent 936d689 commit f812c43

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
6+
<OutputType>Exe</OutputType>
7+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
8+
<IsTestingPlatformApplication>true</IsTestingPlatformApplication>
9+
</PropertyGroup>
10+
11+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
namespace ConsoleAppDoesNothing;
5+
6+
public class Program
7+
{
8+
/// <summary>
9+
/// A console application that does "nothing" - just exits without any handshake or testing platform interaction.
10+
/// This is used to test dotnet test behavior with non-MTP console applications.
11+
/// </summary>
12+
public static void Main(string[] args)
13+
{
14+
// Intentionally does nothing - no handshake, no test framework, just exits
15+
// This simulates a regular console app that doesn't implement MTP protocol
16+
}
17+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.DotNet.Cli.Commands.Test;
5+
using CommandResult = Microsoft.DotNet.Cli.Utils.CommandResult;
6+
using ExitCodes = Microsoft.NET.TestFramework.ExitCode;
7+
8+
namespace Microsoft.DotNet.Cli.Test.Tests
9+
{
10+
public class GivenDotnetTestRunsConsoleAppWithoutHandshake : SdkTest
11+
{
12+
public GivenDotnetTestRunsConsoleAppWithoutHandshake(ITestOutputHelper log) : base(log)
13+
{
14+
}
15+
16+
[InlineData(TestingConstants.Debug)]
17+
[InlineData(TestingConstants.Release)]
18+
[Theory]
19+
public void RunConsoleAppDoesNothing_ShouldReturnCorrectExitCode(string configuration)
20+
{
21+
// This test validates the behavior when running `dotnet test` against a console application
22+
// that does "nothing" and doesn't implement the MTP (Message Transport Protocol) handshake.
23+
//
24+
// The issue (#49733) suggests that silently ignoring such applications is not good behavior.
25+
// This test validates that the improved behavior provides a meaningful error message.
26+
27+
TestAsset testInstance = _testAssetsManager.CopyTestAsset("ConsoleAppDoesNothing", Guid.NewGuid().ToString())
28+
.WithSource();
29+
30+
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
31+
.WithWorkingDirectory(testInstance.Path)
32+
.Execute(TestingPlatformOptions.ConfigurationOption.Name, configuration);
33+
34+
if (!TestContext.IsLocalized())
35+
{
36+
// The new behavior should provide a clear error message indicating that
37+
// the console app is not a test project and doesn't implement MTP
38+
result.StdOut.Should().Contain("is not a test project and does not implement the testing platform protocol");
39+
result.StdOut.Should().Contain("ConsoleAppDoesNothing.csproj");
40+
}
41+
42+
// The new behavior should return GenericFailure exit code instead of success
43+
result.ExitCode.Should().Be(ExitCodes.GenericFailure,
44+
"dotnet test should fail with a meaningful error when run against console app without MTP handshake");
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)