;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-size)
  #:use-module (guix store)
  #:use-module (guix monads)
  #:use-module (guix packages)
  #:use-module (guix derivations)
  #:use-module (guix gexp)
  #:use-module (guix tests)
  #:use-module (guix scripts size)
  #:use-module (gnu packages)
  #:use-module (gnu packages bootstrap)
  #:use-module (ice-9 match)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-64))


(test-begin "size")

(test-assertm "store-profile"
  (mlet* %store-monad ((file1 (gexp->derivation "file1"
                                                #~(symlink #$%bootstrap-guile
                                                           #$output)))
                       (file2 (text-file* "file2"
                                          "the file => " file1)))
    (define (matching-profile item)
      (lambda (profile)
        (string=? item (profile-file profile))))

    (mbegin %store-monad
      (built-derivations (list file2))
      (mlet %store-monad ((profiles (store-profile
                                     (list (derivation->output-path file2))))
                          (bash     (interned-file
                                     (search-bootstrap-binary
                                      "bash" (%current-system)) "bash"
                                      #:recursive? #t))
                          (guile    (package->derivation %bootstrap-guile)))
        (define (lookup-profile item)
          (find (matching-profile (if (derivation? item)
                                      (derivation->output-path item)
                                      item))
                profiles))

        (letrec-syntax ((match* (syntax-rules (=>)
                                  ((_ ((drv => profile) rest ...) body)
                                   (match (lookup-profile drv)
                                     ((? profile? profile)
                                      (match* (rest ...) body))))
                                  ((_ () body)
                                   body))))
          ;; Make sure we get all three profiles with sensible values.
          (return (and (= (length profiles) 4)
                       (match* ((file1 => profile1)
                                (file2 => profile2)
                                (guile => profile3)
                                (bash  => profile4)) ;dependency of GUILE
                         (and (> (profile-closure-size profile2) 0)
                              (= (profile-closure-size profile2)
                                 (+ (profile-self-size profile1)
                                    (profile-self-size profile2)
                                    (profile-self-size profile3)
                                    (profile-self-size profile4))))))))))))

(test-assertm "store-profile with multiple items"
  (mlet* %store-monad ((file1 (gexp->derivation "file1"
                                                #~(symlink #$%bootstrap-guile
                                                           #$output)))
                       (file2 (text-file* "file2"
                                          "the file => " file1)))
    (mbegin %store-monad
      (built-derivations (list file2))
      (mlet %store-monad ((profiles  (store-profile
                                      (list (derivation->output-path file2)
                                            (derivation->output-path file1))))
                          (reference (store-profile
                                      (list (derivation->output-path file2)))))
        (return (and (= (length profiles) 4)
                     (lset= equal? profiles reference)))))))

(test-end "size")

;;; Local Variables:
;;; eval: (put 'match* 'scheme-indent-function 1)
;;; End:
go-github-com-libp2p-go-flow-metrics: Move to golang-web....* gnu/packages/golang.scm (go-github-com-libp2p-go-flow-metrics): Move from here ... * gnu/packages/golang-web.scm: ... to here. Change-Id: I6847de630820dc895cb3d14f16b086fd1cc69bb7 Sharlatan Hellseher 2024-08-25gnu: go-github-com-libp2p-go-flow-metrics: Enable tests....* gnu/packages/golang.scm (go-github-com-libp2p-go-flow-metrics): Enable tests. Change-Id: Ic117d3e0ca06719bf6b0a058f7475169afd12d11 Sharlatan Hellseher 2024-08-25gnu: go-github-com-libp2p-go-flow-metrics: Update to 0.1.0....* gnu/packages/golang.scm (go-github-com-libp2p-go-flow-metrics): Update to 0.1.0. [propagated-inputs]: Add go-github-com-benbjohnson-clock. Change-Id: I13799b39e8d22a4f1be763eeef24dd2170d1cba1 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-go-logr-stdr....* gnu/packages/golang-xyz.scm (go-github-com-go-logr-stdr): New variable. Change-Id: I3cbe5e34306ee0c07143155e499f9f0aa6be2761 Sharlatan Hellseher 2024-08-25gnu: go-github-com-miekg-dns: Move to golang-web....* gnu/packages/golang-xyz.scm (go-github-com-miekg-dns): Move from here ... * gnu/packages/golang-web.scm: ... to here. Change-Id: I7d1e38dd4fdc9578cdefdf01ff43f5201c490f73 Sharlatan Hellseher 2024-08-25gnu: go-github-com-miekg-dns: Update to 1.1.62....* gnu/packages/golang-xyz.scm (go-github-com-miekg-dns): Update to 1.1.62. [arguments] <#:phases>: Add 'disable-failing-tests. Change-Id: I857df6a1520e0e08f7255b700ffc2ac1494b27db Sharlatan Hellseher 2024-08-25gnu: go-github-com-prometheus-procfs: Enable tests....* gnu/packages/prometheus.scm (go-github-com-prometheus-procfs): Enable tests. [arguments] <#:phases>: Add 'unpack-testdata and 'remove-testdata phases. Use custom 'check phase. Change-Id: Iae01ce9cb57748ce4b155e2b814dd69ff9ba5114 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-prometheus-statsd-exporter....* gnu/packages/prometheus.scm (go-github-com-prometheus-statsd-exporter): New variable. Change-Id: Ibb45cfd1d4b944d6c809305650df6c323bbf52e0 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-stvp-go-udp-testing....* gnu/packages/golang-check.scm (go-github-com-stvp-go-udp-testing): New variable. Change-Id: I23a507d23cdf419beeba5d44bb6bed6f7f4fcdce Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-prometheus-exporter-toolkit....* gnu/packages/prometheus.scm (go-github-com-prometheus-exporter-toolkit): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I89d3a28a1f8ceab9ec3e8754582b2292205b3772 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-validate....* gnu/packages/golang-web.scm (go-github-com-go-openapi-validate): New variable. Co-authored-by: Sharlatan Hellseher <sharlatanus@gmail.com> Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I775c1d2acdfa58f42a3898ced33f24a0a0fb2ee9 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-loads....* gnu/packages/golang-web.scm (go-github-com-go-openapi-loads): New variable. Co-authored-by: Sharlatan Hellseher <sharlatanus@gmail.com> Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: If5c3d479064ae04e01035c7c7ff1b61acb406749 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-analysis....* gnu/packages/golang-web.scm (go-github-com-go-openapi-analysis): New variable. Co-authored-by: Sharlatan Hellseher <sharlatanus@gmail.com> Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I8d2831c4a71908058ebd8d8935dddb3ef75ce360 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-strfmt....* gnu/packages/golang-web.scm (go-github-com-go-openapi-strfmt): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I31a3d51315991aae3ead5cde12fc14d913235a6a Leo Nikkilä 2024-08-25gnu: go-github-com-google-uuid: Update to 1.6.0....* gnu/packages/golang.scm (go-github-com-google-uuid): Update to 1.6.0. Change-Id: Iecc6a649124e45fa2155042cc56350779ec1880c Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-go-openapi-spec....* gnu/packages/golang-web.scm (go-github-com-go-openapi-spec): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I4fa578345ffa7ad550926b37489f1a0c5a827fb9 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-jsonreference....* gnu/packages/golang-web.scm (go-github-com-go-openapi-jsonreference): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I55eb6403fb5b7460d74c7b21a38b85b2194304d8 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-jsonpointer....* gnu/packages/golang-web.scm (go-github-com-go-openapi-jsonpointer): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I85a2342fa9740fa68ad52c6391465d30a284986d Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-swag....* gnu/packages/golang-web.scm (go-github-com-go-openapi-swag): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Id6258a11cdb8e1c04de0dc155ecef157ec74df83 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-openapi-errors....* gnu/packages/golang-web.scm (go-github-com-go-openapi-errors): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I3676121428a741124a6a15ef0855de48c882ff4a Leo Nikkilä 2024-08-25gnu: Add go-go-mongodb-org-mongo-driver....* gnu/packages/golang-xyz.scm (go-go-mongodb-org-mongo-driver): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ib7bc1252593c91d33cb75436cdc9e803e11977af Leo Nikkilä 2024-08-25gnu: Add go-github-com-aws-aws-lambda-go....* gnu/packages/golang-web.scm (go-github-com-aws-aws-lambda-go): New variable. Change-Id: I5abb8225f0c36232e8fbd6c37763ae30f842eab2 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-youmark-pkcs8....* gnu/packages/golang-crypto.scm (go-github-com-youmark-pkcs8): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: If16a5d911d645396c5976893f2fc43a7f26bf283 Leo Nikkilä 2024-08-25gnu: Add go-k8s-io-klog-v2....* gnu/packages/golang-xyz.scm (go-k8s-io-klog-v2): New variable. Change-Id: I98900fdd7449b4e6bf6d4ea35eac659b188182a4 Sharlatan Hellseher 2024-08-25gnu: Add go-k8s-io-klog....* gnu/packages/golang-xyz.scm (go-k8s-io-klog): New variable. Change-Id: I5985ef3f9342fb1cc671c3d113cef78785650548 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-shurcool-vfsgen....* gnu/packages/golang-web.scm (go-github-com-shurcool-vfsgen): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I7f89b17c4950b68147922fac0fea49fa527a9172 Leo Nikkilä 2024-08-25gnu: Add go-github-com-shurcool-httpfs....* gnu/packages/golang-web.scm (go-github-com-shurcool-httpfs): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ie0413ac3c9bd50365f197b2c6f6ec4f00fbc0d97 Leo Nikkilä 2024-08-25gnu: Add go-github-com-shurcool-httpgzip....* gnu/packages/golang-web.scm (go-github-com-shurcool-httpgzip): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I78255b1729587c99ba1bbb6c8759d55d00c83497 Leo Nikkilä 2024-08-25gnu: Add go-github-com-puerkitobio-urlesc....* gnu/packages/golang-web.scm (go-github-com-puerkitobio-urlesc): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: If2cbb27f329e681bf83615ff82cc4f6a9a34804e Leo Nikkilä 2024-08-25gnu: Add go-github-com-puerkitobio-purell....* gnu/packages/golang-web.scm (go-github-com-puerkitobio-purell): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ib7dc05b5c4fd554e3ee6a0a5b297bbb1a3daaa4c Leo Nikkilä 2024-08-25gnu: Add go-github-com-opentracing-contrib-go-stdlib....* gnu/packages/golang-web.scm (go-github-com-opentracing-contrib-go-stdlib): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I29ccd97ccd3618b845b161ee6bf7d4d09fe1b82c Leo Nikkilä 2024-08-25gnu: Add go-github-com-oklog-ulid-v2....* gnu/packages/golang-xyz.scm (go-github-com-oklog-ulid-v2, go-ulid): New variables. Change-Id: I6512659023330ab1ff03bc9c2e43e3ad92a30490 Sharlatan Hellseher 2024-08-25gnu: Add go-github-com-oklog-ulid....* gnu/packages/golang-xyz.scm (go-github-com-oklog-ulid): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Iff799292882f22db38273a597a2b83de781cf51d Leo Nikkilä 2024-08-25gnu: Add go-github-com-oklog-run....* gnu/packages/golang-xyz.scm (go-github-com-oklog-run): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: If0a0f1cb274ed10e991001079ff152dbe31c8ce4 Leo Nikkilä 2024-08-25gnu: Add go-github-com-mailru-easyjson....* gnu/packages/golang-web.scm (go-github-com-mailru-easyjson): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I62da25345aa44a0d6811ea0e50de58eeaea0fbe4 Leo Nikkilä 2024-08-25gnu: Add go-github-com-go-stack-stack....* gnu/packages/golang-xyz.scm (go-github-com-go-stack-stack): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: Ia9e8049ec5b0bb977b6e54faaa98dd9868e0d84c Leo Nikkilä 2024-08-25gnu: Add go-github-com-edsrzf-mmap-go....* gnu/packages/golang-xyz.scm (go-github-com-edsrzf-mmap-go): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I53bab656d8e9607c93b48c8877c9f568cbd4ef41 Leo Nikkilä 2024-08-25gnu: Add go-github-com-dennwc-varint....* gnu/packages/golang-xyz.scm (go-github-com-dennwc-varint): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I2e0b00e09fa20b0047e29ada307c1b3eb8c90a74 Leo Nikkilä 2024-08-25gnu: Add go-github-com-asaskevich-govalidator....* gnu/packages/golang-xyz.scm (go-github-com-asaskevich-govalidator): New variable. Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com> Change-Id: I81bedd44ba1b41771a114733b443a73953e7d7e1 Leo Nikkilä 2024-08-25gnu: trealla: Update to 2.55.24....* gnu/packages/prolog.scm (trealla): Update to 2.55.24. Change-Id: I0e94ef0b863f137d63bd36e13212d64263f496d4 jgart 2024-08-25gnu: emacs-dape: Update to 0.15.0....* gnu/packages/emacs-xyz.scm (emacs-dape): Update to 0.15.0. Change-Id: I662a06317e4d2bd535687fe35d42a1e36b045ab3 jgart