#!/bin/sh
# Test reproducible sha1-based password generation

set -e

seed_file=$(mktemp)
trap 'rm -f "$seed_file"' EXIT

printf 'test seed data\n' > "$seed_file"

# Same input and seed should produce the same password
output1=$(pwgen -1 -H "$seed_file" 20)
output2=$(pwgen -1 -H "$seed_file" 20)

if [ "$output1" != "$output2" ]; then
    echo "sha1 reproducibility test failed" >&2
    exit 1
fi

# Different seed should produce different password
# The `#` syntax appends the specified string to the seed,
# creating a different seed for testing.
output3=$(pwgen -1 -H "${seed_file}#different" 20)
if [ "$output1" = "$output3" ]; then
    echo "sha1 different seed test failed" >&2
    exit 1
fi

echo "sha1 tests passed"
