Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion test/dotnet.Tests/TelemetryTests/TelemetryFilterTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using Microsoft.DotNet.Cli.Commands;
using Microsoft.DotNet.Cli.Telemetry;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Utilities;
Expand Down Expand Up @@ -52,7 +54,21 @@ public void TopLevelCommandNameShouldBeSentToTelemetryWithGlobalJsonState()
[Fact]
public void SubLevelCommandNameShouldBeSentToTelemetry()
{
var parseResult = Parser.Parse(["new", "console"]);
// Use a fresh DotNetCommandDefinition to avoid test pollution from
// other tests that may have dynamically added template names (e.g. "console")
// as subcommands to the static Parser.RootCommand's "new" command.
// See InstantiateCommand.ExecuteAsync which mutates the static parser tree.
var rootCommand = new DotNetCommandDefinition();
// Remove the built-in VersionOption that conflicts with the SDK's custom --version option.
// In production, Parser.NormalizeRootOptions handles this, but it's private.
for (int i = rootCommand.Options.Count - 1; i >= 0; i--)
{
if (rootCommand.Options[i] is VersionOption)
{
rootCommand.Options.RemoveAt(i);
}
}
var parseResult = rootCommand.Parse(["new", "console"], Parser.ParserConfiguration);
TelemetryEventEntry.SendFiltered(parseResult);
_fakeTelemetry
.LogEntries.Should()
Expand Down
Loading