<commit_before>#!/usr/bin/env bash

source "$(dirname -- "$0")/setup.sh"

function run_tests {
	go test "$1" -covermode=count -coverprofile=tmp.cov
	test_result=$?
	# Can't do race tests at the same time as coverage as it'll report
	# lots of false positives
	go test -race "$1"
	let test_result=$test_result+$?
	echo -ne "${YELLOW}=>${RESET} test $1 - "
	if [ "$test_result" == "0" ]; then
		echo -e "${GREEN}SUCCEEDED${RESET}"
	else
		echo -e "${RED}FAILED${RESET}"
	fi
}

function test_all {
	let a=0
	for pkg in $(go list "./$1/..." | grep -v /vendor/); do
		run_tests "$pkg"
		let a=$a+$test_result
		if [ "$test_result" == "0" ]; then
			sed 1d tmp.cov >> coverage.cov
		fi
		rm tmp.cov
	done
	test_result=$a
}

echo "mode: count" > coverage.cov

ret=0

fold_start "test" "run tests"
test_all "$1"
let ret=$ret+$test_result
fold_end "test"

if [ "$ret" == "0" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then
	fold_start "coveralls" "post to coveralls"
	"$(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls" -coverprofile=coverage.cov -service=travis-ci
	fold_end "coveralls"
fi

rm coverage.cov

exit $ret<commit_msg>Use an environment variable to report coverage<commit_after>#!/usr/bin/env bash

source "$(dirname -- "$0")/setup.sh"

function run_tests {
	go test "$1" -covermode=count -coverprofile=tmp.cov
	test_result=$?
	# Can't do race tests at the same time as coverage as it'll report
	# lots of false positives
	go test -race "$1"
	let test_result=$test_result+$?
	echo -ne "${YELLOW}=>${RESET} test $1 - "
	if [ "$test_result" == "0" ]; then
		echo -e "${GREEN}SUCCEEDED${RESET}"
	else
		echo -e "${RED}FAILED${RESET}"
	fi
}

function test_all {
	let a=0
	for pkg in $(go list "./$1/..." | grep -v /vendor/); do
		run_tests "$pkg"
		let a=$a+$test_result
		if [ "$test_result" == "0" ]; then
			sed 1d tmp.cov >> coverage.cov
		fi
		rm tmp.cov
	done
	test_result=$a
}

echo "mode: count" > coverage.cov

ret=0

fold_start "test" "run tests"
test_all "$1"
let ret=$ret+$test_result
fold_end "test"

if [ "$ret" == "0" ] && [ "$REPORT_COVERAGE" == "true" ]; then
	fold_start "coveralls" "post to coveralls"
	"$(go env GOPATH | awk 'BEGIN{FS=":"} {print $1}')/bin/goveralls" -coverprofile=coverage.cov -service=travis-ci
	fold_end "coveralls"
fi

rm coverage.cov

exit $ret
{'fraction_non_alphanumeric': 0.17777777777777778, 'fraction_numerical': 0.011328976034858388, 'mean_word_length': 3.9376344086021504, 'pattern_counts': {'":': 2, '<': 3, '<?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': '7437363', 'n_tokens_mistral': 942, 'n_tokens_neox': 893, 'n_words': 257}