summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2023-05-05 17:34:01 +0200
committerLudovic Courtès <ludo@gnu.org>2023-05-18 20:01:32 +0200
commitba5da5125a81307500982517e2f458d57b024668 (patch)
tree3497f027375eb532b004b838a0c88ed4dfceb3f0 /tests
parentc1007786fdec6c749887bbd9bf8f46ff27e69055 (diff)
style: Add 'arguments' styling rule.
* guix/scripts/style.scm (unquote->ungexp, gexpify-argument-value) (quote-argument-value, gexpify-argument-tail) (gexpify-package-arguments): New procedures. (%gexp-keywords): New variable. (%options): Add "arguments" case for 'styling-procedure. (show-stylings): Update. * tests/style.scm ("gexpify arguments, already gexpified") ("gexpify arguments, non-gexp arguments, margin comment") ("gexpify arguments, phases and flags") ("gexpify arguments, append arguments") ("gexpify arguments, substitute-keyword-arguments") ("gexpify arguments, append substitute-keyword-arguments"): New tests. * doc/guix.texi (package Reference): For 'arguments', add compatibility note and link to 'guix style'. (Invoking guix style): Document the 'arguments' styling rule.
Diffstat (limited to 'tests')
-rw-r--r--tests/style.scm136
1 files changed, 136 insertions, 0 deletions
diff --git a/tests/style.scm b/tests/style.scm
index f141a57d7f..5e38549606 100644
--- a/tests/style.scm
+++ b/tests/style.scm
@@ -386,6 +386,142 @@
(list (package-inputs (@ (my-packages) my-coreutils))
(read-package-field (@ (my-packages) my-coreutils) 'inputs 4)))))
+(test-assert "gexpify arguments, already gexpified"
+ (call-with-test-package '((arguments
+ (list #:configure-flags #~'("--help"))))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+ (define (fingerprint file)
+ (let ((stat (stat file)))
+ (list (stat:mtime stat) (stat:size stat))))
+ (define before
+ (fingerprint file))
+
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (equal? (fingerprint file) before))))
+
+(test-equal "gexpify arguments, non-gexp arguments, margin comment"
+ (list (list #:tests? #f #:test-target "check")
+ "\
+ (arguments (list #:tests? #f ;no tests
+ #:test-target \"check\"))\n")
+ (call-with-test-package '((arguments
+ '(#:tests? #f
+ #:test-target "check")))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+
+ (substitute* file
+ (("#:tests\\? #f" all)
+ (string-append all " ;no tests\n")))
+
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (load file)
+ (list (package-arguments (@ (my-packages) my-coreutils))
+ (read-package-field (@ (my-packages) my-coreutils) 'arguments 2)))))
+
+(test-equal "gexpify arguments, phases and flags"
+ "\
+ (list #:tests? #f
+ #:configure-flags #~'(\"--fast\")
+ #:make-flags #~(list (string-append \"CC=\"
+ #$(cc-for-target)))
+ #:phases #~(modify-phases %standard-phases
+ ;; Line comment.
+ whatever)))\n"
+ (call-with-test-package '((arguments
+ `(#:tests? #f
+ #:configure-flags '("--fast")
+ #:make-flags
+ (list (string-append "CC=" ,(cc-for-target)))
+ #:phases (modify-phases %standard-phases
+ whatever))))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+
+ (substitute* file
+ (("whatever")
+ "\n;; Line comment.
+ whatever"))
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (load file)
+ (read-package-field (@ (my-packages) my-coreutils) 'arguments 7))))
+
+(test-equal "gexpify arguments, append arguments"
+ "\
+ (append (list #:tests? #f
+ #:configure-flags #~'(\"--fast\"))
+ (package-arguments coreutils)))\n"
+ (call-with-test-package '((arguments
+ `(#:tests? #f
+ #:configure-flags '("--fast")
+ ,@(package-arguments coreutils))))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (load file)
+ (read-package-field (@ (my-packages) my-coreutils) 'arguments 3))))
+
+(test-equal "gexpify arguments, substitute-keyword-arguments"
+ "\
+ (substitute-keyword-arguments (package-arguments coreutils)
+ ((#:tests? _ #f)
+ #t)
+ ((#:make-flags flags
+ #~'())
+ #~(cons \"-DXYZ=yes\"
+ #$flags))))\n"
+ (call-with-test-package '((arguments
+ (substitute-keyword-arguments
+ (package-arguments coreutils)
+ ((#:tests? _ #f) #t)
+ ((#:make-flags flags ''())
+ `(cons "-DXYZ=yes" ,flags)))))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (load file)
+ (read-package-field (@ (my-packages) my-coreutils) 'arguments 7))))
+
+(test-equal "gexpify arguments, append substitute-keyword-arguments"
+ "\
+ (append (list #:tests? #f)
+ (substitute-keyword-arguments (package-arguments coreutils)
+ ((#:make-flags flags)
+ #~(append `(\"-n\" ,%output)
+ #$flags)))))\n"
+ (call-with-test-package '((arguments
+ `(#:tests? #f
+ ,@(substitute-keyword-arguments
+ (package-arguments coreutils)
+ ((#:make-flags flags)
+ `(append `("-n" ,%output) ,flags))))))
+ (lambda (directory)
+ (define file
+ (string-append directory "/my-packages.scm"))
+
+ (system* "guix" "style" "-L" directory "my-coreutils"
+ "-S" "arguments")
+
+ (load file)
+ (read-package-field (@ (my-packages) my-coreutils) 'arguments 5))))
(test-end)