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

Side by Side Diff: tests/compiler/dart2js/zero_termination_test.dart

Issue 2238073005: Fix http test (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « tests/compiler/dart2js/quarantined/http_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 import 'dart:async'; 11 import 'dart:async';
12 import 'dart:convert'; 12 import 'dart:convert';
13 import 'dart:io'; 13 import 'dart:io';
14 import 'package:async_helper/async_helper.dart'; 14 import 'package:async_helper/async_helper.dart';
15 import 'package:expect/expect.dart'; 15 import 'package:expect/expect.dart';
16 import 'package:path/path.dart' as path; 16 import 'package:path/path.dart' as path;
17 17
18 import 'launch_helper.dart' show launchDart2Js;
19
18 Uri pathOfData = Platform.script; 20 Uri pathOfData = Platform.script;
19 Directory tempDir; 21 Directory tempDir;
20 String outFilePath; 22 String outFilePath;
21 23
22 _sendNotFound(HttpResponse response) { 24 _sendNotFound(HttpResponse response) {
23 response.statusCode = HttpStatus.NOT_FOUND; 25 response.statusCode = HttpStatus.NOT_FOUND;
24 response.close(); 26 response.close();
25 } 27 }
26 28
27 Future handleRequest(HttpRequest request) { 29 Future handleRequest(HttpRequest request) {
(...skipping 11 matching lines...) Expand all
39 }); 41 });
40 } 42 }
41 43
42 void cleanup() { 44 void cleanup() {
43 File outFile = new File(outFilePath); 45 File outFile = new File(outFilePath);
44 if (outFile.existsSync()) { 46 if (outFile.existsSync()) {
45 outFile.deleteSync(); 47 outFile.deleteSync();
46 } 48 }
47 } 49 }
48 50
49 Future launchDart2Js(args) {
50 String dart2jsPath = path.normalize(
51 path.join(path.fromUri(Platform.script),
52 '../../../../pkg/compiler/lib/src/dart2js.dart'));
53 List allArgs = [];
54 if (Platform.packageRoot != null) {
55 allArgs.add('--package-root=${Platform.packageRoot}');
56 } else if (Platform.packageConfig != null) {
57 allArgs.add('--packages=${Platform.packageConfig}');
58 }
59 allArgs.add(dart2jsPath);
60 allArgs.addAll(args);
61 return Process.run(Platform.executable, allArgs, stdoutEncoding: null);
62 }
63
64 void check(ProcessResult result) { 51 void check(ProcessResult result) {
65 Expect.notEquals(0, result.exitCode); 52 Expect.notEquals(0, result.exitCode);
66 List<int> stdout = result.stdout; 53 List<int> stdout = result.stdout;
67 String stdoutString = UTF8.decode(stdout); 54 String stdoutString = UTF8.decode(stdout);
68 Expect.isTrue(stdoutString.contains("Error")); 55 Expect.isTrue(stdoutString.contains("Error"));
69 // Make sure the "499" from the last line is in the output. 56 // Make sure the "499" from the last line is in the output.
70 Expect.isTrue(stdoutString.contains("499")); 57 Expect.isTrue(stdoutString.contains("499"));
71 58
72 // Make sure that the output does not contain any 0 character. 59 // Make sure that the output does not contain any 0 character.
73 Expect.isFalse(stdout.contains(0)); 60 Expect.isFalse(stdout.contains(0));
74 } 61 }
75 62
76 Future testFile() async { 63 Future testFile() async {
77 String inFilePath = 64 String inFilePath =
78 pathOfData.resolve('data/one_line_dart_program.dart').path; 65 pathOfData.resolve('data/one_line_dart_program.dart').path;
79 List<String> args = [inFilePath, "--out=" + outFilePath]; 66 List<String> args = [inFilePath, "--out=" + outFilePath];
80 67
81 await cleanup(); 68 await cleanup();
82 check(await launchDart2Js(args)); 69 check(await launchDart2Js(args, noStdoutEncoding: true));
83 await cleanup(); 70 await cleanup();
84 } 71 }
85 72
86 Future serverRunning(HttpServer server) async { 73 Future serverRunning(HttpServer server) async {
87 int port = server.port; 74 int port = server.port;
88 String inFilePath = "http://127.0.0.1:$port/data/one_line_dart_program.dart"; 75 String inFilePath = "http://127.0.0.1:$port/data/one_line_dart_program.dart";
89 List<String> args = [inFilePath, "--out=" + outFilePath]; 76 List<String> args = [inFilePath, "--out=" + outFilePath];
90 77
91 server.listen(handleRequest); 78 server.listen(handleRequest);
92 try { 79 try {
93 await cleanup(); 80 await cleanup();
94 check(await launchDart2Js(args)); 81 check(await launchDart2Js(args, noStdoutEncoding: true));
95 } finally { 82 } finally {
96 await server.close(); 83 await server.close();
97 await cleanup(); 84 await cleanup();
98 } 85 }
99 } 86 }
100 87
101 Future testHttp() { 88 Future testHttp() {
102 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0) 89 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0)
103 .then((HttpServer server) => serverRunning(server)); 90 .then((HttpServer server) => serverRunning(server));
104 } 91 }
105 92
106 runTests() async { 93 runTests() async {
107 tempDir = Directory.systemTemp.createTempSync('directory_test'); 94 tempDir = Directory.systemTemp.createTempSync('directory_test');
108 outFilePath = path.join(tempDir.path, "out.js"); 95 outFilePath = path.join(tempDir.path, "out.js");
109 96
110 try { 97 try {
111 await testFile(); 98 await testFile();
112 await testHttp(); 99 await testHttp();
113 } finally { 100 } finally {
114 await tempDir.delete(recursive:true); 101 await tempDir.delete(recursive:true);
115 } 102 }
116 } 103 }
117 104
118 main() { 105 main() {
119 asyncStart(); 106 asyncStart();
120 runTests().whenComplete(asyncEnd); 107 runTests().whenComplete(asyncEnd);
121 } 108 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/quarantined/http_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698