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

Side by Side Diff: test/codegen_test.dart

Issue 1056613002: reduce diff churn due to server_mode test (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 8 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 | « test/codegen/expect/server_mode/html_input.txt ('k') | tool/test.sh » ('j') | 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 /// Tests code generation. 5 /// Tests code generation.
6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks 6 /// Runs Dart Dev Compiler on all input in the `codegen` directory and checks
7 /// that the output is what we expected. 7 /// that the output is what we expected.
8 library dev_compiler.test.codegen_test; 8 library dev_compiler.test.codegen_test;
9 9
10 import 'dart:io'; 10 import 'dart:io';
11 import 'package:cli_util/cli_util.dart' show getSdkDir; 11 import 'package:cli_util/cli_util.dart' show getSdkDir;
12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine, Logger; 12 import 'package:analyzer/src/generated/engine.dart' show AnalysisEngine, Logger;
13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException; 13 import 'package:analyzer/src/generated/java_engine.dart' show CaughtException;
14 import 'package:args/args.dart'; 14 import 'package:args/args.dart';
15 import 'package:logging/logging.dart' show Level; 15 import 'package:logging/logging.dart' show Level;
16 import 'package:path/path.dart' as path; 16 import 'package:path/path.dart' as path;
17 import 'package:unittest/unittest.dart'; 17 import 'package:unittest/unittest.dart';
18 18
19 import 'package:dev_compiler/devc.dart'; 19 import 'package:dev_compiler/devc.dart';
20 import 'package:dev_compiler/src/options.dart'; 20 import 'package:dev_compiler/src/options.dart';
21 import 'package:dev_compiler/src/dependency_graph.dart' 21 import 'package:dev_compiler/src/dependency_graph.dart'
22 show defaultRuntimeFiles; 22 show defaultRuntimeFiles;
23 import 'package:dev_compiler/src/utils.dart'
24 show computeHash, computeHashFromFile;
25 import 'package:html/parser.dart' as html;
23 26
24 final ArgParser argParser = new ArgParser() 27 final ArgParser argParser = new ArgParser()
25 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null) 28 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null)
26 ..addFlag('dart-gen', 29 ..addFlag('dart-gen',
27 abbr: 'd', help: 'Generate dart output', defaultsTo: false); 30 abbr: 'd', help: 'Generate dart output', defaultsTo: false);
28 31
29 main(arguments) { 32 main(arguments) {
30 if (arguments == null) arguments = []; 33 if (arguments == null) arguments = [];
31 ArgResults args = argParser.parse(arguments); 34 ArgResults args = argParser.parse(arguments);
32 var script = Platform.script.path; 35 var script = Platform.script.path;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 223
221 var result = 224 var result =
222 compile(filePath, realSdk, serverMode: true, subDir: 'server_mode'); 225 compile(filePath, realSdk, serverMode: true, subDir: 'server_mode');
223 var success = !result.failure; 226 var success = !result.failure;
224 227
225 // Write compiler messages to disk. 228 // Write compiler messages to disk.
226 new File(path.join(actualDir, 'server_mode', 'html_input.txt')) 229 new File(path.join(actualDir, 'server_mode', 'html_input.txt'))
227 .writeAsStringSync(compilerMessages.toString()); 230 .writeAsStringSync(compilerMessages.toString());
228 231
229 var expectedFiles = [ 232 var expectedFiles = [
230 'html_input.html',
231 'dir/html_input_a.js', 233 'dir/html_input_a.js',
232 'dir/html_input_b.js', 234 'dir/html_input_b.js',
233 'dir/html_input_c.js', 235 'dir/html_input_c.js',
234 'dir/html_input_d.js', 236 'dir/html_input_d.js',
235 'dir/html_input_e.js', 237 'dir/html_input_e.js',
236 'dev_compiler/runtime/messages_widget.js', 238 'dev_compiler/runtime/messages_widget.js',
237 'dev_compiler/runtime/messages.css' 239 'dev_compiler/runtime/messages.css'
238 ]..addAll(expectedRuntime); 240 ]..addAll(expectedRuntime);
239 241
242 // Parse the HTML file and verify its contents were expected.
243 var htmlPath = path.join(actualDir, 'server_mode', 'html_input.html');
244 var doc = html.parse(new File(htmlPath).readAsStringSync());
245
240 for (var filepath in expectedFiles) { 246 for (var filepath in expectedFiles) {
241 var outFile = new File(path.join(actualDir, 'server_mode', filepath)); 247 var outPath = path.join(actualDir, 'server_mode', filepath);
242 expect(outFile.existsSync(), success, 248 expect(new File(outPath).existsSync(), success,
243 reason: '${outFile.path} was created iff compilation succeeds'); 249 reason: '$outPath was created iff compilation succeeds');
250
251 var query;
252 if (filepath.endsWith('js')) {
253 var hash;
254 if (filepath.startsWith('dev_compiler')) {
255 hash = computeHashFromFile(outPath);
256 } else {
257 // TODO(jmesserly): see if we can get this to return the same
258 // answer as computeHashFromFile.
259 hash = computeHash(new File(outPath).readAsStringSync());
260 }
261 query = 'script[src="cached/$hash/$filepath"]';
262 } else {
263 var hash = computeHashFromFile(outPath);
264 query = 'link[href="cached/$hash/$filepath"]';
265 }
266 expect(doc.querySelector(query), isNotNull,
267 reason: "should find `$query` in $htmlPath for $outPath");
244 } 268 }
269
270 // Clean up the server mode folder, otherwise it causes diff churn.
271 var dir = new Directory(path.join(actualDir, 'server_mode'));
272 if (dir.existsSync()) dir.deleteSync(recursive: true);
Siggi Cherem (dart-lang) 2015/04/01 21:28:20 minor nit: maybe just assert that it exists? expe
245 }); 273 });
246 } 274 }
247 } 275 }
248 276
249 /// An implementation of analysis engine's [Logger] that prints. 277 /// An implementation of analysis engine's [Logger] that prints.
250 class PrintLogger implements Logger { 278 class PrintLogger implements Logger {
251 @override void logError(String message, [CaughtException exception]) { 279 @override void logError(String message, [CaughtException exception]) {
252 print('[AnalysisEngine] error $message $exception'); 280 print('[AnalysisEngine] error $message $exception');
253 } 281 }
254 282
255 @override void logError2(String message, Object exception) { 283 @override void logError2(String message, Object exception) {
256 print('[AnalysisEngine] error $message $exception'); 284 print('[AnalysisEngine] error $message $exception');
257 } 285 }
258 286
259 void logInformation(String message, [CaughtException exception]) {} 287 void logInformation(String message, [CaughtException exception]) {}
260 void logInformation2(String message, Object exception) {} 288 void logInformation2(String message, Object exception) {}
261 } 289 }
OLDNEW
« no previous file with comments | « test/codegen/expect/server_mode/html_input.txt ('k') | tool/test.sh » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698