Skip to content

Commit 6a9a4f0

Browse files
bkonyiCommit Queue
authored andcommitted
[ CLI ] Support --suppress-analytics before CLI commands and for dart test
Fixes #56842 TEST=pkg/dartdev/test/commands/test_test.dart Change-Id: I1692352e3847c977c72a948d26be8ef8311ec69e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390900 Commit-Queue: Ben Konyi <[email protected]> Auto-Submit: Ben Konyi <[email protected]> Reviewed-by: Derek Xu <[email protected]> Commit-Queue: Derek Xu <[email protected]>
1 parent da9d9f2 commit 6a9a4f0

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

pkg/dartdev/lib/src/commands/test.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,16 @@ Run "${runner!.executableName} help" to see global options.''');
6363
try {
6464
final testExecutable = await getExecutableForCommand('test:test',
6565
nativeAssets: nativeAssets);
66-
final argsRestNoExperiment = args.rest
67-
.where((e) => !e.startsWith('--$experimentFlagName='))
66+
final argsRestNoExperimentOrSuppressAnalytics = args.rest
67+
.where((e) =>
68+
!e.startsWith('--$experimentFlagName=') &&
69+
e != '--suppress-analytics')
6870
.toList();
69-
log.trace('dart $testExecutable ${argsRestNoExperiment.join(' ')}');
71+
log.trace(
72+
'dart $testExecutable ${argsRestNoExperimentOrSuppressAnalytics.join(' ')}');
7073
VmInteropHandler.run(
7174
testExecutable.executable,
72-
argsRestNoExperiment,
75+
argsRestNoExperimentOrSuppressAnalytics,
7376
packageConfigOverride: testExecutable.packageConfig!,
7477
// TODO(bkonyi): remove once DartDev moves to AOT and this flag can be
7578
// provided directly to the process spawned by `dart run` and

pkg/dartdev/test/commands/test_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,42 @@ void main() {
207207
expect(vm.systemIsolates!.where((e) => e.name == 'main'), isNotEmpty);
208208
});
209209

210+
// Regression tests for https://github.com/dart-lang/sdk/issues/56842
211+
group('properly handles --suppress-analytics', () {
212+
void suppressAnalyticsTest({required bool beforeCommand}) {
213+
test('${beforeCommand ? 'before' : 'after'} command', () async {
214+
final p = project(pubspecExtras: {
215+
'dev_dependencies': {'test': 'any'}
216+
});
217+
p.file('test/foo_test.dart', '''
218+
import 'package:test/test.dart';
219+
220+
void main() {
221+
test('', () {
222+
expect(1,1);
223+
});
224+
}
225+
''');
226+
227+
// An implicit `pub get` will happen.
228+
final result = await p.run([
229+
if (beforeCommand) '--suppress-analytics',
230+
'test',
231+
'--no-color',
232+
'--reporter',
233+
'expanded',
234+
if (!beforeCommand) '--suppress-analytics',
235+
]);
236+
expect(result.stderr, isEmpty);
237+
expect(result.stdout, contains('All tests passed!'));
238+
expect(result.exitCode, 0);
239+
});
240+
}
241+
242+
suppressAnalyticsTest(beforeCommand: true);
243+
suppressAnalyticsTest(beforeCommand: false);
244+
});
245+
210246
group('--enable-experiment', () {
211247
late TestProject p;
212248
Future<ProcessResult> runTestWithExperimentFlag(String? flag) async {

runtime/bin/main_options.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ bool Options::ParseArguments(int argc,
550550
} else if (IsOption(argv[i], "disable-telemetry")) {
551551
disable_dartdev_analytics = true;
552552
skipVmOption = true;
553+
} else if (IsOption(argv[i], "suppress-analytics")) {
554+
dart_options->AddArgument("--suppress-analytics");
555+
skipVmOption = true;
553556
} else if (IsOption(argv[i], "no-analytics")) {
554557
// Just add this option even if we don't go to dartdev.
555558
// It is irrelevant for the vm.

0 commit comments

Comments
 (0)