diff --git a/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs b/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs index d84264e6c49e..ed960a88d6ef 100644 --- a/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/MTP/MicrosoftTestingPlatformTestCommand.cs @@ -40,6 +40,10 @@ private int RunInternal(ParseResult parseResult, bool isHelp) ValidationUtility.ValidateMutuallyExclusiveOptions(parseResult); ValidationUtility.ValidateSolutionOrProjectOrDirectoryOrModulesArePassedCorrectly(parseResult); + CommonOptions.ValidateSelfContainedOptions( + parseResult.HasOption(TestCommandParser.SelfContainedOption), + parseResult.HasOption(TestCommandParser.NoSelfContainedOption)); + int degreeOfParallelism = GetDegreeOfParallelism(parseResult); var testOptions = new TestOptions( IsHelp: isHelp, diff --git a/src/Cli/dotnet/Commands/Test/TestCommandParser.cs b/src/Cli/dotnet/Commands/Test/TestCommandParser.cs index 57be7086f011..145ce40e00e9 100644 --- a/src/Cli/dotnet/Commands/Test/TestCommandParser.cs +++ b/src/Cli/dotnet/Commands/Test/TestCommandParser.cs @@ -158,6 +158,10 @@ private static Option CreateBlameHangDumpOption() public static readonly Option NoRestoreOption = CommonOptions.NoRestoreOption; + public static readonly Option SelfContainedOption = CommonOptions.SelfContainedOption; + + public static readonly Option NoSelfContainedOption = CommonOptions.NoSelfContainedOption; + public static readonly Option FrameworkOption = CommonOptions.FrameworkOption(CliCommandStrings.TestFrameworkOptionDescription); public static readonly Option ConfigurationOption = CommonOptions.ConfigurationOption(CliCommandStrings.TestConfigurationOptionDescription); @@ -250,6 +254,8 @@ private static Command GetTestingPlatformCliCommand() command.Options.Add(CommonOptions.RuntimeOption(CliCommandStrings.TestRuntimeOptionDescription)); command.Options.Add(VerbosityOption); command.Options.Add(CommonOptions.NoRestoreOption); + command.Options.Add(SelfContainedOption); + command.Options.Add(NoSelfContainedOption); command.Options.Add(MicrosoftTestingPlatformOptions.NoBuildOption); command.Options.Add(MicrosoftTestingPlatformOptions.NoAnsiOption); command.Options.Add(MicrosoftTestingPlatformOptions.NoProgressOption); @@ -297,6 +303,8 @@ private static Command GetVSTestCliCommand() command.Options.Add(FrameworkOption); command.Options.Add(CommonOptions.RuntimeOption(CliCommandStrings.TestRuntimeOptionDescription)); command.Options.Add(NoRestoreOption); + command.Options.Add(SelfContainedOption); + command.Options.Add(NoSelfContainedOption); command.Options.Add(CommonOptions.InteractiveMsBuildForwardOption); command.Options.Add(VerbosityOption); command.Options.Add(CommonOptions.ArchitectureOption); diff --git a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs index 5fc54e4e1630..77e434fb60fd 100644 --- a/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs +++ b/src/Cli/dotnet/Commands/Test/VSTest/TestCommand.cs @@ -23,6 +23,10 @@ public static int Run(ParseResult parseResult) { parseResult.HandleDebugSwitch(); + CommonOptions.ValidateSelfContainedOptions( + parseResult.HasOption(TestCommandParser.SelfContainedOption), + parseResult.HasOption(TestCommandParser.NoSelfContainedOption)); + FeatureFlag.Instance.PrintFlagFeatureState(); // We use also current process id for the correlation id for possible future usage in case we need to know the parent process diff --git a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs index 6c054f61ceed..c91c2a033303 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestfromCsproj.cs @@ -836,6 +836,87 @@ public void PropertiesEndingWithDotDllShouldNotFail(string property) result.ExitCode.Should().Be(1); } + [Fact] + public void ItTestsWithSelfContainedOption() + { + var testInstance = _testAssetsManager.CopyTestAsset("XunitCore") + .WithSource() + .WithVersionVariables(); + + var rootPath = testInstance.Path; + var rid = EnvironmentInfo.GetCompatibleRid(); + + var result = new DotnetTestCommand(Log, disableNewOutput: true, ConsoleLoggerOutputNormal) + .WithWorkingDirectory(rootPath) + .Execute("--runtime", rid, "--self-contained"); + + result + .Should() + .NotHaveStdErrContaining("NETSDK1179") + .And + .NotHaveStdErrContaining("MSB1001"); + + if (!TestContext.IsLocalized()) + { + result.StdOut.Should().Contain("Total tests: 2"); + result.StdOut.Should().Contain("Passed: 1"); + result.StdOut.Should().Contain("Failed: 1"); + } + } + + [Fact] + public void ItTestsWithNoSelfContainedOption() + { + var testInstance = _testAssetsManager.CopyTestAsset("XunitCore") + .WithSource() + .WithVersionVariables(); + + var rootPath = testInstance.Path; + var rid = EnvironmentInfo.GetCompatibleRid(); + + var result = new DotnetTestCommand(Log, disableNewOutput: true, ConsoleLoggerOutputNormal) + .WithWorkingDirectory(rootPath) + .Execute("--runtime", rid, "--no-self-contained"); + + result + .Should() + .NotHaveStdErrContaining("NETSDK1179") + .And + .NotHaveStdErrContaining("MSB1001"); + + if (!TestContext.IsLocalized()) + { + result.StdOut.Should().Contain("Total tests: 2"); + result.StdOut.Should().Contain("Passed: 1"); + result.StdOut.Should().Contain("Failed: 1"); + } + } + + [Fact] + public void ItFailsWhenBothSelfContainedAndNoSelfContainedAreSpecified() + { + var testInstance = _testAssetsManager.CopyTestAsset("XunitCore") + .WithSource() + .WithVersionVariables(); + + var rootPath = testInstance.Path; + var rid = EnvironmentInfo.GetCompatibleRid(); + + var result = new DotnetTestCommand(Log, disableNewOutput: true, ConsoleLoggerOutputNormal) + .WithWorkingDirectory(rootPath) + .Execute("--runtime", rid, "--self-contained", "--no-self-contained"); + + result + .Should() + .Fail(); + + if (!TestContext.IsLocalized()) + { + result.StdErr.Should().Contain("--self-contained") + .And.Contain("--no-self-contained"); + } + } + [Fact] public void DistributedLoggerEndingWithDotDllShouldBePassedToMSBuild() {