-
Notifications
You must be signed in to change notification settings - Fork 0
/
generated_files_test.dart
49 lines (40 loc) · 1.41 KB
/
generated_files_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'dart:io';
import 'package:test/test.dart';
Stream<File> listGeneratedFilesInLib() => Directory('lib')
.list(recursive: true)
.where((entity) => entity is File)
.cast<File>()
.where((file) => file.path.endsWith('.g.dart'));
void main() {
test(
'generated files are up to date',
timeout: Timeout.parse('10m'),
() async {
final originalContents = {
await for (final file in listGeneratedFilesInLib())
file.path: await file.readAsString(),
};
final buildResult = Process.runSync(Platform.resolvedExecutable,
['run', 'build_runner', 'build', '--delete-conflicting-outputs']);
expect(buildResult.exitCode, 0);
final updatedContents = {
await for (final file in listGeneratedFilesInLib())
file.path: await file.readAsString(),
};
for (final originalPath in originalContents.keys) {
// File was deleted by build
expect(updatedContents, contains(originalPath));
}
for (final updatedPath in updatedContents.keys) {
// File was created by build
expect(originalContents, contains(updatedPath));
}
for (final MapEntry(key: path, value: originalContent)
in originalContents.entries) {
final updatedContent = updatedContents[path]!;
// File was modified by build
expect(originalContent, equals(updatedContent));
}
},
);
}