Skip to content

Commit

Permalink
Add option to create a VS test playlist (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz authored Feb 12, 2024
1 parent 1bce481 commit fef1671
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion runfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void ShowHelp()
Console.WriteLine(" search-timeline Search timeline info");
Console.WriteLine(" search-helix Search helix logs");
Console.WriteLine(" search-buildlog Search build logs");
Console.WriteLine(" tests Print build test failures");
Console.WriteLine(" search-tests Print build test failures");
Console.WriteLine(" timeline Dump the timeline");
Console.WriteLine(" yaml Dump the YML for a build");
Console.WriteLine();
Expand Down
28 changes: 23 additions & 5 deletions runfo/RuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,15 @@ internal async Task<int> PrintFailedTests(IEnumerable<string> args)
{
bool verbose = false;
bool markdown = false;
string? playlist = null;
bool includeAllTests = false;
string? name = null;
string grouping = "tests";
var optionSet = new BuildSearchOptionSet()
{
{ "g|grouping=", "output grouping: tests*, builds, jobs", g => grouping = g },
{ "m|markdown", "output in markdown", m => markdown = m is object },
{ "playlist=", "save VS test playlist to a file", p => playlist = p },
{ "n|name=", "name regex to match in results", n => name = n },
{ "at|all-tests", "include all tests", at => includeAllTests = at is object },
{ "v|verbose", "verbose output", d => verbose = d is object },
Expand All @@ -908,7 +910,7 @@ internal async Task<int> PrintFailedTests(IEnumerable<string> args)
ParseAll(optionSet, args);

var collection = await QueryUtil.ListBuildTestInfosAsync(optionSet, includeAllTests);
await PrintFailureInfo(collection, grouping, name, verbose, markdown);
await PrintFailureInfo(collection, grouping, name, verbose, markdown, playlist);
return ExitSuccess;
}

Expand All @@ -917,20 +919,21 @@ private async Task PrintFailureInfo(
string grouping,
string? name,
bool verbose,
bool markdown)
bool markdown,
string? playlist)
{
FilterToTestName();
SavePlaylist();

switch (grouping)
{
case "tests":
FilterToTestName();
await GroupByTests();
break;
case "builds":
FilterToTestName();
GroupByBuilds();
break;
case "jobs":
FilterToTestName();
GroupByJobs();
break;
default:
Expand All @@ -946,6 +949,21 @@ void FilterToTestName()
}
}

void SavePlaylist()
{
if (!string.IsNullOrEmpty(playlist))
{
// Test playlist file format docs: https://learn.microsoft.com/en-us/visualstudio/test/run-unit-tests-with-test-explorer?view=vs-2022#create-custom-playlists
using var writer = File.CreateText(playlist);
writer.WriteLine("<Playlist Version=\"2.0\"><Rule Match=\"Any\">");
foreach (var testName in collection.GetTestCaseTitles())
{
writer.WriteLine($"<Property Name=\"TestWithNormalizedFullyQualifiedName\" Value=\"{testName}\" />");
}
writer.WriteLine("</Rule></Playlist>");
}
}

void GroupByBuilds()
{
foreach (var buildTestInfo in collection)
Expand Down

0 comments on commit fef1671

Please sign in to comment.