<commit_before>#!/bin/bash

if [ "$#" -eq 0 ]; then
  echo
  echo '  How to use test_wrapper.sh'
  echo
  echo '  1. running specific tests in one folder'
  echo "     $ cd test/app_model"
  echo '     $ ./run.sh <ID*>'
  echo
  echo '  2. running all the tests in one folder'
  echo "     $ cd test/app_model"
  echo '     $ ./run.sh'
  echo
  echo '  3. running all the tests in all the folders'
  echo "     $ cd test"
  echo '     $ ./run.sh'
  echo
  exit
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# collect trailing arguments to forward to tests

while (( "$#" )); do
  if [[ $1 == *.rb ]]; then
    testFiles+=($1)
    shift
  else
    args=($*)
    break
  fi
done

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# check if tests alter the current git user!
# I don't want any confusion between the git repo created
# in a test (for an animal) and the main git repo of cyber-dojo!

gitUserNameBefore=`git config user.name`

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# set env-vars if not set

HOME_DIR="$( cd "$( dirname "${0}" )/.." && pwd )"

VAR=${CYBER_DOJO_STORER_CLASS:-HostDiskStorer}
export CYBER_DOJO_STORER_CLASS=${VAR}

export CYBER_DOJO_LOG_CLASS=MemoryLog

VAR=${CYBER_DOJO_RUNNER_TIMEOUT:=10}
export CYBER_DOJO_RUNNER_TIMEOUT=${VAR}

VAR=${CYBER_DOJO_RUNNER_SUDO:-''}
export CYBER_DOJO_RUNNER_SUDO=${VAR}

# ensure empty dirs exist
mkdir -p ${HOME_DIR}/caches

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run-the-tests!

rm -rf ../../coverage/.resultset.json
mkdir -p coverage
test_log='coverage/test.log'
# ensure Mocks saving to Dir.tmpdir have clean start
rm -rf ${TMPDIR}/cyber-dojo-*
ruby -e "%w( ${testFiles[*]} ).map{ |file| './'+file }.each { |file| require file }" -- ${args[*]} 2>&1 | tee ${test_log}
cp -R ../../coverage .
#pwd                       # eg  .../cyber-dojo/test/app_lib
cwd=${PWD##*/}             # eg  app_lib
module=${cwd/_//}          # eg  app/lib
ruby ../print_coverage_percent.rb index.html $module | tee -a ${test_log}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gitUserNameAfter=`git config user.name`

if [ "$gitUserNameBefore" != "$gitUserNameAfter" ]; then
  echo --------------------------------------
  echo META TEST FAILURE!
  echo --------------------------------------
  echo Before
  echo '  $ git config user.name'
  echo "  $ $gitUserNameBefore"
  echo
  echo After
  echo '  $ git config user.name'
  echo "  $ $gitUserNameAfter"
  echo --------------------------------------
fi


<commit_msg>stripped more from test_wrapper.sh now not supporting local testing<commit_after>#!/bin/bash

if [ ! -f /.dockerenv ]; then
  echo 'FAILED: test_wrapper.sh is being executed outside of docker-container.'
  exit 1
fi

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# collect trailing arguments to forward to tests

while (( "$#" )); do
  if [[ $1 == *.rb ]]; then
    testFiles+=($1)
    shift
  else
    args=($*)
    break
  fi
done

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# ensure caches dir exists
HOME_DIR="$( cd "$( dirname "${0}" )/.." && pwd )"
mkdir -p ${HOME_DIR}/caches

export CYBER_DOJO_LOG_CLASS=MemoryLog

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# run-the-tests!

rm -rf ../../coverage/.resultset.json
mkdir -p coverage
test_log='coverage/test.log'
# ensure Mocks saving to Dir.tmpdir have clean start
rm -rf ${TMPDIR}/cyber-dojo-*
ruby -e "%w( ${testFiles[*]} ).map{ |file| './'+file }.each { |file| require file }" -- ${args[*]} 2>&1 | tee ${test_log}
cp -R ../../coverage .
#pwd                       # eg  .../cyber-dojo/test/app_lib
cwd=${PWD##*/}             # eg  app_lib
module=${cwd/_//}          # eg  app/lib
ruby ../print_coverage_percent.rb index.html $module | tee -a ${test_log}



{'fraction_non_alphanumeric': 0.23078906652913872, 'fraction_numerical': 0.004383702939659618, 'mean_word_length': 1.6156439649359406, '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': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4079817', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1442, 'n_words': 339}