Skip to content

Commit

Permalink
Introduce RequiresDotNetOrMonoGreaterThanOrEqualTo() helper
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Oct 5, 2013
1 parent afc3d6e commit 467fbd0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs
Expand Up @@ -4,6 +4,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using LibGit2Sharp.Core;
Expand Down Expand Up @@ -172,6 +173,42 @@ protected static void InconclusiveIf(Func<bool> predicate, string message)
throw new SkipException(message);
}

protected void RequiresDotNetOrMonoGreaterThanOrEqualTo(Version minimumVersion)
{
Type type = Type.GetType("Mono.Runtime");

if (type == null)
{
// We're running on top of .Net
return;
}

MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);

if (displayName == null)
{
throw new InvalidOperationException("Cannot access Mono.RunTime.GetDisplayName() method.");
}

var version = (string) displayName.Invoke(null, null);

Version current;

try
{
current = new Version(version.Split(' ')[0]);
}
catch (Exception e)
{
throw new Exception(string.Format("Cannot parse Mono version '{0}'.", version), e);
}

InconclusiveIf(() => current < minimumVersion,
string.Format(
"Current Mono version is {0}. Minimum required version to run this test is {1}.",
current, minimumVersion));
}

protected static void AssertValueInConfigFile(string configFilePath, string regex)
{
var text = File.ReadAllText(configFilePath);
Expand Down

0 comments on commit 467fbd0

Please sign in to comment.