Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove regex timeout for IsLocalMethod and IsTypeFilterMatch #1689

Merged
merged 4 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,4 @@ coverage.*.cobertura.xml
coverage.*.opencover.xml

FolderProfile.pubxml
/NuGet.config
11 changes: 8 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@
<VSTestLogger Include="html%3BLogFileName=TestResults-$(TargetFramework)-$(MSBuildProjectName).html" />
</ItemGroup>

<PropertyGroup>
<PropertyGroup Condition=" '$(OS)' != 'Windows_NT' ">
<VSTestResultsDirectory>$(RepoRoot)artifacts/testresults/$(Configuration.ToLowerInvariant())</VSTestResultsDirectory>
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
</PropertyGroup>

<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<VSTestResultsDirectory>$(RepoRoot)artifacts\testresults\$(Configuration.ToLowerInvariant())</VSTestResultsDirectory>
<VSTestLogger>@(VSTestLogger)</VSTestLogger>
</PropertyGroup>

<PropertyGroup>
<!--
Do not change versions since we need to support VSTest DataCollectors. We need to load assembly version 1.6.0 to properly work
Expand All @@ -69,9 +74,9 @@
<MicrosoftBuildTaskVersion>15.7.179</MicrosoftBuildTaskVersion>
<MicrosoftBuildTaskUtilitiesCoreVersion>15.7.179</MicrosoftBuildTaskUtilitiesCoreVersion>
<NuGetBuildTasksPackageVersion>6.9.0-rc.86</NuGetBuildTasksPackageVersion>
<MicrosoftBuildTaskSystemReflectionMetaData>1.4.2</MicrosoftBuildTaskSystemReflectionMetaData>
<MicrosoftBuildTaskSystemReflectionMetaData>1.4.2</MicrosoftBuildTaskSystemReflectionMetaData>
<MicrosoftBuildTaskSystemCollectionImmutable>1.5.0</MicrosoftBuildTaskSystemCollectionImmutable> >= 1.3.1
-->
-->
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion eng/publish-coverage-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions src/coverlet.core/Helpers/InstrumentationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
=> Regex.IsMatch(method, WildcardToRegex("<*>*__*|*"));

public void SetLogger(ILogger logger)
{
Expand All @@ -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 (Regex.IsMatch(type, typePattern) && Regex.IsMatch(module, modulePattern))
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<PropertyGroup>
<IsTestProject>true</IsTestProject>
<NoWarn>$(NoWarn);NU1301</NoWarn>
<NoWarn>$(NoWarn);NU1301;IDE0007</NoWarn>
</PropertyGroup>
</Project>
38 changes: 22 additions & 16 deletions test/coverlet.core.tests/Helpers/InstrumentationHelperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down