diff options
| author | Rob Mensching <rob@firegiant.com> | 2022-02-10 14:25:09 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2022-02-10 20:47:53 -0800 |
| commit | 5cac3441738744ca79ac6a4256d1f99631dbad8d (patch) | |
| tree | aba1ffb3379030cbc2e7eff445f02a2360842065 /src | |
| parent | 16df83128a59025f81d8e052c50219c851961624 (diff) | |
| download | wix-5cac3441738744ca79ac6a4256d1f99631dbad8d.tar.gz wix-5cac3441738744ca79ac6a4256d1f99631dbad8d.tar.bz2 wix-5cac3441738744ca79ac6a4256d1f99631dbad8d.zip | |
Add logging to tests to help diagnose intermittent test failures
Diffstat (limited to 'src')
3 files changed, 55 insertions, 2 deletions
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 | |||
| 4 | { | 4 | { |
| 5 | using System; | 5 | using System; |
| 6 | using System.IO; | 6 | using System.IO; |
| 7 | using System.Reflection; | ||
| 8 | using System.Runtime.CompilerServices; | ||
| 7 | 9 | ||
| 8 | public class TestData | 10 | public class TestData |
| 9 | { | 11 | { |
| 10 | public static string Get(params string[] paths) | 12 | public static string Get(params string[] paths) |
| 11 | { | 13 | { |
| 12 | var localPath = Path.GetDirectoryName(new Uri(System.Reflection.Assembly.GetCallingAssembly().CodeBase).LocalPath); | 14 | var localPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); |
| 13 | return Path.Combine(localPath, Path.Combine(paths)); | 15 | return Path.Combine(localPath, Path.Combine(paths)); |
| 14 | } | 16 | } |
| 17 | |||
| 18 | public static string GetUnitTestLogsFolder([CallerFilePath] string path = "", [CallerMemberName] string method = "") | ||
| 19 | { | ||
| 20 | var startingPath = Path.GetDirectoryName(new Uri(Assembly.GetCallingAssembly().CodeBase).LocalPath); | ||
| 21 | var buildPath = startingPath; | ||
| 22 | |||
| 23 | while (!String.IsNullOrEmpty(buildPath)) | ||
| 24 | { | ||
| 25 | var folderName = Path.GetFileName(buildPath); | ||
| 26 | if (String.Equals("build", folderName, StringComparison.OrdinalIgnoreCase)) | ||
| 27 | { | ||
| 28 | break; | ||
| 29 | } | ||
| 30 | |||
| 31 | buildPath = Path.GetDirectoryName(buildPath); | ||
| 32 | } | ||
| 33 | |||
| 34 | if (String.IsNullOrEmpty(buildPath)) | ||
| 35 | { | ||
| 36 | 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."); | ||
| 37 | } | ||
| 38 | |||
| 39 | var testLogsFolder = Path.Combine(buildPath, "logs", "UnitTests", $"{Path.GetFileNameWithoutExtension(path)}_{method}"); | ||
| 40 | Directory.CreateDirectory(testLogsFolder); | ||
| 41 | |||
| 42 | return testLogsFolder; | ||
| 43 | } | ||
| 15 | } | 44 | } |
| 16 | } | 45 | } |
diff --git a/src/wix/test/WixToolsetTest.CoreIntegration/ValidationFixture.cs b/src/wix/test/WixToolsetTest.CoreIntegration/ValidationFixture.cs index 69965c0d..fd8f6f87 100644 --- a/src/wix/test/WixToolsetTest.CoreIntegration/ValidationFixture.cs +++ b/src/wix/test/WixToolsetTest.CoreIntegration/ValidationFixture.cs | |||
| @@ -172,6 +172,10 @@ namespace WixToolsetTest.CoreIntegration | |||
| 172 | { | 172 | { |
| 173 | var folder = TestData.Get(@"TestData"); | 173 | var folder = TestData.Get(@"TestData"); |
| 174 | 174 | ||
| 175 | var testLogsFolder = TestData.GetUnitTestLogsFolder(); | ||
| 176 | File.Delete(Path.Combine(testLogsFolder, "build.txt")); | ||
| 177 | File.Delete(Path.Combine(testLogsFolder, "validate.txt")); | ||
| 178 | |||
| 175 | using (var fs = new DisposableFileSystem()) | 179 | using (var fs = new DisposableFileSystem()) |
| 176 | { | 180 | { |
| 177 | var baseFolder = fs.GetFolder(); | 181 | var baseFolder = fs.GetFolder(); |
| @@ -187,6 +191,8 @@ namespace WixToolsetTest.CoreIntegration | |||
| 187 | "-o", msiPath, | 191 | "-o", msiPath, |
| 188 | }); | 192 | }); |
| 189 | 193 | ||
| 194 | File.WriteAllLines(Path.Combine(testLogsFolder, "build.txt"), result.Messages.Select(m => m.ToString())); | ||
| 195 | |||
| 190 | result.AssertSuccess(); | 196 | result.AssertSuccess(); |
| 191 | 197 | ||
| 192 | var validationResult = WixRunner.Execute(new[] | 198 | var validationResult = WixRunner.Execute(new[] |
| @@ -196,6 +202,8 @@ namespace WixToolsetTest.CoreIntegration | |||
| 196 | msiPath | 202 | msiPath |
| 197 | }); | 203 | }); |
| 198 | 204 | ||
| 205 | File.WriteAllLines(Path.Combine(testLogsFolder, "validate.txt"), validationResult.Messages.Select(m => m.ToString())); | ||
| 206 | |||
| 199 | Assert.Equal(1, validationResult.ExitCode); | 207 | Assert.Equal(1, validationResult.ExitCode); |
| 200 | 208 | ||
| 201 | var messages = validationResult.Messages.Select(m => m.ToString()).ToArray(); | 209 | var messages = validationResult.Messages.Select(m => m.ToString()).ToArray(); |
| @@ -212,6 +220,10 @@ namespace WixToolsetTest.CoreIntegration | |||
| 212 | { | 220 | { |
| 213 | var folder = TestData.Get(@"TestData"); | 221 | var folder = TestData.Get(@"TestData"); |
| 214 | 222 | ||
| 223 | var testLogsFolder = TestData.GetUnitTestLogsFolder(); | ||
| 224 | File.Delete(Path.Combine(testLogsFolder, "build.txt")); | ||
| 225 | File.Delete(Path.Combine(testLogsFolder, "validate.txt")); | ||
| 226 | |||
| 215 | using (var fs = new DisposableFileSystem()) | 227 | using (var fs = new DisposableFileSystem()) |
| 216 | { | 228 | { |
| 217 | var baseFolder = fs.GetFolder(); | 229 | var baseFolder = fs.GetFolder(); |
| @@ -227,6 +239,8 @@ namespace WixToolsetTest.CoreIntegration | |||
| 227 | "-o", msiPath, | 239 | "-o", msiPath, |
| 228 | }); | 240 | }); |
| 229 | 241 | ||
| 242 | File.WriteAllLines(Path.Combine(testLogsFolder, "build.txt"), result.Messages.Select(m => m.ToString())); | ||
| 243 | |||
| 230 | result.AssertSuccess(); | 244 | result.AssertSuccess(); |
| 231 | 245 | ||
| 232 | var validationResult = WixRunner.Execute(warningsAsErrors: false, new[] | 246 | var validationResult = WixRunner.Execute(warningsAsErrors: false, new[] |
| @@ -237,6 +251,8 @@ namespace WixToolsetTest.CoreIntegration | |||
| 237 | msiPath | 251 | msiPath |
| 238 | }); | 252 | }); |
| 239 | 253 | ||
| 254 | File.WriteAllLines(Path.Combine(testLogsFolder, "validate.txt"), validationResult.Messages.Select(m => m.ToString())); | ||
| 255 | |||
| 240 | validationResult.AssertSuccess(); | 256 | validationResult.AssertSuccess(); |
| 241 | 257 | ||
| 242 | var messages = validationResult.Messages.Select(m => m.ToString()).ToArray(); | 258 | var messages = validationResult.Messages.Select(m => m.ToString()).ToArray(); |
diff --git a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs index 0bee1b01..f0761762 100644 --- a/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs +++ b/src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | |||
| @@ -6,6 +6,8 @@ namespace WixToolsetTest.Sdk | |||
| 6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
| 7 | using System.IO; | 7 | using System.IO; |
| 8 | using System.Linq; | 8 | using System.Linq; |
| 9 | using System.Runtime.CompilerServices; | ||
| 10 | using System.Threading; | ||
| 9 | using WixBuildTools.TestSupport; | 11 | using WixBuildTools.TestSupport; |
| 10 | using Xunit; | 12 | using Xunit; |
| 11 | 13 | ||
| @@ -328,6 +330,10 @@ namespace WixToolsetTest.Sdk | |||
| 328 | { | 330 | { |
| 329 | var sourceFolder = TestData.Get(@"TestData\MsiPackageWithIceError\MsiPackage"); | 331 | var sourceFolder = TestData.Get(@"TestData\MsiPackageWithIceError\MsiPackage"); |
| 330 | 332 | ||
| 333 | var testLogsFolder = TestData.GetUnitTestLogsFolder(); | ||
| 334 | File.Delete(Path.Combine(testLogsFolder, buildSystem + ".binlog")); | ||
| 335 | File.Delete(Path.Combine(testLogsFolder, buildSystem + ".msi")); | ||
| 336 | |||
| 331 | using (var fs = new TestDataFolderFileSystem()) | 337 | using (var fs = new TestDataFolderFileSystem()) |
| 332 | { | 338 | { |
| 333 | fs.Initialize(sourceFolder); | 339 | fs.Initialize(sourceFolder); |
| @@ -335,7 +341,9 @@ namespace WixToolsetTest.Sdk | |||
| 335 | var projectPath = Path.Combine(baseFolder, "MsiPackage.wixproj"); | 341 | var projectPath = Path.Combine(baseFolder, "MsiPackage.wixproj"); |
| 336 | 342 | ||
| 337 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, suppressValidation: false); | 343 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, suppressValidation: false); |
| 338 | Assert.Equal(1, result.ExitCode); | 344 | |
| 345 | File.Copy(Path.ChangeExtension(projectPath, ".binlog"), Path.Combine(testLogsFolder, buildSystem + ".binlog")); | ||
| 346 | File.Copy(Path.Combine(baseFolder, "obj", "x86", "Release", "en-US", "MsiPackage.msi"), Path.Combine(testLogsFolder, buildSystem + ".msi")); | ||
| 339 | 347 | ||
| 340 | var iceIssues = result.Output.Where(line => line.Contains(": error") || line.Contains(": warning")) | 348 | var iceIssues = result.Output.Where(line => line.Contains(": error") || line.Contains(": warning")) |
| 341 | .Select(line => line.Replace(baseFolder, "<baseFolder>") | 349 | .Select(line => line.Replace(baseFolder, "<baseFolder>") |
