Skip to content

Commit daaa32b

Browse files
authored
Add CustomDimensions.commandRunIsTest (#124135)
1 parent 0cfcdee commit daaa32b

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

packages/flutter_tools/lib/src/commands/run.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ class RunCommand extends RunCommandBase {
498498
commandRunAndroidEmbeddingVersion: androidEmbeddingVersion,
499499
commandRunEnableImpeller: enableImpeller.asBool,
500500
commandRunIOSInterfaceType: iOSInterfaceType,
501+
commandRunIsTest: targetFile.endsWith('_test.dart'),
501502
);
502503
}
503504

packages/flutter_tools/lib/src/reporting/custom_dimensions.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class CustomDimensions {
6868
this.hotEventReloadVMTimeInMs,
6969
this.commandRunEnableImpeller,
7070
this.commandRunIOSInterfaceType,
71+
this.commandRunIsTest,
7172
});
7273

7374
final String? sessionHostOsDetails; // cd1
@@ -127,6 +128,7 @@ class CustomDimensions {
127128
final int? hotEventReloadVMTimeInMs; // cd 55
128129
final bool? commandRunEnableImpeller; // cd 56
129130
final String? commandRunIOSInterfaceType; // cd 57
131+
final bool? commandRunIsTest; // cd 58
130132

131133
/// Convert to a map that will be used to upload to the analytics backend.
132134
Map<String, String> toMap() => <String, String>{
@@ -187,6 +189,7 @@ class CustomDimensions {
187189
if (hotEventReloadVMTimeInMs != null) cdKey(CustomDimensionsEnum.hotEventReloadVMTimeInMs): hotEventReloadVMTimeInMs.toString(),
188190
if (commandRunEnableImpeller != null) cdKey(CustomDimensionsEnum.commandRunEnableImpeller): commandRunEnableImpeller.toString(),
189191
if (commandRunIOSInterfaceType != null) cdKey(CustomDimensionsEnum.commandRunIOSInterfaceType): commandRunIOSInterfaceType.toString(),
192+
if (commandRunIsTest != null) cdKey(CustomDimensionsEnum.commandRunIsTest): commandRunIsTest.toString(),
190193
};
191194

192195
/// Merge the values of two [CustomDimensions] into one. If a value is defined
@@ -254,6 +257,7 @@ class CustomDimensions {
254257
hotEventReloadVMTimeInMs: other.hotEventReloadVMTimeInMs ?? hotEventReloadVMTimeInMs,
255258
commandRunEnableImpeller: other.commandRunEnableImpeller ?? commandRunEnableImpeller,
256259
commandRunIOSInterfaceType: other.commandRunIOSInterfaceType ?? commandRunIOSInterfaceType,
260+
commandRunIsTest: other.commandRunIsTest ?? commandRunIsTest,
257261
);
258262
}
259263

@@ -315,6 +319,7 @@ class CustomDimensions {
315319
hotEventReloadVMTimeInMs: _extractInt(map, CustomDimensionsEnum.hotEventReloadVMTimeInMs),
316320
commandRunEnableImpeller: _extractBool(map, CustomDimensionsEnum.commandRunEnableImpeller),
317321
commandRunIOSInterfaceType: _extractString(map, CustomDimensionsEnum.commandRunIOSInterfaceType),
322+
commandRunIsTest: _extractBool(map, CustomDimensionsEnum.commandRunIsTest),
318323
);
319324

320325
static bool? _extractBool(Map<String, String> map, CustomDimensionsEnum field) =>
@@ -402,6 +407,7 @@ enum CustomDimensionsEnum {
402407
hotEventReloadVMTimeInMs, // cd55
403408
commandRunEnableImpeller, // cd56
404409
commandRunIOSInterfaceType, // cd57
410+
commandRunIsTest, // cd58
405411
}
406412

407413
String cdKey(CustomDimensionsEnum cd) => 'cd${cd.index + 1}';

packages/flutter_tools/test/commands.shard/hermetic/run_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ void main() {
475475
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
476476
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
477477
'cd57': 'usb',
478+
'cd58': 'false',
478479
})
479480
)));
480481
}, overrides: <Type, Generator>{
@@ -488,6 +489,41 @@ void main() {
488489
Usage: () => usage,
489490
});
490491

492+
testUsingContext('correctly reports tests to usage', () async {
493+
fs.currentDirectory.childDirectory('test').childFile('widget_test.dart').createSync(recursive: true);
494+
fs.currentDirectory.childDirectory('ios').childFile('AppDelegate.swift').createSync(recursive: true);
495+
final RunCommand command = RunCommand();
496+
final FakeDevice mockDevice = FakeDevice(sdkNameAndVersion: 'iOS 13')
497+
..startAppSuccess = false;
498+
499+
testDeviceManager.devices = <Device>[mockDevice];
500+
501+
await expectToolExitLater(createTestCommandRunner(command).run(<String>[
502+
'run',
503+
'--no-pub',
504+
'--no-hot',
505+
'test/widget_test.dart',
506+
]), isNull);
507+
508+
expect(usage.commands, contains(
509+
TestUsageCommand('run', parameters: CustomDimensions.fromMap(<String, String>{
510+
'cd3': 'false', 'cd4': 'ios', 'cd22': 'iOS 13',
511+
'cd23': 'debug', 'cd18': 'false', 'cd15': 'swift', 'cd31': 'true',
512+
'cd57': 'usb',
513+
'cd58': 'true',
514+
})),
515+
));
516+
}, overrides: <Type, Generator>{
517+
AnsiTerminal: () => fakeTerminal,
518+
Artifacts: () => artifacts,
519+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
520+
DeviceManager: () => testDeviceManager,
521+
FileSystem: () => fs,
522+
ProcessManager: () => FakeProcessManager.any(),
523+
Stdio: () => FakeStdio(),
524+
Usage: () => usage,
525+
});
526+
491527
group('--machine', () {
492528
testUsingContext('enables multidex by default', () async {
493529
final DaemonCapturingRunCommand command = DaemonCapturingRunCommand();
@@ -745,6 +781,7 @@ void main() {
745781
commandRunModeName: 'debug',
746782
commandRunProjectModule: false,
747783
commandRunProjectHostLanguage: '',
784+
commandRunIsTest: false,
748785
));
749786
}, overrides: <Type, Generator>{
750787
DeviceManager: () => testDeviceManager,
@@ -785,6 +822,7 @@ void main() {
785822
commandRunProjectModule: false,
786823
commandRunProjectHostLanguage: '',
787824
commandRunIOSInterfaceType: 'usb',
825+
commandRunIsTest: false,
788826
));
789827
}, overrides: <Type, Generator>{
790828
DeviceManager: () => testDeviceManager,
@@ -828,6 +866,7 @@ void main() {
828866
commandRunProjectModule: false,
829867
commandRunProjectHostLanguage: '',
830868
commandRunIOSInterfaceType: 'wireless',
869+
commandRunIsTest: false,
831870
));
832871
}, overrides: <Type, Generator>{
833872
DeviceManager: () => testDeviceManager,
@@ -871,6 +910,7 @@ void main() {
871910
commandRunProjectModule: false,
872911
commandRunProjectHostLanguage: '',
873912
commandRunIOSInterfaceType: 'wireless',
913+
commandRunIsTest: false,
874914
));
875915
}, overrides: <Type, Generator>{
876916
DeviceManager: () => testDeviceManager,

0 commit comments

Comments
 (0)