Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Unified Diff: packages/intl/test/data_directory.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « packages/intl/test/bidi_utils_test.dart ('k') | packages/intl/test/date_time_format_file_even_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/intl/test/data_directory.dart
diff --git a/packages/intl/test/data_directory.dart b/packages/intl/test/data_directory.dart
new file mode 100644
index 0000000000000000000000000000000000000000..70aa385cfbb7c3518b1bdcba4be4dd76d3882435
--- /dev/null
+++ b/packages/intl/test/data_directory.dart
@@ -0,0 +1,43 @@
+// Copyright (c) 2012, 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.
+
+/**
+ * A utility function for test and tools that compensates (at least for very
+ * simple cases) for file-dependent programs being run from different
+ * directories. The important cases are
+ * - running in the directory that contains the test itself, i.e.
+ * test/ or a sub-directory.
+ * - running in root of this package, which is where the editor and bots will
+ * run things by default
+ */
+library data_directory;
+
+import "dart:io";
+import "package:path/path.dart" as path;
+
+String get dataDirectory {
+ return path.join(intlDirectory, datesRelativeToIntl);
+}
+
+/// Returns whether [dir] is the root of the `intl` package. We validate that it
+/// is by looking for a pubspec file with the entry `name: intl`.
+bool _isIntlRoot(String dir) {
+ var file = new File(path.join(dir, 'pubspec.yaml'));
+ if (!file.existsSync()) return false;
+ return file.readAsStringSync().contains('name: intl\n');
+}
+
+String get intlDirectory {
+ var dir = path.fromUri(Platform.script);
+ var root = path.rootPrefix(dir);
+
+ while (dir != root) {
+ if (_isIntlRoot(dir)) return dir;
+ dir = path.dirname(dir);
+ }
+ throw new UnsupportedError(
+ 'Cannot find the root directory of the `intl` package.');
+}
+
+String get datesRelativeToIntl => path.join('lib', 'src', 'data', 'dates');
« no previous file with comments | « packages/intl/test/bidi_utils_test.dart ('k') | packages/intl/test/date_time_format_file_even_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698