-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathconfiguration.dart
1120 lines (1041 loc) · 40.1 KB
/
configuration.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:boolean_selector/boolean_selector.dart';
import 'package:collection/collection.dart';
import 'package:glob/glob.dart';
import 'package:path/path.dart' as p;
import 'package:source_span/source_span.dart';
import 'package:test_api/scaffolding.dart' // ignore: deprecated_member_use
show
Timeout;
import 'package:test_api/src/backend/platform_selector.dart'; // ignore: implementation_imports
import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
import '../util/io.dart';
import 'compiler_selection.dart';
import 'configuration/args.dart' as args;
import 'configuration/custom_runtime.dart';
import 'configuration/load.dart';
import 'configuration/reporters.dart';
import 'configuration/runtime_settings.dart';
import 'configuration/utils.dart';
import 'configuration/values.dart';
import 'runtime_selection.dart';
import 'suite.dart';
export 'suite.dart' show TestSelection;
/// The key used to look up [Configuration.current] in a zone.
final _currentKey = Object();
/// A class that encapsulates the command-line configuration of the test runner.
class Configuration {
/// An empty configuration with only default values.
///
/// Using this is slightly more efficient than manually constructing a new
/// configuration with no arguments.
static final empty = Configuration._unsafe();
/// The usage string for the command-line arguments.
static String get usage => args.usage;
/// Whether `--help` was passed.
bool get help => _help ?? false;
final bool? _help;
/// Custom HTML template file.
final String? customHtmlTemplatePath;
/// Whether `--version` was passed.
bool get version => _version ?? false;
final bool? _version;
/// Whether to pause for debugging after loading each test suite.
bool get pauseAfterLoad => _pauseAfterLoad ?? false;
final bool? _pauseAfterLoad;
/// Whether to run browsers in their respective debug modes
bool get debug => pauseAfterLoad || (_debug ?? false) || coverage != null;
final bool? _debug;
/// The output folder for coverage gathering
final String? coverage;
/// The path to the file from which to load more configuration information.
///
/// This is *not* resolved automatically.
String get configurationPath => _configurationPath ?? 'dart_test.yaml';
final String? _configurationPath;
/// The name of the reporter to use to display results.
String get reporter => _reporter ?? defaultReporter;
final String? _reporter;
/// The map of file reporters where the key is the name of the reporter and
/// the value is the filepath to which its output should be written.
final Map<String, String> fileReporters;
/// Whether to disable retries of tests.
bool get noRetry => _noRetry ?? false;
final bool? _noRetry;
/// The URL for the `pub serve` instance from which to load tests, or `null`
/// if tests should be loaded from the filesystem.
final Uri? pubServeUrl;
/// Whether to use command-line color escapes.
bool get color => _color ?? canUseSpecialChars;
final bool? _color;
/// How many tests to run concurrently.
int get concurrency =>
pauseAfterLoad ? 1 : (_concurrency ?? defaultConcurrency);
final int? _concurrency;
/// The index of the current shard, if sharding is in use, or `null` if it's
/// not.
///
/// Sharding is a technique that allows the Google internal test framework to
/// easily split a test run across multiple workers without requiring the
/// tests to be modified by the user. When sharding is in use, the runner gets
/// a shard index (this field) and a total number of shards, and is expected
/// to provide the following guarantees:
///
/// * Running the same invocation of the runner, with the same shard index and
/// total shards, will run the same set of tests.
/// * Across all shards, each test must be run exactly once.
///
/// In addition, tests should be balanced across shards as much as possible.
final int? shardIndex;
/// The total number of shards, if sharding is in use, or `null` if it's not.
///
/// See [shardIndex] for details.
final int? totalShards;
/// The list of packages to fold when producing [StackTrace]s.
Set<String> get foldTraceExcept => _foldTraceExcept ?? {};
final Set<String>? _foldTraceExcept;
/// If non-empty, all packages not in this list will be folded when producing
/// [StackTrace]s.
Set<String> get foldTraceOnly => _foldTraceOnly ?? {};
final Set<String>? _foldTraceOnly;
/// The paths from which to load tests, and the test cases to run.
Map<String, Set<TestSelection>> get testSelections =>
_testSelections ??
const {
'test': {TestSelection()}
};
final Map<String, Set<TestSelection>>? _testSelections;
/// Whether the load paths were passed explicitly or the default was used.
bool get explicitPaths => _testSelections != null;
/// The glob matching the basename of tests to run.
///
/// This is used to find tests within a directory.
Glob get filename => _filename ?? defaultFilename;
final Glob? _filename;
/// The set of presets to use.
///
/// Any chosen presets for the parent configuration are added to the chosen
/// preset sets for child configurations as well.
///
/// Note that the order of this set matters.
final Set<String> chosenPresets;
/// The set of tags that have been declared in any way in this configuration.
late final Set<String> knownTags = UnmodifiableSetView({
...includeTags.variables,
...excludeTags.variables,
...suiteDefaults.knownTags,
for (var configuration in presets.values) ...configuration.knownTags
});
/// Only run tests whose tags match this selector.
///
/// When [merge]d, this is intersected with the other configuration's included
/// tags.
final BooleanSelector includeTags;
/// Do not run tests whose tags match this selector.
///
/// When [merge]d, this is unioned with the other configuration's
/// excluded tags.
final BooleanSelector excludeTags;
/// Configuration presets.
///
/// These are configurations that can be explicitly selected by the user via
/// the command line. Preset configuration takes precedence over the base
/// configuration.
///
/// This is guaranteed not to have any keys that match [chosenPresets]; those
/// are resolved when the configuration is constructed.
final Map<String, Configuration> presets;
/// All preset names that are known to be valid.
///
/// This includes presets that have already been resolved.
Set<String> get knownPresets => _knownPresets ??= UnmodifiableSetView({
...presets.keys,
for (var configuration in presets.values) ...configuration.knownPresets
});
Set<String>? _knownPresets;
/// Whether to use the original `data:` URI isolate spawning strategy for VM
/// tests.
///
/// This can make more sense than the default strategy in systems such as
/// `bazel` where only a single test suite is ran at a time.
///
/// Note that this will also override any compiler settings, it will
/// effectively use `Compiler.none` regardless of setting.
bool get useDataIsolateStrategy => _useDataIsolateStrategy ?? false;
final bool? _useDataIsolateStrategy;
/// Built-in runtimes whose settings are overridden by the user.
final Map<String, RuntimeSettings> overrideRuntimes;
/// Runtimes defined by the user in terms of existing runtimes.
final Map<String, CustomRuntime> defineRuntimes;
/// The default suite-level configuration.
final SuiteConfiguration suiteDefaults;
/// The set of patterns to check test names against in all suites that run.
final Set<Pattern> globalPatterns;
/// The seed used to generate randomness for test case shuffling.
///
/// If null or zero no shuffling will occur.
/// The same seed will shuffle the tests in the same way every time.
final int? testRandomizeOrderingSeed;
/// Returns the current configuration, or a default configuration if no
/// current configuration is set.
///
/// The current configuration is set using [asCurrent].
static Configuration get current =>
Zone.current[_currentKey] as Configuration? ?? Configuration._unsafe();
/// Parses the configuration from [args].
///
/// Throws a [FormatException] if [args] are invalid.
factory Configuration.parse(List<String> arguments) => args.parse(arguments);
/// Loads configuration from [path].
///
/// If [global] is `true`, this restricts the configuration to rules that are
/// supported globally.
///
/// Throws an [IOException] if [path] does not exist or cannot be read. Throws
/// a [FormatException] if the file contents are invalid.
factory Configuration.load(String path, {bool global = false}) {
final content = File(path).readAsStringSync();
final sourceUrl = p.toUri(path);
return parse(content, global: global, sourceUrl: sourceUrl);
}
/// Parses configuration from YAML formatted [content].
///
/// If [global] is `true`, this restricts the configuration to rules that are
/// supported globally.
///
/// If [sourceUrl] is provided it will be set as the source url for the yaml
/// document.
///
/// Throws a [FormatException] if the content is invalid.
factory Configuration.loadFromString(String content,
{bool global = false, Uri? sourceUrl}) =>
parse(content, global: global, sourceUrl: sourceUrl);
factory Configuration(
{required bool? help,
required String? customHtmlTemplatePath,
required bool? version,
required bool? pauseAfterLoad,
required bool? debug,
required bool? color,
required String? configurationPath,
required String? reporter,
required Map<String, String>? fileReporters,
required String? coverage,
required int? pubServePort,
required int? concurrency,
required int? shardIndex,
required int? totalShards,
required Map<String, Set<TestSelection>>? testSelections,
required Iterable<String>? foldTraceExcept,
required Iterable<String>? foldTraceOnly,
required Glob? filename,
required Iterable<String>? chosenPresets,
required Map<String, Configuration>? presets,
required Map<String, RuntimeSettings>? overrideRuntimes,
required Map<String, CustomRuntime>? defineRuntimes,
required bool? noRetry,
required bool? useDataIsolateStrategy,
required int? testRandomizeOrderingSeed,
// Suite-level configuration
required bool? allowDuplicateTestNames,
required bool? allowTestRandomization,
required bool? jsTrace,
required bool? runSkipped,
required Iterable<String>? dart2jsArgs,
required String? precompiledPath,
required Iterable<Pattern>? globalPatterns,
required Iterable<CompilerSelection>? compilerSelections,
required Iterable<RuntimeSelection>? runtimes,
required BooleanSelector? includeTags,
required BooleanSelector? excludeTags,
required Map<BooleanSelector, SuiteConfiguration>? tags,
required Map<PlatformSelector, SuiteConfiguration>? onPlatform,
required bool? ignoreTimeouts,
// Test-level configuration
required Timeout? timeout,
required bool? verboseTrace,
required bool? chainStackTraces,
required bool? skip,
required int? retry,
required String? skipReason,
required PlatformSelector? testOn,
required Iterable<String>? addTags}) {
var chosenPresetSet = chosenPresets?.toSet();
var configuration = Configuration._(
help: help,
customHtmlTemplatePath: customHtmlTemplatePath,
version: version,
pauseAfterLoad: pauseAfterLoad,
debug: debug,
color: color,
configurationPath: configurationPath,
reporter: reporter,
fileReporters: fileReporters,
coverage: coverage,
pubServePort: pubServePort,
concurrency: concurrency,
shardIndex: shardIndex,
totalShards: totalShards,
testSelections: testSelections,
foldTraceExcept: foldTraceExcept,
foldTraceOnly: foldTraceOnly,
filename: filename,
chosenPresets: chosenPresetSet,
presets: _withChosenPresets(presets, chosenPresetSet),
overrideRuntimes: overrideRuntimes,
defineRuntimes: defineRuntimes,
noRetry: noRetry,
useDataIsolateStrategy: useDataIsolateStrategy,
testRandomizeOrderingSeed: testRandomizeOrderingSeed,
includeTags: includeTags,
excludeTags: excludeTags,
globalPatterns: globalPatterns,
suiteDefaults: SuiteConfiguration(
allowDuplicateTestNames: allowDuplicateTestNames,
allowTestRandomization: allowTestRandomization,
jsTrace: jsTrace,
runSkipped: runSkipped,
dart2jsArgs: dart2jsArgs,
precompiledPath: precompiledPath,
compilerSelections: compilerSelections,
runtimes: runtimes,
tags: tags,
onPlatform: onPlatform,
ignoreTimeouts: ignoreTimeouts,
// Test-level configuration
timeout: timeout,
verboseTrace: verboseTrace,
chainStackTraces: chainStackTraces,
skip: skip,
retry: retry,
skipReason: skipReason,
testOn: testOn,
addTags: addTags));
return configuration._resolvePresets();
}
/// A constructor that doesn't require all of its options to be passed.
///
/// This should only be used in situations where you really only want to
/// configure a specific restricted set of options.
factory Configuration._unsafe(
{bool? help,
String? customHtmlTemplatePath,
bool? version,
bool? pauseAfterLoad,
bool? debug,
bool? color,
String? configurationPath,
String? reporter,
Map<String, String>? fileReporters,
String? coverage,
int? pubServePort,
int? concurrency,
int? shardIndex,
int? totalShards,
Map<String, Set<TestSelection>>? testSelections,
Iterable<String>? foldTraceExcept,
Iterable<String>? foldTraceOnly,
Glob? filename,
Iterable<String>? chosenPresets,
Map<String, Configuration>? presets,
Map<String, RuntimeSettings>? overrideRuntimes,
Map<String, CustomRuntime>? defineRuntimes,
bool? noRetry,
bool? useDataIsolateStrategy,
int? testRandomizeOrderingSeed,
// Suite-level configuration
bool? allowDuplicateTestNames,
bool? allowTestRandomization,
bool? jsTrace,
bool? runSkipped,
Iterable<String>? dart2jsArgs,
String? precompiledPath,
Iterable<Pattern>? globalPatterns,
Iterable<CompilerSelection>? compilerSelections,
Iterable<RuntimeSelection>? runtimes,
BooleanSelector? includeTags,
BooleanSelector? excludeTags,
Map<BooleanSelector, SuiteConfiguration>? tags,
Map<PlatformSelector, SuiteConfiguration>? onPlatform,
bool? ignoreTimeouts,
// Test-level configuration
Timeout? timeout,
bool? verboseTrace,
bool? chainStackTraces,
bool? skip,
int? retry,
String? skipReason,
PlatformSelector? testOn,
Iterable<String>? addTags}) =>
Configuration(
help: help,
customHtmlTemplatePath: customHtmlTemplatePath,
version: version,
pauseAfterLoad: pauseAfterLoad,
debug: debug,
color: color,
configurationPath: configurationPath,
reporter: reporter,
fileReporters: fileReporters,
coverage: coverage,
pubServePort: pubServePort,
concurrency: concurrency,
shardIndex: shardIndex,
totalShards: totalShards,
testSelections: testSelections,
foldTraceExcept: foldTraceExcept,
foldTraceOnly: foldTraceOnly,
filename: filename,
chosenPresets: chosenPresets,
presets: presets,
overrideRuntimes: overrideRuntimes,
defineRuntimes: defineRuntimes,
noRetry: noRetry,
useDataIsolateStrategy: useDataIsolateStrategy,
testRandomizeOrderingSeed: testRandomizeOrderingSeed,
allowDuplicateTestNames: allowDuplicateTestNames,
allowTestRandomization: allowTestRandomization,
jsTrace: jsTrace,
runSkipped: runSkipped,
dart2jsArgs: dart2jsArgs,
precompiledPath: precompiledPath,
globalPatterns: globalPatterns,
compilerSelections: compilerSelections,
runtimes: runtimes,
includeTags: includeTags,
excludeTags: excludeTags,
tags: tags,
onPlatform: onPlatform,
ignoreTimeouts: ignoreTimeouts,
timeout: timeout,
verboseTrace: verboseTrace,
chainStackTraces: chainStackTraces,
skip: skip,
retry: retry,
skipReason: skipReason,
testOn: testOn,
addTags: addTags);
/// Suite level configuration allowed in the global test config file.
///
/// This is per-user configuration and should be limited as such, it should
/// not contain options that would change the pass/fail result of any given
/// test, or change which tests would run.
factory Configuration.globalTest({
required bool? verboseTrace,
required bool? jsTrace,
required Timeout? timeout,
required Map<String, Configuration>? presets,
required bool? chainStackTraces,
required Iterable<String>? foldTraceExcept,
required Iterable<String>? foldTraceOnly,
}) =>
Configuration(
foldTraceExcept: foldTraceExcept,
foldTraceOnly: foldTraceOnly,
jsTrace: jsTrace,
timeout: timeout,
verboseTrace: verboseTrace,
chainStackTraces: chainStackTraces,
help: null,
customHtmlTemplatePath: null,
version: null,
pauseAfterLoad: null,
debug: null,
color: null,
configurationPath: null,
reporter: null,
fileReporters: null,
coverage: null,
pubServePort: null,
concurrency: null,
shardIndex: null,
totalShards: null,
testSelections: null,
filename: null,
chosenPresets: null,
presets: presets,
overrideRuntimes: null,
defineRuntimes: null,
noRetry: null,
useDataIsolateStrategy: null,
testRandomizeOrderingSeed: null,
ignoreTimeouts: null,
allowDuplicateTestNames: null,
allowTestRandomization: null,
runSkipped: null,
dart2jsArgs: null,
precompiledPath: null,
globalPatterns: null,
compilerSelections: null,
runtimes: null,
includeTags: null,
excludeTags: null,
tags: null,
onPlatform: null,
skip: null,
retry: null,
skipReason: null,
testOn: null,
addTags: null,
);
/// Suite level configuration that is not allowed in the global test
/// config file.
///
/// This configuration may alter the pass/fail result of a test run, and thus
/// should only be configured per package and not at the global level (global
/// config is user specific).
factory Configuration.localTest({
required bool? skip,
required int? retry,
required String? skipReason,
required PlatformSelector? testOn,
required Iterable<String>? addTags,
required bool? allowDuplicateTestNames,
required bool? allowTestRandomization,
}) =>
Configuration(
allowDuplicateTestNames: allowDuplicateTestNames,
allowTestRandomization: allowTestRandomization,
skip: skip,
retry: retry,
skipReason: skipReason,
testOn: testOn,
addTags: addTags,
help: null,
customHtmlTemplatePath: null,
version: null,
pauseAfterLoad: null,
debug: null,
color: null,
configurationPath: null,
reporter: null,
fileReporters: null,
coverage: null,
pubServePort: null,
concurrency: null,
shardIndex: null,
totalShards: null,
testSelections: null,
foldTraceExcept: null,
foldTraceOnly: null,
filename: null,
chosenPresets: null,
presets: null,
overrideRuntimes: null,
defineRuntimes: null,
noRetry: null,
useDataIsolateStrategy: null,
testRandomizeOrderingSeed: null,
jsTrace: null,
runSkipped: null,
dart2jsArgs: null,
precompiledPath: null,
globalPatterns: null,
compilerSelections: null,
runtimes: null,
includeTags: null,
excludeTags: null,
tags: null,
onPlatform: null,
ignoreTimeouts: null,
timeout: null,
verboseTrace: null,
chainStackTraces: null,
);
/// Runner configuration that is allowed in the global test config file.
///
/// This is per-user configuration and should be limited as such, it should
/// not contain options that would change the pass/fail result of any given
/// test, or change which tests would run.
///
/// Note that [customHtmlTemplatePath] violates this rule, and really should
/// not be configurable globally.
factory Configuration.globalRunner(
{required bool? pauseAfterLoad,
required String? customHtmlTemplatePath,
required bool? runSkipped,
required String? reporter,
required Map<String, String>? fileReporters,
required int? concurrency,
required Iterable<CompilerSelection>? compilerSelections,
required Iterable<RuntimeSelection>? runtimes,
required Iterable<String>? chosenPresets,
required Map<String, RuntimeSettings>? overrideRuntimes}) =>
Configuration(
customHtmlTemplatePath: customHtmlTemplatePath,
pauseAfterLoad: pauseAfterLoad,
runSkipped: runSkipped,
reporter: reporter,
fileReporters: fileReporters,
concurrency: concurrency,
compilerSelections: compilerSelections,
runtimes: runtimes,
chosenPresets: chosenPresets,
overrideRuntimes: overrideRuntimes,
help: null,
version: null,
debug: null,
color: null,
configurationPath: null,
coverage: null,
pubServePort: null,
shardIndex: null,
totalShards: null,
testSelections: null,
foldTraceExcept: null,
foldTraceOnly: null,
filename: null,
presets: null,
defineRuntimes: null,
noRetry: null,
useDataIsolateStrategy: null,
testRandomizeOrderingSeed: null,
allowDuplicateTestNames: null,
allowTestRandomization: null,
jsTrace: null,
dart2jsArgs: null,
precompiledPath: null,
globalPatterns: null,
includeTags: null,
excludeTags: null,
tags: null,
onPlatform: null,
ignoreTimeouts: null,
timeout: null,
verboseTrace: null,
chainStackTraces: null,
skip: null,
retry: null,
skipReason: null,
testOn: null,
addTags: null,
);
/// Runner configuration that is not allowed in the global test config file.
///
/// This configuration may alter the pass/fail result of a test run, and thus
/// should only be configured per package and not at the global level (global
/// config is user specific).
factory Configuration.localRunner(
{required int? pubServePort,
required Iterable<Pattern>? globalPatterns,
required Map<String, Set<TestSelection>>? testSelections,
required Glob? filename,
required BooleanSelector? includeTags,
required BooleanSelector? excludeTags,
required Map<String, CustomRuntime>? defineRuntimes}) =>
Configuration(
pubServePort: pubServePort,
globalPatterns: globalPatterns,
testSelections: testSelections,
filename: filename,
includeTags: includeTags,
excludeTags: excludeTags,
defineRuntimes: defineRuntimes,
help: null,
customHtmlTemplatePath: null,
version: null,
pauseAfterLoad: null,
debug: null,
color: null,
configurationPath: null,
reporter: null,
fileReporters: null,
coverage: null,
concurrency: null,
shardIndex: null,
totalShards: null,
foldTraceExcept: null,
foldTraceOnly: null,
chosenPresets: null,
presets: null,
overrideRuntimes: null,
noRetry: null,
useDataIsolateStrategy: null,
testRandomizeOrderingSeed: null,
allowDuplicateTestNames: null,
allowTestRandomization: null,
jsTrace: null,
runSkipped: null,
dart2jsArgs: null,
precompiledPath: null,
compilerSelections: null,
runtimes: null,
tags: null,
onPlatform: null,
ignoreTimeouts: null,
timeout: null,
verboseTrace: null,
chainStackTraces: null,
skip: null,
retry: null,
skipReason: null,
testOn: null,
addTags: null);
/// A specialized constructor for configuring only `onPlatform`.
factory Configuration.onPlatform(
Map<PlatformSelector, SuiteConfiguration> onPlatform) =>
Configuration._unsafe(onPlatform: onPlatform);
factory Configuration.tags(Map<BooleanSelector, SuiteConfiguration> tags) =>
Configuration._unsafe(tags: tags);
static Map<String, Configuration>? _withChosenPresets(
Map<String, Configuration>? map, Set<String>? chosenPresets) {
if (map == null || chosenPresets == null) return map;
return map.map((key, config) => MapEntry(
key,
config.change(
chosenPresets: config.chosenPresets.union(chosenPresets))));
}
/// Creates new Configuration.
///
/// Unlike [Configuration.new], this assumes [presets] is already resolved.
Configuration._(
{required bool? help,
required this.customHtmlTemplatePath,
required bool? version,
required bool? pauseAfterLoad,
required bool? debug,
required bool? color,
required String? configurationPath,
required String? reporter,
required Map<String, String>? fileReporters,
required this.coverage,
required int? pubServePort,
required int? concurrency,
required this.shardIndex,
required this.totalShards,
required Map<String, Set<TestSelection>>? testSelections,
required Iterable<String>? foldTraceExcept,
required Iterable<String>? foldTraceOnly,
required Glob? filename,
required Iterable<String>? chosenPresets,
required Map<String, Configuration>? presets,
required Map<String, RuntimeSettings>? overrideRuntimes,
required Map<String, CustomRuntime>? defineRuntimes,
required bool? noRetry,
required bool? useDataIsolateStrategy,
required this.testRandomizeOrderingSeed,
required BooleanSelector? includeTags,
required BooleanSelector? excludeTags,
required Iterable<Pattern>? globalPatterns,
required SuiteConfiguration? suiteDefaults})
: _help = help,
_version = version,
_pauseAfterLoad = pauseAfterLoad,
_debug = debug,
_color = color,
_configurationPath = configurationPath,
_reporter = reporter,
fileReporters = fileReporters ?? {},
pubServeUrl = pubServePort == null
? null
: Uri.parse('http://localhost:$pubServePort'),
_concurrency = concurrency,
_testSelections = testSelections == null || testSelections.isEmpty
? null
: Map.unmodifiable(testSelections),
_foldTraceExcept = _set(foldTraceExcept),
_foldTraceOnly = _set(foldTraceOnly),
_filename = filename,
chosenPresets = UnmodifiableSetView(chosenPresets?.toSet() ?? {}),
presets = _map(presets),
overrideRuntimes = _map(overrideRuntimes),
defineRuntimes = _map(defineRuntimes),
_noRetry = noRetry,
_useDataIsolateStrategy = useDataIsolateStrategy,
includeTags = includeTags ?? BooleanSelector.all,
excludeTags = excludeTags ?? BooleanSelector.none,
globalPatterns = globalPatterns == null
? const {}
: UnmodifiableSetView(globalPatterns.toSet()),
suiteDefaults = (() {
var config = suiteDefaults ?? SuiteConfiguration.empty;
if (pauseAfterLoad == true) {
return config.change(ignoreTimeouts: true);
}
return config;
}()) {
if (_filename != null && _filename!.context.style != p.style) {
throw ArgumentError(
"filename's context must match the current operating system, was "
'${_filename!.context.style}.');
}
if ((shardIndex == null) != (totalShards == null)) {
throw ArgumentError(
'shardIndex and totalShards may only be passed together.');
} else if (shardIndex != null) {
RangeError.checkValueInInterval(
shardIndex!, 0, totalShards! - 1, 'shardIndex');
}
}
/// Creates a new [Configuration] that takes its configuration from
/// [SuiteConfiguration].
factory Configuration.fromSuiteConfiguration(
SuiteConfiguration suiteConfig) =>
Configuration._(
suiteDefaults: suiteConfig,
globalPatterns: null,
help: null,
customHtmlTemplatePath: null,
version: null,
pauseAfterLoad: null,
debug: null,
color: null,
configurationPath: null,
reporter: null,
fileReporters: null,
coverage: null,
pubServePort: null,
concurrency: null,
shardIndex: null,
totalShards: null,
testSelections: null,
foldTraceExcept: null,
foldTraceOnly: null,
filename: null,
chosenPresets: null,
presets: null,
overrideRuntimes: null,
defineRuntimes: null,
noRetry: null,
useDataIsolateStrategy: null,
testRandomizeOrderingSeed: null,
includeTags: null,
excludeTags: null,
);
/// Returns a set from [input].
///
/// If [input] is `null` or empty, this returns `null`.
static Set<T>? _set<T>(Iterable<T>? input) {
if (input == null) return null;
var set = Set<T>.from(input);
if (set.isEmpty) return null;
return set;
}
/// Returns an unmodifiable copy of [input] or an empty unmodifiable map.
static Map<K, V> _map<K, V>(Map<K, V>? input) {
input ??= {};
return Map.unmodifiable(input);
}
/// Runs [body] with this as [Configuration.current].
///
/// This is zone-scoped, so this will be the current configuration in any
/// asynchronous callbacks transitively created by [body].
T asCurrent<T>(T Function() body) =>
runZoned(body, zoneValues: {_currentKey: this});
/// Throws a [FormatException] if this refers to any undefined runtimes.
void validateRuntimes(List<Runtime> allRuntimes) {
// We don't need to verify [customRuntimes] here because those runtimes
// already need to be verified and resolved to create [allRuntimes].
for (var settings in overrideRuntimes.values) {
if (!allRuntimes
.any((runtime) => runtime.identifier == settings.identifier)) {
throw SourceSpanFormatException(
'Unknown platform "${settings.identifier}".',
settings.identifierSpan);
}
}
suiteDefaults.validateRuntimes(allRuntimes);
for (var config in presets.values) {
config.validateRuntimes(allRuntimes);
}
}
/// Merges this with [other].
///
/// For most fields, if both configurations have values set, [other]'s value
/// takes precedence. However, certain fields are merged together instead.
/// This is indicated in those fields' documentation.
Configuration merge(Configuration other) {
if (this == Configuration.empty) return other;
if (other == Configuration.empty) return this;
var foldTraceOnly = other._foldTraceOnly ?? _foldTraceOnly;
var foldTraceExcept = other._foldTraceExcept ?? _foldTraceExcept;
if (_foldTraceOnly != null) {
if (other._foldTraceExcept != null) {
foldTraceOnly = _foldTraceOnly!.difference(other._foldTraceExcept!);
} else if (other._foldTraceOnly != null) {
foldTraceOnly = other._foldTraceOnly!.intersection(_foldTraceOnly!);
}
} else if (_foldTraceExcept != null) {
if (other._foldTraceOnly != null) {
foldTraceOnly = other._foldTraceOnly!.difference(_foldTraceExcept!);
} else if (other._foldTraceExcept != null) {
foldTraceExcept = other._foldTraceExcept!.union(_foldTraceExcept!);
}
}
var result = Configuration._(
help: other._help ?? _help,
customHtmlTemplatePath:
other.customHtmlTemplatePath ?? customHtmlTemplatePath,
version: other._version ?? _version,
pauseAfterLoad: other._pauseAfterLoad ?? _pauseAfterLoad,
debug: other._debug ?? _debug,
color: other._color ?? _color,
configurationPath: other._configurationPath ?? _configurationPath,
reporter: other._reporter ?? _reporter,
fileReporters: mergeMaps(fileReporters, other.fileReporters),
coverage: other.coverage ?? coverage,
pubServePort: (other.pubServeUrl ?? pubServeUrl)?.port,
concurrency: other._concurrency ?? _concurrency,
shardIndex: other.shardIndex ?? shardIndex,
totalShards: other.totalShards ?? totalShards,
testSelections: other._testSelections ?? _testSelections,
foldTraceExcept: foldTraceExcept,
foldTraceOnly: foldTraceOnly,
filename: other._filename ?? _filename,
chosenPresets: chosenPresets.union(other.chosenPresets),
presets: _mergeConfigMaps(presets, other.presets),
overrideRuntimes: mergeUnmodifiableMaps(
overrideRuntimes, other.overrideRuntimes,
value: (settings1, settings2) => RuntimeSettings(
settings1.identifier,
settings1.identifierSpan,
[...settings1.settings, ...settings2.settings])),
defineRuntimes:
mergeUnmodifiableMaps(defineRuntimes, other.defineRuntimes),
noRetry: other._noRetry ?? _noRetry,
useDataIsolateStrategy:
other._useDataIsolateStrategy ?? _useDataIsolateStrategy,
testRandomizeOrderingSeed:
other.testRandomizeOrderingSeed ?? testRandomizeOrderingSeed,
includeTags: includeTags.intersection(other.includeTags),
excludeTags: excludeTags.union(other.excludeTags),
globalPatterns: globalPatterns.union(other.globalPatterns),
suiteDefaults: suiteDefaults.merge(other.suiteDefaults));
result = result._resolvePresets();
// Make sure the merged config preserves any presets that were chosen and
// discarded.
result._knownPresets = knownPresets.union(other.knownPresets);
return result;
}
/// Returns a copy of this configuration with the given fields updated.
///
/// Note that unlike [merge], this has no merging behavior—the old value is
/// always replaced by the new one.
Configuration change(
{bool? help,
String? customHtmlTemplatePath,
bool? version,
bool? pauseAfterLoad,
bool? debug,
bool? color,
String? configurationPath,
String? reporter,
Map<String, String>? fileReporters,
String? coverage,
int? pubServePort,