private void ConfigureOptions() { var parser = new OptionParser(s => ErrorMessages.Add(s)); // NOTE: The order in which patterns are added // determines the display order for the help. this.Add("test=", "Comma-separated list of {NAMES} of tests to run or explore. This option may be repeated.", v => ((List <string>)TestList).AddRange(TestNameParser.Parse(parser.RequiredValue(v, "--test")))); this.Add("testlist=", "File {PATH} containing a list of tests to run, one per line. This option may be repeated.", v => { string testListFile = parser.RequiredValue(v, "--testlist"); var fullTestListPath = ExpandToFullPath(testListFile); if (!File.Exists(fullTestListPath)) { ErrorMessages.Add("Unable to locate file: " + testListFile); } else { try { using (var rdr = new StreamReader(fullTestListPath)) { while (!rdr.EndOfStream) { var line = rdr.ReadLine().Trim(); if (!string.IsNullOrEmpty(line) && line[0] != '#') { ((List <string>)TestList).Add(line); } } } } catch (IOException) { ErrorMessages.Add("Unable to read file: " + testListFile); } } }); this.Add("where=", "Test selection {EXPRESSION} indicating what tests will be run. See description below.", v => WhereClause = parser.RequiredValue(v, "--where")); this.Add("params|p=", "Deprecated and will be removed in a future release. Please use --testparam instead.", v => { const string deprecationWarning = "--params is deprecated and will be removed in a future release. Please use --testparam instead."; if (!WarningMessages.Contains(deprecationWarning)) { WarningMessages.Add(deprecationWarning); } string parameters = parser.RequiredValue(v, "--params"); foreach (string param in parameters.Split(new[] { ';' })) { var valuePair = parser.RequiredKeyValue(param); if (valuePair.HasValue) { TestParameters[valuePair.Value.Key] = valuePair.Value.Value; } } }); this.Add("testparam|tp=", "Followed by a key-value pair separated by an equals sign. Test code can access the value by name.", v => { var valuePair = parser.RequiredKeyValue(parser.RequiredValue(v, "--testparam")); if (valuePair.HasValue) { TestParameters[valuePair.Value.Key] = valuePair.Value.Value; } }); this.Add("timeout=", "Set timeout for each test case in {MILLISECONDS}.", v => DefaultTimeout = parser.RequiredInt(v, "--timeout")); this.Add("seed=", "Set the random {SEED} used to generate test cases.", v => RandomSeed = parser.RequiredInt(v, "--seed")); this.Add("workers=", "Specify the {NUMBER} of worker threads to be used in running tests. If not specified, defaults to 2 or the number of processors, whichever is greater.", v => NumberOfTestWorkers = parser.RequiredInt(v, "--workers")); this.Add("stoponerror", "Stop run immediately upon any test failure or error.", v => StopOnError = v != null); this.Add("wait", "Wait for input before closing console window.", v => WaitBeforeExit = v != null); // Output Control this.Add("work=", "{PATH} of the directory to use for output files. If not specified, defaults to the current directory.", v => workDirectory = parser.RequiredValue(v, "--work")); this.Add("output|out=", "File {PATH} to contain text output from the tests.", v => OutFile = parser.RequiredValue(v, "--output")); this.Add("result=", "An output {SPEC} for saving the test results.\nThis option may be repeated.", v => { var spec = parser.ResolveOutputSpecification(parser.RequiredValue(v, "--resultxml"), resultOutputSpecifications, _fileSystem, CURRENT_DIRECTORY_ON_ENTRY); if (spec != null) { resultOutputSpecifications.Add(spec); } }); this.Add("explore:", "Display or save test info rather than running tests. Optionally provide an output {SPEC} for saving the test info. This option may be repeated.", v => { Explore = true; var spec = parser.ResolveOutputSpecification(v, ExploreOutputSpecifications, _fileSystem, CURRENT_DIRECTORY_ON_ENTRY); if (spec != null) { ExploreOutputSpecifications.Add(spec); } }); this.Add("noresult", "Don't save any test results.", v => noresult = v != null); this.Add("labels=", "Specify whether to write test case names to the output. Values: Off, On, Before, After, BeforeAndAfter, All", v => DisplayTestLabels = parser.RequiredValue(v, "--labels", "Off", "On", "Before", "After", "BeforeAndAfter", "All")); this.Add("test-name-format=", "Non-standard naming pattern to use in generating test names.", v => DefaultTestNamePattern = parser.RequiredValue(v, "--test-name-format")); this.Add("trace=", "Set internal trace {LEVEL}.\nValues: Off, Error, Warning, Info, Verbose (Debug)", v => InternalTraceLevel = parser.RequiredValue(v, "--trace", "Off", "Error", "Warning", "Info", "Verbose", "Debug")); this.Add("teamcity", "Turns on use of TeamCity service messages. TeamCity engine extension is required.", v => TeamCity = v != null); this.Add("noheader|noh", "Suppress display of program information at start of run.", v => NoHeader = v != null); this.Add("nocolor|noc", "Displays console output without color.", v => NoColor = v != null); this.Add("help|h", "Display this message and exit.", v => ShowHelp = v != null); this.Add("version|V", "Display the header and exit.", v => ShowVersion = v != null); this.Add("encoding=", "Specifies the encoding to use for Console standard output, for example utf-8, ascii, unicode.", v => ConsoleEncoding = parser.RequiredValue(v, "--encoding")); // Default this.Add("<>", v => { if (v.StartsWith("-") || v.StartsWith("/") && Path.DirectorySeparatorChar != '/') { ErrorMessages.Add("Invalid argument: " + v); } else { InputFiles.Add(v); } }); this.Add("config=", "{NAME} of a project configuration to load (e.g.: Debug).", v => ActiveConfig = parser.RequiredValue(v, "--config")); this.AddNetFxOnlyOption("configfile=", "{NAME} of configuration file to use for this run.", NetFxOnlyOption("configfile=", v => ConfigurationFile = parser.RequiredValue(v, "--configfile"))); // Where to Run Tests this.AddNetFxOnlyOption("process=", "{PROCESS} isolation for test assemblies.\nValues: InProcess, Separate, Multiple. If not specified, defaults to Separate for a single assembly or Multiple for more than one.", NetFxOnlyOption("process=", v => { ProcessModel = parser.RequiredValue(v, "--process", "Single", "InProcess", "Separate", "Multiple"); // Change so it displays correctly even though it isn't absolutely needed if (ProcessModel.ToLower() == "single") { ProcessModel = "InProcess"; } })); this.AddNetFxOnlyOption("inprocess", "Synonym for --process:InProcess", NetFxOnlyOption("inprocess", v => ProcessModel = "InProcess")); this.AddNetFxOnlyOption("domain=", "{DOMAIN} isolation for test assemblies.\nValues: None, Single, Multiple. If not specified, defaults to Single for a single assembly or Multiple for more than one.", NetFxOnlyOption("domain=", v => DomainUsage = parser.RequiredValue(v, "--domain", "None", "Single", "Multiple"))); // How to Run Tests this.AddNetFxOnlyOption("framework=", "{FRAMEWORK} type/version to use for tests.\nExamples: mono, net-3.5, v4.0, 2.0, mono-4.0. If not specified, tests will run under the framework they are compiled with.", NetFxOnlyOption("framework=", v => Framework = parser.RequiredValue(v, "--framework"))); this.AddNetFxOnlyOption("x86", "Run tests in an x86 process on 64 bit systems", NetFxOnlyOption("x86", v => RunAsX86 = v != null)); this.Add("dispose-runners", "Dispose each test runner after it has finished running its tests.", v => DisposeRunners = v != null); this.AddNetFxOnlyOption("shadowcopy", "Shadow copy test files", NetFxOnlyOption("shadowcopy", v => ShadowCopyFiles = v != null)); this.AddNetFxOnlyOption("loaduserprofile", "Load user profile in test runner processes", NetFxOnlyOption("loaduserprofile", v => LoadUserProfile = v != null)); this.Add("skipnontestassemblies", "Skip any non-test assemblies specified, without error.", v => SkipNonTestAssemblies = v != null); this.AddNetFxOnlyOption("agents=", "Specify the maximum {NUMBER} of test assembly agents to run at one time. If not specified, there is no limit.", NetFxOnlyOption("agents=", v => _maxAgents = parser.RequiredInt(v, "--agents"))); this.AddNetFxOnlyOption("debug", "Launch debugger to debug tests.", NetFxOnlyOption("debug", v => DebugTests = v != null)); this.AddNetFxOnlyOption("pause", "Pause before running to allow attaching a debugger.", NetFxOnlyOption("pause", v => PauseBeforeRun = v != null)); this.Add("list-extensions", "List all extension points and the extensions for each.", v => ListExtensions = v != null); this.AddNetFxOnlyOption("set-principal-policy=", "Set PrincipalPolicy for the test domain.", NetFxOnlyOption("set-principal-policy=", v => PrincipalPolicy = parser.RequiredValue(v, "--set-principal-policy", "UnauthenticatedPrincipal", "NoPrincipal", "WindowsPrincipal"))); #if DEBUG this.AddNetFxOnlyOption("debug-agent", "Launch debugger in nunit-agent when it starts.", NetFxOnlyOption("debug-agent", v => DebugAgent = v != null)); #endif }