guile-rdf/test-modules/download-tests.scm

download-tests.scm

1
;;;; Copyright (C) 2020 Julien Lepiller <julien@lepiller.eu>
2
;;;;
3
;;;; This library is free software; you can redistribute it and/or
4
;;;; modify it under the terms of the GNU Lesser General Public
5
;;;; License as published by the Free Software Foundation; either
6
;;;; version 3 of the License, or (at your option) any later version.
7
;;;;
8
;;;; This library is distributed in the hope that it will be useful,
9
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
10
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
;;;; Lesser General Public License for more details.
12
;;;;
13
;;;; You should have received a copy of the GNU Lesser General Public
14
;;;; License along with this library; if not, write to the Free Software
15
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
;;;;
17
18
(define-module (test-modules download-tests)
19
  #:use-module (ice-9 match)
20
  #:use-module (rnrs bytevectors)
21
  #:use-module (test-modules test-case)
22
  #:use-module (test-modules testsuite)
23
  #:use-module (turtle tordf)
24
  #:use-module (web client)
25
  #:use-module (web response)
26
  #:export (download-test-files))
27
28
(define test-dir "test-files")
29
30
(define base-url "http://www.w3.org/2013/")
31
32
(define (get-test-doc url)
33
  "Get a test suite object from the manifest at @var{url}."
34
  (call-with-values
35
    (lambda ()
36
      (http-get url))
37
    (lambda (hdr body)
38
      (if (equal? (response-code hdr) 200)
39
          (if (string? body)
40
              body
41
              (utf8->string body))
42
          (throw 'error-fetching-test-manifest (response-code hdr))))))
43
44
(define (mkdir-p dir)
45
  (unless (file-exists? dir)
46
    (mkdir-p (dirname dir))
47
    (mkdir dir)))
48
49
(define (download url)
50
  (let ((filename (string-append test-dir "/"
51
                                 (substring url (string-length base-url)))))
52
    (mkdir-p (dirname filename))
53
    (call-with-output-file filename
54
      (lambda (port)
55
        (display (get-test-doc url) port)))))
56
57
(define (download-test-files)
58
  (for-each
59
    (lambda (manifest)
60
      (pk 'downloading manifest)
61
      (download manifest)
62
      (let ((plan (rdf->test-plan
63
                    (turtle->rdf (get-test-doc manifest) manifest)
64
                    manifest)))
65
        (for-each
66
          (lambda (test)
67
            (download (test-case-action test))
68
            (when (test-case-result test)
69
              (download (test-case-result test))))
70
          plan)))
71
    manifests))
72
73
(download-test-files)
74