Skip to content

Commit

Permalink
[tool] Handle Flutter dev dependencies (#5775)
Browse files Browse the repository at this point in the history
A non-Flutter package can have Flutter-based tests (e.g., cupertino_icons), in which case we need to use `flutter test` rather than `dart test` just like we would for a package with a non-dev Flutter dependency. This updates the `requiresFlutter` check to include dev dependencies as well as normal dependencies.
  • Loading branch information
stuartmorgan authored Jan 4, 2024
1 parent 7beab0d commit e573185
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 6 additions & 2 deletions script/tool/lib/src/common/repository_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ class RepositoryPackage {

/// Returns true if the package depends on Flutter.
bool requiresFlutter() {
const String flutterDependency = 'flutter';
final Pubspec pubspec = parsePubspec();
return pubspec.dependencies.containsKey('flutter');
return pubspec.dependencies.containsKey(flutterDependency) ||
pubspec.devDependencies.containsKey(flutterDependency);
}

/// True if this appears to be a federated plugin package, according to
Expand Down Expand Up @@ -151,7 +153,9 @@ class RepositoryPackage {
return false;
}
// Check whether this is one of the enclosing package's examples.
return enclosingPackage.getExamples().any((RepositoryPackage p) => p.path == path);
return enclosingPackage
.getExamples()
.any((RepositoryPackage p) => p.path == path);
}

/// Returns the Flutter example packages contained in the package, if any.
Expand Down
12 changes: 12 additions & 0 deletions script/tool/test/common/repository_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';

import '../util.dart';
Expand Down Expand Up @@ -221,6 +222,17 @@ void main() {
expect(package.requiresFlutter(), true);
});

test('returns true for a dev dependency on Flutter', () async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir);
final File pubspecFile = package.pubspecFile;
final Pubspec pubspec = package.parsePubspec();
pubspec.devDependencies['flutter'] = SdkDependency('flutter');
pubspecFile.writeAsStringSync(pubspec.toString());

expect(package.requiresFlutter(), true);
});

test('returns false for non-Flutter package', () async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir);
Expand Down

0 comments on commit e573185

Please sign in to comment.