|
4 | 4 | // See the LICENSE file in the project root for full license information. |
5 | 5 |
|
6 | 6 | using System; |
| 7 | +using System.Diagnostics; |
7 | 8 | using System.Diagnostics.CodeAnalysis; |
8 | 9 | using System.IO; |
9 | 10 | using System.Linq; |
@@ -42,14 +43,45 @@ private static void CheckApproval(Assembly assembly, [CallerMemberName]string me |
42 | 43 | var approvedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.approved.txt"); |
43 | 44 | var receivedFileName = Path.Combine(sourceDirectory, $"ApiApprovalTests.{memberName}.{targetFrameworkName}.received.txt"); |
44 | 45 |
|
45 | | - var approvedPublicApi = File.ReadAllText(approvedFileName); |
| 46 | + string approvedPublicApi = string.Empty; |
| 47 | + |
| 48 | + if (File.Exists(approvedFileName)) |
| 49 | + { |
| 50 | + approvedPublicApi = File.ReadAllText(approvedFileName); |
| 51 | + } |
46 | 52 |
|
47 | 53 | var receivedPublicApi = Filter(ApiGenerator.GeneratePublicApi(assembly)); |
48 | 54 |
|
49 | 55 | if (!string.Equals(receivedPublicApi, approvedPublicApi, StringComparison.InvariantCulture)) |
50 | 56 | { |
51 | 57 | File.WriteAllText(receivedFileName, receivedPublicApi); |
52 | | - ShouldlyConfiguration.DiffTools.GetDiffTool().Open(receivedFileName, approvedFileName, true); |
| 58 | + try |
| 59 | + { |
| 60 | + ShouldlyConfiguration.DiffTools.GetDiffTool().Open(receivedFileName, approvedFileName, true); |
| 61 | + } |
| 62 | + catch (ShouldAssertException) |
| 63 | + { |
| 64 | + var process = new Process |
| 65 | + { |
| 66 | + StartInfo = new ProcessStartInfo |
| 67 | + { |
| 68 | + Arguments = $"\"{approvedFileName}\" \"{receivedFileName}\"", |
| 69 | + UseShellExecute = false, |
| 70 | + RedirectStandardOutput = true, |
| 71 | + CreateNoWindow = true |
| 72 | + } |
| 73 | + }; |
| 74 | +#if NET_461 |
| 75 | + process.StartInfo.FileName = "FC"; |
| 76 | +#else |
| 77 | + process.StartInfo.FileName = "diff"; |
| 78 | +#endif |
| 79 | + process.Start(); |
| 80 | + string output = process.StandardOutput.ReadToEnd(); |
| 81 | + process.WaitForExit(); |
| 82 | + |
| 83 | + throw new Exception("Invalid API configuration: " + Environment.NewLine + output); |
| 84 | + } |
53 | 85 | } |
54 | 86 |
|
55 | 87 | Assert.Equal(approvedPublicApi, receivedPublicApi); |
|
0 commit comments