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

Unified Diff: pkg/testing/lib/src/test_description.dart

Issue 2624373003: Move package:testing to SDK. (Closed)
Patch Set: Created 3 years, 11 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 | « pkg/testing/lib/src/test_dart/status_file_parser.dart ('k') | pkg/testing/lib/src/test_root.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/testing/lib/src/test_description.dart
diff --git a/pkg/testing/lib/src/test_description.dart b/pkg/testing/lib/src/test_description.dart
new file mode 100644
index 0000000000000000000000000000000000000000..9e2495b5aeafa2826ae2636f1c1f580f8f03b668
--- /dev/null
+++ b/pkg/testing/lib/src/test_description.dart
@@ -0,0 +1,67 @@
+// Copyright (c) 2016, 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.md file.
+
+library testing.test_description;
+
+import 'dart:io' show
+ File,
+ FileSystemEntity;
+
+class TestDescription implements Comparable<TestDescription> {
+ final Uri root;
+ final File file;
+ final Uri output;
+
+ TestDescription(this.root, this.file, {this.output});
+
+ Uri get uri => file.uri;
+
+ String get shortName {
+ String baseName = "$uri".substring("$root".length);
+ return baseName.substring(0, baseName.length - ".dart".length);
+ }
+
+ String get escapedName => shortName.replaceAll("/", "__");
+
+ void writeImportOn(StringSink sink) {
+ sink.write("import '");
+ sink.write(uri);
+ sink.write("' as ");
+ sink.write(escapedName);
+ sink.writeln(" show main;");
+ }
+
+ void writeClosureOn(StringSink sink) {
+ sink.write(' "');
+ sink.write(shortName);
+ sink.write('": ');
+ sink.write(escapedName);
+ sink.writeln('.main,');
+ }
+
+ static TestDescription from(
+ Uri root, FileSystemEntity entity, {Pattern pattern}) {
+ if (entity is! File) return null;
+ pattern ??= "_test.dart";
+ String path = entity.uri.path;
+ bool hasMatch = false;
+ if (pattern is String) {
+ if (path.endsWith(pattern)) hasMatch = true;
+ } else if (path.contains(pattern)) {
+ hasMatch = true;
+ }
+ return hasMatch ? new TestDescription(root, entity) : null;
+ }
+
+ int compareTo(TestDescription other) => "$uri".compareTo("${other.uri}");
+
+ String formatError(String message) {
+ String base = Uri.base.toFilePath();
+ String path = uri.toFilePath();
+ if (path.startsWith(base)) {
+ path = path.substring(base.length);
+ }
+ return "$path:$message";
+ }
+}
« no previous file with comments | « pkg/testing/lib/src/test_dart/status_file_parser.dart ('k') | pkg/testing/lib/src/test_root.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698