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

Unified Diff: tools/testing/dart/test_config_utils.dart

Issue 8574052: Start extracting common test_config.dart functionality into a utility library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 9 years, 1 month 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 | « tests/standalone/test_config.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/test_config_utils.dart
diff --git a/tools/testing/dart/test_config_utils.dart b/tools/testing/dart/test_config_utils.dart
new file mode 100644
index 0000000000000000000000000000000000000000..71a6dd87e71beeef9d76b31eb532f6c9480ca766
--- /dev/null
+++ b/tools/testing/dart/test_config_utils.dart
@@ -0,0 +1,93 @@
+// Copyright (c) 2011, 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.
+
+#library("test_config_utils");
+
+/**
+ * TestUtils is a collection of utility methods used to write
+ * test_config.dart scripts for test suites.
+ */
+class TestUtils {
+
+ /**
+ * Get a list of argument lists for the dart shell command.
+ */
+ static List<List<String>> argumentLists(String filename,
+ Map optionsFromFile,
+ Map configuration) {
+ List args = ["--ignore-unrecognized-flags"];
+ if (configuration["checked"]) {
+ args.add("--enable_type_checks");
+ }
+ if (configuration["component"] == "leg") {
+ args.add("--enable_leg");
+ }
+
+ List<String> dartOptions = optionsFromFile["dartOptions"];
+ args.addAll(dartOptions == null ? [filename] : dartOptions);
+
+ var result = new List<List<String>>();
+ List<List<String>> vmOptionsList = optionsFromFile["vmOptions"];
+ if (vmOptionsList.isEmpty()) return [args];
+ for (var vmOptions in vmOptionsList) {
Bill Hesse 2011/11/17 09:35:24 I like better if (vmOptionsList.isEmpty() { res
Mads Ager (google) 2011/11/17 09:38:07 Done. I actually like the early return better but
+ vmOptions.addAll(args);
+ result.add(vmOptions);
+ }
+
+ return result;
+ }
+
+ /**
+ * Extract test options from the test file itself.
+ */
+ static Map optionsFromFile(String filename, Map configuration) {
+ RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
+ RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
+
+ // Read the entire file into a byte buffer and transform it to a
+ // String. This will treat the file as ascii but the only parts
+ // we are interested in will be ascii in any case.
+ File file = new File(filename);
+ file.openSync();
+ List chars = new List(file.lengthSync());
+ var offset = 0;
+ while (offset != chars.length) {
+ offset += file.readListSync(chars, offset, chars.length - offset);
+ }
+ file.closeSync();
+ String contents = new String.fromCharCodes(chars);
+ chars = null;
+
+ // Find the options in the file.
+ List<List> result = new List<List>();
+ List<String> dartOptions;
+ bool isNegative = false;
+
+ Iterable<Match> matches = testOptionsRegExp.allMatches(contents);
+ for (var match in matches) {
+ result.add(match[1].split(' ').filter((e) => e != ''));
+ }
+
+ matches = dartOptionsRegExp.allMatches(contents);
+ for (var match in matches) {
+ if (dartOptions != null) {
+ throw new Exception(
+ 'More than one "// DartOptions=" line in test $filename');
+ }
+ dartOptions = match[1].split(' ').filter((e) => e != '');
+ }
+
+ if (contents.contains("@compile-error") ||
+ contents.contains("@runtime-error")) {
+ isNegative = true;
+ } else if (contents.contains("@dynamic-type-error") &&
+ configuration['checked']) {
+ isNegative = true;
+ }
+
+ return { "vmOptions": result,
+ "dartOptions": dartOptions,
+ "isNegative" : isNegative };
+ }
+}
« no previous file with comments | « tests/standalone/test_config.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698