Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the check for the expected number of categorized libraries in Dart SDK #3962

Merged
merged 2 commits into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions tool/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -937,8 +937,8 @@ Not all files are formatted:
Future<void> validateSdkDocs() async {
await docSdk();
const expectedLibCount = 0;
const expectedSubLibCounts = {19, 20, 21};
const expectedTotalCounts = {19, 20, 21};
const expectedSubLibCount = 20;
const expectedTotalCount = 20;
var indexHtml = File(path.join(_sdkDocsDir.path, 'index.html'));
if (!indexHtml.existsSync()) {
throw StateError("No 'index.html' found for the SDK docs");
Expand All @@ -953,10 +953,11 @@ Future<void> validateSdkDocs() async {
}
print("Found $foundLibCount 'dart:' entries in 'index.html'");

var foundSubLibCount =
_findCount(indexContents, '<li class="section-subitem"><a href="dart-');
if (!expectedSubLibCounts.contains(foundSubLibCount)) {
throw StateError("Expected $expectedSubLibCounts 'dart:' entries in "
var libLinkPattern =
RegExp('<li class="section-subitem"><a [^>]*href="dart-');
var foundSubLibCount = _findCount(indexContents, libLinkPattern);
if (expectedSubLibCount != foundSubLibCount) {
throw StateError("Expected $expectedSubLibCount 'dart:' entries in "
"'index.html' to be in categories, but found $foundSubLibCount");
}
print('$foundSubLibCount index.html dart: entries in categories found');
Expand All @@ -965,11 +966,11 @@ Future<void> validateSdkDocs() async {
var libraries =
_sdkDocsDir.listSync().where((fs) => fs.path.contains('dart-'));
var libraryCount = libraries.length;
if (!expectedTotalCounts.contains(libraryCount)) {
if (expectedTotalCount != libraryCount) {
var libraryNames =
libraries.map((l) => "'${path.basename(l.path)}'").join(', ');
throw StateError('Unexpected docs generated for SDK libraries; expected '
'$expectedTotalCounts directories, but $libraryCount directories were '
'$expectedTotalCount directories, but $libraryCount directories were '
'generated: $libraryNames');
}
print("Found $libraryCount 'dart:' libraries");
Expand All @@ -987,12 +988,12 @@ final Directory _sdkDocsDir =
Directory.systemTemp.createTempSync('sdkdocs').absolute;

/// Returns the number of (perhaps overlapping) occurrences of [str] in [match].
int _findCount(String str, String match) {
int _findCount(String str, Pattern match) {
var count = 0;
var index = str.indexOf(match);
while (index != -1) {
count++;
index = str.indexOf(match, index + match.length);
index = str.indexOf(match, index + 1);
}
return count;
}
Expand Down
Loading