/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
- // ****************************************************************
- // This is free software licensed under the NUnit license. You
- // may obtain a copy of the license as well as information regarding
- // copyright ownership at http://nunit.org.
- // ****************************************************************
-
- namespace NUnit.Util
- {
- using System;
- using System.IO;
-
- /// <summary>
- /// Summary description for StackTraceFilter.
- /// </summary>
- public class StackTraceFilter
- {
- public static string Filter(string stack)
- {
- if(stack == null) return null;
- StringWriter sw = new StringWriter();
- StringReader sr = new StringReader(stack);
-
- try
- {
- string line;
- while ((line = sr.ReadLine()) != null)
- {
- if (!FilterLine(line))
- sw.WriteLine(line.Trim());
- }
- }
- catch (Exception)
- {
- return stack;
- }
- return sw.ToString();
- }
-
- static bool FilterLine(string line)
- {
- string[] patterns = new string[]
- {
- "NUnit.Core.TestCase",
- "NUnit.Core.ExpectedExceptionTestCase",
- "NUnit.Core.TemplateTestCase",
- "NUnit.Core.TestResult",
- "NUnit.Core.TestSuite",
- "NUnit.Framework.Assertion",
- "NUnit.Framework.Assert",
- "System.Reflection.MonoMethod"
- };
-
- for (int i = 0; i < patterns.Length; i++)
- {
- if (line.IndexOf(patterns[i]) > 0)
- return true;
- }
-
- return false;
- }
-
- }
- }