Skip to content

Commit 2d9a8cc

Browse files
authored
Make dotnet-watch tests TFM agnostic (dotnet#44604)
1 parent 467d7ba commit 2d9a8cc

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ class AppUpdateHandler
127127

128128
await App.AssertOutputLineStartsWith("Updated");
129129

130-
AssertEx.Contains(
131-
"dotnet watch ⚠ [WatchHotReloadApp (net9.0)] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'AppUpdateHandler, WatchHotReloadApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' but neither exists.",
130+
AssertEx.ContainsRegex(
131+
@"dotnet watch ⚠ \[WatchHotReloadApp \(net\d+\.\d+\)\] Expected to find a static method 'ClearCache' or 'UpdateApplication' on type 'AppUpdateHandler, WatchHotReloadApp, Version=1\.0\.0\.0, Culture=neutral, PublicKeyToken=null' but neither exists.",
132132
App.Process.Output);
133133
}
134134

@@ -168,13 +168,13 @@ class AppUpdateHandler
168168

169169
await App.AssertOutputLineStartsWith("Updated");
170170

171-
AssertEx.Contains(
172-
"dotnet watch ⚠ [WatchHotReloadApp (net9.0)] Exception from 'System.Action`1[System.Type[]]': System.InvalidOperationException: Bug!",
171+
AssertEx.ContainsRegex(
172+
@"dotnet watch ⚠ \[WatchHotReloadApp \(net\d+\.\d+\)\] Exception from 'System.Action`1\[System.Type\[\]\]': System.InvalidOperationException: Bug!",
173173
App.Process.Output);
174174

175175
if (verbose)
176176
{
177-
AssertEx.Contains("dotnet watch 🕵️ [WatchHotReloadApp (net9.0)] Deltas applied.", App.Process.Output);
177+
AssertEx.ContainsRegex(@"dotnet watch 🕵️ \[WatchHotReloadApp \(net\d+\.\d+\)\] Deltas applied.", App.Process.Output);
178178
}
179179
else
180180
{

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

+21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System.Collections;
5+
using System.Text.RegularExpressions;
56
using Xunit.Sdk;
67

78
namespace Microsoft.DotNet.Watcher.Tools
@@ -241,6 +242,26 @@ public static void Contains(string expected, IEnumerable<string> items)
241242
Fail(message.ToString());
242243
}
243244

245+
public static void ContainsRegex(string pattern, IEnumerable<string> items)
246+
{
247+
var regex = new Regex(pattern, RegexOptions.Compiled);
248+
249+
if (items.Any(item => regex.IsMatch(item)))
250+
{
251+
return;
252+
}
253+
254+
var message = new StringBuilder();
255+
message.AppendLine($"Pattern '{pattern}' not found in:");
256+
257+
foreach (var item in items)
258+
{
259+
message.AppendLine($"'{item}'");
260+
}
261+
262+
Fail(message.ToString());
263+
}
264+
244265
public static void DoesNotContain(string expected, IEnumerable<string> items)
245266
=> Assert.DoesNotContain(expected, items);
246267
}

0 commit comments

Comments
 (0)