Skip to content

Commit

Permalink
Tests: macOS now correctly throws unique violation exception.
Browse files Browse the repository at this point in the history
Follow-up from
ccec6e8 unblock macOS CI failure
  • Loading branch information
greenrobot-team committed Oct 16, 2023
1 parent ddd09b0 commit fa5b593
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
7 changes: 7 additions & 0 deletions objectbox_test/test/basics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import 'package:objectbox/src/native/bindings/helpers.dart';
import 'package:objectbox/src/native/version.dart';
import 'package:test/test.dart';

import 'test_env.dart';

void main() {
test("Dart version test helper", () {
expect(atLeastDart("2.15.0"), true);
expect(atLeastDart("999.0.0"), false);
});

print("Testing basics of ObjectBox using C lib V${libraryVersion()}");

// Prior to Dart 2.6, the exception wasn't accessible and may have crashed.
Expand Down
23 changes: 12 additions & 11 deletions objectbox_test/test/box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,17 +240,18 @@ void main() {
final object = TestEntity2()..value = 42;
final future = box.putQueuedAwaitResult(object);

try {
await future;
} catch (e) {
// TODO: Mac in GitHub CI (not locally reproducible yet)...
if (Platform.isMacOS) {
expect(e is ObjectBoxException, isTrue);
expect((e as ObjectBoxException).message, '');
} else {
expect(e is UniqueViolationException, isTrue);
expect(e.toString(), contains('Unique constraint'));
}
if (Platform.isMacOS && !atLeastDart('3.1.0')) {
// Before Dart 3.1 an incorrect exception is thrown on macOS.
expect(
() async => await future,
throwsA(
predicate((e) => e is ObjectBoxException && e.message == '')));
} else {
expect(
() async => await future,
throwsA(predicate((e) =>
e is UniqueViolationException &&
e.message.contains('Unique constraint'))));
}

expect(object.id, isNull); // ID must remain unassigned
Expand Down
11 changes: 11 additions & 0 deletions objectbox_test/test/test_env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,14 @@ dynamic notAtLeastDart2_15_0() {
return false;
}
}

bool atLeastDart(String expectedLowestVersion) {
final dartVersion = RegExp('([0-9]+).([0-9]+).([0-9]+)')
.firstMatch(Platform.version)
?.group(0);
if (dartVersion != null && dartVersion.compareTo(expectedLowestVersion) > 0) {
return true;
} else {
return false;
}
}

0 comments on commit fa5b593

Please sign in to comment.