| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 // A regression test for issue 22667. |
| 6 // |
| 7 // Makes sure that we don't print a '\0' character for files that are not |
| 8 // properly new-line terminated. |
| 9 library zero_termination_test; |
| 10 |
| 11 import 'dart:async'; |
| 12 import 'dart:convert'; |
| 13 import 'dart:io'; |
| 14 import 'package:async_helper/async_helper.dart'; |
| 15 import 'package:expect/expect.dart'; |
| 16 import 'package:path/path.dart' as path; |
| 17 |
| 18 Uri pathOfData = Platform.script; |
| 19 Directory tempDir; |
| 20 String outFilePath; |
| 21 |
| 22 _sendNotFound(HttpResponse response) { |
| 23 response.statusCode = HttpStatus.NOT_FOUND; |
| 24 response.close(); |
| 25 } |
| 26 |
| 27 Future handleRequest(HttpRequest request) { |
| 28 final String path = request.uri.path.substring(1); |
| 29 final Uri requestPath = pathOfData.resolve(path); |
| 30 final File file = new File(requestPath.toFilePath()); |
| 31 return file.exists().then((bool found) { |
| 32 if (found) { |
| 33 file.openRead() |
| 34 .pipe(request.response) |
| 35 .catchError((e) { _sendNotFound(request.response); }); |
| 36 } else { |
| 37 _sendNotFound(request.response); |
| 38 } |
| 39 }); |
| 40 } |
| 41 |
| 42 void cleanup() { |
| 43 File outFile = new File(outFilePath); |
| 44 if (outFile.existsSync()) { |
| 45 outFile.deleteSync(); |
| 46 } |
| 47 } |
| 48 |
| 49 Future launchDart2Js(args) { |
| 50 String ext = Platform.isWindows ? '.bat' : ''; |
| 51 String command = |
| 52 path.normalize(path.join(path.fromUri(Platform.script), |
| 53 '../../../../sdk/bin/dart2js${ext}')); |
| 54 return Process.run(command, args, stdoutEncoding: null); |
| 55 } |
| 56 |
| 57 void check(ProcessResult result) { |
| 58 Expect.notEquals(0, result.exitCode); |
| 59 List<int> stdout = result.stdout; |
| 60 String stdoutString = UTF8.decode(stdout); |
| 61 Expect.isTrue(stdoutString.contains("Error")); |
| 62 // Make sure the "499" from the last line is in the output. |
| 63 Expect.isTrue(stdoutString.contains("499")); |
| 64 |
| 65 // Make sure that the output does not contain any 0 character. |
| 66 Expect.isFalse(stdout.contains(0)); |
| 67 } |
| 68 |
| 69 Future testFile() async { |
| 70 String inFilePath = pathOfData.resolve('one_line_dart_program.dart').path; |
| 71 List<String> args = [inFilePath, "--out=" + outFilePath]; |
| 72 |
| 73 await cleanup(); |
| 74 check(await launchDart2Js(args)); |
| 75 await cleanup(); |
| 76 } |
| 77 |
| 78 Future serverRunning(HttpServer server) async { |
| 79 int port = server.port; |
| 80 String inFilePath = "http://127.0.0.1:$port/one_line_dart_program.dart"; |
| 81 List<String> args = [inFilePath, "--out=" + outFilePath]; |
| 82 |
| 83 server.listen(handleRequest); |
| 84 try { |
| 85 await cleanup(); |
| 86 check(await launchDart2Js(args)); |
| 87 } finally { |
| 88 await server.close(); |
| 89 await cleanup(); |
| 90 } |
| 91 } |
| 92 |
| 93 Future testHttp() { |
| 94 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0) |
| 95 .then((HttpServer server) => serverRunning(server)); |
| 96 } |
| 97 |
| 98 runTests() async { |
| 99 tempDir = Directory.systemTemp.createTempSync('directory_test'); |
| 100 outFilePath = path.join(tempDir.path, "out.js"); |
| 101 |
| 102 try { |
| 103 await testFile(); |
| 104 await testHttp(); |
| 105 } finally { |
| 106 await tempDir.delete(recursive:true); |
| 107 } |
| 108 } |
| 109 |
| 110 main() { |
| 111 asyncStart(); |
| 112 runTests().whenComplete(asyncEnd); |
| 113 } |
| OLD | NEW |