diff options
| author | Nicolas Graves <ngraves@ngraves.fr> | 2026-01-24 01:14:53 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2026-05-07 17:35:32 +0200 |
| commit | 8a505cfd48264973f1208ffe04894af12074b8c7 (patch) | |
| tree | 87556102717bdde4e00ce79d0bd8f1aab5695341 /tests | |
| parent | 10bf5b6c2975088828c0b151d17cbb3e451d300c (diff) | |
style: Add ‘remove-input’ and related styling rules.
* guix/scripts/style.scm (input-matches?, package-list->string,
%field-accessors, remove-from-package-field, transform-package-field):
Add variables.
(%options): Add options --remove-input, --remove-native-input,
--remove-propagated-input, and --parameter.
(guix-style): Implement those options. To keep ony one autoload, use
specification->package+output rather than specification->package.
* tests/style.scm ("remove-input, single input removed",
"remove-input, one of multiple inputs removed",
"remove-input, middle input removed from list",
"remove-input, non-existent input unchanged",
"remove-input, input with output specifier",
"remove-native-input, single input removed",
"remove-native-input, one of multiple inputs removed",
"remove-native-input, does not affect inputs field",
"remove-propagated-input, single input removed",
"remove-propagated-input, one of multiple inputs removed",
"remove-propagated-input, does not affect other fields",
"remove-input from all three fields independently",
"remove-input, dry-run does not modify file"): New tests.
("url-fetch->git-fetch, preserved field"): Drop the use of %patch-path
and %package-module-path, which are not necessary because of -L.
Change the mocked procedure from specification->package to
specification->package+output, as in the implementation.
* doc/guix.texi (Invoking guix style): Add description for guix style
-S remove-*input rules.
Change-Id: I449c87930310a73ad316b4cb5db72d0906ea495d
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Merges: #5862
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/style.scm | 209 |
1 files changed, 205 insertions, 4 deletions
diff --git a/tests/style.scm b/tests/style.scm index 17cc9507f78..60b99638dd6 100644 --- a/tests/style.scm +++ b/tests/style.scm | |||
| @@ -616,15 +616,13 @@ | |||
| 616 | (call-with-output-file (string-append directory "/foo.patch") | 616 | (call-with-output-file (string-append directory "/foo.patch") |
| 617 | (const #t)) | 617 | (const #t)) |
| 618 | 618 | ||
| 619 | (parameterize ((test-directory directory) | 619 | (parameterize ((test-directory directory)) |
| 620 | (%patch-path (list directory)) | ||
| 621 | (%package-module-path (list directory ""))) | ||
| 622 | (with-temporary-git-repository repository | 620 | (with-temporary-git-repository repository |
| 623 | `((add "README" "Initial commit") | 621 | `((add "README" "Initial commit") |
| 624 | (commit "First commit") | 622 | (commit "First commit") |
| 625 | (tag "1.0" "Initial release")) | 623 | (tag "1.0" "Initial release")) |
| 626 | (mock ((guix import utils) git-repository-url? (const #t)) | 624 | (mock ((guix import utils) git-repository-url? (const #t)) |
| 627 | (mock ((gnu packages) specification->package | 625 | (mock ((gnu packages) specification->package+output |
| 628 | (lambda (spec) | 626 | (lambda (spec) |
| 629 | (car | 627 | (car |
| 630 | (vhash-fold* cons '() spec | 628 | (vhash-fold* cons '() spec |
| @@ -725,6 +723,209 @@ | |||
| 725 | ;; File should be unchanged | 723 | ;; File should be unchanged |
| 726 | (equal? (call-with-input-file file port-sha256) before-hash)))) | 724 | (equal? (call-with-input-file file port-sha256) before-hash)))) |
| 727 | 725 | ||
| 726 | |||
| 727 | ;;; | ||
| 728 | ;;; remove-input, remove-native-input, remove-propagated-input | ||
| 729 | ;;; | ||
| 730 | |||
| 731 | (test-equal "remove-input, single input removed" | ||
| 732 | '((inputs (list))) | ||
| 733 | (call-with-test-package '((inputs (list gmp))) | ||
| 734 | (lambda (directory) | ||
| 735 | (define file | ||
| 736 | (string-append directory "/my-packages.scm")) | ||
| 737 | |||
| 738 | (system* "guix" "style" "-L" directory | ||
| 739 | "-S" "remove-input" "--parameter=gmp" | ||
| 740 | "my-coreutils") | ||
| 741 | |||
| 742 | (load file) | ||
| 743 | (read-package-field (@ (my-packages) my-coreutils) 'inputs)))) | ||
| 744 | |||
| 745 | (test-equal "remove-input, one of multiple inputs removed" | ||
| 746 | `(("acl" ,acl)) | ||
| 747 | (call-with-test-package '((inputs (list gmp acl))) | ||
| 748 | (lambda (directory) | ||
| 749 | (define file | ||
| 750 | (string-append directory "/my-packages.scm")) | ||
| 751 | |||
| 752 | (system* "guix" "style" "-L" directory | ||
| 753 | "-S" "remove-input" "--parameter=gmp" | ||
| 754 | "my-coreutils") | ||
| 755 | |||
| 756 | (load file) | ||
| 757 | (package-inputs (@ (my-packages) my-coreutils))))) | ||
| 758 | |||
| 759 | (test-equal "remove-input, middle input removed from list" | ||
| 760 | `(("gmp" ,gmp) ("mpfr" ,mpfr)) | ||
| 761 | (call-with-test-package '((inputs (list gmp acl mpfr))) | ||
| 762 | (lambda (directory) | ||
| 763 | (define file | ||
| 764 | (string-append directory "/my-packages.scm")) | ||
| 765 | |||
| 766 | (system* "guix" "style" "-L" directory | ||
| 767 | "-S" "remove-input" "--parameter=acl" | ||
| 768 | "my-coreutils") | ||
| 769 | |||
| 770 | (load file) | ||
| 771 | (package-inputs (@ (my-packages) my-coreutils))))) | ||
| 772 | |||
| 773 | (test-equal "remove-input, non-existent input unchanged" | ||
| 774 | `(("gmp" ,gmp) ("acl" ,acl)) | ||
| 775 | (call-with-test-package '((inputs (list gmp acl))) | ||
| 776 | (lambda (directory) | ||
| 777 | (define file | ||
| 778 | (string-append directory "/my-packages.scm")) | ||
| 779 | |||
| 780 | (system* "guix" "style" "-L" directory | ||
| 781 | "-S" "remove-input" "--parameter=mpfr" | ||
| 782 | "my-coreutils") | ||
| 783 | |||
| 784 | (load file) | ||
| 785 | (package-inputs (@ (my-packages) my-coreutils))))) | ||
| 786 | |||
| 787 | (test-equal "remove-input, input with output specifier" | ||
| 788 | `(("acl" ,acl)) | ||
| 789 | (call-with-test-package '((inputs (list `(,gmp "debug") acl))) | ||
| 790 | (lambda (directory) | ||
| 791 | (define file | ||
| 792 | (string-append directory "/my-packages.scm")) | ||
| 793 | |||
| 794 | (system* "guix" "style" "-L" directory | ||
| 795 | "-S" "remove-input" "--parameter=gmp:debug" | ||
| 796 | "my-coreutils") | ||
| 797 | |||
| 798 | (load file) | ||
| 799 | (package-inputs (@ (my-packages) my-coreutils))))) | ||
| 800 | |||
| 801 | ;; (test-skip 100) | ||
| 802 | |||
| 803 | (test-equal "remove-native-input, single input removed" | ||
| 804 | '() | ||
| 805 | (call-with-test-package '((native-inputs (list gmp))) | ||
| 806 | (lambda (directory) | ||
| 807 | (define file | ||
| 808 | (string-append directory "/my-packages.scm")) | ||
| 809 | |||
| 810 | (system* "guix" "style" "-L" directory | ||
| 811 | "-S" "remove-native-input" "--parameter=gmp" | ||
| 812 | "my-coreutils") | ||
| 813 | |||
| 814 | (load file) | ||
| 815 | (package-native-inputs (@ (my-packages) my-coreutils))))) | ||
| 816 | |||
| 817 | (test-equal "remove-native-input, one of multiple inputs removed" | ||
| 818 | `(("acl" ,acl)) | ||
| 819 | (call-with-test-package '((native-inputs (list gmp acl))) | ||
| 820 | (lambda (directory) | ||
| 821 | (define file | ||
| 822 | (string-append directory "/my-packages.scm")) | ||
| 823 | |||
| 824 | (system* "guix" "style" "-L" directory | ||
| 825 | "-S" "remove-native-input" "--parameter=gmp" | ||
| 826 | "my-coreutils") | ||
| 827 | |||
| 828 | (load file) | ||
| 829 | (package-native-inputs (@ (my-packages) my-coreutils))))) | ||
| 830 | |||
| 831 | (test-equal "remove-native-input, does not affect inputs field" | ||
| 832 | `(("gmp" ,gmp)) | ||
| 833 | (call-with-test-package '((inputs (list gmp)) | ||
| 834 | (native-inputs (list acl))) | ||
| 835 | (lambda (directory) | ||
| 836 | (define file | ||
| 837 | (string-append directory "/my-packages.scm")) | ||
| 838 | |||
| 839 | (system* "guix" "style" "-L" directory | ||
| 840 | "-S" "remove-native-input" "--parameter=acl" | ||
| 841 | "my-coreutils") | ||
| 842 | |||
| 843 | (load file) | ||
| 844 | (package-inputs (@ (my-packages) my-coreutils))))) | ||
| 845 | |||
| 846 | (test-equal "remove-propagated-input, single input removed" | ||
| 847 | '() | ||
| 848 | (call-with-test-package '((propagated-inputs (list gmp))) | ||
| 849 | (lambda (directory) | ||
| 850 | (define file | ||
| 851 | (string-append directory "/my-packages.scm")) | ||
| 852 | |||
| 853 | (system* "guix" "style" "-L" directory | ||
| 854 | "-S" "remove-propagated-input" "--parameter=gmp" | ||
| 855 | "my-coreutils") | ||
| 856 | |||
| 857 | (load file) | ||
| 858 | (package-propagated-inputs (@ (my-packages) my-coreutils))))) | ||
| 859 | |||
| 860 | (test-equal "remove-propagated-input, one of multiple inputs removed" | ||
| 861 | `(("acl" ,acl)) | ||
| 862 | (call-with-test-package '((propagated-inputs (list gmp acl))) | ||
| 863 | (lambda (directory) | ||
| 864 | (define file | ||
| 865 | (string-append directory "/my-packages.scm")) | ||
| 866 | |||
| 867 | (system* "guix" "style" "-L" directory | ||
| 868 | "-S" "remove-propagated-input" "--parameter=gmp" | ||
| 869 | "my-coreutils") | ||
| 870 | |||
| 871 | (load file) | ||
| 872 | (package-propagated-inputs (@ (my-packages) my-coreutils))))) | ||
| 873 | |||
| 874 | (test-equal "remove-propagated-input, does not affect other fields" | ||
| 875 | (list `(("gmp" ,gmp)) `(("acl" ,acl))) | ||
| 876 | (call-with-test-package '((inputs (list gmp)) | ||
| 877 | (native-inputs (list acl)) | ||
| 878 | (propagated-inputs (list mpfr))) | ||
| 879 | (lambda (directory) | ||
| 880 | (define file | ||
| 881 | (string-append directory "/my-packages.scm")) | ||
| 882 | |||
| 883 | (system* "guix" "style" "-L" directory | ||
| 884 | "-S" "remove-propagated-input" "--parameter=mpfr" | ||
| 885 | "my-coreutils") | ||
| 886 | |||
| 887 | (load file) | ||
| 888 | (list (package-inputs (@ (my-packages) my-coreutils)) | ||
| 889 | (package-native-inputs (@ (my-packages) my-coreutils)))))) | ||
| 890 | |||
| 891 | (test-equal "remove-input from all three fields independently" | ||
| 892 | (list '() '() '()) | ||
| 893 | (call-with-test-package '((inputs (list gmp)) | ||
| 894 | (native-inputs (list acl)) | ||
| 895 | (propagated-inputs (list mpfr))) | ||
| 896 | (lambda (directory) | ||
| 897 | (define file | ||
| 898 | (string-append directory "/my-packages.scm")) | ||
| 899 | |||
| 900 | (system* "guix" "style" "-L" directory | ||
| 901 | "-S" "remove-input" "--parameter=gmp" | ||
| 902 | "my-coreutils") | ||
| 903 | (system* "guix" "style" "-L" directory | ||
| 904 | "-S" "remove-native-input" "--parameter=acl" | ||
| 905 | "my-coreutils") | ||
| 906 | (system* "guix" "style" "-L" directory | ||
| 907 | "-S" "remove-propagated-input" "--parameter=mpfr" | ||
| 908 | "my-coreutils") | ||
| 909 | |||
| 910 | (load file) | ||
| 911 | (list (package-inputs (@ (my-packages) my-coreutils)) | ||
| 912 | (package-native-inputs (@ (my-packages) my-coreutils)) | ||
| 913 | (package-propagated-inputs (@ (my-packages) my-coreutils)))))) | ||
| 914 | |||
| 915 | (test-assert "remove-input, dry-run does not modify file" | ||
| 916 | (call-with-test-package '((inputs (list gmp acl))) | ||
| 917 | (lambda (directory) | ||
| 918 | (define file | ||
| 919 | (string-append directory "/my-packages.scm")) | ||
| 920 | (define before-hash | ||
| 921 | (call-with-input-file file port-sha256)) | ||
| 922 | |||
| 923 | (system* "guix" "style" "-L" directory "-n" | ||
| 924 | "-S" "remove-input" "--parameter=gmp" | ||
| 925 | "my-coreutils") | ||
| 926 | |||
| 927 | (equal? (call-with-input-file file port-sha256) before-hash)))) | ||
| 928 | |||
| 728 | (test-end) | 929 | (test-end) |
| 729 | 930 | ||
| 730 | ;; Local Variables: | 931 | ;; Local Variables: |
