<commit_before>#!/bin/bash

for t in test/*.do; do
	echo "Running $t"

  INPUT_FILE=${t%.*}.in
  OUTPUT=""
  if [ -e $INPUT_FILE ]; then
    # echo "using '$INPUT_FILE'"
    OUTPUT=`./mrdo --optimize=true --dump_module=false $t < $INPUT_FILE 2> /dev/null`
  else
    OUTPUT=`./mrdo --optimize=true --dump_module=false $t 2> /dev/null`
  fi

	if [ $? -ne 0 ]; then
    echo "non-zero error code"
		break
  fi

  if [ "$OUTPUT" != "" ]; then
    GOLD_FILE=${t%.*}.out
    DIFF=""
    if [ -e $GOLD_FILE ]; then
      # echo "checking '$OUTPUT' against '`cat $GOLD_FILE`' (from $GOLD_FILE)"
      DIFF=`diff <(echo "$OUTPUT") $GOLD_FILE`
      if [ "$DIFF" != "" ]; then
        echo "expected `cat ${t%.*}.out`, got $OUTPUT"
        break
      fi
    else
      echo "missing expected gold file $GOLD_FILE"
      break
    fi
  fi
done
<commit_msg>Use exec and add command line processing to run_tests<commit_after>#!/bin/bash

exec 6>&2         # save stderr to fd6
exec 2> /dev/null # redirect stderr to null

while getopts ":dh" opt; do
  case $opt in
    d)
      exec 2>&6 6>&-  # restore stderr and close fd6
      ;;
    h)
      echo "Usage: $0 [-d]"
      echo "  -d: show debug output from mrdo"
      exit 0
      ;;
    \?)
      echo "unknown option: -$OPTARG"
      exec 2>&6 6>&-  # restore stderr and close fd6
      exit 1
      ;;
  esac
done

for t in test/*.do; do
	echo "Running $t"

  INPUT_FILE=${t%.*}.in
  if [ -e $INPUT_FILE ]; then
    # echo "using '$INPUT_FILE'"
    exec < $INPUT_FILE
  fi
  OUTPUT=`./mrdo --optimize=true --dump_module=false $t`

	if [ $? -ne 0 ]; then
    echo "non-zero error code"
		break
  fi

  if [ "$OUTPUT" != "" ]; then
    GOLD_FILE=${t%.*}.out
    DIFF=""
    if [ -e $GOLD_FILE ]; then
      # echo "checking '$OUTPUT' against '`cat $GOLD_FILE`' (from $GOLD_FILE)"
      DIFF=`diff <(echo "$OUTPUT") $GOLD_FILE`
      if [ "$DIFF" != "" ]; then
        echo "expected `cat ${t%.*}.out`, got $OUTPUT"
        break
      fi
    else
      echo "missing expected gold file $GOLD_FILE"
      break
    fi
  fi
done

{'fraction_non_alphanumeric': 0.16224046354418156, 'fraction_numerical': 0.009174311926605505, 'mean_word_length': 2.2274143302180685, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 11, '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': '1297476', 'n_tokens_mistral': 798, 'n_tokens_neox': 756, 'n_words': 231}