mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00

Towards https://github.com/flutter/flutter/issues/150575 Removes more usage of `Usage`. This PR is scoped to removing all references to it in `pub`-related code. <details> <summary> Pre-launch checklist </summary> - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. </details> If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
159 lines
4.9 KiB
Dart
159 lines
4.9 KiB
Dart
// Copyright 2014 The Flutter 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:file/memory.dart';
|
|
import 'package:flutter_tools/src/base/logger.dart';
|
|
import 'package:flutter_tools/src/base/platform.dart';
|
|
import 'package:flutter_tools/src/cache.dart';
|
|
import 'package:flutter_tools/src/dart/pub.dart';
|
|
import 'package:flutter_tools/src/project.dart';
|
|
|
|
import '../../src/common.dart';
|
|
import '../../src/fake_process_manager.dart';
|
|
import '../../src/fakes.dart';
|
|
|
|
const String _dartBin = 'bin/cache/dart-sdk/bin/dart';
|
|
|
|
void main() {
|
|
setUpAll(() {
|
|
Cache.flutterRoot = '';
|
|
});
|
|
|
|
testWithoutContext('throws a tool exit if pub cannot be run', () async {
|
|
final FakeProcessManager processManager = FakeProcessManager.empty();
|
|
final BufferLogger logger = BufferLogger.test();
|
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
|
|
|
processManager.excludedExecutables.add(_dartBin);
|
|
fileSystem.file('pubspec.yaml').createSync();
|
|
|
|
final Pub pub = Pub.test(
|
|
fileSystem: fileSystem,
|
|
logger: logger,
|
|
processManager: processManager,
|
|
platform: FakePlatform(),
|
|
botDetector: const FakeBotDetector(false),
|
|
stdio: FakeStdio(),
|
|
);
|
|
|
|
await expectLater(
|
|
() => pub.deps(FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)),
|
|
throwsToolExit(message: 'Your Flutter SDK download may be corrupt'),
|
|
);
|
|
});
|
|
|
|
testWithoutContext('fails on non-zero exit code', () async {
|
|
final BufferLogger logger = BufferLogger.test();
|
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
|
final ProcessManager processManager = _dartPubDepsFails(
|
|
'Bad thing',
|
|
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
|
exitCode: 1,
|
|
);
|
|
|
|
final Pub pub = Pub.test(
|
|
fileSystem: fileSystem,
|
|
logger: logger,
|
|
processManager: processManager,
|
|
platform: FakePlatform(),
|
|
botDetector: const FakeBotDetector(false),
|
|
stdio: FakeStdio(),
|
|
);
|
|
|
|
await expectLater(
|
|
() => pub.deps(FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)),
|
|
throwsA(
|
|
isA<StateError>().having(
|
|
(StateError e) => e.message,
|
|
'message',
|
|
contains('dart pub --suppress-analytics deps --json failed'),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
testWithoutContext('fails on non-parseable JSON', () async {
|
|
final BufferLogger logger = BufferLogger.test();
|
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
|
final ProcessManager processManager = _dartPubDepsReturns(
|
|
'Not JSON haha!',
|
|
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
|
);
|
|
|
|
final Pub pub = Pub.test(
|
|
fileSystem: fileSystem,
|
|
logger: logger,
|
|
processManager: processManager,
|
|
platform: FakePlatform(),
|
|
botDetector: const FakeBotDetector(false),
|
|
stdio: FakeStdio(),
|
|
);
|
|
|
|
await expectLater(
|
|
() => pub.deps(FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)),
|
|
throwsA(
|
|
isA<StateError>().having(
|
|
(StateError e) => e.message,
|
|
'message',
|
|
contains('dart pub --suppress-analytics deps --json had unexpected output'),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
|
|
testWithoutContext('fails on unexpected JSON type', () async {
|
|
final BufferLogger logger = BufferLogger.test();
|
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
|
final ProcessManager processManager = _dartPubDepsReturns(
|
|
'[]',
|
|
project: FlutterProject.fromDirectoryTest(fileSystem.currentDirectory),
|
|
);
|
|
|
|
final Pub pub = Pub.test(
|
|
fileSystem: fileSystem,
|
|
logger: logger,
|
|
processManager: processManager,
|
|
platform: FakePlatform(),
|
|
botDetector: const FakeBotDetector(false),
|
|
stdio: FakeStdio(),
|
|
);
|
|
|
|
await expectLater(
|
|
() => pub.deps(FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)),
|
|
throwsA(
|
|
isA<StateError>().having(
|
|
(StateError e) => e.message,
|
|
'message',
|
|
contains('Not a JSON object'),
|
|
),
|
|
),
|
|
);
|
|
});
|
|
}
|
|
|
|
ProcessManager _dartPubDepsReturns(String dartPubDepsOutput, {required FlutterProject project}) {
|
|
return FakeProcessManager.list(<FakeCommand>[
|
|
FakeCommand(
|
|
command: const <String>[_dartBin, 'pub', '--suppress-analytics', 'deps', '--json'],
|
|
stdout: dartPubDepsOutput,
|
|
workingDirectory: project.directory.path,
|
|
),
|
|
]);
|
|
}
|
|
|
|
ProcessManager _dartPubDepsFails(
|
|
String dartPubDepsError, {
|
|
required FlutterProject project,
|
|
required int exitCode,
|
|
}) {
|
|
return FakeProcessManager.list(<FakeCommand>[
|
|
FakeCommand(
|
|
command: const <String>[_dartBin, 'pub', '--suppress-analytics', 'deps', '--json'],
|
|
exitCode: exitCode,
|
|
stderr: dartPubDepsError,
|
|
workingDirectory: project.directory.path,
|
|
),
|
|
]);
|
|
}
|