From 6c1650151ecd65c9d2b9797d91bb237c02f50876 Mon Sep 17 00:00:00 2001 From: Simon Binder Date: Wed, 20 Jan 2021 12:50:21 +0100 Subject: [PATCH] Run migrated tests in strong null safety --- .github/workflows/main.yml | 2 +- moor/lib/src/runtime/data_class.dart | 4 ++-- .../src/runtime/query_builder/migration.dart | 22 +++++++++---------- moor/test/data/utils/mocks.dart | 9 ++++++++ moor/test/transactions_test.dart | 11 +++++----- 5 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 295ee650..9058682a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: # build, test and upload coverage - run: dart run build_runner build --delete-conflicting-outputs working-directory: moor - - run: dart --no-sound-null-safety --null-assertions test #-x background_isolate --coverage=coverage + - run: dart test #-x background_isolate --coverage=coverage working-directory: moor # - uses: actions/upload-artifact@v2 # with: diff --git a/moor/lib/src/runtime/data_class.dart b/moor/lib/src/runtime/data_class.dart index 251223a1..e9fb773c 100644 --- a/moor/lib/src/runtime/data_class.dart +++ b/moor/lib/src/runtime/data_class.dart @@ -129,10 +129,10 @@ class Value { @override bool operator ==(Object other) => identical(this, other) || - other is Value && present == other.present && value == other.value; + other is Value && present == other.present && _value == other._value; @override - int get hashCode => present.hashCode ^ value.hashCode; + int get hashCode => present.hashCode ^ _value.hashCode; } /// Serializer responsible for mapping atomic types from and to json. diff --git a/moor/lib/src/runtime/query_builder/migration.dart b/moor/lib/src/runtime/query_builder/migration.dart index cc3bc845..fbd4ca29 100644 --- a/moor/lib/src/runtime/query_builder/migration.dart +++ b/moor/lib/src/runtime/query_builder/migration.dart @@ -146,23 +146,23 @@ class Migrator { for (final row in schemaQuery) { final type = row.readString('type'); - final sql = row.readString('sql'); + final sql = row.read('sql'); final name = row.readString('name'); + if (sql == null) { + // These indexes are created by sqlite to enforce different kinds of + // special constraints. + // They do not have any SQL create statement as they are created + // automatically by the constraints on the table. + // They can not be re-created and need to be skipped. + assert(name.startsWith('sqlite_autoindex')); + continue; + } + switch (type) { case 'trigger': case 'view': - createAffected.add(sql); - break; case 'index': - if (name.startsWith('sqlite_autoindex')) { - // These indexes are created by sqlite to enforce - // different kinds of special constraints. - // They do not have any SQL create statement as they are - // created automatically by the constraints on the table. - // They can not be re-created and need to be skipped. - break; - } createAffected.add(sql); break; } diff --git a/moor/test/data/utils/mocks.dart b/moor/test/data/utils/mocks.dart index 87f521e5..5eec7125 100644 --- a/moor/test/data/utils/mocks.dart +++ b/moor/test/data/utils/mocks.dart @@ -94,6 +94,15 @@ class MockTransactionExecutor extends MockExecutor when(send()).thenAnswer((_) => Future.value(null)); when(rollback()).thenAnswer((_) => Future.value(null)); } + + @override + Future send() { + return _nsm(Invocation.method(#send, []), Future.value(null)); + } + + @override + Future rollback() => + _nsm(Invocation.method(#rollback, []), Future.value(null)); } class MockStreamQueries extends Mock implements StreamQueryStore { diff --git a/moor/test/transactions_test.dart b/moor/test/transactions_test.dart index 660fc27a..fb2f3ee0 100644 --- a/moor/test/transactions_test.dart +++ b/moor/test/transactions_test.dart @@ -1,4 +1,3 @@ -//@dart=2.9 import 'dart:async'; @TestOn('!browser') // todo: Figure out why this doesn't run in js @@ -27,9 +26,9 @@ import 'data/tables/todos.dart'; import 'data/utils/mocks.dart'; void main() { - TodoDb db; - MockExecutor executor; - MockStreamQueries streamQueries; + late TodoDb db; + late MockExecutor executor; + late MockStreamQueries streamQueries; setUp(() { executor = MockExecutor(); @@ -43,7 +42,7 @@ void main() { // create a database without mocked stream queries db = TodoDb(MockExecutor()); - Stream stream; + late Stream stream; final didSetUpStream = Completer(); final makeUpdate = Completer(); @@ -92,7 +91,7 @@ void main() { }); test('stream queries terminate on exceptional transaction', () async { - Stream stream; + late Stream stream; try { await db.transaction(() async {