Example #1
0
 public void TwoNames(string name1, string name2)
 {
     char[]   delims = new char[] { ' ', ',' };
     string[] names  = TestNameParser.Parse(name1 + "," + name2);
     Assert.That(names.Length, Is.EqualTo(2));
     Assert.That(names[0], Is.EqualTo(name1.Trim(delims)));
     Assert.That(names[1], Is.EqualTo(name2.Trim(delims)));
 }
Example #2
0
 public void TwoNames(string name1, string name2)
 {
     char[]   delims = new char[] { ' ', ',' };
     string[] names  = TestNameParser.Parse(name1 + "," + name2);
     Assert.AreEqual(2, names.Length);
     Assert.AreEqual(name1.Trim(delims), names[0]);
     Assert.AreEqual(name2.Trim(delims), names[1]);
 }
Example #3
0
 public void SingleName(string name)
 {
     string[] names = TestNameParser.Parse(name);
     Assert.AreEqual(1, names.Length);
     Assert.AreEqual(name.Trim(new char[] { ' ', ',' }), names[0]);
 }
Example #4
0
        public ConsoleOptions(params string[] args)
        {
            // NOTE: The order in which patterns are added
            // determines the display order for the help.

            // Old Options no longer supported:
            //   fixture
            //   xmlConsole
            //   noshadow
            //   nothread
            //   nodots

            // Options to be added:
            //   teamcity
            //   workers

            // Select Tests
            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(RequiredValue(v, "--test"))));

            this.Add("include=", "Test {CATEGORIES} to be included. May be a single category, a comma-separated list of categories or a category expression.",
                     v => Include = RequiredValue(v, "--include"));

            this.Add("exclude=", "Test {CATEGORIES} to be excluded. May be a single category, a comma-separated list of categories or a category expression.",
                     v => Exclude = RequiredValue(v, "--exclude"));

            this.Add("config=", "{NAME} of a project configuration to load (e.g.: Debug).",
                     v => ActiveConfig = RequiredValue(v, "--config"));

            // Where to Run Tests
            this.Add("process=", "{PROCESS} isolation for test assemblies.\nValues: Single, Separate, Multiple",
                     v => ProcessModel = RequiredValue(v, "--process", "Single", "Separate", "Multiple"));

            this.Add("domain=", "{DOMAIN} isolation for test assemblies.\nValues: None, Single, Multiple",
                     v => DomainUsage = RequiredValue(v, "--domain", "None", "Single", "Multiple"));

            // How to Run Tests
            this.Add("framework=", "{FRAMEWORK} type/version to use for tests.\nExamples: mono, net-3.5, v4.0, 2.0, mono-4.0",
                     v => Framework = RequiredValue(v, "--framework"));

            this.Add("x86", "Run tests in an x86 process on 64 bit systems",
                     v => RunAsX86 = v != null);

            this.Add("dispose-runners", "Dispose each test runner after it has finished running its tests.",
                     v => DisposeRunners = v != null);

            this.Add("timeout=", "Set timeout for each test case in {MILLISECONDS}.",
                     v => defaultTimeout = RequiredInt(v, "--timeout"));

            this.Add("seed=", "Set the random {SEED} used to generate test cases.",
                     v => randomSeed = RequiredInt(v, "--seed"));

            this.Add("workers=", "Specify the {NUMBER} of worker threads to be used in running tests.",
                     v => numWorkers = 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);

            this.Add("pause", "Pause before run to allow debugging.",
                     v => PauseBeforeRun = v != null);

            // Output Control
            this.Add("work=", "{PATH} of the directory to use for output files.",
                     v => WorkDirectory = RequiredValue(v, "--work"));

            this.Add("output|out=", "File {PATH} to contain text output from the tests.",
                     v => OutFile = RequiredValue(v, "--output"));

            this.Add("err=", "File {PATH} to contain error output from the tests.",
                     v => ErrFile = RequiredValue(v, "--err"));

            this.Add("result=", "An output {SPEC} for saving the test results.\nThis option may be repeated.",
                     v => resultOutputSpecifications.Add(new OutputSpecification(RequiredValue(v, "--resultxml"))));

            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;
                if (v != null)
                {
                    ExploreOutputSpecifications.Add(new OutputSpecification(v));
                }
            });

            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, All",
                     v => DisplayTestLabels = RequiredValue(v, "--labels", "Off", "On", "All"));

            this.Add("trace=", "Set internal trace {LEVEL}.\nValues: Off, Error, Warning, Info, Verbose (Debug)",
                     v => InternalTraceLevel = RequiredValue(v, "--trace", "Off", "Error", "Warning", "Info", "Verbose", "Debug"));

            this.Add("teamcity", "Turns on use of TeamCity service messages.",
                     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("verbose|v", "Display additional information as the test runs.",
                     v => Verbose = v != null);

            this.Add("help|h", "Display this message and exit.",
                     v => ShowHelp = v != null);

            // Default
            this.Add("<>", v =>
            {
                if (v.StartsWith("-") || v.StartsWith("/") && Path.DirectorySeparatorChar != '/')
                {
                    ErrorMessages.Add("Invalid argument: " + v);
                }
                else
                {
                    InputFiles.Add(v);
                }
            });

            if (args != null)
            {
                this.Parse(args);
            }
        }
        void ConfigureOptions()
        {
            // NOTE: The order in which patterns are added
            // determines the display order for the help.

            // Select Tests
            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(RequiredValue(v, "--test"))));

            this.Add("where=", "Test selection {EXPRESSION} indicating what tests will be run. See description below.",
                     v => WhereClause = RequiredValue(v, "--where"));

            this.Add("timeout=", "Set timeout for each test case in {MILLISECONDS}.",
                     v => DefaultTimeout = RequiredInt(v, "--timeout"));

            this.Add("seed=", "Set the random {SEED} used to generate test cases.",
                     v => RandomSeed = RequiredInt(v, "--seed"));
