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

Side by Side Diff: test/codegen_test.dart

Issue 1243503007: fixes #221, initial sync*, async, async* implementation (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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 | « test/codegen/unittest.dart ('k') | test/js_test_tools/chai/.bower.json » ('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';
(...skipping 29 matching lines...) Expand all
40 40
41 tearDown(() { 41 tearDown(() {
42 if (loggerSub != null) { 42 if (loggerSub != null) {
43 loggerSub.cancel(); 43 loggerSub.cancel();
44 loggerSub = null; 44 loggerSub = null;
45 } 45 }
46 }); 46 });
47 47
48 var inputDir = path.join(testDirectory, 'codegen'); 48 var inputDir = path.join(testDirectory, 'codegen');
49 var expectDir = path.join(inputDir, 'expect'); 49 var expectDir = path.join(inputDir, 'expect');
50 var paths = new Directory(inputDir)
51 .listSync()
52 .where((f) => f is File)
53 .map((f) => f.path)
54 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p));
55 50
56 bool compile(String entryPoint, AnalysisContext context, 51 bool compile(String entryPoint, AnalysisContext context,
57 {bool checkSdk: false, bool sourceMaps: false, String subDir}) { 52 {bool checkSdk: false, bool sourceMaps: false}) {
58 // TODO(jmesserly): add a way to specify flags in the test file, so 53 // TODO(jmesserly): add a way to specify flags in the test file, so
59 // they're more self-contained. 54 // they're more self-contained.
60 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); 55 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime');
61 var options = new CompilerOptions( 56 var options = new CompilerOptions(
62 codegenOptions: new CodegenOptions( 57 codegenOptions: new CodegenOptions(
63 outputDir: subDir == null 58 outputDir: expectDir,
64 ? expectDir
65 : path.join(expectDir, subDir),
66 emitSourceMaps: sourceMaps, 59 emitSourceMaps: sourceMaps,
67 forceCompile: checkSdk), 60 forceCompile: checkSdk),
68 useColors: false, 61 useColors: false,
69 checkSdk: checkSdk, 62 checkSdk: checkSdk,
70 runtimeDir: runtimeDir, 63 runtimeDir: runtimeDir,
71 inputs: [entryPoint]); 64 inputs: [entryPoint],
65 inputBaseDir: inputDir);
72 var reporter = createErrorReporter(context, options); 66 var reporter = createErrorReporter(context, options);
73 return new BatchCompiler(context, options, reporter: reporter).run(); 67 return new BatchCompiler(context, options, reporter: reporter).run();
74 } 68 }
75 69
76 // Remove old output, and `packages` symlinks which mess up the diff. 70 // Remove old output, and `packages` symlinks which mess up the diff.
77 var dir = new Directory(expectDir); 71 var dir = new Directory(expectDir);
78 if (dir.existsSync()) dir.deleteSync(recursive: true); 72 if (dir.existsSync()) dir.deleteSync(recursive: true);
79 var packagesDirs = new Directory(inputDir) 73 var packagesDirs = new Directory(inputDir)
80 .listSync(recursive: true) 74 .listSync(recursive: true)
81 .where((d) => d is Directory && path.basename(d.path) == 'packages'); 75 .where((d) => d is Directory && path.basename(d.path) == 'packages');
82 packagesDirs.forEach((d) => d.deleteSync()); 76 packagesDirs.forEach((d) => d.deleteSync());
83 77
84 for (var filePath in paths) { 78 for (var dir in [null, 'language']) {
85 var filename = path.basenameWithoutExtension(filePath); 79 group('dartdevc ' + path.join('test', 'codegen', dir), () {
80 var testFiles = new Directory(path.join(inputDir, dir))
81 .listSync()
82 .where((f) => f is File)
83 .map((f) => f.path)
84 .where((p) => p.endsWith('.dart') && filePattern.hasMatch(p));
86 85
87 test('devc $filename.dart', () { 86 for (var filePath in testFiles) {
88 compilerMessages.writeln('// Messages from compiling $filename.dart'); 87 var filename = path.basenameWithoutExtension(filePath);
89 88
90 // TODO(jmesserly): this was added to get some coverage of source maps 89 test('$filename.dart', () {
91 // We need a more comprehensive strategy to test them. 90 compilerMessages.writeln('// Messages from compiling $filename.dart');
92 var sourceMaps = filename == 'map_keys';
93 var success = compile(filePath, realSdkContext, sourceMaps: sourceMaps);
94 91
95 // Write compiler messages to disk. 92 // TODO(jmesserly): this was added to get some coverage of source maps
96 new File(path.join(expectDir, '$filename.txt')) 93 // We need a more comprehensive strategy to test them.
97 .writeAsStringSync(compilerMessages.toString()); 94 var sourceMaps = filename == 'map_keys';
95 var success =
96 compile(filePath, realSdkContext, sourceMaps: sourceMaps);
98 97
99 var outFile = new File(path.join(expectDir, '$filename.js')); 98 // Write compiler messages to disk.
100 expect(outFile.existsSync(), success, 99 var outDir = path.join(expectDir, dir);
101 reason: '${outFile.path} was created iff compilation succeeds'); 100 new File(path.join(outDir, '$filename.txt'))
101 .writeAsStringSync(compilerMessages.toString());
102 102
103 // TODO(jmesserly): ideally we'd diff the output here. For now it 103 var outFile = new File(path.join(outDir, '$filename.js'));
104 // happens in the containing shell script. 104 expect(outFile.existsSync(), success,
105 reason: '${outFile.path} was created iff compilation succeeds');
106
107 // TODO(jmesserly): ideally we'd diff the output here. For now it
108 // happens in the containing shell script.
109 });
110 }
105 }); 111 });
106 } 112 }
107 113
108 if (Platform.environment.containsKey('COVERALLS_TOKEN')) { 114 if (Platform.environment.containsKey('COVERALLS_TOKEN')) {
109 group('sdk', () { 115 group('sdk', () {
110 // The analyzer does not bubble exception messages for certain internal 116 // The analyzer does not bubble exception messages for certain internal
111 // dart:* library failures, such as failing to find 117 // dart:* library failures, such as failing to find
112 // "_internal/libraries.dart". Instead it produces an opaque "failed to 118 // "_internal/libraries.dart". Instead it produces an opaque "failed to
113 // instantiate dart:core" message. To remedy this we hook up an analysis 119 // instantiate dart:core" message. To remedy this we hook up an analysis
114 // logger that prints these messages. 120 // logger that prints these messages.
(...skipping 22 matching lines...) Expand all
137 }); 143 });
138 } 144 }
139 145
140 var expectedRuntime = 146 var expectedRuntime =
141 defaultRuntimeFiles.map((f) => 'dev_compiler/runtime/$f'); 147 defaultRuntimeFiles.map((f) => 'dev_compiler/runtime/$f');
142 148
143 test('devc jscodegen sunflower.html', () { 149 test('devc jscodegen sunflower.html', () {
144 var filePath = path.join(inputDir, 'sunflower', 'sunflower.html'); 150 var filePath = path.join(inputDir, 'sunflower', 'sunflower.html');
145 compilerMessages.writeln('// Messages from compiling sunflower.html'); 151 compilerMessages.writeln('// Messages from compiling sunflower.html');
146 152
147 var success = compile(filePath, realSdkContext, subDir: 'sunflower'); 153 var success = compile(filePath, realSdkContext);
148 154
149 // Write compiler messages to disk. 155 // Write compiler messages to disk.
150 new File(path.join(expectDir, 'sunflower', 'sunflower.txt')) 156 new File(path.join(expectDir, 'sunflower', 'sunflower.txt'))
151 .writeAsStringSync(compilerMessages.toString()); 157 .writeAsStringSync(compilerMessages.toString());
152 158
153 var expectedFiles = [ 159 var expectedFiles = ['sunflower.html', 'sunflower.js',];
154 'sunflower.html',
155 'sunflower.js',
156 ]..addAll(expectedRuntime);
157 160
158 for (var filepath in expectedFiles) { 161 for (var filepath in expectedFiles) {
159 var outFile = new File(path.join(expectDir, 'sunflower', filepath)); 162 var outFile = new File(path.join(expectDir, 'sunflower', filepath));
160 expect(outFile.existsSync(), success, 163 expect(outFile.existsSync(), success,
161 reason: '${outFile.path} was created iff compilation succeeds'); 164 reason: '${outFile.path} was created iff compilation succeeds');
162 } 165 }
163 }); 166 });
164 167
165 test('devc jscodegen html_input.html', () { 168 test('devc jscodegen html_input.html', () {
166 var filePath = path.join(inputDir, 'html_input.html'); 169 var filePath = path.join(inputDir, 'html_input.html');
(...skipping 28 matching lines...) Expand all
195 print('[AnalysisEngine] error $message $exception'); 198 print('[AnalysisEngine] error $message $exception');
196 } 199 }
197 200
198 @override void logError2(String message, Object exception) { 201 @override void logError2(String message, Object exception) {
199 print('[AnalysisEngine] error $message $exception'); 202 print('[AnalysisEngine] error $message $exception');
200 } 203 }
201 204
202 void logInformation(String message, [CaughtException exception]) {} 205 void logInformation(String message, [CaughtException exception]) {}
203 void logInformation2(String message, Object exception) {} 206 void logInformation2(String message, Object exception) {}
204 } 207 }
OLDNEW
« no previous file with comments | « test/codegen/unittest.dart ('k') | test/js_test_tools/chai/.bower.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698