Skip to content
Snippets Groups Projects
Commit 2e1bafb0 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

packages: Gracefully print packages whose 'location' is #f.

* guix/packages.scm (<package> printer): Check whether LOC is #f.
* tests/packages.scm ("printer with location", "printer without
  location"): New tests.
parent 9c814b82
No related branches found
No related tags found
No related merge requests found
...@@ -229,11 +229,14 @@ (define-record-type* <package> ...@@ -229,11 +229,14 @@ (define-record-type* <package>
(lambda (package port) (lambda (package port)
(let ((loc (package-location package)) (let ((loc (package-location package))
(format simple-format)) (format simple-format))
(format port "#<package ~a-~a ~a:~a ~a>" (format port "#<package ~a-~a ~a~a>"
(package-name package) (package-name package)
(package-version package) (package-version package)
(location-file loc) (if loc
(location-line loc) (format #f "~a:~a "
(location-file loc)
(location-line loc))
"")
(number->string (object-address (number->string (object-address
package) package)
16))))) 16)))))
......
...@@ -19,7 +19,12 @@ ...@@ -19,7 +19,12 @@
(define-module (test-packages) (define-module (test-packages)
#:use-module (guix tests) #:use-module (guix tests)
#:use-module (guix store) #:use-module (guix store)
#:use-module (guix utils) #:use-module ((guix utils)
;; Rename the 'location' binding to allow proper syntax
;; matching when setting the 'location' field of a package.
#:renamer (lambda (name)
(cond ((eq? name 'location) 'make-location)
(else name))))
#:use-module (guix hash) #:use-module (guix hash)
#:use-module (guix derivations) #:use-module (guix derivations)
#:use-module (guix packages) #:use-module (guix packages)
...@@ -34,6 +39,7 @@ (define-module (test-packages) ...@@ -34,6 +39,7 @@ (define-module (test-packages)
#:use-module (srfi srfi-34) #:use-module (srfi srfi-34)
#:use-module (srfi srfi-64) #:use-module (srfi srfi-64)
#:use-module (rnrs io ports) #:use-module (rnrs io ports)
#:use-module (ice-9 regex)
#:use-module (ice-9 match)) #:use-module (ice-9 match))
;; Test the high-level packaging layer. ;; Test the high-level packaging layer.
...@@ -52,6 +58,21 @@ (define-syntax-rule (dummy-package name* extra-fields ...) ...@@ -52,6 +58,21 @@ (define-syntax-rule (dummy-package name* extra-fields ...)
(home-page #f) (license #f) (home-page #f) (license #f)
extra-fields ...)) extra-fields ...))
(test-assert "printer with location"
(string-match "^#<package foo-0 foo.scm:42 [[:xdigit:]]+>$"
(with-output-to-string
(lambda ()
(write
(dummy-package "foo"
(location (make-location "foo.scm" 42 7))))))))
(test-assert "printer without location"
(string-match "^#<package foo-0 [[:xdigit:]]+>$"
(with-output-to-string
(lambda ()
(write
(dummy-package "foo" (location #f)))))))
(test-assert "package-field-location" (test-assert "package-field-location"
(let () (let ()
(define (goto port line column) (define (goto port line column)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment