-
-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathSentryStackFrameTests.cs
More file actions
329 lines (283 loc) · 9.05 KB
/
SentryStackFrameTests.cs
File metadata and controls
329 lines (283 loc) · 9.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
namespace Sentry.Tests.Protocol.Exceptions;
public class SentryStackFrameTests
{
private readonly IDiagnosticLogger _testOutputLogger;
public SentryStackFrameTests(ITestOutputHelper output)
{
_testOutputLogger = new TestOutputDiagnosticLogger(output);
}
[Fact]
public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
{
var sut = new SentryStackFrame
{
FileName = "FileName",
Function = "Function",
Module = "Module",
LineNumber = 1,
ColumnNumber = 2,
AbsolutePath = "AbsolutePath",
ContextLine = "ContextLine",
PreContext = { "pre" },
PostContext = { "post" },
InApp = true,
Vars = { { "var", "val" } },
FramesOmitted = { 1, 2 },
Package = "Package",
Platform = "Platform",
ImageAddress = 3,
SymbolAddress = 4,
InstructionAddress = 5,
AddressMode = "rel:0"
};
var actual = sut.ToJsonString(_testOutputLogger, indented: true);
Assert.Equal("""
{
"pre_context": [
"pre"
],
"post_context": [
"post"
],
"vars": {
"var": "val"
},
"frames_omitted": [
1,
2
],
"filename": "FileName",
"function": "Function",
"module": "Module",
"lineno": 1,
"colno": 2,
"abs_path": "AbsolutePath",
"context_line": "ContextLine",
"in_app": true,
"package": "Package",
"platform": "Platform",
"image_addr": "0x3",
"symbol_addr": "0x4",
"instruction_addr": "0x5",
"addr_mode": "rel:0"
}
""",
actual);
var parsed = Json.Parse(actual, SentryStackFrame.FromJson);
parsed.Should().BeEquivalentTo(sut);
}
[Fact]
public void PreContext_Getter_NotNull()
{
var sut = new SentryStackFrame();
Assert.NotNull(sut.PreContext);
}
[Fact]
public void PostContext_Getter_NotNull()
{
var sut = new SentryStackFrame();
Assert.NotNull(sut.PostContext);
}
[Fact]
public void Vars_Getter_NotNull()
{
var sut = new SentryStackFrame();
Assert.NotNull(sut.Vars);
}
[Fact]
public void FramesOmitted_Getter_NotNull()
{
var sut = new SentryStackFrame();
Assert.NotNull(sut.FramesOmitted);
}
[Fact]
public void ConfigureAppFrame_InAppIncludeMatches_TrueSet()
{
// Arrange
var module = "IncludedModule";
var sut = new SentryStackFrame
{
Module = module
};
var options = new SentryOptions();
options.AddInAppInclude(module);
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.True(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_InAppExcludeMatches_TrueSet()
{
// Arrange
var module = "ExcludedModule";
var sut = new SentryStackFrame
{
Module = module
};
var options = new SentryOptions();
options.AddInAppExclude(module);
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.False(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_InAppRuleDoesntMatch_TrueSet()
{
// Arrange
var module = "AppModule";
var sut = new SentryStackFrame
{
Module = module
};
var options = new SentryOptions();
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.True(sut.InApp);
}
[Theory]
[InlineData("Namespace", ".*", true)] // Substring + Regex
[InlineData("OtherNamespace", ".*", false)] // Substring + Regex
[InlineData("Name.*", ".*", true)] // Regex + Regex
[InlineData("OtherName.*", ".*", false)] // Regex + Regex
[InlineData(@"Namespace\..*", "Foo", true)] // Regex + Substring
[InlineData(@"OtherNamespace\..*", "Namespace", false)] // Regex + Substring
public void ConfigureAppFrame_InAppRuleExclude_MatchesRegex(string include, string exclude, bool shouldMatch)
{
// Arrange
var module = "Namespace.AppModule";
var sut = new SentryStackFrame
{
Module = module
};
var options = new SentryOptions
{
InAppInclude = [new Regex(include)],
InAppExclude = [new Regex(exclude)]
};
// Act
sut.ConfigureAppFrame(options);
// Assert
sut.InApp.Should().Be(shouldMatch);
}
[Fact]
public void ConfigureAppFrame_WithDefaultOptions_RecognizesInAppFrame()
{
var options = new SentryOptions();
var sut = new SentryStackFrame()
{
Function = "Program.<Main>() {QuickJitted}",
Module = "Console.Customized"
};
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.True(sut.InApp);
}
// Sentry internal frame is marked properly with default options.
// This is an actual frame as captured by Sentry.Profiling.
[Fact]
public void ConfigureAppFrame_WithDefaultOptions_RecognizesSentryInternalFrame()
{
var options = new SentryOptions();
var sut = new SentryStackFrame()
{
Function = "Sentry.Internal.Hub.StartTransaction(class Sentry.ITransactionContext,class System.Collections.Generic.IReadOnlyDictionary`2<class System.String,class System.Object>) {QuickJitted}",
Module = "Sentry"
};
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.False(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_WithDefaultOptions_NotBuiltInIgnoredMarkedAsInApp()
{
var options = new SentryOptions();
var sut = new SentryStackFrame
{
Function = "async void MainActivity.OnCreate(Bundle savedInstanceState)+(?) =\\u003E { }",
Package = "SymbolCollector.Android, Version=1.23.0.0, Culture=neutral, PublicKeyToken=null"
};
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.True(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_WithDefaultOptions_JavaPackageNotInApp()
{
var options = new SentryOptions();
var sut = new SentryStackFrame
{
Function = "void StaticMethods.CallStaticVoidMethod(JniObjectReference, JniMethodInfo, JniArgumentValue*)",
Package = "Java.Interop, Version=9.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065"
};
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.False(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_WithDefaultOptions_SystemPackageNotInApp()
{
var options = new SentryOptions();
var sut = new SentryStackFrame
{
Function = "void Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirError)",
Package = "System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
FileName = "Interop.IOErrors.cs",
};
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.False(sut.InApp);
}
[Fact]
public void ConfigureAppFrame_InAppAlreadySet_InAppIgnored()
{
// Arrange
var module = "ExcludedModule";
var sut = new SentryStackFrame
{
Module = module
};
var options = new SentryOptions();
options.AddInAppExclude(module);
sut.InApp = true;
// Act
sut.ConfigureAppFrame(options);
// Assert
Assert.True(sut.InApp, "InApp started as true but ConfigureAppFrame changed it to false.");
}
[Fact]
public void ConfigureAppFrame_NativeAOTWithoutMethodInfo_InAppIsNull()
{
// See values set by TryCreateNativeAOTFrame
var sut = new SentryStackFrame
{
ImageAddress = 1,
InstructionAddress = 2
};
// Act
sut.ConfigureAppFrame(new());
// Assert
Assert.Null(sut.InApp);
}
#if NET8_0_OR_GREATER
[Fact]
public void ConfigureAppFrame_NativeAOTWithoutMethodInfo_InAppIsSet()
{
var sut = DebugStackTrace.ParseNativeAOTToString(
"System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x42 at offset 66 in file:line:column <filename unknown>:0:0");
sut.ConfigureAppFrame(new());
Assert.False(sut.InApp);
sut = DebugStackTrace.ParseNativeAOTToString(
"Program.<<Main>$>d__0.MoveNext() + 0xdd at offset 221 in file:line:column <filename unknown>:0:0");
sut.ConfigureAppFrame(new());
Assert.True(sut.InApp);
}
#endif
}