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

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

Issue 1320913002: dart2js: Add test to compile empty main without any libraries. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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 | « tests/compiler/dart2js/dart2js.status ('k') | no next file » | 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) 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 4
5 library mock_compiler; 5 library mock_compiler;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 class WarningMessage { 43 class WarningMessage {
44 Spannable node; 44 Spannable node;
45 Message message; 45 Message message;
46 WarningMessage(this.node, this.message); 46 WarningMessage(this.node, this.message);
47 47
48 toString() => message.kind.toString(); 48 toString() => message.kind.toString();
49 } 49 }
50 50
51 final Uri PATCH_CORE = new Uri(scheme: 'patch', path: 'core'); 51 final Uri PATCH_CORE = new Uri(scheme: 'patch', path: 'core');
52 52
53 typedef String LibrarySourceProvider(Uri uri);
54
53 class MockCompiler extends Compiler { 55 class MockCompiler extends Compiler {
54 api.DiagnosticHandler diagnosticHandler; 56 api.DiagnosticHandler diagnosticHandler;
55 List<WarningMessage> warnings; 57 List<WarningMessage> warnings;
56 List<WarningMessage> errors; 58 List<WarningMessage> errors;
57 List<WarningMessage> hints; 59 List<WarningMessage> hints;
58 List<WarningMessage> infos; 60 List<WarningMessage> infos;
59 List<WarningMessage> crashes; 61 List<WarningMessage> crashes;
60 /// Expected number of warnings. If `null`, the number of warnings is 62 /// Expected number of warnings. If `null`, the number of warnings is
61 /// not checked. 63 /// not checked.
62 final int expectedWarnings; 64 final int expectedWarnings;
63 /// Expected number of errors. If `null`, the number of errors is not checked. 65 /// Expected number of errors. If `null`, the number of errors is not checked.
64 final int expectedErrors; 66 final int expectedErrors;
65 final Map<String, SourceFile> sourceFiles; 67 final Map<String, SourceFile> sourceFiles;
66 Node parsedTree; 68 Node parsedTree;
67 final String testedPatchVersion; 69 final String testedPatchVersion;
70 final LibrarySourceProvider librariesOverride;
68 71
69 MockCompiler.internal( 72 MockCompiler.internal(
70 {Map<String, String> coreSource, 73 {Map<String, String> coreSource,
71 bool enableTypeAssertions: false, 74 bool enableTypeAssertions: false,
72 bool enableMinification: false, 75 bool enableMinification: false,
73 bool enableConcreteTypeInference: false, 76 bool enableConcreteTypeInference: false,
74 int maxConcreteTypeSize: 5, 77 int maxConcreteTypeSize: 5,
75 bool disableTypeInference: false, 78 bool disableTypeInference: false,
76 bool analyzeAll: false, 79 bool analyzeAll: false,
77 bool analyzeOnly: false, 80 bool analyzeOnly: false,
78 bool emitJavaScript: true, 81 bool emitJavaScript: true,
79 bool preserveComments: false, 82 bool preserveComments: false,
80 // Our unit tests check code generation output that is 83 // Our unit tests check code generation output that is
81 // affected by inlining support. 84 // affected by inlining support.
82 bool disableInlining: true, 85 bool disableInlining: true,
83 bool trustTypeAnnotations: false, 86 bool trustTypeAnnotations: false,
84 bool enableAsyncAwait: false, 87 bool enableAsyncAwait: false,
85 int this.expectedWarnings, 88 int this.expectedWarnings,
86 int this.expectedErrors, 89 int this.expectedErrors,
87 api.CompilerOutputProvider outputProvider, 90 api.CompilerOutputProvider outputProvider,
88 String patchVersion}) 91 String patchVersion,
92 LibrarySourceProvider this.librariesOverride})
89 : sourceFiles = new Map<String, SourceFile>(), 93 : sourceFiles = new Map<String, SourceFile>(),
90 testedPatchVersion = patchVersion, 94 testedPatchVersion = patchVersion,
91 super(enableTypeAssertions: enableTypeAssertions, 95 super(enableTypeAssertions: enableTypeAssertions,
92 enableMinification: enableMinification, 96 enableMinification: enableMinification,
93 enableConcreteTypeInference: enableConcreteTypeInference, 97 enableConcreteTypeInference: enableConcreteTypeInference,
94 maxConcreteTypeSize: maxConcreteTypeSize, 98 maxConcreteTypeSize: maxConcreteTypeSize,
95 disableTypeInferenceFlag: disableTypeInference, 99 disableTypeInferenceFlag: disableTypeInference,
96 analyzeAllFlag: analyzeAll, 100 analyzeAllFlag: analyzeAll,
97 analyzeOnly: analyzeOnly, 101 analyzeOnly: analyzeOnly,
98 emitJavaScript: emitJavaScript, 102 emitJavaScript: emitJavaScript,
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 expectedWarnings != warnings.length) { 164 expectedWarnings != warnings.length) {
161 throw "unexpected warnings during compilation ${warnings}"; 165 throw "unexpected warnings during compilation ${warnings}";
162 } else { 166 } else {
163 return result; 167 return result;
164 } 168 }
165 }); 169 });
166 } 170 }
167 171
168 /** 172 /**
169 * Registers the [source] with [uri] making it possible load [source] as a 173 * Registers the [source] with [uri] making it possible load [source] as a
170 * library. 174 * library. If an override has been provided in [librariesOverride], that
175 * is used instead.
171 */ 176 */
172 void registerSource(Uri uri, String source) { 177 void registerSource(Uri uri, String source) {
178 if (librariesOverride != null) {
179 String override = librariesOverride(uri);
180 if (override != null) {
181 source = override;
182 }
183 }
173 sourceFiles[uri.toString()] = new MockFile(source); 184 sourceFiles[uri.toString()] = new MockFile(source);
174 } 185 }
175 186
176 // TODO(johnniwinther): Remove this when we don't filter certain type checker 187 // TODO(johnniwinther): Remove this when we don't filter certain type checker
177 // warnings. 188 // warnings.
178 void reportWarning(Spannable node, MessageKind messageKind, 189 void reportWarning(Spannable node, MessageKind messageKind,
179 [Map arguments = const {}]) { 190 [Map arguments = const {}]) {
180 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind]; 191 MessageTemplate template = MessageTemplate.TEMPLATES[messageKind];
181 reportDiagnostic(node, 192 reportDiagnostic(node,
182 template.message(arguments, terseDiagnostics), 193 template.message(arguments, terseDiagnostics),
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 MockElement(Element enclosingElement) 424 MockElement(Element enclosingElement)
414 : super('', ElementKind.FUNCTION, Modifiers.EMPTY, 425 : super('', ElementKind.FUNCTION, Modifiers.EMPTY,
415 enclosingElement); 426 enclosingElement);
416 427
417 get node => null; 428 get node => null;
418 429
419 parseNode(_) => null; 430 parseNode(_) => null;
420 431
421 bool get hasNode => false; 432 bool get hasNode => false;
422 } 433 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/dart2js.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698