;;;; dynamic-import-test.scm -*- Scheme -*- ;;;; Kon Lovett, Feb '22 (import test) (import (test-utils gloss)) (import (only (chicken format) format)) (test-begin "Dynamic Import") ;;; (import dynamic-import) ;NOTE copy-n-paste from source since exporting for testing is still pollution ;(srfi 1) (import (chicken fixnum)) (define (make-list len elt) ;elt optional but here always provided (do ((i len (fx- i 1)) (ans '() (cons elt ans))) ((fx<= i 0) ans)) ) (define (make-list/as df) (case-lambda (() df) ((n) (cond ((fixnum? n) (make-list n df)) ((list? n) (make-list (length n) df)) (else (error 'make-list/as "invalid length specification" n df)) ) ) ) ) (test-group "\"Catching\" Warnings" (define +warns+ '()) ;NOTE disable to see warnings during the test (enable-warnings #f) (dynamic-import-warning (lambda args (set! +warns+ (cons args +warns+)))) (define falses (make-list/as #f)) (test-group "Low Level" (test #f (apply values (dynamic-importer '(foo) '(m1) falses))) (test '(23 32) (dynamic-importer '(foo bar) '(m1 m2) '(23 32))) (test #f (apply values (dynamic-importer '(bar) '(m1 srfi-1) falses))) (test 23 (apply values (dynamic-importer '(baz) '(m1 srfi-1) (make-list/as 23)))) ) (test-group "Higher Level" (dynamic-import append-reverse! srfi-1 falses) (test-assert (procedure? append-reverse!)) (dynamic-import (delete-duplicates delete-duplicates!) (foo bar baz srfi-1) falses) (test-assert (procedure? delete-duplicates)) (test-assert (procedure? delete-duplicates!)) (dynamic-import foobar (m1 srfi-1) (default 23)) (test 23 foobar) ) ;(gloss "warnings" +warns+) (test "\"Caught\" warnings" 5 (length +warns+)) ) ;;; (test-end "Dynamic Import") (test-exit)