File tree 4 files changed +28
-9
lines changed
packages/sqlite_async/test/utils
4 files changed +28
-9
lines changed Original file line number Diff line number Diff line change 1
1
import 'package:sqlite_async/sqlite_async.dart' ;
2
- import 'package:test_api/src/backend/invoker.dart' ;
3
2
4
3
class TestDefaultSqliteOpenFactory extends DefaultSqliteOpenFactory {
5
4
final String sqlitePath;
@@ -9,14 +8,7 @@ class TestDefaultSqliteOpenFactory extends DefaultSqliteOpenFactory {
9
8
}
10
9
11
10
abstract class AbstractTestUtils {
12
- String dbPath () {
13
- final test = Invoker .current! .liveTest;
14
- var testName = test.test.name;
15
- var testShortName =
16
- testName.replaceAll (RegExp (r'[\s\./]' ), '_' ).toLowerCase ();
17
- var dbName = "test-db/$testShortName .db" ;
18
- return dbName;
19
- }
11
+ String dbPath ();
20
12
21
13
/// Generates a test open factory
22
14
Future <TestDefaultSqliteOpenFactory > testFactory (
Original file line number Diff line number Diff line change @@ -26,6 +26,10 @@ class TestSqliteOpenFactory extends TestDefaultSqliteOpenFactory {
26
26
sqlite_open.open.overrideFor (sqlite_open.OperatingSystem .linux, () {
27
27
return DynamicLibrary .open (sqlitePath);
28
28
});
29
+ sqlite_open.open.overrideFor (sqlite_open.OperatingSystem .macOS, () {
30
+ return DynamicLibrary .open (
31
+ '/Users/simon/src/sqlite_async.dart/sqlite-autoconf-3480000/.libs/libsqlite3.dylib' );
32
+ });
29
33
final db = super .open (options);
30
34
31
35
db.createFunction (
Original file line number Diff line number Diff line change 1
1
import 'abstract_test_utils.dart' ;
2
2
3
3
class TestUtils extends AbstractTestUtils {
4
+ @override
5
+ String dbPath () {
6
+ throw UnimplementedError ();
7
+ }
8
+
4
9
@override
5
10
Future <void > cleanDb ({required String path}) {
6
11
throw UnimplementedError ();
Original file line number Diff line number Diff line change 1
1
import 'dart:async' ;
2
2
import 'dart:js_interop' ;
3
+ import 'dart:math' ;
3
4
4
5
import 'package:sqlite_async/sqlite_async.dart' ;
5
6
import 'package:test/test.dart' ;
@@ -9,6 +10,8 @@ import 'abstract_test_utils.dart';
9
10
@JS ('URL.createObjectURL' )
10
11
external String _createObjectURL (Blob blob);
11
12
13
+ String ? _dbPath;
14
+
12
15
class TestUtils extends AbstractTestUtils {
13
16
late Future <void > _isInitialized;
14
17
late final SqliteOptions webOptions;
@@ -33,6 +36,21 @@ class TestUtils extends AbstractTestUtils {
33
36
wasmUri: sqliteWasmUri.toString (), workerUri: sqliteUri));
34
37
}
35
38
39
+ @override
40
+ String dbPath () {
41
+ if (_dbPath case final path? ) {
42
+ return path;
43
+ }
44
+
45
+ final created = _dbPath = 'test-db/${Random ().nextInt (1 << 31 )}/test.db' ;
46
+ addTearDown (() {
47
+ // Pick a new path for the next test.
48
+ _dbPath = null ;
49
+ });
50
+
51
+ return created;
52
+ }
53
+
36
54
@override
37
55
Future <void > cleanDb ({required String path}) async {}
38
56
You can’t perform that action at this time.
0 commit comments