diff options
Diffstat (limited to 'tests/generate-tests.lisp')
-rw-r--r-- | tests/generate-tests.lisp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/generate-tests.lisp b/tests/generate-tests.lisp new file mode 100644 index 0000000..da1301b --- /dev/null +++ b/tests/generate-tests.lisp @@ -0,0 +1,54 @@ +;; This file is part of eris-cl. +;; Copyright (C) 2022 Piotr SzarmaĆski + +;; eris-cl is free software: you can redistribute it and/or modify it under the +;; terms of the GNU Lesser General Public License as published by the Free +;; Software Foundation, either version 3 of the License, or (at your option) any +;; later versqion. + +;; eris-cl 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 +;; eris-cl. If not, see <https://www.gnu.org/licenses/>. + +;; This generates the autogenerated-tests.lisp file. It requires you to tar -xf +;; the test vectors tarball right in the tests directory. +;; Also requires the jonathan package in addition to the regular dependencies. + +(asdf:load-system :jonathan) +(defpackage :eris-json-files + (:use common-lisp jonathan)) + +(in-package :eris-json-files) +(defparameter *json-files* (loop for i from 0 to 12 collecting (format nil "test-vectors/eris-test-vector-positive-~2,'0d.json" i))) +(defparameter *json-files-negative* (loop for i from 13 to 24 collecting (format nil "test-vectors/eris-test-vector-negative-~2,'0d.json" i))) + + +(defmacro with-json (json &body expr) + (alexandria:with-gensyms (json-sym) + `(let ((,json-sym (jonathan:parse ,json))) + (macrolet ((json (symbol) (list (quote getf) (quote ,json-sym) symbol))) + ,@expr)))) + +(with-open-file (stream "autogenerated-tests.lisp" :direction :output :if-does-not-exist :create :if-exists :supersede) + (format stream ";;;; Autogenerated file.~%") + (print '(in-package :eris/test) stream) + (print '(def-suite* machine-generated-tests :in eris-tests) stream) + (map 'nil (lambda (file) + (with-json (with-open-file (json-file file) + (alexandria:read-stream-content-into-string json-file)) + (print `(test ,(intern (format nil "test-~d" (json :|id|)) *package*) + (positive-test ,(json :|urn|) ,(json :|content|) (quote ,(json :|blocks|)) ,(json :|convergence-secret|) ,(json :|block-size|))) + stream))) + *json-files*) + + (map 'nil (lambda (file) + (with-json (with-open-file (json-file file) + (alexandria:read-stream-content-into-string json-file)) + (print `(test ,(intern (format nil "test-~d" (json :|id|)) *package*) + (negative-test ,(json :|urn|) (quote ,(json :|blocks|)))) + stream))) + *json-files-negative*)) + |