You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dateKeys-dart/tool/release_copy.dart

57 lines
2.0 KiB

// Writes test/vectors/release.g.dart: the text of
// testdata/vectors/release.json, every file of testdata/releases/ in
// hexadecimal, and the text of test/vectors/release_archive_texts.json, as
// Dart constants for test/release_object_test.dart compiled to JavaScript,
// where no file can be read. test/release_object_vm_test.dart checks that
// the copy is the files byte for byte. Run it after every sync of testdata/.
//
// dart run tool/release_copy.dart
import 'dart:io';
void main() {
final root = File(Platform.script.toFilePath()).parent.parent;
String text(String path) {
final s = File('${root.path}/$path').readAsStringSync();
if (s.contains("'''")) throw StateError('$path holds three quotes');
return s;
}
final files =
Directory('${root.path}/testdata/releases')
.listSync()
.whereType<File>()
.toList()
..sort((a, b) => a.path.compareTo(b.path));
final out = StringBuffer()
..write(
'// Generated by tool/release_copy.dart from\n'
'// testdata/vectors/release.json, testdata/releases/ and\n'
'// test/vectors/release_archive_texts.json, for the tests that also\n'
'// run compiled to JavaScript, where no file can be read. Do not edit.\n'
'\n'
'/// The text of testdata/vectors/release.json.\n'
"const releaseJson = r'''\n"
"${text('testdata/vectors/release.json')}''';\n"
'\n'
'/// The files of testdata/releases/, by name, in hexadecimal.\n'
'const releaseFiles = {\n',
);
for (final f in files) {
final name = f.uri.pathSegments.last;
final hex = [
for (final b in f.readAsBytesSync()) b.toRadixString(16).padLeft(2, '0'),
].join();
out.write(" '$name': '$hex',\n");
}
out.write(
'};\n'
'\n'
'/// The text of test/vectors/release_archive_texts.json.\n'
"const releaseArchiveTextsJson = r'''\n"
"${text('test/vectors/release_archive_texts.json')}''';\n",
);
File('${root.path}/test/vectors/release.g.dart')
.writeAsStringSync(out.toString());
}

Powered by TurnKey Linux.