Add failing test for #447

This commit is contained in:
Simon Binder 2020-03-18 13:09:18 +01:00
parent 5b675a811b
commit 2da8577b01
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
2 changed files with 41 additions and 4 deletions

View File

@ -10,13 +10,15 @@ class AnalyzeDartStep extends AnalyzingStep {
for (final accessor in parseResult.dbAccessors) {
final transitiveImports = _transitiveImports(accessor.imports);
var availableEntities = _availableEntities(transitiveImports)
.followedBy(accessor.declaredTables)
.toList();
final unsortedEntities = _availableEntities(transitiveImports)
.followedBy(accessor.declaredTables);
List<MoorSchemaEntity> availableEntities;
try {
availableEntities = sortEntitiesTopologically(availableEntities);
availableEntities = sortEntitiesTopologically(unsortedEntities.toSet());
} on CircularReferenceException catch (e) {
// Just keep them unsorted so that we can generate some code
availableEntities = unsortedEntities.toList();
final msg = StringBuffer(
'Found a circular reference in your database. This can cause '
'exceptions at runtime when opening the database. This is the '

View File

@ -0,0 +1,35 @@
import 'package:moor_generator/src/analyzer/runner/results.dart';
import 'package:test/test.dart';
import '../utils.dart';
void main() {
test("tables imported in two ways aren't duplicated", () async {
final state = TestState.withContent({
'foo|lib/main.dart': '''
import 'package:moor/moor.dart';
import 'table.dart';
@UseMoor(tables: [Users], include: {'file.moor'})
class MyDatabase {}
''',
'foo|lib/file.moor': '''
import 'table.dart';
''',
'foo|lib/table.dart': '''
import 'package:moor/moor.dart';
class Users extends Table {
IntColumn get id => integer().autoIncrement()();
}
'''
});
final dbFile = await state.analyze('package:foo/main.dart');
final db =
(dbFile.currentResult as ParsedDartFile).declaredDatabases.single;
expect(db.entities, hasLength(1));
}, skip: 'https://github.com/simolus3/moor/issues/447');
}