| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 /** | 5 /** |
| 6 * A unit test library for running groups of tests in a browser, instead of the | 6 * A unit test library for running groups of tests in a browser, instead of the |
| 7 * entire test file. This is especially used for large tests files that have | 7 * entire test file. This is especially used for large tests files that have |
| 8 * many subtests, so we can mark groups as failing at a finer granularity than | 8 * many subtests, so we can mark groups as failing at a finer granularity than |
| 9 * the entire test file. | 9 * the entire test file. |
| 10 * | 10 * |
| 11 * To use, import this file, and call [useHtmlIndividualConfiguration] at the | 11 * To use, import this file, and call [useHtmlIndividualConfiguration] at the |
| 12 * start of your set sequence. Important constraint: your group descriptions | 12 * start of your set sequence. Important constraint: your group descriptions |
| 13 * MUST NOT contain spaces. | 13 * MUST NOT contain spaces. |
| 14 */ | 14 */ |
| 15 library unittest_html_individual_config; | 15 library unittest_html_individual_config; |
| 16 | 16 |
| 17 import 'dart:html'; | 17 import 'dart:html'; |
| 18 import 'unittest.dart' as unittest; | 18 import 'unittest.dart' as unittest; |
| 19 import 'html_config.dart' as htmlconfig; | 19 import 'html_config.dart' as htmlconfig; |
| 20 | 20 |
| 21 class HtmlIndividualConfiguration extends htmlconfig.HtmlConfiguration { | 21 class HtmlIndividualConfiguration extends htmlconfig.HtmlConfiguration { |
| 22 | 22 |
| 23 String _noSuchTest = ''; | 23 String _noSuchTest = ''; |
| 24 HtmlIndividualConfiguration(isLayoutTest): super(isLayoutTest); | 24 HtmlIndividualConfiguration(isLayoutTest): super(isLayoutTest); |
| 25 | 25 |
| 26 void onStart() { | 26 void onStart() { |
| 27 var testGroupName = window.location.search; | 27 var testGroupName = window.location.search; |
| 28 var groupVar = '&group='; | 28 var groupVar = 'group='; |
| 29 if (testGroupName != '' && testGroupName.contains(groupVar)) { | 29 if (testGroupName != '' && testGroupName.contains(groupVar)) { |
| 30 try { | 30 try { |
| 31 testGroupName = testGroupName.substring( | 31 testGroupName = testGroupName.substring( |
| 32 testGroupName.indexOf(groupVar) + groupVar.length); | 32 testGroupName.indexOf(groupVar) + groupVar.length); |
| 33 var endIndex = testGroupName.indexOf('&'); | 33 var endIndex = testGroupName.indexOf('&'); |
| 34 testGroupName = testGroupName.substring(0, | 34 testGroupName = testGroupName.substring(0, |
| 35 endIndex == -1 ? testGroupName.length : endIndex); | 35 endIndex == -1 ? testGroupName.length : endIndex); |
| 36 unittest.filterTests('^$testGroupName${unittest.groupSep}'); | 36 unittest.filterTests('^$testGroupName${unittest.groupSep}'); |
| 37 } catch (e) { | 37 } catch (e) { |
| 38 print('tried to match "$testGroupName"'); | 38 print('tried to match "$testGroupName"'); |
| 39 print('NO_SUCH_TEST'); | 39 print('NO_SUCH_TEST'); |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 super.onStart(); | 42 super.onStart(); |
| 43 } | 43 } |
| 44 } | 44 } |
| 45 | 45 |
| 46 void useHtmlIndividualConfiguration([bool isLayoutTest = false]) { | 46 void useHtmlIndividualConfiguration([bool isLayoutTest = false]) { |
| 47 if (unittest.config != null) return; | 47 if (unittest.config != null) return; |
| 48 unittest.configure(new HtmlIndividualConfiguration(isLayoutTest)); | 48 unittest.configure(new HtmlIndividualConfiguration(isLayoutTest)); |
| 49 } | 49 } |
| OLD | NEW |