size.scm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-size)
  19. #:use-module (guix store)
  20. #:use-module (guix monads)
  21. #:use-module (guix packages)
  22. #:use-module (guix derivations)
  23. #:use-module (guix gexp)
  24. #:use-module (guix tests)
  25. #:use-module (guix scripts size)
  26. #:use-module (gnu packages)
  27. #:use-module (gnu packages bootstrap)
  28. #:use-module (ice-9 match)
  29. #:use-module (srfi srfi-1)
  30. #:use-module (srfi srfi-64))
  31. (test-begin "size")
  32. (test-assertm "store-profile"
  33. (mlet* %store-monad ((file1 (gexp->derivation "file1"
  34. #~(symlink #$%bootstrap-guile
  35. #$output)))
  36. (file2 (text-file* "file2"
  37. "the file => " file1)))
  38. (define (matching-profile item)
  39. (lambda (profile)
  40. (string=? item (profile-file profile))))
  41. (mbegin %store-monad
  42. (built-derivations (list file2))
  43. (mlet %store-monad ((profiles (store-profile
  44. (list (derivation->output-path file2))))
  45. (bash (interned-file
  46. (search-bootstrap-binary
  47. "bash" (%current-system)) "bash"
  48. #:recursive? #t))
  49. (guile (package->derivation %bootstrap-guile)))
  50. (define (lookup-profile item)
  51. (find (matching-profile (if (derivation? item)
  52. (derivation->output-path item)
  53. item))
  54. profiles))
  55. (letrec-syntax ((match* (syntax-rules (=>)
  56. ((_ ((drv => profile) rest ...) body)
  57. (match (lookup-profile drv)
  58. ((? profile? profile)
  59. (match* (rest ...) body))))
  60. ((_ () body)
  61. body))))
  62. ;; Make sure we get all three profiles with sensible values.
  63. (return (and (= (length profiles) 4)
  64. (match* ((file1 => profile1)
  65. (file2 => profile2)
  66. (guile => profile3)
  67. (bash => profile4)) ;dependency of GUILE
  68. (and (> (profile-closure-size profile2) 0)
  69. (= (profile-closure-size profile2)
  70. (+ (profile-self-size profile1)
  71. (profile-self-size profile2)
  72. (profile-self-size profile3)
  73. (profile-self-size profile4))))))))))))
  74. (test-assertm "store-profile with multiple items"
  75. (mlet* %store-monad ((file1 (gexp->derivation "file1"
  76. #~(symlink #$%bootstrap-guile
  77. #$output)))
  78. (file2 (text-file* "file2"
  79. "the file => " file1)))
  80. (mbegin %store-monad
  81. (built-derivations (list file2))
  82. (mlet %store-monad ((profiles (store-profile
  83. (list (derivation->output-path file2)
  84. (derivation->output-path file1))))
  85. (reference (store-profile
  86. (list (derivation->output-path file2)))))
  87. (return (and (= (length profiles) 4)
  88. (lset= equal? profiles reference)))))))
  89. (test-end "size")
  90. ;;; Local Variables:
  91. ;;; eval: (put 'match* 'scheme-indent-function 1)
  92. ;;; End: