| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 library mock_compiler; | 5 library mock_compiler; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:compiler/compiler_new.dart' as api; | 10 import 'package:compiler/compiler_new.dart' as api; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 api.CompilerDiagnostics diagnosticHandler; | 55 api.CompilerDiagnostics diagnosticHandler; |
| 56 | 56 |
| 57 /// Expected number of warnings. If `null`, the number of warnings is | 57 /// Expected number of warnings. If `null`, the number of warnings is |
| 58 /// not checked. | 58 /// not checked. |
| 59 final int expectedWarnings; | 59 final int expectedWarnings; |
| 60 | 60 |
| 61 /// Expected number of errors. If `null`, the number of errors is not checked. | 61 /// Expected number of errors. If `null`, the number of errors is not checked. |
| 62 final int expectedErrors; | 62 final int expectedErrors; |
| 63 final Map<String, SourceFile> sourceFiles; | 63 final Map<String, SourceFile> sourceFiles; |
| 64 Node parsedTree; | 64 Node parsedTree; |
| 65 final String testedPatchVersion; | |
| 66 final LibrarySourceProvider librariesOverride; | 65 final LibrarySourceProvider librariesOverride; |
| 67 final DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); | 66 final DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); |
| 68 final ResolvedUriTranslator resolvedUriTranslator = | 67 final ResolvedUriTranslator resolvedUriTranslator = |
| 69 new MockResolvedUriTranslator(); | 68 new MockResolvedUriTranslator(); |
| 70 final Measurer measurer = new Measurer(); | 69 final Measurer measurer = new Measurer(); |
| 71 | 70 |
| 72 MockCompiler.internal( | 71 MockCompiler.internal( |
| 73 {Map<String, String> coreSource, | 72 {Map<String, String> coreSource, |
| 74 bool enableTypeAssertions: false, | 73 bool enableTypeAssertions: false, |
| 75 bool enableUserAssertions: false, | 74 bool enableUserAssertions: false, |
| 76 bool enableMinification: false, | 75 bool enableMinification: false, |
| 77 bool disableTypeInference: false, | 76 bool disableTypeInference: false, |
| 78 bool analyzeAll: false, | 77 bool analyzeAll: false, |
| 79 bool analyzeOnly: false, | 78 bool analyzeOnly: false, |
| 80 bool preserveComments: false, | 79 bool preserveComments: false, |
| 81 // Our unit tests check code generation output that is | 80 // Our unit tests check code generation output that is |
| 82 // affected by inlining support. | 81 // affected by inlining support. |
| 83 bool disableInlining: true, | 82 bool disableInlining: true, |
| 84 bool trustTypeAnnotations: false, | 83 bool trustTypeAnnotations: false, |
| 85 bool trustJSInteropTypeAnnotations: false, | 84 bool trustJSInteropTypeAnnotations: false, |
| 86 bool enableAsyncAwait: false, | 85 bool enableAsyncAwait: false, |
| 87 int this.expectedWarnings, | 86 int this.expectedWarnings, |
| 88 int this.expectedErrors, | 87 int this.expectedErrors, |
| 89 api.CompilerOutput outputProvider, | 88 api.CompilerOutput outputProvider, |
| 90 String patchVersion, | |
| 91 LibrarySourceProvider this.librariesOverride}) | 89 LibrarySourceProvider this.librariesOverride}) |
| 92 : sourceFiles = new Map<String, SourceFile>(), | 90 : sourceFiles = new Map<String, SourceFile>(), |
| 93 testedPatchVersion = patchVersion, | |
| 94 super( | 91 super( |
| 95 options: new CompilerOptions( | 92 options: new CompilerOptions( |
| 96 entryPoint: new Uri(scheme: 'mock'), | 93 entryPoint: new Uri(scheme: 'mock'), |
| 97 libraryRoot: Uri.parse('placeholder_library_root_for_mock/'), | 94 libraryRoot: Uri.parse('placeholder_library_root_for_mock/'), |
| 98 enableTypeAssertions: enableTypeAssertions, | 95 enableTypeAssertions: enableTypeAssertions, |
| 99 enableUserAssertions: enableUserAssertions, | 96 enableUserAssertions: enableUserAssertions, |
| 100 disableInlining: disableInlining, | 97 disableInlining: disableInlining, |
| 101 enableAssertMessage: true, | 98 enableAssertMessage: true, |
| 102 enableMinification: enableMinification, | 99 enableMinification: enableMinification, |
| 103 disableTypeInference: disableTypeInference, | 100 disableTypeInference: disableTypeInference, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 128 Map<String, String> asyncLibrarySource = <String, String>{}; | 125 Map<String, String> asyncLibrarySource = <String, String>{}; |
| 129 asyncLibrarySource.addAll(DEFAULT_ASYNC_LIBRARY); | 126 asyncLibrarySource.addAll(DEFAULT_ASYNC_LIBRARY); |
| 130 if (enableAsyncAwait) { | 127 if (enableAsyncAwait) { |
| 131 asyncLibrarySource.addAll(ASYNC_AWAIT_LIBRARY); | 128 asyncLibrarySource.addAll(ASYNC_AWAIT_LIBRARY); |
| 132 } | 129 } |
| 133 registerSource(Uris.dart_async, buildLibrarySource(asyncLibrarySource)); | 130 registerSource(Uris.dart_async, buildLibrarySource(asyncLibrarySource)); |
| 134 registerSource(LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP, | 131 registerSource(LookupMapResolutionAnalysis.PACKAGE_LOOKUP_MAP, |
| 135 buildLibrarySource(DEFAULT_LOOKUP_MAP_LIBRARY)); | 132 buildLibrarySource(DEFAULT_LOOKUP_MAP_LIBRARY)); |
| 136 } | 133 } |
| 137 | 134 |
| 138 String get patchVersion { | |
| 139 return testedPatchVersion != null ? testedPatchVersion : super.patchVersion; | |
| 140 } | |
| 141 | |
| 142 /// Initialize the mock compiler with an empty main library. | 135 /// Initialize the mock compiler with an empty main library. |
| 143 Future<Uri> init([String mainSource = ""]) { | 136 Future<Uri> init([String mainSource = ""]) { |
| 144 Uri uri = new Uri(scheme: "mock"); | 137 Uri uri = new Uri(scheme: "mock"); |
| 145 registerSource(uri, mainSource); | 138 registerSource(uri, mainSource); |
| 146 return libraryLoader | 139 return libraryLoader |
| 147 .loadLibrary(uri) | 140 .loadLibrary(uri) |
| 148 .then((LoadedLibraries loadedLibraries) { | 141 .then((LoadedLibraries loadedLibraries) { |
| 149 processLoadedLibraries(loadedLibraries); | 142 processLoadedLibraries(loadedLibraries); |
| 150 mainApp = loadedLibraries.rootLibrary; | 143 mainApp = loadedLibraries.rootLibrary; |
| 151 startResolution(); | 144 startResolution(); |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 trustTypeAnnotations: trustTypeAnnotations, | 390 trustTypeAnnotations: trustTypeAnnotations, |
| 398 enableTypeAssertions: enableTypeAssertions, | 391 enableTypeAssertions: enableTypeAssertions, |
| 399 enableUserAssertions: enableUserAssertions, | 392 enableUserAssertions: enableUserAssertions, |
| 400 expectedErrors: expectedErrors, | 393 expectedErrors: expectedErrors, |
| 401 expectedWarnings: expectedWarnings, | 394 expectedWarnings: expectedWarnings, |
| 402 outputProvider: outputProvider); | 395 outputProvider: outputProvider); |
| 403 compiler.registerSource(uri, code); | 396 compiler.registerSource(uri, code); |
| 404 compiler.diagnosticHandler = createHandler(compiler, code); | 397 compiler.diagnosticHandler = createHandler(compiler, code); |
| 405 return compiler; | 398 return compiler; |
| 406 } | 399 } |
| OLD | NEW |