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

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

Issue 10919098: Run dart2js tests unmodified in browser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 3 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: dart/tools/testing/dart/test_suite.dart
diff --git a/dart/tools/testing/dart/test_suite.dart b/dart/tools/testing/dart/test_suite.dart
index 943b1853ce8c959966dc8f4282d948b08ef2a087..f8a7cd51a4e323772beccaea341afe532c4c2db2 100644
--- a/dart/tools/testing/dart/test_suite.dart
+++ b/dart/tools/testing/dart/test_suite.dart
@@ -395,7 +395,11 @@ class StandardTestSuite implements TestSuite {
if (expectations.contains(SKIP)) return;
if (TestUtils.isBrowserRuntime(configuration['runtime'])) {
- enqueueBrowserTest(info, testName, expectations);
+ if (configuration['compiler'] == 'dart2js') {
+ enqueueBrowserTestNoFuss(info, testName, expectations);
+ } else {
+ enqueueBrowserTest(info, testName, expectations);
+ }
} else {
enqueueStandardTest(info, testName, expectations);
}
@@ -699,6 +703,156 @@ class StandardTestSuite implements TestSuite {
}
}
+ /**
+ * The [StandardTestSuite] has support for tests that
kasperl 2012/09/06 10:29:29 Javascript -> JavaScript (a few times)
+ * compile a test from Dart to Javascript, and then run the resulting
+ * Javascript. This function creates a working directory to hold the
+ * Javascript version of the test, and copies the appropriate framework
+ * files to that directory. It creates a [BrowserTestCase], which has
+ * two sequential steps to be run by the [ProcessQueue when] the test is
+ * executed: a compilation
+ * step and an execution step, both with the appropriate executable and
+ * arguments.
+ */
+ void enqueueBrowserTestNoFuss(TestInformation info,
kasperl 2012/09/06 10:29:29 It's hard for me to see what the difference betwee
ahe 2012/09/08 13:32:33 I'll refactor this before submitting.
+ String testName,
+ Set<String> expectations) {
+ Map optionsFromFile = info.optionsFromFile;
+ Path filePath = info.filePath;
+ String filename = filePath.toString();
+ bool isWebTest = optionsFromFile['containsDomImport'];
+
+ final String compiler = configuration['compiler'];
+ final String runtime = configuration['runtime'];
+
+ for (var vmOptions in getVmOptions(optionsFromFile)) {
+ // Create a unique temporary directory for each set of vmOptions.
+ // TODO(dart:429): Replace separate replaceAlls with a RegExp when
+ // replaceAll(RegExp, String) is implemented.
+ String optionsName = '';
+ if (getVmOptions(optionsFromFile).length > 1) {
+ optionsName = Strings.join(vmOptions, '-').replaceAll('-','')
+ .replaceAll('=','')
+ .replaceAll('/','');
+ }
+ final String tempDir = createOutputDirectory(info.filePath, optionsName);
+
+ String dartWrapperFilename = '$filePath';
+ String compiledDartWrapperFilename = '$tempDir/test.js';
+
+ String htmlPath = '$tempDir/test.html';
+ if (isWebTest) {
+ dartWrapperFilename = filename;
+ // TODO(whesse): Once test.py is retired, adjust the relative path in
+ // the client/samples/dartcombat test to its css file, remove the
+ // "../../" from this path, and move this out of the isWebTest guard.
+ // Also remove getHtmlName, and just use test.html.
+ // TODO(efortuna): this shortening of htmlFilename is a band-aid until
+ // the above TODO gets fixed. Windows cannot have paths that are longer
+ // than 260 characters, and without this hack, we were running past the
+ // the limit.
+ String htmlFilename = getHtmlName(filename);
+ while ('$tempDir/../$htmlFilename'.length >= 260) {
+ htmlFilename = htmlFilename.substring(htmlFilename.length~/2);
+ }
+ htmlPath = '$tempDir/../$htmlFilename';
+ }
+ final String scriptPath = (compiler == 'none') ?
+ dartWrapperFilename : compiledDartWrapperFilename;
+ // Create the HTML file for the test.
+ RandomAccessFile htmlTest = new File(htmlPath).openSync(FileMode.WRITE);
+ String filePrefix = '';
+ if (Platform.operatingSystem == 'windows') {
+ // Firefox on Windows does not like absolute file path names that start
+ // with 'C:' adding 'file:///' solves the problem.
+ filePrefix = 'file:///';
+ }
+ String content = null;
+ Path dir = filePath.directoryPath;
+ String nameNoExt = filePath.filenameWithoutExtension;
+ Path pngPath = dir.append('$nameNoExt.png');
+ Path txtPath = dir.append('$nameNoExt.txt');
+ Path expectedOutput = null;
+ if (new File.fromPath(pngPath).existsSync()) {
+ expectedOutput = pngPath;
+ content = getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath');
+ } else if (new File.fromPath(txtPath).existsSync()) {
+ expectedOutput = txtPath;
+ content = getHtmlLayoutContents(scriptType, '$filePrefix$scriptPath');
+ } else {
+ content = getHtmlContents(
+ filename,
+ '$filePrefix${dartDir.append("pkg/unittest/test_controller.js")}',
+ '$filePrefix${dartDir.append("client/dart.js")}',
+ scriptType,
+ '$filePrefix$scriptPath');
+ }
+ htmlTest.writeStringSync(content);
+ htmlTest.closeSync();
+
+ // Construct the command(s) that compile all the inputs needed by the
+ // browser test. For running Dart in DRT, this will be noop commands.
+ List<Command> commands = [];
+ if (compiler != 'none') {
+ commands.add(_compileCommand(
+ dartWrapperFilename, compiledDartWrapperFilename,
+ compiler, tempDir, vmOptions));
+
+ // some tests require compiling multiple input scripts.
+ List<String> otherScripts = optionsFromFile['otherScripts'];
+ for (String name in otherScripts) {
+ Path namePath = new Path(name);
+ Expect.equals(namePath.extension, 'dart');
+ String baseName = namePath.filenameWithoutExtension;
+ Path fromPath = filePath.directoryPath.join(namePath);
+ commands.add(_compileCommand(
+ fromPath.toNativePath(), '$tempDir/$baseName.js',
+ compiler, tempDir, vmOptions));
+ }
+ }
+
+ // Construct the command that executes the browser test
+ List<String> args;
+ if (runtime == 'ie' || runtime == 'ff' || runtime == 'chrome' ||
+ runtime == 'safari' || runtime == 'opera' || runtime == 'dartium') {
+ args = [dartDir.append('tools/testing/run_selenium.py').toNativePath(),
+ '--browser=$runtime',
+ '--timeout=${configuration["timeout"] - 2}',
+ '--out=$htmlPath'];
+ if (runtime == 'dartium') {
+ args.add('--executable=$dartiumFilename');
+ }
+ } else {
+ args = [
+ dartDir.append('tools/testing/drt-trampoline.py').toNativePath(),
+ dumpRenderTreeFilename,
+ '--no-timeout'
+ ];
+ if (runtime == 'drt' &&
+ (compiler == 'none' || compiler == 'dart2dart')) {
+ var dartFlags = ['--ignore-unrecognized-flags'];
+ if (configuration["checked"]) {
+ dartFlags.add('--enable_asserts');
+ dartFlags.add("--enable_type_checks");
+ }
+ dartFlags.addAll(vmOptions);
+ args.add('--dart-flags=${Strings.join(dartFlags, " ")}');
+ }
+ args.add(htmlPath);
+ if (expectedOutput != null) {
+ args.add('--out-expectation=${expectedOutput.toNativePath()}');
+ }
+ }
+ commands.add(new Command('python', args));
+
+ // Create BrowserTestCase and queue it.
+ var testCase = new BrowserTestCase('$suiteName/$testName',
+ commands, configuration, completeHandler, expectations,
+ optionsFromFile['isNegative']);
+ doTest(testCase);
+ }
+ }
+
/** Helper to create a compilation command for a single input file. */
Command _compileCommand(String inputFile, String outputFile,
String compiler, String dir, var vmOptions) {
« dart/pkg/unittest/test_controller.js ('K') | « dart/pkg/unittest/test_controller.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698