changeset 35476:c1f7037c2ded

tests: teach `f` to handle sha256 checksums
author Matt Harbison <matt_harbison@yahoo.com>
date Wed, 20 Dec 2017 20:46:33 -0500
parents ea4d27aac557
children 02f54a1ec9eb
files tests/f tests/test-tools.t
diffstat 2 files changed, 10 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/tests/f	Wed Dec 20 20:41:12 2017 -0500
+++ b/tests/f	Wed Dec 20 20:46:33 2017 -0500
@@ -59,7 +59,7 @@
         if isfile:
             if opts.type:
                 facts.append('file')
-            if opts.hexdump or opts.dump or opts.md5 or opts.sha1:
+            if any((opts.hexdump, opts.dump, opts.md5, opts.sha1, opts.sha256)):
                 content = open(f, 'rb').read()
         elif islink:
             if opts.type:
@@ -95,6 +95,9 @@
         if opts.sha1 and content is not None:
             h = hashlib.sha1(content)
             facts.append('sha1=%s' % h.hexdigest()[:opts.bytes])
+        if opts.sha256 and content is not None:
+            h = hashlib.sha256(content)
+            facts.append('sha256=%s' % h.hexdigest()[:opts.bytes])
         if isstdin:
             outfile.write(b', '.join(facts) + b'\n')
         elif facts:
@@ -150,6 +153,8 @@
                       help="recurse into directories")
     parser.add_option("-S", "--sha1", action="store_true",
                       help="show sha1 hash of the content")
+    parser.add_option("", "--sha256", action="store_true",
+                      help="show sha256 hash of the content")
     parser.add_option("-M", "--md5", action="store_true",
                       help="show md5 hash of the content")
     parser.add_option("-D", "--dump", action="store_true",
--- a/tests/test-tools.t	Wed Dec 20 20:41:12 2017 -0500
+++ b/tests/test-tools.t	Wed Dec 20 20:46:33 2017 -0500
@@ -13,6 +13,7 @@
                           check if file is newer (or same)
     -r, --recurse         recurse into directories
     -S, --sha1            show sha1 hash of the content
+    --sha256              show sha256 hash of the content
     -M, --md5             show md5 hash of the content
     -D, --dump            dump file content
     -H, --hexdump         hexdump file content
@@ -41,6 +42,9 @@
   $ f --sha1 foo
   foo: sha1=f1d2d2f924e986ac86fdf7b36c94bcdf32beec15
 
+  $ f --sha256 foo
+  foo: sha256=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
+
 #if symlink
   $ f foo --mode
   foo: mode=644