Unverified Commit b8597f0a authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

Move usage flutter create tests into memory filesystem. (#35160)

parent d41eeeb5
......@@ -17,7 +17,6 @@ import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/dart/sdk.dart';
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart';
......@@ -1055,68 +1054,6 @@ void main() {
HttpClientFactory: () =>
() => MockHttpClient(404, result: 'not found'),
});
group('usageValues', () {
testUsingContext('set template type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=module', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'module'));
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'app'));
await runner.run(<String>['create', '--no-pub', '--template=package', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'package'));
await runner.run(<String>['create', '--no-pub', '--template=plugin', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'plugin'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('set iOS host language type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'objc'));
await runner.run(<String>[
'create',
'--no-pub',
'--template=app',
'--ios-language=swift',
projectDir.path,
]);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'swift'));
}, timeout: allowForCreateFlutterProject);
testUsingContext('set Android host language type as usage value', () async {
Cache.flutterRoot = '../..';
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--no-pub', '--template=app', projectDir.path]);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'java'));
await runner.run(<String>[
'create',
'--no-pub',
'--template=app',
'--android-language=kotlin',
projectDir.path,
]);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'kotlin'));
}, timeout: allowForCreateFlutterProject);
});
}
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:args/command_runner.dart';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/commands/create.dart';
import 'package:flutter_tools/src/doctor.dart';
import 'package:flutter_tools/src/usage.dart';
import '../src/common.dart';
import '../src/testbed.dart';
void main() {
group('usageValues', () {
Testbed testbed;
setUpAll(() {
Cache.disableLocking();
});
setUp(() {
testbed = Testbed(setup: () {
final List<String> paths = <String>[
fs.path.join('flutter', 'packages', 'flutter', 'pubspec.yaml'),
fs.path.join('flutter', 'packages', 'flutter_driver', 'pubspec.yaml'),
fs.path.join('flutter', 'packages', 'flutter_test', 'pubspec.yaml'),
fs.path.join('flutter', 'bin', 'cache', 'artifacts', 'gradle_wrapper', 'wrapper'),
fs.path.join('usr', 'local', 'bin', 'adb'),
fs.path.join('Android', 'platform-tools', 'foo'),
];
for (String path in paths) {
fs.file(path).createSync(recursive: true);
}
}, overrides: <Type, Generator>{
DoctorValidatorsProvider: () => FakeDoctorValidatorsProvider(),
});
});
test('set template type as usage value', () => testbed.run(() async {
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=module', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'module'));
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=app', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'app'));
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=package', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'package'));
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=plugin', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateProjectType, 'plugin'));
}));
test('set iOS host language type as usage value', () => testbed.run(() async {
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=app', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'objc'));
await runner.run(<String>[
'create',
'--flutter-root=flutter',
'--no-pub',
'--template=app',
'--ios-language=swift',
'testy',
]);
expect(await command.usageValues, containsPair(kCommandCreateIosLanguage, 'swift'));
}));
test('set Android host language type as usage value', () => testbed.run(() async {
final CreateCommand command = CreateCommand();
final CommandRunner<void> runner = createTestCommandRunner(command);
await runner.run(<String>['create', '--flutter-root=flutter', '--no-pub', '--template=app', 'testy']);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'java'));
await runner.run(<String>[
'create',
'--flutter-root=flutter',
'--no-pub',
'--template=app',
'--android-language=kotlin',
'testy',
]);
expect(await command.usageValues, containsPair(kCommandCreateAndroidLanguage, 'kotlin'));
}));
});
}
class FakeDoctorValidatorsProvider implements DoctorValidatorsProvider {
@override
List<DoctorValidator> get validators => <DoctorValidator>[];
@override
List<Workflow> get workflows => <Workflow>[];
}
......@@ -13,6 +13,7 @@ import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/context_runner.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/version.dart';
import 'context.dart';
......@@ -28,6 +29,7 @@ final Map<Type, Generator> _testbedDefaults = <Type, Generator>{
Logger: () => BufferLogger(), // Allows reading logs and prevents stdout.
OutputPreferences: () => OutputPreferences(showColor: false), // configures BufferLogger to avoid color codes.
Usage: () => NoOpUsage(), // prevent addition of analytics from burdening test mocks
FlutterVersion: () => FakeFlutterVersion() // prevent requirement to mock git for test runner.
};
/// Manages interaction with the tool injection and runner system.
......@@ -140,4 +142,68 @@ class NoOpUsage implements Usage {
@override
void sendTiming(String category, String variableName, Duration duration, {String label}) {}
}
\ No newline at end of file
}
class FakeFlutterVersion implements FlutterVersion {
@override
String get channel => 'master';
@override
Future<void> checkFlutterVersionFreshness() async { }
@override
bool checkRevisionAncestry({String tentativeDescendantRevision, String tentativeAncestorRevision}) {
throw UnimplementedError();
}
@override
String get dartSdkVersion => '12';
@override
String get engineRevision => '42.2';
@override
String get engineRevisionShort => '42';
@override
Future<void> ensureVersionFile() async { }
@override
String get frameworkAge => null;
@override
String get frameworkCommitDate => null;
@override
String get frameworkDate => null;
@override
String get frameworkRevision => null;
@override
String get frameworkRevisionShort => null;
@override
String get frameworkVersion => null;
@override
String getBranchName({bool redactUnknownBranches = false}) {
return 'master';
}
@override
String getVersionString({bool redactUnknownBranches = false}) {
return 'v0.0.0';
}
@override
bool get isMaster => true;
@override
String get repositoryUrl => null;
@override
Map<String, Object> toJson() {
return null;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment