~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/GuiException/UiException/ExceptionItem.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ****************************************************************
2
 
// This is free software licensed under the NUnit license. You may
3
 
// obtain a copy of the license at http://nunit.org
4
 
// ****************************************************************
5
 
 
6
 
using System;
7
 
using System.Collections.Generic;
8
 
using System.Text;
9
 
using System.IO;
10
 
 
11
 
namespace NUnit.UiException
12
 
{    
13
 
    /// <summary>
14
 
    /// (Formerly named ExceptionItem)
15
 
    /// 
16
 
    /// This is the output analysis of one error line coming from
17
 
    /// a stack trace that still gathers the same data but in more
18
 
    /// convenient way to be read from.
19
 
    ///   An ErrorItem represents one error with possible location
20
 
    /// informations such as:
21
 
    ///   - filename where the error has occured
22
 
    ///   - file's line number
23
 
    ///   - method name
24
 
    /// </summary>
25
 
    public class ErrorItem
26
 
    {
27
 
        /// <summary>
28
 
        /// An access path to the source file referred by this item.
29
 
        /// </summary>
30
 
        private string _path;
31
 
 
32
 
        /// <summary>
33
 
        /// The full qualified name of the member method referred by this item.
34
 
        /// </summary>
35
 
        private string _fullyQualifiedMethodName;
36
 
 
37
 
        /// <summary>
38
 
        /// The line index where the exception occured.
39
 
        /// </summary>
40
 
        private int _line;
41
 
 
42
 
        /// <summary>
43
 
        /// Store the content of the file pointed by _path.
44
 
        /// </summary>
45
 
        private string _text;
46
 
      
47
 
        /// <summary>
48
 
        /// Create an instance of ErrorItem that
49
 
        /// has source code attachments.
50
 
        /// </summary>
51
 
        public ErrorItem(string path, int lineNumber)
52
 
        {
53
 
            UiExceptionHelper.CheckNotNull(path, "path");
54
 
 
55
 
            _path = path;
56
 
            _line = lineNumber;
57
 
 
58
 
            return;
59
 
        }
60
 
 
61
 
        /// <summary>
62
 
        /// Create a new exception item.
63
 
        /// </summary>
64
 
        /// <param name="path">An absolute path to the source code file.</param>
65
 
        /// <param name="fullMethodName">A full qualified name of a member method.</param>
66
 
        /// <param name="lineNumber">A line index where the exception occured.</param>
67
 
        public ErrorItem(string path, string fullMethodName, int lineNumber)
68
 
        {
69
 
            _path = path;
70
 
            _fullyQualifiedMethodName = fullMethodName;
71
 
            _line = lineNumber;
72
 
 
73
 
            return;
74
 
        }
75
 
 
76
 
        /// <summary>
77
 
        /// Create an instance of ErrorItem that doesn't have
78
 
        /// any source code attachments.
79
 
        /// </summary>
80
 
        public ErrorItem()
81
 
        {
82
 
            // nothing to do
83
 
        }
84
 
 
85
 
        /// <summary>
86
 
        /// Reads and returns the part of Path that contains the filename
87
 
        /// of the source code file.
88
 
        /// </summary>
89
 
        public string FileName 
90
 
        {
91
 
            get { return (System.IO.Path.GetFileName(_path)); }
92
 
        }
93
 
 
94
 
        /// <summary>
95
 
        /// Gets the absolute path to the source code file.
96
 
        /// </summary>
97
 
        public string Path 
98
 
        {
99
 
            get { return (_path); }
100
 
        }
101
 
 
102
 
        /// <summary>
103
 
        /// Returns the file language - e.g.: the string after
104
 
        /// the last dot or null -
105
 
        /// </summary>
106
 
        public string FileExtension
107
 
        {
108
 
            get 
109
 
            {
110
 
                int dotIndex;
111
 
 
112
 
                if (_path == null)
113
 
                    return (null);
114
 
 
115
 
                dotIndex = _path.LastIndexOf(".", StringComparison.Ordinal);
116
 
                if (dotIndex > -1 && dotIndex < _path.Length - 1)
117
 
                    return (_path.Substring(dotIndex + 1));
118
 
 
119
 
                return (null); 
120
 
            }
121
 
        }
122
 
 
123
 
        /// <summary>
124
 
        /// Gets the full qualified name of the member method.
125
 
        /// </summary>
126
 
        public string FullyQualifiedMethodName
127
 
        {
128
 
            get { return (_fullyQualifiedMethodName); }
129
 
        }
130
 
 
131
 
        /// <summary>
132
 
        /// Reads and return the method part from the FullyQualifiedMethodName.
133
 
        /// The value contains the signature of the method.
134
 
        /// </summary>
135
 
        public string MethodName
136
 
        {
137
 
            get
138
 
            {
139
 
                int index;
140
 
 
141
 
                if (FullyQualifiedMethodName == null)
142
 
                    return ("");
143
 
 
144
 
                if ((index = FullyQualifiedMethodName.LastIndexOf(".", 
145
 
                            StringComparison.Ordinal)) == -1)
146
 
                    return (FullyQualifiedMethodName);
147
 
 
148
 
                return (FullyQualifiedMethodName.Substring(index + 1));
149
 
            }
150
 
        }
151
 
 
152
 
        /// <summary>
153
 
        /// Gets the method name without the argument list.
154
 
        /// </summary>
155
 
        public string BaseMethodName
156
 
        {
157
 
            get
158
 
            {
159
 
                string method = MethodName;
160
 
                int index = method.IndexOf("(", StringComparison.Ordinal);
161
 
 
162
 
                if (index > 0)
163
 
                    return (method.Substring(0, index));
164
 
 
165
 
                return (method);
166
 
            }
167
 
        }
168
 
 
169
 
        /// <summary>
170
 
        /// Reads and returns the class part from the FullyQualifiedMethodName.
171
 
        /// </summary>
172
 
        public string ClassName
173
 
        {
174
 
            get
175
 
            {
176
 
                int end_index;
177
 
                int start_index;
178
 
 
179
 
                if (FullyQualifiedMethodName == null)
180
 
                    return ("");
181
 
 
182
 
                if ((end_index = FullyQualifiedMethodName.LastIndexOf(".", 
183
 
                                StringComparison.Ordinal)) == -1)
184
 
                    return ("");
185
 
 
186
 
                start_index = end_index - 1;
187
 
                while (start_index > 0 && FullyQualifiedMethodName[start_index] != '.')
188
 
                    start_index--;
189
 
 
190
 
                if (start_index >= 0 && FullyQualifiedMethodName[start_index] == '.')
191
 
                    start_index++;
192
 
 
193
 
                return (FullyQualifiedMethodName.Substring(start_index, end_index - start_index));
194
 
            }
195
 
        }
196
 
 
197
 
        /// <summary>
198
 
        /// Gets the line number where the exception occured.
199
 
        /// </summary>
200
 
        public int LineNumber 
201
 
        {
202
 
            get { return (_line); }
203
 
        }
204
 
 
205
 
        /// <summary>
206
 
        /// Gets a boolean that says whether this item has source
207
 
        /// code localization attachments.
208
 
        /// </summary>
209
 
        public bool HasSourceAttachment {
210
 
            get { return (_path != null); }
211
 
        }
212
 
 
213
 
        /// <summary>
214
 
        /// Read and return the content of the underlying file. If the file
215
 
        /// cannot be found or read an exception is raised.
216
 
        /// </summary>
217
 
        public string ReadFile()
218
 
        {
219
 
            if (!System.IO.File.Exists(_path))
220
 
                throw new FileNotFoundException("File does not exist. File: " + _path);
221
 
 
222
 
            if (_text == null)
223
 
            {
224
 
                StreamReader rder = new StreamReader(_path);
225
 
                _text = rder.ReadToEnd();
226
 
                rder.Close();
227
 
            }
228
 
 
229
 
            return (_text);
230
 
        }
231
 
 
232
 
        public override string ToString() {
233
 
            return ("TraceItem: {'" + _path + "', " + _fullyQualifiedMethodName + ", " + _line + "}");
234
 
        }
235
 
 
236
 
        public override bool Equals(object obj)
237
 
        {
238
 
            ErrorItem item = obj as ErrorItem;
239
 
 
240
 
            if (item == null)
241
 
                return (false);
242
 
 
243
 
            return (_path == item._path &&
244
 
                    _fullyQualifiedMethodName == item._fullyQualifiedMethodName &&
245
 
                    _line == item._line);
246
 
        }
247
 
 
248
 
        public override int GetHashCode() {
249
 
            return base.GetHashCode();
250
 
        }
251
 
    }
252
 
}
 
1
// ****************************************************************
 
2
// This is free software licensed under the NUnit license. You may
 
3
// obtain a copy of the license at http://nunit.org
 
4
// ****************************************************************
 
5
 
 
6
using System;
 
7
using System.Collections.Generic;
 
8
using System.Text;
 
9
using System.IO;
 
10
 
 
11
namespace NUnit.UiException
 
12
{    
 
13
    /// <summary>
 
14
    /// (Formerly named ExceptionItem)
 
15
    /// 
 
16
    /// This is the output analysis of one error line coming from
 
17
    /// a stack trace that still gathers the same data but in more
 
18
    /// convenient way to be read from.
 
19
    ///   An ErrorItem represents one error with possible location
 
20
    /// informations such as:
 
21
    ///   - filename where the error has occured
 
22
    ///   - file's line number
 
23
    ///   - method name
 
24
    /// </summary>
 
25
    public class ErrorItem
 
26
    {
 
27
        /// <summary>
 
28
        /// An access path to the source file referred by this item.
 
29
        /// </summary>
 
30
        private string _path;
 
31
 
 
32
        /// <summary>
 
33
        /// The full qualified name of the member method referred by this item.
 
34
        /// </summary>
 
35
        private string _fullyQualifiedMethodName;
 
36
 
 
37
        /// <summary>
 
38
        /// The line index where the exception occured.
 
39
        /// </summary>
 
40
        private int _line;
 
41
 
 
42
        /// <summary>
 
43
        /// Store the content of the file pointed by _path.
 
44
        /// </summary>
 
45
        private string _text;
 
46
      
 
47
        /// <summary>
 
48
        /// Create an instance of ErrorItem that
 
49
        /// has source code attachments.
 
50
        /// </summary>
 
51
        public ErrorItem(string path, int lineNumber)
 
52
        {
 
53
            UiExceptionHelper.CheckNotNull(path, "path");
 
54
 
 
55
            _path = path;
 
56
            _line = lineNumber;
 
57
 
 
58
            return;
 
59
        }
 
60
 
 
61
        /// <summary>
 
62
        /// Create a new exception item.
 
63
        /// </summary>
 
64
        /// <param name="path">An absolute path to the source code file.</param>
 
65
        /// <param name="fullMethodName">A full qualified name of a member method.</param>
 
66
        /// <param name="lineNumber">A line index where the exception occured.</param>
 
67
        public ErrorItem(string path, string fullMethodName, int lineNumber)
 
68
        {
 
69
            _path = path;
 
70
            _fullyQualifiedMethodName = fullMethodName;
 
71
            _line = lineNumber;
 
72
 
 
73
            return;
 
74
        }
 
75
 
 
76
        /// <summary>
 
77
        /// Create an instance of ErrorItem that doesn't have
 
78
        /// any source code attachments.
 
79
        /// </summary>
 
80
        public ErrorItem()
 
81
        {
 
82
            // nothing to do
 
83
        }
 
84
 
 
85
        /// <summary>
 
86
        /// Reads and returns the part of Path that contains the filename
 
87
        /// of the source code file.
 
88
        /// </summary>
 
89
        public string FileName 
 
90
        {
 
91
            get { return (System.IO.Path.GetFileName(_path)); }
 
92
        }
 
93
 
 
94
        /// <summary>
 
95
        /// Gets the absolute path to the source code file.
 
96
        /// </summary>
 
97
        public string Path 
 
98
        {
 
99
            get { return (_path); }
 
100
        }
 
101
 
 
102
        /// <summary>
 
103
        /// Returns the file language - e.g.: the string after
 
104
        /// the last dot or null -
 
105
        /// </summary>
 
106
        public string FileExtension
 
107
        {
 
108
            get 
 
109
            {
 
110
                int dotIndex;
 
111
 
 
112
                if (_path == null)
 
113
                    return (null);
 
114
 
 
115
                dotIndex = _path.LastIndexOf(".", StringComparison.Ordinal);
 
116
                if (dotIndex > -1 && dotIndex < _path.Length - 1)
 
117
                    return (_path.Substring(dotIndex + 1));
 
118
 
 
119
                return (null); 
 
120
            }
 
121
        }
 
122
 
 
123
        /// <summary>
 
124
        /// Gets the full qualified name of the member method.
 
125
        /// </summary>
 
126
        public string FullyQualifiedMethodName
 
127
        {
 
128
            get { return (_fullyQualifiedMethodName); }
 
129
        }
 
130
 
 
131
        /// <summary>
 
132
        /// Reads and return the method part from the FullyQualifiedMethodName.
 
133
        /// The value contains the signature of the method.
 
134
        /// </summary>
 
135
        public string MethodName
 
136
        {
 
137
            get
 
138
            {
 
139
                int index;
 
140
 
 
141
                if (FullyQualifiedMethodName == null)
 
142
                    return ("");
 
143
 
 
144
                if ((index = FullyQualifiedMethodName.LastIndexOf(".", 
 
145
                            StringComparison.Ordinal)) == -1)
 
146
                    return (FullyQualifiedMethodName);
 
147
 
 
148
                return (FullyQualifiedMethodName.Substring(index + 1));
 
149
            }
 
150
        }
 
151
 
 
152
        /// <summary>
 
153
        /// Gets the method name without the argument list.
 
154
        /// </summary>
 
155
        public string BaseMethodName
 
156
        {
 
157
            get
 
158
            {
 
159
                string method = MethodName;
 
160
                int index = method.IndexOf("(", StringComparison.Ordinal);
 
161
 
 
162
                if (index > 0)
 
163
                    return (method.Substring(0, index));
 
164
 
 
165
                return (method);
 
166
            }
 
167
        }
 
168
 
 
169
        /// <summary>
 
170
        /// Reads and returns the class part from the FullyQualifiedMethodName.
 
171
        /// </summary>
 
172
        public string ClassName
 
173
        {
 
174
            get
 
175
            {
 
176
                int end_index;
 
177
                int start_index;
 
178
 
 
179
                if (FullyQualifiedMethodName == null)
 
180
                    return ("");
 
181
 
 
182
                if ((end_index = FullyQualifiedMethodName.LastIndexOf(".", 
 
183
                                StringComparison.Ordinal)) == -1)
 
184
                    return ("");
 
185
 
 
186
                start_index = end_index - 1;
 
187
                while (start_index > 0 && FullyQualifiedMethodName[start_index] != '.')
 
188
                    start_index--;
 
189
 
 
190
                if (start_index >= 0 && FullyQualifiedMethodName[start_index] == '.')
 
191
                    start_index++;
 
192
 
 
193
                return (FullyQualifiedMethodName.Substring(start_index, end_index - start_index));
 
194
            }
 
195
        }
 
196
 
 
197
        /// <summary>
 
198
        /// Gets the line number where the exception occured.
 
199
        /// </summary>
 
200
        public int LineNumber 
 
201
        {
 
202
            get { return (_line); }
 
203
        }
 
204
 
 
205
        /// <summary>
 
206
        /// Gets a boolean that says whether this item has source
 
207
        /// code localization attachments.
 
208
        /// </summary>
 
209
        public bool HasSourceAttachment {
 
210
            get { return (_path != null); }
 
211
        }
 
212
 
 
213
        /// <summary>
 
214
        /// Read and return the content of the underlying file. If the file
 
215
        /// cannot be found or read an exception is raised.
 
216
        /// </summary>
 
217
        public string ReadFile()
 
218
        {
 
219
            if (!System.IO.File.Exists(_path))
 
220
                throw new FileNotFoundException("File does not exist. File: " + _path);
 
221
 
 
222
            if (_text == null)
 
223
            {
 
224
                StreamReader rder = new StreamReader(_path);
 
225
                _text = rder.ReadToEnd();
 
226
                rder.Close();
 
227
            }
 
228
 
 
229
            return (_text);
 
230
        }
 
231
 
 
232
        public override string ToString() {
 
233
            return ("TraceItem: {'" + _path + "', " + _fullyQualifiedMethodName + ", " + _line + "}");
 
234
        }
 
235
 
 
236
        public override bool Equals(object obj)
 
237
        {
 
238
            ErrorItem item = obj as ErrorItem;
 
239
 
 
240
            if (item == null)
 
241
                return (false);
 
242
 
 
243
            return (_path == item._path &&
 
244
                    _fullyQualifiedMethodName == item._fullyQualifiedMethodName &&
 
245
                    _line == item._line);
 
246
        }
 
247
 
 
248
        public override int GetHashCode() {
 
249
            return base.GetHashCode();
 
250
        }
 
251
    }
 
252
}