Re-enable xUnit2008 (Assert.True with regex) (dotnet/corefx#39739)
authorStephen Toub <stoub@microsoft.com>
Thu, 25 Jul 2019 01:58:45 +0000 (21:58 -0400)
committerGitHub <noreply@github.com>
Thu, 25 Jul 2019 01:58:45 +0000 (21:58 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/e091ee920b211b28a9d8a7928ca3b15294789d82

src/libraries/CodeAnalysis.ruleset
src/libraries/System.ComponentModel.Composition/tests/System/ComponentModel/Composition/ImportDefinitionTests.cs
src/libraries/System.Diagnostics.DiagnosticSource/tests/HttpHandlerDiagnosticListenerTests.cs
src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsUserErrors.cs
src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsWriteEvent.cs
src/libraries/System.Drawing.Common/tests/Imaging/ImageCodecInfoTests.cs
src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs
src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj

index b0747ae..f3c5d72 100644 (file)
@@ -87,7 +87,6 @@
     <Rule Id="xUnit2005" Action="None" /> <!-- Do not use identity check on value type -->
     <Rule Id="xUnit2006" Action="None" /> <!-- Do not use invalid string equality check -->
     <Rule Id="xUnit2007" Action="None" /> <!-- Do not use typeof expression to check the type -->
-    <Rule Id="xUnit2008" Action="None" /> <!-- Do not use boolean check to match on regular expressions -->
     <Rule Id="xUnit2009" Action="None" /> <!-- Do not use boolean check to check for substrings -->
     <Rule Id="xUnit2013" Action="None" /> <!-- Do not use equality check to check for collection size. -->
     <Rule Id="xUnit2017" Action="None" /> <!-- Do not use Contains() to check if a value exists in a collection -->
index 14c401c..8bcc2c4 100644 (file)
@@ -172,7 +172,7 @@ namespace System.ComponentModel.Composition
             {
                 var item = new ImportDefinition(e.Input, "", ImportCardinality.ExactlyOne, false, false);
 
-                Assert.True(Regex.IsMatch(item.ToString(), e.Output));
+                Assert.Matches(e.Output, item.ToString());
             }
         }
 
@@ -190,7 +190,7 @@ namespace System.ComponentModel.Composition
             {
                 var item = new DerivedImportDefinition(e.Input);
 
-                Assert.True(Regex.IsMatch(item.ToString(), e.Output));
+                Assert.Matches(e.Output, item.ToString());
             }
         }
 
index f0a1aea..c199912 100644 (file)
@@ -170,7 +170,7 @@ namespace System.Diagnostics.Tests
 
                     var traceparent = startRequest.Headers["traceparent"];
                     Assert.NotNull(traceparent);
-                    Assert.True(Regex.IsMatch(traceparent, "^[0-9a-f][0-9a-f]-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f][0-9a-f]$"));
+                    Assert.Matches("^[0-9a-f][0-9a-f]-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f][0-9a-f]$", traceparent);
                     Assert.Null(startRequest.Headers["tracestate"]);
                     Assert.Null(startRequest.Headers["Request-Id"]);
                 }
@@ -216,7 +216,7 @@ namespace System.Diagnostics.Tests
                     Assert.Equal("some=state", tracestate);
                     Assert.Equal("k=v", correlationContext);
                     Assert.True(traceparent.StartsWith($"00-{parent.TraceId.ToHexString()}-"));
-                    Assert.True(Regex.IsMatch(traceparent, "^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$"));
+                    Assert.Matches("^[0-9a-f]{2}-[0-9a-f]{32}-[0-9a-f]{16}-[0-9a-f]{2}$", traceparent);
                     Assert.Null(startRequest.Headers["Request-Id"]);
                 }
             }
index 51ef8f5..3dcedbb 100644 (file)
@@ -52,7 +52,7 @@ namespace BasicEventSourceTests
 
                     string message = _event.PayloadString(0, "message");
                     // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_Bad_Type_ByteArray: Unsupported type Byte[] in event source. "
-                    Assert.True(Regex.IsMatch(message, "Unsupported type"));
+                    Assert.Matches("Unsupported type", message);
                 }
             }
             finally
@@ -126,7 +126,7 @@ namespace BasicEventSourceTests
             Debug.WriteLine(string.Format("Message=\"{0}\"", message));
             // expected message: "ERROR: Exception in Command Processing for EventSource BadEventSource_MismatchedIds: Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent. "
             if (!PlatformDetection.IsFullFramework) // Full framework has typo
-                Assert.True(Regex.IsMatch(message, "Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent"));
+                Assert.Matches("Event Event2 was assigned event ID 2 but 1 was passed to WriteEvent", message);
         }
 
         [Fact]
index e2d9517..06e4404 100644 (file)
@@ -341,7 +341,7 @@ namespace BasicEventSourceTests
                                 Assert.Equal(logger.Name, evts[0].ProviderName);
                                 Assert.Equal("EventSourceMessage", evts[0].EventName);
                                 string errorMsg = evts[0].PayloadString(0, "message");
