@@ -14,63 +14,62 @@ namespace System.Text.RegularExpressions.Tests
14
14
[ SkipOnTargetFramework ( TargetFrameworkMonikers . NetFramework ) ]
15
15
public class RegexCompileToAssemblyTests : FileCleanupTestBase
16
16
{
17
- public static bool IsDebug => typeof ( Regex ) . Assembly . GetCustomAttributes ( false ) . OfType < DebuggableAttribute > ( ) . Any ( da => da . IsJITTrackingEnabled ) ;
18
- public static bool IsRelease => ! IsDebug ;
19
- public static bool IsDebugAndRemoteExecutorSupported => IsDebug && RemoteExecutor . IsSupported ;
20
-
21
- [ ConditionalFact ( nameof ( IsRelease ) ) ]
22
- public void CompileToAssembly_PNSE ( )
17
+ [ Fact ]
18
+ public void CompileToAssembly_SimpleTest ( )
23
19
{
24
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null ) ) ;
25
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null , null ) ) ;
26
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null , null , null ) ) ;
20
+ bool isDebug = typeof ( Regex ) . Assembly . GetCustomAttributes ( false ) . OfType < DebuggableAttribute > ( ) . Any ( da => da . IsJITTrackingEnabled ) ;
27
21
28
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
29
- [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
30
- new AssemblyName ( "abcd" ) ) ) ;
22
+ if ( ! isDebug )
23
+ {
24
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null ) ) ;
25
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null , null ) ) ;
26
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly ( null , null , null , null ) ) ;
31
27
32
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
33
- [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
34
- new AssemblyName ( "abcd" ) ,
35
- [ new CustomAttributeBuilder ( typeof ( AssemblyCompanyAttribute ) . GetConstructor ( [ typeof ( string ) ] ) , new [ ] { "TestCompany" } ) ] ) ) ;
28
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
29
+ [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
30
+ new AssemblyName ( "abcd" ) ) ) ;
36
31
37
- Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
38
- [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
39
- new AssemblyName ( "abcd" ) ,
40
- [ new CustomAttributeBuilder ( typeof ( AssemblyCompanyAttribute ) . GetConstructor ( [ typeof ( string ) ] ) , new [ ] { "TestCompany" } ) ] ,
41
- "resourceFile" ) ) ;
42
- }
32
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
33
+ [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
34
+ new AssemblyName ( "abcd" ) ,
35
+ [ new CustomAttributeBuilder ( typeof ( AssemblyCompanyAttribute ) . GetConstructor ( [ typeof ( string ) ] ) , new [ ] { "TestCompany" } ) ] ) ) ;
43
36
44
- [ ConditionalFact ( nameof ( IsDebugAndRemoteExecutorSupported ) ) ]
45
- public void CompileToAssembly_SimpleUseInDebug ( )
46
- {
47
- RemoteExecutor . Invoke ( ( ) =>
37
+ Assert . Throws < PlatformNotSupportedException > ( ( ) => Regex . CompileToAssembly (
38
+ [ new RegexCompilationInfo ( "abcd" , RegexOptions . None , "abcd" , "SomeNamespace" , true ) ] ,
39
+ new AssemblyName ( "abcd" ) ,
40
+ [ new CustomAttributeBuilder ( typeof ( AssemblyCompanyAttribute ) . GetConstructor ( [ typeof ( string ) ] ) , new [ ] { "TestCompany" } ) ] ,
41
+ "resourceFile" ) ) ;
42
+ }
43
+ else if ( RemoteExecutor . IsSupported )
48
44
{
49
- ( RegexCompilationInfo rci , string validInput , string invalidInput ) [ ] regexes =
50
- [
51
- ( new RegexCompilationInfo ( "abcd" , RegexOptions . None , "Type1" , "Namespace1" , ispublic : true ) , "123abcd123" , "123abed123" ) ,
52
- ( new RegexCompilationInfo ( "(a|b|cde)+" , RegexOptions . None , "Type2" , "Namespace2.Sub" , ispublic : true ) , "abcde" , "cd" ) ,
53
- ] ;
45
+ RemoteExecutor . Invoke ( ( ) =>
46
+ {
47
+ ( RegexCompilationInfo rci , string validInput , string invalidInput ) [ ] regexes =
48
+ [
49
+ ( new RegexCompilationInfo ( "abcd" , RegexOptions . None , "Type1" , "Namespace1" , ispublic : true ) , "123abcd123" , "123abed123" ) ,
50
+ ( new RegexCompilationInfo ( "(a|b|cde)+" , RegexOptions . None , "Type2" , "Namespace2.Sub" , ispublic : true ) , "abcde" , "cd" ) ,
51
+ ] ;
54
52
55
- string assemblyName = Path . GetRandomFileName ( ) ;
53
+ string assemblyName = Path . GetRandomFileName ( ) ;
56
54
57
- string cwd = Environment . CurrentDirectory ;
58
- Environment . CurrentDirectory = TestDirectory ;
59
- try
60
- {
61
- Regex . CompileToAssembly ( regexes . Select ( r => r . rci ) . ToArray ( ) , new AssemblyName ( assemblyName ) ) ;
62
- }
63
- finally
64
- {
65
- Environment . CurrentDirectory = cwd ;
66
- }
55
+ string cwd = Environment . CurrentDirectory ;
56
+ Environment . CurrentDirectory = TestDirectory ;
57
+ try
58
+ {
59
+ Regex . CompileToAssembly ( regexes . Select ( r => r . rci ) . ToArray ( ) , new AssemblyName ( assemblyName ) ) ;
60
+ }
61
+ finally
62
+ {
63
+ Environment . CurrentDirectory = cwd ;
64
+ }
67
65
68
- string assemblyPath = Path . Combine ( TestDirectory , assemblyName + ".dll" ) ;
69
- Assert . True ( File . Exists ( assemblyPath ) ) ;
66
+ string assemblyPath = Path . Combine ( TestDirectory , assemblyName + ".dll" ) ;
67
+ Assert . True ( File . Exists ( assemblyPath ) ) ;
70
68
71
- // Uncomment to save the assembly to the desktop for inspection:
72
- // File.Copy(assemblyPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.GetFileName(assemblyPath)));
73
- } ) . Dispose ( ) ;
69
+ // Uncomment to save the assembly to the desktop for inspection:
70
+ // File.Copy(assemblyPath, Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), Path.GetFileName(assemblyPath)));
71
+ } ) . Dispose ( ) ;
72
+ }
74
73
}
75
74
}
76
75
}
0 commit comments