summaryrefslogtreecommitdiff
path: root/scripts/run-tests.sh
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-11-04 23:39:42 -0500
committerDavid Rothstein <drothstein@gmail.com>2014-11-04 23:39:42 -0500
commitcd3826875558cf9cf6faf0a797f9a468e43b44d8 (patch)
treee5a7d3bb31c68d8b180f0618fda93f5a3720b5c1 /scripts/run-tests.sh
parentb73583ffb3274f7f7561cae5bc45db2890a3cc25 (diff)
downloadbrdo-cd3826875558cf9cf6faf0a797f9a468e43b44d8.tar.gz
brdo-cd3826875558cf9cf6faf0a797f9a468e43b44d8.tar.bz2
Issue #2310415 by cilefen, ednawig, TravisCarden: Fixed run-tests.sh does not handle the error when invalid test groups/classes are specified.
Diffstat (limited to 'scripts/run-tests.sh')
-rwxr-xr-xscripts/run-tests.sh60
1 files changed, 54 insertions, 6 deletions
diff --git a/scripts/run-tests.sh b/scripts/run-tests.sh
index 189d7f2e8..9078168a1 100755
--- a/scripts/run-tests.sh
+++ b/scripts/run-tests.sh
@@ -419,9 +419,20 @@ function simpletest_script_get_test_list() {
else {
if ($args['class']) {
// Check for valid class names.
- foreach ($args['test_names'] as $class_name) {
- if (in_array($class_name, $all_tests)) {
- $test_list[] = $class_name;
+ $test_list = array();
+ foreach ($args['test_names'] as $test_class) {
+ if (class_exists($test_class)) {
+ $test_list[] = $test_class;
+ }
+ else {
+ $groups = simpletest_test_get_all();
+ $all_classes = array();
+ foreach ($groups as $group) {
+ $all_classes = array_merge($all_classes, array_keys($group));
+ }
+ simpletest_script_print_error('Test class not found: ' . $test_class);
+ simpletest_script_print_alternatives($test_class, $all_classes, 6);
+ exit(1);
}
}
}
@@ -444,9 +455,12 @@ function simpletest_script_get_test_list() {
// Check for valid group names and get all valid classes in group.
foreach ($args['test_names'] as $group_name) {
if (isset($groups[$group_name])) {
- foreach ($groups[$group_name] as $class_name => $info) {
- $test_list[] = $class_name;
- }
+ $test_list = array_merge($test_list, array_keys($groups[$group_name]));
+ }
+ else {
+ simpletest_script_print_error('Test group not found: ' . $group_name);
+ simpletest_script_print_alternatives($group_name, array_keys($groups));
+ exit(1);
}
}
}
@@ -674,3 +688,37 @@ function simpletest_script_color_code($status) {
}
return 0; // Default formatting.
}
+
+/**
+ * Prints alternative test names.
+ *
+ * Searches the provided array of string values for close matches based on the
+ * Levenshtein algorithm.
+ *
+ * @see http://php.net/manual/en/function.levenshtein.php
+ *
+ * @param string $string
+ * A string to test.
+ * @param array $array
+ * A list of strings to search.
+ * @param int $degree
+ * The matching strictness. Higher values return fewer matches. A value of
+ * 4 means that the function will return strings from $array if the candidate
+ * string in $array would be identical to $string by changing 1/4 or fewer of
+ * its characters.
+ */
+function simpletest_script_print_alternatives($string, $array, $degree = 4) {
+ $alternatives = array();
+ foreach ($array as $item) {
+ $lev = levenshtein($string, $item);
+ if ($lev <= strlen($item) / $degree || FALSE !== strpos($string, $item)) {
+ $alternatives[] = $item;
+ }
+ }
+ if (!empty($alternatives)) {
+ simpletest_script_print(" Did you mean?\n", SIMPLETEST_SCRIPT_COLOR_FAIL);
+ foreach ($alternatives as $alternative) {
+ simpletest_script_print(" - $alternative\n", SIMPLETEST_SCRIPT_COLOR_FAIL);
+ }
+ }
+}