Skip to content

Commit 73d7c2e

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

File tree

4 files changed

+63
-0
lines changed

4 files changed

+63
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[dotnet.test.runner]
2+
name = "Microsoft.Testing.Platform"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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 handshake with us.
23+
TestAsset testInstance = _testAssetsManager.CopyTestAsset("ConsoleAppDoesNothing", Guid.NewGuid().ToString())
24+
.WithSource();
25+
26+
CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false)
27+
.WithWorkingDirectory(testInstance.Path)
28+
.Execute(TestingPlatformOptions.ConfigurationOption.Name, configuration);
29+
30+
result.ExitCode.Should().Be(ExitCodes.GenericFailure, "dotnet test should fail with a meaningful error when run against console app without MTP handshake");
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)