| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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 // Checks that dart2js produces the expected static type warnings and |
| 6 // compile-time errors for the provided multitests. |
| 7 |
| 8 import 'dart:async'; |
| 9 |
| 10 import 'package:expect/expect.dart'; |
| 11 import 'package:async_helper/async_helper.dart'; |
| 12 |
| 13 import 'memory_compiler.dart'; |
| 14 |
| 15 import '../../../tools/testing/dart/multitest.dart' |
| 16 show ExtractTestsFromMultitest; |
| 17 import '../../../tools/testing/dart/utils.dart' |
| 18 show Path; |
| 19 |
| 20 void check(List<String> testFiles, |
| 21 {List<String> arguments: const <String>[], |
| 22 List<String> options: const <String>[]}) { |
| 23 bool outcomeMismatch = false; |
| 24 bool verbose = arguments.contains('-v'); |
| 25 var cachedCompiler; |
| 26 asyncTest(() => Future.forEach(testFiles, (String testFile) { |
| 27 Map<String, String> testSources = {}; |
| 28 Map<String, Set<String>> testOutcomes = {}; |
| 29 String fileName = 'tests/$testFile'; |
| 30 ExtractTestsFromMultitest(new Path(fileName), testSources, testOutcomes); |
| 31 return Future.forEach(testSources.keys, (String testName) { |
| 32 String testFileName = '$fileName/$testName'; |
| 33 Set<String> expectedOutcome = testOutcomes[testName]; |
| 34 DiagnosticCollector collector = new DiagnosticCollector(); |
| 35 var compiler = compilerFor( |
| 36 {testFileName: testSources[testName]}, |
| 37 diagnosticHandler: collector, |
| 38 options: ['--analyze-only']..addAll(options), |
| 39 showDiagnostics: verbose, |
| 40 cachedCompiler: cachedCompiler); |
| 41 return compiler.run(Uri.parse('memory:$testFileName')).then((_) { |
| 42 if (expectedOutcome.contains('compile-time error')) { |
| 43 if (collector.errors.isEmpty) { |
| 44 print('$testFileName: Missing compile-time error.'); |
| 45 outcomeMismatch = true; |
| 46 } |
| 47 } else if (expectedOutcome.contains('static type warning')) { |
| 48 if (collector.warnings.isEmpty) { |
| 49 print('$testFileName: Missing static type warning.'); |
| 50 outcomeMismatch = true; |
| 51 } |
| 52 } else { |
| 53 // Expect ok. |
| 54 if (!collector.errors.isEmpty || |
| 55 !collector.warnings.isEmpty) { |
| 56 collector.errors.forEach((message) { |
| 57 print('$testFileName: Unexpected error: ${message.message}'); |
| 58 }); |
| 59 collector.warnings.forEach((message) { |
| 60 print('$testFileName: Unexpected warning: ${message.message}'); |
| 61 }); |
| 62 outcomeMismatch = true; |
| 63 } |
| 64 } |
| 65 cachedCompiler = compiler; |
| 66 }); |
| 67 }); |
| 68 }).then((_) { |
| 69 Expect.isFalse(outcomeMismatch, 'Outcome mismatch'); |
| 70 })); |
| 71 } |
| OLD | NEW |