PageRenderTime 41ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/util/StackTraceFilter.cs

#
C# | 63 lines | 48 code | 7 blank | 8 comment | 7 complexity | 56113aa0aaafebe1f581cdc733a1fb9c MD5 | raw file
Possible License(s): GPL-2.0
  1. // ****************************************************************
  2. // This is free software licensed under the NUnit license. You
  3. // may obtain a copy of the license as well as information regarding
  4. // copyright ownership at http://nunit.org.
  5. // ****************************************************************
  6. namespace NUnit.Util
  7. {
  8. using System;
  9. using System.IO;
  10. /// <summary>
  11. /// Summary description for StackTraceFilter.
  12. /// </summary>
  13. public class StackTraceFilter
  14. {
  15. public static string Filter(string stack)
  16. {
  17. if(stack == null) return null;
  18. StringWriter sw = new StringWriter();
  19. StringReader sr = new StringReader(stack);
  20. try
  21. {
  22. string line;
  23. while ((line = sr.ReadLine()) != null)
  24. {
  25. if (!FilterLine(line))
  26. sw.WriteLine(line.Trim());
  27. }
  28. }
  29. catch (Exception)
  30. {
  31. return stack;
  32. }
  33. return sw.ToString();
  34. }
  35. static bool FilterLine(string line)
  36. {
  37. string[] patterns = new string[]
  38. {
  39. "NUnit.Core.TestCase",
  40. "NUnit.Core.ExpectedExceptionTestCase",
  41. "NUnit.Core.TemplateTestCase",
  42. "NUnit.Core.TestResult",
  43. "NUnit.Core.TestSuite",
  44. "NUnit.Framework.Assertion",
  45. "NUnit.Framework.Assert",
  46. "System.Reflection.MonoMethod"
  47. };
  48. for (int i = 0; i < patterns.Length; i++)
  49. {
  50. if (line.IndexOf(patterns[i]) > 0)
  51. return true;
  52. }
  53. return false;
  54. }
  55. }
  56. }