Example #1
0
        static int Main(string[] args)
        {
            CommandLineOptions options = new CommandLineOptions();

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                WriteHeader();
                Console.WriteLine(ex.Message, ex.OptionName);
                return ConsoleRunner.INVALID_ARG;
            }

            if (!options.NoHeader)
                WriteHeader();

            if (options.ShowHelp)
            {
                //Console.Write(options.HelpText);
                WriteHelpText(options);
                return ConsoleRunner.OK;
            }

            if (!options.Validate())
            {
                foreach (string message in options.ErrorMessages)
                    Console.Error.WriteLine(message);

                return ConsoleRunner.INVALID_ARG;
            }

            try
            {
                return new ConsoleRunner(options).Execute();
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
#if DEBUG
                Console.WriteLine(ex.StackTrace);
#endif
                return ConsoleRunner.FILE_NOT_FOUND;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return ConsoleRunner.UNEXPECTED_ERROR;
            }
            finally
            {
                if (options.WaitBeforeExit)
                {
                    Console.Out.WriteLine("\nPress any key to continue . . .");
                    Console.ReadKey(true);
                }
            }
        }
Example #2
0
        public static string CreateTestFilter(CommandLineOptions options)
        {
            TestFilterBuilder builder = new TestFilterBuilder();
            foreach (string testName in options.Tests)
                builder.Tests.Add(testName);

            // TODO: Support multiple include / exclude options

            if (options.Include != null)
                builder.Include.Add(options.Include);

            if (options.Exclude != null)
                builder.Exclude.Add(options.Exclude);

            return builder.GetFilterText();
        }
        public ConsoleRunner(CommandLineOptions commandlineOptions)
        {
            this.options = commandlineOptions;

            string assemblyPath = Path.GetFullPath(options.AssemblyName);
            AppDomain testDomain = AppDomain.CurrentDomain;
            if (options.RunInSeparateAppDomain)
                testDomain = CreateDomain(Path.GetDirectoryName(assemblyPath));

            var driverSettings = options.CreateDriverSettings();
            this.driver = new FrameworkDriver(assemblyPath, testDomain, driverSettings);

            this.workDirectory = options.WorkDirectory;
            if (this.workDirectory == null)
                this.workDirectory = Environment.CurrentDirectory;
            else if (!Directory.Exists(this.workDirectory))
                Directory.CreateDirectory(this.workDirectory);
        }
Example #4
0
 private static void WriteHelpText(CommandLineOptions options)
 {
     Console.WriteLine();
     Console.WriteLine("TEST-HARNESS [assemblyname] [options]");
     Console.WriteLine();
     Console.WriteLine("Runs or displays a set of NUnit framework tests contained in an assembly.");
     Console.WriteLine("The harness is not intended for general test execution, but is a tool used");
     Console.WriteLine("in the development of the framework to avoid any dependency on higher-level");
     Console.WriteLine("test runners like nunit-console or on the NUnit test engine.");
     Console.WriteLine();
     Console.WriteLine("Options:");
     Console.WriteLine();
     options.WriteOptionDescriptions(Console.Out);
     Console.WriteLine();
     Console.WriteLine("Description:");
     Console.WriteLine("      By default, this command runs the tests contained in the");
     Console.WriteLine("      assembly specified in the command line. Only one assembly");
     Console.WriteLine("      may be specified.");
     Console.WriteLine();
     Console.WriteLine("      If the --explore option is used, no tests are executed but");
     Console.WriteLine("      the XML description of the tests is displayed on the console");
     Console.WriteLine("      or saved in the file specified with the option.");
     Console.WriteLine();
     Console.WriteLine("      The --selftest option is equivalent to using test-harness.exe");
     Console.WriteLine("      as the assembly name. No assemblyname should be specified with");
     Console.WriteLine("      this option.");
     Console.WriteLine();
     Console.WriteLine("      When --help is used anything else on the command line is ignored.");
     Console.WriteLine();
 }
 public TestEventListener(CommandLineOptions options, TextWriter outWriter)
 {
     this.options = options;
     this.outWriter = outWriter; 
 }