#!/usr/bin/env -S bash -e

# XXX: sometimes this is flaky in github :/
# grep: /tmp/tmp.Un5/environ: No such file or directory
# cat: /tmp/tmp.Un5/environ: No such file or directory
# Error: Could not match '' in '/tmp/tmp.Un5/environ' to '123,,:123,321,:true,false:123'.
exit 0	# XXX: disable for now

. "$(dirname "$0")/../util.sh"

set -o errexit
set -o pipefail

# these values represent environment variable values below or defaults set in test/shell/env0.mcl
regex="123,,:123,321,:true,false:123"

tmpdir="$($mktemp --tmpdir -d tmp.XXX)"
if [[ ! "$tmpdir" =~ "/tmp" ]]; then
	echo "unexpected tmpdir in: ${tmpdir}"
	exit 99
fi

env TMPDIR="${tmpdir}" TEST=123 EMPTY="" $TIMEOUT "$MGMT" run --tmp-prefix --converger-timeout=5 --converged-exit lang env0.mcl
e=$?

egrep "$regex" "$tmpdir/environ" || fail_test "Could not match '$(cat "$tmpdir/environ")' in '$tmpdir/environ' to '$regex'."

if [ "$tmpdir" = "" ]; then
	echo "BUG, tried to delete empty string path"
	exit 99
fi
# cleanup if everything went well
rm -r "$tmpdir"

exit $e
