Prevent tests from importing other tests. (#27800)

This pattern is problematic when Flutter is ported to build systems
that require each executable end-point to be self-contained (e.g.
Bazel).
This commit is contained in:
Ian Hickson
2019-02-12 12:29:36 -08:00
committed by Todd Volkert
parent ead5e8e4d7
commit 58939b70ef
11 changed files with 168 additions and 93 deletions

View File

@@ -17,7 +17,7 @@ import 'package:process/process.dart';
import '../src/common.dart';
import '../src/context.dart';
import 'flutter_command_test.dart';
import 'utils.dart';
const String _kFlutterRoot = '/flutter/flutter';
const String _kEngineRoot = '/flutter/engine';

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/usage.dart';
@@ -13,19 +11,19 @@ import 'package:mockito/mockito.dart';
import '../src/common.dart';
import '../src/context.dart';
import 'utils.dart';
void main() {
group('Flutter Command', () {
MockCache cache;
MockitoCache cache;
MockitoUsage usage;
MockClock clock;
MockUsage usage;
List<int> mockTimes;
setUp(() {
cache = MockCache();
cache = MockitoCache();
usage = MockitoUsage();
clock = MockClock();
usage = MockUsage();
when(usage.isFirstRun).thenReturn(false);
when(clock.now()).thenAnswer(
(Invocation _) => DateTime.fromMillisecondsSinceEpoch(mockTimes.removeAt(0))
@@ -157,40 +155,4 @@ void main() {
});
});
}
typedef CommandFunction = Future<FlutterCommandResult> Function();
class DummyFlutterCommand extends FlutterCommand {
DummyFlutterCommand({
this.shouldUpdateCache = false,
this.noUsagePath = false,
this.commandFunction,
});
final bool noUsagePath;
final CommandFunction commandFunction;
@override
final bool shouldUpdateCache;
@override
String get description => 'does nothing';
@override
Future<String> get usagePath => noUsagePath ? null : super.usagePath;
@override
String get name => 'dummy';
@override
Future<FlutterCommandResult> runCommand() async {
return commandFunction == null ? null : await commandFunction();
}
}
class MockCache extends Mock implements Cache {}
class MockUsage extends Mock implements Usage {}

View File

@@ -0,0 +1,45 @@
// Copyright 2017 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 'dart:async';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/usage.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:mockito/mockito.dart';
typedef CommandFunction = Future<FlutterCommandResult> Function();
class DummyFlutterCommand extends FlutterCommand {
DummyFlutterCommand({
this.shouldUpdateCache = false,
this.noUsagePath = false,
this.commandFunction,
});
final bool noUsagePath;
final CommandFunction commandFunction;
@override
final bool shouldUpdateCache;
@override
String get description => 'does nothing';
@override
Future<String> get usagePath => noUsagePath ? null : super.usagePath;
@override
String get name => 'dummy';
@override
Future<FlutterCommandResult> runCommand() async {
return commandFunction == null ? null : await commandFunction();
}
}
class MockitoCache extends Mock implements Cache {}
class MockitoUsage extends Mock implements Usage {}