#!/usr/bin/env bash
set -x
cat >test.cc <<'EOF'
#include <stdexcept>
int main (int narg, const char* argv[]) {
	throw std::runtime_error("Test error");
}
EOF

g++ test.cc

if [[ -x a.exe ]]; then
	./a.exe
	rc="$?"
elif [[ -x a.out ]]; then
	./a.out
	rc="$?"
else
	echo "Couldn't find compiled file!"
	exit 2
fi

if (( rc == 0 )); then
	echo 'Unexpected zero return code from execution'
	exit 1
else
	echo 'Expected non-zero return code received: '"$rc"
	exit 0
fi
