~nunit-core/nunitv2/2.5

« back to all changes in this revision

Viewing changes to src/NUnitFramework/core/StackTraceFilter.cs

  • Committer: jnewkirk
  • Date: 2002-07-10 20:00:13 UTC
  • Revision ID: vcs-imports@canonical.com-20020710200013-j8us5mbi0usp7p02
initialĀ load

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Copyright (C) 2002. James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. All Rights Reserved.
 
3
//
 
4
namespace Nunit.Core
 
5
{
 
6
        using System;
 
7
        using System.IO;
 
8
 
 
9
        /// <summary>
 
10
        /// Summary description for StackTraceFilter.
 
11
        /// </summary>
 
12
        public class StackTraceFilter
 
13
        {
 
14
                public static string Filter(string stack) 
 
15
                {
 
16
                        if(stack == null) return null;
 
17
                        StringWriter sw = new StringWriter();
 
18
                        StringReader sr = new StringReader(stack);
 
19
 
 
20
                        try 
 
21
                        {
 
22
                                string line;
 
23
                                while ((line = sr.ReadLine()) != null) 
 
24
                                {
 
25
                                        if (!FilterLine(line))
 
26
                                                sw.WriteLine(line);
 
27
                                }
 
28
                        } 
 
29
                        catch (Exception) 
 
30
                        {
 
31
                                return stack;
 
32
                        }
 
33
                        return sw.ToString();
 
34
                }
 
35
 
 
36
                static bool FilterLine(string line) 
 
37
                {
 
38
                        string[] patterns = new string[]
 
39
                        {
 
40
                                "Nunit.Core.TestCase",
 
41
                                "Nunit.Core.ExpectedExceptionTestCase",
 
42
                                "Nunit.Core.TemplateTestCase",
 
43
                                "Nunit.Core.TestResult",
 
44
                                "Nunit.Core.TestSuite",
 
45
                                "Nunit.Framework.Assertion" 
 
46
                        };
 
47
 
 
48
                        for (int i = 0; i < patterns.Length; i++) 
 
49
                        {
 
50
                                if (line.IndexOf(patterns[i]) > 0)
 
51
                                        return true;
 
52
                        }
 
53
 
 
54
                        return false;
 
55
                }
 
56
 
 
57
        }
 
58
}