mirror of
https://github.com/flutter/packages.git
synced 2025-05-30 13:07:27 +08:00
[flutter_plugin_tool] Add custom-test command (#5058)
This commit is contained in:
77
script/tool/lib/src/custom_test_command.dart
Normal file
77
script/tool/lib/src/custom_test_command.dart
Normal file
@ -0,0 +1,77 @@
|
||||
// Copyright 2013 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/file.dart';
|
||||
import 'package:platform/platform.dart';
|
||||
|
||||
import 'common/package_looping_command.dart';
|
||||
import 'common/process_runner.dart';
|
||||
import 'common/repository_package.dart';
|
||||
|
||||
const String _scriptName = 'run_tests.dart';
|
||||
const String _legacyScriptName = 'run_tests.sh';
|
||||
|
||||
/// A command to run custom, package-local tests on packages.
|
||||
///
|
||||
/// This is an escape hatch for adding tests that this tooling doesn't support.
|
||||
/// It should be used sparingly; prefer instead to add functionality to this
|
||||
/// tooling to eliminate the need for bespoke tests.
|
||||
class CustomTestCommand extends PackageLoopingCommand {
|
||||
/// Creates a custom test command instance.
|
||||
CustomTestCommand(
|
||||
Directory packagesDir, {
|
||||
ProcessRunner processRunner = const ProcessRunner(),
|
||||
Platform platform = const LocalPlatform(),
|
||||
}) : super(packagesDir, processRunner: processRunner, platform: platform);
|
||||
|
||||
@override
|
||||
final String name = 'custom-test';
|
||||
|
||||
@override
|
||||
final String description = 'Runs package-specific custom tests defined in '
|
||||
'a package\'s tool/$_scriptName file.\n\n'
|
||||
'This command requires "dart" to be in your path.';
|
||||
|
||||
@override
|
||||
Future<PackageResult> runForPackage(RepositoryPackage package) async {
|
||||
final File script =
|
||||
package.directory.childDirectory('tool').childFile(_scriptName);
|
||||
final File legacyScript = package.directory.childFile(_legacyScriptName);
|
||||
String? customSkipReason;
|
||||
bool ranTests = false;
|
||||
|
||||
// Run the custom Dart script if presest.
|
||||
if (script.existsSync()) {
|
||||
final int exitCode = await processRunner.runAndStream(
|
||||
'dart', <String>['run', 'tool/$_scriptName'],
|
||||
workingDir: package.directory);
|
||||
if (exitCode != 0) {
|
||||
return PackageResult.fail();
|
||||
}
|
||||
ranTests = true;
|
||||
}
|
||||
|
||||
// Run the legacy script if present.
|
||||
if (legacyScript.existsSync()) {
|
||||
if (platform.isWindows) {
|
||||
customSkipReason = '$_legacyScriptName is not supported on Windows. '
|
||||
'Please migrate to $_scriptName.';
|
||||
} else {
|
||||
final int exitCode = await processRunner.runAndStream(
|
||||
legacyScript.path, <String>[],
|
||||
workingDir: package.directory);
|
||||
if (exitCode != 0) {
|
||||
return PackageResult.fail();
|
||||
}
|
||||
ranTests = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ranTests) {
|
||||
return PackageResult.skip(customSkipReason ?? 'No custom tests');
|
||||
}
|
||||
|
||||
return PackageResult.success();
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ import 'analyze_command.dart';
|
||||
import 'build_examples_command.dart';
|
||||
import 'common/core.dart';
|
||||
import 'create_all_plugins_app_command.dart';
|
||||
import 'custom_test_command.dart';
|
||||
import 'drive_examples_command.dart';
|
||||
import 'federation_safety_check_command.dart';
|
||||
import 'firebase_test_lab_command.dart';
|
||||
@ -50,6 +51,7 @@ void main(List<String> args) {
|
||||
..addCommand(AnalyzeCommand(packagesDir))
|
||||
..addCommand(BuildExamplesCommand(packagesDir))
|
||||
..addCommand(CreateAllPluginsAppCommand(packagesDir))
|
||||
..addCommand(CustomTestCommand(packagesDir))
|
||||
..addCommand(DriveExamplesCommand(packagesDir))
|
||||
..addCommand(FederationSafetyCheckCommand(packagesDir))
|
||||
..addCommand(FirebaseTestLabCommand(packagesDir))
|
||||
|
Reference in New Issue
Block a user