| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2015, the Dartino 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.md file. | |
| 4 | |
| 5 library test.fletch_warnings_suite; | |
| 6 | |
| 7 import 'dart:io' as io; | |
| 8 | |
| 9 import 'dart:convert' show | |
| 10 UTF8; | |
| 11 | |
| 12 import 'test_suite.dart' show | |
| 13 TestSuite, | |
| 14 TestUtils; | |
| 15 | |
| 16 import 'test_runner.dart' show | |
| 17 Command, | |
| 18 CommandBuilder, | |
| 19 CompilationCommandOutputImpl, | |
| 20 TestCase; | |
| 21 | |
| 22 import 'runtime_configuration.dart' show | |
| 23 RuntimeConfiguration; | |
| 24 | |
| 25 import 'status_file_parser.dart' show | |
| 26 Expectation, | |
| 27 TestExpectations; | |
| 28 | |
| 29 import 'compiler_configuration.dart' show | |
| 30 CommandArtifact; | |
| 31 | |
| 32 const Map<String, String> URIS_TO_ANALYZE = const <String, String>{ | |
| 33 "hub_main": "package:fletchc/src/hub/hub_main.dart", | |
| 34 "fletch_test_suite": "tests/fletch_tests/fletch_test_suite.dart", | |
| 35 "test_dart": "tools/test.dart", | |
| 36 }; | |
| 37 | |
| 38 class FletchWarningsRuntimeConfiguration extends RuntimeConfiguration { | |
| 39 final String system; | |
| 40 final String dartBinary; | |
| 41 | |
| 42 FletchWarningsRuntimeConfiguration(Map configuration) | |
| 43 : system = configuration['system'], | |
| 44 dartBinary = '${TestUtils.buildDir(configuration)}' | |
| 45 '${io.Platform.pathSeparator}dart', | |
| 46 super.subclass(); | |
| 47 | |
| 48 List<Command> computeRuntimeCommands( | |
| 49 TestSuite suite, | |
| 50 CommandBuilder commandBuilder, | |
| 51 CommandArtifact artifact, | |
| 52 String script, | |
| 53 List<String> arguments, | |
| 54 Map<String, String> environmentOverrides) { | |
| 55 return <Command>[ | |
| 56 commandBuilder.getAnalysisCommand( | |
| 57 'dart2js-analyze-only', | |
| 58 dartBinary, | |
| 59 <String>[ | |
| 60 '--packages=.packages', // For the VM. | |
| 61 './third_party/dart/pkg/compiler/lib/src/dart2js.dart', | |
| 62 '--packages=.packages', // For dart2js. | |
| 63 '--library-root=third_party/dart/sdk/', | |
| 64 '--analyze-only', | |
| 65 '--show-package-warnings', | |
| 66 '--categories=Server', | |
| 67 '--allow-native-extensions']..addAll(arguments), | |
| 68 null, | |
| 69 flavor: 'dart2js')]; | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 class FletchWarningsSuite extends TestSuite { | |
| 74 FletchWarningsSuite(Map configuration, testSuiteDir) | |
| 75 : super(configuration, "warnings"); | |
| 76 | |
| 77 void forEachTest( | |
| 78 void onTest(TestCase testCase), | |
| 79 Map testCache, | |
| 80 [void onDone()]) { | |
| 81 this.doTest = onTest; | |
| 82 if (configuration['runtime'] != 'fletch_warnings') { | |
| 83 onDone(); | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 RuntimeConfiguration runtimeConfiguration = | |
| 88 new RuntimeConfiguration(configuration); | |
| 89 | |
| 90 // There are no status files for this. Please fix warnings. | |
| 91 TestExpectations expectations = new TestExpectations(); | |
| 92 | |
| 93 URIS_TO_ANALYZE.forEach((String testName, String uri) { | |
| 94 List<Command> commands = runtimeConfiguration.computeRuntimeCommands( | |
| 95 this, | |
| 96 CommandBuilder.instance, | |
| 97 null, | |
| 98 uri, | |
| 99 <String>[uri], | |
| 100 null); | |
| 101 var testCase = new TestCase( | |
| 102 '$suiteName/$testName', | |
| 103 commands, | |
| 104 configuration, expectations.expectations(testName)); | |
| 105 enqueueNewTestCase(testCase); | |
| 106 }); | |
| 107 | |
| 108 onDone(); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 /// Pattern that matches warnings (from dart2js) that contain a comment saying | |
| 113 /// "NO_LINT". | |
| 114 final RegExp noLintFilter = | |
| 115 new RegExp(r"[^\n]*\n[^\n]*\n[^\n]* // NO_LINT\n *\^+\n"); | |
| 116 | |
| 117 class FletchWarningsOutputCommand extends CompilationCommandOutputImpl { | |
| 118 FletchWarningsOutputCommand( | |
| 119 Command command, int exitCode, bool timedOut, | |
| 120 List<int> stdout, List<int> stderr, | |
| 121 Duration time, bool compilationSkipped) | |
| 122 : super( | |
| 123 command, exitCode, timedOut, stdout, stderr, time, | |
| 124 compilationSkipped); | |
| 125 | |
| 126 Expectation result(TestCase testCase) { | |
| 127 Expectation result = super.result(testCase); | |
| 128 if (result != Expectation.PASS) return result; | |
| 129 | |
| 130 var filteredStdout = | |
| 131 UTF8.decode(stdout, allowMalformed: true).replaceAll(noLintFilter, ""); | |
| 132 if (filteredStdout.isNotEmpty) { | |
| 133 return Expectation.STATIC_WARNING; | |
| 134 } | |
| 135 | |
| 136 return Expectation.PASS; | |
| 137 } | |
| 138 } | |
| OLD | NEW |