aboutsummaryrefslogtreecommitdiff
path: root/tests/status.scm
blob: 01a61f734529941ad3a4634a7ee96d2b1f1ddaf3 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018, 2019 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-status)
  #:use-module (guix status)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-11)
  #:use-module (srfi srfi-64)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs io ports)
  #:use-module (ice-9 match))

(test-begin "status")

(test-equal "compute-status, no-op"
  (build-status)
  (let-values (((port get-status)
                (build-event-output-port compute-status)))
    (display "foo\nbar\n\baz\n" port)
    (get-status)))

(test-equal "compute-status, builds + substitutes"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux")))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 500
                                      #:start 'now))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux")))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 500
                                      #:transferred 42
                                      #:start 'now))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux")))
         (downloads-completed (list (download "bar" "http://example.org/bar"
                                              #:size 500
                                              #:transferred 500
                                              #:start 'now
                                              #:end 'now)))))
  (let-values (((port get-status)
                (build-event-output-port (lambda (event status)
                                           (compute-status event status
                                                           #:current-time
                                                           (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux \n" port)
    (display "@ substituter-started bar\n" port)
    (display "@ download-started bar http://example.org/bar 500\n" port)
    (display "various\nthings\nget\nwritten\n" port)
    (let ((first (get-status)))
      (display "@ download-progress bar http://example.org/bar 500 42\n"
               port)
      (let ((second (get-status)))
        (display "@ download-progress bar http://example.org/bar 500 84\n"
                 port)
        (display "@ build-succeeded foo.drv\n" port)
        (display "@ download-succeeded bar http://example.org/bar 500\n" port)
        (display "Almost done!\n" port)
        (display "@ substituter-succeeded bar\n" port)
        (list first second (get-status))))))

(test-equal "compute-status, missing events"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux"
                                #:log-file "foo.log")))
         (downloading (list (download "baz" "http://example.org/baz"
                                      #:size 500
                                      #:transferred 42
                                      #:start 'now)
                            (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:transferred 0
                                      #:start 'now))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux"
                                        #:log-file "foo.log")))
         (downloads-completed (list (download "baz" "http://example.org/baz"
                                              #:size 500
                                              #:transferred 500
                                              #:start 'now
                                              #:end 'now)
                                    (download "bar" "http://example.org/bar"
                                              #:size 999
                                              #:transferred 999
                                              #:start 'now
                                              #:end 'now)))))
  ;; Below we omit 'substituter-started' events and the like.
  (let-values (((port get-status)
                (build-event-output-port (lambda (event status)
                                           (compute-status event status
                                                           #:current-time
                                                           (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux foo.log\n" port)
    (display "@ download-started bar http://example.org/bar 999\n" port)
    (display "various\nthings\nget\nwritten\n" port)
    (display "@ download-progress baz http://example.org/baz 500 42\n"
             port)
    (let ((first (get-status)))
      (display "@ build-succeeded foo.drv\n" port)
      (display "@ download-succeeded bar http://example.org/bar 999\n" port)
      (display "Almost done!\n" port)
      (display "@ substituter-succeeded baz\n" port)
      (list first (get-status)))))

(test-equal "build-output-port, UTF-8"
  '((build-log #f "lambda is λ!\n"))
  (let-values (((port get-status) (build-event-output-port cons '()))
               ((bv)              (string->utf8 "lambda is λ!\n")))
    (put-bytevector port bv)
    (force-output port)
    (get-status)))

(test-equal "current-build-output-port, UTF-8 + garbage"
  ;; What about a mixture of UTF-8 + garbage?
  (let ((replacement "�"))
    `((build-log #f ,(string-append "garbage: " replacement "lambda: λ\n"))))
  (let-values (((port get-status) (build-event-output-port cons '())))
    (display "garbage: " port)
    (put-bytevector port #vu8(128))
    (put-bytevector port (string->utf8 "lambda: λ\n"))
    (force-output port)
    (get-status)))

(test-equal "compute-status, multiplexed build output"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:start 'now))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloading (list (download "bar" "http://example.org/bar"
                                      #:size 999
                                      #:transferred 42
                                      #:start 'now))))
        (build-status
         ;; "bar" is now only listed as a download.
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121)))
         (downloads-completed (list (download "bar" "http://example.org/bar"
                                              #:size 999
                                              #:transferred 999
                                              #:start 'now
                                              #:end 'now)))))
  (let-values (((port get-status)
                (build-event-output-port (lambda (event status)
                                           (compute-status event status
                                                           #:current-time
                                                           (const 'now)
                                                           #:derivation-path->output-path
                                                           (match-lambda
                                                             ("bar.drv" "bar")))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-started bar.drv - armhf-linux bar.log 144\n" port)
    (display "@ build-log 121 6\nHello!" port)
    (display "@ build-log 144 50
@ download-started bar http://example.org/bar 999\n" port)
    (let ((first (get-status)))
      (display "@ build-log 121 30\n@ build-started FAKE!.drv 555\n")
      (display "@ build-log 144 54
@ download-progress bar http://example.org/bar 999 42\n"
               port)
      (let ((second (get-status)))
        (display "@ download-succeeded bar http://example.org/bar 999\n" port)
        (display "@ build-succeeded foo.drv\n" port)
        (display "@ build-succeeded bar.drv\n" port)
        (list first second (get-status))))))

(test-equal "compute-status, build completion"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:completion 0.))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:completion 50.))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
                                        #:completion 100.)))))
  (let-values (((port get-status)
                (build-event-output-port (lambda (event status)
                                           (compute-status event status
                                                           #:current-time
                                                           (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-log 121 6\nHello!" port)
    (let ((first (get-status)))
      (display "@ build-log 121 20\n[ 0/100] building X\n" port)
      (display "@ build-log 121 6\nHello!" port)
      (let ((second (get-status)))
        (display "@ build-log 121 20\n[50/100] building Y\n" port)
        (display "@ build-log 121 6\nHello!" port)
        (let ((third (get-status)))
          (display "@ build-log 121 21\n[100/100] building Z\n" port)
          (display "@ build-log 121 6\nHello!" port)
          (display "@ build-succeeded foo.drv\n" port)
          (list first second third (get-status)))))))

(test-equal "compute-status, build phase"
  (list (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'configure))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'configure
                                #:completion 50.))))
        (build-status
         (building (list (build "foo.drv" "x86_64-linux" #:id 121
                                #:phase 'install))))
        (build-status
         (builds-completed (list (build "foo.drv" "x86_64-linux" #:id 121
                                        #:phase 'install)))))
  (let-values (((port get-status)
                (build-event-output-port (lambda (event status)
                                           (compute-status event status
                                                           #:current-time
                                                           (const 'now))))))
    (display "@ build-started foo.drv - x86_64-linux  121\n" port)
    (display "@ build-log 121 27\nstarting phase `configure'\n" port)
    (display "@ build-log 121 6\nabcde!" port)
    (let ((first (get-status)))
      (display "@ build-log 121 20\n[50/100] building Y\n" port)
      (display "@ build-log 121 6\nfghik!" port)
      (let ((second (get-status)))
        (display "@ build-log 121 21\n[100/100] building Z\n" port)
        (display "@ build-log 121 25\nstarting phase `install'\n" port)
        (display "@ build-log 121 6\nlmnop!" port)
        (let ((third (get-status)))
          (display "@ build-succeeded foo.drv\n" port)
          (list first second third (get-status)))))))

(test-end "status")
mthl@gnu.org> Ludovic Courtès 2016-03-04emacs: Use '@' to separate package names and version numbers....This is a followup to commit 1b846da8c372bee78851439fd9e72b2499115e5a. * emacs/guix-base.el (guix-package-name-specification): Use "@" instead of "-". * emacs/guix-main.scm (name+version->full-name): Likewise. (package-inputs-names): Use 'make-package-specification' instead of 'package-full-name'. (full-name->name+version): Update the docstring. * emacs/guix-ui-package.el (guix-packages-by-name): Likewise. Alex Kost 2016-03-04emacs: hydra: Use '-' to separate job names and version numbers....* emacs/guix-hydra.el (guix-hydra-job-name-specification): New procedure. * emacs/guix-ui-package.el (guix-package-info-insert-systems) (guix-package-list-latest-builds): Use it. Alex Kost 2016-02-24Do not check package freshness during upgrade....Fixes <http://bugs.gnu.org/22740>. Reported by Andreas Enge <andreas@enge.fr>. * gnu/packages.scm (waiting, ftp-open*, check-package-freshness): Remove. * guix/scripts/package.scm (options->installable): Adjust accordingly. * emacs/guix-main.scm (package->manifest-entry*): Likewise. Alex Kost 2016-02-22emacs: Do not allow a user to modify system profiles....Fixes <http://bugs.gnu.org/22607>. Reported by myglc2 <myglc2@gmail.com>. Remove possibilities to install/delete packages to/from a system profile both for "Package List" and "Package Info" buffers. * emacs/guix-profiles.el (guix-system-profile-regexp): New variable. (guix-system-profile?): New procedure. * emacs/guix-ui-package.el (guix-package-info-insert-output): Do not display "Install"/"Delete" button for a system profile. (guix-package-assert-non-system-profile): New procedure. (guix-package-execute-actions): Use it. Alex Kost 2016-02-22emacs: Set 'guix-buffer-item' before displaying entries....* emacs/guix-buffer.el (guix-buffer-set): Set 'guix-buffer-item' early, so that it can be used during displaying entries. For example, this allows us to use a value of the current guix profile when package entries are inserted in a "List" or "Info" buffer. Alex Kost 2016-02-22emacs: Add 'M-x guix-installed-{user/system}-packages'....* emacs/guix-ui-package.el (guix-installed-user-packages) (guix-installed-system-packages): New commands. * doc/emacs.texi (Emacs Commands): Document them. Alex Kost 2016-02-18emacs: Autoload hooks instead of putting them in 'guix-init'....* emacs/guix-init.el: Move adding hooks to... * emacs/guix-build-log.el: ... here. * emacs/guix-devel.el: ... and here. Alex Kost 2016-02-10emacs: 'C-u M-x guix-edit' prompts for directory....* emacs/guix-base.el (guix-read-directory): New procedure. (guix-find-location, guix-edit): Add optional 'directory' argument. * emacs/guix-ui-package.el (guix-package-list-edit) (guix-output-list-edit): Likewise. * doc/emacs.texi (Emacs Commands): Mention "C-u". Alex Kost 2016-02-07emacs: Find Emacs packages in a system profile....Fixes <http://bugs.gnu.org/22550>. Reported by myglc2 <myglc2@gmail.com>. * emacs/guix-emacs.el (guix-emacs-autoload-packages): Autoload Emacs packages installed in a system profile. Alex Kost 2016-02-07emacs: Move the code to load Emacs packages after installing....This code should belong to "guix-backend" as it is run after a REPL operation to check if new Emacs packages have been installed and to autoload them if needed. * emacs/guix-emacs.el (guix-emacs-activate-after-operation) (guix-emacs-load-autoloads-maybe): Move and rename to... * emacs/guix-backend.el (guix-emacs-activate-after-operation) (guix-repl-autoload-emacs-packages-maybe): ... this. (guix-after-repl-operation-hook): Adjust for the renaming. Alex Kost 2016-02-07emacs: Factorize searching for Emacs packages....* emacs/guix-emacs.el: (guix-emacs-directories): New procedure. (guix-emacs-find-autoloads-in-directory): Rename to... (guix-emacs-find-autoloads): ... this. (guix-emacs-load-autoloads): Remove. Replace with... (guix-emacs-autoload-packages): ... this. New procedure. At first, find a list of directories with Emacs packages, then add them to 'load-path' and finally, load autoloads. * doc/emacs.texi (Emacs Initial Setup): Adjust accordingly. Alex Kost 2016-02-04emacs: Add missing (require 'guix-profiles)....Reported by Christopher Allan Webber <cwebber@dustycloud.org> on #guix. Several modules use the code from 'guix-profiles' without requiring it. It was never noticed before commits e4e2154644ecf76ea02a50304c1405c00c9ffdd1 and 13fe4891fa247d306e203ee14c6886513bd86b52, because 'guix-emacs' required this module. But now, when 'site-start.el' loads 'guix-emacs', 'guix-profiles' may not exist yet, so it may not be required. This will lead to an error when some of "M-x guix-..." commands will be used. See <https://gnunet.org/bot/log/guix/2016-02-03#T898859>. * emacs/guix-base.el: Require 'guix-profiles'. * emacs/guix-ui.el: Likewise. * emacs/guix-ui-generation.el: Likewise. * emacs/guix-ui-package.el: Likewise. Alex Kost 2016-02-01emacs: command: Disambiguate "w" key in build options....This is a followup to commit 47c0f92c37dc7d50d9d4598ce5b91c4cdfec6ed1. * emacs/guix-command.el (guix-command-improve-common-build-argument): Use "W" key for '--with-input' option (leave "w" for '--with-source'). Alex Kost 2016-01-29guix system: Rename 'dmd-graph' to 'shepherd-graph'....* doc/images/dmd-graph.dot: Rename to... * doc/images/shepherd-graph.dot: ... this. * doc.am (DOT_FILES): Adjust accordingly. * guix/scripts/system.scm (dmd-service-node-label) (dmd-service-node-type, export-dmd-graph): Rename to... (shepherd-service-node-label, shepherd-service-node-type) (export-shepherd-graph): ... this. (show-help, process-action, process-command): Rename 'dmd-graph' to 'shepherd-graph'. * emacs/guix-command.el (guix-command-additional-execute-arguments) (guix-command-special-executors): Likewise. * doc/guix.texi: Likewise. * doc/emacs.texi (Emacs Popup Interface): Likewise. Alex Kost