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

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

Issue 1167353003: Opt-in to generate code for compile-time error. Only supported for SSA. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test that the compiler can generates code with compile time error according
6 // to the compiler options.
7
8 library dart2js.test.import;
9
10 import 'package:expect/expect.dart';
11 import 'package:async_helper/async_helper.dart';
12 import 'package:compiler/src/dart2jslib.dart';
13 import 'package:compiler/src/dart_backend/dart_backend.dart';
14 import 'package:compiler/src/js_backend/js_backend.dart';
15 import 'memory_compiler.dart';
16 import 'output_collector.dart';
17
18 const MEMORY_SOURCE_FILES = const {
19 'main.dart': '''
20 foo() {
21 const list = [];
22 }
23
24 main() {
25 foo();
26 }
27 ''',
28 };
29
30 test(List<String> options,
31 {bool expectedOutput,
32 bool expectedCodeGenerated,
33 bool expectHint: false}) async {
34 DiagnosticCollector collector = new DiagnosticCollector();
35 OutputCollector outputCollector = new OutputCollector();
36 Compiler compiler = compilerFor(
37 MEMORY_SOURCE_FILES,
38 diagnosticHandler: collector,
39 outputProvider: outputCollector,
40 options: options);
41
42 return compiler.run(Uri.parse('memory:main.dart')).then(
43 (bool success) {
44 Expect.isFalse(
45 success,
46 "Expected compilation failure.");
47 Expect.isTrue(
48 collector.warnings.isEmpty,
49 "Unexpected warnings: ${collector.warnings}");
50 Expect.isFalse(
51 collector.errors.isEmpty,
52 "Expected compile-time errors.");
53 Expect.equals(
54 expectHint,
55 collector.hints.isNotEmpty,
56 "Unexpected hints: ${collector.warnings}");
57
58 bool isCodeGenerated;
59 if (options.contains('--output-type=dart')) {
60 DartBackend backend = compiler.backend;
61 isCodeGenerated = backend.outputter.libraryInfo != null;
62 } else {
63 JavaScriptBackend backend = compiler.backend;
64 isCodeGenerated = backend.generatedCode.isNotEmpty;
65 }
66 Expect.equals(
67 expectedCodeGenerated,
68 isCodeGenerated,
69 expectedCodeGenerated
70 ? "Expected generated code for options $options."
71 : "Expected no code generated for options $options.");
72 Expect.equals(
73 expectedOutput,
74 outputCollector.outputMap.isNotEmpty,
75 expectedOutput
76 ? "Expected output for options $options."
77 : "Expected no output for options $options.");
78 });
79 }
80
81 void main() {
82 asyncTest(() async {
83 await test(
84 [],
85 expectedCodeGenerated: false,
86 expectedOutput: false);
87 await test(
88 ['--test-mode'],
89 expectedCodeGenerated: false,
90 expectedOutput: false);
91 await test(
92 ['--generate-code-with-compile-time-errors'],
93 expectedCodeGenerated: true,
94 expectedOutput: true);
95 await test(
96 ['--generate-code-with-compile-time-errors', '--test-mode'],
97 expectedCodeGenerated: true,
98 expectedOutput: false);
99
100 await test(
101 ['--use-cps-ir'],
102 expectedCodeGenerated: false,
103 expectedOutput: false);
104 await test(
105 ['--use-cps-ir', '--test-mode'],
106 expectedCodeGenerated: false,
107 expectedOutput: false);
108 await test(
109 ['--use-cps-ir', '--generate-code-with-compile-time-errors'],
110 expectedCodeGenerated: false,
111 expectedOutput: false,
112 expectHint: true);
113 await test(
114 ['--use-cps-ir',
115 '--generate-code-with-compile-time-errors',
116 '--test-mode'],
117 expectedCodeGenerated: false,
118 expectedOutput: false,
119 expectHint: true);
120
121 await test(
122 ['--output-type=dart'],
123 expectedCodeGenerated: false,
124 expectedOutput: false);
125 await test(
126 ['--output-type=dart', '--test-mode'],
127 expectedCodeGenerated: false,
128 expectedOutput: false);
129 await test(
130 ['--output-type=dart', '--generate-code-with-compile-time-errors'],
131 expectedCodeGenerated: false,
132 expectedOutput: false,
133 expectHint: true);
134 await test(
135 ['--output-type=dart',
136 '--generate-code-with-compile-time-errors',
137 '--test-mode'],
138 expectedCodeGenerated: false,
139 expectedOutput: false,
140 expectHint: true);
141 });
142 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/analyze_only_test.dart ('k') | tests/compiler/dart2js/mock_compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698