1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System;
- using NUnit.Framework;
- using NUnit.Framework.Interfaces;
- using NUnit.Framework.Internal;
- namespace UnityEngine.TestRunner.NUnitExtensions
- {
- internal static class TestResultExtensions
- {
- public static void RecordPrefixedException(this TestResult testResult, string prefix, Exception ex, ResultState resultState = null)
- {
- if (ex is NUnitException)
- {
- ex = ex.InnerException;
- }
- if (resultState == null)
- {
- resultState = testResult.ResultState == ResultState.Cancelled
- ? ResultState.Cancelled
- : ResultState.Error;
- }
- var exceptionMessage = ExceptionHelper.BuildMessage(ex);
- string stackTrace = "--" + prefix + NUnit.Env.NewLine + ExceptionHelper.BuildStackTrace(ex);
- if (testResult.StackTrace != null)
- {
- stackTrace = testResult.StackTrace + NUnit.Env.NewLine + stackTrace;
- }
- if (testResult.Test.IsSuite)
- {
- resultState = resultState.WithSite(FailureSite.TearDown);
- }
- if (ex is ResultStateException)
- {
- exceptionMessage = ex.Message;
- resultState = ((ResultStateException)ex).ResultState;
- stackTrace = StackFilter.Filter(ex.StackTrace);
- }
- string message = (string.IsNullOrEmpty(prefix) ? "" : (prefix + " : ")) + exceptionMessage;
- if (testResult.Message != null)
- {
- message = testResult.Message + NUnit.Env.NewLine + message;
- }
- testResult.SetResult(resultState, message, stackTrace);
- }
- public static void RecordPrefixedError(this TestResult testResult, string prefix, string error, ResultState resultState = null)
- {
- if (resultState == null)
- {
- resultState = testResult.ResultState == ResultState.Cancelled
- ? ResultState.Cancelled
- : ResultState.Error;
- }
-
- if (testResult.Test.IsSuite)
- {
- resultState = resultState.WithSite(FailureSite.TearDown);
- }
- string message = (string.IsNullOrEmpty(prefix) ? "" : (prefix + " : ")) + error;
- if (testResult.Message != null)
- {
- message = testResult.Message + NUnit.Env.NewLine + message;
- }
- testResult.SetResult(resultState, message);
- }
- }
- }
|