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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/generate_code_with_compile_time_errors_test.dart
diff --git a/tests/compiler/dart2js/generate_code_with_compile_time_errors_test.dart b/tests/compiler/dart2js/generate_code_with_compile_time_errors_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..bf9b86e66de4965c22f6c501ad3c43a93c570ca8
--- /dev/null
+++ b/tests/compiler/dart2js/generate_code_with_compile_time_errors_test.dart
@@ -0,0 +1,142 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test that the compiler can generates code with compile time error according
+// to the compiler options.
+
+library dart2js.test.import;
+
+import 'package:expect/expect.dart';
+import 'package:async_helper/async_helper.dart';
+import 'package:compiler/src/dart2jslib.dart';
+import 'package:compiler/src/dart_backend/dart_backend.dart';
+import 'package:compiler/src/js_backend/js_backend.dart';
+import 'memory_compiler.dart';
+import 'output_collector.dart';
+
+const MEMORY_SOURCE_FILES = const {
+ 'main.dart': '''
+foo() {
+ const list = [];
+}
+
+main() {
+ foo();
+}
+''',
+};
+
+test(List<String> options,
+ {bool expectedOutput,
+ bool expectedCodeGenerated,
+ bool expectHint: false}) async {
+ DiagnosticCollector collector = new DiagnosticCollector();
+ OutputCollector outputCollector = new OutputCollector();
+ Compiler compiler = compilerFor(
+ MEMORY_SOURCE_FILES,
+ diagnosticHandler: collector,
+ outputProvider: outputCollector,
+ options: options);
+
+ return compiler.run(Uri.parse('memory:main.dart')).then(
+ (bool success) {
+ Expect.isFalse(
+ success,
+ "Expected compilation failure.");
+ Expect.isTrue(
+ collector.warnings.isEmpty,
+ "Unexpected warnings: ${collector.warnings}");
+ Expect.isFalse(
+ collector.errors.isEmpty,
+ "Expected compile-time errors.");
+ Expect.equals(
+ expectHint,
+ collector.hints.isNotEmpty,
+ "Unexpected hints: ${collector.warnings}");
+
+ bool isCodeGenerated;
+ if (options.contains('--output-type=dart')) {
+ DartBackend backend = compiler.backend;
+ isCodeGenerated = backend.outputter.libraryInfo != null;
+ } else {
+ JavaScriptBackend backend = compiler.backend;
+ isCodeGenerated = backend.generatedCode.isNotEmpty;
+ }
+ Expect.equals(
+ expectedCodeGenerated,
+ isCodeGenerated,
+ expectedCodeGenerated
+ ? "Expected generated code for options $options."
+ : "Expected no code generated for options $options.");
+ Expect.equals(
+ expectedOutput,
+ outputCollector.outputMap.isNotEmpty,
+ expectedOutput
+ ? "Expected output for options $options."
+ : "Expected no output for options $options.");
+ });
+}
+
+void main() {
+ asyncTest(() async {
+ await test(
+ [],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--test-mode'],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--generate-code-with-compile-time-errors'],
+ expectedCodeGenerated: true,
+ expectedOutput: true);
+ await test(
+ ['--generate-code-with-compile-time-errors', '--test-mode'],
+ expectedCodeGenerated: true,
+ expectedOutput: false);
+
+ await test(
+ ['--use-cps-ir'],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--use-cps-ir', '--test-mode'],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--use-cps-ir', '--generate-code-with-compile-time-errors'],
+ expectedCodeGenerated: false,
+ expectedOutput: false,
+ expectHint: true);
+ await test(
+ ['--use-cps-ir',
+ '--generate-code-with-compile-time-errors',
+ '--test-mode'],
+ expectedCodeGenerated: false,
+ expectedOutput: false,
+ expectHint: true);
+
+ await test(
+ ['--output-type=dart'],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--output-type=dart', '--test-mode'],
+ expectedCodeGenerated: false,
+ expectedOutput: false);
+ await test(
+ ['--output-type=dart', '--generate-code-with-compile-time-errors'],
+ expectedCodeGenerated: false,
+ expectedOutput: false,
+ expectHint: true);
+ await test(
+ ['--output-type=dart',
+ '--generate-code-with-compile-time-errors',
+ '--test-mode'],
+ expectedCodeGenerated: false,
+ expectedOutput: false,
+ expectHint: true);
+ });
+}
« 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