IronRuby.Tests.Driver.RunUnitTests C# (CSharp) Method

RunUnitTests() private method

private RunUnitTests ( List largs ) : int
largs List
return int
        private int RunUnitTests(List<string>/*!*/ largs) {

            _tests = new Tests(this);
            
            if (_displayList) {
                for (int i = 0; i < _tests.TestMethods.Length; i++) {
                    Console.WriteLine(_tests.TestMethods[i].Method.Name);
                }
                return -1;
            }

            // check whether there is a preselected case:
            IList<TestCase> selectedCases = new List<TestCase>();

            foreach (var m in _tests.TestMethods) {
                if (m.Method.IsDefined(typeof(RunAttribute), false)) {
                    AddTestCases(selectedCases, m);
                }
            }

            if (selectedCases.Count == 0 && largs.Count > 0) {
                foreach (var m in _tests.TestMethods) {
                    bool caseIsSpecified = largs.Contains(m.Method.Name);
                    if ((caseIsSpecified && !_excludeSelectedCases) || (!caseIsSpecified && _excludeSelectedCases)) {
                        AddTestCases(selectedCases, m);
                    }
                }
            } else if (selectedCases.Count > 0 && largs.Count > 0) {
                Console.WriteLine("Arguments overrided by Run attribute.");
            } else if (selectedCases.Count == 0 && largs.Count == 0) {
                foreach (var m in _tests.TestMethods) {
                    AddTestCases(selectedCases, m);
                }
            }

            foreach (TestCase testCase in selectedCases) {
                RunTestCase(testCase);
            }

            var failedCases = new List<string>();
            if (_failedAssertions.Count > 0) {
                for (int i = 0; i < _failedAssertions.Count; i++) {
                    string test = _failedAssertions[i].Item000;
                    StackFrame frame = _failedAssertions[i].Item001;
                    string message = _failedAssertions[i].Item002;
                    failedCases.Add(test);

                    Console.Error.WriteLine();
                    if (_partialTrust) {
                        ColorWrite(ConsoleColor.Red, "{0}) {1}", failedCases.Count, test);
                    } else {
                        ColorWrite(ConsoleColor.Red, "{0}) {1} {2} : {3}", failedCases.Count, test, frame.GetFileName(), frame.GetFileLineNumber());
                    }
                    Console.Error.WriteLine(message);
                }
            }

            if (_unexpectedExceptions.Count > 0) {
                for (int i = 0; i < _unexpectedExceptions.Count; i++) {
                    string test = _unexpectedExceptions[i].Item000;
                    Exception exception = _unexpectedExceptions[i].Item001;

                    Console.Error.WriteLine();
                    ColorWrite(ConsoleColor.Red, "{0}) {1} (unexpected exception)", failedCases.Count, test);
                    Console.Error.WriteLine(exception);
                    failedCases.Add(test);
                }
            }

            if (failedCases.Count == 0) {
                ColorWrite(ConsoleColor.Green, "PASSED");
            } else {
                Console.WriteLine();
                // TODO:
                if (!_partialTrust) { 
                    Console.Write("Repro: {0}", Environment.CommandLine);
                } else {
                    Console.Write("Repro: IronRuby.Tests.exe /partial{0}{1}", 
                        _noAdaptiveCompilation ? " /noadaptive" : "",
                        _isDebug ? " /debug" : "");
                }
                if (largs.Count == 0) {
                    Console.Write(" {0}", String.Join(" ", failedCases.ToArray()));
                }
                Console.WriteLine();
            }
            return failedCases.Count;
        }

Usage Example

Esempio n. 1
0
        public static int Run(List <string> /*!*/ args)
        {
            if (Thread.CurrentThread.CurrentCulture.ToString() != "en-US")
            {
                Console.WriteLine("Current culture: {0}", Thread.CurrentThread.CurrentCulture);
            }

            if (!ParseArguments(args))
            {
                return(-3);
            }

            int status = 0;

            if (_runTokenizerDriver)
            {
                TokenizerTestDriver driver = new TokenizerTestDriver((RubyContext)HostingHelpers.GetLanguageContext(Ruby.CreateEngine()));
                if (!driver.ParseArgs(args))
                {
                    return(-3);
                }

                status = driver.RunTests();
            }
            else
            {
                InitializeDomain();
                Driver driver = new Driver();

                if (Manual.TestCode.Trim().Length == 0)
                {
                    status = driver.RunUnitTests(args);
                }
                else
                {
                    driver.RunManualTest();

                    // for case the test is forgotten, this would fail the test suite:
                    status = -2;
                }
            }

            // return failure on bad filter (any real failures throw)
            return(status);
        }
All Usage Examples Of IronRuby.Tests.Driver::RunUnitTests