Skip to content

Instantly share code, notes, and snippets.

@jonasnick
Last active February 9, 2023 16:38
Show Gist options
  • Save jonasnick/5e37248e3fa5911cd41e1da2f5f4e395 to your computer and use it in GitHub Desktop.
Save jonasnick/5e37248e3fa5911cd41e1da2f5f4e395 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -x
assert_fail() {
exit=$1
if [[ "$exit" == 0 ]]; then
echo "tests unexpectedly succeeded"
exit 1
fi
}
assert_succ() {
exit=$1
output=$2
runs=$3
if [[ "$exit" != 0 ]]; then
echo "tests unexpectedly failed"
exit 1
fi
if [[ "$output" != *"test count = $runs"* ]]; then
echo "test count wrong, should've been $runs"
exit 1
fi
}
output=$(./tests)
assert_succ $? "$output" 64
output=$(./tests 1)
assert_succ $? "$output" 1
output=$(SECP256K1_TEST_ITERS=2 ./tests)
assert_succ $? "$output" 2
./tests a
assert_fail $?
SECP256K1_TEST_ITERS=a ./tests
assert_fail $?
SECP256K1_TEST_ITERS=2 ./tests 4
assert_fail $?
output=$(./tests 3 ecdsa)
assert_succ $? "$output" 3
output=$(./tests ecdsa)
assert_succ $? "$output" 64
output=$(./tests 1 ecdsa schnorrsig)
assert_succ $? "$output" 1
./tests 3 foo
assert_fail $?
./tests foo
assert_fail $?
./tests scalar recovery
# only fails if recovery is not enabled
assert_fail $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment