Skip to content

Commit

Permalink
Test refactoring by folders. Running tests for all existing inputs.
Browse files Browse the repository at this point in the history
  • Loading branch information
desistefanova committed Mar 17, 2022
1 parent 827b437 commit 20dd56d
Show file tree
Hide file tree
Showing 63 changed files with 120 additions and 139 deletions.
21 changes: 21 additions & 0 deletions generator/test/error_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:realm_generator/realm_generator.dart';
import 'package:test/test.dart';
import 'test_util.dart';

void main() {
const directory = 'test/error_test_data';
getListOfTestFiles(directory).forEach((inputFile, outputFile) {
executeTest(getTestName(inputFile), () async {
await expectLater(
() async => await generatorTestBuilder(directory, inputFile),
throwsA(
isA<RealmInvalidGenerationSourceError>().having(
(e) => e.format(),
'format()',
await readFileAsErrorFormattedString(directory, outputFile),
),
),
);
});
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm only support indexes on String, int, and bool fields

in: asset:pkg/test/generator_test_io/bool_not_allowed_as_primary_key.dart:9:8
in: asset:pkg/test/error_test_data/bool_not_allowed_as_primary_key.dart:9:8
5 │ @RealmModel()
6 │ @MapTo('Bad')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm only support indexes on String, int, and bool fields

in: asset:pkg/test/generator_test_io/bool_not_allowed_on_indexed_field.dart:9:8
in: asset:pkg/test/error_test_data/bool_not_allowed_on_indexed_field.dart:9:8
5 │ @RealmModel()
6 │ @MapTo('Bad')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Duplicate definition

in: asset:pkg/test/generator_test_io/defining_both_class_prefixes.dart:9:7
in: asset:pkg/test/error_test_data/defining_both_class_prefixes.dart:9:7
5 │ @RealmModel()
6 │ class $Bad1 {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Duplicate primary keys

in: asset:pkg/test/generator_test_io/double_primary_key.dart:11:15
in: asset:pkg/test/error_test_data/double_primary_key.dart:11:15
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
No constructors allowed on realm model classes

in: asset:pkg/test/generator_test_io/illigal_constructor.dart:10:3
in: asset:pkg/test/error_test_data/illigal_constructor.dart:10:3
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm model classes can only extend Object

in: asset:pkg/test/generator_test_io/invalid_extend.dart:8:7
in: asset:pkg/test/error_test_data/invalid_extend.dart:8:7
7 │ @RealmModel()
8 │ class _Bad extends Base {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Invalid class name

in: asset:pkg/test/generator_test_io/invalid_model_name_mapping.dart:7:8
in: asset:pkg/test/error_test_data/invalid_model_name_mapping.dart:7:8
6 │ @RealmModel()
7 │ @MapTo(one) // <- invalid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Missing prefix on realm model name

in: asset:pkg/test/generator_test_io/invalid_model_name_prefix.dart:6:7
in: asset:pkg/test/error_test_data/invalid_model_name_prefix.dart:6:7
5 │ @RealmModel()
6 │ class Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Not a realm type

in: asset:pkg/test/generator_test_io/list_of_list_not_supported.dart:8:21
in: asset:pkg/test/error_test_data/list_of_list_not_supported.dart:8:21
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Field type not supported yet

in: asset:pkg/test/generator_test_io/map_unsupported.dart:7:8
in: asset:pkg/test/error_test_data/map_unsupported.dart:7:8
5 │ @RealmModel()
6 │ class _Person {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Not a realm type

in: asset:pkg/test/generator_test_io/missing_underscore.dart:7:8
in: asset:pkg/test/error_test_data/missing_underscore.dart:7:8
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm object references must be nullable

in: asset:pkg/test/generator_test_io/non_nullable_realm_object_reference.dart:13:8
in: asset:pkg/test/error_test_data/non_nullable_realm_object_reference.dart:13:8
8 │ @RealmModel()
9 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Not a realm type

in: asset:pkg/test/generator_test_io/not_a_realm_type.dart:9:8
in: asset:pkg/test/error_test_data/not_a_realm_type.dart:9:8
5 │ class NonRealm {}
│ ━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm only support indexes on String, int, and bool fields

in: asset:pkg/test/generator_test_io/not_an_indexable_type.dart:9:8
in: asset:pkg/test/error_test_data/not_an_indexable_type.dart:9:8
6 │ @RealmModel()
7 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Realm collections cannot be nullable

in: asset:pkg/test/generator_test_io/nullable_list.dart:10:3
in: asset:pkg/test/error_test_data/nullable_list.dart:10:3
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Nullable realm objects are not allowed in collections

in: asset:pkg/test/generator_test_io/nullable_list_elements.dart:14:8
in: asset:pkg/test/error_test_data/nullable_list_elements.dart:14:8
8 │ @RealmModel()
9 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Primary key cannot be nullable

in: asset:pkg/test/generator_test_io/primary_key_cannot_be_nullable.dart:8:3
in: asset:pkg/test/error_test_data/primary_key_cannot_be_nullable.dart:8:3
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Repeated annotation

in: asset:pkg/test/generator_test_io/repeated_class_annotations.dart:7:1
in: asset:pkg/test/error_test_data/repeated_class_annotations.dart:7:1
5 │ @RealmModel()
│ ━━━━━━━━━━━━━
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Repeated annotation

in: asset:pkg/test/generator_test_io/repeated_field_annotations.dart:9:3
in: asset:pkg/test/error_test_data/repeated_field_annotations.dart:9:3
5 │ @RealmModel()
6 │ class _Bad {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Duplicate definition

in: asset:pkg/test/generator_test_io/reusing_map_to_name.dart:11:7
in: asset:pkg/test/error_test_data/reusing_map_to_name.dart:11:7
5 │ @RealmModel()
6 │ @MapTo('Bad3')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Field type not supported yet

in: asset:pkg/test/generator_test_io/set_unsupported.dart:7:8
in: asset:pkg/test/error_test_data/set_unsupported.dart:7:8
5 │ @RealmModel()
6 │ class _Person {
Expand Down
79 changes: 0 additions & 79 deletions generator/test/generator_test.dart

This file was deleted.

20 changes: 5 additions & 15 deletions generator/test/good_test.dart
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@

import 'test_util.dart';

void main() {
final tests = {
'required argument with default value',
'required argument',
'list initialization',
'optional argument',
'user defined getter',
};

for (var testData in tests) {
var fileName = testData.replaceAll(' ', '_');

generatorTest(testData, () async {
await generatorTestBuilder('good_test_io', '$fileName.dart', '$fileName.expected');
const directory = 'test/good_test_data';
getListOfTestFiles(directory).forEach((inputFile, outputFile) {
executeTest(getTestName(inputFile), () async {
await generatorTestBuilder(directory, inputFile, outputFile);
});
}
});
}
File renamed without changes.
32 changes: 32 additions & 0 deletions generator/test/info_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'package:build_test/build_test.dart';
import 'package:realm_generator/realm_generator.dart';
import 'package:test/test.dart';
import 'test_util.dart';

void main() {
const directory = 'test/info_test_data';
getListOfTestFiles(directory).forEach((inputFile, outputFile) {
executeTest(getTestName(inputFile), () async {
final sb = StringBuffer();
var done = false;

await testBuilder(
generateRealmObjects(),
await getInputFileAsset('$directory/$inputFile'),
reader: await PackageAssetReader.currentIsolate(),
onLog: (l) {
if (!done) {
// disregard all, but first record
sb.writeln(l);
done = true;
}
},
);

expect(
sb.toString(),
await readFileAsErrorFormattedString(directory, outputFile),
);
});
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[INFO] testBuilder: Indexed is implied for a primary key

in: asset:pkg/test/generator_test_io/primary_key_always_indexed.dart:9:12
in: asset:pkg/test/info_test_data/primary_key_always_indexed.dart:9:12
7 │ @PrimaryKey()
8 │ @Indexed()
Expand Down

0 comments on commit 20dd56d

Please sign in to comment.