Skip to content

Commit

Permalink
analyzer issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vaind committed Sep 18, 2024
1 parent f9a3b73 commit 42a868c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 46 deletions.
7 changes: 3 additions & 4 deletions flutter/lib/src/native/c/sentry_native.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class SentryNative with SentryNativeSafeInvoker implements SentryNativeBinding {
final SentryFlutterOptions options;

@visibleForTesting
static late final native =
binding.SentryNative(DynamicLibrary.open('sentry.dll'));
static final native = binding.SentryNative(DynamicLibrary.open('sentry.dll'));

Check warning on line 22 in flutter/lib/src/native/c/sentry_native.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/c/sentry_native.dart#L22

Added line #L22 was not covered by tests

@visibleForTesting
static String? crashpadPath;
Expand Down Expand Up @@ -338,7 +337,7 @@ binding.sentry_value_u? dynamicToNativeValue(

extension on String {
binding.sentry_value_u toNativeValue() {
final cValue = this.toNativeUtf8();
final cValue = toNativeUtf8();
final result = SentryNative.native.value_new_string(cValue.cast());
malloc.free(cValue);

Check warning on line 342 in flutter/lib/src/native/c/sentry_native.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/c/sentry_native.dart#L339-L342

Added lines #L339 - L342 were not covered by tests
return result;
Expand All @@ -348,7 +347,7 @@ extension on String {
extension on int {
binding.sentry_value_u toNativeValue() {
if (this > 0x7FFFFFFF) {
return this.toString().toNativeValue();
return toString().toNativeValue();

Check warning on line 350 in flutter/lib/src/native/c/sentry_native.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/c/sentry_native.dart#L348-L350

Added lines #L348 - L350 were not covered by tests
} else {
return SentryNative.native.value_new_int32(this);

Check warning on line 352 in flutter/lib/src/native/c/sentry_native.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/c/sentry_native.dart#L352

Added line #L352 was not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion flutter/lib/src/native/c/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:ffi/ffi.dart';

/// Creates and collects native pointers that need to be freed.
class FreeableFactory {
List<Pointer> _allocated = [];
final _allocated = <Pointer>[];

Pointer<Char> str(String? dartString) {

Check warning on line 9 in flutter/lib/src/native/c/utils.dart

View check run for this annotation

Codecov / codecov/patch

flutter/lib/src/native/c/utils.dart#L9

Added line #L9 was not covered by tests
if (dartString == null) {
Expand Down
4 changes: 2 additions & 2 deletions flutter/test/integrations/native_sdk_integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ void main() {

setUp(() {
fixture = IntegrationTestFixture(NativeSdkIntegration.new);
when(fixture.binding.init(any)).thenReturn(() {});
when(fixture.binding.close()).thenReturn(() {});
when(fixture.binding.init(any)).thenReturn(null);
when(fixture.binding.close()).thenReturn(null);
});

test('adds integration', () async {
Expand Down
18 changes: 9 additions & 9 deletions flutter/test/native_scope_observer_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,65 +18,65 @@ void main() {
});

test('addBreadcrumbCalls', () async {
when(mock.addBreadcrumb(any)).thenReturn(() {});
when(mock.addBreadcrumb(any)).thenReturn(null);
final breadcrumb = Breadcrumb();
await sut.addBreadcrumb(breadcrumb);

expect(verify(mock.addBreadcrumb(captureAny)).captured.single, breadcrumb);
});

test('clearBreadcrumbsCalls', () async {
when(mock.clearBreadcrumbs()).thenReturn(() {});
when(mock.clearBreadcrumbs()).thenReturn(null);
await sut.clearBreadcrumbs();

verify(mock.clearBreadcrumbs()).called(1);
});

test('removeContextsCalls', () async {
when(mock.removeContexts(any)).thenReturn(() {});
when(mock.removeContexts(any)).thenReturn(null);
await sut.removeContexts('fixture-key');

expect(
verify(mock.removeContexts(captureAny)).captured.single, 'fixture-key');
});

test('removeExtraCalls', () async {
when(mock.removeExtra(any)).thenReturn(() {});
when(mock.removeExtra(any)).thenReturn(null);
await sut.removeExtra('fixture-key');

expect(verify(mock.removeExtra(captureAny)).captured.single, 'fixture-key');
});

test('removeTagCalls', () async {
when(mock.removeTag(any)).thenReturn(() {});
when(mock.removeTag(any)).thenReturn(null);
await sut.removeTag('fixture-key');

expect(verify(mock.removeTag(captureAny)).captured.single, 'fixture-key');
});

test('setContextsCalls', () async {
when(mock.setContexts(any, any)).thenReturn(() {});
when(mock.setContexts(any, any)).thenReturn(null);
await sut.setContexts('fixture-key', 'fixture-value');

verify(mock.setContexts('fixture-key', 'fixture-value')).called(1);
});

test('setExtraCalls', () async {
when(mock.setExtra(any, any)).thenReturn(() {});
when(mock.setExtra(any, any)).thenReturn(null);
await sut.setExtra('fixture-key', 'fixture-value');

verify(mock.setExtra('fixture-key', 'fixture-value')).called(1);
});

test('setTagCalls', () async {
when(mock.setTag(any, any)).thenReturn(() {});
when(mock.setTag(any, any)).thenReturn(null);
await sut.setTag('fixture-key', 'fixture-value');

verify(mock.setTag('fixture-key', 'fixture-value')).called(1);
});

test('setUserCalls', () async {
when(mock.setUser(any)).thenReturn(() {});
when(mock.setUser(any)).thenReturn(null);

final user = SentryUser(id: 'foo bar');
await sut.setUser(user);
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/profiling_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void main() {
});

test('dispose() calls native discard() exactly once', () async {
when(mock.discardProfiler(any)).thenReturn(() {});
when(mock.discardProfiler(any)).thenReturn(null);

sut.dispose();
sut.dispose(); // Additional calls must not have an effect.
Expand Down
31 changes: 2 additions & 29 deletions flutter/test/sentry_native/sentry_native_test_ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:io';
import 'dart:typed_data';

import 'package:ffi/ffi.dart';
import 'package:file/memory.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:sentry/src/platform/platform.dart' as platform;
import 'package:sentry_flutter/sentry_flutter.dart';
Expand Down Expand Up @@ -41,8 +40,7 @@ void main() {
options = SentryFlutterOptions(dsn: fakeDsn)
// ignore: invalid_use_of_internal_member
..automatedTestMode = true
..debug = true
..fileSystem = MemoryFileSystem.test();
..debug = true;
sut = createBinding(options) as SentryNative;
});

Expand Down Expand Up @@ -226,31 +224,6 @@ void main() {
(File file) => file.existsSync(),
);
});

test('getAppDebugImage returns app.so debug image', () async {
await options.fileSystem.directory('/path/to/data').create(recursive: true);
await options.fileSystem
.file('/path/to/data/app.so')
.writeAsString('12345');

final image = await sut.getAppDebugImage(
SentryStackTrace(
frames: [],
// ignore: invalid_use_of_internal_member
buildId: '4c6950bd9e9cc9839071742a7295c09e',
// ignore: invalid_use_of_internal_member
baseAddr: '0x123',
),
[DebugImage(type: 'pe', codeFile: '/path/to/application.exe')],
);

expect(image, isNotNull);
expect(image!.codeFile, '/path/to/data/app.so');
expect(image.codeId, '4c6950bd9e9cc9839071742a7295c09e');
expect(image.debugId, 'bd50694c9c9e83c99071742a7295c09e');
expect(image.imageAddr, '0x123');
expect(image.imageSize, 5);
});
}

/// Runs [command] with command's stdout and stderr being forwrarded to
Expand Down Expand Up @@ -319,7 +292,7 @@ bool _builtVersionIsExpected(String cmakeBuildDir, String buildOutputDir) {
.any((name) => !File('$buildOutputDir/$name').existsSync());
}

late final _configuredSentryNativeVersion =
final _configuredSentryNativeVersion =
File('$repoRootDir/sentry-native/CMakeCache.txt')
.readAsLinesSync()
.map((line) => line.startsWith('version=') ? line.substring(8) : null)
Expand Down

0 comments on commit 42a868c

Please sign in to comment.