| 1 |
;; Testing autoload subtleties part 2 |
| 2 |
;; This is splitted from test/load.scm, since these tests here uses |
| 3 |
;; object system, so we want them to run after test/object.scm. |
| 4 |
|
| 5 |
(use gauche.test) |
| 6 |
|
| 7 |
(test-start "autoload and autoprovide") |
| 8 |
|
| 9 |
(add-load-path ".") |
| 10 |
|
| 11 |
;;--------------------------------------------------------------- |
| 12 |
(test-section "autoload and implicit generic definition") |
| 13 |
|
| 14 |
(sys-system "rm -rf test.o") |
| 15 |
(sys-mkdir "test.o" #o777) |
| 16 |
(with-output-to-file "test.o/a.scm" |
| 17 |
(lambda () |
| 18 |
(write '(autoload "test.o/b" foo1 foo2)) |
| 19 |
(write '(define-method foo1 ((x <string>)) 'foo1-string)) |
| 20 |
(write '(define-method foo2 ((x <string>)) 'foo2-string)) |
| 21 |
(write '(provide #f)) |
| 22 |
)) |
| 23 |
(with-output-to-file "test.o/b.scm" |
| 24 |
(lambda () |
| 25 |
(write '(define-method foo1 ((x <list>)) 'foo1-list)) |
| 26 |
(write '(define-method foo2 ((x <list>)) 'foo2-list)) |
| 27 |
(write '(provide #f)) |
| 28 |
)) |
| 29 |
|
| 30 |
(test* "autoload triggered by implicit generic definition" 'foo1-list |
| 31 |
(and (load "test.o/a") (foo1 '()))) |
| 32 |
|
| 33 |
(test* "autoload triggered by implicit generic definition" 'foo2-list |
| 34 |
(foo2 '())) |
| 35 |
|
| 36 |
(sys-system "rm -rf test.o") |
| 37 |
|
| 38 |
;;--------------------------------------------------------------- |
| 39 |
(test-section "autoload and class redefinition check") |
| 40 |
|
| 41 |
(sys-mkdir "test.o" #o777) |
| 42 |
(with-output-to-file "test.o/a.scm" |
| 43 |
(lambda () |
| 44 |
(write '(autoload "test.o/b" <foo>)) |
| 45 |
(write '(define-class <foo> () ((x) (y :init-value 'y)))) |
| 46 |
(write '(provide #f)) |
| 47 |
)) |
| 48 |
(with-output-to-file "test.o/b.scm" |
| 49 |
(lambda () |
| 50 |
(write '(define-class <foo> () ((x :init-value 'x)))) |
| 51 |
(write '(define *foo* (make <foo>))) |
| 52 |
(write '(provide #f)) |
| 53 |
)) |
| 54 |
|
| 55 |
(test* "autoload triggered by class redefinition check" 'y |
| 56 |
(and (load "test.o/a") |
| 57 |
(slot-ref *foo* 'y))) |
| 58 |
|
| 59 |
(sys-system "rm -rf test.o") |
| 60 |
|
| 61 |
;;--------------------------------------------------------------- |
| 62 |
(test-section "circular autoload") |
| 63 |
|
| 64 |
(sys-mkdir "test.o" #o777) |
| 65 |
(with-output-to-file "test.o/a.scm" |
| 66 |
(lambda () |
| 67 |
(write '(autoload "test.o/b" <bar>)) |
| 68 |
(write '(define-class <bar> () ())) |
| 69 |
(write '(provide #f)) |
| 70 |
)) |
| 71 |
(with-output-to-file "test.o/b.scm" |
| 72 |
(lambda () |
| 73 |
(write '(define-method bar ((x <bar>)) x)) |
| 74 |
(write '(provide #f)) |
| 75 |
)) |
| 76 |
|
| 77 |
(test* "circular-autoload" (test-error) |
| 78 |
(load "test.o/a")) |
| 79 |
|
| 80 |
(sys-system "rm -rf test.o") |
| 81 |
|
| 82 |
;;--------------------------------------------------------------- |
| 83 |
(test-section "autoprovide feature") |
| 84 |
|
| 85 |
(sys-mkdir "test.o" #o777) |
| 86 |
|
| 87 |
(test* "autoprovide - basic" #t |
| 88 |
(begin |
| 89 |
(with-output-to-file "test.o/autoprovide-a.scm" |
| 90 |
(lambda () (write 1))) |
| 91 |
(eval '(require "test.o/autoprovide-a") (interaction-environment)) |
| 92 |
(provided? "test.o/autoprovide-a"))) |
| 93 |
|
| 94 |
(test* "autoprovide - providing different feature" '(#f #t #t) |
| 95 |
(begin |
| 96 |
(with-output-to-file "test.o/autoprovide-b.scm" |
| 97 |
(lambda () |
| 98 |
(write '(provide "test.o/autoprovide-bb")) |
| 99 |
(write '(provide "test.o/autoprovide-ba")))) |
| 100 |
(eval '(require "test.o/autoprovide-b") (interaction-environment)) |
| 101 |
(list (provided? "test.o/autoprovide-b") |
| 102 |
(provided? "test.o/autoprovide-ba") |
| 103 |
(provided? "test.o/autoprovide-bb")))) |
| 104 |
|
| 105 |
(test* "autoprovide - disabling autoprovide" #f |
| 106 |
(begin |
| 107 |
(with-output-to-file "test.o/autoprovide-c.scm" |
| 108 |
(lambda () (write '(provide #f)))) |
| 109 |
(eval '(require "test.o/autoprovide-c") (interaction-environment)) |
| 110 |
(provided? "test.o/autoprovide-c"))) |
| 111 |
|
| 112 |
(test* "autoprovide - cascading require" '(#f #t) |
| 113 |
(begin |
| 114 |
(with-output-to-file "test.o/autoprovide-d.scm" |
| 115 |
(lambda () |
| 116 |
(write '(require "test.o/autoprovide-e")) |
| 117 |
(write '(provide #f)))) |
| 118 |
(with-output-to-file "test.o/autoprovide-e.scm" |
| 119 |
(lambda () (write 1))) |
| 120 |
(eval '(require "test.o/autoprovide-d") (interaction-environment)) |
| 121 |
(list (provided? "test.o/autoprovide-d") |
| 122 |
(provided? "test.o/autoprovide-e")))) |
| 123 |
|
| 124 |
(sys-system "rm -rf test.o") |
| 125 |
|
| 126 |
|
| 127 |
;; relative load path ------------------------------- |
| 128 |
|
| 129 |
(test-section "relative load path") |
| 130 |
|
| 131 |
(test* "relative load path" "ok!" |
| 132 |
;; avoid using process-output->string since it is tested after |
| 133 |
;; this file. |
| 134 |
(begin |
| 135 |
(cond-expand |
| 136 |
[gauche.os.windows |
| 137 |
(let1 gosh (or (sys-getenv "TESTGOSH") ".\\gosh") |
| 138 |
(sys-system #"~gosh -ftest ..\\test\\relative-load-path > test.o"))] |
| 139 |
[else |
| 140 |
(let1 gosh (or (sys-getenv "TESTGOSH") "./gosh") |
| 141 |
(sys-system #"~gosh -ftest ../test/relative-load-path > test.o"))]) |
| 142 |
(rlet1 r (with-input-from-file "test.o" read-line) |
| 143 |
(sys-unlink "test.o")))) |
| 144 |
|
| 145 |
(test-end) |