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

Side by Side Diff: test/codegen_test.dart

Issue 1840203002: More analyzer updates, and handle negative_tests (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 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
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:analyzer/src/generated/engine.dart' 11 import 'package:analyzer/src/generated/engine.dart'
12 show AnalysisContext, AnalysisEngine, Logger; 12 show AnalysisContext, 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:analyzer/src/generated/source_io.dart';
14 import 'package:args/args.dart'; 15 import 'package:args/args.dart';
16 import 'package:cli_util/cli_util.dart' show getSdkDir;
15 import 'package:logging/logging.dart' show Level; 17 import 'package:logging/logging.dart' show Level;
16 import 'package:path/path.dart' as path; 18 import 'package:path/path.dart' as path;
17 import 'package:test/test.dart'; 19 import 'package:test/test.dart';
18 20
19 import 'package:dev_compiler/devc.dart'; 21 import 'package:dev_compiler/devc.dart';
22 import 'package:dev_compiler/src/analysis_context.dart';
20 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles; 23 import 'package:dev_compiler/src/compiler.dart' show defaultRuntimeFiles;
21 import 'package:dev_compiler/src/options.dart'; 24 import 'package:dev_compiler/src/options.dart';
22 import 'package:dev_compiler/src/report.dart' show LogReporter; 25 import 'package:dev_compiler/src/report.dart' show LogReporter;
23 26
24 import 'testing.dart' show realSdkContext, testDirectory; 27 import 'testing.dart' show testDirectory;
25 import 'multitest.dart'; 28 import 'multitest.dart';
26 29
27 final ArgParser argParser = new ArgParser() 30 final ArgParser argParser = new ArgParser()
28 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null); 31 ..addOption('dart-sdk', help: 'Dart SDK Path', defaultsTo: null);
29 32
30 final inputDir = path.join(testDirectory, 'codegen'); 33 final inputDir = path.join(testDirectory, 'codegen');
31 34
32 Iterable<String> _findTests(String dir, RegExp filePattern) { 35 Iterable<String> _findTests(String dir, RegExp filePattern) {
33 var files = new Directory(dir) 36 var files = new Directory(dir)
34 .listSync() 37 .listSync()
(...skipping 23 matching lines...) Expand all
58 61
59 tearDown(() { 62 tearDown(() {
60 if (loggerSub != null) { 63 if (loggerSub != null) {
61 loggerSub.cancel(); 64 loggerSub.cancel();
62 loggerSub = null; 65 loggerSub = null;
63 } 66 }
64 }); 67 });
65 68
66 var expectDir = path.join(inputDir, 'expect'); 69 var expectDir = path.join(inputDir, 'expect');
67 70
68 BatchCompiler createCompiler(AnalysisContext context, 71 BatchCompiler createCompiler(DartUriResolver sdkResolver, {bool checkSdk: fals e,
69 {bool checkSdk: false,
70 bool sourceMaps: false, 72 bool sourceMaps: false,
71 bool destructureNamedParams: false, 73 bool destructureNamedParams: false,
72 bool closure: false, 74 bool closure: false,
73 ModuleFormat moduleFormat: ModuleFormat.legacy}) { 75 ModuleFormat moduleFormat: ModuleFormat.legacy}) {
76
77 String _testCodegenPath(String p1, [String p2]) =>
78 path.join(testDirectory, 'codegen', p1, p2);
79
80 var context = createAnalysisContextWithSources(new SourceResolverOptions(
81 customUrlMappings: {
82 'package:expect/expect.dart': _testCodegenPath('expect.dart'),
83 'package:async_helper/async_helper.dart':
84 _testCodegenPath('async_helper.dart'),
85 'package:unittest/unittest.dart': _testCodegenPath('unittest.dart'),
86 'package:dom/dom.dart': _testCodegenPath('sunflower', 'dom.dart')
87 }), sdkResolver: sdkResolver);
88
74 // TODO(jmesserly): add a way to specify flags in the test file, so 89 // TODO(jmesserly): add a way to specify flags in the test file, so
75 // they're more self-contained. 90 // they're more self-contained.
76 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime'); 91 var runtimeDir = path.join(path.dirname(testDirectory), 'lib', 'runtime');
77 var options = new CompilerOptions( 92 var options = new CompilerOptions(
78 codegenOptions: new CodegenOptions( 93 codegenOptions: new CodegenOptions(
79 outputDir: expectDir, 94 outputDir: expectDir,
80 emitSourceMaps: sourceMaps, 95 emitSourceMaps: sourceMaps,
81 closure: closure, 96 closure: closure,
82 destructureNamedParams: destructureNamedParams, 97 destructureNamedParams: destructureNamedParams,
83 forceCompile: checkSdk, 98 forceCompile: checkSdk,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 var filename = path.basenameWithoutExtension(filePath); 145 var filename = path.basenameWithoutExtension(filePath);
131 tests.forEach((name, contents) { 146 tests.forEach((name, contents) {
132 new File(path.join(fullDir, '${filename}_${name}_multi.dart')) 147 new File(path.join(fullDir, '${filename}_${name}_multi.dart'))
133 .writeAsStringSync(contents); 148 .writeAsStringSync(contents);
134 }); 149 });
135 } 150 }
136 } 151 }
137 } 152 }
138 } 153 }
139 154
140 var batchCompiler = createCompiler(realSdkContext); 155 var realSdkResolver = createSdkPathResolver(getSdkDir().path);
156 var batchCompiler = createCompiler(realSdkResolver);
141 157
142 var allDirs = [null]; 158 var allDirs = [null];
143 allDirs.addAll(testDirs); 159 allDirs.addAll(testDirs);
144 for (var dir in allDirs) { 160 for (var dir in allDirs) {
145 if (codeCoverage && dir != null) continue; 161 if (codeCoverage && dir != null) continue;
146 162
147 group('dartdevc ' + path.join('test', 'codegen', dir), () { 163 group('dartdevc ' + path.join('test', 'codegen', dir), () {
148 var outDir = new Directory(path.join(expectDir, dir)); 164 var outDir = new Directory(path.join(expectDir, dir));
149 if (!outDir.existsSync()) outDir.createSync(recursive: true); 165 if (!outDir.existsSync()) outDir.createSync(recursive: true);
150 166
(...skipping 16 matching lines...) Expand all
167 ? ModuleFormat.node 183 ? ModuleFormat.node
168 : ModuleFormat.legacy; 184 : ModuleFormat.legacy;
169 var success; 185 var success;
170 // TODO(vsm): Is it okay to reuse the same context here? If there is 186 // TODO(vsm): Is it okay to reuse the same context here? If there is
171 // overlap between test files, we may need separate ones for each 187 // overlap between test files, we may need separate ones for each
172 // compiler. 188 // compiler.
173 var compiler = (sourceMaps || 189 var compiler = (sourceMaps ||
174 closure || 190 closure ||
175 destructureNamedParams || 191 destructureNamedParams ||
176 moduleFormat != ModuleFormat.legacy) 192 moduleFormat != ModuleFormat.legacy)
177 ? createCompiler(realSdkContext, 193 ? createCompiler(realSdkResolver,
178 sourceMaps: sourceMaps, 194 sourceMaps: sourceMaps,
179 destructureNamedParams: destructureNamedParams, 195 destructureNamedParams: destructureNamedParams,
180 closure: closure, 196 closure: closure,
181 moduleFormat: moduleFormat) 197 moduleFormat: moduleFormat)
182 : batchCompiler; 198 : batchCompiler;
183 success = compile(compiler, filePath); 199 success = compile(compiler, filePath);
184 200
185 var outFile = new File(path.join(outDir.path, '$filename.js')); 201 var outFile = new File(path.join(outDir.path, '$filename.js'));
186 expect(!success || outFile.existsSync(), true, 202 expect(!success || outFile.existsSync(), true,
187 reason: '${outFile.path} was created if compilation succeeds'); 203 reason: '${outFile.path} was created if compilation succeeds');
(...skipping 12 matching lines...) Expand all
200 var savedLogger; 216 var savedLogger;
201 setUp(() { 217 setUp(() {
202 savedLogger = AnalysisEngine.instance.logger; 218 savedLogger = AnalysisEngine.instance.logger;
203 AnalysisEngine.instance.logger = new PrintLogger(); 219 AnalysisEngine.instance.logger = new PrintLogger();
204 }); 220 });
205 tearDown(() { 221 tearDown(() {
206 AnalysisEngine.instance.logger = savedLogger; 222 AnalysisEngine.instance.logger = savedLogger;
207 }); 223 });
208 224
209 test('devc dart:core', () { 225 test('devc dart:core', () {
210 var testSdkContext = createAnalysisContextWithSources( 226 var testSdkResolver = createSdkPathResolver(path.join(
211 new SourceResolverOptions(dartSdkPath: path.join( 227 testDirectory, '..', 'tool', 'generated_sdk'));
212 testDirectory, '..', 'tool', 'generated_sdk')));
213 228
214 // Get the test SDK. We use a checked in copy so test expectations can 229 // Get the test SDK. We use a checked in copy so test expectations can
215 // be generated against a specific SDK version. 230 // be generated against a specific SDK version.
216 var compiler = createCompiler(testSdkContext, checkSdk: true); 231 var compiler = createCompiler(testSdkResolver, checkSdk: true);
217 compile(compiler, 'dart:core'); 232 compile(compiler, 'dart:core');
218 var outFile = new File(path.join(expectDir, 'dart/core.js')); 233 var outFile = new File(path.join(expectDir, 'dart/core.js'));
219 expect(outFile.existsSync(), true, 234 expect(outFile.existsSync(), true,
220 reason: '${outFile.path} was created for dart:core'); 235 reason: '${outFile.path} was created for dart:core');
221 }); 236 });
222 }); 237 });
223 } 238 }
224 239
225 var expectedRuntime = 240 var expectedRuntime =
226 defaultRuntimeFiles.map((f) => 'dev_compiler/runtime/$f'); 241 defaultRuntimeFiles.map((f) => 'dev_compiler/runtime/$f');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 /// An implementation of analysis engine's [Logger] that prints. 277 /// An implementation of analysis engine's [Logger] that prints.
263 class PrintLogger implements Logger { 278 class PrintLogger implements Logger {
264 @override 279 @override
265 void logError(String message, [CaughtException exception]) { 280 void logError(String message, [CaughtException exception]) {
266 print('[AnalysisEngine] error $message $exception'); 281 print('[AnalysisEngine] error $message $exception');
267 } 282 }
268 283
269 void logInformation(String message, [CaughtException exception]) {} 284 void logInformation(String message, [CaughtException exception]) {}
270 void logInformation2(String message, Object exception) {} 285 void logInformation2(String message, Object exception) {}
271 } 286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698