Skip to content

Commit 467fbd0

Browse files
committed
Introduce RequiresDotNetOrMonoGreaterThanOrEqualTo() helper
1 parent afc3d6e commit 467fbd0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.IO;
66
using System.Linq;
7+
using System.Reflection;
78
using System.Text;
89
using System.Text.RegularExpressions;
910
using LibGit2Sharp.Core;
@@ -172,6 +173,42 @@ protected static void InconclusiveIf(Func<bool> predicate, string message)
172173
throw new SkipException(message);
173174
}
174175

176+
protected void RequiresDotNetOrMonoGreaterThanOrEqualTo(Version minimumVersion)
177+
{
178+
Type type = Type.GetType("Mono.Runtime");
179+
180+
if (type == null)
181+
{
182+
// We're running on top of .Net
183+
return;
184+
}
185+
186+
MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
187+
188+
if (displayName == null)
189+
{
190+
throw new InvalidOperationException("Cannot access Mono.RunTime.GetDisplayName() method.");
191+
}
192+
193+
var version = (string) displayName.Invoke(null, null);
194+
195+
Version current;
196+
197+
try
198+
{
199+
current = new Version(version.Split(' ')[0]);
200+
}
201+
catch (Exception e)
202+
{
203+
throw new Exception(string.Format("Cannot parse Mono version '{0}'.", version), e);
204+
}
205+
206+
InconclusiveIf(() => current < minimumVersion,
207+
string.Format(
208+
"Current Mono version is {0}. Minimum required version to run this test is {1}.",
209+
current, minimumVersion));
210+
}
211+
175212
protected static void AssertValueInConfigFile(string configFilePath, string regex)
176213
{
177214
var text = File.ReadAllText(configFilePath);

0 commit comments

Comments
 (0)