File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
LibGit2Sharp.Tests/TestHelpers Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 44using System . Globalization ;
55using System . IO ;
66using System . Linq ;
7+ using System . Reflection ;
78using System . Text ;
89using System . Text . RegularExpressions ;
910using 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 ) ;
You can’t perform that action at this time.
0 commit comments