Skip to content

Commit 915812c

Browse files
authored
[flutter_tools] Add tests for negative lookahead regex in test runner and batch entrypoints (flutter#191438)
## Description Fixes flutter#84270 The root cause of flutter#84270 (delayed variable expansion in batch scripts stripping `!` from CLI arguments like `^(?!Golden).+`) was previously addressed in flutter#106861, which removed `SETLOCAL ENABLEDELAYEDEXPANSION` from `bin/flutter.bat`, `bin/dart.bat`, and `bin/internal/shared.bat`. However, flutter#84270 was left open without dedicated regression tests. This PR: 1. Adds a hermetic unit test in `test_test.dart` verifying that `TestCommand` preserves and forwards negative lookahead regexes (`^(?!Golden).+`) to `FlutterTestRunner`. 2. Adds a case-insensitive static test in `script_test.dart` asserting that Windows entrypoint batch scripts do not enable delayed expansion. 3. Unskips and modernizes the integration test in `variable_expansion_windows_test.dart` verifying that `bin/dart.bat` preserves lookahead regexes on Windows. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/
1 parent a3191ed commit 915812c

3 files changed

Lines changed: 59 additions & 20 deletions

File tree

‎packages/flutter_tools/test/commands.shard/hermetic/test_test.dart‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,6 +1757,24 @@ resolution: workspace
17571757
ProcessManager: () => FakeProcessManager.any(),
17581758
},
17591759
);
1760+
1761+
testUsingContext(
1762+
'passes regular expression lookahead in --name argument to test runner',
1763+
() async {
1764+
final testRunner = FakeFlutterTestRunner(0);
1765+
1766+
final testCommand = TestCommand(testRunner: testRunner);
1767+
final CommandRunner<void> commandRunner = createTestCommandRunner(testCommand);
1768+
1769+
await commandRunner.run(const <String>['test', '--name', r'^(?!Golden).+', '--no-pub']);
1770+
1771+
expect(testRunner.lastNames, <String>[r'^(?!Golden).+']);
1772+
},
1773+
overrides: <Type, Generator>{
1774+
FileSystem: () => fs,
1775+
ProcessManager: () => FakeProcessManager.any(),
1776+
},
1777+
);
17601778
}
17611779

17621780
class FakeFlutterTestRunner implements FlutterTestRunner {
@@ -1771,6 +1789,8 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
17711789
int? lastConcurrency;
17721790
TestWatcher? lastTestWatcher;
17731791
FakeVmServiceHost? fakeVmServiceHost;
1792+
List<String> lastNames = const <String>[];
1793+
List<String> lastPlainNames = const <String>[];
17741794

17751795
@override
17761796
Future<int> runTests(
@@ -1817,6 +1837,8 @@ class FakeFlutterTestRunner implements FlutterTestRunner {
18171837
lastReporterOption = reporter;
18181838
lastConcurrency = concurrency;
18191839
lastTestWatcher = watcher;
1840+
lastNames = names;
1841+
lastPlainNames = plainNames;
18201842

18211843
if (leastRunTime != null) {
18221844
await Future<void>.delayed(leastRunTime!);

‎packages/flutter_tools/test/commands.shard/permeable/script_test.dart‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,24 @@ void main() {
3030
},
3131
skip: !Platform.isWindows, // [intended] relies on Windows's cmd.exe
3232
);
33+
34+
testUsingContext('windows entrypoint batch scripts do not enable delayed expansion', () {
35+
final String flutterRoot = getFlutterRoot();
36+
final File flutterBat = globals.fs.file(
37+
globals.fs.path.join(flutterRoot, 'bin', 'flutter.bat'),
38+
);
39+
final File dartBat = globals.fs.file(globals.fs.path.join(flutterRoot, 'bin', 'dart.bat'));
40+
final File sharedBat = globals.fs.file(
41+
globals.fs.path.join(flutterRoot, 'bin', 'internal', 'shared.bat'),
42+
);
43+
44+
expect(flutterBat.existsSync(), isTrue);
45+
expect(dartBat.existsSync(), isTrue);
46+
expect(sharedBat.existsSync(), isTrue);
47+
48+
final delayedExpansionPattern = RegExp(r'ENABLEDELAYEDEXPANSION', caseSensitive: false);
49+
expect(flutterBat.readAsStringSync(), isNot(contains(delayedExpansionPattern)));
50+
expect(dartBat.readAsStringSync(), isNot(contains(delayedExpansionPattern)));
51+
expect(sharedBat.readAsStringSync(), isNot(contains(delayedExpansionPattern)));
52+
});
3353
}

‎packages/flutter_tools/test/integration.shard/variable_expansion_windows_test.dart‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,21 @@ import 'test_utils.dart';
99

1010
void main() {
1111
// Regression test for https://github.com/flutter/flutter/issues/84270 .
12-
testWithoutContext(
13-
'dart command will expand variables on windows',
14-
() async {
15-
final ProcessResult result = await processManager.run(<String>[
16-
fileSystem.path.join(getFlutterRoot(), 'bin', 'dart'),
17-
fileSystem.path.join(
18-
getFlutterRoot(),
19-
'packages',
20-
'flutter_tools',
21-
'test',
22-
'integration.shard',
23-
'variable_expansion_windows.dart',
24-
),
25-
'"^(?!Golden).+"',
26-
]);
27-
expect(result.stdout, contains('args: ["(?!Golden).+"]'));
28-
},
29-
// https://github.com/flutter/flutter/issues/87934
30-
skip: 'Reverted in https://github.com/flutter/flutter/pull/86000',
31-
);
12+
testWithoutContext('dart command will not expand variables on windows', () async {
13+
final ProcessResult result = await processManager.run(<String>[
14+
fileSystem.path.join(getFlutterRoot(), 'bin', 'dart.bat'),
15+
fileSystem.path.join(
16+
getFlutterRoot(),
17+
'packages',
18+
'flutter_tools',
19+
'test',
20+
'integration.shard',
21+
'variable_expansion_windows.dart',
22+
),
23+
'"^(?!Golden).+"',
24+
]);
25+
expect(result.exitCode, 0, reason: 'Process failed with stderr: ${result.stderr}');
26+
expect(result.stdout, contains('(?!Golden)'));
27+
expect(result.stdout, isNot(contains('(?Golden)')));
28+
}, skip: !platform.isWindows);
3229
}

0 commit comments

Comments
 (0)