summaryrefslogtreecommitdiff
path: root/utils/gen-hash-tests.bash
blob: 9999af0c991e4aa8166b5e750c8450e86e23326f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
test_string='The quick brown fox jumps over the lazy dog'

if [[ ${#} -lt 1 ]]; then
    echo "Usage: ${0} <hashlib-name> [<program-to-use>]"
    exit 1
fi

algo=${1}
algo_sum=${2:-${algo}sum}

empty=$(printf '' | ${algo_sum} | cut -d' ' -f1)
str=$(printf '%s' "${test_string}" | ${algo_sum} | cut -d' ' -f1)

cat <<_EOF_

    def test_${algo}(self):
        try:
            self.assertEqual(hash_bytes(TEST_STRING, '${algo}'),
                    '${str}')
        except UnsupportedHash:
            raise unittest.SkipTest('hash not supported')

    def test_${algo}_empty(self):
        try:
            self.assertEqual(hash_bytes(b'', '${algo}'),
                    '${empty}')
        except UnsupportedHash:
            raise unittest.SkipTest('hash not supported')
_EOF_