From d0491dcf15e35c348432c46033a9315fc587691b Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Wed, 9 Nov 2022 15:47:05 -0800 Subject: [PATCH] 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 --- .../config/skeletons/dartpad-sample.html | 2 +- dev/tools/dartdoc.dart | 32 +++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/dev/snippets/config/skeletons/dartpad-sample.html b/dev/snippets/config/skeletons/dartpad-sample.html index 48b726b30b..6913021cd8 100644 --- a/dev/snippets/config/skeletons/dartpad-sample.html +++ b/dev/snippets/config/skeletons/dartpad-sample.html @@ -13,7 +13,7 @@

{@end-inject-html} \ No newline at end of file diff --git a/dev/tools/dartdoc.dart b/dev/tools/dartdoc.dart index f7f94c8374..7c9ffaf009 100644 --- a/dev/tools/dartdoc.dart +++ b/dev/tools/dartdoc.dart @@ -394,7 +394,7 @@ void _sanityCheckExample(String fileString, String regExpString) { final RegExp regExp = RegExp(regExpString, dotAll: true); final String contents = file.readAsStringSync(); if (!regExp.hasMatch(contents)) { - throw Exception("Missing example code in ${file.path}. Either it didn't get published, publishing has changed, or the example no longer exists."); + throw Exception("Missing example code matching '$regExpString' in ${file.path}."); } } else { throw Exception( @@ -403,7 +403,7 @@ void _sanityCheckExample(String fileString, String regExpString) { } /// Runs a sanity check by running a test. -void sanityCheckDocs() { +void sanityCheckDocs([Platform platform = const LocalPlatform()]) { final List canaries = [ '$kPublishRoot/assets/overrides.css', '$kPublishRoot/api/dart-io/File-class.html', @@ -414,6 +414,7 @@ void sanityCheckDocs() { '$kPublishRoot/api/material/Material-class.html', '$kPublishRoot/api/material/Tooltip-class.html', '$kPublishRoot/api/widgets/Widget-class.html', + '$kPublishRoot/api/widgets/Listener-class.html', ]; for (final String canary in canaries) { if (!File(canary).existsSync()) { @@ -434,11 +435,28 @@ void sanityCheckDocs() { r'\s*.*Color\s+get\s+barrierColor.*', ); - // Check a "dartpad" example, any one will do. - _sanityCheckExample( - '$kPublishRoot/api/widgets/PhysicalShape-class.html', - r'\s*\s*', - ); + // Check a "dartpad" example, any one will do, and check for the correct URL + // arguments. + // Just use "master" for any branch other than the LUCH_BRANCH. + final String? luciBranch = platform.environment['LUCI_BRANCH']?.trim(); + final String expectedBranch = luciBranch != null && luciBranch.isNotEmpty ? luciBranch : 'master'; + final List argumentRegExps = [ + r'split=\d+', + r'run=true', + r'null_safety=true', + r'sample_id=widgets\.Listener\.\d+', + 'sample_channel=$expectedBranch', + 'channel=$expectedBranch', + ]; + for (final String argumentRegExp in argumentRegExps) { + _sanityCheckExample( + '$kPublishRoot/api/widgets/Listener-class.html', + r'\s*\s*<\/iframe>', + ); + } } /// Creates a custom index.html because we try to maintain old