PageRenderTime 23ms CodeModel.GetById 19ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/src/NUnit/util/StackTraceFilter.cs

#
C# | 63 lines | 48 code | 7 blank | 8 comment | 7 complexity | 56113aa0aaafebe1f581cdc733a1fb9c MD5 | raw file
 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
 7namespace NUnit.Util
 8{
 9	using System;
10	using System.IO;
11
12	/// <summary>
13	/// Summary description for StackTraceFilter.
14	/// </summary>
15	public class StackTraceFilter
16	{
17		public static string Filter(string stack) 
18		{
19			if(stack == null) return null;
20			StringWriter sw = new StringWriter();
21			StringReader sr = new StringReader(stack);
22
23			try 
24			{
25				string line;
26				while ((line = sr.ReadLine()) != null) 
27				{
28					if (!FilterLine(line))
29						sw.WriteLine(line.Trim());
30				}
31			} 
32			catch (Exception) 
33			{
34				return stack;
35			}
36			return sw.ToString();
37		}
38
39		static bool FilterLine(string line) 
40		{
41			string[] patterns = new string[]
42			{
43				"NUnit.Core.TestCase",
44				"NUnit.Core.ExpectedExceptionTestCase",
45				"NUnit.Core.TemplateTestCase",
46				"NUnit.Core.TestResult",
47				"NUnit.Core.TestSuite",
48				"NUnit.Framework.Assertion", 
49				"NUnit.Framework.Assert",
50                "System.Reflection.MonoMethod"
51			};
52
53			for (int i = 0; i < patterns.Length; i++) 
54			{
55				if (line.IndexOf(patterns[i]) > 0)
56					return true;
57			}
58
59			return false;
60		}
61
62	}
63}