public static int TestRunnerMain()

in isamunittests/IsamTestHelper.cs [1527:1675]


        public static int TestRunnerMain(params string[] args)
        {
            string testDllPath = null;
            Dictionary<string, string[]> arguments = new Dictionary<string, string[]>(args.Length - 1);

            char[] argumentSeparators = new[] { ':' };
            char[] valueSeparators = new[] { ',' };
            string[] emptyValues = new string[0];
            string previousArg = null;

            foreach (string s in args)
            {
                if (s.StartsWith("-") || s.StartsWith("/"))
                {
                    bool needToSetPreviousArg = false;
                    string[] parsed = s.Substring(1).Split(argumentSeparators, 2);
                    if (parsed.Length > 1)
                    {
                        arguments[parsed[0].ToLower()] = parsed[1].Split(valueSeparators);
                        if (string.IsNullOrEmpty(parsed[1]))
                        {
                            needToSetPreviousArg = true;
                        }
                    }
                    else
                    {
                        needToSetPreviousArg = true;
                    }

                    if (needToSetPreviousArg)
                    {
                        previousArg = parsed[0].ToLower();
                        arguments[previousArg] = emptyValues;
                        continue;
                    }
                }
                else
                {
                    if (string.IsNullOrEmpty(previousArg))
                    {
                        if (null != testDllPath)
                        {
                            Debug.WriteLine("Cannot specify multiple test DLLs");
                            return -1;
                        }

                        testDllPath = s;
                    }
                    else
                    {
                        arguments[previousArg] = s.Split(valueSeparators);
                    }
                }
                previousArg = null;
            }

            if (null == testDllPath)
            {
                PrintHelp();
                return -1;
            }

            try
            {
                var testRunner = new TestRunner(testDllPath);

                if (arguments.ContainsKey("help"))
                {
                    PrintHelp();
                }

                if (arguments.ContainsKey("list"))
                {
                    testRunner.ListTests();
                }

                if (arguments.ContainsKey("donotshuffle"))
                {
                    testRunner.ShuffleTests = false;
                }

                if (arguments.ContainsKey("donotcatch"))
                {
                    testRunner.CatchExceptions = false;
                }

                if (arguments.ContainsKey("priority"))
                {
                    foreach (string p in arguments["priority"])
                    {
                        int priority;
                        if (int.TryParse(p, out priority))
                        {
                            testRunner.RunTestsWithPriority(priority);
                        }
                        else
                        {
                            Debug.WriteLine("Unknown priority {0}", p);
                            return -1;
                        }
                    }
                }

                if (arguments.ContainsKey("suite"))
                {
                    foreach (string suite in arguments["suite"])
                    {
                        if (testRunner.RunTestsInClass(suite) < 1)
                        {
                            Debug.WriteLine("No tests found in suite {0} or suite not found", suite);
                            return -1;
                        }
                    }
                }

                if (arguments.ContainsKey("test"))
                {
                    foreach (string test in arguments["test"])
                    {
                        if (testRunner.RunTestsWithName(test) < 1)
                        {
                            Debug.WriteLine("Test {0} not found", test);
                            return -1;
                        }
                    }
                }

                if (arguments.ContainsKey("all"))
                {
                    testRunner.RunTests();
                }

                if (testRunner.HasFailures)
                {
                    return -1;
                }
            }
            catch (ReflectionTypeLoadException ex)
            {
                foreach (Exception loaderException in ex.LoaderExceptions)
                {
                    Debug.WriteLine(loaderException.Message);
                }

                throw;
            }

            return 0;
        }