Skip to content

Commit e9a4696

Browse files
committed
Adding a scrubber to remove most of the list output as a direct comparison will fail far more often than is maintainable.
1 parent 70a4d10 commit e9a4696

4 files changed

+113
-128
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
11
Warning: use of 'dotnet new --list' is deprecated. Use 'dotnet new list' instead.
22
For more information, run:
33
dotnet new list -h
4-
54
These templates matched your input:
6-
7-
Template Name Short Name Language Tags
8-
-------------------------------------------- -------------------------- ---------- ----------------------------------
9-
API Controller apicontroller [C#] Web/ASP.NET
10-
ASP.NET Core Empty web [C#],F# Web/Empty
11-
ASP.NET Core gRPC Service grpc [C#] Web/gRPC/API/Service
12-
ASP.NET Core Web API webapi [C#],F# Web/Web API/API/Service/WebAPI
13-
ASP.NET Core Web API (native AOT) webapiaot [C#] Web/Web API/API/Service
14-
ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC
15-
ASP.NET Core Web App (Razor Pages) webapp,razor [C#] Web/MVC/Razor Pages
16-
Blazor Server App blazorserver [C#] Web/Blazor
17-
Blazor Web App blazor [C#] Web/Blazor/WebAssembly
18-
Blazor WebAssembly Standalone App blazorwasm [C#] Web/Blazor/WebAssembly/PWA
19-
Class Library classlib [C#],F#,VB Common/Library
20-
Console App console [C#],F#,VB Common/Console
21-
dotnet gitignore file gitignore,.gitignore Config
22-
Dotnet local tool manifest file tool-manifest Config
23-
EditorConfig file editorconfig,.editorconfig Config
24-
global.json file globaljson,global.json Config
25-
MSBuild Directory.Build.props file buildprops MSBuild/props
26-
MSBuild Directory.Build.targets file buildtargets MSBuild/props
27-
MSBuild Directory.Packages.props file packagesprops MSBuild/packages/props/CPM
28-
MSTest Playwright Test Project mstest-playwright [C#] Test/MSTest/Playwright/Desktop/Web
29-
MSTest Test Class mstest-class [C#],F#,VB Test/MSTest
30-
MSTest Test Project mstest [C#],F#,VB Test/MSTest/Desktop/Web
31-
MVC Controller mvccontroller [C#] Web/ASP.NET
32-
MVC ViewImports viewimports [C#] Web/ASP.NET
33-
MVC ViewStart viewstart [C#] Web/ASP.NET
34-
NuGet Config nugetconfig,nuget.config Config
35-
NUnit 3 Test Item nunit-test [C#],F#,VB Test/NUnit
36-
NUnit 3 Test Project nunit [C#],F#,VB Test/NUnit/Desktop/Web
37-
NUnit Playwright Test Project nunit-playwright [C#] Test/NUnit/Playwright/Desktop/Web
38-
Protocol Buffer File proto Web/gRPC
39-
Razor Class Library razorclasslib [C#] Web/Razor/Library
40-
Razor Component razorcomponent [C#] Web/ASP.NET
41-
Razor Page page [C#] Web/ASP.NET
42-
Razor View view [C#] Web/ASP.NET
43-
Solution File sln,solution Solution
44-
Web Config webconfig Config
45-
Worker Service worker [C#],F# Common/Worker/Web
46-
xUnit Test Project xunit [C#],F#,VB Test/xUnit/Desktop/Web
5+
Template Name Short Name Language Tags
6+
API
7+
ASP.NET
8+
Blazor
9+
Class
10+
Console
11+
dotnet
12+
Dotnet
13+
EditorConfig
14+
global.json
15+
MSBuild
16+
MSTest
17+
MVC
18+
NuGet
19+
NUnit
20+
Protocol
21+
Razor
22+
Solution
23+
Web
24+
Windows
25+
Worker
26+
WPF
27+
xUnit
Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
11
Warning: use of 'dotnet new --list' is deprecated. Use 'dotnet new list' instead.
22
For more information, run:
33
dotnet new list -h
4-
54
These templates matched your input:
6-
7-
Template Name Short Name Language Tags
8-
-------------------------------------------- -------------------------- ---------- ------------------------------
9-
API Controller apicontroller [C#] Web/ASP.NET
10-
ASP.NET Core Empty web [C#],F# Web/Empty
11-
ASP.NET Core gRPC Service grpc [C#] Web/gRPC/API/Service
12-
ASP.NET Core Web API webapi [C#],F# Web/Web API/API/Service/WebAPI
13-
ASP.NET Core Web API (native AOT) webapiaot [C#] Web/Web API/API/Service
14-
ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC
15-
ASP.NET Core Web App (Razor Pages) webapp,razor [C#] Web/MVC/Razor Pages
16-
Blazor Server App blazorserver [C#] Web/Blazor
17-
Blazor Web App blazor [C#] Web/Blazor/WebAssembly
18-
Blazor WebAssembly Standalone App blazorwasm [C#] Web/Blazor/WebAssembly/PWA
19-
Class Library classlib [C#],F#,VB Common/Library
20-
Console App console [C#],F#,VB Common/Console
21-
dotnet gitignore file gitignore,.gitignore Config
22-
Dotnet local tool manifest file tool-manifest Config
23-
EditorConfig file editorconfig,.editorconfig Config
24-
global.json file globaljson,global.json Config
25-
MSBuild Directory.Build.props file buildprops MSBuild/props
26-
MSBuild Directory.Build.targets file buildtargets MSBuild/props
27-
MSBuild Directory.Packages.props file packagesprops MSBuild/packages/props/CPM
28-
MSTest Playwright Test Project mstest-playwright [C#] Test/MSTest/Playwright
29-
MSTest Test Class mstest-class [C#],F#,VB Test/MSTest
30-
MSTest Test Project mstest [C#],F#,VB Test/MSTest
31-
MVC Controller mvccontroller [C#] Web/ASP.NET
32-
MVC ViewImports viewimports [C#] Web/ASP.NET
33-
MVC ViewStart viewstart [C#] Web/ASP.NET
34-
NuGet Config nugetconfig,nuget.config Config
35-
NUnit 3 Test Item nunit-test [C#],F#,VB Test/NUnit
36-
NUnit 3 Test Project nunit [C#],F#,VB Test/NUnit
37-
NUnit Playwright Test Project nunit-playwright [C#] Test/NUnit/Playwright
38-
Protocol Buffer File proto Web/gRPC
39-
Razor Class Library razorclasslib [C#] Web/Razor/Library
40-
Razor Component razorcomponent [C#] Web/ASP.NET
41-
Razor Page page [C#] Web/ASP.NET
42-
Razor View view [C#] Web/ASP.NET
43-
Solution File sln,solution Solution
44-
Web Config webconfig Config
45-
Worker Service worker [C#],F# Common/Worker/Web
46-
xUnit Test Project xunit [C#],F#,VB Test/xUnit
5+
Template Name Short Name Language Tags
6+
API
7+
ASP.NET
8+
Blazor
9+
Class
10+
Console
11+
dotnet
12+
Dotnet
13+
EditorConfig
14+
global.json
15+
MSBuild
16+
MSTest
17+
MVC
18+
NuGet
19+
NUnit
20+
Protocol
21+
Razor
22+
Solution
23+
Web
24+
Windows
25+
Worker
26+
WPF
27+
xUnit
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,27 @@
11
Warning: use of 'dotnet new --list' is deprecated. Use 'dotnet new list' instead.
22
For more information, run:
33
dotnet new list -h
4-
54
These templates matched your input:
6-
7-
Template Name Short Name Language Tags
8-
-------------------------------------------- -------------------------- ---------- ----------------------------------
9-
API Controller apicontroller [C#] Web/ASP.NET
10-
ASP.NET Core Empty web [C#],F# Web/Empty
11-
ASP.NET Core gRPC Service grpc [C#] Web/gRPC/API/Service
12-
ASP.NET Core Web API webapi [C#],F# Web/Web API/API/Service/WebAPI
13-
ASP.NET Core Web API (native AOT) webapiaot [C#] Web/Web API/API/Service
14-
ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC
15-
ASP.NET Core Web App (Razor Pages) webapp,razor [C#] Web/MVC/Razor Pages
16-
Blazor Server App blazorserver [C#] Web/Blazor
17-
Blazor Web App blazor [C#] Web/Blazor/WebAssembly
18-
Blazor WebAssembly Standalone App blazorwasm [C#] Web/Blazor/WebAssembly/PWA
19-
Class Library classlib [C#],F#,VB Common/Library
20-
Console App console [C#],F#,VB Common/Console
21-
dotnet gitignore file gitignore,.gitignore Config
22-
Dotnet local tool manifest file tool-manifest Config
23-
EditorConfig file editorconfig,.editorconfig Config
24-
global.json file globaljson,global.json Config
25-
MSBuild Directory.Build.props file buildprops MSBuild/props
26-
MSBuild Directory.Build.targets file buildtargets MSBuild/props
27-
MSBuild Directory.Packages.props file packagesprops MSBuild/packages/props/CPM
28-
MSTest Playwright Test Project mstest-playwright [C#] Test/MSTest/Playwright/Desktop/Web
29-
MSTest Test Class mstest-class [C#],F#,VB Test/MSTest
30-
MSTest Test Project mstest [C#],F#,VB Test/MSTest/Desktop/Web
31-
MVC Controller mvccontroller [C#] Web/ASP.NET
32-
MVC ViewImports viewimports [C#] Web/ASP.NET
33-
MVC ViewStart viewstart [C#] Web/ASP.NET
34-
NuGet Config nugetconfig,nuget.config Config
35-
NUnit 3 Test Item nunit-test [C#],F#,VB Test/NUnit
36-
NUnit 3 Test Project nunit [C#],F#,VB Test/NUnit/Desktop/Web
37-
NUnit Playwright Test Project nunit-playwright [C#] Test/NUnit/Playwright/Desktop/Web
38-
Protocol Buffer File proto Web/gRPC
39-
Razor Class Library razorclasslib [C#] Web/Razor/Library
40-
Razor Component razorcomponent [C#] Web/ASP.NET
41-
Razor Page page [C#] Web/ASP.NET
42-
Razor View view [C#] Web/ASP.NET
43-
Solution File sln,solution Solution
44-
Web Config webconfig Config
45-
Worker Service worker [C#],F# Common/Worker/Web
46-
xUnit Test Project xunit [C#],F#,VB Test/xUnit/Desktop/Web
5+
Template Name Short Name Language Tags
6+
API
7+
ASP.NET
8+
Blazor
9+
Class
10+
Console
11+
dotnet
12+
Dotnet
13+
EditorConfig
14+
global.json
15+
MSBuild
16+
MSTest
17+
MVC
18+
NuGet
19+
NUnit
20+
Protocol
21+
Razor
22+
Solution
23+
Web
24+
Windows
25+
Worker
26+
WPF
27+
xUnit

test/dotnet-new.Tests/DotnetNewListTests.Approval.cs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public Task BasicTest_WhenLegacyCommandIsUsed(string commandName)
2424
return Verify(commandResult.StdOut)
2525
.UniqueForOSPlatform()
2626
.UseTextForParameters("common")
27-
.DisableRequireUniquePrefix();
27+
.DisableRequireUniquePrefix()
28+
.AddScrubber(ScrubData);
2829
}
2930

3031
[Fact]
@@ -39,7 +40,48 @@ public Task BasicTest_WhenListCommandIsUsed()
3940
.Should()
4041
.Pass();
4142

42-
return Verify(commandResult.StdOut).UniqueForOSPlatform();
43+
return Verify(commandResult.StdOut)
44+
.UniqueForOSPlatform()
45+
.AddScrubber(ScrubData);
46+
}
47+
48+
// We're listing the built in templates which we don't control so this fails often
49+
// By scrubbing out the last three columns and then taking only the unique first words
50+
// we can ensure that the list is showing columns and they haven't significantly changed.
51+
// That's the best we can do for validating an output we don't control
52+
private static void ScrubData(StringBuilder input)
53+
{
54+
var lines = input.ToString().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
55+
var scrubbedLines = new HashSet<string>();
56+
bool isTable = false;
57+
58+
foreach (var line in lines)
59+
{
60+
if (line.StartsWith("-----"))
61+
{
62+
isTable = true;
63+
continue;
64+
}
65+
66+
if (isTable)
67+
{
68+
var columns = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
69+
if (columns.Length > 0)
70+
{
71+
scrubbedLines.Add(columns[0]);
72+
}
73+
}
74+
else
75+
{
76+
scrubbedLines.Add(line);
77+
}
78+
}
79+
80+
input.Clear();
81+
foreach (var scrubbedLine in scrubbedLines)
82+
{
83+
input.AppendLine(scrubbedLine);
84+
}
4385
}
4486

4587
[Fact]

0 commit comments

Comments
 (0)