migrate test/add, test/cache, test/embedding plus a bit more to null-safety (#3205)

diff --git a/test/add/common/add_test.dart b/test/add/common/add_test.dart
index 51d5b71..e124be8 100644
--- a/test/add/common/add_test.dart
+++ b/test/add/common/add_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io' show File;
 
 import 'package:path/path.dart' as p;
diff --git a/test/add/common/invalid_options.dart b/test/add/common/invalid_options.dart
index 17262d2..0b60ed8 100644
--- a/test/add/common/invalid_options.dart
+++ b/test/add/common/invalid_options.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
@@ -42,7 +40,7 @@
     // Make the default server serve errors. Only the custom server should
     // be accessed.
     await serveNoPackages();
-    globalPackageServer.serveErrors();
+    globalPackageServer!.serveErrors();
 
     final server = await PackageServer.start((builder) {
       builder.serve('foo', '1.2.3');
@@ -79,7 +77,7 @@
     // Make the default server serve errors. Only the custom server should
     // be accessed.
     await serveNoPackages();
-    globalPackageServer.serveErrors();
+    globalPackageServer!.serveErrors();
 
     final server = await PackageServer.start((builder) {
       builder.serve('foo', '1.2.3');
diff --git a/test/add/common/version_constraint_test.dart b/test/add/common/version_constraint_test.dart
index 22df8bc..d865727 100644
--- a/test/add/common/version_constraint_test.dart
+++ b/test/add/common/version_constraint_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
diff --git a/test/add/common/version_resolution_test.dart b/test/add/common/version_resolution_test.dart
index a6ad690..4bd355b 100644
--- a/test/add/common/version_resolution_test.dart
+++ b/test/add/common/version_resolution_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
@@ -26,7 +24,7 @@
     /// foo's package creator releases a newer version of foo, and we
     /// want to test that this is what the user gets when they run
     /// pub add foo.
-    globalPackageServer.add((builder) {
+    globalPackageServer!.add((builder) {
       builder.serve('foo', '3.5.0');
       builder.serve('foo', '3.1.0');
       builder.serve('foo', '2.5.0');
@@ -51,7 +49,7 @@
     await d.appDir({'bar': '1.0.0'}).create();
     await pubGet();
 
-    globalPackageServer.add((builder) {
+    globalPackageServer!.add((builder) {
       builder.serve('foo', '4.0.0');
       builder.serve('foo', '2.0.0');
     });
@@ -75,7 +73,7 @@
     await d.appDir({'bar': '^1.0.0'}).create();
     await pubGet();
 
-    globalPackageServer.add((builder) {
+    globalPackageServer!.add((builder) {
       builder.serve('foo', '5.0.0');
       builder.serve('foo', '4.0.0');
       builder.serve('foo', '2.0.0');
diff --git a/test/add/git/git_test.dart b/test/add/git/git_test.dart
index b120e38..2577af8 100644
--- a/test/add/git/git_test.dart
+++ b/test/add/git/git_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
diff --git a/test/add/git/ref_test.dart b/test/add/git/ref_test.dart
index fadd80a..11dfc0b 100644
--- a/test/add/git/ref_test.dart
+++ b/test/add/git/ref_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
diff --git a/test/add/git/subdir_test.dart b/test/add/git/subdir_test.dart
index 3bf381a..0f78069 100644
--- a/test/add/git/subdir_test.dart
+++ b/test/add/git/subdir_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
diff --git a/test/add/hosted/non_default_pub_server_test.dart b/test/add/hosted/non_default_pub_server_test.dart
index 33b6753..fbe966e 100644
--- a/test/add/hosted/non_default_pub_server_test.dart
+++ b/test/add/hosted/non_default_pub_server_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
diff --git a/test/add/path/absolute_path_test.dart b/test/add/path/absolute_path_test.dart
index dc74638..0811bea 100644
--- a/test/add/path/absolute_path_test.dart
+++ b/test/add/path/absolute_path_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:path/path.dart' as path;
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
diff --git a/test/add/path/relative_path_test.dart b/test/add/path/relative_path_test.dart
index 9d443e8..8fa1932 100644
--- a/test/add/path/relative_path_test.dart
+++ b/test/add/path/relative_path_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io' show Platform;
 
 import 'package:pub/src/exit_codes.dart' as exit_codes;
diff --git a/test/add/sdk/sdk_test.dart b/test/add/sdk/sdk_test.dart
index 1ded16e..25995e3 100644
--- a/test/add/sdk/sdk_test.dart
+++ b/test/add/sdk/sdk_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:path/path.dart' as p;
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
diff --git a/test/cache/clean_test.dart b/test/cache/clean_test.dart
index 1ba2ac7..b03c0c8 100644
--- a/test/cache/clean_test.dart
+++ b/test/cache/clean_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:path/path.dart' as path;
 import 'package:pub/src/io.dart';
 import 'package:test/test.dart';
diff --git a/test/cache/list_test.dart b/test/cache/list_test.dart
index 9d8b9f3..a2c26a4 100644
--- a/test/cache/list_test.dart
+++ b/test/cache/list_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:path/path.dart' as path;
 import 'package:test/test.dart';
 
diff --git a/test/cache/repair/empty_cache_test.dart b/test/cache/repair/empty_cache_test.dart
index 679e32a..13d68cc 100644
--- a/test/cache/repair/empty_cache_test.dart
+++ b/test/cache/repair/empty_cache_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../test_pub.dart';
diff --git a/test/cache/repair/git_test.dart b/test/cache/repair/git_test.dart
index abb0ab7..262343a 100644
--- a/test/cache/repair/git_test.dart
+++ b/test/cache/repair/git_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:path/path.dart' as path;
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:pub/src/io.dart';
diff --git a/test/cache/repair/handles_corrupted_binstub_test.dart b/test/cache/repair/handles_corrupted_binstub_test.dart
index b1c3556..9991ec1 100644
--- a/test/cache/repair/handles_corrupted_binstub_test.dart
+++ b/test/cache/repair/handles_corrupted_binstub_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
diff --git a/test/cache/repair/handles_corrupted_global_lockfile_test.dart b/test/cache/repair/handles_corrupted_global_lockfile_test.dart
index 3952871..9a9af05 100644
--- a/test/cache/repair/handles_corrupted_global_lockfile_test.dart
+++ b/test/cache/repair/handles_corrupted_global_lockfile_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
diff --git a/test/cache/repair/handles_failure_test.dart b/test/cache/repair/handles_failure_test.dart
index 8016d30..471bcf8 100644
--- a/test/cache/repair/handles_failure_test.dart
+++ b/test/cache/repair/handles_failure_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:pub/src/exit_codes.dart' as exit_codes;
 import 'package:test/test.dart';
 
@@ -21,7 +19,7 @@
     // Set up a cache with some packages.
     await d.dir(cachePath, [
       d.dir('hosted', [
-        d.dir('localhost%58${globalServer.port}', [
+        d.dir('localhost%58${globalServer!.port}', [
           d.dir('foo-1.2.3',
               [d.libPubspec('foo', '1.2.3'), d.file('broken.txt')]),
           d.dir('foo-1.2.4',
diff --git a/test/cache/repair/handles_orphaned_binstub_test.dart b/test/cache/repair/handles_orphaned_binstub_test.dart
index 4954121..9c4e74a 100644
--- a/test/cache/repair/handles_orphaned_binstub_test.dart
+++ b/test/cache/repair/handles_orphaned_binstub_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
diff --git a/test/cache/repair/hosted.dart b/test/cache/repair/hosted.dart
index 23d839b..97c8167 100644
--- a/test/cache/repair/hosted.dart
+++ b/test/cache/repair/hosted.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io';
 
 import 'package:pub/src/exit_codes.dart' as exit_codes;
@@ -27,7 +25,7 @@
     // Set up a cache with some broken packages.
     await d.dir(cachePath, [
       d.dir('hosted', [
-        d.dir('localhost%58${globalServer.port}', [
+        d.dir('localhost%58${globalServer!.port}', [
           d.dir('foo-1.2.3',
               [d.libPubspec('foo', '1.2.3'), d.file('broken.txt')]),
           d.dir('foo-1.2.5',
@@ -66,7 +64,7 @@
     // Set up a cache with some broken packages.
     await d.dir(cachePath, [
       d.dir('hosted', [
-        d.dir('localhost%58${globalServer.port}', [
+        d.dir('localhost%58${globalServer!.port}', [
           d.dir('bar-1.2.4', [d.file('broken.txt')]),
           d.dir('foo-1.2.3', [d.file('broken.txt')]),
           d.dir('foo-1.2.5', [d.file('broken.txt')]),
@@ -102,7 +100,7 @@
     // Set up a cache with some broken packages.
     await d.dir(cachePath, [
       d.dir('hosted', [
-        d.dir('localhost%58${globalServer.port}', [
+        d.dir('localhost%58${globalServer!.port}', [
           d.dir('bar-1.2.4', [d.file('pubspec.yaml', '{')]),
           d.dir('foo-1.2.3', [d.file('pubspec.yaml', '{')]),
           d.dir('foo-1.2.5', [d.file('pubspec.yaml', '{')]),
diff --git a/test/cache/repair/recompiles_snapshots_test.dart b/test/cache/repair/recompiles_snapshots_test.dart
index 698e148..89b3575 100644
--- a/test/cache/repair/recompiles_snapshots_test.dart
+++ b/test/cache/repair/recompiles_snapshots_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
diff --git a/test/cache/repair/updates_binstubs_test.dart b/test/cache/repair/updates_binstubs_test.dart
index bfb6400..1cd848b 100644
--- a/test/cache/repair/updates_binstubs_test.dart
+++ b/test/cache/repair/updates_binstubs_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'package:test/test.dart';
 
 import '../../descriptor.dart' as d;
diff --git a/test/deps/executables_test.dart b/test/deps/executables_test.dart
index 978cc24..ea864fd 100644
--- a/test/deps/executables_test.dart
+++ b/test/deps/executables_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import '../descriptor.dart' as d;
 import '../golden_file.dart';
 import '../test_pub.dart';
diff --git a/test/descriptor.dart b/test/descriptor.dart
index aa95ca6..7a592db 100644
--- a/test/descriptor.dart
+++ b/test/descriptor.dart
@@ -64,7 +64,7 @@
 ///
 /// [contents] may contain [Future]s that resolve to serializable objects,
 /// which may in turn contain [Future]s recursively.
-Descriptor pubspec(Map<String, Object> contents) => YamlDescriptor(
+Descriptor pubspec(Map<String, Object?> contents) => YamlDescriptor(
       'pubspec.yaml',
       yaml({
         ...contents,
diff --git a/test/embedding/embedding_test.dart b/test/embedding/embedding_test.dart
index b5cf8bd..20e127e 100644
--- a/test/embedding/embedding_test.dart
+++ b/test/embedding/embedding_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:convert';
 import 'dart:io';
 
@@ -16,14 +14,14 @@
 
 const _command_runner = 'tool/test-bin/pub_command_runner.dart';
 
-String snapshot;
+late String snapshot;
 
 /// Runs `dart tool/test-bin/pub_command_runner.dart [args]` and appends the output to [buffer].
 Future<void> runEmbeddingToBuffer(
   List<String> args,
   StringBuffer buffer, {
-  String workingDirextory,
-  Map<String, String> environment,
+  String? workingDirectory,
+  Map<String, String>? environment,
   dynamic exitCode = 0,
 }) async {
   final process = await TestProcess.start(
@@ -33,7 +31,7 @@
       ...getPubTestEnvironment(),
       ...?environment,
     },
-    workingDirectory: workingDirextory,
+    workingDirectory: workingDirectory,
   );
   await process.shouldExit(exitCode);
 
@@ -53,15 +51,15 @@
   /// next section in golden file.
   Future<void> runEmbedding(
     List<String> args, {
-    String workingDirextory,
-    Map<String, String> environment,
+    String? workingDirextory,
+    Map<String, String>? environment,
     dynamic exitCode = 0,
   }) async {
     final buffer = StringBuffer();
     await runEmbeddingToBuffer(
       args,
       buffer,
-      workingDirextory: workingDirextory,
+      workingDirectory: workingDirextory,
       environment: environment,
       exitCode: exitCode,
     );
@@ -136,7 +134,7 @@
     await runEmbeddingToBuffer(
       ['pub', 'get'],
       buffer,
-      workingDirextory: app.io.path,
+      workingDirectory: app.io.path,
       environment: {...getPubTestEnvironment(), '_PUB_LOG_ANALYTICS': 'true'},
     );
     final analytics = buffer
diff --git a/test/embedding/get_executable_for_command_test.dart b/test/embedding/get_executable_for_command_test.dart
index 7667e12..611f5ef 100644
--- a/test/embedding/get_executable_for_command_test.dart
+++ b/test/embedding/get_executable_for_command_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io';
 
 import 'package:path/path.dart' show separator;
@@ -23,7 +21,7 @@
   executable,
   packageConfig,
   errorMessage,
-  CommandResolutionIssue issue,
+  CommandResolutionIssue? issue,
 }) async {
   final _cachePath = getPubTestEnvironment()['PUB_CACHE'];
   final oldVerbosity = log.verbosity;
diff --git a/test/get/with_empty_environment_test.dart b/test/get/with_empty_environment_test.dart
index 0e23034..9a9f9e2 100644
--- a/test/get/with_empty_environment_test.dart
+++ b/test/get/with_empty_environment_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io';
 
 import 'package:test/test.dart';
diff --git a/test/remove/remove_test.dart b/test/remove/remove_test.dart
index 777d41b..52194c9 100644
--- a/test/remove/remove_test.dart
+++ b/test/remove/remove_test.dart
@@ -2,8 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-// @dart=2.10
-
 import 'dart:io' show File;
 
 import 'package:path/path.dart' as p;
diff --git a/test/test_pub.dart b/test/test_pub.dart
index 898b52f..9f23e48 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -133,7 +133,7 @@
   Object? silent,
   Object? warning,
   int? exitCode,
-  Map<String, String>? environment,
+  Map<String, String?>? environment,
   String? workingDirectory,
   includeParentEnvironment = true,
 }) async {
@@ -189,7 +189,7 @@
   Object? error,
   Object? warning,
   int? exitCode,
-  Map<String, String>? environment,
+  Map<String, String?>? environment,
   String? workingDirectory,
   bool includeParentEnvironment = true,
 }) async =>