| 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.backend.declarer; | 5 library test.backend.declarer; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 | 8 |
| 9 import '../frontend/timeout.dart'; | 9 import '../frontend/timeout.dart'; |
| 10 import 'group.dart'; | 10 import 'group.dart'; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 var group = _group; | 40 var group = _group; |
| 41 _tests.add(new LocalTest(description, metadata, () { | 41 _tests.add(new LocalTest(description, metadata, () { |
| 42 // TODO(nweiz): It might be useful to throw an error here if a test starts | 42 // TODO(nweiz): It might be useful to throw an error here if a test starts |
| 43 // running while other tests from the same declarer are also running, | 43 // running while other tests from the same declarer are also running, |
| 44 // since they might share closurized state. | 44 // since they might share closurized state. |
| 45 | 45 |
| 46 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in | 46 // TODO(nweiz): Use async/await here once issue 23497 has been fixed in |
| 47 // two stable versions. | 47 // two stable versions. |
| 48 return Invoker.current.waitForOutstandingCallbacks(() { | 48 return Invoker.current.waitForOutstandingCallbacks(() { |
| 49 return group.runSetUp().then((_) => body()); | 49 return group.runSetUps().then((_) => body()); |
| 50 }).then((_) => group.runTearDown()); | 50 }).then((_) => group.runTearDowns()); |
| 51 })); | 51 })); |
| 52 } | 52 } |
| 53 | 53 |
| 54 /// Creates a group of tests. | 54 /// Creates a group of tests. |
| 55 void group(String description, void body(), {String testOn, | 55 void group(String description, void body(), {String testOn, |
| 56 Timeout timeout, skip, Map<String, dynamic> onPlatform}) { | 56 Timeout timeout, skip, Map<String, dynamic> onPlatform}) { |
| 57 var oldGroup = _group; | 57 var oldGroup = _group; |
| 58 | 58 |
| 59 var metadata = new Metadata.parse( | 59 var metadata = new Metadata.parse( |
| 60 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); | 60 testOn: testOn, timeout: timeout, skip: skip, onPlatform: onPlatform); |
| 61 | 61 |
| 62 // Don' load the tests for a skipped group. | 62 // Don' load the tests for a skipped group. |
| 63 if (metadata.skip) { | 63 if (metadata.skip) { |
| 64 _tests.add(new LocalTest(description, metadata, () {})); | 64 _tests.add(new LocalTest(description, metadata, () {})); |
| 65 return; | 65 return; |
| 66 } | 66 } |
| 67 | 67 |
| 68 _group = new Group(oldGroup, description, metadata); | 68 _group = new Group(oldGroup, description, metadata); |
| 69 try { | 69 try { |
| 70 body(); | 70 body(); |
| 71 } finally { | 71 } finally { |
| 72 _group = oldGroup; | 72 _group = oldGroup; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 /// Registers a function to be run before tests. | 76 /// Registers a function to be run before tests. |
| 77 void setUp(callback()) { | 77 void setUp(callback()) { |
| 78 if (_group.setUp != null) { | 78 _group.setUps.add(callback); |
| 79 throw new StateError("setUp() may not be called multiple times for the " | |
| 80 "same group."); | |
| 81 } | |
| 82 | |
| 83 _group.setUp = callback; | |
| 84 } | 79 } |
| 85 | 80 |
| 86 /// Registers a function to be run after tests. | 81 /// Registers a function to be run after tests. |
| 87 void tearDown(callback()) { | 82 void tearDown(callback()) { |
| 88 if (_group.tearDown != null) { | 83 _group.tearDowns.add(callback); |
| 89 throw new StateError("tearDown() may not be called multiple times for " | |
| 90 "the same group."); | |
| 91 } | |
| 92 | |
| 93 _group.tearDown = callback; | |
| 94 } | 84 } |
| 95 } | 85 } |
| OLD | NEW |