Improve error message for schema difference

This commit is contained in:
Simon Binder
2022-08-06 21:35:05 +02:00
parent b6f6156407
commit 8cc85de5f7
2 changed files with 10 additions and 8 deletions
@@ -166,7 +166,7 @@ class FindSchemaDifferences {
if (refType != actType) {
return FoundDifference(
'Different types: ${ref.typeName} and ${act.typeName}');
'Different types: Expected ${ref.typeName}, got ${act.typeName}');
}
try {
@@ -174,19 +174,20 @@ class FindSchemaDifferences {
} catch (e) {
final firstSpan = ref.constraints.spanOrNull?.text ?? '';
final secondSpan = act.constraints.spanOrNull?.text ?? '';
return FoundDifference('Not equal: `$firstSpan` and `$secondSpan`');
return FoundDifference(
'Not equal: `$firstSpan` (expected) and `$secondSpan` (actual)');
}
return const Success();
}
CompareResult _compareByAst(AstNode a, AstNode b) {
CompareResult _compareByAst(AstNode reference, AstNode actual) {
try {
enforceEqual(a, b);
enforceEqual(reference, actual);
return const Success();
} catch (e) {
return FoundDifference(
'Not equal: `${a.span?.text}` and `${b.span?.text}`');
return FoundDifference('Not equal: Expected `${reference.span?.text}`, '
'got `${actual.span?.text}`');
}
}
@@ -70,7 +70,7 @@ void main() {
expect(result, hasChanges);
expect(
result.describe(),
contains('Different types: TEXT and INTEGER'),
contains('Different types: Expected TEXT, got INTEGER'),
);
});
@@ -83,7 +83,8 @@ void main() {
expect(result, hasChanges);
expect(
result.describe(),
contains('Not equal: `PRIMARY KEY NOT NULL` and ``'),
contains(
'Not equal: `PRIMARY KEY NOT NULL` (expected) and `` (actual)'),
);
});
});