Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit d0491dc

Browse files
authored
Add the channel parameter to the Dartpad samples (#115018)
* Add the channel paramter to the Dartpad samples * Add sanity check test * Make sample_id more generic
1 parent dccc761 commit d0491dc

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

dev/snippets/config/skeletons/dartpad-sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</p>
1414
</div>
1515
<iframe class="snippet-dartpad"
16-
src="https://dartpad.dev/embed-flutter.html?split=60&amp;run=true&amp;null_safety=true&amp;sample_id={{id}}&amp;sample_channel={{channel}}">
16+
src="https://dartpad.dev/embed-flutter.html?split=60&amp;run=true&amp;null_safety=true&amp;sample_id={{id}}&amp;sample_channel={{channel}}&amp;channel={{channel}}">
1717
</iframe>
1818
</div>
1919
{@end-inject-html}

dev/tools/dartdoc.dart

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void _sanityCheckExample(String fileString, String regExpString) {
394394
final RegExp regExp = RegExp(regExpString, dotAll: true);
395395
final String contents = file.readAsStringSync();
396396
if (!regExp.hasMatch(contents)) {
397-
throw Exception("Missing example code in ${file.path}. Either it didn't get published, publishing has changed, or the example no longer exists.");
397+
throw Exception("Missing example code matching '$regExpString' in ${file.path}.");
398398
}
399399
} else {
400400
throw Exception(
@@ -403,7 +403,7 @@ void _sanityCheckExample(String fileString, String regExpString) {
403403
}
404404

405405
/// Runs a sanity check by running a test.
406-
void sanityCheckDocs() {
406+
void sanityCheckDocs([Platform platform = const LocalPlatform()]) {
407407
final List<String> canaries = <String>[
408408
'$kPublishRoot/assets/overrides.css',
409409
'$kPublishRoot/api/dart-io/File-class.html',
@@ -414,6 +414,7 @@ void sanityCheckDocs() {
414414
'$kPublishRoot/api/material/Material-class.html',
415415
'$kPublishRoot/api/material/Tooltip-class.html',
416416
'$kPublishRoot/api/widgets/Widget-class.html',
417+
'$kPublishRoot/api/widgets/Listener-class.html',
417418
];
418419
for (final String canary in canaries) {
419420
if (!File(canary).existsSync()) {
@@ -434,11 +435,28 @@ void sanityCheckDocs() {
434435
r'\s*<pre.*id="sample-code">.*Color\s+get\s+barrierColor.*</pre>',
435436
);
436437

437-
// Check a "dartpad" example, any one will do.
438-
_sanityCheckExample(
439-
'$kPublishRoot/api/widgets/PhysicalShape-class.html',
440-
r'\s*<iframe\s+class="snippet-dartpad"\s+src="https://dartpad\.dev.*sample_id=widgets\.PhysicalShape\.\d+.*">\s*</iframe>',
441-
);
438+
// Check a "dartpad" example, any one will do, and check for the correct URL
439+
// arguments.
440+
// Just use "master" for any branch other than the LUCH_BRANCH.
441+
final String? luciBranch = platform.environment['LUCI_BRANCH']?.trim();
442+
final String expectedBranch = luciBranch != null && luciBranch.isNotEmpty ? luciBranch : 'master';
443+
final List<String> argumentRegExps = <String>[
444+
r'split=\d+',
445+
r'run=true',
446+
r'null_safety=true',
447+
r'sample_id=widgets\.Listener\.\d+',
448+
'sample_channel=$expectedBranch',
449+
'channel=$expectedBranch',
450+
];
451+
for (final String argumentRegExp in argumentRegExps) {
452+
_sanityCheckExample(
453+
'$kPublishRoot/api/widgets/Listener-class.html',
454+
r'\s*<iframe\s+class="snippet-dartpad"\s+src="'
455+
r'https:\/\/dartpad.dev\/embed-flutter.html\?.*?\b'
456+
'$argumentRegExp'
457+
r'\b.*">\s*<\/iframe>',
458+
);
459+
}
442460
}
443461

444462
/// Creates a custom index.html because we try to maintain old

0 commit comments

Comments
 (0)