| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 // A regression test for issue 22667. | 5 // A regression test for issue 22667. |
| 6 // | 6 // |
| 7 // Makes sure that we don't print a '\0' character for files that are not | 7 // Makes sure that we don't print a '\0' character for files that are not |
| 8 // properly new-line terminated. | 8 // properly new-line terminated. |
| 9 library zero_termination_test; | 9 library zero_termination_test; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 response.statusCode = HttpStatus.NOT_FOUND; | 25 response.statusCode = HttpStatus.NOT_FOUND; |
| 26 response.close(); | 26 response.close(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 Future handleRequest(HttpRequest request) { | 29 Future handleRequest(HttpRequest request) { |
| 30 final String path = request.uri.path.substring(1); | 30 final String path = request.uri.path.substring(1); |
| 31 final Uri requestPath = pathOfData.resolve(path); | 31 final Uri requestPath = pathOfData.resolve(path); |
| 32 final File file = new File(requestPath.toFilePath()); | 32 final File file = new File(requestPath.toFilePath()); |
| 33 return file.exists().then((bool found) { | 33 return file.exists().then((bool found) { |
| 34 if (found) { | 34 if (found) { |
| 35 file.openRead() | 35 file.openRead().pipe(request.response).catchError((e) { |
| 36 .pipe(request.response) | 36 _sendNotFound(request.response); |
| 37 .catchError((e) { _sendNotFound(request.response); }); | 37 }); |
| 38 } else { | 38 } else { |
| 39 _sendNotFound(request.response); | 39 _sendNotFound(request.response); |
| 40 } | 40 } |
| 41 }); | 41 }); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void cleanup() { | 44 void cleanup() { |
| 45 File outFile = new File(outFilePath); | 45 File outFile = new File(outFilePath); |
| 46 if (outFile.existsSync()) { | 46 if (outFile.existsSync()) { |
| 47 outFile.deleteSync(); | 47 outFile.deleteSync(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 try { | 79 try { |
| 80 await cleanup(); | 80 await cleanup(); |
| 81 check(await launchDart2Js(args, noStdoutEncoding: true)); | 81 check(await launchDart2Js(args, noStdoutEncoding: true)); |
| 82 } finally { | 82 } finally { |
| 83 await server.close(); | 83 await server.close(); |
| 84 await cleanup(); | 84 await cleanup(); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 Future testHttp() { | 88 Future testHttp() { |
| 89 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0) | 89 return HttpServer |
| 90 .bind(InternetAddress.LOOPBACK_IP_V4, 0) |
| 90 .then((HttpServer server) => serverRunning(server)); | 91 .then((HttpServer server) => serverRunning(server)); |
| 91 } | 92 } |
| 92 | 93 |
| 93 runTests() async { | 94 runTests() async { |
| 94 tempDir = Directory.systemTemp.createTempSync('directory_test'); | 95 tempDir = Directory.systemTemp.createTempSync('directory_test'); |
| 95 outFilePath = path.join(tempDir.path, "out.js"); | 96 outFilePath = path.join(tempDir.path, "out.js"); |
| 96 | 97 |
| 97 try { | 98 try { |
| 98 await testFile(); | 99 await testFile(); |
| 99 await testHttp(); | 100 await testHttp(); |
| 100 } finally { | 101 } finally { |
| 101 await tempDir.delete(recursive:true); | 102 await tempDir.delete(recursive: true); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 main() { | 106 main() { |
| 106 asyncStart(); | 107 asyncStart(); |
| 107 runTests().whenComplete(asyncEnd); | 108 runTests().whenComplete(asyncEnd); |
| 108 } | 109 } |
| OLD | NEW |