2016-05-26 16:06:52 +03:00
using System ;
using Mono.Options ;
namespace xharness
{
class MainClass
{
public static int Main ( string [ ] args )
{
var harness = new Harness ( ) ;
Action showHelp = null ;
var os = new OptionSet ( ) {
{ "h|?|help" , "Displays the help" , ( v ) = > showHelp ( ) } ,
{ "v|verbose" , "Show verbose output" , ( v ) = > harness . Verbosity + + } ,
2017-01-16 09:24:14 +03:00
{ "use-system:" , "Use the system version of Xamarin.iOS/Xamarin.Mac or the locally build version. Default: the locally build version." , ( v ) = > harness . UseSystem = v = = "1" | | v = = "true" | | string . IsNullOrEmpty ( v ) } ,
2016-05-26 16:06:52 +03:00
// Configure
{ "mac" , "Configure for Xamarin.Mac instead of iOS." , ( v ) = > harness . Mac = true } ,
{ "configure" , "Creates project files and makefiles." , ( v ) = > harness . Action = HarnessAction . Configure } ,
{ "autoconf" , "Automatically decide what to configure." , ( v ) = > harness . AutoConf = true } ,
{ "rootdir=" , "The root directory for the tests." , ( v ) = > harness . RootDirectory = v } ,
2017-09-22 19:04:32 +03:00
{ "project=" , "Add a project file to process. This can be specified multiple times." , ( v ) = > harness . IOSTestProjects . Add ( new iOSTestProject ( v ) ) } ,
2016-05-26 16:06:52 +03:00
{ "watchos-container-template=" , "The directory to use as a template for a watchos container app." , ( v ) = > harness . WatchOSContainerTemplate = v } ,
{ "watchos-app-template=" , "The directory to use as a template for a watchos app." , ( v ) = > harness . WatchOSAppTemplate = v } ,
// Run
{ "run=" , "Executes a project." , ( v ) = >
{
harness . Action = HarnessAction . Run ;
2017-09-22 19:04:32 +03:00
harness . IOSTestProjects . Add ( new iOSTestProject ( v ) ) ;
2016-05-26 16:06:52 +03:00
}
} ,
{ "install=" , "Installs a project." , ( v ) = >
{
harness . Action = HarnessAction . Install ;
2017-09-22 19:04:32 +03:00
harness . IOSTestProjects . Add ( new iOSTestProject ( v ) ) ;
2016-05-26 16:06:52 +03:00
}
} ,
2017-01-02 10:58:46 +03:00
{ "uninstall=" , "Uninstalls a project." , ( v ) = >
{
harness . Action = HarnessAction . Uninstall ;
2017-09-22 19:04:32 +03:00
harness . IOSTestProjects . Add ( new iOSTestProject ( v ) ) ;
2017-01-02 10:58:46 +03:00
}
} ,
2016-05-26 16:06:52 +03:00
{ "sdkroot=" , "Where Xcode is" , ( v ) = > harness . SdkRoot = v } ,
2018-08-04 00:06:23 +03:00
{ "sdkroot94=" , "Where Xcode 9.4 is" , ( v ) = > harness . SdkRoot94 = v } ,
2016-11-16 17:23:11 +03:00
{ "target=" , "Where to run the project ([ios|watchos|tvos]-[device|simulator|simulator-32|simulator-64])." , ( v ) = > harness . Target = v . ParseAsAppRunnerTarget ( ) } ,
2016-05-26 16:06:52 +03:00
{ "configuration=" , "Which configuration to run (defaults to Debug)." , ( v ) = > harness . Configuration = v } ,
2016-06-06 13:48:53 +03:00
{ "logdirectory=" , "Where to store logs." , ( v ) = > harness . LogDirectory = v } ,
2016-05-26 16:06:52 +03:00
{ "logfile=" , "Where to store the log." , ( v ) = > harness . LogFile = v } ,
{ "timeout=" , "Timeout for a test run (in minutes). Default is 10 minutes." , ( v ) = > harness . Timeout = double . Parse ( v ) } ,
2016-06-06 13:48:53 +03:00
{ "jenkins:" , "Execute test run for jenkins." , ( v ) = >
{
harness . JenkinsConfiguration = v ;
harness . Action = HarnessAction . Jenkins ;
}
} ,
{ "dry-run" , "Only print what would be done." , ( v ) = > harness . DryRun = true } ,
2016-08-05 23:28:13 +03:00
{ "setenv:" , "Set the specified environment variable when running apps." , ( v ) = >
{
var split = v . Split ( '=' ) ;
harness . EnvironmentVariables [ split [ 0 ] ] = split [ 1 ] ;
}
} ,
2017-08-03 15:31:02 +03:00
{ "label=" , "Comma-separated list of labels to select which tests to run." , ( v ) = >
{
harness . Labels . UnionWith ( v . Split ( new char [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries ) ) ;
}
} ,
2017-08-29 15:59:37 +03:00
{ "markdown-summary=" , "The path where a summary (in Markdown format) will be written." , ( v ) = > harness . MarkdownSummaryPath = v } ,
2017-11-22 18:03:36 +03:00
{ "periodic-command=" , "A command to execute periodically." , ( v ) = > harness . PeriodicCommand = v } ,
{ "periodic-command-arguments=" , "Arguments to the command to execute periodically." , ( v ) = > harness . PeriodicCommandArguments = v } ,
{ "periodic-interval=" , "An interval (in minutes) between every attempt to execute the periodic command." , ( v ) = > harness . PeriodicCommandInterval = TimeSpan . FromMinutes ( double . Parse ( v ) ) } ,
2017-11-28 21:16:46 +03:00
{ "include-system-permission-tests:" , "If tests that require system permissions (which could cause the OS to launch dialogs that hangs the test) should be executed or not. Default is to include such tests." , ( v ) = > harness . IncludeSystemPermissionTests = ParseBool ( v , "include-system-permission-tests" ) } ,
2016-05-26 16:06:52 +03:00
} ;
showHelp = ( ) = > {
os . WriteOptionDescriptions ( Console . Out ) ;
System . Environment . Exit ( 0 ) ;
} ;
var input = os . Parse ( args ) ;
if ( input . Count > 0 )
throw new Exception ( string . Format ( "Unknown arguments: {0}" , string . Join ( ", " , input . ToArray ( ) ) ) ) ;
if ( harness . Action = = HarnessAction . None )
showHelp ( ) ;
2016-12-24 18:55:51 +03:00
// XS sets this, which breaks pretty much everything if it doesn't match what was passed to --sdkroot.
Environment . SetEnvironmentVariable ( "XCODE_DEVELOPER_DIR_PATH" , null ) ;
2016-05-26 16:06:52 +03:00
return harness . Execute ( ) ;
}
2017-11-28 21:16:46 +03:00
internal static bool TryParseBool ( string value , out bool result )
{
if ( string . IsNullOrEmpty ( value ) ) {
result = true ;
return true ;
}
switch ( value . ToLowerInvariant ( ) ) {
case "1" :
case "yes" :
case "true" :
case "enable" :
result = true ;
return true ;
case "0" :
case "no" :
case "false" :
case "disable" :
result = false ;
return true ;
default :
return bool . TryParse ( value , out result ) ;
}
}
internal static bool ParseBool ( string value , string name , bool show_error = true )
{
bool result ;
if ( ! TryParseBool ( value , out result ) )
throw new Exception ( $"Could not parse the command line argument '-{name}:{value}'" ) ;
return result ;
}
2016-05-26 16:06:52 +03:00
}
}