Files
sdk/pkg/dartdev/test/analytics_test.dart
T
Sigurd Meldgaard f3fe9dc3b3 Reland "Improve handling of disable-dartdev-analytics"
This is a reland of 58860f4814

Original change's description:
> Improve handling of disable-dartdev-analytics
>
> This is second try of https://dart-review.googlesource.com/c/sdk/+/171284
> that was reverted to to faulty logic in main_options.
>
> Some other refactorings are piggy-backed along.
>
> TestProject.runSync no longer takes a 'command' argument. It was anyway
> often not an argument.
>
> Also stop the messy handling of pub arguments. It is no longer needed.
>
> BUG: https://github.com/dart-lang/sdk/issues/44135
> Change-Id: I49abf5810d9ea262409ba9d93f0471037cb8a753
> TEST=The VM change is tested via all the pkg/dartdev/test/command/* tests that invoke dart with the --no-analytics flag.
> TEST=Furthermore manual test that the --no-analytics flag is passed to dartdev.
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174261
> Reviewed-by: Jonas Jensen <jonasfj@google.com>
> Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>

Change-Id: I725662f578d061f87171ceffe9aff3de83688f58
TEST=Furthermore run the vm-kernel-precomp-obfuscate-linux-release-x64-try trybot
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174473
Commit-Queue: Sigurd Meldgaard <sigurdm@google.com>
Reviewed-by: Jonas Jensen <jonasfj@google.com>
2020-12-04 14:22:10 +00:00

266 lines
6.7 KiB
Dart

// Copyright (c) 2020, 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:convert';
import 'dart:io';
import 'package:dartdev/src/analytics.dart';
import 'package:test/test.dart';
import 'utils.dart';
List<Map> extractAnalytics(ProcessResult result) {
return LineSplitter.split(result.stderr)
.where((line) => line.startsWith('[analytics]: '))
.map((line) => json.decode(line.substring('[analytics]: '.length)) as Map)
.toList();
}
void main() {
group('DisabledAnalytics', disabledAnalyticsObject);
group('Sending analytics', () {
test('help', () {
final p = project(logAnalytics: true);
final result = p.runSync(['help']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'help'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'help',
'label': null,
'value': null
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'help',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('create', () {
final p = project(logAnalytics: true);
final result = p.runSync(['create', '-tpackage-simple', 'name']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'create'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'create',
'label': null,
'value': null,
'cd1': '0',
'cd3': ' template ',
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'create',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('pub get', () {
final p = project(logAnalytics: true);
final result = p.runSync(['pub', 'get', '--dry-run']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'pub/get'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'pub/get',
'label': null,
'value': null,
'cd1': '0',
'cd3': ' dry-run '
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'pub/get',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('format', () {
final p = project(logAnalytics: true);
final result = p.runSync(['format', '-l80']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'format'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'format',
'label': null,
'value': null,
'cd1': '0',
'cd3': ' line-length ',
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'format',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('run', () {
final p = project(
mainSrc: 'void main(List<String> args) => print(args)',
logAnalytics: true);
final result = p.runSync([
'run',
'--no-pause-isolates-on-exit',
'--enable-asserts',
'lib/main.dart',
'--argument'
]);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'run'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'run',
'label': null,
'value': null,
'cd1': '0',
'cd3': ' enable-asserts pause-isolates-on-exit ',
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'run',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('run --enable-experiments', () {
final p = project(
mainSrc: 'void main(List<String> args) => print(args);',
logAnalytics: true);
final result = p.runSync([
'run',
'--enable-experiment=non-nullable',
'lib/main.dart',
]);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'run'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'run',
'label': null,
'value': null,
'cd1': '0',
'cd2': ' non-nullable ',
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'run',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
test('compile', () {
final p = project(
mainSrc: 'void main(List<String> args) => print(args);',
logAnalytics: true);
final result = p
.runSync(['compile', 'kernel', 'lib/main.dart', '-o', 'main.kernel']);
expect(extractAnalytics(result), [
{
'hitType': 'screenView',
'message': {'viewName': 'compile/kernel'}
},
{
'hitType': 'event',
'message': {
'category': 'dartdev',
'action': 'compile/kernel',
'label': null,
'value': null,
'cd1': '0',
'cd3': ' output ',
}
},
{
'hitType': 'timing',
'message': {
'variableName': 'compile/kernel',
'time': isA<int>(),
'category': 'commands',
'label': null
}
}
]);
});
});
}
void disabledAnalyticsObject() {
test('object', () {
var diabledAnalytics = DisabledAnalytics('trackingId', 'appName');
expect(diabledAnalytics.trackingId, 'trackingId');
expect(diabledAnalytics.applicationName, 'appName');
expect(diabledAnalytics.enabled, isFalse);
expect(diabledAnalytics.firstRun, isFalse);
});
}