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

Commit 755e897

Browse files
committed
added script to massage stable channel tests
1 parent d0d9362 commit 755e897

File tree

6 files changed

+131
-2
lines changed

6 files changed

+131
-2
lines changed

.cirrus.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ task:
197197
- export CIRRUS_CHANGE_MESSAGE=""
198198
- export CIRRUS_COMMIT_MESSAGE=""
199199
- ./script/tool_runner.sh lint-android # must come after build-examples
200+
stable_channel_conditional_script:
201+
- dart ./ci/stable_conditional.dart $CHANNEL
200202
native_unit_test_script:
201203
# Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they
202204
# might include non-ASCII characters which makes Gradle crash.

ci/stable_conditional.dart

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
//
5+
// stable_conditional.dart
6+
//
7+
// Performs simple find and replace operations for conditional compilation
8+
// before executing stable channel tests.
9+
//
10+
// Example input:
11+
// int main() {
12+
// // FLUTTER_STABLE_CHANNEL_BEGIN
13+
// printf("hello world\n");
14+
// // FLUTTER_STABLE_CHANNEL_REPLACE
15+
// // printf("goodbye world\n");
16+
// // FLUTTER_STABLE_CHANNEL_END
17+
// }
18+
//
19+
// Example output:
20+
// int main() {
21+
// printf("goodbye world\n");
22+
// }
23+
24+
import 'dart:convert' show LineSplitter;
25+
import 'dart:io' show Directory, FileSystemEntity, File;
26+
27+
final RegExp _isSourceRegex =
28+
RegExp(r'\.cc$|\.java$|\.m$\.h$|\.c$|\.swift$|\.kt$');
29+
final RegExp _replacer = RegExp(
30+
r'^\s*// FLUTTER_STABLE_CHANNEL_BEGIN(.*?)^\s*// FLUTTER_STABLE_CHANNEL_REPLACE(.*?)^\s*// FLUTTER_STABLE_CHANNEL_END',
31+
multiLine: true,
32+
dotAll: true);
33+
final RegExp _commentRemover = RegExp(r'^(\s*)\/+\s*(.*)');
34+
const String _newline = '\n';
35+
36+
bool _isSourceFile(FileSystemEntity entity) =>
37+
_isSourceRegex.hasMatch(entity.path);
38+
39+
void _process(FileSystemEntity entity) {
40+
const LineSplitter splitter = LineSplitter();
41+
final String text = File(entity.path).readAsStringSync();
42+
String replaced = '';
43+
int index = 0;
44+
for (final RegExpMatch match in _replacer.allMatches(text)) {
45+
replaced += text.substring(index, match.start);
46+
for (final String line in splitter.convert(match.group(2)!)) {
47+
final RegExpMatch? commentRemoverMatch = _commentRemover.firstMatch(line);
48+
if (commentRemoverMatch != null) {
49+
replaced += commentRemoverMatch.group(1)! +
50+
commentRemoverMatch.group(2)! +
51+
_newline;
52+
}
53+
}
54+
index = match.end;
55+
}
56+
if (replaced.isNotEmpty) {
57+
replaced += text.substring(index, text.length);
58+
File(entity.path).writeAsStringSync(replaced);
59+
print('modified: ${entity.path}');
60+
}
61+
}
62+
63+
void main(List<String> args) {
64+
final String channel = args[0];
65+
if (channel == 'stable') {
66+
final Directory dir = Directory('.');
67+
dir.list(recursive: true).where(_isSourceFile).forEach(_process);
68+
}
69+
}

packages/android_intent/android/src/test/java/io/flutter/plugins/androidintent/MethodCallHandlerImplTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ public void startListening_registersChannel() {
5555
methodCallHandler.startListening(messenger);
5656

5757
verify(messenger, times(1))
58+
// FLUTTER_STABLE_CHANNEL_BEGIN
5859
.setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class), eq(null));
60+
// FLUTTER_STABLE_CHANNEL_REPLACE
61+
// .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
62+
// FLUTTER_STABLE_CHANNEL_END
5963
}
6064

