~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/BackendBindings/Ruby/RubyBinding/Project/Src/RubyTestResult.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using ICSharpCode.SharpDevelop.Dom;
 
6
using System.Text.RegularExpressions;
 
7
using ICSharpCode.UnitTesting;
 
8
 
 
9
namespace ICSharpCode.RubyBinding
 
10
{
 
11
        public class RubyTestResult : TestResult
 
12
        {
 
13
                public RubyTestResult(TestResult testResult)
 
14
                        : base(testResult.Name)
 
15
                {
 
16
                        ResultType = testResult.ResultType;
 
17
                        Message = testResult.Message;
 
18
                        StackTrace = testResult.StackTrace;
 
19
                }
 
20
                
 
21
                protected override void OnStackTraceChanged()
 
22
                {
 
23
                        if (String.IsNullOrEmpty(StackTrace)) {
 
24
                                ResetStackTraceFilePosition();
 
25
                        } else {
 
26
                                GetFilePositionFromStackTrace();
 
27
                        }
 
28
                }
 
29
                
 
30
                void ResetStackTraceFilePosition()
 
31
                {
 
32
                        StackTraceFilePosition = FilePosition.Empty;
 
33
                }
 
34
                
 
35
                /// <summary>
 
36
                /// Stack trace: Failure:
 
37
                /// test_fail(SecondTests)
 
38
                ///     [d:\temp\test\rubytests\SecondTests.rb:6:in `test_fail'
 
39
                ///      d:\temp\test\rubytests/sdtestrunner.rb:73:in `start_mediator'
 
40
                ///      d:\temp\test\rubytests/sdtestrunner.rb:47:in `start']:
 
41
                /// Assertion was false.
 
42
                /// <false> is not true.
 
43
                /// </summary>
 
44
                void GetFilePositionFromStackTrace()
 
45
                {
 
46
                        Match match = Regex.Match(StackTrace, "\\s\\[(.*?):(\\d+):", RegexOptions.Multiline);
 
47
                        if (match.Success) {
 
48
                                try {
 
49
                                        SetStackTraceFilePosition(match.Groups);
 
50
                                } catch (OverflowException) {
 
51
                                        // Ignore.
 
52
                                }
 
53
                        }
 
54
                }
 
55
                
 
56
                void SetStackTraceFilePosition(GroupCollection groups)
 
57
                {
 
58
                        string fileName = groups[1].Value;
 
59
                        int line = Convert.ToInt32(groups[2].Value);
 
60
                        int column = 1;
 
61
                        
 
62
                        StackTraceFilePosition = new FilePosition(fileName, line, column);
 
63
                }
 
64
        }
 
65
}