Repository: dart-lang/pub-dev (dart)

Issue:
Better automation for pkg/pub_integration/test/publish_rejection_test.dart
The test creates a templated package and tries to publish it. It needs dependent packages to be published first, and right now that list is fixed. With a new SDK the template and the dependencies may change, which requires the fixed versions to be updated.

Instead, we should read the dependencies from the templated package's pubspec.yaml and publish them.

Pull request description:
Fixes #8898.

Patch:
diff --git a/pkg/pub_integration/pubspec.yaml b/pkg/pub_integration/pubspec.yaml
index 6da202b89e..12685149c0 100644
--- a/pkg/pub_integration/pubspec.yaml
+++ b/pkg/pub_integration/pubspec.yaml
@@ -19,5 +19,6 @@ dependencies:
 dev_dependencies:
   coverage: any # test already depends on it
   markdown: ^7.3.0
+  pubspec_parse: ^1.5.0
   shelf: ^1.4.0
   test: ^1.16.5


Test patch:
diff --git a/pkg/pub_integration/test/publish_rejection_test.dart b/pkg/pub_integration/test/publish_rejection_test.dart
index 80fc6800e2..5b7210c689 100644
--- a/pkg/pub_integration/test/publish_rejection_test.dart
+++ b/pkg/pub_integration/test/publish_rejection_test.dart
@@ -8,6 +8,8 @@ import 'package:path/path.dart' as p;
 import 'package:pub_integration/src/fake_credentials.dart';
 import 'package:pub_integration/src/fake_test_context_provider.dart';
 import 'package:pub_integration/src/pub_tool_client.dart';
+import 'package:pub_semver/pub_semver.dart';
+import 'package:pubspec_parse/pubspec_parse.dart';
 import 'package:test/test.dart';
 
 void main() {
@@ -36,10 +38,27 @@ void main() {
     test('uses a template', () async {
       final tempDir = await Directory.systemTemp.createTemp();
       try {
-        final dependentPackages = {
-          'lints': '6.0.0',
-          'path': '1.9.1',
-          'test': '1.99.0',
+        // create templated package
+        final pkgDir = p.join(tempDir.path, 'pkg');
+        await globalDartTool.create(pkgDir);
+
+        // collect dependencies:
+        final pubspec = Pubspec.parse(
+            await File(p.join(pkgDir, 'pubspec.yaml')).readAsString());
+
+        String extractConstraint(Dependency d) {
+          if (d is! HostedDependency) {
+            throw ArgumentError();
+          }
+          final v = d.version as VersionRange;
+          return v.min.toString();
+        }
+
+        final dependentPackages = <String, String>{
+          ...pubspec.dependencies
+              .map((k, v) => MapEntry(k, extractConstraint(v))),
+          ...pubspec.devDependencies
+              .map((k, v) => MapEntry(k, extractConstraint(v))),
         };
         for (final d in dependentPackages.keys) {
           final pkgDir = p.join(tempDir.path, d);
@@ -59,11 +78,6 @@ void main() {
           await localDartTool.publish(pkgDir);
         }
 
-        final pkgName = 'pkg';
-        final pkgDir = p.join(tempDir.path, pkgName);
-        // create templated package
-        await globalDartTool.create(pkgDir);
-
         // customize content to clear publishing warnings
         final pubspecFile = File(p.join(pkgDir, 'pubspec.yaml'));
         final pubspecContent = await pubspecFile.readAsString();