-                                Assert.True(Regex.IsMatch(errorMsg, "called with 1.*defined with 3"));
+                                Assert.Matches("called with 1.*defined with 3", errorMsg);
                             }
 
                             int eventIdx = evts.Count - 1;
index 7b3fecf..70aa28c 100644 (file)
@@ -96,7 +96,7 @@ namespace System.Drawing.Imaging.Tests
             Assert.Equal(format.Guid, codecInfo.FormatID);
             Assert.Contains(CodecName, codecInfo.CodecName);
             Assert.Equal(DllName, codecInfo.DllName);
-            Assert.True(extRegex.IsMatch(codecInfo.FilenameExtension));
+            Assert.Matches(extRegex, codecInfo.FilenameExtension);
             Assert.Equal(Flags, codecInfo.Flags);
             Assert.Contains(FormatDescription, codecInfo.FormatDescription);
             Assert.Contains(MimeType, codecInfo.MimeType);
index d3d6891..8233cce 100644 (file)
@@ -3420,9 +3420,9 @@ namespace CoreXml.Test.XLinq
                         // \p{Pi} any kind of opening quote https://www.compart.com/en/unicode/category/Pi
                         // \p{Pf} any kind of closing quote https://www.compart.com/en/unicode/category/Pf
                         // \p{Po} any kind of punctuation character that is not a dash, bracket, quote or connector https://www.compart.com/en/unicode/category/Po
-                        Assert.True(Regex.IsMatch(exception.Message, @"[\p{Pi}\p{Po}]" + Regex.Escape("]]>") + @"[\p{Pf}\p{Po}]"));
-                        Assert.True(Regex.IsMatch(exception.Message, @"\b" + "XML" + @"\b"));
-                        Assert.True(Regex.IsMatch(exception.Message, @"\b" + "CDATA" + @"\b"));
+                        Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape("]]>") + @"[\p{Pf}\p{Po}]", exception.Message);
+                        Assert.Matches(@"\b" + "XML" + @"\b", exception.Message);
+                        Assert.Matches(@"\b" + "CDATA" + @"\b", exception.Message);
                     }
                 }
 
@@ -3616,9 +3616,9 @@ namespace CoreXml.Test.XLinq
                         // \p{Pi} any kind of opening quote https://www.compart.com/en/unicode/category/Pi
                         // \p{Pf} any kind of closing quote https://www.compart.com/en/unicode/category/Pf
                         // \p{Po} any kind of punctuation character that is not a dash, bracket, quote or connector https://www.compart.com/en/unicode/category/Po
-                        Assert.True(Regex.IsMatch(exception.Message, @"\b" + "XML" + @"\b"));
-                        Assert.True(Regex.IsMatch(exception.Message, @"[\p{Pi}\p{Po}]" + Regex.Escape("--") + @"[\p{Pf}\p{Po}]"));
-                        Assert.True(Regex.IsMatch(exception.Message, @"[\p{Pi}\p{Po}]" + Regex.Escape("-") + @"[\p{Pf}\p{Po}]"));
+                        Assert.Matches(@"\b" + "XML" + @"\b", exception.Message);
+                        Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape("--") + @"[\p{Pf}\p{Po}]", exception.Message);
+                        Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape("-") + @"[\p{Pf}\p{Po}]", exception.Message);
                     }
                 }
             }
@@ -4221,8 +4221,8 @@ namespace CoreXml.Test.XLinq
                         // \p{Pi} any kind of opening quote https://www.compart.com/en/unicode/category/Pi
                         // \p{Pf} any kind of closing quote https://www.compart.com/en/unicode/category/Pf
                         // \p{Po} any kind of punctuation character that is not a dash, bracket, quote or connector https://www.compart.com/en/unicode/category/Po
-                        Assert.True(Regex.IsMatch(exception.Message, @"[\p{Pi}\p{Po}]" + Regex.Escape("?>") + @"[\p{Pf}\p{Po}]"));
-                        Assert.True(Regex.IsMatch(exception.Message, @"\b" + "XML" + @"\b"));
+                        Assert.Matches(@"[\p{Pi}\p{Po}]" + Regex.Escape("?>") + @"[\p{Pf}\p{Po}]", exception.Message);
+                        Assert.Matches(@"\b" + "XML" + @"\b", exception.Message);
                     }
                 }
 
index 46a68e3..ed6a26b 100644 (file)
@@ -2,6 +2,7 @@
   <PropertyGroup>
     <ProjectGuid>{94B106C2-D574-4392-80AB-3EE308A078DF}</ProjectGuid>
     <IncludeRemoteExecutor>true</IncludeRemoteExecutor>
+    <NoWarn>$(NoWarn);xUnit2008</NoWarn>
     <Configurations>netcoreapp-Debug;netcoreapp-Release;uap-Debug;uap-Release</Configurations>
   </PropertyGroup>
   <PropertyGroup>