Merge pull request #1912 from simolus3/fix-tests

Fix tests
This commit is contained in:
Simon Binder 2022-06-28 23:21:18 +02:00 committed by GitHub
commit 46454c28fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 122 additions and 80 deletions

View File

@ -203,7 +203,7 @@ class DialectOptions {
@JsonSerializable() @JsonSerializable()
class SqliteAnalysisOptions { class SqliteAnalysisOptions {
@JsonKey(name: 'modules', defaultValue: []) @JsonKey(name: 'modules')
final List<SqlModule> modules; final List<SqlModule> modules;
@JsonKey(fromJson: _parseSqliteVersion) @JsonKey(fromJson: _parseSqliteVersion)

View File

@ -164,7 +164,7 @@ SqliteAnalysisOptions _$SqliteAnalysisOptionsFromJson(Map json) =>
(v as List<dynamic>?) (v as List<dynamic>?)
?.map((e) => $enumDecode(_$SqlModuleEnumMap, e)) ?.map((e) => $enumDecode(_$SqlModuleEnumMap, e))
.toList() ?? .toList() ??
[]), const []),
version: $checkedConvert( version: $checkedConvert(
'version', (v) => _parseSqliteVersion(v as String?)), 'version', (v) => _parseSqliteVersion(v as String?)),
); );

View File

@ -14,7 +14,7 @@ dependencies:
recase: '>=2.0.1 <5.0.0' recase: '>=2.0.1 <5.0.0'
meta: ^1.1.0 meta: ^1.1.0
path: ^1.6.0 path: ^1.6.0
json_annotation: ^4.1.0 json_annotation: ^4.5.0
stream_transform: '>=0.1.0 <3.0.0' stream_transform: '>=0.1.0 <3.0.0'
# CLI # CLI
@ -49,7 +49,7 @@ dev_dependencies:
test_descriptor: ^2.0.0 test_descriptor: ^2.0.0
build_runner: ^2.0.0 build_runner: ^2.0.0
build_test: ^2.0.0 build_test: ^2.0.0
json_serializable: ^6.1.3 json_serializable: ^6.2.0
# Used to test the migration from moor to drift # Used to test the migration from moor to drift
moor: any moor: any

View File

