[flutter_tool] Make BotDetector context free (#48605)
This commit is contained in:
@@ -5,9 +5,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_tools/src/base/bot_detector.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart' hide IOSink;
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/commands/packages.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
|
||||
@@ -2,13 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/base/bot_detector.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import '../../src/common.dart';
|
||||
import '../../src/context.dart';
|
||||
import '../../src/mocks.dart';
|
||||
|
||||
void main() {
|
||||
@@ -20,45 +17,33 @@ void main() {
|
||||
setUp(() {
|
||||
fakePlatform = FakePlatform()..environment = <String, String>{};
|
||||
mockStdio = MockStdio();
|
||||
botDetector = const BotDetector();
|
||||
botDetector = BotDetector(platform: fakePlatform);
|
||||
});
|
||||
|
||||
group('isRunningOnBot', () {
|
||||
testUsingContext('returns false unconditionally if BOT=false is set', () async {
|
||||
testWithoutContext('returns false unconditionally if BOT=false is set', () async {
|
||||
fakePlatform.environment['BOT'] = 'false';
|
||||
fakePlatform.environment['TRAVIS'] = 'true';
|
||||
expect(botDetector.isRunningOnBot, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
Stdio: () => mockStdio,
|
||||
Platform: () => fakePlatform,
|
||||
});
|
||||
|
||||
testUsingContext('returns false unconditionally if FLUTTER_HOST is set', () async {
|
||||
testWithoutContext('returns false unconditionally if FLUTTER_HOST is set', () async {
|
||||
fakePlatform.environment['FLUTTER_HOST'] = 'foo';
|
||||
fakePlatform.environment['TRAVIS'] = 'true';
|
||||
expect(botDetector.isRunningOnBot, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
Stdio: () => mockStdio,
|
||||
Platform: () => fakePlatform,
|
||||
});
|
||||
|
||||
testUsingContext('returns false with and without a terminal attached', () async {
|
||||
testWithoutContext('returns false with and without a terminal attached', () async {
|
||||
mockStdio.stdout.hasTerminal = true;
|
||||
expect(botDetector.isRunningOnBot, isFalse);
|
||||
mockStdio.stdout.hasTerminal = false;
|
||||
expect(botDetector.isRunningOnBot, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
Stdio: () => mockStdio,
|
||||
Platform: () => fakePlatform,
|
||||
});
|
||||
|
||||
testUsingContext('can test analytics outputs on bots when outputting to a file', () async {
|
||||
testWithoutContext('can test analytics outputs on bots when outputting to a file', () async {
|
||||
fakePlatform.environment['TRAVIS'] = 'true';
|
||||
fakePlatform.environment['FLUTTER_ANALYTICS_LOG_FILE'] = '/some/file';
|
||||
expect(botDetector.isRunningOnBot, isFalse);
|
||||
}, overrides: <Type, Generator>{
|
||||
Stdio: () => mockStdio,
|
||||
Platform: () => fakePlatform,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,11 +7,11 @@ import 'dart:collection';
|
||||
|
||||
import 'package:file/file.dart';
|
||||
import 'package:file/memory.dart';
|
||||
import 'package:flutter_tools/src/base/bot_detector.dart';
|
||||
import 'package:flutter_tools/src/base/common.dart';
|
||||
import 'package:flutter_tools/src/base/context.dart';
|
||||
import 'package:flutter_tools/src/base/file_system.dart';
|
||||
import 'package:flutter_tools/src/base/io.dart';
|
||||
import 'package:flutter_tools/src/base/utils.dart';
|
||||
import 'package:flutter_tools/src/cache.dart';
|
||||
import 'package:flutter_tools/src/dart/pub.dart';
|
||||
import 'package:flutter_tools/src/reporting/reporting.dart';
|
||||
|
||||
Reference in New Issue
Block a user