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

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

Issue 469903002: Added a test for dump-info with lots of closures. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rename variables to make the test easier to read Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 // Test that parameters keep their names in the output. 4 // Test that parameters keep their names in the output.
5 5
6 import "package:expect/expect.dart"; 6 import "package:expect/expect.dart";
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'memory_compiler.dart'; 8 import 'memory_compiler.dart';
9 import 'package:compiler/implementation/dump_info.dart'; 9 import 'package:compiler/implementation/dump_info.dart';
10 import 'dart:convert'; 10 import 'dart:convert';
(...skipping 24 matching lines...) Expand all
35 a = 3; 35 a = 3;
36 } 36 }
37 37
38 main() { 38 main() {
39 print(a); 39 print(a);
40 f(); 40 f();
41 print(new c(2).foo()); 41 print(new c(2).foo());
42 } 42 }
43 """; 43 """;
44 44
45 const String TEST_TWO = r"""
45 main() { 46 main() {
46 var compiler = compilerFor({'main.dart': TEST_ONE}, options: ["--dump-info"]); 47 print(bar);
47 asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) { 48 print(bar());
48 var dumpTask = compiler.dumpInfoTask; 49 print(new X().foo);
49 dumpTask.collectInfo(); 50 print(new X().foo());
50 var info = dumpTask.infoCollector; 51 }
51 52
52 StringBuffer sb = new StringBuffer(); 53 bar() => [() => [() => [() => [() => [() => [() => [() => [() => [() => [() =>
53 dumpTask.dumpInfoJson(sb); 54 [() => []]]]]]]]]]]];
54 String json = sb.toString(); 55
55 Map<String, dynamic> map = JSON.decode(json); 56 class X {
56 Expect.isTrue(map.isNotEmpty); 57 foo() => [() => [() => [() => [() => [() => [() => [() => [() => [() =>
58 [() => []]]]]]]]]]];
59 }
60 """;
61
62 typedef void JsonTaking(Map<String, dynamic> json);
sra1 2014/08/13 21:45:26 I'd put a line between top level declarations unle
Ty Overby (Google) 2014/08/13 22:00:31 Done.
63 void jsonTest(String program, JsonTaking testFn) {
64 var compiler = compilerFor({'main.dart': program}, options: ['--dump-info']);
65 asyncTest(() => compiler.runCompiler(Uri.parse('memory:main.dart')).then(
66 (_) {
67 var dumpTask = compiler.dumpInfoTask;
68 dumpTask.collectInfo();
69 var info = dumpTask.infoCollector;
70
71 StringBuffer sb = new StringBuffer();
72 dumpTask.dumpInfoJson(sb);
73 String json = sb.toString();
74 Map<String, dynamic> map = JSON.decode(json);
75
76 testFn(map);
77 }));
78 }
79
80 main() {
81 jsonTest(TEST_ONE, (map) {
57 Expect.isTrue(map['elements'].isNotEmpty); 82 Expect.isTrue(map['elements'].isNotEmpty);
58 Expect.isTrue(map['elements']['function'].isNotEmpty); 83 Expect.isTrue(map['elements']['function'].isNotEmpty);
59 Expect.isTrue(map['elements']['library'].isNotEmpty); 84 Expect.isTrue(map['elements']['library'].isNotEmpty);
60 85
61 Expect.isTrue(map['elements']['library'].values.any((lib) { 86 Expect.isTrue(map['elements']['library'].values.any((lib) {
62 return lib['name'] == "main"; 87 return lib['name'] == "main";
63 })); 88 }));
64 Expect.isTrue(map['elements']['class'].values.any((clazz) { 89 Expect.isTrue(map['elements']['class'].values.any((clazz) {
65 return clazz['name'] == "c"; 90 return clazz['name'] == "c";
66 })); 91 }));
67 Expect.isTrue(map['elements']['function'].values.any((fun) { 92 Expect.isTrue(map['elements']['function'].values.any((fun) {
68 return fun['name'] == 'f'; 93 return fun['name'] == 'f';
69 })); 94 }));
70 })); 95 });
96
97 jsonTest(TEST_TWO, (map) {
98 var functions = map['elements']['function'].values;
99 Expect.isTrue(functions.any((fn) {
100 return fn['name'] == 'bar' && fn['children'].length == 11;
101 }));
102 Expect.isTrue(functions.any((fn) {
103 return fn['name'] == 'foo' && fn['children'].length == 10;
104 }));
105 });
71 } 106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698