Пример #1
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled, "Test cancelled by user", ex.StackTrace);
            }
            else if (ex is AssertionException)
            {
                SetResult(ResultState.Failure, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is IgnoreException)
            {
                SetResult(ResultState.Ignored, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is InconclusiveException)
            {
                SetResult(ResultState.Inconclusive, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is SuccessException)
            {
                SetResult(ResultState.Success, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else
            {
                SetResult(ResultState.Error,
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
Пример #2
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        /// <param name="site">THe FailureSite to use in the result</param>
        public void RecordException(Exception ex, FailureSite site)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

            if (ex is ResultStateException)
            {
                SetResult(((ResultStateException)ex).ResultState.WithSite(site),
                          ex.Message,
                          StackFilter.Filter(ex.StackTrace));
            }
#if !PORTABLE
            else if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled.WithSite(site),
                          "Test cancelled by user",
                          ex.StackTrace);
            }
#endif
            else
            {
                SetResult(ResultState.Error.WithSite(site),
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
Пример #3
0
        /// <summary>
        /// Set the test result based on the type of exception thrown
        /// </summary>
        /// <param name="ex">The exception that was thrown</param>
        public void RecordException(Exception ex)
        {
            if (ex is NUnitException)
            {
                ex = ex.InnerException;
            }

#if MONO
            exceptionType = ex?.GetType().ToString();
#endif

            if (ex is System.Threading.ThreadAbortException)
            {
                SetResult(ResultState.Cancelled, "Test cancelled by user", ex.StackTrace);
            }
            else if (ex is AssertionException)
            {
                SetResult(ResultState.Failure, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is IgnoreException)
            {
                SetResult(ResultState.Ignored, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is InconclusiveException)
            {
                SetResult(ResultState.Inconclusive, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else if (ex is SuccessException)
            {
                SetResult(ResultState.Success, ex.Message, StackFilter.Filter(ex.StackTrace));
            }
            else
            {
                MethodInfo write = null;
                if (Environment.GetEnvironmentVariable("MONO_TEST_TELEMETRY") != null)
                {
                    write = Type.GetType("Mono.Runtime", false).GetMethod("WriteStateToDisk", BindingFlags.NonPublic | BindingFlags.Static);
                }
                if (write != null)
                {
                    write.Invoke(null, new object [] { ex });
                }

                SetResult(ResultState.Error,
                          ExceptionHelper.BuildMessage(ex),
                          ExceptionHelper.BuildStackTrace(ex));
            }
        }
Пример #4
0
 public void FilterFailureTrace2()
 {
     Assert.That(StackFilter.Filter(rawTrace2), Is.EqualTo(filteredTrace2));
 }