Pub dependencies project validator (#106895)
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
// 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/file_system.dart';
|
||||
import 'package:flutter_tools/src/project.dart';
|
||||
import 'package:flutter_tools/src/project_validator.dart';
|
||||
import 'package:flutter_tools/src/project_validator_result.dart';
|
||||
|
||||
import '../src/common.dart';
|
||||
import '../src/context.dart';
|
||||
|
||||
void main() {
|
||||
late FileSystem fileSystem;
|
||||
|
||||
group('PubDependenciesProjectValidator', () {
|
||||
|
||||
setUp(() {
|
||||
fileSystem = MemoryFileSystem.test();
|
||||
});
|
||||
|
||||
testWithoutContext('success when all dependencies are hosted', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stdout: '{"packages": [{"dependencies": ["abc"], "source": "hosted"}]}',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'All pub dependencies are hosted on https://pub.dartlang.org';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.success);
|
||||
});
|
||||
|
||||
testWithoutContext('error when command dart pub deps fails', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stderr: 'command fail',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'command fail';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.error);
|
||||
});
|
||||
|
||||
testWithoutContext('warning on dependencies not hosted', () async {
|
||||
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
|
||||
const FakeCommand(
|
||||
command: <String>['dart', 'pub', 'deps', '--json'],
|
||||
stdout: '{"packages": [{"dependencies": ["dep1", "dep2"], "source": "other"}]}',
|
||||
),
|
||||
]);
|
||||
final PubDependenciesProjectValidator validator = PubDependenciesProjectValidator(processManager);
|
||||
|
||||
final List<ProjectValidatorResult> result = await validator.start(
|
||||
FlutterProject.fromDirectoryTest(fileSystem.currentDirectory)
|
||||
);
|
||||
const String expected = 'dep1, dep2 are not hosted';
|
||||
expect(result.length, 1);
|
||||
expect(result[0].value, expected);
|
||||
expect(result[0].status, StatusProjectValidator.warning);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -54,5 +54,36 @@ void main() {
|
||||
|
||||
expect(loggerTest.statusText, contains(expected));
|
||||
});
|
||||
|
||||
testUsingContext('PubDependenciesProjectValidator success ', () async {
|
||||
final BufferLogger loggerTest = BufferLogger.test();
|
||||
final AnalyzeCommand command = AnalyzeCommand(
|
||||
artifacts: globals.artifacts!,
|
||||
fileSystem: fileSystem,
|
||||
logger: loggerTest,
|
||||
platform: globals.platform,
|
||||
terminal: globals.terminal,
|
||||
processManager: globals.processManager,
|
||||
allProjectValidators: <ProjectValidator>[
|
||||
PubDependenciesProjectValidator(globals.processManager),
|
||||
],
|
||||
);
|
||||
final CommandRunner<void> runner = createTestCommandRunner(command);
|
||||
|
||||
await runner.run(<String>[
|
||||
'analyze',
|
||||
'--no-pub',
|
||||
'--no-current-package',
|
||||
'--suggestions',
|
||||
'../../dev/integration_tests/flutter_gallery',
|
||||
]);
|
||||
|
||||
const String expected = '\n'
|
||||
'┌────────────────────────────────────────────────────────────────────────────────────┐\n'
|
||||
'│ Pub dependencies │\n'
|
||||
'│ [✓] Dart dependencies: All pub dependencies are hosted on https://pub.dartlang.org │\n'
|
||||
'└────────────────────────────────────────────────────────────────────────────────────┘\n';
|
||||
expect(loggerTest.statusText, contains(expected));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user