OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 polymer.test.build.common; | 5 library polymer.test.build.common; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 import 'package:polymer/src/build/common.dart'; |
10 import 'package:stack_trace/stack_trace.dart'; | 11 import 'package:stack_trace/stack_trace.dart'; |
11 import 'package:unittest/unittest.dart'; | 12 import 'package:unittest/unittest.dart'; |
12 | 13 |
13 String idToString(AssetId id) => '${id.package}|${id.path}'; | 14 String idToString(AssetId id) => '${id.package}|${id.path}'; |
14 AssetId idFromString(String s) { | 15 AssetId idFromString(String s) { |
15 int index = s.indexOf('|'); | 16 int index = s.indexOf('|'); |
16 return new AssetId(s.substring(0, index), s.substring(index + 1)); | 17 return new AssetId(s.substring(0, index), s.substring(index + 1)); |
17 } | 18 } |
18 | 19 |
19 String _removeTrailingWhitespace(String str) => | 20 String _removeTrailingWhitespace(String str) => |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 if (messages == null) return; | 122 if (messages == null) return; |
122 expect(messagesSeen, messages.length, | 123 expect(messagesSeen, messages.length, |
123 reason: 'less messages than expected'); | 124 reason: 'less messages than expected'); |
124 }); | 125 }); |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
128 testPhases(String testName, List<List<Transformer>> phases, | 129 testPhases(String testName, List<List<Transformer>> phases, |
129 Map<String, String> inputFiles, Map<String, String> expectedFiles, | 130 Map<String, String> inputFiles, Map<String, String> expectedFiles, |
130 [List<String> expectedMessages, bool solo = false]) { | 131 [List<String> expectedMessages, bool solo = false]) { |
131 | |
132 // Include mock versions of the polymer library that can be used to test | 132 // Include mock versions of the polymer library that can be used to test |
133 // resolver-based code generation. | 133 // resolver-based code generation. |
134 POLYMER_MOCKS.forEach((file, contents) { inputFiles[file] = contents; }); | 134 POLYMER_MOCKS.forEach((file, contents) { inputFiles[file] = contents; }); |
135 (solo ? solo_test : test)(testName, () { | 135 (solo ? solo_test : test)(testName, () { |
136 var helper = new TestHelper(phases, inputFiles, expectedMessages)..run(); | 136 var helper = new TestHelper(phases, inputFiles, expectedMessages)..run(); |
137 return helper.checkAll(expectedFiles).whenComplete(() => helper.tearDown()); | 137 return helper.checkAll(expectedFiles).whenComplete(() => helper.tearDown()); |
138 }); | 138 }); |
139 } | 139 } |
140 | 140 |
141 solo_testPhases(String testName, List<List<Transformer>> phases, | 141 solo_testPhases(String testName, List<List<Transformer>> phases, |
142 Map<String, String> inputFiles, Map<String, String> expectedFiles, | 142 Map<String, String> inputFiles, Map<String, String> expectedFiles, |
143 [List<String> expectedMessages]) => | 143 [List<String> expectedMessages]) => |
144 testPhases(testName, phases, inputFiles, expectedFiles, expectedMessages, | 144 testPhases(testName, phases, inputFiles, expectedFiles, expectedMessages, |
145 true); | 145 true); |
146 | 146 |
| 147 |
| 148 // Similar to testPhases, but tests all the cases around log behaviour in |
| 149 // different modes. Any expectedFiles with [LOG_EXTENSION] will be removed from |
| 150 // the expectation as appropriate, and any error logs will be changed to expect |
| 151 // warning logs as appropriate. |
| 152 testLogOutput(Function buildPhase, String testName, |
| 153 Map<String, String> inputFiles, Map<String, String> expectedFiles, |
| 154 [List<String> expectedMessages, bool solo = false]) { |
| 155 |
| 156 final transformOptions = [ |
| 157 new TransformOptions(injectBuildLogsInOutput: false, releaseMode: false), |
| 158 new TransformOptions(injectBuildLogsInOutput: false, releaseMode: true), |
| 159 new TransformOptions(injectBuildLogsInOutput: true, releaseMode: false), |
| 160 new TransformOptions(injectBuildLogsInOutput: true, releaseMode: true), |
| 161 ]; |
| 162 |
| 163 for (var options in transformOptions) { |
| 164 var phase = buildPhase(options); |
| 165 var actualExpectedFiles = {}; |
| 166 expectedFiles.forEach((file, content) { |
| 167 if (file.contains(LOG_EXTENSION) |
| 168 && (!options.injectBuildLogsInOutput || options.releaseMode)) { |
| 169 return; |
| 170 } |
| 171 actualExpectedFiles[file] = content; |
| 172 }); |
| 173 var fullTestName = '$testName: ' |
| 174 'injectLogs=${options.injectBuildLogsInOutput} ' |
| 175 'releaseMode=${options.releaseMode}'; |
| 176 testPhases( |
| 177 fullTestName, [[phase]], inputFiles, |
| 178 actualExpectedFiles, |
| 179 expectedMessages.map((m) => |
| 180 options.releaseMode ? m : m.replaceFirst('error:', 'warning:')) |
| 181 .toList(), |
| 182 solo); |
| 183 } |
| 184 } |
| 185 |
147 /// Generate an expected ._data file, where all files are assumed to be in the | 186 /// Generate an expected ._data file, where all files are assumed to be in the |
148 /// same [package]. | 187 /// same [package]. |
149 String expectedData(List<String> urls, {package: 'a', experimental: false}) { | 188 String expectedData(List<String> urls, {package: 'a', experimental: false}) { |
150 var ids = urls.map((e) => '["$package","$e"]').join(','); | 189 var ids = urls.map((e) => '["$package","$e"]').join(','); |
151 return '{"experimental_bootstrap":$experimental,"script_ids":[$ids]}'; | 190 return '{"experimental_bootstrap":$experimental,"script_ids":[$ids]}'; |
152 } | 191 } |
153 | 192 |
154 const EMPTY_DATA = '{"experimental_bootstrap":false,"script_ids":[]}'; | 193 const EMPTY_DATA = '{"experimental_bootstrap":false,"script_ids":[]}'; |
155 | 194 |
156 const WEB_COMPONENTS_TAG = | 195 const WEB_COMPONENTS_TAG = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 | 241 |
203 'observe|lib/observe.dart': | 242 'observe|lib/observe.dart': |
204 'library observe;\n' | 243 'library observe;\n' |
205 'export "src/metadata.dart";', | 244 'export "src/metadata.dart";', |
206 | 245 |
207 'observe|lib/src/metadata.dart': | 246 'observe|lib/src/metadata.dart': |
208 'library observe.src.metadata;\n' | 247 'library observe.src.metadata;\n' |
209 'class ObservableProperty { const ObservableProperty(); }\n' | 248 'class ObservableProperty { const ObservableProperty(); }\n' |
210 'const observable = const ObservableProperty();\n', | 249 'const observable = const ObservableProperty();\n', |
211 }; | 250 }; |
OLD | NEW |