huangcm
2024-12-18 9d29be7f7249789d6ffd0440067187a9f040c2cd
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
 
[ -f testing.sh ] && . testing.sh
 
#testing "name" "command" "result" "infile" "stdin"
 
# These tests are based on RFC3174 which were based on FIPS PUB 180-1
 
testing "TEST1" \
        "sha1sum" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  -\n" \
        "" "abc"
 
testing "TEST2" \
        "sha1sum" \
        "84983e441c3bd26ebaae4aa1f95129e5e54670f1  -\n" \
        "" "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
 
testing "TEST3" \
        'dd if=/dev/zero bs=1000 count=1000 2>/dev/null | tr \\0 a | sha1sum' \
        "34aa973cd4c4daa4f61eeb2bdbad27316534016f  -\n" \
        "" ""
 
testing "TEST4" \
        'for i in `seq 1 10`; do echo -n 0123456701234567012345670123456701234567012345670123456701234567 ; done | sha1sum' \
        "dea356a2cddd90c7a7ecedc5ebb563934f460452  -\n" \
        "" ""
 
echo -n "abc" > file1
echo -n "def" > file2
testing "sha1sum" \
        "sha1sum" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  -\n" \
        "" "abc"
 
testing "-" \
        "sha1sum -" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  -\n" \
        "" "abc"
 
testing "file" \
        "sha1sum file1" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  file1\n" \
        "" ""
 
testing "file1 file2" \
        "sha1sum file1 file2" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  file1\n589c22335a381f122d129225f5c0ba3056ed5811  file2\n" \
        "" ""
 
testing "file1 file2 -" \
        "sha1sum file1 file2 -" \
        "a9993e364706816aba3e25717850c26c9cd0d89d  file1\n589c22335a381f122d129225f5c0ba3056ed5811  file2\na9993e364706816aba3e25717850c26c9cd0d89d  -\n" \
        "" "abc"
 
rm -f file1 file2