From 99d8853ef0dd6b505eb6832a622e33b197ee09ad Mon Sep 17 00:00:00 2001 From: Kevin Jones Date: Thu, 19 May 2016 11:02:56 -0400 Subject: [PATCH] Move command line parsing into try/catch for test. If invalid parameters are specified in `dotnet test`, the CLI does not catch exceptions that can be thrown such as when specifying `-r` without a runtime. Fixes 3084. --- src/dotnet/commands/dotnet-test/Program.cs | 4 ++-- .../dotnet-test.Tests/GivenThatWeWantToRunTests.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/dotnet/commands/dotnet-test/Program.cs b/src/dotnet/commands/dotnet-test/Program.cs index 88925d7f9..43a7e81bd 100644 --- a/src/dotnet/commands/dotnet-test/Program.cs +++ b/src/dotnet/commands/dotnet-test/Program.cs @@ -26,10 +26,10 @@ namespace Microsoft.DotNet.Tools.Test var dotnetTestParams = new DotnetTestParams(); - dotnetTestParams.Parse(args); - try { + dotnetTestParams.Parse(args); + if (dotnetTestParams.Help) { return 0; diff --git a/test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs b/test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs index 709893840..703243dc4 100644 --- a/test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs +++ b/test/dotnet-test.Tests/GivenThatWeWantToRunTests.cs @@ -25,5 +25,19 @@ namespace Microsoft.Dotnet.Tools.Test.Tests .And .HaveStdErrContaining("dotnet restore"); } + + [Fact] + public void It_fails_correctly_with_invalid_runtime_parameter() + { + var instance = TestAssetsManager.CreateTestInstance(Path.Combine("ProjectsWithTests", "NetCoreAppOnlyProject")); + + new DotnetTestCommand() + .WithLockFiles() + .ExecuteWithCapturedOutput(instance.TestRoot) + .Should() + .Fail() + .And + .HaveStdErrContaining("Missing value for option 'runtime'"); + } } }