@ -166,8 +166,6 @@ class Entries extends Table with TableInfo<Entries, Entrie> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
List<Set<GeneratedColumn>> get uniqueKeys => [];
@override
Entrie map(Map<String, dynamic> data, {String? tablePrefix}) { Entrie map(Map<String, dynamic> data, {String? tablePrefix}) {
return Entrie.fromData(data, return Entrie.fromData(data,
prefix: tablePrefix != null ? '$tablePrefix.' : null); prefix: tablePrefix != null ? '$tablePrefix.' : null);

View File

@ -7,14 +7,14 @@ environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
js: ^0.6.3 js: ^0.6.4
stream_channel: ^2.1.0 stream_channel: ^2.1.0
drift: drift:
dev_dependencies: dev_dependencies:
build_runner: ^2.0.0 build_runner: ^2.1.11
build_web_compilers: ^3.0.0 build_web_compilers: ^3.2.3
lints: ^1.0.1 lints: ^2.0.0
drift_dev: drift_dev:
dependency_overrides: dependency_overrides:

View File

@ -171,8 +171,6 @@ class Users extends Table with TableInfo<Users, User> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
List<Set<GeneratedColumn>> get uniqueKeys => [];
@override
User map(Map<String, dynamic> data, {String tablePrefix}) { User map(Map<String, dynamic> data, {String tablePrefix}) {
return User.fromData(data, return User.fromData(data,
prefix: tablePrefix != null ? '$tablePrefix.' : null); prefix: tablePrefix != null ? '$tablePrefix.' : null);

View File

@ -11,10 +11,10 @@ class _$Foo extends Foo {
final User moorField; final User moorField;
factory _$Foo([void Function(FooBuilder) updates]) => factory _$Foo([void Function(FooBuilder) updates]) =>
(new FooBuilder()..update(updates)).build(); (new FooBuilder()..update(updates))._build();
_$Foo._({this.moorField}) : super._() { _$Foo._({this.moorField}) : super._() {
BuiltValueNullFieldError.checkNotNull(moorField, 'Foo', 'moorField'); BuiltValueNullFieldError.checkNotNull(moorField, r'Foo', 'moorField');
} }
@override @override
@ -37,7 +37,7 @@ class _$Foo extends Foo {
@override @override
String toString() { String toString() {
return (newBuiltValueToStringHelper('Foo')..add('moorField', moorField)) return (newBuiltValueToStringHelper(r'Foo')..add('moorField', moorField))
.toString(); .toString();
} }
} }
@ -72,14 +72,16 @@ class FooBuilder implements Builder<Foo, FooBuilder> {
} }
@override @override
_$Foo build() { Foo build() => _build();
_$Foo _build() {
final _$result = _$v ?? final _$result = _$v ??
new _$Foo._( new _$Foo._(
moorField: BuiltValueNullFieldError.checkNotNull( moorField: BuiltValueNullFieldError.checkNotNull(
moorField, 'Foo', 'moorField')); moorField, r'Foo', 'moorField'));
replace(_$result); replace(_$result);
return _$result; return _$result;
} }
} }
// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,deprecated_member_use_from_same_package,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new // ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,deprecated_member_use_from_same_package,lines_longer_than_80_chars,no_leading_underscores_for_local_identifiers,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new,unnecessary_lambdas

View File

@ -6,7 +6,7 @@ part of 'database.dart';
// MoorGenerator // MoorGenerator
// ************************************************************************** // **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this // ignore_for_file: type=lint
class KeyValue extends DataClass implements Insertable<KeyValue> { class KeyValue extends DataClass implements Insertable<KeyValue> {
final String key; final String key;
final String value; final String value;
@ -169,8 +169,6 @@ class $KeyValuesTable extends KeyValues
@override @override
Set<GeneratedColumn> get $primaryKey => {key}; Set<GeneratedColumn> get $primaryKey => {key};
@override @override
List<Set<GeneratedColumn>> get uniqueKeys => [];
@override
KeyValue map(Map<String, dynamic> data, {String? tablePrefix}) { KeyValue map(Map<String, dynamic> data, {String? tablePrefix}) {
return KeyValue.fromData(data, return KeyValue.fromData(data,
prefix: tablePrefix != null ? '$tablePrefix.' : null); prefix: tablePrefix != null ? '$tablePrefix.' : null);

View File

@ -0,0 +1,23 @@
targets:
$default:
builders:
drift_dev:
options:
override_hash_and_equals_in_result_sets: true
use_column_name_as_json_key_when_defined_in_moor_file: true
generate_connect_constructor: true
compact_query_methods: true
write_from_json_string_constructor: true
raw_result_set_data: false
apply_converters_on_variables: true
generate_values_in_copy_with: true
named_parameters: false
new_sql_code_generation: true
scoped_dart_components: true
sql:
dialect: sqlite
options:
version: "3.37"
modules:
- json1
- fts5

View File

@ -93,6 +93,10 @@ class User extends DataClass implements Insertable<User> {
preferences: serializer.fromJson<Preferences?>(json['preferences']), preferences: serializer.fromJson<Preferences?>(json['preferences']),
); );
} }
factory User.fromJsonString(String encodedJson,
{ValueSerializer? serializer}) =>
User.fromJson(DataClass.parseJson(encodedJson) as Map<String, dynamic>,
serializer: serializer);
@override @override
Map<String, dynamic> toJson({ValueSerializer? serializer}) { Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
@ -109,14 +113,15 @@ class User extends DataClass implements Insertable<User> {
{int? id, {int? id,
String? name, String? name,
DateTime? birthDate, DateTime? birthDate,
Uint8List? profilePicture, Value<Uint8List?> profilePicture = const Value.absent(),
Preferences? preferences}) => Value<Preferences?> preferences = const Value.absent()}) =>
User( User(
id: id ?? this.id, id: id ?? this.id,
name: name ?? this.name, name: name ?? this.name,
birthDate: birthDate ?? this.birthDate, birthDate: birthDate ?? this.birthDate,
profilePicture: profilePicture ?? this.profilePicture, profilePicture:
preferences: preferences ?? this.preferences, profilePicture.present ? profilePicture.value : this.profilePicture,
preferences: preferences.present ? preferences.value : this.preferences,
); );
@override @override
String toString() { String toString() {
@ -366,6 +371,11 @@ class Friendship extends DataClass implements Insertable<Friendship> {
reallyGoodFriends: serializer.fromJson<bool>(json['reallyGoodFriends']), reallyGoodFriends: serializer.fromJson<bool>(json['reallyGoodFriends']),
); );
} }
factory Friendship.fromJsonString(String encodedJson,
{ValueSerializer? serializer}) =>
Friendship.fromJson(
DataClass.parseJson(encodedJson) as Map<String, dynamic>,
serializer: serializer);
@override @override
Map<String, dynamic> toJson({ValueSerializer? serializer}) { Map<String, dynamic> toJson({ValueSerializer? serializer}) {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
@ -549,7 +559,7 @@ abstract class _$Database extends GeneratedDatabase {
late final $FriendshipsTable friendships = $FriendshipsTable(this); late final $FriendshipsTable friendships = $FriendshipsTable(this);
Selectable<User> mostPopularUsers(int amount) { Selectable<User> mostPopularUsers(int amount) {
return customSelect( return customSelect(
'SELECT * FROM users AS u ORDER BY (SELECT COUNT(*) FROM friendships WHERE first_user = u.id OR second_user = u.id) DESC LIMIT @1', 'SELECT * FROM users AS u ORDER BY (SELECT COUNT(*) FROM friendships WHERE first_user = u.id OR second_user = u.id) DESC LIMIT ?1',
variables: [ variables: [
Variable<int>(amount) Variable<int>(amount)
], ],
@ -561,7 +571,7 @@ abstract class _$Database extends GeneratedDatabase {
Selectable<int> amountOfGoodFriends(int user) { Selectable<int> amountOfGoodFriends(int user) {
return customSelect( return customSelect(
'SELECT COUNT(*) AS _c0 FROM friendships AS f WHERE f.really_good_friends = 1 AND(f.first_user = @1 OR f.second_user = @1)', 'SELECT COUNT(*) AS _c0 FROM friendships AS f WHERE f.really_good_friends = 1 AND(f.first_user = ?1 OR f.second_user = ?1)',
variables: [ variables: [
Variable<int>(user) Variable<int>(user)
], ],
@ -572,7 +582,7 @@ abstract class _$Database extends GeneratedDatabase {
Selectable<FriendshipsOfResult> friendshipsOf(int user) { Selectable<FriendshipsOfResult> friendshipsOf(int user) {
return customSelect( return customSelect(
'SELECT f.really_good_friends,"user"."id" AS "nested_0.id", "user"."name" AS "nested_0.name", "user"."birth_date" AS "nested_0.birth_date", "user"."profile_picture" AS "nested_0.profile_picture", "user"."preferences" AS "nested_0.preferences" FROM friendships AS f INNER JOIN users AS "user" ON "user".id IN (f.first_user, f.second_user) AND "user".id != @1 WHERE(f.first_user = @1 OR f.second_user = @1)', 'SELECT f.really_good_friends,"user"."id" AS "nested_0.id", "user"."name" AS "nested_0.name", "user"."birth_date" AS "nested_0.birth_date", "user"."profile_picture" AS "nested_0.profile_picture", "user"."preferences" AS "nested_0.preferences" FROM friendships AS f INNER JOIN users AS user ON user.id IN (f.first_user, f.second_user) AND user.id != ?1 WHERE(f.first_user = ?1 OR f.second_user = ?1)',
variables: [ variables: [
Variable<int>(user) Variable<int>(user)
], ],
@ -596,7 +606,7 @@ abstract class _$Database extends GeneratedDatabase {
} }
Selectable<Preferences?> settingsFor(int user) { Selectable<Preferences?> settingsFor(int user) {
return customSelect('SELECT preferences FROM users WHERE id = @1', return customSelect('SELECT preferences FROM users WHERE id = ?1',
variables: [ variables: [
Variable<int>(user) Variable<int>(user)
], ],
@ -621,7 +631,7 @@ abstract class _$Database extends GeneratedDatabase {
Future<List<Friendship>> returning(int var1, int var2, bool var3) { Future<List<Friendship>> returning(int var1, int var2, bool var3) {
return customWriteReturning( return customWriteReturning(
'INSERT INTO friendships VALUES (@1, @2, @3) RETURNING *', 'INSERT INTO friendships VALUES (?1, ?2, ?3) RETURNING *',
variables: [ variables: [
Variable<int>(var1), Variable<int>(var1),
Variable<int>(var2), Variable<int>(var2),

View File

@ -1,7 +1,7 @@
name: web name: web
description: Run integration tests for Moor on the web description: Run integration tests for Moor on the web
environment: environment:
sdk: '>=2.4.0 <3.0.0' sdk: '>=2.6.0 <3.0.0'
dependencies: dependencies:
drift: drift:

View File

@ -6,7 +6,7 @@ part of 'saves_after_migration_regression_test.dart';
// MoorGenerator // MoorGenerator
// ************************************************************************** // **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps, unnecessary_this // ignore_for_file: type=lint
class Foo extends DataClass implements Insertable<Foo> { class Foo extends DataClass implements Insertable<Foo> {
final int id; final int id;
Foo({@required this.id}); Foo({@required this.id});
@ -137,8 +137,6 @@ class $FoosTable extends Foos with TableInfo<$FoosTable, Foo> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
List<Set<GeneratedColumn>> get uniqueKeys => [];
@override
Foo map(Map<String, dynamic> data, {String tablePrefix}) { Foo map(Map<String, dynamic> data, {String tablePrefix}) {
return Foo.fromData(data, return Foo.fromData(data,
prefix: tablePrefix != null ? '$tablePrefix.' : null); prefix: tablePrefix != null ? '$tablePrefix.' : null);
@ -280,8 +278,6 @@ class $BarsTable extends Bars with TableInfo<$BarsTable, Bar> {
@override @override
Set<GeneratedColumn> get $primaryKey => {id}; Set<GeneratedColumn> get $primaryKey => {id};
@override @override
List<Set<GeneratedColumn>> get uniqueKeys => [];
@override
Bar map(Map<String, dynamic> data, {String tablePrefix}) { Bar map(Map<String, dynamic> data, {String tablePrefix}) {
return Bar.fromData(data, return Bar.fromData(data,
prefix: tablePrefix != null ? '$tablePrefix.' : null); prefix: tablePrefix != null ? '$tablePrefix.' : null);

View File

@ -1,20 +1,23 @@
#!/bin/bash #!/bin/bash
set -e set -e
echo "- Generate drift"
(cd ../drift && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) function generate() {
echo "- Generate docs" echo "------------- Generate: $1 -------------"
(cd ../docs && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) pushd $1 > /dev/null
echo "- Generate benchmarks" dart pub upgrade
(cd ../extras/benchmarks && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) dart run build_runner build --delete-conflicting-outputs
echo "- Generate integration_tests/tests" popd > /dev/null
(cd ../extras/integration_tests/tests && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) }
echo "- Generate integration_tests/web"
(cd ../extras/integration_tests/web && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) cd "$(dirname "$0")/.."
echo "- Generate migrations_example" generate 'drift'
(cd ../extras/migrations_example && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) generate 'drift_dev'
echo "- Generate web_worker_example" generate 'docs'
(cd ../extras/web_worker_example && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) generate 'extras/benchmarks'
echo "- Generate with_built_value" generate 'extras/integration_tests/drift_testcases'
(cd ../extras/with_built_value && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) generate 'extras/integration_tests/web'
echo "- Generate flutter_web_worker_example" generate 'examples/app'
(cd ../extras/flutter_web_worker_example && rm -rf .dart_tool && dart pub get && dart run build_runner build --delete-conflicting-outputs) generate 'examples/flutter_web_worker_example'
generate 'examples/migrations_example'
generate 'examples/web_worker_example'
generate 'examples/with_built_value'

View File

@ -2,11 +2,11 @@
EXIT_CODE=0 EXIT_CODE=0
pushd extras/drift_postgres #pushd extras/drift_postgres
echo "Running integration tests with Postgres" #echo "Running integration tests with Postgres"
dart pub upgrade #dart pub upgrade
dart test || EXIT_CODE=$? #dart test || EXIT_CODE=$?
popd #popd
pushd examples/with_built_value pushd examples/with_built_value
echo "Running build runner in with_built_value" echo "Running build runner in with_built_value"

View File

@ -1,27 +1,41 @@
#!/bin/bash #!/bin/bash
set -e set -e
cd ../drift
rm -rf .dart_tool function run_test() {
dart pub get echo "------------- Running test: $1 -------------"
pushd $1 > /dev/null
dart pub upgrade
dart format -o none --set-exit-if-changed . dart format -o none --set-exit-if-changed .
dart analyze --fatal-infos --fatal-warnings dart analyze --fatal-infos --fatal-warnings
dart run build_runner build --delete-conflicting-outputs if [[ "$2" == 'vm+web' ]]; then
dart test dart test
dart test -p chrome dart test -p chrome
elif [[ "$2" == 'web-only' ]]; then
cd ../drift_dev dart test -p chrome
rm -rf .dart_tool else
dart pub get
dart format -o none --set-exit-if-changed .
dart analyze --fatal-infos --fatal-warnings
dart test dart test
fi
popd > /dev/null
}
cd ../sqlparser function run_test_flutter() {
rm -rf .dart_tool echo "------------- Running flutter test: $1 -------------"
dart pub get pushd $1 > /dev/null
flutter pub upgrade
flutter clean
dart format -o none --set-exit-if-changed . dart format -o none --set-exit-if-changed .
dart analyze --fatal-infos --fatal-warnings flutter analyze --fatal-infos --fatal-warnings
dart test flutter test $2
popd > /dev/null
}
cd .. cd ..
./tool/misc_integration_test.sh run_test 'drift' 'vm+web'
run_test 'drift_dev'
run_test 'sqlparser'
run_test_flutter 'drift_sqflite' 'integration_test'
run_test_flutter 'examples/app'
run_test 'examples/migrations_example'
run_test_flutter 'extras/integration_tests/ffi_on_flutter' 'integration_test/drift_native.dart'
run_test 'extras/integration_tests/web' 'web-only'
#run_test 'extras/drift_postgres'