Skip to content

Commit

Permalink
Generator fixes (realm#982)
Browse files Browse the repository at this point in the history
* print the exception stacktrace if generator encounters an exception

throw on no expected file found
generator tests are named after the exact file name
  • Loading branch information
blagoev authored Oct 24, 2022
1 parent 63c76c4 commit 72c5552
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"name": "Dart: Attach to Process",
"type": "dart",
"request": "attach",
"observatoryUri": "http://127.0.0.1:8181/CvAvF39i-48=/",
"vmServiceUri": "http://127.0.0.1:5858",
"packages": "package:realm/main.dart"
},
{
Expand Down
2 changes: 1 addition & 1 deletion generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class _Car {
* Use a terminal to launch a debuggee with command

```
dart --observe --pause-isolates-on-start --enable-vm-service:5858/127.0.0.1 --disable-service-auth-codes .dart_tool/build/entrypoint/build.dart build
dart run --observe --pause-isolates-on-start --enable-vm-service:5858/127.0.0.1 --disable-service-auth-codes .dart_tool/build/entrypoint/build.dart build
```

##### The "Dart" name and logo and the "Flutter" name and logo are trademarks owned by Google.
2 changes: 1 addition & 1 deletion generator/lib/src/class_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ extension ClassElementEx on ClassElement {
} catch (e, s) {
// Fallback. Not perfect, but better than just forwarding original error.
throw RealmInvalidGenerationSourceError(
'$e',
'$e \n $s',
todo: //
'Unexpected error. Please open an issue on: '
'https://github.com/realm/realm-dart',
Expand Down
2 changes: 1 addition & 1 deletion generator/lib/src/field_element_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ extension FieldElementEx on FieldElement {
} catch (e, s) {
// Fallback. Not perfect, but better than just forwarding original error.
throw RealmInvalidGenerationSourceError(
'$e',
'$e \n $s',
todo: //
'Unexpected error. Please open an issue on: '
'https://github.com/realm/realm-dart',
Expand Down
10 changes: 6 additions & 4 deletions generator/test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ Map<String, String> getListOfTestFiles(String directory) {
for (var file in files) {
if (_path.extension(file.path) == '.dart' && !file.path.endsWith('g.dart')) {
var expectedFileName = _path.setExtension(file.path, '.expected');
if (!files.any((f) => f.path == expectedFileName)) expectedFileName = '';
if (!files.any((f) => f.path == expectedFileName)) {
throw "Expected file not found. $expectedFileName";
}
result.addAll({_path.basename(file.path): _path.basename(expectedFileName)});
}
}
return result;
}

Future<dynamic> generatorTestBuilder(String directoryName, String inputFileName, [String expectedFileName = ""]) async {
Future<dynamic> generatorTestBuilder(String directoryName, String inputFileName, [String? expectedFileName]) async {
return testBuilder(generateRealmObjects(), await getInputFileAsset('$directoryName/$inputFileName'),
outputs: expectedFileName.isNotEmpty ? await getExpectedFileAsset('$directoryName/$inputFileName', '$directoryName/$expectedFileName') : null,
outputs: expectedFileName != null ? await getExpectedFileAsset('$directoryName/$inputFileName', '$directoryName/$expectedFileName') : null,
reader: await PackageAssetReader.currentIsolate());
}

Expand Down Expand Up @@ -114,5 +116,5 @@ String _stringReplacements(String content) {
}

String getTestName(String file) {
return _path.basename(file.replaceAll('_', ' '));
return _path.basename(file);
}

0 comments on commit 72c5552

Please sign in to comment.