| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 test.src.task.driver_test; | 5 library test.src.task.driver_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/context/cache.dart'; | 7 import 'package:analyzer/src/context/cache.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart' | 9 import 'package:analyzer/src/generated/engine.dart' |
| 10 show AnalysisContext, CacheState, RetentionPriority; | 10 show AnalysisContext, CacheState, RetentionPriority; |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 CacheEntry entry = new CacheEntry(); | 152 CacheEntry entry = new CacheEntry(); |
| 153 expect(entry.explicitlyAdded, false); | 153 expect(entry.explicitlyAdded, false); |
| 154 entry.explicitlyAdded = true; | 154 entry.explicitlyAdded = true; |
| 155 expect(entry.explicitlyAdded, true); | 155 expect(entry.explicitlyAdded, true); |
| 156 } | 156 } |
| 157 | 157 |
| 158 test_fixExceptionState_error_exception() { | 158 test_fixExceptionState_error_exception() { |
| 159 ResultDescriptor result = new ResultDescriptor('test', null); | 159 ResultDescriptor result = new ResultDescriptor('test', null); |
| 160 CaughtException exception = new CaughtException(null, null); | 160 CaughtException exception = new CaughtException(null, null); |
| 161 CacheEntry entry = new CacheEntry(); | 161 CacheEntry entry = new CacheEntry(); |
| 162 entry.setState(result, CacheState.ERROR); | 162 entry.setErrorState(<ResultDescriptor>[result], exception); |
| 163 entry.exception = exception; | |
| 164 entry.fixExceptionState(); | 163 entry.fixExceptionState(); |
| 165 expect(entry.getState(result), CacheState.ERROR); | 164 expect(entry.getState(result), CacheState.ERROR); |
| 166 expect(entry.exception, exception); | 165 expect(entry.exception, exception); |
| 167 } | 166 } |
| 168 | 167 |
| 169 test_fixExceptionState_error_noException() { | |
| 170 ResultDescriptor result = new ResultDescriptor('test', null); | |
| 171 CacheEntry entry = new CacheEntry(); | |
| 172 entry.setState(result, CacheState.ERROR); | |
| 173 entry.fixExceptionState(); | |
| 174 expect(entry.getState(result), CacheState.ERROR); | |
| 175 expect(entry.exception, isNotNull); | |
| 176 } | |
| 177 | |
| 178 test_fixExceptionState_noError_exception() { | 168 test_fixExceptionState_noError_exception() { |
| 179 ResultDescriptor result = new ResultDescriptor('test', null); | 169 ResultDescriptor result = new ResultDescriptor('test', null); |
| 180 CacheEntry entry = new CacheEntry(); | 170 CacheEntry entry = new CacheEntry(); |
| 181 entry.exception = new CaughtException(null, null); | 171 // set one result to ERROR |
| 172 CaughtException exception = new CaughtException(null, null); |
| 173 entry.setErrorState(<ResultDescriptor>[result], exception); |
| 174 // set the same result to VALID |
| 175 entry.setValue(result, 1); |
| 176 // fix the exception state |
| 182 entry.fixExceptionState(); | 177 entry.fixExceptionState(); |
| 183 expect(entry.getState(result), CacheState.INVALID); | |
| 184 expect(entry.exception, isNull); | 178 expect(entry.exception, isNull); |
| 185 } | 179 } |
| 186 | 180 |
| 187 test_fixExceptionState_noError_noException() { | 181 test_fixExceptionState_noError_noException() { |
| 188 ResultDescriptor result = new ResultDescriptor('test', null); | 182 ResultDescriptor result = new ResultDescriptor('test', null); |
| 189 CacheEntry entry = new CacheEntry(); | 183 CacheEntry entry = new CacheEntry(); |
| 190 entry.fixExceptionState(); | 184 entry.fixExceptionState(); |
| 191 expect(entry.getState(result), CacheState.INVALID); | 185 expect(entry.getState(result), CacheState.INVALID); |
| 192 expect(entry.exception, isNull); | 186 expect(entry.exception, isNull); |
| 193 } | 187 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 expect(entry.hasAstStructure, true); | 220 expect(entry.hasAstStructure, true); |
| 227 } | 221 } |
| 228 | 222 |
| 229 test_hasErrorState_false() { | 223 test_hasErrorState_false() { |
| 230 CacheEntry entry = new CacheEntry(); | 224 CacheEntry entry = new CacheEntry(); |
| 231 expect(entry.hasErrorState(), false); | 225 expect(entry.hasErrorState(), false); |
| 232 } | 226 } |
| 233 | 227 |
| 234 test_hasErrorState_true() { | 228 test_hasErrorState_true() { |
| 235 ResultDescriptor result = new ResultDescriptor('test', null); | 229 ResultDescriptor result = new ResultDescriptor('test', null); |
| 230 CaughtException exception = new CaughtException(null, null); |
| 236 CacheEntry entry = new CacheEntry(); | 231 CacheEntry entry = new CacheEntry(); |
| 237 entry.setState(result, CacheState.ERROR); | 232 entry.setErrorState(<ResultDescriptor>[result], exception); |
| 238 expect(entry.hasErrorState(), true); | 233 expect(entry.hasErrorState(), true); |
| 239 } | 234 } |
| 240 | 235 |
| 241 test_invalidateAllInformation() { | 236 test_invalidateAllInformation() { |
| 242 ResultDescriptor result = new ResultDescriptor('test', null); | 237 ResultDescriptor result = new ResultDescriptor('test', null); |
| 243 CacheEntry entry = new CacheEntry(); | 238 CacheEntry entry = new CacheEntry(); |
| 244 entry.setValue(result, 'value'); | 239 entry.setValue(result, 'value'); |
| 245 entry.invalidateAllInformation(); | 240 entry.invalidateAllInformation(); |
| 246 expect(entry.getState(result), CacheState.INVALID); | 241 expect(entry.getState(result), CacheState.INVALID); |
| 247 expect(entry.getValue(result), isNull); | 242 expect(entry.getValue(result), isNull); |
| 248 } | 243 } |
| 249 | 244 |
| 245 test_setErrorState() { |
| 246 ResultDescriptor result1 = new ResultDescriptor('res1', 1); |
| 247 ResultDescriptor result2 = new ResultDescriptor('res2', 2); |
| 248 ResultDescriptor result3 = new ResultDescriptor('res3', 3); |
| 249 // prepare some good state |
| 250 CacheEntry entry = new CacheEntry(); |
| 251 entry.setValue(result1, 10); |
| 252 entry.setValue(result2, 20); |
| 253 entry.setValue(result3, 30); |
| 254 // set error state |
| 255 CaughtException exception = new CaughtException(null, null); |
| 256 entry.setErrorState(<ResultDescriptor>[result1, result2], exception); |
| 257 // verify |
| 258 expect(entry.exception, exception); |
| 259 expect(entry.getState(result1), CacheState.ERROR); |
| 260 expect(entry.getState(result2), CacheState.ERROR); |
| 261 expect(entry.getState(result3), CacheState.VALID); |
| 262 expect(entry.getValue(result1), 1); |
| 263 expect(entry.getValue(result2), 2); |
| 264 expect(entry.getValue(result3), 30); |
| 265 } |
| 266 |
| 267 test_setErrorState_noDescriptors() { |
| 268 CaughtException exception = new CaughtException(null, null); |
| 269 CacheEntry entry = new CacheEntry(); |
| 270 expect(() { |
| 271 entry.setErrorState(<ResultDescriptor>[], exception); |
| 272 }, throwsArgumentError); |
| 273 } |
| 274 |
| 275 test_setErrorState_noException() { |
| 276 ResultDescriptor result = new ResultDescriptor('test', null); |
| 277 CacheEntry entry = new CacheEntry(); |
| 278 expect(() { |
| 279 entry.setErrorState(<ResultDescriptor>[result], null); |
| 280 }, throwsArgumentError); |
| 281 } |
| 282 |
| 250 test_setState_error() { | 283 test_setState_error() { |
| 251 ResultDescriptor result = new ResultDescriptor('test', null); | 284 ResultDescriptor result = new ResultDescriptor('test', null); |
| 252 CacheEntry entry = new CacheEntry(); | 285 CacheEntry entry = new CacheEntry(); |
| 253 entry.setState(result, CacheState.ERROR); | 286 entry.setValue(result, 42); |
| 254 expect(entry.getState(result), CacheState.ERROR); | 287 // an invalid state change |
| 255 expect(entry.getValue(result), isNull); | 288 expect(() { |
| 289 entry.setState(result, CacheState.ERROR); |
| 290 }, throwsArgumentError); |
| 291 // no changes |
| 292 expect(entry.getState(result), CacheState.VALID); |
| 293 expect(entry.getValue(result), 42); |
| 294 } |
| 295 |
| 296 test_setState_flushed() { |
| 297 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 298 CacheEntry entry = new CacheEntry(); |
| 299 // set VALID |
| 300 entry.setValue(result, 10); |
| 301 expect(entry.getState(result), CacheState.VALID); |
| 302 expect(entry.getValue(result), 10); |
| 303 // set FLUSHED |
| 304 entry.setState(result, CacheState.FLUSHED); |
| 305 expect(entry.getState(result), CacheState.FLUSHED); |
| 306 expect(entry.getValue(result), 1); |
| 307 } |
| 308 |
| 309 test_setState_inProcess() { |
| 310 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 311 CacheEntry entry = new CacheEntry(); |
| 312 // set VALID |
| 313 entry.setValue(result, 10); |
| 314 expect(entry.getState(result), CacheState.VALID); |
| 315 expect(entry.getValue(result), 10); |
| 316 // set IN_PROCESS |
| 317 entry.setState(result, CacheState.IN_PROCESS); |
| 318 expect(entry.getState(result), CacheState.IN_PROCESS); |
| 319 expect(entry.getValue(result), 10); |
| 256 } | 320 } |
| 257 | 321 |
| 258 test_setState_invalid() { | 322 test_setState_invalid() { |
| 259 ResultDescriptor result = new ResultDescriptor('test', null); | 323 ResultDescriptor result = new ResultDescriptor('test', 1); |
| 260 CacheEntry entry = new CacheEntry(); | 324 CacheEntry entry = new CacheEntry(); |
| 325 // set VALID |
| 326 entry.setValue(result, 10); |
| 327 expect(entry.getState(result), CacheState.VALID); |
| 328 expect(entry.getValue(result), 10); |
| 329 // set INVALID |
| 261 entry.setState(result, CacheState.INVALID); | 330 entry.setState(result, CacheState.INVALID); |
| 262 expect(entry.getState(result), CacheState.INVALID); | 331 expect(entry.getState(result), CacheState.INVALID); |
| 263 expect(entry.getValue(result), isNull); | 332 expect(entry.getValue(result), 1); |
| 264 } | 333 } |
| 265 | 334 |
| 266 test_setState_valid() { | 335 test_setState_valid() { |
| 267 ResultDescriptor result = new ResultDescriptor('test', null); | 336 ResultDescriptor result = new ResultDescriptor('test', null); |
| 268 CacheEntry entry = new CacheEntry(); | 337 CacheEntry entry = new CacheEntry(); |
| 269 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); | 338 expect(() => entry.setState(result, CacheState.VALID), throwsArgumentError); |
| 270 } | 339 } |
| 271 | 340 |
| 272 test_setValue() { | 341 test_setValue() { |
| 273 String value = 'value'; | 342 String value = 'value'; |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 return new UniversalCachePartition(null, 8, policy); | 496 return new UniversalCachePartition(null, 8, policy); |
| 428 } | 497 } |
| 429 | 498 |
| 430 void test_contains() { | 499 void test_contains() { |
| 431 UniversalCachePartition partition = | 500 UniversalCachePartition partition = |
| 432 new UniversalCachePartition(null, 8, null); | 501 new UniversalCachePartition(null, 8, null); |
| 433 TestSource source = new TestSource(); | 502 TestSource source = new TestSource(); |
| 434 expect(partition.contains(source), isTrue); | 503 expect(partition.contains(source), isTrue); |
| 435 } | 504 } |
| 436 } | 505 } |
| OLD | NEW |