Make it possible to condition tests on line number support (#50165)
authorMichal Strehovský <MichalStrehovsky@users.noreply.github.com>
Wed, 24 Mar 2021 13:20:04 +0000 (14:20 +0100)
committerGitHub <noreply@github.com>
Wed, 24 Mar 2021 13:20:04 +0000 (09:20 -0400)
* Update PlatformDetection.cs

* Update ExceptionTests.cs

* Update PlatformDetection.cs

src/libraries/Common/tests/TestUtilities/System/PlatformDetection.cs
src/libraries/System.Runtime/tests/System/ExceptionTests.cs

index b163e97..ddb5ae2 100644 (file)
@@ -85,6 +85,8 @@ namespace System
 
             }
         }
+        
+        public static bool IsLineNumbersSupported => true;
 
         public static bool IsInContainer => GetIsInContainer();
         public static bool SupportsComInterop => IsWindows && IsNotMonoRuntime; // matches definitions in clr.featuredefines.props
index 8c01f9a..3bec61d 100644 (file)
@@ -151,7 +151,15 @@ namespace System.Tests
         {
             try
             {
-                const string frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)\([^)]*\)\sin\s(?<filePath>.*)\:line\s(?<lineNumber>[\d]+)";
+                string frameParserRegex;
+                if (PlatformDetection.IsLineNumbersSupported)
+                {
+                    frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)\([^)]*\)\sin\s(?<filePath>.*)\:line\s(?<lineNumber>[\d]+)";
+                }
+                else
+                {
+                    frameParserRegex = @"\s+at\s.+\.(?<memberName>[^(.]+)";
+                }
 
                 using (var sr = new StringReader(reportedCallStack))
                 {
@@ -162,8 +170,12 @@ namespace System.Tests
                     var match = Regex.Match(frame, frameParserRegex);
                     Assert.True(match.Success);
                     Assert.Equal(expectedStackFrame.CallerMemberName, match.Groups["memberName"].Value);
-                    Assert.Equal(expectedStackFrame.SourceFilePath, match.Groups["filePath"].Value);
-                    Assert.Equal(expectedStackFrame.SourceLineNumber, Convert.ToInt32(match.Groups["lineNumber"].Value));
+                    
+                    if (PlatformDetection.IsLineNumbersSupported)
+                    {
+                        Assert.Equal(expectedStackFrame.SourceFilePath, match.Groups["filePath"].Value);
+                        Assert.Equal(expectedStackFrame.SourceLineNumber, Convert.ToInt32(match.Groups["lineNumber"].Value));
+                    }
                 }
             }
             catch