Skip to content

Commit 11346f2

Browse files
committed
enable dynamic repo tests
1 parent 8150dec commit 11346f2

File tree

6 files changed

+23
-67
lines changed

6 files changed

+23
-67
lines changed

src/GitVersionCore.Tests/DynamicRepositoryTests.cs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
1-
using System.Diagnostics;
21
using System.IO;
32
using GitVersion;
43
using NUnit.Framework;
5-
using GitVersion.Helpers;
64
using GitVersion.Log;
75

86
namespace GitVersionCore.Tests
97
{
108
[TestFixture]
11-
[Ignore("These tests are slow and fail on the second run in Test Explorer and need to be re-written")]
129
public class DynamicRepositoryTests : TestBase
1310
{
1411
string workDirectory;
1512

13+
private void ClearReadOnly(DirectoryInfo parentDirectory)
14+
{
15+
if (parentDirectory == null) return;
16+
parentDirectory.Attributes = FileAttributes.Normal;
17+
foreach (var fi in parentDirectory.GetFiles())
18+
{
19+
fi.Attributes = FileAttributes.Normal;
20+
}
21+
foreach (var di in parentDirectory.GetDirectories())
22+
{
23+
ClearReadOnly(di);
24+
}
25+
}
1626

1727
[OneTimeSetUp]
1828
public void CreateTemporaryRepository()
@@ -23,6 +33,9 @@ public void CreateTemporaryRepository()
2333
// Clean directory upfront, some build agents are having troubles
2434
if (Directory.Exists(workDirectory))
2535
{
36+
var di = new DirectoryInfo(workDirectory);
37+
ClearReadOnly(di);
38+
2639
Directory.Delete(workDirectory, true);
2740
}
2841

@@ -43,8 +56,6 @@ public void Cleanup()
4356
[TestCase("Ctl_develop", "https://github.com/Catel/Catel", "develop", "0e2b6c125a730d2fa5e24394ef64abe62c98e9e9", "5.12.0-alpha.188")]
4457
[TestCase("Ctl_develop", "https://github.com/Catel/Catel", "develop", "71e71359f37581784e18c94e7a45eee72cbeeb30", "5.12.0-alpha.192")]
4558
[TestCase("Ctl_master", "https://github.com/Catel/Catel", "master", "f5de8964c35180a5f8607f5954007d5828aa849f", "5.10.0")]
46-
[TestCase("CtlA_develop", "https://github.com/Catel/Catel.Analyzers", "develop", "be0aa94642d6ff1df6209e2180a7fe0de9aab384", "0.1.0-alpha.21")]
47-
[TestCase("CtlA_develop", "https://github.com/Catel/Catel.Analyzers", "develop", "0e2b6c125a730d2fa5e24394ef64abe62c98e9e9", "0.1.0-alpha.23")]
4859
public void FindsVersionInDynamicRepo(string name, string url, string targetBranch, string commitId, string expectedFullSemVer)
4960
{
5061
var root = Path.Combine(workDirectory, name);
@@ -54,12 +65,6 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
5465
Directory.CreateDirectory(dynamicDirectory);
5566
Directory.CreateDirectory(workingDirectory);
5667

57-
Logger.AddLoggersTemporarily(
58-
x => Debug.WriteLine($"[DEBUG] {x}"),
59-
x => Debug.WriteLine($"[INFO] {x}"),
60-
x => Debug.WriteLine($"[WARNING] {x}"),
61-
x => Debug.WriteLine($"[ERROR] {x}"));
62-
6368
var executeCore = new ExecuteCore(new TestFileSystem(), new TestEnvironment(), new NullLog());
6469

6570
var versionVariables = executeCore.ExecuteGitVersion(url, dynamicDirectory, null, targetBranch,

src/GitVersionCore/Configuration/Config.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using GitVersion.VersioningModes;
77
using YamlDotNet.Serialization;
88
using GitVersion.Extensions;
9-
using GitVersion.Helpers;
109

1110
namespace GitVersion.Configuration
1211
{
@@ -114,7 +113,8 @@ public BranchConfig GetConfigForBranch(string branchName)
114113
.Select(kvp => kvp.Value)
115114
.First();
116115

117-
Logger.Warning(
116+
// TODO check how to log this
117+
Console.WriteLine(
118118
$"Multiple branch configurations match the current branch branchName of '{branchName}'. " +
119119
$"Using the first matching configuration, '{picked}'. Matching configurations include: '{matchingConfigs}'");
120120

src/GitVersionCore/Configuration/ConfigurationProvider.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Text;
55
using GitVersion.Configuration.Init.Wizard;
6-
using GitVersion.Helpers;
76
using GitVersion.VersioningModes;
87
using GitVersion.Extensions;
98
using GitVersion.Common;
@@ -257,7 +256,7 @@ public static void Init(string workingDirectory, IFileSystem fileSystem, IConsol
257256
using (var stream = fileSystem.OpenWrite(configFilePath))
258257
using (var writer = new StreamWriter(stream))
259258
{
260-
Logger.Info("Saving config file");
259+
log.Info("Saving config file");
261260
ConfigSerialiser.Write(config, writer);
262261
stream.Flush();
263262
}

src/GitVersionCore/Extensions/VersionAssemblyInfoResources/AssemblyInfoFileUpdater.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.IO;
44
using System.Linq;
55
using System.Text.RegularExpressions;
6-
using GitVersion.Helpers;
76
using GitVersion.OutputVariables;
87
using GitVersion.Common;
98
using GitVersion.Log;
@@ -197,7 +196,7 @@ private bool EnsureVersionAssemblyInfoFile(bool ensureAssemblyInfo, IFileSystem
197196
return true;
198197
}
199198

200-
Logger.Warning($"No version assembly info template available to create source file '{fullPath}'");
199+
log.Warning($"No version assembly info template available to create source file '{fullPath}'");
201200
return false;
202201
}
203202

src/GitVersionCore/Helpers/Logger.cs

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static Logger()
1616

1717
private static Action<string> Debug { get; set; }
1818
public static Action<string> Info { get; private set; }
19-
public static Action<string> Warning { get; private set; }
19+
private static Action<string> Warning { get; set; }
2020
public static Action<string> Error { get; private set; }
2121

2222
public static void SetLoggers(Action<string> debug, Action<string> info, Action<string> warn, Action<string> error)
@@ -32,39 +32,6 @@ public static void SetLoggers(Action<string> debug, Action<string> info, Action<
3232
Error = LogMessage(ObscurePassword(error), "ERROR");
3333
}
3434

35-
public static IDisposable AddLoggersTemporarily(Action<string> debug, Action<string> info, Action<string> warn, Action<string> error)
36-
{
37-
var currentDebug = Debug;
38-
var currentInfo = Info;
39-
var currentWarn = Warning;
40-
var currentError = Error;
41-
SetLoggers(s =>
42-
{
43-
debug(s);
44-
currentDebug(s);
45-
}, s =>
46-
{
47-
info(s);
48-
currentInfo(s);
49-
}, s =>
50-
{
51-
warn(s);
52-
currentWarn(s);
53-
}, s =>
54-
{
55-
error(s);
56-
currentError(s);
57-
});
58-
59-
return new ActionDisposable(() =>
60-
{
61-
Debug = currentDebug;
62-
Info = currentInfo;
63-
Warning = currentWarn;
64-
Error = currentError;
65-
});
66-
}
67-
6835
private static Action<string> ObscurePassword(Action<string> info)
6936
{
7037
void LogAction(string s)
@@ -88,20 +55,5 @@ private static void Reset()
8855
Warning = s => throw new Exception("Warning logger not defined. Attempted to log: " + s);
8956
Error = s => throw new Exception("Error logger not defined. Attempted to log: " + s);
9057
}
91-
92-
private class ActionDisposable : IDisposable
93-
{
94-
private readonly Action action;
95-
96-
public ActionDisposable(Action action)
97-
{
98-
this.action = action;
99-
}
100-
101-
public void Dispose()
102-
{
103-
action();
104-
}
105-
}
10658
}
10759
}

src/GitVersionCore/SemanticVersionPreReleaseTag.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ public static SemanticVersionPreReleaseTag Parse(string preReleaseTag)
9595
var match = Regex.Match(preReleaseTag, @"(?<name>.*?)\.?(?<number>\d+)?$");
9696
if (!match.Success)
9797
{
98-
Logger.Warning($"Unable to successfully parse semver tag {preReleaseTag}");
98+
// TODO check how to log this
99+
Console.WriteLine($"Unable to successfully parse semver tag {preReleaseTag}");
99100
return new SemanticVersionPreReleaseTag();
100101
}
101102

0 commit comments

Comments
 (0)