<commit_before>#! /bin/bash

DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/bash-spec.sh"

function it {
  echo "  $1"
  echo "    $2"
}

function describe {
  echo "$1"
  echo "$2"
}

function context {
  echo "$1"
  echo "$2"
}

function pass {
  echo "     PASS"
}

function fail {
  echo "**** FAIL - expected:$( if [[ "$_negation_" == true ]]; then echo " NOT"; fi; ) $_expected_ | actual: ${_actual_[@]}"
}<commit_msg>Added a summary section that counts passes and fails and exits with the appropriate code<commit_after>#! /bin/bash

DIR="${BASH_SOURCE%/*}"
if [[ ! -d "$DIR" ]]; then DIR="$PWD"; fi
. "$DIR/bash-spec.sh"

result_file=$RANDOM

exec 6<&1
exec > "$result_file"

function output_results {
  exec 1>&6 6>&-
  local results=$( cat "$result_file" )
  rm "$result_file"
  local passes=$( echo "$results" | grep "PASS" | wc -l )
  local fails=$( echo "$results" | grep "\*\*\*\* FAIL" | wc -l )
  echo "$results"
  echo "--SUMMARY--"
  echo "$passes PASSED"
  echo "$fails FAILED"
  if [[ $fails -gt 0 ]]; then
    exit 1
  else
    exit 0
  fi
}

function it {
  echo "  $1"
  echo "    $2"
}

function describe {
  echo "$1"
  echo "$2"
}

function context {
  echo "$1"
  echo "$2"
}

function pass {
  echo "     PASS"
}

function fail {
  echo "**** FAIL - expected:$( if [[ "$_negation_" == true ]]; then echo " NOT"; fi; ) $_expected_ | actual: ${_actual_[@]}"
}

trap output_results EXIT
{'fraction_non_alphanumeric': 0.19693806541405706, 'fraction_numerical': 0.013917884481558803, 'mean_word_length': 3.085227272727273, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2434595', 'n_tokens_mistral': 569, 'n_tokens_neox': 543, 'n_words': 164}