Skip to content

Commit c6eaa69

Browse files
authored
Fix a couple of dotnet-watch test failures (#49558)
1 parent 9081d8f commit c6eaa69

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#nullable disable
55

6+
using System.Text.RegularExpressions;
7+
68
namespace Microsoft.DotNet.Watch.UnitTests
79
{
810
public class ApplyDeltaTests(ITestOutputHelper logger) : DotNetWatchTestBase(logger)
@@ -30,6 +32,8 @@ public static void Print()
3032
}
3133
""");
3234

35+
await App.AssertOutputLineStartsWith(MessageDescriptor.ReEvaluationCompleted);
36+
3337
// update existing file:
3438
UpdateSourceFile(Path.Combine(dependencyDir, "Foo.cs"), """
3539
public class Lib
@@ -254,7 +258,7 @@ public async Task DefaultItemExcludes_DefaultItemsEnabled()
254258
App.Start(testAsset, []);
255259

256260
await App.AssertWaitingForChanges();
257-
App.AssertOutputContains(@"dotnet watch ⌚ Exclusion glob: 'AppData/**/*.*;bin\Debug\/**;obj\Debug\/**;bin\/**;obj\/**");
261+
App.AssertOutputContains(new Regex(@"dotnet watch ⌚ Exclusion glob: 'AppData/[*][*]/[*][.][*];bin[/\\]+Debug[/\\]+[*][*];obj[/\\]+Debug[/\\]+[*][*];bin[/\\]+[*][*];obj[/\\]+[*][*]"));
258262
App.Process.ClearOutput();
259263

260264
UpdateSourceFile(appDataFilePath, """

test/dotnet-watch.Tests/Utilities/AssertEx.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
using System.Collections;
88
using System.Diagnostics;
9+
using System.Text.RegularExpressions;
910
using Xunit.Sdk;
1011

1112
namespace Microsoft.DotNet.Watch.UnitTests
@@ -253,5 +254,26 @@ public static void ContainsSubstring(string expected, IEnumerable<string> items)
253254

254255
Fail(message.ToString());
255256
}
257+
258+
public static void ContainsPattern(Regex expected, IEnumerable<string> items)
259+
{
260+
if (items.Any(item => expected.IsMatch(item)))
261+
{
262+
return;
263+
}
264+
265+
var message = new StringBuilder();
266+
message.AppendLine($"Expected pattern not found in the output:");
267+
message.AppendLine(expected.ToString());
268+
message.AppendLine();
269+
message.AppendLine("Actual output:");
270+
271+
foreach (var item in items)
272+
{
273+
message.AppendLine($"'{item}'");
274+
}
275+
276+
Fail(message.ToString());
277+
}
256278
}
257279
}

test/dotnet-watch.Tests/Watch/Utilities/DotNetWatchTestBase.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ public void Log(string message, [CallerFilePath] string? testPath = null, [Calle
3030

3131
public void UpdateSourceFile(string path, string text, [CallerFilePath] string? testPath = null, [CallerLineNumber] int testLine = 0)
3232
{
33+
var existed = File.Exists(path);
3334
WriteAllText(path, text);
34-
Log($"File '{path}' updated", testPath, testLine);
35+
Log($"File '{path}' " + (existed ? "updated" : "added"), testPath, testLine);
3536
}
3637

3738
public void UpdateSourceFile(string path, Func<string, string> contentTransform, [CallerFilePath] string? testPath = null, [CallerLineNumber] int testLine = 0)

test/dotnet-watch.Tests/Watch/Utilities/WatchableApp.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#nullable disable
55

66
using System.Runtime.CompilerServices;
7+
using System.Text.RegularExpressions;
78

89
namespace Microsoft.DotNet.Watch.UnitTests
910
{
@@ -39,6 +40,9 @@ public void AssertOutputContains(string message)
3940
public void AssertOutputDoesNotContain(string message)
4041
=> Assert.DoesNotContain(Process.Output, line => line.Contains(message));
4142

43+
public void AssertOutputContains(Regex pattern)
44+
=> AssertEx.ContainsPattern(pattern, Process.Output);
45+
4246
public void AssertOutputContains(MessageDescriptor descriptor, string projectDisplay = null)
4347
=> AssertOutputContains(GetLinePrefix(descriptor, projectDisplay));
4448

0 commit comments

Comments
 (0)