From ed4281ff072443167c43207c039570126061d23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 12 Apr 2022 13:30:32 +0200 Subject: Add a lot of new unit tests. --- tests/convert.scm | 69 ++++++++++++ tests/test/crypto.scm | 3 + tests/test/datetime.scm | 214 +++++++++++++++++++++++++++++++++++-- tests/test/html/caltable.scm | 105 ++++++++++++++++++ tests/test/html/component.scm | 59 ++++++++++ tests/test/recurrence-advanced.scm | 34 +++++- tests/test/srfi-41-util.scm | 58 ++++++++-- tests/test/translation.scm | 15 +++ tests/test/util.scm | 148 ++++++++++++++++++++++--- tests/test/uuid.scm | 12 +++ 10 files changed, 683 insertions(+), 34 deletions(-) create mode 100644 tests/convert.scm create mode 100644 tests/test/html/caltable.scm create mode 100644 tests/test/html/component.scm create mode 100644 tests/test/translation.scm create mode 100644 tests/test/uuid.scm (limited to 'tests') diff --git a/tests/convert.scm b/tests/convert.scm new file mode 100644 index 00000000..534c5b70 --- /dev/null +++ b/tests/convert.scm @@ -0,0 +1,69 @@ +(add-to-load-path "../module") + +(use-modules (ice-9 documentation) + (ice-9 format) + (srfi srfi-1) + (hnh util path) + (datetime) + ) + +(print-set! quote-keywordish-symbols #f) + +(define (module-definition name old-sandbox-definition) + `(define-module (test ,name) + :use-module (srfi srfi-64) + :use-module (srfi srfi-88) + ,@(concatenate + (map (lambda (def) `(:use-module (,(car def) :select ,(cdr def)))) + old-sandbox-definition)))) + +(define (read-multiple port) + (let loop ((done '())) + (let ((sexp (read port))) + (if (eof-object? sexp) + (reverse done) + (loop (cons sexp done)))))) + +(define files + '("annoying-events.scm" + "base64.scm" + "cpp.scm" + "datetime-compare.scm" + "datetime.scm" + "datetime-util.scm" + "let-env.scm" + "let.scm" + "param.scm" + "recurrence-advanced.scm" + "recurrence-simple.scm" + "rrule-serialization.scm" + "server.scm" + "srfi-41-util.scm" + "termios.scm" + "tz.scm" + "util.scm" + "vcomponent-control.scm" + "vcomponent-datetime.scm" + "vcomponent-formats-common-types.scm" + "vcomponent.scm" + "web-server.scm" + "xcal.scm" + "xml-namespace.scm" + )) + +(for-each (lambda (file) + (format #t "~a~%" file) + (call-with-output-file (path-append "test" (basename file)) + (lambda (p) + (define commentary (file-commentary file)) + (unless (string-null? commentary) + (format p ";;; Commentary:~%") + (for-each (lambda (line) (format p ";; ~a~%" line)) + (string-split commentary #\newline)) + (format p ";;; Code:~%~%")) + (let ((forms (call-with-input-file file read-multiple))) + (format p "~y~%" (module-definition (string->symbol (string-drop-right file 4)) + (car forms))) + (format p "~{~y~%~}~%" (cdr forms)))))) + files) + diff --git a/tests/test/crypto.scm b/tests/test/crypto.scm index 71ecfc99..8d195fa8 100644 --- a/tests/test/crypto.scm +++ b/tests/test/crypto.scm @@ -13,3 +13,6 @@ (test-equal "sha256 string digest to port" "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969" (get-output-string port))) + +(test-error 'wrong-type-arg + (sha256 'something-which-is-not-a-string-or-bytevector)) diff --git a/tests/test/datetime.scm b/tests/test/datetime.scm index d9c08ec2..8648006b 100644 --- a/tests/test/datetime.scm +++ b/tests/test/datetime.scm @@ -12,7 +12,7 @@ :use-module ((ice-9 format) :select (format)) :use-module ((hnh util) :select (let*)) :use-module ((ice-9 i18n) :select (make-locale)) - :use-module ((guile) :select (LC_TIME))) + :use-module ((guile) :select (LC_CTYPE LC_TIME))) (test-equal "empty time" @@ -55,6 +55,17 @@ "~a" #2020-01-01)) +(test-equal "time print" + "#20:30:40" + (format #f "~a" #20:30:40)) + +(test-equal "time print bad" + "#<