Don't create stdinLines just to cancel it (#1438)

diff --git a/pkgs/test/CHANGELOG.md b/pkgs/test/CHANGELOG.md
index 1e36c49..04debcb 100644
--- a/pkgs/test/CHANGELOG.md
+++ b/pkgs/test/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 1.16.4
+
+* Update `test_core` dependency to `0.3.14`.
+
 ## 1.16.3
 
 * Update `web_socket_channel` dependency to support latest.
diff --git a/pkgs/test/pubspec.yaml b/pkgs/test/pubspec.yaml
index 3abc23a..6d33746 100644
--- a/pkgs/test/pubspec.yaml
+++ b/pkgs/test/pubspec.yaml
@@ -1,5 +1,5 @@
 name: test
-version: 1.16.3
+version: 1.16.4
 description: A full featured library for writing and running Dart tests.
 repository: https://github.com/dart-lang/test/blob/master/pkgs/test
 
@@ -32,7 +32,7 @@
   yaml: ">=2.0.0 <4.0.0"
   # Use an exact version until the test_api and test_core package are stable.
   test_api: 0.2.19
-  test_core: 0.3.13
+  test_core: 0.3.14
 
 dev_dependencies:
   fake_async: ^1.0.0
diff --git a/pkgs/test_core/CHANGELOG.md b/pkgs/test_core/CHANGELOG.md
index 8572ea5..41d52e5 100644
--- a/pkgs/test_core/CHANGELOG.md
+++ b/pkgs/test_core/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.3.14
+
+* Handle issue closing `stdin` during shutdown.
+
 ## 0.3.13
 
 * Allow the latest analyzer `1.0.0`.
diff --git a/pkgs/test_core/lib/src/executable.dart b/pkgs/test_core/lib/src/executable.dart
index c054674..991c740 100644
--- a/pkgs/test_core/lib/src/executable.dart
+++ b/pkgs/test_core/lib/src/executable.dart
@@ -50,7 +50,7 @@
     signalSubscription = null;
   }
   isShutdown = true;
-  stdinLines.cancel(immediate: true);
+  cancelStdinLines();
 }
 
 Future<void> _execute(List<String> args) async {
diff --git a/pkgs/test_core/lib/src/util/io.dart b/pkgs/test_core/lib/src/util/io.dart
index 347ca89..d489d3b 100644
--- a/pkgs/test_core/lib/src/util/io.dart
+++ b/pkgs/test_core/lib/src/util/io.dart
@@ -3,14 +3,13 @@
 // BSD-style license that can be found in the LICENSE file.
 
 import 'dart:async';
+import 'dart:convert';
 import 'dart:core' as core;
 import 'dart:core';
-import 'dart:convert';
 import 'dart:io';
 
 import 'package:async/async.dart';
 import 'package:path/path.dart' as p;
-
 import 'package:test_api/src/backend/operating_system.dart'; // ignore: implementation_imports
 import 'package:test_api/src/backend/runtime.dart'; // ignore: implementation_imports
 import 'package:test_api/src/backend/suite_platform.dart'; // ignore: implementation_imports
@@ -54,9 +53,14 @@
 ///
 /// Also returns an empty stream for Fuchsia since Fuchsia components can't
 /// access stdin.
-final stdinLines = StreamQueue(
+StreamQueue<String> get stdinLines => _stdinLines ??= StreamQueue(
     Platform.isFuchsia ? Stream<String>.empty() : lineSplitter.bind(stdin));
 
+StreamQueue<String>? _stdinLines;
+
+/// Call cancel on [stdinLines], but only if it's been accessed previously.
+void cancelStdinLines() => _stdinLines?.cancel(immediate: true);
+
 /// Whether this is being run as a subprocess in the test package's own tests.
 bool inTestTests = Platform.environment['_DART_TEST_TESTING'] == 'true';
 
diff --git a/pkgs/test_core/pubspec.yaml b/pkgs/test_core/pubspec.yaml
index a19d8d6..87d4be2 100644
--- a/pkgs/test_core/pubspec.yaml
+++ b/pkgs/test_core/pubspec.yaml
@@ -1,5 +1,5 @@
 name: test_core
-version: 0.3.13
+version: 0.3.14
 description: A basic library for writing tests and running them on the VM.
 homepage: https://github.com/dart-lang/test/blob/master/pkgs/test_core