From 5cac3441738744ca79ac6a4256d1f99631dbad8d Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 10 Feb 2022 14:25:09 -0800 Subject: Add logging to tests to help diagnose intermittent test failures --- src/internal/WixBuildTools.TestSupport/TestData.cs | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/internal/WixBuildTools.TestSupport/TestData.cs') diff --git a/src/internal/WixBuildTools.TestSupport/TestData.cs b/src/internal/WixBuildTools.TestSupport/TestData.cs index 8587330d..309e9038 100644 --- a/src/internal/WixBuildTools.TestSupport/TestData.cs +++ b/src/internal/WixBuildTools.TestSupport/TestData.cs @@ -4,13 +4,42 @@ namespace WixBuildTools.TestSupport { using System; using System.IO; + using System.Reflection; + using System.Runtime.CompilerServices; public class TestData { public static string Get(params string[] paths) { - var localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetCallingAssembly().CodeBase).LocalPath); + var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); return Path.Combine(localPath, Path.Combine(paths)); } + + public static string GetUnitTestLogsFolder([CallerFilePath] string path = "", [CallerMemberName] string method = "") + { + var startingPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); + var buildPath = startingPath; + + while (!String.IsNullOrEmpty(buildPath)) + { + var folderName = Path.GetFileName(buildPath); + if (String.Equals("build", folderName, StringComparison.OrdinalIgnoreCase)) + { + break; + } + + buildPath = Path.GetDirectoryName(buildPath); + } + + if (String.IsNullOrEmpty(buildPath)) + { + throw new InvalidOperationException($"Could not find the 'build' folder in the test path: {startingPath}. Cannot get test logs folder without being able to find the build folder."); + } + + var testLogsFolder = Path.Combine(buildPath, "logs", "UnitTests", $"{Path.GetFileNameWithoutExtension(path)}_{method}"); + Directory.CreateDirectory(testLogsFolder); + + return testLogsFolder; + } } } -- cgit v1.2.3-55-g6feb