8
8
using Shouldly ;
9
9
using YamlDotNet . Serialization ;
10
10
using GitVersion . Configuration ;
11
- using GitVersion . Helpers ;
12
11
using GitVersion . VersioningModes ;
13
12
using GitVersion . Extensions ;
14
13
using GitVersion . Common ;
14
+ using GitVersion . Log ;
15
15
16
16
namespace GitVersionCore . Tests
17
17
{
@@ -22,13 +22,14 @@ public class ConfigProviderTests : TestBase
22
22
23
23
string repoPath ;
24
24
IFileSystem fileSystem ;
25
- ConfigFileLocator configFileLocator ;
25
+ IConfigFileLocator configFileLocator ;
26
26
27
27
[ SetUp ]
28
28
public void Setup ( )
29
29
{
30
30
fileSystem = new TestFileSystem ( ) ;
31
- configFileLocator = new DefaultConfigFileLocator ( ) ;
31
+ var log = new NullLog ( ) ;
32
+ configFileLocator = new DefaultConfigFileLocator ( fileSystem , log ) ;
32
33
repoPath = DefaultRepoPath ;
33
34
34
35
ShouldlyConfiguration . ShouldMatchApprovedDefaults . LocateTestMethodUsingAttribute < TestAttribute > ( ) ;
@@ -52,7 +53,7 @@ public void CanReadOldDocument()
52
53
tag: rc
53
54
" ;
54
55
SetupConfigFileContent ( text ) ;
55
- var error = Should . Throw < OldConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ) ;
56
+ var error = Should . Throw < OldConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , configFileLocator ) ) ;
56
57
error . Message . ShouldContainWithoutWhitespace ( @"GitVersion configuration file contains old configuration, please fix the following errors:
57
58
GitVersion branch configs no longer are keyed by regexes, update:
58
59
dev(elop)?(ment)?$ -> develop
@@ -65,15 +66,15 @@ assemblyVersioningScheme has been replaced by assembly-versioning-scheme
65
66
[ Test ]
66
67
public void OverwritesDefaultsWithProvidedConfig ( )
67
68
{
68
- var defaultConfig = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
69
+ var defaultConfig = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
69
70
const string text = @"
70
71
next-version: 2.0.0
71
72
branches:
72
73
develop:
73
74
mode: ContinuousDeployment
74
75
tag: dev" ;
75
76
SetupConfigFileContent ( text ) ;
76
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
77
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
77
78
78
79
config . NextVersion . ShouldBe ( "2.0.0" ) ;
79
80
config . Branches [ "develop" ] . Increment . ShouldBe ( defaultConfig . Branches [ "develop" ] . Increment ) ;
@@ -86,7 +87,7 @@ public void AllBranchesModeWhenUsingMainline()
86
87
{
87
88
const string text = @"mode: Mainline" ;
88
89
SetupConfigFileContent ( text ) ;
89
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
90
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
90
91
var branches = config . Branches . Select ( x => x . Value ) ;
91
92
branches . All ( branch => branch . VersioningMode == VersioningMode . Mainline ) . ShouldBe ( true ) ;
92
93
}
@@ -100,7 +101,7 @@ public void CanRemoveTag()
100
101
release:
101
102
tag: """"" ;
102
103
SetupConfigFileContent ( text ) ;
103
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
104
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
104
105
105
106
config . NextVersion . ShouldBe ( "2.0.0" ) ;
106
107
config . Branches [ "release" ] . Tag . ShouldBe ( string . Empty ) ;
@@ -115,7 +116,7 @@ public void RegexIsRequired()
115
116
bug:
116
117
tag: bugfix" ;
117
118
SetupConfigFileContent ( text ) ;
118
- var ex = Should . Throw < GitVersionConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ) ;
119
+ var ex = Should . Throw < GitVersionConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , configFileLocator ) ) ;
119
120
ex . Message . ShouldBe ( "Branch configuration 'bug' is missing required configuration 'regex'\n \n " +
120
121
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info" ) ;
121
122
}
@@ -130,7 +131,7 @@ public void SourceBranchIsRequired()
130
131
regex: 'bug[/-]'
131
132
tag: bugfix" ;
132
133
SetupConfigFileContent ( text ) ;
133
- var ex = Should . Throw < GitVersionConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ) ;
134
+ var ex = Should . Throw < GitVersionConfigurationException > ( ( ) => ConfigurationProvider . Provide ( repoPath , configFileLocator ) ) ;
134
135
ex . Message . ShouldBe ( "Branch configuration 'bug' is missing required configuration 'source-branches'\n \n " +
135
136
"See http://gitversion.readthedocs.io/en/latest/configuration/ for more info" ) ;
136
137
}
@@ -146,7 +147,7 @@ public void CanProvideConfigForNewBranch()
146
147
tag: bugfix
147
148
source-branches: []" ;
148
149
SetupConfigFileContent ( text ) ;
149
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
150
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
150
151
151
152
config . Branches [ "bug" ] . Regex . ShouldBe ( "bug[/-]" ) ;
152
153
config . Branches [ "bug" ] . Tag . ShouldBe ( "bugfix" ) ;
@@ -157,7 +158,7 @@ public void NextVersionCanBeInteger()
157
158
{
158
159
const string text = "next-version: 2" ;
159
160
SetupConfigFileContent ( text ) ;
160
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
161
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
161
162
162
163
config . NextVersion . ShouldBe ( "2.0" ) ;
163
164
}
@@ -167,7 +168,7 @@ public void NextVersionCanHaveEnormousMinorVersion()
167
168
{
168
169
const string text = "next-version: 2.118998723" ;
169
170
SetupConfigFileContent ( text ) ;
170
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
171
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
171
172
172
173
config . NextVersion . ShouldBe ( "2.118998723" ) ;
173
174
}
@@ -177,7 +178,7 @@ public void NextVersionCanHavePatch()
177
178
{
178
179
const string text = "next-version: 2.12.654651698" ;
179
180
SetupConfigFileContent ( text ) ;
180
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
181
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
181
182
182
183
config . NextVersion . ShouldBe ( "2.12.654651698" ) ;
183
184
}
@@ -188,7 +189,7 @@ public void NextVersionCanHavePatch()
188
189
[ Description ( "Won't run on Mono due to source information not being available for ShouldMatchApproved." ) ]
189
190
public void CanWriteOutEffectiveConfiguration ( )
190
191
{
191
- var config = ConfigurationProvider . GetEffectiveConfigAsString ( repoPath , fileSystem , configFileLocator ) ;
192
+ var config = ConfigurationProvider . GetEffectiveConfigAsString ( repoPath , configFileLocator ) ;
192
193
193
194
config . ShouldMatchApproved ( ) ;
194
195
}
@@ -203,7 +204,7 @@ public void CanUpdateAssemblyInformationalVersioningScheme()
203
204
204
205
SetupConfigFileContent ( text ) ;
205
206
206
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
207
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
207
208
config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinor ) ;
208
209
config . AssemblyFileVersioningScheme . ShouldBe ( AssemblyFileVersioningScheme . MajorMinorPatch ) ;
209
210
config . AssemblyInformationalFormat . ShouldBe ( "{NugetVersion}" ) ;
@@ -219,7 +220,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithMultipleVariables(
219
220
220
221
SetupConfigFileContent ( text ) ;
221
222
222
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
223
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
223
224
config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinor ) ;
224
225
config . AssemblyFileVersioningScheme . ShouldBe ( AssemblyFileVersioningScheme . MajorMinorPatch ) ;
225
226
config . AssemblyInformationalFormat . ShouldBe ( "{Major}.{Minor}.{Patch}" ) ;
@@ -238,7 +239,7 @@ public void CanUpdateAssemblyInformationalVersioningSchemeWithFullSemVer()
238
239
239
240
SetupConfigFileContent ( text ) ;
240
241
241
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
242
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
242
243
config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinorPatch ) ;
243
244
config . AssemblyFileVersioningScheme . ShouldBe ( AssemblyFileVersioningScheme . MajorMinorPatch ) ;
244
245
config . AssemblyInformationalFormat . ShouldBe ( "{FullSemVer}" ) ;
@@ -249,7 +250,7 @@ public void CanReadDefaultDocument()
249
250
{
250
251
const string text = "" ;
251
252
SetupConfigFileContent ( text ) ;
252
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
253
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
253
254
config . AssemblyVersioningScheme . ShouldBe ( AssemblyVersioningScheme . MajorMinorPatch ) ;
254
255
config . AssemblyFileVersioningScheme . ShouldBe ( AssemblyFileVersioningScheme . MajorMinorPatch ) ;
255
256
config . AssemblyInformationalFormat . ShouldBe ( null ) ;
@@ -276,15 +277,17 @@ public void NoWarnOnGitVersionYmlFile()
276
277
{
277
278
SetupConfigFileContent ( string . Empty ) ;
278
279
279
- var s = string . Empty ;
280
+ var stringLogger = string . Empty ;
281
+ void Action ( string info ) => stringLogger = info ;
280
282
281
- void Action ( string info ) => s = info ;
283
+ var logAppender = new TestLogAppender ( Action ) ;
284
+ var log = new Log ( logAppender ) ;
282
285
283
- using ( Logger . AddLoggersTemporarily ( Action , Action , Action , Action ) )
284
- {
285
- ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
286
- }
287
- s . Length . ShouldBe ( 0 ) ;
286
+ var defaultConfigFileLocator = new DefaultConfigFileLocator ( fileSystem , log ) ;
287
+
288
+ ConfigurationProvider . Provide ( repoPath , defaultConfigFileLocator ) ;
289
+
290
+ stringLogger . Length . ShouldBe ( 0 ) ;
288
291
}
289
292
290
293
string SetupConfigFileContent ( string text , string fileName = DefaultConfigFileLocator . DefaultFileName )
@@ -311,7 +314,7 @@ public void ShouldUseSpecifiedSourceBranchesForDevelop()
311
314
source-branches: ['develop']
312
315
tag: dev" ;
313
316
SetupConfigFileContent ( text ) ;
314
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
317
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
315
318
316
319
config . Branches [ "develop" ] . SourceBranches . ShouldBe ( new List < string > { "develop" } ) ;
317
320
}
@@ -326,7 +329,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForDevelop()
326
329
mode: ContinuousDeployment
327
330
tag: dev" ;
328
331
SetupConfigFileContent ( text ) ;
329
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
332
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
330
333
331
334
config . Branches [ "develop" ] . SourceBranches . ShouldBe ( new List < string > ( ) ) ;
332
335
}
@@ -342,7 +345,7 @@ public void ShouldUseSpecifiedSourceBranchesForFeature()
342
345
source-branches: ['develop', 'release']
343
346
tag: dev" ;
344
347
SetupConfigFileContent ( text ) ;
345
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
348
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
346
349
347
350
config . Branches [ "feature" ] . SourceBranches . ShouldBe ( new List < string > { "develop" , "release" } ) ;
348
351
}
@@ -357,7 +360,7 @@ public void ShouldUseDefaultSourceBranchesWhenNotSpecifiedForFeature()
357
360
mode: ContinuousDeployment
358
361
tag: dev" ;
359
362
SetupConfigFileContent ( text ) ;
360
- var config = ConfigurationProvider . Provide ( repoPath , fileSystem , configFileLocator ) ;
363
+ var config = ConfigurationProvider . Provide ( repoPath , configFileLocator ) ;
361
364
362
365
config . Branches [ "feature" ] . SourceBranches . ShouldBe (
363
366
new List < string > { "develop" , "master" , "release" , "feature" , "support" , "hotfix" } ) ;
0 commit comments