diff --git a/readme.md b/readme.md index 47c41e8..dcd1148 100644 --- a/readme.md +++ b/readme.md @@ -56,7 +56,6 @@ and use the incomplete sort that is installed on your system. This is not a big deal; if your test files all start with alphanumeric letters, the output should look fine. - ## Install Urchin is contained in a single file, so you can install it by copying it to a directory in your `PATH`. For example, you can run the following as root. diff --git a/urchin b/urchin index d6b4956..c5a60e9 100755 --- a/urchin +++ b/urchin @@ -56,6 +56,13 @@ if [ -n "${ZSH_VERSION}" ]; then fi +sort_python() { + python -c 'import sys +for line in sorted(sys.stdin.readlines()): + sys.stdout.write(line) +' +} + # All temporary files go here urchin_tmp=$(mktemp -d) > "${urchin_tmp}/log" @@ -274,9 +281,7 @@ report_outcome() { # Use a temporary file rather than a pipe because a pipe starts a sub-shell # and thus makes the above variables local. sorted_log_file=$(mktemp) - - # GNU sort is broken. Oh well. - sort "${log_file}" > "${sorted_log_file}" + "${sort}" "${log_file}" > "${sorted_log_file}" while read line; do abspath=$(echo "${line}" | cut -f1) @@ -580,10 +585,17 @@ main() { # Warn about strange sort commands weird_string='@ b\n- d\n? a\n~ c\n! e\n' sort_result="$(printf "${weird_string}" | sort | cut -d\ -f2 | tr -d '\n')" - if test "${sort_result}" != edacb; then - echo 'Your version of sort sorts in dictionary order (-d) by default. - Depending on how you name your tests, your Urchin output may look strange. - If this is a problem, install BusyBox or BSD coreutils.' >&2 + if test "${sort_result}" = edacb; then + sort=sort + else + if which python > /dev/null; then + sort=sort_python + else + echo 'Your version of sort sorts in dictionary order (-d) by default. + Depending on how you name your tests, your Urchin output may look strange. + If this is a problem, install BusyBox or BSD coreutils.' >&2 + sort=sort + fi fi if test -n "${urchin_timeout}"; then