diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-10-05 21:35:55 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-10-05 22:05:19 +0400 |
commit | 467fbd0ae68783a6f8d9437e8bbdec2d6129928a (patch) | |
tree | ea611b0f63ed9745e274b7855a3a8836e77f21e4 /LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | |
parent | afc3d6e99e969026c8ae364154b3765671362f92 (diff) |
Introduce RequiresDotNetOrMonoGreaterThanOrEqualTo() helper
Diffstat (limited to 'LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs')
-rw-r--r-- | LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs index 24abcd27..4d076806 100644 --- a/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs +++ b/LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs @@ -4,6 +4,7 @@ using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using System.Text.RegularExpressions; using LibGit2Sharp.Core; @@ -172,6 +173,42 @@ namespace LibGit2Sharp.Tests.TestHelpers 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); |