Changeset 39580 in project
- Timestamp:
- 02/06/21 17:30:14 (4 weeks ago)
- Location:
- release/5/simple-tests/tags/3.0
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
release/5/simple-tests/tags/3.0/simple-tests.egg
r39512 r39580 4 4 (category testing) 5 5 (license "BSD") 6 (version " 2.3.2")6 (version "3.0") 7 7 (author "Juergen Lorenz") 8 (components (extension simple-tests 9 (csc-options "-O3" "-d0")))) 8 (component-options (csc-options "-O3" "-d1")) 9 (components (extension simple-tests))) 10 -
release/5/simple-tests/tags/3.0/simple-tests.scm
r39512 r39580 1 2 ; Author: Juergen Lorenz 3 ; ju (at) jugilo (dot) de 4 ; 5 ; Copyright (c) 2011-2021, Juergen Lorenz 1 ; Copyright (c) 2013-2021 , Juergen Lorenz, ju (at) jugilo (dot) de 6 2 ; All rights reserved. 7 3 ; … … 16 12 ; notice, this list of conditions and the following disclaimer in the 17 13 ; documentation and/or other materials provided with the distribution. 18 ;19 14 ; Neither the name of the author nor the names of its contributors may be 20 15 ; used to endorse or promote products derived from this software without 21 16 ; specific prior written permission. 22 ; 17 ; 23 18 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 19 ; IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED … … 32 27 ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 28 ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 ; 29 30 35 31 36 32 #|[ 37 33 This is a simple Unit Test Framework inspired by Peter Seibel's 38 34 "Practical Common Lisp" together with some routines which might be 39 useful for debugging. 40 A second test interface is added with version 2.0 41 ]|# 42 35 useful for debugging. It underwent several changes in the maintenance 36 process, most of them are now marked deprecated but are still there in 37 favor of backwards compatibility. 38 39 For the future, it's sufficient to use only the following six routines, 40 the parameter verbose? and the macros pe, ppp, check, make-tester and 41 test-all. 42 43 pe, ppp and check are mostly used in the development phase, make-tester 44 and test-all are the actual test routines to go into tests/run.scm. 45 46 A tester is a nullary predicate which produces a lot of information as 47 side-effects provided the parameter verbose? is true. These testers are 48 invoked in test-all. 49 50 pe is a combination of pretty-print and expand enhanced with additional 51 text; ppp pretty-prints a list of expressions and its values, while 52 check does the same but accompanies these computed values with expected 53 ones, allowing for local variables in the checks. 54 ]|# 43 55 44 56 (module simple-tests ( 45 ; common46 simple-tests57 verbose? 58 writeln 47 59 and? 48 writeln49 60 pe 61 xpr:val 50 62 ppp 51 63 ppp* 64 xpr:val* 52 65 ppp** 53 xpr:val54 xpr:val*66 (define-test *failures* *locations*) 67 (compound-test *failures* group-on-cdrs) 55 68 == 56 ; old interface57 define-test58 (compound-test group-on-cdrs)59 *locations*60 *failures*61 ; new interface62 69 check 63 70 define-checks 64 71 do-checks 65 (check-all check-all-proc) 72 define-tester 73 (test-all test-all-proc) 74 (check-all test-all-proc) 75 simple-tests 66 76 ) 67 77 68 (import scheme (chicken base) (chicken syntax) (chicken pretty-print)) 78 (import scheme 79 (only (chicken base) 80 print case-lambda cut chop exit receive make-parameter) 81 (only (chicken syntax) expand) 82 (only (chicken module) import-for-syntax) 83 (only (chicken pretty-print) pp) 84 ) 69 85 70 86 (import-for-syntax (only (chicken base) chop)) … … 72 88 ;;;;;; Common interface ;;;;;; 73 89 74 ;;; (simple-tests [sym]) 75 ;;; --------------------- 76 ;;; documentation procedure 77 (define simple-tests 78 (let ( 79 (signatures '((simple-tests 80 procedure: 81 (simple-tests sym ..) 82 "documentation procedure") 83 (and? 84 procedure: 85 (and? xpr ...) 86 "Pascal like and procedure") 87 (writeln 88 procedure: 89 (writeln xpr ....) 90 "write analog of print") 91 (pe 92 procedure: 93 (pe macro-code) 94 " composes pretty-print and expand") 95 (ppp 96 macro: 97 (ppp xpr ...) 98 " print each xpr quoted in a headline" 99 "and pretty-print xpr's computed value") 100 (ppp* 101 macro: 102 (ppp* xpr ypr . xpr-yprs) 103 "print each xpr quoted in a headline" 104 "and pretty-print xpr's computed and" 105 "expected value, ypr") 106 (ppp** 107 macro: 108 (ppp** ((var val) ...) xpr ypr . xpr-yprs) 109 "wraps ppp* into a let") 110 (xpr:val 111 macro: 112 (xpr:val xpr ...) 113 "alias to ppp") 114 (xpr:val* 115 macro: 116 (xpr:val* xpr ypr . xpr-yprs) 117 "alias to ppp*") 118 (== 119 procedure: 120 (==) 121 (== x) 122 (== type? type-equal?) 123 "generic type equality as curried procedure:" 124 "the first resets the local database," 125 "the second is the curried equality check" 126 "and the third adds a new equality procedure" 127 "to the local database") 128 129 (define-test 130 macro: 131 (define-test (name . parameters) form . forms) 132 "creates a test function") 133 (compound-test 134 macro: 135 (compound-test (name) test . tests) 136 "checks all tests created with define-test" 137 "and reports a summary of results") 138 139 (check 140 macro: 141 (check ((var val) ...) xpr ypr . xpr-yprs) 142 "compares xpr and ypr .... with == in the" 143 "environment defined by (var val) ...") 144 (define-checks 145 macro: 146 (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs) 147 "returns a unary predicate, name?," 148 "comparing xpr with ypr ...." 149 "and using var val ... within this checks." 150 "verbose? controls the reported results") 151 (do-checks 152 macro: 153 (do-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs) 154 "alias to define-checks") 155 (check-all 156 macro: 157 (check-all name check-xpr ....) 158 "checks all check-expressions created by do-check" 159 "and reports the results"))) 160 ) 161 (case-lambda 162 (() (map car signatures)) 163 ((sym) 164 (let ((pair (assq sym signatures))) 165 (if pair 166 (for-each print (cdr pair)) 167 (print "Choose one of " (map car signatures)))))))) 168 90 #|[ 91 (verbose? ..) 92 --- parameter --- 93 gets or sets the value of the parameter verbose? 94 ]|# 95 (define verbose? 96 (make-parameter #t 97 (lambda (x) 98 (if (not x) 99 x 100 #t)))) 101 102 #|[ 103 (writeln xpr ...) 104 --- procedure --- 105 write analog of print, expressions separated by whitespace 106 ]|# 169 107 (define (writeln . args) 170 108 (for-each (lambda (a) … … 174 112 (newline)) 175 113 176 ;;; (and? . xprs) 177 ;;; ------------- 178 ;;; non-short-circuited and which executes all side-effects 114 #|[ 115 (and? . xprs) 116 --- procedure --- 117 non-short-circuited and which executes all side-effects 118 ]|# 179 119 (define (and? . xprs) 180 120 (let ((result #t)) … … 183 123 result)) 184 124 185 ;;; (pe macro-code) 186 ;;; --------------- 187 ;;; composes pretty-print and expand 125 #|[ 126 (pe macro-code) 127 --- macro --- 128 composes pretty-print and expand, 129 does nothing in compiled code. 130 ]|# 188 131 (define (pe macro-code) 189 (pp (expand macro-code))) 190 191 #|[ 192 The following macro, xpr:val, pretty-prints the literal representation 193 of each of its arguments as well as their respective values. The call 194 to eval-when guarantees, that the whole expression does nothing in 195 compiled code. 196 ]|# 197 198 ;;; (xpr:val xpr ...) 199 ;;; ----------------- 200 ;;; print each xpr quoted in a headline and pretty-print xpr's computed 201 ;;; value. 132 (cond-expand 133 ((not compiling) 134 (newline) 135 (print "Macro expansion:") 136 (print "----------------") 137 (pp macro-code) 138 (print "->") 139 (pp (expand macro-code)) 140 (print "----------------") 141 (newline)) 142 (else))) 143 144 ;;; The following macro, xpr:val, pretty-prints the literal representation 145 ;;; of each of its arguments as well as their respective values. The call 146 ;;; to eval-when guarantees, that the whole expression does nothing in 147 ;;; compiled code. 148 149 #|[ 150 (xpr:val xpr ...) 151 --- macro --- 152 Deprecated! 153 Print each xpr quoted in a headline and pretty-print xpr's computed 154 value. 155 ]|# 202 156 (define-syntax xpr:val 203 157 (syntax-rules () … … 212 166 (else))))) 213 167 214 ;;; (ppp xpr ...) 215 ;;; ------------- 216 ;;; print each xpr quoted in a headline and pretty-print xpr's computed 217 ;;; value. Alias to xpr:val. 168 #|[ 169 (ppp xpr ...) 170 --- macro --- 171 print each xpr quoted in a headline and pretty-print xpr's computed 172 value. Alias to xpr:val. 173 ]|# 218 174 (define-syntax ppp 219 175 (syntax-rules () 220 176 ((_ xpr ...) 221 (xpr:val xpr ...)))) 177 (cond-expand 178 ((not compiling) 179 (begin (print "Computing " 'xpr " ...") 180 (pp xpr) 181 ) 182 ... 183 ) 184 (else))))) 222 185 223 186 (define-syntax help-ppp* ; internal … … 235 198 )) 236 199 ; 237 ;;;; (ppp* {xpr ypr} ...) 238 ;;; -------------------- 239 ;;; print each xpr quoted in a headline and pretty-print xpr's computed 240 ;;; and expected value, ypr. 200 #|[ 201 (ppp* {xpr ypr} ...) 202 --- macro --- 203 Deprecated! 204 Print each xpr quoted in a headline and pretty-print xpr's computed 205 and expected value, ypr. 206 ]|# 241 207 (define-syntax ppp* 242 208 (syntax-rules () … … 247 213 (else))))) 248 214 249 ;;; (xpr:val* {xpr ypr} ...) 250 ;;; ------------------------ 251 ;;; print each xpr quoted in a headline and pretty-print xpr's computed 252 ;;; and expected value, ypr. 253 ;;; Alias to ppp* 254 (define-syntax xpr:val* 215 #|[ 216 (xpr:val* {xpr ypr} ...) 217 --- macro --- 218 Deprecated! 219 Print each xpr quoted in a headline and pretty-print xpr's computed 220 and expected value, ypr. 221 Alias to ppp* 222 ]|# 223 (define-syntax xpr:val* ; deprecated 255 224 (syntax-rules () 256 225 ((_ . pairs) 257 226 (ppp* . pairs)))) 258 227 259 ;;; (ppp** ((var val) ...) xpr ypr . other xpr-ypr-pairs) 260 ;;; ----------------------------------------------------- 261 ;;; ppp* wrapped into a let 228 #|[ 229 (ppp** ((var val) ...) xpr ypr . other-xpr-ypr-pairs) 230 --- macro --- 231 Deprecated! 232 ppp* wrapped into a let 233 ]|# 262 234 (define-syntax ppp** 263 235 (syntax-rules () … … 268 240 ;;;;;;;; old interface ;;;;;;;;; 269 241 270 ;; helper macro because I don't want to export it 271 (define-syntax disp 242 (define-syntax disp ; internal 272 243 (syntax-rules () 273 244 ((_) … … 277 248 ;;; ------------------------ 278 249 ;;; reports succuss or failure of form and updates failures if necessary 279 (define-syntax report-result 250 (define-syntax report-result ; internal 280 251 (syntax-rules () 281 252 ((_ loc form) … … 299 270 #f))))) 300 271 301 ;;; (check-em . forms) ;; internal272 ;;; (check-em . forms) 302 273 ;;; ------------------ 303 274 ;;; report result of all forms 304 (define-syntax check-em 275 (define-syntax check-em ; internal 305 276 (syntax-rules () 306 277 ((_ form ...) … … 309 280 ...))))) 310 281 311 ;; internal helper 312 (define-syntax show-args 282 (define-syntax show-args ; internal 313 283 (syntax-rules () 314 284 ((_ (name arg ...)) … … 316 286 ((_ arg) arg))) 317 287 318 ;;; (define-test (name . parameters) form . forms) 319 ;;; ---------------------------------------------- 320 ;;; creates a test function 288 #|[ 289 (define-test (name . parameters) form . forms) 290 --- macro *locations* *failures* --- 291 Deprecated! 292 Creates a test function 293 ]|# 321 294 (define-syntax define-test 322 295 (syntax-rules () … … 329 302 ((check-em form . forms) *locations*)))))) 330 303 331 ;;; (compound-test (name) test . tests) 332 ;;; ----------------------------------- 333 ;;; invokes all tests and reports a summary 304 #|[ 305 (compound-test (name) test . tests) 306 --- macro group-on-cdrs *failures* --- 307 Deprecated! 308 Invokes all tests and reports a summary 309 ]|# 334 310 (define-syntax compound-test 335 311 (syntax-rules () 336 312 ((_ (name) test0 test1 ...) 337 313 (begin 314 (writeln "XXX" 'test0 test0 test1 ...) ;;;;; 315 (writeln "YYY" (and? test0 test1 ...)) ;;;;; 338 316 (print "\nTesting " 'name " ...") 339 317 (print "----------------------------") … … 362 340 (exit 1)))))))) 363 341 364 ;;; internal helper from bindings342 ;;; internal helper 365 343 (define (filter ok? lst) 366 344 (let loop ((lst lst) (yes '()) (no '())) … … 383 361 (loop no (cons yes result)))))) 384 362 363 ;;;*failures* 364 ;;; ---------- 365 ;;; Deprecated! 366 ;;; global variable 367 (define *failures* '()) 368 385 369 ;;; *locations* 386 370 ;;; ----------- 387 ;;; dynamic variable 371 ;;; Deprecated! 372 ;;; global variable 388 373 (define *locations* '()) 389 390 ;;; *failures*391 ;;; ----------392 ;;; global variable collecting failure information393 (define *failures* '())394 374 395 375 ;;;;;;; new interface ;;;;;;;;;;; … … 401 381 ; (string=? (symbol->string x) (symbol->string y))) 402 382 403 ;;; (==) 404 ;;; (== x) 405 ;;; (== type? type-equal?) 406 ;;; ---------------------- 407 ;;; generic type equality as curried procedure 383 #|[ 384 (==) 385 (== x) 386 (== type? type-equal?) 387 --- procedure --- 388 Deprecated! 389 Generic type equality as curried procedure 390 ]|# 408 391 (define == 409 392 (let* ((pairs (list (cons pair? (curry equal?)) … … 438 421 ;;; (check* ((var val) ...) xpr ypr . xpr-yprs) ;; internal 439 422 ;;; -------------------------------------------------------------- 423 (define-syntax check* ; internal 424 (ir-macro-transformer 425 (lambda (form inject compare?) 426 (let ((var-vals (cadr form)) 427 (xpr-yprs (cddr form)) 428 (select-failures 429 (lambda (pairs) 430 (let loop ((pairs pairs)) 431 (cond 432 ((null? pairs) '()) 433 ((caar pairs) (loop (cdr pairs))) 434 (else 435 (cons (car pairs) (loop (cdr pairs)))))))) 436 ) 437 `(lambda (verbose?) 438 (letrec ,var-vals 439 (let ((tests '())) 440 ,@(map (lambda (p) 441 `(begin 442 (let ((x ,(car p))) 443 ; protect against functions changing state 444 (when verbose? 445 (print "testing " ',(car p) " ...") 446 (print* "computed: ") (writeln x) 447 (print* "expected: ") (writeln ,(cadr p)) 448 ) 449 (set! tests 450 (cons (cons ((cut equal? <> x) ,(cadr p)) 451 ',(car p)) 452 tests))) 453 ;(cons (cons ((== x) ,(cadr p)) ',(car p)) 454 ; tests))) 455 )) 456 (chop xpr-yprs 2)) 457 (let ((fails (,select-failures (reverse tests)))) 458 (when verbose? 459 (print "Failed test expressions:") 460 (print "------------------------") 461 (if (null? fails) 462 (print "none") 463 (for-each print (map cdr fails)))) 464 (if (null? fails) #t #f))))) 465 )))) 440 466 ;(define-syntax check* 441 467 ; (er-macro-transformer … … 495 521 ; (,%if (,%null? ,%fails) #t #f))))) 496 522 ; )))) 497 (define-syntax check* 498 (ir-macro-transformer 499 (lambda (form inject compare?) 500 (let ((var-vals (cadr form)) 501 (xpr-yprs (cddr form)) 502 (select-failures 503 (lambda (pairs) 504 (let loop ((pairs pairs)) 505 (cond 506 ((null? pairs) '()) 507 ((caar pairs) (loop (cdr pairs))) 508 (else 509 (cons (car pairs) (loop (cdr pairs)))))))) 510 ) 511 `(lambda (verbose?) 512 (letrec ,var-vals 513 (let ((tests '())) 514 ,@(map (lambda (p) 515 `(begin 516 (let ((x ,(car p))) 517 ; protect against functions changing state 518 (when verbose? 519 (print "testing " ',(car p) " ...") 520 (print* "computed: ") (writeln x) 521 (print* "expected: ") (writeln ,(cadr p)) 522 ) 523 (set! tests 524 (cons (cons ((== x) ,(cadr p)) ',(car p)) 525 tests))) 526 )) 527 (chop xpr-yprs 2)) 528 (let ((fails (,select-failures (reverse tests)))) 529 (when verbose? 530 (print "Failed test expressions:") 531 (print "------------------------") 532 (if (null? fails) 533 (print "none") 534 (for-each print (map cdr fails)))) 535 (if (null? fails) #t #f))))) 536 )))) 537 ;;; (check ((var val) ...) xpr ypr . xpr-yprs) 538 ;;; ------------------------------------------ 539 ;;; compare xpr and ypr .... in sequence with == 540 ;;; in the environment defined by var val ... 523 #|[ 524 (check ((var val) ...) xpr ypr . xpr-yprs) 525 --- macro --- 526 Compare xpr and ypr .... in sequence with equal? 527 in the environment defined by var val ... 528 ]|# 541 529 (define-syntax check 542 530 (syntax-rules () … … 544 532 ((check* ((var val) ...) xpr ypr . xpr-yprs) #t)))) 545 533 546 ;;; (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs) 547 ;;; -------------------------------------------------------------- 548 ;;; returns a unary predicate, name?, comparing xpr with ypr .... 549 ;;; and using var val ... within this checks, 550 ;;; verbose? controls the reported summary. 534 #|[ 535 (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs) 536 --- macro --- 537 Deprecated! 538 Returns a unary predicate, name?, comparing xpr with ypr .... 539 and using var val ... within this checks, 540 verbose? controls the reported summary. 541 ]|# 551 542 (define-syntax define-checks 552 543 (ir-macro-transformer … … 572 563 ,@xpr-yprs) ,verbose?))))))))) 573 564 574 ;;; (do-checks (name? verbose? . var-val-pairs) xpr ypr . xpr-yprs) 575 ;;; --------------------------------------------------------------- 576 ;;; returns a unary predicate, name?, comparing xpr with ypr .... 577 ;;; and using var val ... within this checks, 578 ;;; alias to define-checks 565 #|[ 566 (do-checks (name? verbose? . var-val-pairs) xpr ypr . xpr-yprs) 567 --- macro --- 568 Deprecated! 569 Returns a unary predicate, name?, comparing xpr with ypr .... 570 and using var val ... within this checks, 571 alias to define-checks 572 ]|# 579 573 (define-syntax do-checks 580 574 (syntax-rules () … … 583 577 xpr ypr . xpr-ypr-pairs)))) 584 578 585 (define (check-all-proc name . test-name-pairs) ; internal to check-all 586 ; used internally in check-all, must be exported within check-all 579 #|[ 580 (define-tester (name? . var-vals) xpr ypr . xpr-yprs) 581 --- macro --- 582 Returns a thunk predicate, name?, comparing xpr with ypr .... 583 and using var val ... within this tests. 584 The parameter verbose? controls the reported summary, i. e. 585 the side effects. 586 ]|# 587 (define-syntax define-tester 588 (ir-macro-transformer 589 (lambda (form inject compare?) 590 (let ((header (cadr form)) 591 (xpr-yprs (cddr form))) 592 (let ((name (car header)) 593 (var-vals (cdr header))) 594 `(define (,name) 595 (when (verbose?) 596 (print "\nIn " ',name ":") 597 (print* "===" 598 (make-string (string-length 599 (symbol->string ',name)) #\=) 600 "=\n") 601 ) 602 ((check* ,(chop var-vals 2) ,@xpr-yprs) (verbose?)))))))) 603 604 (define (test-all-proc name . test-name-pairs) 605 ; used internally in test-all, must be exported within test-all 587 606 (let loop ((pairs (chop test-name-pairs 2)) (failures '())) 588 607 (cond … … 604 623 (loop (cdr pairs) (cons (cadar pairs) failures)))))) 605 624 606 ;;; (check-all Name check-xpr ....) 607 ;;; ------------------------------- 608 ;;; checks all check-expressions defined with define-checks 609 ;;; producing a list of failures and exiting with 0 or 1 625 #|[ 626 (test-all Name tester ....) 627 --- macro test-all-proc --- 628 invokes all testers defined with define-tester 629 producing a list of failures and exiting with 0 or 1 630 ]|# 631 (define-syntax test-all 632 (er-macro-transformer 633 (lambda (form rename compare?) 634 (let ((name (cadr form)) 635 (tests (cddr form)) 636 (%test-all-proc (rename 'test-all-proc)) 637 (%list (rename 'list)) 638 ) 639 `(,%test-all-proc ',name 640 ,@(apply append 641 (map (lambda (t) `((,t) '(,t))) 642 tests))))))) 643 644 #|[ 645 (check-all Name check-xpr ....) 646 --- macro test-all-proc --- 647 Deprecated! 648 checks all check-expressions defined with define-checks 649 producing a list of failures and exiting with 0 or 1 650 ]|# 610 651 (define-syntax check-all 611 652 (er-macro-transformer … … 613 654 (let ((name (cadr form)) 614 655 (checks (cddr form)) 615 (% check-all-proc (rename 'check-all-proc))656 (%test-all-proc (rename 'test-all-proc)) 616 657 ) 617 `(,% check-all-proc ',name658 `(,%test-all-proc ',name 618 659 ,@(apply append 619 660 (map (lambda (t) `(,t ',t)) 620 661 checks))))))) 621 ) ; simple-tests 622 623 ;(import simple-tests) 624 ; 625 ;(pe '(check ((lst '(0 1 2))) 626 ; (car lst) 627 ; 0 628 ; (cdr lst) 629 ; '(1 2))) 630 ; 631 ;(check ((lst '(0 1 2))) 632 ; (car lst) 633 ; 0 634 ; (cdr lst) 635 ; '(0 1 2)) 636 ; 637 ;(pe '(define-checks (foo verbose? lst '(0 1 2)) 638 ; (car lst) 639 ; 0 640 ; (cdr lst) 641 ; '(1 2))) 642 ;(define-checks (foo verbose? lst '(0 1 2)) 643 ; (car lst) 644 ; 0 645 ; (cdr lst) 646 ; '(1 2 3)) 647 ;(foo #t) 648 ;(ppp (foo #f)) 662 663 #|[ 664 (simple-tests) 665 (simple-tests sym) 666 --- procedure --- 667 documentation procedure 668 ]|# 669 (define simple-tests 670 (let ( 671 (alist '( 672 (verbose? 673 parameter: 674 (verbose? ..) 675 "gets or sets the value of the parameter verbose?" 676 ) 677 (writeln 678 procedure: 679 (writeln xpr ...) 680 "write analog of print, expressions separated by whitespace" 681 ) 682 (and? 683 procedure: 684 (and? . xprs) 685 "non-short-circuited and which executes all side-effects" 686 ) 687 (pe 688 macro: 689 (pe macro-code) 690 "composes pretty-print and expand," 691 "does nothing in compiled code." 692 ) 693 (xpr:val 694 macro: 695 (xpr:val xpr ...) 696 "Deprecated!" 697 "Print each xpr quoted in a headline and pretty-print xpr's computed" 698 "value." 699 ) 700 (ppp 701 macro: 702 (ppp xpr ...) 703 "print each xpr quoted in a headline and pretty-print xpr's computed" 704 "value. Alias to xpr:val." 705 ) 706 (ppp* 707 macro: 708 (ppp* {xpr ypr} ...) 709 "Deprecated!" 710 "Print each xpr quoted in a headline and pretty-print xpr's computed" 711 "and expected value, ypr." 712 ) 713 (xpr:val* 714 macro: 715 (xpr:val* {xpr ypr} ...) 716 "Deprecated!" 717 "Print each xpr quoted in a headline and pretty-print xpr's computed" 718 "and expected value, ypr." 719 "Alias to ppp*" 720 ) 721 (ppp** 722 macro: 723 (ppp** ((var val) ...) xpr ypr . other-xpr-ypr-pairs) 724 "Deprecated!" 725 "ppp* wrapped into a let" 726 ) 727 (define-test 728 macro: 729 (define-test (name . parameters) form . forms) 730 "Deprecated!" 731 "Creates a test function" 732 ) 733 (compound-test 734 macro: 735 (compound-test (name) test . tests) 736 "Deprecated!" 737 "Invokes all tests and reports a summary" 738 ) 739 (== 740 procedure: 741 (==) 742 (== x) 743 (== type? type-equal?) 744 "Deprecated!" 745 "Generic type equality as curried procedure" 746 ) 747 (check 748 macro: 749 (check ((var val) ...) xpr ypr . xpr-yprs) 750 "Compare xpr and ypr .... in sequence with equal?" 751 "in the environment defined by var val ..." 752 ) 753 (define-checks 754 macro: 755 (define-checks (name? verbose? . var-vals) xpr ypr . xpr-yprs) 756 "Deprecated!" 757 "Returns a unary predicate, name?, comparing xpr with ypr ...." 758 "and using var val ... within this checks," 759 "verbose? controls the reported summary." 760 ) 761 (do-checks 762 macro: 763 (do-checks (name? verbose? . var-val-pairs) xpr ypr . xpr-yprs) 764 "Deprecated!" 765 "Returns a unary predicate, name?, comparing xpr with ypr ...." 766 "and using var val ... within this checks," 767 "alias to define-checks" 768 ) 769 (define-tester 770 macro: 771 (define-tester (name? . var-vals) xpr ypr . xpr-yprs) 772 "Returns a thunk predicate, name?, comparing xpr with ypr ...." 773 "and using var val ... within this tests." 774 "The parameter verbose? controls the reported summary, i. e." 775 "the side effects." 776 ) 777 (test-all 778 macro: 779 (test-all Name tester ....) 780 "invokes all testers defined with define-tester" 781 "producing a list of failures and exiting with 0 or 1" 782 ) 783 (check-all 784 macro: 785 (check-all Name check-xpr ....) 786 "Deprecated!" 787 "checks all check-expressions defined with define-checks" 788 "producing a list of failures and exiting with 0 or 1" 789 ) 790 (simple-tests 791 procedure: 792 (simple-tests) 793 (simple-tests sym) 794 "with sym: documentation of exported symbol" 795 "without sym: list of exported symbols" 796 ) 797 )) 798 ) 799 (case-lambda 800 (() (map car alist)) 801 ((sym) 802 (let ((pair (assq sym alist))) 803 (if pair 804 (for-each print (cdr pair)) 805 (print "Choose one of " (map car alist)))))))) 806 ) -
release/5/simple-tests/tags/3.0/tests/run.scm
r39187 r39580 1 1 (import simple-tests) 2 2 3 ;;; old interface 4 5 (define-test (bar n) 6 (positive? n) 7 (even? n)) 8 9 (define-test (foo x y) 10 (< x y) 11 "COMMENT" 12 (bar 4) 13 (odd? 3) 14 (positive? 3)) 15 16 (define-test (++) 17 (= (+ 1 2) 3) 18 (= (+ 1 2 3) 6)) 19 20 (define-test (**) 21 (= (* 1 2) 2) 22 (= (* 1 2 3) 6)) 23 24 (define-test (arithmetic) 25 (++) 26 (**)) 27 28 (define-test (baz) 29 (and? #t #t #t) 30 (and?) 31 (not (and? #t #f #t))) 32 33 34 ;(compound-test (simple-tests) 35 ; (baz) 36 ; (arithmetic?) 37 ; (foo 1 2) 38 ; ) 39 40 ;;; new interface 3 (import (only (chicken base) parameterize print case-lambda)) 41 4 42 5 (newline) 43 (print "check")44 (print "=====")45 (check ((lst '(0 1 2 3)))46 lst47 '(0 1 2 3)48 (car lst)49 050 (cadr lst)51 152 (cddr lst)53 '(2 3)54 )55 6 56 ;;; define-checks is an alias to do-checks 57 (do-checks (bar? verbose? n 5) 58 (positive? n) #t 59 (even? n) #f) 7 (define-test (bar n) (positive? n) (even? n)) 60 8 61 (define-checks (+? verbose?) 62 (+ 1 2) 3 63 (+ 1 2 3) 6) 9 (bar 5) 64 10 65 (define-checks (*? verbose?) 66 (* 1 2) 2 67 (* 1 2 3) 6) 11 (define-test (foo x y) (< x y) "COMMENT" (bar 4) (odd? 3) (positive? 3)) 68 12 69 (define-checks (arithmetic? verbose?) 70 (+? #f) #t 71 (*? #f) #t) 13 (foo 1 2) 72 14 73 (do-checks (baz? verbose?) 74 (and? #t #t #t) #t 75 (and?) #t 76 (and? #t #f #t) #f) 15 (define-test (++) (= (+ 1 2) 3) (= (+ 1 2 3) 6)) 77 16 78 (define-checks (qux? verbose?) 79 ((== "x") "y") #f 80 ((== "x") "x") #t 81 ((== baz?) baz?) #t 82 ((== baz?) bar) #f 83 ((== '()) '()) #t 84 ((== 'x) 'y) #f 85 ((== 'x) 'x) #t 86 ((== #(0 1 2)) #(0 1 2)) #t 87 ((== #(0 1 2)) '(0 1 2)) #f 88 ) 17 (++) 18 19 (define-test (**) (= (* 1 2) 2) (= (* 1 2 3) 6)) 20 21 (**) 22 23 (define-test (arithmetic) (++) (**)) 24 25 (arithmetic) 26 27 (define-test (baz) (and? #t #t #t) (and?) (not (and? #t #f #t))) 28 29 (baz) 30 31 '(compound-test (OLD) (bar 5) (foo 1 2) (++) (**) (arithmetic) (baz)) 32 33 (newline) 34 35 (do-checks (bar? verbose? n 5) (positive? n) #t (even? n) #f) 36 37 (bar?) 38 39 (define-checks (+? verbose?) (+ 1 2) 3 (+ 1 2 3) 6) 40 41 (+?) 42 43 (define-checks (*? verbose?) (* 1 2) 2 (* 1 2 3) 6) 44 45 (*?) 46 47 (define-checks (arithmetic? verbose?) (+? #f) #t (*? #f) #t) 48 49 (arithmetic?) 50 51 (do-checks (baz? verbose?) (and? #t #t #t) #t (and?) #t (and? #t #f #t) #f) 52 53 (baz?) 54 55 (define-checks 56 (qux? verbose?) 57 ((== "x") "y") 58 #f 59 ((== "x") "x") 60 #t 61 ((== baz?) baz?) 62 #t 63 ((== baz?) bar?) 64 #f 65 ((== '()) '()) 66 #t 67 ((== 'x) 'y) 68 #f 69 ((== 'x) 'x) 70 #t 71 ((== #(0 1 2)) #(0 1 2)) 72 #t 73 ((== #(0 1 2)) '(0 1 2)) 74 #f) 75 76 (qux?) 89 77 90 78 (define counter 91 (let ((n 0)) 92 (lambda () 93 (set! n (add1 n)) 94 n))) 79 (let ((n 0)) (case-lambda (() (set! n (add1 n)) n) ((k) (set! n k) n)))) 95 80 96 (define-checks (counter? verbose?) 97 (counter) 1 98 (counter) 2 99 (counter) 3 100 (counter) 4 81 (define-checks 82 (counter? verbose?) 83 (counter 0) 84 0 85 (counter) 86 1 87 (counter) 88 2 89 (counter) 90 3 91 (counter) 92 4) 93 94 (counter?) 95 96 '(check-all NEW (bar?) (*?) (+?) (arithmetic?) (baz?) (qux?) (counter?)) 97 98 (define-tester (Bar? n 5) (positive? n) #t (even? n) #f) 99 100 (define-tester (Plus?) (+ 1 2) 3 (+ 1 2 3) 6) 101 102 (define-tester (Times?) (* 1 2) 2 (* 1 2 3) 6) 103 104 (define-tester 105 (Arithmetic?) 106 (parameterize ((verbose? #f)) (Plus?)) 107 #t 108 (parameterize ((verbose? #f)) (Times?)) 109 #t) 110 111 (define Counter 112 (let ((n 0)) (case-lambda (() (set! n (add1 n)) n) ((k) (set! n k) n)))) 113 114 (define-tester 115 (Counter?) 116 (Counter 0) 117 0 118 (Counter) 119 1 120 (Counter) 121 2 122 (Counter) 123 3 124 (Counter) 125 4 126 (Counter 0) 127 0) 128 129 '(test-all SIMPLE-TESTS Bar? Times? Plus? Arithmetic? Counter?) 130 131 (test-all SIMPLE-TESTS 132 Bar? 133 Plus? 134 Times? 135 Arithmetic? 136 Counter? 101 137 ) 102 103 104 (check-all SIMPLE (bar?) (*?) (+?) (arithmetic?) (baz?) (qux?)105 (counter?))
Note: See TracChangeset
for help on using the changeset viewer.