Skip to content

Commit e190195

Browse files
committed
Managed vs. Native vs. NullRefenceException
1 parent adf7b68 commit e190195

File tree

3 files changed

+147
-94
lines changed

3 files changed

+147
-94
lines changed

scripts/ios-integration.Tests.ps1

Lines changed: 131 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,85 +6,147 @@ $ErrorActionPreference = 'Stop'
66
Describe 'MAUI app' {
77
BeforeAll {
88
. $PSScriptRoot/ios-simulator-utils.ps1
9+
10+
$tfm = "net9.0-ios18.0"
11+
$target = "ios-simulator-64"
12+
$arch = ($(uname -m) -eq 'arm64') ? 'arm64' : 'x64'
13+
$rid = "iossimulator-$arch"
14+
$udid = Get-IosSimulatorUdid -IosVersion '18.5' -Verbose
15+
16+
$arguments = @(
17+
"-v",
18+
"--target=$target",
19+
"--output-directory=integration_test_output"
20+
)
21+
if ($udid)
22+
{
23+
$arguments += @("--device=$udid")
24+
}
25+
else
26+
{
27+
Write-Host "No suitable simulator found; proceeding without a specific --device"
28+
}
29+
30+
Push-Location $PSScriptRoot/../test/Sentry.Maui.Device.IntegrationTestApp
31+
32+
Write-Host "::group::Build Sentry.Maui.Device.IntegrationTestApp.csproj"
33+
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
34+
--configuration Release `
35+
--framework $tfm `
36+
--runtime $rid
37+
| ForEach-Object { Write-Host $_ }
38+
$LASTEXITCODE | Should -Be 0
39+
Write-Host '::endgroup::'
40+
}
41+
42+
BeforeEach {
43+
Write-Host "::group::Install bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app"
44+
xharness apple install $arguments `
45+
--app bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app
46+
| ForEach-Object { Write-Host $_ }
47+
$LASTEXITCODE | Should -Be 0
48+
Write-Host '::endgroup::'
949
}
10-
It 'Produces the expected exceptions' {
50+
51+
AfterEach {
52+
Write-Host "::group::Uninstall io.sentry.dotnet.maui.device.integrationtestapp"
53+
xharness apple uninstall $arguments `
54+
--app io.sentry.dotnet.maui.device.integrationtestapp
55+
| ForEach-Object { Write-Host $_ }
56+
$LASTEXITCODE | Should -Be 0
57+
Write-Host '::endgroup::'
58+
}
59+
60+
AfterAll {
61+
Pop-Location
62+
}
63+
64+
It 'Managed crash' {
1165
$result = Invoke-SentryServer {
1266
Param([string]$url)
1367
$dsn = $url.Replace('http://', 'http://key@') + '/0'
1468

15-
Push-Location $PSScriptRoot/../test/Sentry.Maui.Device.IntegrationTestApp
16-
try
17-
{
18-
$tfm = "net9.0-ios18.0"
19-
$target = "ios-simulator-64"
20-
$arch = ($(uname -m) -eq 'arm64') ? 'arm64' : 'x64'
21-
$rid = "iossimulator-$arch"
22-
$udid = Get-IosSimulatorUdid -IosVersion '18.5' -Verbose
23-
24-
$arguments = @(
25-
"-v",
26-
"--target=$target",
27-
"--output-directory=integration_test_output"
28-
)
29-
if ($udid)
30-
{
31-
$arguments += @("--device=$udid")
32-
}
33-
else
34-
{
35-
Write-Host "No suitable simulator found; proceeding without a specific --device"
36-
}
37-
38-
Write-Host "::group::Build"
39-
dotnet build Sentry.Maui.Device.IntegrationTestApp.csproj `
40-
--configuration Release `
41-
--framework $tfm `
42-
--runtime $rid
43-
| ForEach-Object { Write-Host $_ }
44-
$LASTEXITCODE | Should -Be 0
45-
Write-Host '::endgroup::'
46-
47-
Write-Host "::group::Install"
48-
xharness apple install $arguments `
49-
--app bin/Release/$tfm/$rid/Sentry.Maui.Device.IntegrationTestApp.app
50-
| ForEach-Object { Write-Host $_ }
51-
$LASTEXITCODE | Should -Be 0
52-
Write-Host '::endgroup::'
53-
54-
Write-Host "::group::Crash"
55-
xharness apple just-run $arguments `
56-
--app io.sentry.dotnet.maui.device.integrationtestapp `
57-
--set-env SENTRY_DSN=$dsn `
58-
--set-env SENTRY_CRASH_TYPE=Managed
59-
| ForEach-Object { Write-Host $_ }
60-
$LASTEXITCODE | Should -Be 0
61-
Write-Host '::endgroup::'
62-
63-
Write-Host "::group::Re-run"
64-
xharness apple just-run $arguments `
65-
--app io.sentry.dotnet.maui.device.integrationtestapp `
66-
--set-env SENTRY_DSN=$dsn `
67-
--set-env SENTRY_CRASH_TYPE=Exit
68-
| ForEach-Object { Write-Host $_ }
69-
$LASTEXITCODE | Should -Be 0
70-
Write-Host '::endgroup::'
71-
72-
Write-Host "::group::Uninstall"
73-
xharness apple uninstall $arguments `
74-
--app io.sentry.dotnet.maui.device.integrationtestapp
75-
| ForEach-Object { Write-Host $_ }
76-
$LASTEXITCODE | Should -Be 0
77-
Write-Host '::endgroup::'
78-
}
79-
finally
80-
{
81-
Pop-Location
82-
}
69+
Write-Host "::group::Cause managed crash"
70+
xharness apple just-run $arguments `
71+
--app io.sentry.dotnet.maui.device.integrationtestapp `
72+
--set-env SENTRY_DSN=$dsn `
73+
--set-env SENTRY_CRASH_TYPE=Managed
74+
| ForEach-Object { Write-Host $_ }
75+
$LASTEXITCODE | Should -Be 0
76+
Write-Host '::endgroup::'
77+
78+
Write-Host "::group::Re-run"
79+
xharness apple just-run $arguments `
80+
--app io.sentry.dotnet.maui.device.integrationtestapp `
81+
--set-env SENTRY_DSN=$dsn `
82+
--set-env SENTRY_TEST_ACTION=Exit
83+
| ForEach-Object { Write-Host $_ }
84+
$LASTEXITCODE | Should -Be 0
85+
Write-Host '::endgroup::'
8386
}
8487

8588
$result.HasErrors() | Should -BeFalse
8689
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.ApplicationException`""
8790
# TODO: fix redundant SIGABRT (#3954)
8891
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"SIGABRT`"" } | Should -Throw
8992
}
93+
94+
It 'Native crash' {
95+
$result = Invoke-SentryServer {
96+
Param([string]$url)
97+
$dsn = $url.Replace('http://', 'http://key@') + '/0'
98+
99+
Write-Host "::group::Cause native crash"
100+
xharness apple just-run $arguments `
101+
--app io.sentry.dotnet.maui.device.integrationtestapp `
102+
--set-env SENTRY_DSN=$dsn `
103+
--set-env SENTRY_CRASH_TYPE=Native
104+
| ForEach-Object { Write-Host $_ }
105+
$LASTEXITCODE | Should -Be 0
106+
Write-Host '::endgroup::'
107+
108+
Write-Host "::group::Re-run"
109+
xharness apple just-run $arguments `
110+
--app io.sentry.dotnet.maui.device.integrationtestapp `
111+
--set-env SENTRY_DSN=$dsn `
112+
--set-env SENTRY_TEST_ACTION=Exit
113+
| ForEach-Object { Write-Host $_ }
114+
$LASTEXITCODE | Should -Be 0
115+
Write-Host '::endgroup::'
116+
}
117+
118+
$result.HasErrors() | Should -BeFalse
119+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"EXC_[A-Z_]+`""
120+
$result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"System.*Exception`""
121+
}
122+
123+
It 'Null reference exception' {
124+
$result = Invoke-SentryServer {
125+
Param([string]$url)
126+
$dsn = $url.Replace('http://', 'http://key@') + '/0'
127+
128+
Write-Host "::group::Trigger null reference exception"
129+
xharness apple just-run $arguments `
130+
--app io.sentry.dotnet.maui.device.integrationtestapp `
131+
--set-env SENTRY_DSN=$dsn `
132+
--set-env SENTRY_TEST_ACTION=NullReferenceException
133+
| ForEach-Object { Write-Host $_ }
134+
$LASTEXITCODE | Should -Be 0
135+
Write-Host '::endgroup::'
136+
137+
Write-Host "::group::Re-run"
138+
xharness apple just-run $arguments `
139+
--app io.sentry.dotnet.maui.device.integrationtestapp `
140+
--set-env SENTRY_DSN=$dsn `
141+
--set-env SENTRY_TEST_ACTION=Exit
142+
| ForEach-Object { Write-Host $_ }
143+
$LASTEXITCODE | Should -Be 0
144+
Write-Host '::endgroup::'
145+
}
146+
147+
$result.HasErrors() | Should -BeFalse
148+
$result.Envelopes() | Should -AnyElementMatch "`"type`":`"System.NullReferenceException`""
149+
# TODO: fix redundant EXC_BAD_ACCESS (#3954)
150+
{ $result.Envelopes() | Should -Not -AnyElementMatch "`"type`":`"EXC_BAD_ACCESS`"" } | Should -Throw
151+
}
90152
}

test/Sentry.Maui.Device.IntegrationTestApp/MainPage.xaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@
2323
Style="{StaticResource SubHeadline}"
2424
SemanticProperties.HeadingLevel="Level2"
2525
SemanticProperties.Description="Welcome to dot net Multi platform App U I" />
26-
27-
<Button
28-
x:Name="CounterBtn"
29-
Text="Click me"
30-
SemanticProperties.Hint="Counts the number of times you click"
31-
Clicked="OnCounterClicked"
32-
HorizontalOptions="Fill" />
3326
</VerticalStackLayout>
3427
</ScrollView>
3528

test/Sentry.Maui.Device.IntegrationTestApp/MainPage.xaml.cs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,11 @@
22

33
public partial class MainPage : ContentPage
44
{
5-
int count = 0;
6-
75
public MainPage()
86
{
97
InitializeComponent();
108
}
119

12-
private void OnCounterClicked(object? sender, EventArgs e)
13-
{
14-
count++;
15-
16-
if (count == 1)
17-
CounterBtn.Text = $"Clicked {count} time";
18-
else
19-
CounterBtn.Text = $"Clicked {count} times";
20-
21-
SemanticScreenReader.Announce(CounterBtn.Text);
22-
}
23-
2410
protected override void OnAppearing()
2511
{
2612
base.OnAppearing();
@@ -31,11 +17,23 @@ protected override void OnAppearing()
3117
{
3218
SentrySdk.CauseCrash(crashType);
3319
}
34-
else if (crashTypeEnv?.Equals("exit", StringComparison.OrdinalIgnoreCase) == true)
20+
#pragma warning restore CS0618
21+
22+
var testActionEnv = Environment.GetEnvironmentVariable("SENTRY_TEST_ACTION");
23+
if (testActionEnv?.Equals("NullReferenceException", StringComparison.OrdinalIgnoreCase) == true)
3524
{
36-
SentrySdk.Flush();
37-
Environment.Exit(0);
25+
try
26+
{
27+
object? obj = null;
28+
_ = obj.ToString();
29+
}
30+
catch (NullReferenceException ex)
31+
{
32+
SentrySdk.CaptureException(ex);
33+
}
3834
}
39-
#pragma warning restore CS0618
35+
36+
SentrySdk.Flush();
37+
Environment.Exit(0);
4038
}
4139
}

0 commit comments

Comments
 (0)