#if false
            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 => numWorkers = RequiredInt(v, "--workers"));
#endif
            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 = RequiredValue(v, "--work"));

            this.Add("output|out=", "File {PATH} to contain text output from the tests.",
                     v => OutFile = RequiredValue(v, "--output"));

            this.Add("err=", "File {PATH} to contain error output from the tests.",
                     v => ErrFile = RequiredValue(v, "--err"));

            this.Add("full", "Prints full report of all test results.",
                     v => Full = v != null);

            this.Add("result=", "An output {SPEC} for saving the test results.\nThis option may be repeated.",
                     v => resultOutputSpecifications.Add(new OutputSpecification(RequiredValue(v, "--resultxml"))));

            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;
                if (v != null)
                {
                    ExploreOutputSpecifications.Add(new OutputSpecification(v));
                }
            });

            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, All",
                     v => DisplayTestLabels = RequiredValue(v, "--labels", "Off", "On", "All"));

            this.Add("trace=", "Set internal trace {LEVEL}.\nValues: Off, Error, Warning, Info, Verbose (Debug)",
                     v => InternalTraceLevel = RequiredValue(v, "--trace", "Off", "Error", "Warning", "Info", "Verbose", "Debug"));

            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("verbose|v", "Display additional information as the test runs.",
                     v => Verbose = 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);

#if NET451
            this.Add("debug", "Attaches the debugger on launch",
                     v => Debug = v != null);
#endif

            // .NET Core runner options
            this.Add("designtime", "Used to indicate that the runner is being launched by an IDE",
                     v => DesignTime = v != null);

            this.Add("port=", "Used by IDEs to specify a port number to listen for a connection",
                     v => Port = RequiredInt(v, "--port"));

            this.Add("wait-command", "Used by IDEs to indicate that the runner should connect to the port and wait for commands, instead of going ahead and executing the tests",
                     v => WaitCommand = v != null);

            this.Add("list", "Used by IDEs to request a list of tests that can be run",
                     v => List = v != null);

            this.Add("parentProcessId", "Used by IDEs to indicate the Parent PID",
                     v => ParentProcessId = RequiredInt(v, "--parentProcessId"));

            // Default
            this.Add("<>", v =>
            {
                if (v.StartsWith("-", StringComparison.Ordinal) || v.StartsWith("/", StringComparison.Ordinal) && Path.DirectorySeparatorChar != '/')
                {
                    ErrorMessages.Add("Invalid argument: " + v);
                }
                else
                {
                    InputFiles.Add(v);
                }
            });
        }
        internal static bool CreateTestFilter(ConsoleOptions options, out TestFilter testFilter)
        {
            testFilter = TestFilter.Empty;

            SimpleNameFilter nameFilter = new SimpleNameFilter();

            if (options.run != null && options.run != string.Empty)
            {
                Console.WriteLine("Selected test(s): " + options.run);

                foreach (string name in TestNameParser.Parse(options.run))
                {
                    nameFilter.Add(name);
                }

                testFilter = nameFilter;
            }

            if (options.runlist != null && options.runlist != string.Empty)
            {
                Console.WriteLine("Run list: " + options.runlist);

                try
                {
                    using (StreamReader rdr = new StreamReader(options.runlist))
                    {
                        // NOTE: We can't use rdr.EndOfStream because it's
                        // not present in .NET 1.x.
                        string line = rdr.ReadLine();
                        while (line != null && line.Length > 0)
                        {
                            if (line[0] != '#')
                            {
                                nameFilter.Add(line);
                            }
                            line = rdr.ReadLine();
                        }
                    }
                }
                catch (Exception e)
                {
                    if (e is FileNotFoundException || e is DirectoryNotFoundException)
                    {
                        Console.WriteLine("Unable to locate file: " + options.runlist);
                        return(false);
                    }
                    throw;
                }

                testFilter = nameFilter;
            }

            if (!string.IsNullOrEmpty(options.include))
            {
                TestFilter includeFilter = new CategoryExpression(options.include).Filter;
                Console.WriteLine("Included categories: " + includeFilter);

                if (testFilter.IsEmpty)
                {
                    testFilter = includeFilter;
                }
                else
                {
                    testFilter = new AndFilter(testFilter, includeFilter);
                }
            }

            if (!string.IsNullOrEmpty(options.exclude))
            {
                TestFilter excludeFilter = new NotFilter(new CategoryExpression(options.exclude).Filter);
                Console.WriteLine("Excluded categories: " + excludeFilter);

                if (testFilter.IsEmpty)
                {
                    testFilter = excludeFilter;
                }
                else if (testFilter is AndFilter)
                {
                    ((AndFilter)testFilter).Add(excludeFilter);
                }
                else
                {
                    testFilter = new AndFilter(testFilter, excludeFilter);
                }
            }

            if (testFilter is NotFilter)
            {
                ((NotFilter)testFilter).TopLevel = true;
            }

            return(true);
        }
Example #7
0
 public void SingleName(string name)
 {
     string[] names = TestNameParser.Parse(name);
     Assert.That(names.Length, Is.EqualTo(1));
     Assert.That(names[0], Is.EqualTo(name.Trim(new char[] { ' ', ',' })));
 }