1 // Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
2 
3 using System.Diagnostics;
4 using System.Text.RegularExpressions;
5 using System.Threading;
6 using Xunit;
7 
8 namespace System.Web.Razor.Test.Utils
9 {
10     class MiscUtils
11     {
12         public const int TimeoutInSeconds = 1;
13 
StripRuntimeVersion(string s)14         public static string StripRuntimeVersion(string s)
15         {
16             return Regex.Replace(s, @"Runtime Version:[\d.]*", "Runtime Version:N.N.NNNNN.N");
17         }
18 
DoWithTimeoutIfNotDebugging(Func<int, bool> withTimeout)19         public static void DoWithTimeoutIfNotDebugging(Func<int, bool> withTimeout)
20         {
21 #if DEBUG
22             if (Debugger.IsAttached)
23             {
24                 withTimeout(Timeout.Infinite);
25             }
26             else
27             {
28 #endif
29                 Assert.True(withTimeout((int)TimeSpan.FromSeconds(TimeoutInSeconds).TotalMilliseconds), "Timeout expired!");
30 #if DEBUG
31             }
32 #endif
33         }
34     }
35 }
36