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

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

Issue 10683009: Adds support for layout tests. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 6 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
Index: tools/testing/dart/test_suite.dart
diff --git a/tools/testing/dart/test_suite.dart b/tools/testing/dart/test_suite.dart
index 5eabfd167a912a7af096b24046eb9d89fe4b7bdd..0eef6a926ffa4b30a7253054fa80ed295a22acd4 100644
--- a/tools/testing/dart/test_suite.dart
+++ b/tools/testing/dart/test_suite.dart
@@ -519,6 +519,7 @@ class StandardTestSuite implements TestSuite {
String filename = info.filename;
if (optionsFromFile['isMultitest']) return;
bool isWebTest = optionsFromFile['containsDomImport'];
+ List<String> webTestOutput = optionsFromFile['webTestOutput'];
bool isLibraryDefinition = optionsFromFile['isLibraryDefinition'];
if (!isLibraryDefinition && optionsFromFile['containsSourceOrImport']) {
print('Warning for $filename: Browser tests require #library '
@@ -556,14 +557,14 @@ class StandardTestSuite implements TestSuite {
dartLibraryFilename = 'test_as_library.dart';
File file = new File('$tempDir/$dartLibraryFilename');
RandomAccessFile dartLibrary = file.openSync(FileMode.WRITE);
- dartLibrary.writeStringSync(WrapDartTestInLibrary(testPath));
+ dartLibrary.writeStringSync(wrapDartTestInLibrary(testPath));
dartLibrary.closeSync();
}
File file = new File(dartWrapperFilename);
RandomAccessFile dartWrapper = file.openSync(FileMode.WRITE);
dartWrapper.writeStringSync(
- DartTestWrapper(dartDir, dartLibraryFilename));
+ dartTestWrapper(dartDir, dartLibraryFilename));
dartWrapper.closeSync();
} else {
dartWrapperFilename = testPath;
@@ -591,11 +592,17 @@ class StandardTestSuite implements TestSuite {
// with 'C:' adding 'file:///' solves the problem.
filePrefix = 'file:///';
}
- htmlTest.writeStringSync(GetHtmlContents(
+ String content;
+ if (webTestOutput.isEmpty()) {
+ content = getHtmlContents(
filename,
'$filePrefix$dartDir/lib/unittest/test_controller.js',
scriptType,
- '$filePrefix$scriptPath'));
+ '$filePrefix$scriptPath');
+ } else {
+ content = getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath');
+ }
+ htmlTest.writeStringSync(content);
htmlTest.closeSync();
// Construct the command(s) that compile all the inputs needed by the
@@ -609,14 +616,13 @@ class StandardTestSuite implements TestSuite {
// some tests require compiling multiple input scripts.
List<String> otherScripts = optionsFromFile['otherScripts'];
for (String name in otherScripts) {
- int end = filename.lastIndexOf('/');
- if (end == -1) {
+ String dir = _dirNameFromFile(filename);
+ if (dir == null) {
print('Warning: error processing "OtherScripts" of $filename.');
print('Skipping test ($testName).');
return;
}
- String dir = filename.substring(0, end);
- end = name.lastIndexOf('.dart');
+ int end = name.lastIndexOf('.dart');
if (end == -1) {
print('Warning: error processing "OtherScripts" in $filename.');
print('Skipping test ($testName).');
@@ -656,6 +662,10 @@ class StandardTestSuite implements TestSuite {
args.add('--dart-flags=${Strings.join(dartFlags, " ")}');
}
args.add(htmlPath);
+ if (!webTestOutput.isEmpty()) {
+ String dir = _dirNameFromFile(filename);
+ args.add('--out-expectation=$dir/${webTestOutput[0]}');
+ }
}
commands.add(new Command('python', args));
@@ -667,6 +677,11 @@ class StandardTestSuite implements TestSuite {
}
}
+ String _dirNameFromFile(String filename) {
+ int end = filename.lastIndexOf('/');
+ return (end == -1) ? null : filename.substring(0, end);
+ }
+
/** Helper to create a compilation command for a single input file. */
Command _compileCommand(String inputFile, String outputFile,
String compiler, String dir, var vmOptions) {
@@ -852,10 +867,57 @@ class StandardTestSuite implements TestSuite {
return result;
}
+ /**
+ * Special options for individual tests are specified with comments directly
+ * in test files. Here is a list of parameters available:
+ * - Flags can be passed to the vm or dartium process that runs the test as
+ * follows:
+ *
+ * // VMOptions=--flag1 --flag2
+ *
+ * - Flags can be passed to the dart script that contains the test as
+ * follows:
+ *
+ * // DartOptions=--flag1 --flag2
+ *
+ * - For tests that depend on compiling other files with dart2js (e.g.
+ * isolate tests that use multiple source scripts), you can specify
+ * additional files to compile as follows:
+ *
+ * // OtherScripts=file1.dart file2.dart
+ *
+ * - You can indicate whether a test is treated as a web-only test as
+ * follows:
+ *
+ * // WebTest=true
Siggi Cherem (dart-lang) 2012/06/27 01:50:42 this is something I'm adding on a separate CL (htt
+ *
+ * Most tests are not web tests, but can (and will be) wrapped within
+ * another script file to test them also on browser environments (e.g.
+ * language and corelib tests are run this way). Specifing this flag means
+ * that no wrapping is necessary.
+ *
+ * - Using test expectations for layout tests:
+ *
+ * // WebTestOutput=expected_file.txt
+ * or
+ * // WebTestOutput=expected_file.png
+ *
+ * By default tests are run without expectation files: test.dart assumes
Bill Hesse 2012/06/27 09:24:37 Say "web tests" here, not just "tests". This only
Siggi Cherem (dart-lang) 2012/06/27 20:21:05 Done.
+ * tests fail if the process return a non-zero exit code (in the case of web
+ * tests, we check for PASS/FAIL indications in the test output). Specifying
+ * a test output explicitly will check that the test output matches that
+ * specified in the expectation file. In particular, the output of a web
+ * test will be a rendering representation (either in text form if the
+ * expectation ends in .txt, or an image, if the expectation ends in .png).
+ * These expectations can be recorded for the first time by specifying the
+ * option above, running the test, and running the copy command printed by
+ * the test script.
+ */
Map readOptionsFromFile(String filename) {
RegExp testOptionsRegExp = const RegExp(@"// VMOptions=(.*)");
RegExp dartOptionsRegExp = const RegExp(@"// DartOptions=(.*)");
RegExp otherScriptsRegExp = const RegExp(@"// OtherScripts=(.*)");
+ RegExp testOutputRegExp = const RegExp(@"// WebTestOutput=(.*)");
RegExp multiTestRegExp = const RegExp(@"/// [0-9][0-9]:(.*)");
RegExp staticTypeRegExp =
const RegExp(@"/// ([0-9][0-9]:){0,1}\s*static type warning");
@@ -915,10 +977,12 @@ class StandardTestSuite implements TestSuite {
isStaticClean = true;
}
- List<String> otherScripts = new List<String>();
- matches = otherScriptsRegExp.allMatches(contents);
- for (var match in matches) {
- otherScripts.addAll(match[1].split(' ').filter((e) => e != ''));
+ List<String> otherScripts = _readListOption(otherScriptsRegExp, contents);
+ List<String> webTestOutput = _readListOption(testOutputRegExp, contents);
+ if (!webTestOutput.isEmpty() && webTestOutput.length > 1) {
+ throw new Exception(
+ 'Please use a single expected output for '
+ '"// WebTestOutput=" in $filename');
}
if (contents.contains("@compile-error")) {
@@ -954,12 +1018,21 @@ class StandardTestSuite implements TestSuite {
"containsLeadingHash": containsLeadingHash,
"isolateStubs": isolateStubs,
"containsDomImport": containsDomImport,
+ "webTestOutput": webTestOutput,
"isLibraryDefinition": isLibraryDefinition,
"containsSourceOrImport": containsSourceOrImport,
"numStaticTypeAnnotations": numStaticTypeAnnotations,
"numCompileTimeAnnotations": numCompileTimeAnnotations};
}
+ static List<String> _readListOption(RegExp matcher, String contents) {
+ List<String> res = new List<String>();
+ for (var match in matcher.allMatches(contents)) {
+ res.addAll(match[1].split(' ').filter((e) => e != ''));
+ }
+ return res;
+ }
+
List<List<String>> getVmOptions(Map optionsFromFile) {
if (configuration['compiler'] == 'dart2js') {
return [[]];

Powered by Google App Engine
This is Rietveld 408576698