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

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

Issue 8754001: Dart tests: Create generated tests in build directory in test.dart. (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 | « no previous file | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/testing/dart/multitest.dart
diff --git a/tools/testing/dart/multitest.dart b/tools/testing/dart/multitest.dart
index f6788a315d5115cfffd9fb3d5f2a51f49e2b8d75..74ddafd57054f5c9cdee956a3b98544056a8ab7a 100644
--- a/tools/testing/dart/multitest.dart
+++ b/tools/testing/dart/multitest.dart
@@ -75,7 +75,11 @@ void ExtractTestsFromMultitest(String filename,
// Create the set of multitests, which will have a new test added each
// time we see a multitest line with a new key.
Map<String, List<String>> testsAsLines = new Map<String, List<String>>();
-
+
+ // Matches #import( or #source( followed by " or ' followed by anything
+ // except dart: or /, at the beginning of a line.
+ RegExp relativeImportRegExp =
+ const RegExp('^#(import|source)[(]["\'](?!(dart:|/))');
for (String line in lines) {
if (line.contains('///')) {
var parts = line.split('///')[1].split(':');
@@ -90,16 +94,14 @@ void ExtractTestsFromMultitest(String filename,
Expect.isTrue(validMultitestOutcomes.contains(rest));
}
} else {
- if ((line.startsWith('#import(') || line.startsWith('#source(')) &&
- !line.contains("dart:")) {
- // TODO(whesse): Rewrite relative paths to reflect temporary directory.
- tests = [];
- outcomes = [];
- return;
- }
testTemplate.add(line);
for (var test in testsAsLines.getValues()) test.add(line);
}
+ // Warn if any import or source tags have relative paths.
+ if (relativeImportRegExp.hasMatch(line)) {
+ print('Warning: Multitest cannot contain relative imports:');
+ print(' $filename: $line');
+ }
}
// Add the template, with no multitest lines, as a test with key 'none'.
testsAsLines['none'] = testTemplate;
@@ -114,6 +116,8 @@ void ExtractTestsFromMultitest(String filename,
void DoMultitest(String filename,
+ String buildDir,
+ String testDir,
Function doTest(List<String> args,
bool isNegative,
bool isNegativeIfChecked)) {
@@ -121,22 +125,15 @@ void DoMultitest(String filename,
Map<String, String> tests = new Map<String, String>();
Map<String, String> outcomes = new Map<String, String>();
ExtractTestsFromMultitest(filename, tests, outcomes);
+
+ String directory = CreateMultitestDirectory(buildDir, testDir);
String pathSeparator = new Platform().pathSeparator();
int start = filename.lastIndexOf(pathSeparator) + 1;
int end = filename.indexOf('.dart', start);
String baseFilename = filename.substring(start, end);
- Directory dir = new Directory("");
- dir.errorHandler =
- (error) { Expect.fail("Error creating temp directory: $error"); };
-
- dir.createTempHandler = () {
- String path = dir.path + new Platform().pathSeparator();
- Iterator currentKey = tests.getKeys().iterator();
- WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey,
- '$path$baseFilename', doTest);
- };
-
- dir.createTemp();
+ Iterator currentKey = tests.getKeys().iterator();
+ WriteMultitestToFileAndQueueIt(tests, outcomes, currentKey,
+ '$directory$pathSeparator$baseFilename', doTest);
}
@@ -178,3 +175,22 @@ WriteMultitestToFileAndQueueIt(Map<String, String> tests,
};
file.create();
}
+
+String CreateMultitestDirectory(String buildDir, String testDir) {
+ final String generatedTestDirectory = 'generated_tests/';
+ Directory parent_dir = new Directory(buildDir + generatedTestDirectory);
+ if (!parent_dir.existsSync()) {
+ parent_dir.createSync();
+ }
+ final String prefix = 'tests/';
+ final String suffix = '/src';
+ Expect.isTrue(testDir.startsWith(prefix));
+ Expect.isTrue(testDir.endsWith(suffix));
+ String path = parent_dir.path +
+ testDir.substring(prefix.length, testDir.length - suffix.length);
+ Directory dir = new Directory(path);
+ if (!dir.existsSync()) {
+ dir.createSync();
+ }
+ return path;
+}
« no previous file with comments | « no previous file | tools/testing/dart/test_suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698