|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be
|
3 | 3 | // found in the LICENSE file.
|
4 | 4 |
|
| 5 | +import 'package:file/file.dart'; |
5 | 6 | import 'package:file/memory.dart';
|
6 | 7 | import 'package:flutter_tools/src/artifacts.dart';
|
7 | 8 | import 'package:flutter_tools/src/base/os.dart';
|
@@ -384,10 +385,122 @@ void main() {
|
384 | 385 | ),
|
385 | 386 | ));
|
386 | 387 | });
|
| 388 | + |
| 389 | + testWithoutContext('detects no flutter and dart on path', () async { |
| 390 | + final FlutterValidator flutterValidator = FlutterValidator( |
| 391 | + platform: FakePlatform(localeName: 'en_US.UTF-8'), |
| 392 | + flutterVersion: () => FakeFlutterVersion( |
| 393 | + frameworkVersion: '1.0.0', |
| 394 | + channel: 'beta' |
| 395 | + ), |
| 396 | + devToolsVersion: () => '2.8.0', |
| 397 | + userMessages: UserMessages(), |
| 398 | + artifacts: Artifacts.test(), |
| 399 | + fileSystem: MemoryFileSystem.test(), |
| 400 | + processManager: FakeProcessManager.any(), |
| 401 | + operatingSystemUtils: FakeOperatingSystemUtils( |
| 402 | + name: 'Linux', |
| 403 | + whichLookup: const <String, File>{}, |
| 404 | + ), |
| 405 | + flutterRoot: () => 'sdk/flutter', |
| 406 | + ); |
| 407 | + |
| 408 | + expect(await flutterValidator.validate(), _matchDoctorValidation( |
| 409 | + validationType: ValidationType.partial, |
| 410 | + statusInfo: 'Channel beta, 1.0.0, on Linux, locale en_US.UTF-8', |
| 411 | + messages: contains(const ValidationMessage.hint( |
| 412 | + 'The flutter binary is not on your path. Consider adding sdk/flutter/bin to your path.', |
| 413 | + )), |
| 414 | + )); |
| 415 | + }); |
| 416 | + |
| 417 | + testWithoutContext('detects flutter and dart from outside flutter sdk', () async { |
| 418 | + final FileSystem fs = MemoryFileSystem.test(); |
| 419 | + final FlutterValidator flutterValidator = FlutterValidator( |
| 420 | + platform: FakePlatform(localeName: 'en_US.UTF-8'), |
| 421 | + flutterVersion: () => FakeFlutterVersion( |
| 422 | + frameworkVersion: '1.0.0', |
| 423 | + channel: 'beta' |
| 424 | + ), |
| 425 | + devToolsVersion: () => '2.8.0', |
| 426 | + userMessages: UserMessages(), |
| 427 | + artifacts: Artifacts.test(), |
| 428 | + fileSystem: fs, |
| 429 | + processManager: FakeProcessManager.any(), |
| 430 | + operatingSystemUtils: FakeOperatingSystemUtils( |
| 431 | + name: 'Linux', |
| 432 | + whichLookup: <String, File>{ |
| 433 | + 'flutter': fs.file('/usr/bin/flutter')..createSync(recursive: true), |
| 434 | + 'dart': fs.file('/usr/bin/dart')..createSync(recursive: true), |
| 435 | + }, |
| 436 | + ), |
| 437 | + flutterRoot: () => 'sdk/flutter', |
| 438 | + ); |
| 439 | + |
| 440 | + expect(await flutterValidator.validate(), _matchDoctorValidation( |
| 441 | + validationType: ValidationType.partial, |
| 442 | + statusInfo: 'Channel beta, 1.0.0, on Linux, locale en_US.UTF-8', |
| 443 | + messages: contains(const ValidationMessage.hint( |
| 444 | + 'Warning: `flutter` on your path resolves to /usr/bin/flutter, which ' |
| 445 | + 'is not inside your current Flutter SDK checkout at sdk/flutter. ' |
| 446 | + 'Consider adding sdk/flutter/bin to the front of your path.', |
| 447 | + )), |
| 448 | + )); |
| 449 | + }); |
| 450 | + |
| 451 | + testWithoutContext('no warnings if flutter & dart binaries are inside the Flutter SDK', () async { |
| 452 | + final FileSystem fs = MemoryFileSystem.test(); |
| 453 | + final FlutterValidator flutterValidator = FlutterValidator( |
| 454 | + platform: FakePlatform(localeName: 'en_US.UTF-8'), |
| 455 | + flutterVersion: () => FakeFlutterVersion( |
| 456 | + frameworkVersion: '1.0.0', |
| 457 | + channel: 'beta' |
| 458 | + ), |
| 459 | + devToolsVersion: () => '2.8.0', |
| 460 | + userMessages: UserMessages(), |
| 461 | + artifacts: Artifacts.test(), |
| 462 | + fileSystem: fs, |
| 463 | + processManager: FakeProcessManager.any(), |
| 464 | + operatingSystemUtils: FakeOperatingSystemUtils( |
| 465 | + name: 'Linux', |
| 466 | + whichLookup: <String, File>{ |
| 467 | + 'flutter': fs.file('/sdk/flutter/bin/flutter')..createSync(recursive: true), |
| 468 | + 'dart': fs.file('/sdk/flutter/bin/dart')..createSync(recursive: true), |
| 469 | + }, |
| 470 | + ), |
| 471 | + flutterRoot: () => '/sdk/flutter', |
| 472 | + ); |
| 473 | + |
| 474 | + expect(await flutterValidator.validate(), _matchDoctorValidation( |
| 475 | + validationType: ValidationType.installed, |
| 476 | + statusInfo: 'Channel beta, 1.0.0, on Linux, locale en_US.UTF-8', |
| 477 | + messages: isNot(contains(isA<ValidationMessage>().having( |
| 478 | + (ValidationMessage message) => message.message, |
| 479 | + 'message', |
| 480 | + contains('Consider adding /sdk/flutter/bin to the front of your path'), |
| 481 | + ))), |
| 482 | + )); |
| 483 | + }); |
387 | 484 | }
|
388 | 485 |
|
389 | 486 | class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
|
390 |
| - FakeOperatingSystemUtils({required this.name}); |
| 487 | + FakeOperatingSystemUtils({ |
| 488 | + required this.name, |
| 489 | + this.whichLookup, |
| 490 | + FileSystem? fs, |
| 491 | + }) { |
| 492 | + fs ??= MemoryFileSystem.test(); |
| 493 | + whichLookup ??= <String, File>{ |
| 494 | + 'flutter': fs.file('/sdk/flutter/bin/flutter')..createSync(recursive: true), |
| 495 | + 'dart': fs.file('/sdk/flutter/bin/dart')..createSync(recursive: true), |
| 496 | + }; |
| 497 | + } |
| 498 | + |
| 499 | + /// A map of [File]s that calls to [which] will return. |
| 500 | + Map<String, File>? whichLookup; |
| 501 | + |
| 502 | + @override |
| 503 | + File? which(String execName) => whichLookup![execName]; |
391 | 504 |
|
392 | 505 | @override
|
393 | 506 | final String name;
|
|
0 commit comments