blob: 435f2a7331fd838a6831a3b8062f02c50a8cb945 [file] [log] [blame]
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// 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.
/// Test date formatting and parsing while the system time zone is set.
import 'package:test/test.dart';
import 'dart:io';
import 'dart:convert';
// This test relies on setting the TZ environment variable to affect the
// system's time zone calculations. That's only effective on Linux environments,
// and would only work in a browser if we were able to set it before the browser
// launched, which we aren't. So restrict this test to the VM and Linux.
/// The VM arguments we were given, most importantly package-root.
final vmArgs = Platform.executableArguments;
final dart = Platform.executable;
/// Test for a particular timezone. In order to verify that we are in fact
/// running in that time zone, verify that the DateTime offset is one of the
/// expected values.
testTimezone(String timezoneName, {int expectedUtcOffset}) {
// The VM can be invoked with a "-DPACKAGE_DIR=<directory>" argument to
// indicate the root of the Intl package. If it is not provided, we assume
// that the root of the Intl package is the current directory.
var packageDir = new String.fromEnvironment('PACKAGE_DIR');
var packageRelative = 'test/timezone_local_even_test_helper.dart';
var fileToSpawn =
packageDir == null ? packageRelative : '$packageDir/$packageRelative';
test("Run tests in $timezoneName time zone", () async {
List<String> args = []
var environment = <String, String>{'TZ': timezoneName};
if (expectedUtcOffset != null) {
environment['EXPECTED_TZ_OFFSET_FOR_TEST'] = '$expectedUtcOffset';
var result = await, args,
stdoutEncoding: UTF8,
stderrEncoding: UTF8,
includeParentEnvironment: true,
environment: environment);
// Because the actual tests are run in a spawned parocess their output isn't
// directly visible here. To debug, it's necessary to look at the output of
// that test, so we print it here for convenience.
print("Spawning test to run in the $timezoneName time zone. Stderr is:");
print("Spawned test in $timezoneName time zone has Stdout:");
expect(result.exitCode, 0,
reason: "Spawned test failed. See the test log from stderr to debug");