From 1a86c4ba3f2f483175c0b6b10aa5b9010ee57a71 Mon Sep 17 00:00:00 2001 From: Bert Date: Sat, 17 Aug 2024 09:31:45 +0200 Subject: [PATCH 1/4] remove regex timeout for IsLocalMethod and IsTypeFilterMatch --- .gitignore | 1 + .../Helpers/InstrumentationHelper.cs | 6 +-- test/Directory.Build.props | 2 +- .../Helpers/InstrumentationHelperTests.cs | 38 +++++++++++-------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index ace214b5a..478b5fc8b 100644 --- a/.gitignore +++ b/.gitignore @@ -315,3 +315,4 @@ coverage.*.cobertura.xml coverage.*.opencover.xml FolderProfile.pubxml +/NuGet.config diff --git a/src/coverlet.core/Helpers/InstrumentationHelper.cs b/src/coverlet.core/Helpers/InstrumentationHelper.cs index 0c271c8ec..ff681a410 100644 --- a/src/coverlet.core/Helpers/InstrumentationHelper.cs +++ b/src/coverlet.core/Helpers/InstrumentationHelper.cs @@ -25,7 +25,7 @@ internal class InstrumentationHelper : IInstrumentationHelper private readonly ISourceRootTranslator _sourceRootTranslator; private ILogger _logger; private static readonly RegexOptions s_regexOptions = - RegexOptions.Multiline | RegexOptions.Compiled | RegexOptions.IgnoreCase; + RegexOptions.Multiline | RegexOptions.Compiled; public InstrumentationHelper(IProcessExitHandler processExitHandler, IRetryHelper retryHelper, IFileSystem fileSystem, ILogger logger, ISourceRootTranslator sourceRootTranslator) { @@ -420,7 +420,7 @@ public bool IsTypeIncluded(string module, string type, string[] includeFilters) } public bool IsLocalMethod(string method) - => new Regex(WildcardToRegex("<*>*__*|*"), s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(method); + => new Regex(WildcardToRegex("<*>*__*|*")).IsMatch(method); public void SetLogger(ILogger logger) { @@ -442,7 +442,7 @@ private static bool IsTypeFilterMatch(string module, string type, string[] filte typePattern = WildcardToRegex(typePattern); modulePattern = WildcardToRegex(modulePattern); - if (new Regex(typePattern, s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(type) && new Regex(modulePattern, s_regexOptions, TimeSpan.FromSeconds(10)).IsMatch(module)) + if (new Regex(typePattern).IsMatch(type) && new Regex(modulePattern).IsMatch(module)) return true; } diff --git a/test/Directory.Build.props b/test/Directory.Build.props index 46ee48927..d7ecd93ee 100644 --- a/test/Directory.Build.props +++ b/test/Directory.Build.props @@ -3,6 +3,6 @@ true - $(NoWarn);NU1301 + $(NoWarn);NU1301;IDE0007 diff --git a/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs b/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs index 91edf8589..557835806 100644 --- a/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs +++ b/test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs @@ -112,23 +112,29 @@ public void TestBackupOriginalModule() Assert.True(File.Exists(backupPath)); } - [Fact] - public void TestIsValidFilterExpression() + [Theory] + [InlineData("[*]*")] + [InlineData("[*]*core")] + [InlineData("[assembly]*")] + [InlineData("[*]type")] + [InlineData("[assembly]type")] + [InlineData("[coverlet.*.tests?]*")] + [InlineData("[*]Coverlet.Core*")] + [InlineData("[coverlet.*]*")] + public void TestIsValidFilterExpression(string pattern) + { + Assert.True(_instrumentationHelper.IsValidFilterExpression(pattern)); + } + + [Theory] + [InlineData("[*]")] + [InlineData("[-]*")] + [InlineData("*")] + [InlineData("][")] + [InlineData(null)] + public void TestInValidFilterExpression(string pattern) { - Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]*")); - Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]*core")); - Assert.True(_instrumentationHelper.IsValidFilterExpression("[assembly]*")); - Assert.True(_instrumentationHelper.IsValidFilterExpression("[*]type")); - Assert.True(_instrumentationHelper.IsValidFilterExpression("[assembly]type")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[*]")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[-]*")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("*")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("][")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[assembly][*")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[assembly]*]")); - Assert.False(_instrumentationHelper.IsValidFilterExpression("[]")); - Assert.False(_instrumentationHelper.IsValidFilterExpression(null)); + Assert.False(_instrumentationHelper.IsValidFilterExpression(pattern)); } [Fact] From a75142d350f881030851c218ddd230e95bd0fd68 Mon Sep 17 00:00:00 2001 From: Bert Date: Mon, 26 Aug 2024 15:13:28 +0200 Subject: [PATCH 2/4] use static regex method --- src/coverlet.core/Helpers/InstrumentationHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coverlet.core/Helpers/InstrumentationHelper.cs b/src/coverlet.core/Helpers/InstrumentationHelper.cs index ff681a410..82b66056b 100644 --- a/src/coverlet.core/Helpers/InstrumentationHelper.cs +++ b/src/coverlet.core/Helpers/InstrumentationHelper.cs @@ -420,7 +420,7 @@ public bool IsTypeIncluded(string module, string type, string[] includeFilters) } public bool IsLocalMethod(string method) - => new Regex(WildcardToRegex("<*>*__*|*")).IsMatch(method); + => Regex.IsMatch(method, WildcardToRegex("<*>*__*|*")); public void SetLogger(ILogger logger) { @@ -442,7 +442,7 @@ private static bool IsTypeFilterMatch(string module, string type, string[] filte typePattern = WildcardToRegex(typePattern); modulePattern = WildcardToRegex(modulePattern); - if (new Regex(typePattern).IsMatch(type) && new Regex(modulePattern).IsMatch(module)) + if (Regex.IsMatch(type, typePattern) && Regex.IsMatch(module, modulePattern)) return true; } From eeb98e5d78078d974c02aafaa48a0854bb1b6b9a Mon Sep 17 00:00:00 2001 From: Bert Date: Mon, 26 Aug 2024 15:34:09 +0200 Subject: [PATCH 3/4] update PublishCodeCoverageResults version --- eng/publish-coverage-results.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/publish-coverage-results.yml b/eng/publish-coverage-results.yml index 58dda6870..796d8f577 100644 --- a/eng/publish-coverage-results.yml +++ b/eng/publish-coverage-results.yml @@ -26,7 +26,7 @@ steps: artifact: CoverageResults_$(Agent.Os)_$(BuildConfiguration) condition: ${{parameters.condition}} -- task: PublishCodeCoverageResults@1 +- task: PublishCodeCoverageResults@2 displayName: 'Publish code coverage' condition: ${{parameters.condition}} inputs: From a52aec7c6b88a72aaa19c2fca6b6d87a5e8b5344 Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 28 Aug 2024 12:04:03 +0200 Subject: [PATCH 4/4] support windows path separator --- Directory.Build.props | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 91ee686a1..74a9fdaea 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -38,11 +38,16 @@ - + $(RepoRoot)artifacts/testresults/$(Configuration.ToLowerInvariant()) @(VSTestLogger) + + $(RepoRoot)artifacts\testresults\$(Configuration.ToLowerInvariant()) + @(VSTestLogger) + + + -->