Make tests more agnostic to the test environment (#3402)
diff --git a/test/get/with_empty_environment_test.dart b/test/get/with_empty_environment_test.dart
index 30768c4..5dab9b3 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.
-import 'dart:io';
-
import 'package:test/test.dart';
import '../descriptor.dart' as d;
@@ -18,10 +16,6 @@
await pubGet(environment: {
'_PUB_TEST_CONFIG_DIR': null,
- if (Platform.isWindows) ...{
- 'SYSTEMROOT': Platform.environment['SYSTEMROOT'],
- 'TMP': Platform.environment['TMP'],
- },
- }, includeParentEnvironment: false);
+ }, includeParentHomeAndPath: false);
});
}
diff --git a/test/test_pub.dart b/test/test_pub.dart
index e7e7bc7..3c2f102 100644
--- a/test/test_pub.dart
+++ b/test/test_pub.dart
@@ -130,7 +130,7 @@
int? exitCode,
Map<String, String?>? environment,
String? workingDirectory,
- includeParentEnvironment = true,
+ includeParentHomeAndPath = true,
}) async {
if (error != null && warning != null) {
throw ArgumentError("Cannot pass both 'error' and 'warning'.");
@@ -155,7 +155,7 @@
exitCode: exitCode,
environment: environment,
workingDirectory: workingDirectory,
- includeParentEnvironment: includeParentEnvironment);
+ includeParentHomeAndPath: includeParentHomeAndPath);
}
Future<void> pubAdd({
@@ -186,7 +186,7 @@
int? exitCode,
Map<String, String?>? environment,
String? workingDirectory,
- bool includeParentEnvironment = true,
+ bool includeParentHomeAndPath = true,
}) async =>
await pubCommand(
RunCommand.get,
@@ -197,7 +197,7 @@
exitCode: exitCode,
environment: environment,
workingDirectory: workingDirectory,
- includeParentEnvironment: includeParentEnvironment,
+ includeParentHomeAndPath: includeParentHomeAndPath,
);
Future<void> pubUpgrade(
@@ -322,7 +322,7 @@
String? workingDirectory,
Map<String, String?>? environment,
List<String>? input,
- includeParentEnvironment = true}) async {
+ includeParentHomeAndPath = true}) async {
exitCode ??= exit_codes.SUCCESS;
// Cannot pass both output and outputJson.
assert(output == null || outputJson == null);
@@ -331,7 +331,7 @@
args: args,
workingDirectory: workingDirectory,
environment: environment,
- includeParentEnvironment: includeParentEnvironment,
+ includeParentHomeAndPath: includeParentHomeAndPath,
);
if (input != null) {
@@ -446,7 +446,7 @@
String? workingDirectory,
Map<String, String?>? environment,
bool verbose = true,
- includeParentEnvironment = true}) async {
+ includeParentHomeAndPath = true}) async {
args ??= [];
ensureDir(_pathInSandbox(appPath));
@@ -468,7 +468,21 @@
..addAll([pubPath, if (!verbose) '--verbosity=normal'])
..addAll(args);
- final mergedEnvironment = getPubTestEnvironment(tokenEndpoint);
+ final systemRoot = Platform.environment['SYSTEMROOT'];
+ final tmp = Platform.environment['TMP'];
+
+ final mergedEnvironment = {
+ if (includeParentHomeAndPath) ...{
+ 'HOME': Platform.environment['HOME'] ?? '',
+ 'PATH': Platform.environment['PATH'] ?? '',
+ },
+ // These seem to be needed for networking to work.
+ if (Platform.isWindows) ...{
+ if (systemRoot != null) 'SYSTEMROOT': systemRoot,
+ if (tmp != null) 'TMP': tmp,
+ },
+ ...getPubTestEnvironment(tokenEndpoint)
+ };
for (final e in (environment ?? {}).entries) {
var value = e.value;
if (value == null) {
@@ -482,7 +496,7 @@
environment: mergedEnvironment,
workingDirectory: workingDirectory ?? _pathInSandbox(appPath),
description: args.isEmpty ? 'pub' : 'pub ${args.first}',
- includeParentEnvironment: includeParentEnvironment);
+ includeParentEnvironment: false);
}
/// A subclass of [TestProcess] that parses pub's verbose logging output and
diff --git a/test/token/add_token_test.dart b/test/token/add_token_test.dart
index 65f7d56..e8d0dc4 100644
--- a/test/token/add_token_test.dart
+++ b/test/token/add_token_test.dart
@@ -147,7 +147,7 @@
error: contains('No config dir found.'),
exitCode: exit_codes.DATA,
environment: {'_PUB_TEST_CONFIG_DIR': null},
- includeParentEnvironment: false,
+ includeParentHomeAndPath: false,
);
});
diff --git a/test/token/remove_token_test.dart b/test/token/remove_token_test.dart
index bfe2428..df880a4 100644
--- a/test/token/remove_token_test.dart
+++ b/test/token/remove_token_test.dart
@@ -66,7 +66,7 @@
error: contains('No config dir found.'),
exitCode: exit_codes.DATA,
environment: {'_PUB_TEST_CONFIG_DIR': null},
- includeParentEnvironment: false,
+ includeParentHomeAndPath: false,
);
});
}
diff --git a/tool/test.dart b/tool/test.dart
index 7d98156..3aabf88 100755
--- a/tool/test.dart
+++ b/tool/test.dart
@@ -17,6 +17,11 @@
import 'package:pub/src/exceptions.dart';
Future<void> main(List<String> args) async {
+ if (Platform.environment['FLUTTER_ROOT'] != null) {
+ print(
+ 'WARNING: The tests will not run correctly with dart from a flutter checkout!',
+ );
+ }
Process? testProcess;
final sub = ProcessSignal.sigint.watch().listen((signal) {
testProcess?.kill(signal);