Chromium Code Reviews| Index: tests/compiler/dart2js/compiler_helper.dart |
| diff --git a/tests/compiler/dart2js/compiler_helper.dart b/tests/compiler/dart2js/compiler_helper.dart |
| index 9c84a8c23b0b0debd5ec22e810aa0722de5d6f3c..2742b92309716561c44a3d5722d87ea78f90f49b 100644 |
| --- a/tests/compiler/dart2js/compiler_helper.dart |
| +++ b/tests/compiler/dart2js/compiler_helper.dart |
| @@ -16,6 +16,7 @@ export 'package:compiler/src/elements/elements.dart'; |
| import 'package:compiler/src/js_backend/js_backend.dart' |
| as js; |
| +import 'package:compiler/src/commandline_options.dart'; |
| import 'package:compiler/src/common/codegen.dart'; |
| import 'package:compiler/src/common/resolution.dart'; |
| @@ -39,6 +40,8 @@ export 'package:compiler/src/tree/tree.dart'; |
| import 'mock_compiler.dart'; |
| export 'mock_compiler.dart'; |
| +import 'memory_compiler.dart'; |
| + |
| import 'output_collector.dart'; |
| export 'output_collector.dart'; |
| @@ -48,15 +51,19 @@ Future<String> compile(String code, |
| bool minify: false, |
| bool analyzeAll: false, |
| bool disableInlining: true, |
| - void check(String generated)}) { |
| - MockCompiler compiler = new MockCompiler.internal( |
| - enableTypeAssertions: enableTypeAssertions, |
| - // Type inference does not run when manually |
| - // compiling a method. |
| - disableTypeInference: true, |
| - enableMinification: minify, |
| - disableInlining: disableInlining); |
| - return compiler.init().then((_) { |
| + bool useMock: false, |
| + void check(String generated)}) async { |
|
sigurdm
2015/09/10 06:37:51
This parameter could use an explanation.
Johnni Winther
2015/09/11 10:42:06
Done.
|
| + if (useMock) { |
| + // TODO(johnniwinther): Remove this when no longer needed by |
| + // `arithmetic_simplication_test.dart`. |
| + MockCompiler compiler = new MockCompiler.internal( |
| + enableTypeAssertions: enableTypeAssertions, |
| + // Type inference does not run when manually |
| + // compiling a method. |
| + disableTypeInference: true, |
| + enableMinification: minify, |
| + disableInlining: disableInlining); |
| + await compiler.init(); |
| compiler.parseScript(code); |
| lego.Element element = compiler.mainApp.find(entry); |
| if (element == null) return null; |
| @@ -80,7 +87,44 @@ Future<String> compile(String code, |
| check(generated); |
| } |
| return generated; |
| - }); |
| + } else { |
| + List<String> options = <String>[ |
| + Flags.disableTypeInference]; |
| + if (enableTypeAssertions) { |
| + options.add(Flags.enableCheckedMode); |
| + } |
| + if (minify) { |
| + options.add(Flags.minify); |
| + } |
| + if (analyzeAll) { |
| + options.add(Flags.analyzeAll); |
| + } |
| + |
| + Map<String, String> source; |
| + if (entry != 'main') { |
| + source = {'main.dart': "$code\n\nmain() => $entry;" }; |
| + } else { |
| + source = {'main.dart': code}; |
| + } |
| + |
| + CompilationResult result = await runCompiler( |
| + memorySourceFiles: source, |
| + options: options, |
| + beforeRun: (compiler) { |
| + if (disableInlining) { |
| + compiler.disableInlining = true; |
| + } |
| + }); |
| + Expect.isTrue(result.isSuccess); |
| + Compiler compiler = result.compiler; |
| + lego.Element element = compiler.mainApp.find(entry); |
| + js.JavaScriptBackend backend = compiler.backend; |
|
sigurdm
2015/09/10 06:37:51
Code from here could be moved out of the if.
Johnni Winther
2015/09/11 10:42:06
They use different compilers and the true branch i
|
| + String generated = backend.assembleCode(element); |
| + if (check != null) { |
| + check(generated); |
| + } |
| + return generated; |
| + } |
| } |
| // TODO(herhut): Disallow warnings and errors during compilation by default. |
| @@ -225,8 +269,11 @@ void checkNumberOfMatches(Iterator it, int nb) { |
| Expect.isFalse(hasNext, "Found more than $nb matches"); |
| } |
| -Future compileAndMatch(String code, String entry, RegExp regexp) { |
| - return compile(code, entry: entry, check: (String generated) { |
| +Future compileAndMatch(String code, String entry, RegExp regexp, |
| + {bool useMock: false}) { |
| + return compile(code, entry: entry, |
| + useMock: useMock, |
| + check: (String generated) { |
| Expect.isTrue(regexp.hasMatch(generated), |
| '"$generated" does not match /$regexp/'); |
| }); |