| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
| 10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 return Directory.systemTemp | 30 return Directory.systemTemp |
| 31 .createTemp('dart2js_batch_test-') | 31 .createTemp('dart2js_batch_test-') |
| 32 .then((Directory dir) { | 32 .then((Directory dir) { |
| 33 return dir; | 33 return dir; |
| 34 }); | 34 }); |
| 35 } | 35 } |
| 36 | 36 |
| 37 Future setup() { | 37 Future setup() { |
| 38 return createTempDir().then((Directory directory) { | 38 return createTempDir().then((Directory directory) { |
| 39 tmpDir = directory; | 39 tmpDir = directory; |
| 40 Directory sunflowerDir = new Directory.fromUri( | 40 String newPath = path.join(directory.path, "dart2js_batch2_run.dart"); |
| 41 Platform.script.resolve('../../../third_party/sunflower')); | 41 File source = |
| 42 | 42 new File(Platform.script.resolve("dart2js_batch2_run.dart").path); |
| 43 print("Copying '${sunflowerDir.path}' to '${tmpDir.path}'."); | 43 source.copySync(newPath); |
| 44 copyDirectory(sunflowerDir, tmpDir); | |
| 45 }); | 44 }); |
| 46 } | 45 } |
| 47 | 46 |
| 48 void cleanUp() { | 47 void cleanUp() { |
| 49 print("Deleting '${tmpDir.path}'."); | 48 print("Deleting '${tmpDir.path}'."); |
| 50 tmpDir.deleteSync(recursive: true); | 49 tmpDir.deleteSync(recursive: true); |
| 51 } | 50 } |
| 52 | 51 |
| 53 Future launchDart2Js(_) { | 52 Future launchDart2Js(_) { |
| 54 String ext = Platform.isWindows ? '.bat' : ''; | 53 String ext = Platform.isWindows ? '.bat' : ''; |
| 55 String command = | 54 String command = |
| 56 path.normalize(path.join(path.fromUri(Platform.script), | 55 path.normalize(path.join(path.fromUri(Platform.script), |
| 57 '../../../../sdk/bin/dart2js${ext}')); | 56 '../../../../sdk/bin/dart2js${ext}')); |
| 58 print("Running '$command --batch' from '${tmpDir}'."); | 57 print("Running '$command --batch' from '${tmpDir}'."); |
| 59 return Process.start(command, ['--batch'], workingDirectory: tmpDir.path); | 58 return Process.start(command, ['--batch'], workingDirectory: tmpDir.path); |
| 60 } | 59 } |
| 61 | 60 |
| 62 Future runTests(Process process) { | 61 Future runTests(Process process) { |
| 63 String inFile = path.join(tmpDir.path, 'web/sunflower.dart'); | 62 String inFile = path.join(tmpDir.path, 'dart2js_batch2_run.dart'); |
| 64 String outFile = path.join(tmpDir.path, 'out.js'); | 63 String outFile = path.join(tmpDir.path, 'out.js'); |
| 65 String outFile2 = path.join(tmpDir.path, 'out2.js'); | |
| 66 | 64 |
| 67 process.stdin.writeln('--out="$outFile" "$inFile"'); | 65 process.stdin.writeln('--out="$outFile" "$inFile"'); |
| 68 process.stdin.writeln('--out="$outFile2" "$inFile"'); | |
| 69 process.stdin.writeln('too many arguments'); | |
| 70 process.stdin.writeln(r'"non existing file.dart"'); | |
| 71 process.stdin.close(); | 66 process.stdin.close(); |
| 72 Future<String> output = process.stdout.transform(UTF8.decoder).join(); | 67 Future<String> output = process.stdout.transform(UTF8.decoder).join(); |
| 73 Future<String> errorOut = process.stderr.transform(UTF8.decoder).join(); | 68 Future<String> errorOut = process.stderr.transform(UTF8.decoder).join(); |
| 74 return Future.wait([output, errorOut]) | 69 return Future.wait([output, errorOut]) |
| 75 .then((result) { | 70 .then((result) { |
| 76 String stdoutOutput = result[0]; | 71 String stdoutOutput = result[0]; |
| 77 print('out:\n$stdoutOutput'); | |
| 78 String stderrOutput = result[1]; | 72 String stderrOutput = result[1]; |
| 79 print('err:\n$stderrOutput'); | |
| 80 | 73 |
| 81 Expect.equals(4, ">>> EOF STDERR".allMatches(stderrOutput).length); | 74 Expect.isFalse(stdoutOutput.contains("crashed")); |
| 82 Expect.equals(4, ">>>".allMatches(stderrOutput).length); | |
| 83 | |
| 84 Expect.equals(2, ">>> TEST OK".allMatches(stdoutOutput).length); | |
| 85 Expect.equals(2, ">>> TEST FAIL".allMatches(stdoutOutput).length); | |
| 86 Expect.equals(4, ">>>".allMatches(stdoutOutput).length); | |
| 87 }); | 75 }); |
| 88 } | 76 } |
| 89 | 77 |
| 90 void main() { | 78 void main() { |
| 91 var tmpDir; | 79 var tmpDir; |
| 92 asyncTest(() { | 80 asyncTest(() { |
| 93 return setup() | 81 return setup() |
| 94 .then(launchDart2Js) | 82 .then(launchDart2Js) |
| 95 .then(runTests) | 83 .then(runTests) |
| 96 .whenComplete(cleanUp); | 84 .whenComplete(cleanUp); |
| 97 }); | 85 }); |
| 98 } | 86 } |
| OLD | NEW |