|
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | 5 | import 'dart:io'; |
| 6 | +import 'dart:math'; |
6 | 7 |
|
| 8 | +import 'package:args/args.dart'; |
7 | 9 | import 'package:flutter/material.dart'; |
8 | 10 | import 'package:flutter/scheduler.dart'; |
9 | 11 | import 'package:flutter_test/flutter_test.dart'; |
@@ -93,9 +95,44 @@ Future<void> main() async { |
93 | 95 | ), |
94 | 96 | ]; |
95 | 97 |
|
96 | | - print('╡ ••• Running microbenchmarks ••• ╞'); |
| 98 | + // Parses the optional compile-time dart variables; we can't have |
| 99 | + // arguments passed in to main. |
| 100 | + final ArgParser parser = ArgParser(); |
| 101 | + final List<String> allowed = benchmarks.map((Benchmark e) => e.$1).toList(); |
| 102 | + parser.addMultiOption( |
| 103 | + 'tests', |
| 104 | + abbr: 't', |
| 105 | + defaultsTo: allowed, |
| 106 | + allowed: allowed, |
| 107 | + help: 'selected tests to run', |
| 108 | + ); |
| 109 | + parser.addOption( |
| 110 | + 'seed', |
| 111 | + defaultsTo: '12345', |
| 112 | + help: 'selects seed to sort tests by', |
| 113 | + ); |
| 114 | + final List<String> mainArgs = <String>[]; |
| 115 | + const String testArgs = String.fromEnvironment('tests'); |
| 116 | + if (testArgs.isNotEmpty) { |
| 117 | + mainArgs.addAll(<String>['--tests', testArgs]); |
| 118 | + print('╡ ••• environment test override: $testArgs ••• ╞'); |
| 119 | + } |
| 120 | + const String seedArgs = String.fromEnvironment('seed'); |
| 121 | + if (seedArgs.isNotEmpty) { |
| 122 | + mainArgs.addAll(<String>['--seed', seedArgs]); |
| 123 | + print('╡ ••• environment seed override: $seedArgs ••• ╞'); |
| 124 | + } |
| 125 | + final ArgResults results = parser.parse(mainArgs); |
| 126 | + final List<String> selectedTests = results.multiOption('tests'); |
97 | 127 |
|
98 | | - for (final Benchmark mark in benchmarks) { |
| 128 | + // Shuffle the tests becauase we don't want order dependent tests. |
| 129 | + // It is the responsibily of the infra to tell us what the seed value is, |
| 130 | + // in case we want to have the seed stable for some time period. |
| 131 | + final List<Benchmark> tests = benchmarks.where((Benchmark e) => selectedTests.contains(e.$1)).toList(); |
| 132 | + tests.shuffle(Random(int.parse(results.option('seed')!))); |
| 133 | + |
| 134 | + print('╡ ••• Running microbenchmarks ••• ╞'); |
| 135 | + for (final Benchmark mark in tests) { |
99 | 136 | // Reset the frame policy to default - each test can set it on their own. |
100 | 137 | binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.fadePointers; |
101 | 138 | print('╡ ••• Running ${mark.$1} ••• ╞'); |
|
0 commit comments