<commit_before>#!/bin/bash

xcode_path=$(xcode-select -p)
swiftc_version=$(xcrun swiftc -version | cut -f2 -d"(" | cut -f1 -d")" | head -1)

echo
echo "Running tests against: $swiftc_version"
echo "    Using Xcode found at path: $xcode_path"

num_crashed=0
num_tests=0

color_red="\e[01;31m"
color_green="\e[32m"
color_stop="\e[00m"


do_test() {
  path="$1"
  
  if [ -f $path ]; then
    num_tests=$((num_tests + 1))
    test_name=$(basename -s ".swift" "$path")
    test_name=${test_name//-/ }
    
    $(xcrun swiftc $path 2>&1 | egrep -q "error: unable to execute command: Segmentation fault:")

    if [ $? == 0 ]; then
      num_crashed=$((num_crashed + 1))
      printf "    ${color_red}✘${color_stop}  $test_name\n"
    else
      printf "    ${color_green}✓${color_stop}  $test_name\n"
    fi
  fi
}

run_tests() {
  header="$1"
  path="$2"

  echo
  echo "== $header =="
  echo
  
  for test_path in $path/*.swift
  do
    do_test $test_path
  done

}

show_results() {
  if [ $num_crashed == 0 ]; then
    echo "** CRASH-TESTS PASSED **"
    echo
  else
    echo "** CRASH-TESTS FAILED: $num_crashed of $num_tests crashed **"
    echo
  fi
}

run_tests "Currently Known Crashes" "./crashes"
run_tests "Crashes Fixed in Previous Release" "./fixed"

show_results
<commit_msg>Added better printing and md5 crash sums for crashes; foundation for auto-validation of duplicate crashes.<commit_after>#!/bin/bash

xcode_path=$(xcode-select -p)
swiftc_version=$(xcrun swiftc -version | cut -f2 -d"(" | cut -f1 -d")" | head -1)

echo
echo "Running tests against: $swiftc_version"
echo "Using Xcode found at path: $xcode_path"

num_crashed=0
num_tests=0

color_red="\e[01;31m"
color_green="\e[32m"
color_stop="\e[00m"

columns=$(tput cols)

#
# Test results should be logged as this (+---...---+ is the width of terminal):
# +------------------------------------------------------------+
#   ✘  <test name>                                (88591ef1ad)
#

name_size=$((columns-20))
format_fail="  %b  %-$name_size.${name_size}b (%10.10b)\n"
format_pass="  %b  %-$name_size.${name_size}b\n"

do_test() {
  path="$1"
  
  if [ -f $path ]; then
    num_tests=$((num_tests + 1))
    test_name=$(basename -s ".swift" "$path")
    test_name=${test_name//-/ }
    
    output=$(xcrun swiftc $path 2>&1)
    
    md5=$(echo $output | md5)
    
    $(echo $output | egrep -q "error: unable to execute command: Segmentation fault:")
    if [ $? == 0 ]; then
      num_crashed=$((num_crashed + 1))
      printf "$format_fail" "${color_red}✘${color_stop}" "$test_name" "$md5"
    else
      printf "$format_pass" "${color_green}✓${color_stop}" "$test_name" 
    fi
  fi
}

run_tests() {
  header="$1"
  path="$2"

  echo
  echo "== $header =="
  echo
  
  for test_path in $path/*.swift
  do
    do_test $test_path
  done

}

show_results() {
  if [ $num_crashed == 0 ]; then
    echo "** CRASH-TESTS PASSED **"
    echo
  else
    echo "** CRASH-TESTS FAILED: $num_crashed of $num_tests crashed **"
    echo
  fi
}

run_tests "Currently Known Crashes" "./crashes"
run_tests "Crashes Fixed in Previous Release" "./fixed"

show_results

{'fraction_non_alphanumeric': 0.18193465727098015, 'fraction_numerical': 0.019218449711723255, 'mean_word_length': 2.9135338345864663, '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': '6548418', 'n_tokens_mistral': 1236, 'n_tokens_neox': 1192, 'n_words': 286}