Add regex "unit tests" test project (#65944)
authorStephen Toub <stoub@microsoft.com>
Mon, 28 Feb 2022 22:55:35 +0000 (17:55 -0500)
committerGitHub <noreply@github.com>
Mon, 28 Feb 2022 22:55:35 +0000 (17:55 -0500)
commitb4c746b7712e887af066d66d1ec777be6283f6f9
tree48fe544705c43f2ff9969ef5846408d04b70bf49
parent3d6781bdf367b0de082613b7ce9cb9b648ec6309
Add regex "unit tests" test project (#65944)

* Add regex "unit tests" test project

This follows the convention used by the networking tests, which typically have two distinct test projects per library: functional tests and unit tests.  The former are what we typically refer to as our tests for a library, whereas the latter build product source into the test project in order to directly validate internals (an alternative to this is to use InternalsVisibleTo, but that negatively impacts trimming and makes it more challenging to maintain a property boundary for the functional tests).  All the existing tests are moved unedited into the FunctionalTests, and a new UnitTests project is added with some initial tests for the RegexTreeAnalyzer code. The generator parser tests were also consolidated into the functional tests, as there's no longer a good reason for those few tests to be separate.

I fixed a few bugs in RegexTreeAnalyzer as a result.  In particular, we were over-annotating things as potentially containing captures or backtracking because in the implementation we were using the lookup APIs meant to be used only once all analysis was complete.  This doesn't have a negative functional impact, but it does negatively impact perf of compiled / source generator, which then generate unnecessary code.  We were also incorrectly conflating atomicity conferred by a grandparent with atomicity conferred by a parent; we need MayBacktracks to reflect only the atomicity directly contributed by a node, not by its parent's influence, as we need the parent to be able to understand whether the child might backtrack.

* Add some unit tests for RegexFindOptimizations

* Address PR feedback
53 files changed:
src/libraries/System.Text.RegularExpressions/System.Text.RegularExpressions.sln
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexFindOptimizations.cs
src/libraries/System.Text.RegularExpressions/src/System/Text/RegularExpressions/RegexTreeAnalyzer.cs
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/AttRegexTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/AttRegexTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CaptureCollectionTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CaptureCollectionTests2.cs [moved from src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests2.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/CustomDerivedRegexScenarioTest.cs [moved from src/libraries/System.Text.RegularExpressions/tests/CustomDerivedRegexScenarioTest.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/GroupCollectionReadOnlyDictionaryTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/GroupCollectionReadOnlyDictionaryTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/GroupCollectionTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/GroupCollectionTests2.cs [moved from src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests2.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/MatchCollectionTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/MatchCollectionTests2.cs [moved from src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests2.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/MonoRegexTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/MonoRegexTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/PrecompiledRegexScenarioTest.cs [moved from src/libraries/System.Text.RegularExpressions/tests/PrecompiledRegexScenarioTest.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Cache.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Cache.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.CompileToAssembly.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.CompileToAssembly.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Count.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Count.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Ctor.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Ctor.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.EscapeUnescape.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.EscapeUnescape.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.GetGroupNames.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.GetGroupNames.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Groups.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.KnownPattern.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.KnownPattern.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Match.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.MultipleMatches.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.MultipleMatches.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Replace.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Replace.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Split.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Split.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Tests.Common.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.Tests.Common.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.UnicodeChar.Tests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/Regex.UnicodeChar.Tests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexAssert.netcoreapp.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexAssert.netcoreapp.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexAssert.netfx.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexAssert.netfx.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCharacterSetTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexCharacterSetTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCompilationInfoTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexCompilationInfoTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexCultureTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexCultureTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexExperiment.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexExperiment.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorAttributeTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexGeneratorAttributeTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorHelper.netcoreapp.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexGeneratorHelper.netcoreapp.cs with 75% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorHelper.netfx.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexGeneratorHelper.netfx.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGeneratorParserTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Generators.Tests/RegexGeneratorParserTests.cs with 76% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexGroupNameTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexGroupNameTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexMatchTimeoutExceptionTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexMatchTimeoutExceptionTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexParserTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexParserTests.netcoreapp.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.netcoreapp.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexParserTests.netfx.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexParserTests.netfx.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexReductionTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexReductionTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/RegexRunnerTests.cs [moved from src/libraries/System.Text.RegularExpressions/tests/RegexRunnerTests.cs with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/System.Text.RegularExpressions.Tests.csproj [moved from src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Tests.csproj with 86% similarity]
src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/THIRD-PARTY-NOTICES.TXT [moved from src/libraries/System.Text.RegularExpressions/tests/THIRD-PARTY-NOTICES.TXT with 100% similarity]
src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Generators.Tests/System.Text.RegularExpressions.Generators.Tests.csproj [deleted file]
src/libraries/System.Text.RegularExpressions/tests/System.Text.RegularExpressions.Generators.Tests/System.Text.RegularExpressions.Generators.Tests.sln [deleted file]
src/libraries/System.Text.RegularExpressions/tests/UnitTests/RegexFindOptimizationsTests.cs [new file with mode: 0644]
src/libraries/System.Text.RegularExpressions/tests/UnitTests/RegexTreeAnalyzerTests.cs [new file with mode: 0644]
src/libraries/System.Text.RegularExpressions/tests/UnitTests/Stubs.cs [new file with mode: 0644]
src/libraries/System.Text.RegularExpressions/tests/UnitTests/System.Text.RegularExpressions.UnitTests.csproj [new file with mode: 0644]