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 20 matching lines...) Expand all Loading... | |
31 /// The description will be added to the descriptions of any surrounding | 31 /// The description will be added to the descriptions of any surrounding |
32 /// [group]s. | 32 /// [group]s. |
33 /// | 33 /// |
34 /// If [testOn] is passed, it's parsed as a [PlatformSelector], and the test | 34 /// If [testOn] is passed, it's parsed as a [PlatformSelector], and the test |
35 /// will only be run on matching platforms. | 35 /// will only be run on matching platforms. |
36 /// | 36 /// |
37 /// If [timeout] is passed, it's used to modify or replace the default timeout | 37 /// If [timeout] is passed, it's used to modify or replace the default timeout |
38 /// of 30 seconds. Timeout modifications take precedence in suite-group-test | 38 /// of 30 seconds. Timeout modifications take precedence in suite-group-test |
39 /// order, so [timeout] will also modify any timeouts set on the group or | 39 /// order, so [timeout] will also modify any timeouts set on the group or |
40 /// suite. | 40 /// suite. |
41 void test(String description, body(), {String testOn, Timeout timeout}) { | 41 /// |
42 /// If [skip] is a String or `true`, the test is skipped. If it's a String, it | |
43 /// should explain why the test is skipped; this reason will be printed in | |
44 /// lieu of running the test. | |
kevmoo
2015/04/17 22:53:34
in lieu -> instead
more simple English are better
nweiz
2015/04/17 22:56:12
Done.
| |
45 void test(String description, body(), {String testOn, Timeout timeout, | |
46 skip}) { | |
42 // TODO(nweiz): Once tests have begun running, throw an error if [test] is | 47 // TODO(nweiz): Once tests have begun running, throw an error if [test] is |
43 // called. | 48 // called. |
44 var prefix = _group.description; | 49 var prefix = _group.description; |
45 if (prefix != null) description = "$prefix $description"; | 50 if (prefix != null) description = "$prefix $description"; |
46 | 51 |
47 var metadata = _group.metadata.merge( | 52 var metadata = _group.metadata.merge( |
48 new Metadata.parse(testOn: testOn, timeout: timeout)); | 53 new Metadata.parse(testOn: testOn, timeout: timeout, skip: skip)); |
49 var group = _group; | 54 var group = _group; |
50 _tests.add(new LocalTest(description, metadata, () { | 55 _tests.add(new LocalTest(description, metadata, () { |
51 // TODO(nweiz): It might be useful to throw an error here if a test starts | 56 // TODO(nweiz): It might be useful to throw an error here if a test starts |
52 // running while other tests from the same declarer are also running, | 57 // running while other tests from the same declarer are also running, |
53 // since they might share closurized state. | 58 // since they might share closurized state. |
54 return group.runSetUp().then((_) => body()); | 59 return group.runSetUp().then((_) => body()); |
55 }, tearDown: group.runTearDown)); | 60 }, tearDown: group.runTearDown)); |
56 } | 61 } |
57 | 62 |
58 /// Creates a group of tests. | 63 /// Creates a group of tests. |
59 /// | 64 /// |
60 /// A group's description is included in the descriptions of any tests or | 65 /// A group's description is included in the descriptions of any tests or |
61 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the | 66 /// sub-groups it contains. [setUp] and [tearDown] are also scoped to the |
62 /// containing group. | 67 /// containing group. |
63 /// | 68 /// |
64 /// If [testOn] is passed, it's parsed as a [PlatformSelector], and any tests | 69 /// If [testOn] is passed, it's parsed as a [PlatformSelector], and any tests |
65 /// in the group will only be run on matching platforms. | 70 /// in the group will only be run on matching platforms. |
66 /// | 71 /// |
67 /// If [timeout] is passed, it's used to modify or replace the default timeout | 72 /// If [timeout] is passed, it's used to modify or replace the default timeout |
68 /// of 30 seconds. Timeout modifications take precedence in suite-group-test | 73 /// of 30 seconds. Timeout modifications take precedence in suite-group-test |
69 /// order, so [timeout] will also modify any timeouts set on the group or | 74 /// order, so [timeout] will also modify any timeouts set on the group or |
70 /// suite. | 75 /// suite. |
76 /// | |
77 /// If [skip] is a String or `true`, the group is skipped. If it's a String, | |
78 /// it should explain why the group is skipped; this reason will be printed in | |
79 /// lieu of running the group's tests. | |
kevmoo
2015/04/17 22:53:34
same righch 'ere
| |
71 void group(String description, void body(), {String testOn, | 80 void group(String description, void body(), {String testOn, |
72 Timeout timeout}) { | 81 Timeout timeout, skip}) { |
73 var oldGroup = _group; | 82 var oldGroup = _group; |
74 | 83 |
75 var metadata = new Metadata.parse(testOn: testOn, timeout: timeout); | 84 var metadata = new Metadata.parse( |
85 testOn: testOn, timeout: timeout, skip: skip); | |
86 | |
87 // Don' load the tests for a skipped group. | |
88 if (metadata.skip) { | |
89 _tests.add(new LocalTest(description, metadata, () {})); | |
90 return; | |
91 } | |
92 | |
76 _group = new Group(oldGroup, description, metadata); | 93 _group = new Group(oldGroup, description, metadata); |
77 try { | 94 try { |
78 body(); | 95 body(); |
79 } finally { | 96 } finally { |
80 _group = oldGroup; | 97 _group = oldGroup; |
81 } | 98 } |
82 } | 99 } |
83 | 100 |
84 /// Registers a function to be run before tests. | 101 /// Registers a function to be run before tests. |
85 /// | 102 /// |
(...skipping 22 matching lines...) Expand all Loading... | |
108 /// groups or at the top level. | 125 /// groups or at the top level. |
109 void tearDown(callback()) { | 126 void tearDown(callback()) { |
110 if (_group.tearDown != null) { | 127 if (_group.tearDown != null) { |
111 throw new StateError("tearDown() may not be called multiple times for " | 128 throw new StateError("tearDown() may not be called multiple times for " |
112 "the same group."); | 129 "the same group."); |
113 } | 130 } |
114 | 131 |
115 _group.tearDown = callback; | 132 _group.tearDown = callback; |
116 } | 133 } |
117 } | 134 } |
OLD | NEW |