5
5
using System . Text ;
6
6
using BenchmarkDotNet . Characteristics ;
7
7
using BenchmarkDotNet . Environments ;
8
+ using BenchmarkDotNet . Extensions ;
8
9
using BenchmarkDotNet . Running ;
9
10
using Xunit ;
10
11
using BenchmarkDotNet . Tests . XUnit ;
12
+ using System . Runtime ;
11
13
12
14
namespace BenchmarkDotNet . Tests
13
15
{
@@ -20,10 +22,10 @@ public void GeneratesMinimalRequiredAppConfigForEmptySource()
20
22
{
21
23
using ( var destination = new Utf8StringWriter ( ) )
22
24
{
23
- const string expectedMinimal =
25
+ string expectedMinimal =
24
26
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
25
27
"<configuration>" +
26
- "<runtime/ >" +
28
+ $ "<runtime> { GcSettings } </runtime >" +
27
29
"</configuration>" ;
28
30
29
31
AppConfigGenerator . Generate ( Job . Default , TextReader . Null , destination , Resolver ) ;
@@ -38,10 +40,10 @@ public void GeneratesMinimalRequiredAppConfigForAlmostEmptySource()
38
40
using ( var source = new StringReader ( "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" ) )
39
41
using ( var destination = new Utf8StringWriter ( ) )
40
42
{
41
- const string expectedMinimal =
43
+ string expectedMinimal =
42
44
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
43
45
"<configuration>" +
44
- "<runtime/ >" +
46
+ $ "<runtime> { GcSettings } </runtime >" +
45
47
"</configuration>" ;
46
48
47
49
AppConfigGenerator . Generate ( Job . Default , source , destination , Resolver ) ;
@@ -53,50 +55,69 @@ public void GeneratesMinimalRequiredAppConfigForAlmostEmptySource()
53
55
[ Fact ]
54
56
public void RewritesCustomSettings ( )
55
57
{
56
- const string customSettings =
58
+ string customSettingsWithoutRuntimeNode =
57
59
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
58
60
"<!--" +
59
61
"commentsAreSupported" +
60
62
"-->" +
61
63
"<configuration>" +
62
64
"<someConfig>withItsValue</someConfig>" +
63
- "<runtime/>" +
64
65
"</configuration>" ;
65
66
66
- using ( var source = new StringReader ( customSettings ) )
67
+ string customSettingsWithRuntimeNode =
68
+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
69
+ "<!--" +
70
+ "commentsAreSupported" +
71
+ "-->" +
72
+ "<configuration>" +
73
+ "<someConfig>withItsValue</someConfig>" +
74
+ $ "<runtime>{ GcSettings } </runtime>" +
75
+ "</configuration>" ;
76
+
77
+ using ( var source = new StringReader ( customSettingsWithoutRuntimeNode ) )
67
78
using ( var destination = new Utf8StringWriter ( ) )
68
79
{
69
80
AppConfigGenerator . Generate ( Job . Default , source , destination , Resolver ) ;
70
81
71
- AssertAreEqualIgnoringWhitespacesAndCase ( customSettings , destination . ToString ( ) ) ;
82
+ AssertAreEqualIgnoringWhitespacesAndCase ( customSettingsWithRuntimeNode , destination . ToString ( ) ) ;
72
83
}
73
84
}
74
85
75
86
[ Fact ]
76
87
public void RewritesCustomRuntimeSettings ( )
77
88
{
78
- const string customSettings =
89
+ string customSettingsBefore =
79
90
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
80
91
"<!--" +
81
92
"commentsAreSupported" +
82
93
"-->" +
83
94
"<configuration>" +
84
95
"<someConfig>withItsValue</someConfig>" +
85
- "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" /></runtime>" +
96
+ $ "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" /></runtime>" +
86
97
"</configuration>" ;
87
98
88
- using ( var source = new StringReader ( customSettings ) )
99
+ string customSettingsAfter =
100
+ "<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
101
+ "<!--" +
102
+ "commentsAreSupported" +
103
+ "-->" +
104
+ "<configuration>" +
105
+ "<someConfig>withItsValue</someConfig>" +
106
+ $ "<runtime><AppContextSwitchOverrides value=\" Switch.System.IO.UseLegacyPathHandling=false\" />{ GcSettings } </runtime>" +
107
+ "</configuration>" ;
108
+
109
+ using ( var source = new StringReader ( customSettingsBefore ) )
89
110
using ( var destination = new Utf8StringWriter ( ) )
90
111
{
91
112
AppConfigGenerator . Generate ( Job . Default , source , destination , Resolver ) ;
92
113
93
- AssertAreEqualIgnoringWhitespacesAndCase ( customSettings , destination . ToString ( ) ) ;
114
+ AssertAreEqualIgnoringWhitespacesAndCase ( customSettingsAfter , destination . ToString ( ) ) ;
94
115
}
95
116
}
96
117
97
118
[ Theory ]
98
- [ InlineData ( Jit . LegacyJit , "<runtime>< useLegacyJit enabled=\" 1\" /></runtime >" ) ]
99
- [ InlineData ( Jit . RyuJit , "<runtime>< useLegacyJit enabled=\" 0\" /></runtime >" ) ]
119
+ [ InlineData ( Jit . LegacyJit , "<useLegacyJit enabled=\" 1\" />" ) ]
120
+ [ InlineData ( Jit . RyuJit , "<useLegacyJit enabled=\" 0\" />" ) ]
100
121
public void GeneratesRightJitSettings ( Jit jit , string expectedRuntimeNode )
101
122
{
102
123
const string customSettings =
@@ -109,7 +130,7 @@ public void GeneratesRightJitSettings(Jit jit, string expectedRuntimeNode)
109
130
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
110
131
"<configuration>" +
111
132
"<someConfig>withItsValue</someConfig>" +
112
- expectedRuntimeNode +
133
+ $ "<runtime> { expectedRuntimeNode } { GcSettings } </runtime>" +
113
134
"</configuration>" + Environment . NewLine ;
114
135
115
136
using ( var source = new StringReader ( customSettings ) )
@@ -133,7 +154,7 @@ public void RemovesStartupSettingsForPrivateBuildsOfClr()
133
154
string withoutStartup =
134
155
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
135
156
"<configuration>" +
136
- "<runtime/ >" +
157
+ $ "<runtime> { GcSettings } </runtime >" +
137
158
"</configuration>" + Environment . NewLine ;
138
159
139
160
using ( var source = new StringReader ( input ) )
@@ -158,7 +179,7 @@ public void LeavsStartupSettingsIntactForNonPrivateBuildsOfClr()
158
179
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
159
180
"<configuration>" +
160
181
"<startup><supportedRuntime version=\" v4.0\" sku=\" .NETFramework,Version=v4.6.1\" /></startup>" +
161
- "<runtime/ >" +
182
+ $ "<runtime> { GcSettings } </runtime >" +
162
183
"</configuration>" + Environment . NewLine ;
163
184
164
185
using ( var source = new StringReader ( input ) )
@@ -186,7 +207,7 @@ public void RewritesCustomAssemblyBindingRedirects()
186
207
"</runtime>" +
187
208
"</configuration>" ;
188
209
189
- const string settingsWithBindingsAndJit =
210
+ string settingsWithBindingsAndJit =
190
211
"<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" +
191
212
"<configuration>" +
192
213
"<runtime>" +
@@ -197,6 +218,7 @@ public void RewritesCustomAssemblyBindingRedirects()
197
218
"</dependentAssembly>" +
198
219
"</assemblyBinding>" +
199
220
"<useLegacyJit enabled =\" 0\" />" +
221
+ GcSettings +
200
222
"</runtime>" +
201
223
"</configuration>" ;
202
224
@@ -234,6 +256,8 @@ private static string RemoveWhiteSpaces(string input)
234
256
}
235
257
return buffer . ToString ( ) ;
236
258
}
259
+
260
+ private static readonly string GcSettings = $ "<gcConcurrentenabled=\" { ( GCSettings . LatencyMode != GCLatencyMode . Batch ) . ToLowerCase ( ) } \" /><gcServerenabled=\" { GCSettings . IsServerGC . ToLowerCase ( ) } \" />";
237
261
}
238
262
239
263
internal class Utf8StringWriter : StringWriter
0 commit comments