@@ -7,10 +7,8 @@ import 'dart:io';
77
88import '_test_app_driver.dart' ;
99
10- enum TestFileArgItems { experimentsOn, appPath }
11-
12- const _defaultFlutterAppPath = 'test/test_infra/fixtures/flutter_app' ;
13- const _defaultDartCliAppPath = 'test/test_infra/fixtures/empty_app.dart' ;
10+ const defaultFlutterAppPath = 'test/test_infra/fixtures/flutter_app' ;
11+ const defaultDartCliAppPath = 'test/test_infra/fixtures/empty_app.dart' ;
1412
1513/// Test arguments, defined inside the test file as a comment.
1614class TestFileArgs {
@@ -22,56 +20,46 @@ class TestFileArgs {
2220 return TestFileArgs .fromFileContent (content, testAppDevice: testAppDevice);
2321 }
2422
23+ /// Returns a [TestFileArgs] parsed from [fileContent] .
24+ ///
25+ /// Separate from [TestFileArgs.new] for easier testing.
2526 factory TestFileArgs .fromFileContent (
2627 String fileContent, {
2728 required TestAppDevice testAppDevice,
2829 }) {
29- final testFileArgItems = _parseFileContent (fileContent);
30-
31- for ( final arg in testFileArgItems.keys) {
32- testFileArgItems. putIfAbsent (arg, () => null );
33- }
34-
35- return TestFileArgs .parse (testFileArgItems, testAppDevice : testAppDevice );
30+ final args = _parseFileContent (fileContent);
31+ final appPath =
32+ args[ _TestFileArgItems .appPath] ??
33+ (testAppDevice == TestAppDevice .cli
34+ ? defaultDartCliAppPath
35+ : defaultFlutterAppPath);
36+ return TestFileArgs ._parse (args, appPath : appPath );
3637 }
3738
38- TestFileArgs .parse (
39- Map <TestFileArgItems , dynamic > map, {
40- required TestAppDevice testAppDevice,
41- }) : experimentsOn = map[TestFileArgItems .experimentsOn] ?? false ,
42- appPath =
43- map[TestFileArgItems .appPath] ??
44- (testAppDevice == TestAppDevice .cli
45- ? _defaultDartCliAppPath
46- : _defaultFlutterAppPath);
39+ TestFileArgs ._parse (
40+ Map <_TestFileArgItems , dynamic > args, {
41+ required this .appPath,
42+ }) : experimentsOn = args[_TestFileArgItems .experimentsOn] ?? false ;
4743
48- /// If true, experiments will be enabled in the test.
44+ /// Whether experiments are enabled in the test.
4945 final bool experimentsOn;
5046
51- /// Path to the application to connect to.
47+ /// The path to the application to connect to.
5248 final String appPath;
53- }
5449
55- final _argRegex = RegExp (
56- r'^\/\/\s*test-argument\s*:\s*(\w*)\s*=\s*(\S*)\s*$' ,
57- multiLine: true ,
58- );
59-
60- Map <TestFileArgItems , dynamic > _parseFileContent (String fileContent) {
61- final matches = _argRegex.allMatches (fileContent);
62-
63- final entries = matches.map <MapEntry <TestFileArgItems , dynamic >>((
64- RegExpMatch m,
65- ) {
66- final name = m.group (1 ) ?? '' ;
67- if (name.isEmpty) {
68- throw ArgumentError (
69- 'Name of test argument should be provided: [${m .group (0 )}].' ,
70- );
71- }
72- final value = m.group (2 ) ?? '' ;
73- return MapEntry (TestFileArgItems .values.byName (name), jsonDecode (value));
74- });
50+ /// Parses 'test-argument' comments in [fileContent] .
51+ static Map <_TestFileArgItems , dynamic > _parseFileContent (String fileContent) {
52+ return {
53+ for (final m in _argRegex.allMatches (fileContent))
54+ _TestFileArgItems .values.byName (m.group (1 )! ): jsonDecode (m.group (2 )! ),
55+ };
56+ }
7557
76- return Map .fromEntries (entries);
58+ static final _argRegex = RegExp (
59+ r'^\/\/\s*test-argument\s*:\s*(\w+)\s*=\s*(\S*)\s*$' ,
60+ multiLine: true ,
61+ );
7762}
63+
64+ /// The different arguments accepted as "file args."
65+ enum _TestFileArgItems { experimentsOn, appPath }
0 commit comments