md5sum.test 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. [ -f testing.sh ] && . testing.sh
  3. #testing "name" "command" "result" "infile" "stdin"
  4. # These tests are from RFC 1321 appendix 5, reshuffled slightly to test
  5. # varying argument numbers
  6. testing "''" "md5sum" "d41d8cd98f00b204e9800998ecf8427e -\n" "" ""
  7. testing "infile" "md5sum input" \
  8. "0cc175b9c0f1b6a831c399e269772661 input\n" "a" ""
  9. testing "two files" "md5sum - input" \
  10. "900150983cd24fb0d6963f7d28e17f72 -\nf96b697d7cb7938d525a2f31aaf161d0 input\n" \
  11. "message digest" "abc"
  12. testing "4" "md5sum" "c3fcd3d76192e4007dfb496cca67e13b -\n" \
  13. "" "abcdefghijklmnopqrstuvwxyz"
  14. testing "5" "md5sum" "d174ab98d277d9f5a5611c2c9f419d9f -\n" \
  15. "" "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
  16. testing "6" "md5sum" "57edf4a22be3c955ac49da2e2107b67a -\n" \
  17. "" "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
  18. echo -n "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" > "te st"
  19. touch empty
  20. testing "-c spaces" "md5sum -c input || echo ok" \
  21. "te st: OK\nempty: FAILED\n-: OK\nok\n" \
  22. "$(printf "d174ab98d277d9f5a5611c2c9f419d9f te st\n12345678901234567890123456789012 empty\nd41d8cd98f00b204e9800998ecf8427e -\n")" ""
  23. rm "te st" empty
  24. testing "-c nolines" "md5sum -c input 2>/dev/null || echo ok" "ok\n" "" ""
  25. touch empty
  26. echo "d41d8cd98f00b204e9800998ecf8427e empty" > list
  27. echo "041d8cd98f00b204e9800998ecf8427e empty" > badlist
  28. testing "--status okay" "md5sum --status -c list ; echo \$?" "0\n" "" ""
  29. testing "--status fail" "md5sum --status -c badlist ; echo \$?" "1\n" "" ""
  30. testing "-c multiple" "md5sum -c list badlist --status ; echo \$?" "1\n" "" ""
  31. rm empty list badlist