public void ReportWarning(string s) { string location = null; #if !TSS_NO_STACK StackTrace callerStack = new StackTrace(true); StackFrame[] locationFrames = TestContext.GetFramesToReport(callerStack); location = locationFrames.Length == 0 ? TestLogger.GetLocationAsText(callerStack.GetFrames(), "\n") : TestLogger.GetLocationAsText(locationFrames, "\n"); Logger.WriteErrorToLog("Warning: " + s, ConsoleColor.Cyan); Logger.WriteErrorToLog(location, ConsoleColor.Yellow); #endif var t = new TestCaseInfo { TestCase = FullTestCaseName(null), Message = s, Parms = null, Location = location, StackTrace = null, RngSeed = CurRngSeed }; TestsWithWarnings.Add(t); }
internal void ReportTestFailure(bool testException, string assertName, Object[] parms) { if (!ReportErrors) { return; } string fullMsg; #if !TSS_NO_STACK StackTrace callerStack = null; #endif string fullTestCase = FullTestCaseName(assertName); string fullStackTrace = ""; if (!string.IsNullOrEmpty(assertName)) { if (FailedAssertions.ContainsKey(fullTestCase)) { FailedAssertions[fullTestCase]++; return; } FailedAssertions.Add(fullTestCase, 1); } if (testException) { Debug.Assert(parms.Length == 1); TestExceptionInfo ei = TestLogger.ParseException((Exception)parms[0]); fullMsg = ei.message; #if !TSS_NO_STACK callerStack = ei.callerStack; #endif fullStackTrace = ei.fullStack; parms = ConcatParams(CurTestPhaseParms, ei.cmdParms == null ? null : new object[] { ei.cmdParms }); } else { fullMsg = "Assertion " + assertName + " failed"; #if !TSS_NO_STACK callerStack = new StackTrace(true); fullStackTrace = TestLogger.GetLocationAsText(callerStack.GetFrames(), "\n"); parms = ConcatParams(parms, CurTestPhaseParms); #endif } string location = ""; #if !TSS_NO_STACK StackFrame[] locationFrames = GetFramesToReport(callerStack); location = locationFrames.Length == 0 ? fullStackTrace : TestLogger.GetLocationAsText(locationFrames, "\n"); #endif if (testException) { LastExceptionInfo = fullMsg + "\n\n" + location; } var t = new TestCaseInfo { TestCase = fullTestCase, Message = fullMsg, Parms = parms, Location = location, StackTrace = fullStackTrace, RngSeed = CurRngSeed, RepeatedFailures = 1 }; FailedTests.Add(t); int pos = fullMsg.IndexOf("Details:"); string msg; string details = ""; if (pos != -1) { msg = fullMsg.Substring(0, pos); details = fullMsg.Substring(pos) + "\n"; } else { msg = fullMsg + "\n"; } details += TestLogger.GetParamsList(parms, "\n"); Logger.ThreadSafePrint(msg, ConsoleColor.Red); Logger.ThreadSafePrint("To reproduce use option: -seed " + CurRngSeed + "\n", ConsoleColor.Gray); if (details != "") { Logger.ThreadSafePrint(details, ConsoleColor.DarkYellow); } Logger.ThreadSafePrint(location, ConsoleColor.Yellow); } // ReportTestFailure