<commit_before>#!/bin/bash
#
# Test script for libdeflate's gzip and gunzip programs.
#
# To run, you must set GZIP and GUNZIP in the environment to the absolute paths
# to the gzip and gunzip programs to test.  All tests should pass regardless of
# whether the GNU versions or the libdeflate versions, or a combination, of
# these programs are used.
#
# The environmental variable TESTDATA must also be set to a file containing
# test data.
#

set -eu -o pipefail

export -n GZIP GUNZIP TESTDATA

TMPDIR="$(mktemp -d)"
CURRENT_TEST=

cleanup() {
	if [ -n "$CURRENT_TEST" ]; then
		echo "TEST FAILED: \"$CURRENT_TEST\""
	fi
	rm -rf -- "$TMPDIR"
}

trap cleanup EXIT

TESTDATA="$(readlink -f "$TESTDATA")"
cd "$TMPDIR"

begin_test() {
	CURRENT_TEST="$1"
	rm -rf -- "${TMPDIR:?}"/*
	cp "$TESTDATA" file
}

gzip() {
	$GZIP "$@"
}

gunzip() {
	$GUNZIP "$@"
}

assert_status() {
	local expected_status="$1"
	local expected_msg="$2"
	shift 2
	(
		set +e
		{ eval "$*" > /dev/null; } 2>&1
		local actual_status=$?
		if [ "$actual_status" != "$expected_status" ]; then
			echo 1>&2 "Command '$*' exited with status" \
				"$actual_status but expected status" \
				"$expected_status"
			exit 1<commit_msg>gzip_tests: ensure the test file is writable<commit_after>#!/bin/bash
#
# Test script for libdeflate's gzip and gunzip programs.
#
# To run, you must set GZIP and GUNZIP in the environment to the absolute paths
# to the gzip and gunzip programs to test.  All tests should pass regardless of
# whether the GNU versions or the libdeflate versions, or a combination, of
# these programs are used.
#
# The environmental variable TESTDATA must also be set to a file containing
# test data.
#

set -eu -o pipefail

export -n GZIP GUNZIP TESTDATA

TMPDIR="$(mktemp -d)"
CURRENT_TEST=

cleanup() {
	if [ -n "$CURRENT_TEST" ]; then
		echo "TEST FAILED: \"$CURRENT_TEST\""
	fi
	rm -rf -- "$TMPDIR"
}

trap cleanup EXIT

TESTDATA="$(readlink -f "$TESTDATA")"
cd "$TMPDIR"

begin_test() {
	CURRENT_TEST="$1"
	rm -rf -- "${TMPDIR:?}"/*
	cp "$TESTDATA" file
	chmod +w file
}

gzip() {
	$GZIP "$@"
}

gunzip() {
	$GUNZIP "$@"
}

assert_status() {
	local expected_status="$1"
	local expected_msg="$2"
	shift 2
	(
		set +e
		{ eval "$*" > /dev/null; } 2>&1
		local actual_status=$?
		if [ "$actual_status" != "$expected_status" ]; then
			echo 1>&2 "Command '$*' exited with status" \
				"$actual_status but expected status" \
				"$expected_status"
			exit 1
{'fraction_non_alphanumeric': 0.14098360655737704, 'fraction_numerical': 0.007377049180327869, 'mean_word_length': 3.7398058252427187, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4972522', 'n_tokens_mistral': 933, 'n_tokens_neox': 884, 'n_words': 296}