<commit_before>#!/bin/bash
#
# This runs the testsuite. Arguments are passed to prove.
#

export ENVIRONMENT="testsuite"
export COLLECT_COVERAGE=1

startdir="$(dirname "$0")"

die() {
	echo "$@" >&2
	echo "Aborting..." >&2
	exit 1
}


cd "$startdir"

# some sanity checks
test -d system || die 'Required dir not found.'
test -d application || die 'Required dir not found.'
test -f run-tests.sh || die 'Required file not found.'
grep -qF 'getenv("ENVIRONMENT")' application/config/database.php || die "database config doesn't honor ENVIRONMENT."

# prepare
trap cleanup EXIT INT
cleanup() {
	pkill -P $$
	php index.php tools drop_all_tables
}

mkdir -p test-coverage-data

#  run tests
phpdbg -qrr index.php tools drop_all_tables || exit 1
phpdbg -qrr index.php tools update_database || exit 1

prove --ext .php --state=failed,save --timer --comments --exec 'phpdbg -qrr index.php tools test' --recurse "${@:-application/test/tests/}" || exit 1

if (($COLLECT_COVERAGE)); then
	php index.php tools generate_coverage_report
	rm -rf test-coverage-data
fi

<commit_msg>run-tests.sh: Only use phpdbg when coverage information is gathered<commit_after>#!/bin/bash
#
# This runs the testsuite. Arguments are passed to prove.
#

export ENVIRONMENT="testsuite"
export COLLECT_COVERAGE=1

startdir="$(dirname "$0")"

die() {
	echo "$@" >&2
	echo "Aborting..." >&2
	exit 1
}


cd "$startdir"

# some sanity checks
test -d system || die 'Required dir not found.'
test -d application || die 'Required dir not found.'
test -f run-tests.sh || die 'Required file not found.'
grep -qF 'getenv("ENVIRONMENT")' application/config/database.php || die "database config doesn't honor ENVIRONMENT."

# prepare
trap cleanup EXIT INT
cleanup() {
	pkill -P $$
	php index.php tools drop_all_tables
}

mkdir -p test-coverage-data

php=(php)
if ((COLLECT_COVERAGE)); then
	php=(phpdbg -qrr)
fi

#  run tests
"${php[@]}" index.php tools drop_all_tables || exit 1
"${php[@]}" index.php tools update_database || exit 1

prove --ext .php --state=failed,save --timer --comments --exec "${php[*]} index.php tools test" --recurse "${@:-application/test/tests/}" || exit 1

if (($COLLECT_COVERAGE)); then
	php index.php tools generate_coverage_report
	rm -rf test-coverage-data
fi


{'fraction_non_alphanumeric': 0.1443207126948775, 'fraction_numerical': 0.0071269487750556795, 'mean_word_length': 4.11617312072893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5059385', 'n_tokens_mistral': 798, 'n_tokens_neox': 766, 'n_words': 254}