Skip to content

Commit

Permalink
Test to detect new libraries added to the Dart SDK. (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos committed Nov 21, 2023
1 parent 6ca23d0 commit c78b207
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/tag/dart_sdk_libraries_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:convert';
import 'dart:io';

import 'package:http/http.dart';
import 'package:test/test.dart';

/// This tests loads the library specification of the Dart SDK and tests if
/// all of them are mentioned in `lib/src/tag/_specs.dart`.
void main() {
test('Dart SDK libraries exist in _specs.dart', () async {
final rs = await get(Uri.parse(
'https://raw.githubusercontent.com/dart-lang/sdk/main/sdk/lib/libraries.json'));
expect(rs.statusCode, 200);
final parsed = json.decode(rs.body) as Map;
final allLibraries = <String>{};
for (final topLevel in parsed.entries) {
final tlv = topLevel.value;
if (tlv is! Map) {
continue;
}
final libraries = tlv['libraries'];
if (libraries is Map) {
allLibraries.addAll(libraries.keys.whereType<String>());
}
}
final publicLibraries =
allLibraries.where((e) => !e.startsWith('_')).toList();

final exempted = {
'vmservice',
'vmservice_io',
};
final specContent = await File('lib/src/tag/_specs.dart').readAsString();
for (final lib in publicLibraries) {
if (exempted.contains(lib)) {
continue;
}
expect(specContent, contains("'$lib'"));
}
});
}

0 comments on commit c78b207

Please sign in to comment.