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

# From https://github.com/codecov/example-go#caveat-multiple-files
set -e
mkdir -p profiles/

CODECLIMATE=0
if curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 >./cc-test-reporter; then
	CODECLIMATE=1
	chmod +x ./cc-test-reporter
	./cc-test-reporter before-build
fi

# Run tests with coverage for all barista packages
go list ./... \
| grep -v barista/samples \
| tac \
| xargs -n1 -P4 -IPKG sh -c \
'go test -coverprofile=profiles/$(echo "PKG" | sed "s|/|_|g").out -race -covermode=atomic "PKG"'

# Debug log tests need the build tag, otherwise the nop versions will be used.
go test -tags debuglog -coverprofile=profiles/logging_real.out -race -covermode=atomic ./logging

# Merge all code coverage reports.
cat profiles/*.out > coverage.txt
rm -rf profiles/

# Run tests only for samples.
# This is just to make sure that all samples compile.
go test ./samples/...

# Codecov.io wants coverage.txt, but CodeClimate wants c.out.
if [ $CODECLIMATE -eq 1 ]; then
	echo "mode: count" > c.out
	grep -h -v "^mode:" coverage.txt >> c.out<commit_msg>Only update CodeClimate if test reporter id is available<commit_after>#!/usr/bin/env bash

CC_TEST_REPORTER_LOC="https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64"

set -e
mkdir -p profiles/

CODECLIMATE=0
if test -n "$CC_TEST_REPORTER_ID" && curl -LSs "$CC_TEST_REPORTER_LOC" >./cc-test-reporter; then
	CODECLIMATE=1
	chmod +x ./cc-test-reporter
	./cc-test-reporter before-build
fi

# Run tests with coverage for all barista packages
go list ./... \
| grep -v barista/samples \
| tac \
| xargs -n1 -P4 -IPKG sh -c \
'go test -coverprofile=profiles/$(echo "PKG" | sed "s|/|_|g").out -race -covermode=atomic "PKG"'

# Debug log tests need the build tag, otherwise the nop versions will be used.
go test -tags debuglog -coverprofile=profiles/logging_real.out -race -covermode=atomic ./logging

# Merge all code coverage reports.
cat profiles/*.out > coverage.txt
rm -rf profiles/

# Run tests only for samples.
# This is just to make sure that all samples compile.
go test ./samples/...

# Codecov.io wants coverage.txt, but CodeClimate wants c.out.
if [ $CODECLIMATE -eq 1 ]; then
	echo "mode: count" > c.out
	grep -h -v "^mode:" coverage.txt >> c.out
{'fraction_non_alphanumeric': 0.13336229365768898, 'fraction_numerical': 0.006081668114682885, 'mean_word_length': 3.5603960396039604, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '553334', 'n_tokens_mistral': 834, 'n_tokens_neox': 807, 'n_words': 259}