From c3221bf08d291c9f69070aa11d6d60f61a569aae Mon Sep 17 00:00:00 2001 From: Mike Corsaro Date: Thu, 4 Jan 2024 16:52:42 -0800 Subject: [PATCH] [Windows] Fix verification of test count in CI (#19697) * Test ignore * Test off-by-one * Test print out missing category * Cleanup --------- Co-authored-by: Mike Corsaro --- eng/devices/windows.cake | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/eng/devices/windows.cake b/eng/devices/windows.cake index 83d88f187329..d9cee85ea9ff 100644 --- a/eng/devices/windows.cake +++ b/eng/devices/windows.cake @@ -322,7 +322,8 @@ Task("Test") // and if the categories we expected to run match the test result files if (isControlsProjectTestRun) { - var expectedCategoriesRanCount = System.IO.File.ReadAllLines(testsToRunFile).Length-1; + var expectedCategories = System.IO.File.ReadAllLines(testsToRunFile); + var expectedCategoriesRanCount = expectedCategories.Length; var actualResultFileCount = System.IO.Directory.GetFiles(testResultsPath, "TestResults-*.xml").Length; while (actualResultFileCount < expectedCategoriesRanCount) { @@ -344,6 +345,20 @@ Task("Test") // If it's less, throw an exception to fail the pipeline. if (actualResultFileCount < expectedCategoriesRanCount) { + // Grab the category name from the file name + // Ex: "TestResults-com_microsoft_maui_controls_devicetests_Frame.xml" -> "Frame" + var actualFiles = System.IO.Directory.GetFiles(testResultsPath, "TestResults-*.xml"); + var actualCategories = actualFiles.Select(x => x.Substring(0, x.Length - 4) // Remove ".xml" + .Split('_').Last()).ToList(); + + foreach (var category in expectedCategories) + { + if (!actualCategories.Contains(category)) + { + Error($"Error: missing test file result for {category}"); + } + } + throw new Exception($"Expected test result files: {expectedCategoriesRanCount}, actual files: {actualResultFileCount}, some process(es) might have crashed."); } }