-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test to detect new libraries added to the Dart SDK. (#1288)
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'")); | ||
} | ||
}); | ||
} |