diff --git a/Microsoft.DotNet.Cli.sln b/Microsoft.DotNet.Cli.sln index 3be7078be..90ff464bc 100644 --- a/Microsoft.DotNet.Cli.sln +++ b/Microsoft.DotNet.Cli.sln @@ -53,8 +53,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{89905EC4 build\Publish.targets = build\Publish.targets build\RestoreDependency.proj = build\RestoreDependency.proj build\sdks\sdks.csproj = build\sdks\sdks.csproj - build\Signing.proj = build\Signing.proj build\SetupPreviousStage.props = build\SetupPreviousStage.props + build\Signing.proj = build\Signing.proj build\Test.targets = build\Test.targets build\Version.props = build\Version.props build\VersionBadge.props = build\VersionBadge.props @@ -229,6 +229,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.MSBuildSdk EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-cli-build.Tests", "build_projects\dotnet-cli-build.Tests\dotnet-cli-build.Tests.csproj", "{84BB2DD5-B2D8-4C85-AAF9-29D2A74FBF94}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-restore.Tests", "test\dotnet-restore.Tests\dotnet-restore.Tests.csproj", "{B4EE3671-C103-4A37-8DEB-C74E0134104E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1589,6 +1591,30 @@ Global {84BB2DD5-B2D8-4C85-AAF9-29D2A74FBF94}.RelWithDebInfo|x64.Build.0 = Release|Any CPU {84BB2DD5-B2D8-4C85-AAF9-29D2A74FBF94}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {84BB2DD5-B2D8-4C85-AAF9-29D2A74FBF94}.RelWithDebInfo|x86.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|x64.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|x64.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|x86.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Debug|x86.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|x64.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|x86.ActiveCfg = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.MinSizeRel|x86.Build.0 = Debug|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|Any CPU.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|x64.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|x64.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|x86.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.Release|x86.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|x64.Build.0 = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {B4EE3671-C103-4A37-8DEB-C74E0134104E}.RelWithDebInfo|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1660,6 +1686,7 @@ Global {602976C5-2477-4B4C-AD9A-1EAFB250529A} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {FCDFAF40-CC16-4D49-96C0-E49F195E7142} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F} {84BB2DD5-B2D8-4C85-AAF9-29D2A74FBF94} = {88278B81-7649-45DC-8A6A-D3A645C5AFC3} + {B4EE3671-C103-4A37-8DEB-C74E0134104E} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B526D2CE-EE2D-4AD4-93EF-1867D90FF1F5} diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 8c734bc78..2eb25f9e5 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -167,7 +167,12 @@ namespace Microsoft.DotNet.Cli int exitCode; if (BuiltInCommandsCatalog.Commands.TryGetValue(command, out var builtIn)) { - TelemetryEventEntry.SendFiltered(Parser.Instance.ParseFrom($"dotnet {command}", appArgs.ToArray())); + var parseResult = Parser.Instance.ParseFrom($"dotnet {command}", appArgs.ToArray()); + if (!parseResult.Errors.Any()) + { + TelemetryEventEntry.SendFiltered(parseResult); + } + exitCode = builtIn.Command(appArgs.ToArray()); } else diff --git a/test/dotnet.Tests/TelemetryCommandTest.cs b/test/dotnet.Tests/TelemetryCommandTest.cs index 356667009..aa5c1a010 100644 --- a/test/dotnet.Tests/TelemetryCommandTest.cs +++ b/test/dotnet.Tests/TelemetryCommandTest.cs @@ -7,6 +7,7 @@ using Microsoft.DotNet.Cli.Telemetry; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Test.Utilities; using System.Collections.Generic; +using System; using Xunit; namespace Microsoft.DotNet.Tests @@ -24,6 +25,22 @@ namespace Microsoft.DotNet.Tests TelemetryEventEntry.TelemetryFilter = new TelemetryFilter(); } + [Fact] + public void NoTelemetryIfCommandIsInvalid() + { + string[] args = { "publish", "-r"}; + Action a = () => { Cli.Program.ProcessArgs(args); }; + a.ShouldNotThrow(); + } + + [Fact] + public void NoTelemetryIfCommandIsInvalid2() + { + string[] args = { "restore", "-v" }; + Action a = () => { Cli.Program.ProcessArgs(args); }; + a.ShouldNotThrow(); + } + [Fact] public void TopLevelCommandNameShouldBeSentToTelemetry() { @@ -120,7 +137,7 @@ namespace Microsoft.DotNet.Tests public void DotnetNugetCommandFirstArgumentShouldBeSentToTelemetry() { const string argumentToSend = "push"; - string[] args = {"nuget", argumentToSend, "aRoot"}; + string[] args = {"nuget", argumentToSend}; Cli.Program.ProcessArgs(args); _fakeTelemetry .LogEntries.Should()