6165
@Test
@@ -67,9 +71,15 @@ public void startListening_unregistersExistingChannel() {
6771
methodCallHandler.startListening(secondMessenger);
6872

6973
// Unregisters the first and then registers the second.
74+
// FLUTTER_STABLE_CHANNEL_BEGIN
7075
verify(firstMessenger, times(1)).setMessageHandler(CHANNEL_NAME, null, null);
7176
verify(secondMessenger, times(1))
7277
.setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class), eq(null));
78+
// FLUTTER_STABLE_CHANNEL_REPLACE
79+
// verify(firstMessenger, times(1)).setMessageHandler(CHANNEL_NAME, null);
80+
// verify(secondMessenger, times(1))
81+
// .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
82+
// FLUTTER_STABLE_CHANNEL_END
7383
}
7484

7585
@Test
@@ -79,7 +89,11 @@ public void stopListening_unregistersExistingChannel() {
7989

8090
methodCallHandler.stopListening();
8191

92+
// FLUTTER_STABLE_CHANNEL_BEGIN
8293
verify(messenger, times(1)).setMessageHandler(CHANNEL_NAME, null, null);
94+
// FLUTTER_STABLE_CHANNEL_REPLACE
95+
// verify(messenger, times(1)).setMessageHandler(CHANNEL_NAME, null);
96+
// FLUTTER_STABLE_CHANNEL_END
8397
}
8498

8599
@Test
@@ -88,7 +102,11 @@ public void stopListening_doesNothingWhenUnset() {
88102

89103
methodCallHandler.stopListening();
90104

105+
// FLUTTER_STABLE_CHANNEL_BEGIN
91106
verify(messenger, never()).setMessageHandler(CHANNEL_NAME, null, null);
107+
// FLUTTER_STABLE_CHANNEL_REPLACE
108+
// verify(messenger, never()).setMessageHandler(CHANNEL_NAME, null);
109+
// FLUTTER_STABLE_CHANNEL_END
92110
}
93111

94112
@Test

packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/DartMessengerTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ public class DartMessengerTest {
3232
private static class FakeBinaryMessenger implements BinaryMessenger {
3333
private final List<ByteBuffer> sentMessages = new ArrayList<>();
3434

35+
// TODO(aaclarke): Remove when https://github.com/flutter/engine/pull/29147 is on master.
36+
// FLUTTER_STABLE_CHANNEL_BEGIN
3537
@Override
36-
BinaryMessenger.TaskQueue makeBackgroundTaskQueue() {
38+
public BinaryMessenger.TaskQueue makeBackgroundTaskQueue() {
3739
return null;
3840
}
41+
// FLUTTER_STABLE_CHANNEL_REPLACE
42+
// FLUTTER_STABLE_CHANNEL_END
3943

4044
@Override
4145
public void send(@NonNull String channel, ByteBuffer message) {
@@ -47,11 +51,17 @@ public void send(@NonNull String channel, ByteBuffer message, BinaryReply callba
4751
send(channel, message);
4852
}
4953

54+
// TODO(aaclarke): Remove when https://github.com/flutter/engine/pull/29147 is on master.
55+
// FLUTTER_STABLE_CHANNEL_BEGIN
5056
@Override
5157
public void setMessageHandler(
5258
@NonNull String channel,
5359
BinaryMessageHandler handler,
5460
@Nullable BinaryMessenger.TaskQueue taskQueue) {}
61+
// FLUTTER_STABLE_CHANNEL_REPLACE
62+
// @Override
63+
// public void setMessageHandler(@NonNull String channel, BinaryMessageHandler handler) {}
64+
// FLUTTER_STABLE_CHANNEL_END
5565

5666
List<ByteBuffer> getMessages() {
5767
return new ArrayList<>(sentMessages);

packages/quick_actions/quick_actions/android/src/test/java/io/flutter/plugins/quickactions/QuickActionsTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ public class QuickActionsTest {
3333
private static class TestBinaryMessenger implements BinaryMessenger {
3434
public MethodCall lastMethodCall;
3535

36+
// TODO(aaclarke): Remove when https://github.com/flutter/engine/pull/29147 is on master.
37+
// FLUTTER_STABLE_CHANNEL_BEGIN
3638
@Override
37-
BinaryMessenger.TaskQueue makeBackgroundTaskQueue() {
39+
public BinaryMessenger.TaskQueue makeBackgroundTaskQueue() {
3840
return null;
3941
}
42+
// FLUTTER_STABLE_CHANNEL_REPLACE
43+
// FLUTTER_STABLE_CHANNEL_END
4044

4145
@Override
4246
public void send(@NonNull String channel, @Nullable ByteBuffer message) {
@@ -54,13 +58,21 @@ public void send(
5458
}
5559
}
5660

61+
// TODO(aaclarke): Remove when https://github.com/flutter/engine/pull/29147 is on master.
62+
// FLUTTER_STABLE_CHANNEL_BEGIN
5763
@Override
5864
public void setMessageHandler(
5965
@NonNull String channel,
6066
@Nullable BinaryMessageHandler handler,
6167
@Nullable BinaryMessenger.TaskQueue taskQueue) {
6268
// Do nothing.
6369
}
70+
// FLUTTER_STABLE_CHANNEL_REPLACE
71+
// @Override
72+
// public void setMessageHandler(
73+
// @NonNull String channel,
74+
// @Nullable BinaryMessageHandler handler) {}
75+
// FLUTTER_STABLE_CHANNEL_END
6476
}
6577

6678
static final int SUPPORTED_BUILD = 25;

packages/url_launcher/url_launcher/android/src/test/java/io/flutter/plugins/urllauncher/MethodCallHandlerImplTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ public void startListening_registersChannel() {
4444
methodCallHandler.startListening(messenger);
4545

4646
verify(messenger, times(1))
47+
// FLUTTER_STABLE_CHANNEL_BEGIN
4748
.setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class), eq(null));
49+
// FLUTTER_STABLE_CHANNEL_REPLACE
50+
// .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
51+
// FLUTTER_STABLE_CHANNEL_END
4852
}
4953

5054
@Test
@@ -56,9 +60,15 @@ public void startListening_unregistersExistingChannel() {
5660
methodCallHandler.startListening(secondMessenger);
5761

5862
// Unregisters the first and then registers the second.
63+
// FLUTTER_STABLE_CHANNEL_BEGIN
5964
verify(firstMessenger, times(1)).setMessageHandler(CHANNEL_NAME, null, null);
6065
verify(secondMessenger, times(1))
6166
.setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class), eq(null));
67+
// FLUTTER_STABLE_CHANNEL_REPLACE
68+
// verify(firstMessenger, times(1)).setMessageHandler(CHANNEL_NAME, null);
69+
// verify(secondMessenger, times(1))
70+
// .setMessageHandler(eq(CHANNEL_NAME), any(BinaryMessageHandler.class));
71+
// FLUTTER_STABLE_CHANNEL_END
6272
}
6373

6474
@Test
@@ -68,7 +78,11 @@ public void stopListening_unregistersExistingChannel() {
6878

6979
methodCallHandler.stopListening();
7080

81+
// FLUTTER_STABLE_CHANNEL_BEGIN
7182
verify(messenger, times(1)).setMessageHandler(CHANNEL_NAME, null, null);
83+
// FLUTTER_STABLE_CHANNEL_REPLACE
84+
// verify(messenger, times(1)).setMessageHandler(CHANNEL_NAME, null);
85+
// FLUTTER_STABLE_CHANNEL_END
7286
}
7387

7488
@Test
@@ -77,7 +91,11 @@ public void stopListening_doesNothingWhenUnset() {
7791

7892
methodCallHandler.stopListening();
7993

94+
// FLUTTER_STABLE_CHANNEL_BEGIN
8095
verify(messenger, never()).setMessageHandler(CHANNEL_NAME, null, null);
96+
// FLUTTER_STABLE_CHANNEL_REPLACE
97+
// verify(messenger, never()).setMessageHandler(CHANNEL_NAME, null);
98+
// FLUTTER_STABLE_CHANNEL_END
8199
}
82100

83101
@Test

0 commit comments

Comments
 (0)