<commit_before>#!/bin/bash

set -e

OPTIND=1
TESTED_CLIENT=0
TESTED_SERVER=0
TESTS_FAILED=0
SHOULD_REPORT=0

read -d '' HELP_STRING <<'EOF'
  "This script is a testing and coverage reporting utility"
  "Options:"
    "-h:    Display this help menu"
    "-c:    Run client tests"
    "-s:    Run server tests"
    "-r:    Submit coverage report to a coverage analysis tool"

  example:
    ./run_tests.sh -h
    ./run_tests.sh -c
    ./run_tests.sh -s
    ./run_tests.sh -r

EOF


while getopts "hcsrR:" opt; do
  case "$opt" in
  h)
    echo "$HELP_STRING"
    exit 0
    ;;
  c)
    TESTED_CLIENT=1
    cd client
    npm test
    if [ $? -gt 0 ]; then
      TESTS_FAILED=1
    fi
    cd ..
    ;;
  s)
    TESTED_SERVER=1
    coverage run --source libraryapp manage.py test
    if [ $? -gt 0 ]; then
      TESTS_FAILED=1
    fi
    ;;
  r)  SHOULD_REPORT=1
    ;;
  esac
done

shift $((OPTIND-1))

[ "$1" = "--" ] && shift

if [ $TESTED_CLIENT -eq 0 -a $TESTED_SERVER -eq 0 ]; then
  echo "$HELP_STRING"
  exit 1
fi

if [ $SHOULD_REPORT -eq 1 ]; then
  if [ $TESTED_CLIENT -eq 1 ]; then
    cd client
    npm run report
    cd ..
  fi

  if [ $TESTED_SERVER -eq 1 ]; then
    echo "\nPlease configure a coverage analysis solution for the server"
  fi
fi

if [ $TESTS_FAILED -eq 1 ]; then
  echo "\n\n\033[31mSome tests failed.\033[0m\n"; exit 1
else
  echo "\n\n\033[32mAll tests passed!\033[0m\n"; exit 0
fi<commit_msg>add test script pass locally for server<commit_after>#!/bin/bash

OPTIND=1
TESTED_CLIENT=0
TESTED_SERVER=0
TESTS_FAILED=0
SHOULD_REPORT=0

read -d '' HELP_STRING <<'EOF'
  "This script is a testing and coverage reporting utility"
  "Options:"
    "-h:    Display this help menu"
    "-c:    Run client tests"
    "-s:    Run server tests"
    "-r:    Submit coverage report to a coverage analysis tool"

  example:
    ./run_tests.sh -h
    ./run_tests.sh -c
    ./run_tests.sh -s
    ./run_tests.sh -r

EOF

set -e

function export_env() {
    export SECRET_KEY=django-react-library-app
    export DB_USER=postgres
    export DB_PASS=<PASSWORD>
    export DB_SERVICE=postgres
    export DB_PORT=5432
    export DB_NAME=postgres
}

while getopts "hcsrR:" opt; do
  case "$opt" in
  h)
    echo "$HELP_STRING"
    exit 0
    ;;
  c)
    TESTED_CLIENT=1
    cd client
    npm test
    if [ $? -gt 0 ]; then
      TESTS_FAILED=1
    fi
    cd ..
    ;;
  s)
    TESTED_SERVER=1
    export_env
    coverage run --source libraryapp manage.py test
    if [ $? -gt 0 ]; then
      TESTS_FAILED=1
    fi
    ;;
  r)  SHOULD_REPORT=1
    ;;
  esac
done

shift $((OPTIND-1))

[ "$1" = "--" ] && shift

if [ $TESTED_CLIENT -eq 0 -a $TESTED_SERVER -eq 0 ]; then
  echo "$HELP_STRING"
  exit 1
fi

if [ $SHOULD_REPORT -eq 1 ]; then
  if [ $TESTED_CLIENT -eq 1 ]; then
    cd client
    npm run report
    cd ..
  fi

  if [ $TESTED_SERVER -eq 1 ]; then
    echo "\nPlease configure a coverage analysis solution for the server"
  fi
fi

if [ $TESTS_FAILED -eq 1 ]; then
  # https://github.com/ryanoasis/public-bash-scripts/blob/master/unix-color-codes.sh
  echo "\n\n\033[31mSome tests failed.\033[0m\n"; exit 1
else
  echo "\n\n\033[32mAll tests passed!\033[0m\n"; exit 0
fi
{'fraction_non_alphanumeric': 0.1213073538654934, 'fraction_numerical': 0.02765556253928347, 'mean_word_length': 2.378980891719745, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 4, 'https://': 1, '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': '5968984', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1226, 'n_words': 359}