From f9c7080aa3acafc6fb15fa1b304670acfe114704 Mon Sep 17 00:00:00 2001
From: Ludovic Courtès <ludo@gnu.org>
Date: Fri, 1 Jun 2012 23:29:55 +0200
Subject: Fix `bytevector->nix-base32-string'.

* guix/utils.scm (bytevector-quintet-ref-right,
  bytevector-quintet-fold): New procedures.
  (bytevector-quintet-fold-right): Add `quintet-fold' parameter; use it
  instead of `bytevector-quintet-fold'.
  (bytevector->base32-string): Pass BYTEVECTOR-QUINTET-FOLD as the
  first parameter.
  (bytevector->nix-base32-string): Pass BYTEVECTOR-QUINTET-FOLD-RIGHT as
  the first parameter.

* tests/utils.scm ("sha256 & bytevector->nix-base32-string"): New test.
---
 tests/utils.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

(limited to 'tests/utils.scm')

diff --git a/tests/utils.scm b/tests/utils.scm
index 57705e6f48..eade84b5d4 100644
--- a/tests/utils.scm
+++ b/tests/utils.scm
@@ -22,7 +22,10 @@ (define-module (test-utils)
   #:use-module (srfi srfi-1)
   #:use-module (srfi srfi-26)
   #:use-module (srfi srfi-64)
-  #:use-module (rnrs bytevectors))
+  #:use-module (rnrs bytevectors)
+  #:use-module (rnrs io ports)
+  #:use-module (ice-9 rdelim)
+  #:use-module (ice-9 popen))
 
 (test-begin "utils")
 
@@ -43,6 +46,22 @@ (define-module (test-utils)
           "mzxw6ytb"
           "mzxw6ytboi")))
 
+;; The following tests requires `nix-hash' in $PATH.
+(test-skip (if (false-if-exception (system* "nix-hash" "--version"))
+               0
+               1))
+
+(test-assert "sha256 & bytevector->nix-base32-string"
+  (let ((file (search-path %load-path "tests/test.drv")))
+    (equal? (bytevector->nix-base32-string
+             (sha256 (call-with-input-file file get-bytevector-all)))
+            (let* ((c (format #f "nix-hash --type sha256 --base32 --flat \"~a\""
+                              file))
+                   (p (open-input-pipe c))
+                   (l (read-line p)))
+              (close-pipe p)
+              l))))
+
 (test-end)
 
 
-- 
cgit v1.2.3