www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

export-tests.rkt (2672B)


      1 #lang racket
      2 
      3 (require "export-lists.rkt"
      4          "export-count.rkt"
      5          rackunit)
      6 
      7 (provide check-all-documented
      8          check-documented
      9          check-documentation-ratio)
     10 
     11 (define (fail-check-unless cond msg)
     12   (unless cond (fail-check msg)))
     13 
     14 (define-check (check-all-documented module-name)
     15   (let* ([undocumented (module->undocumented-exported-names module-name)]
     16          [num-undocumented (length undocumented)])
     17     (fail-check-unless (zero? num-undocumented)
     18       (check-all-documented-message module-name num-undocumented undocumented))))
     19 
     20 (module+ test
     21   (check-not-exn (thunk check-all-documented 'racket/promise)))
     22 
     23 (define (check-all-documented-message module-name num-undocumented undocumented)
     24   (string-append "Module "
     25                  (symbol->string module-name)
     26                  " has "
     27                  (number->string num-undocumented)
     28                  " undocumented bindings:\n\n"
     29                  (string-join (map symbol->string undocumented)
     30                               "\n")))
     31 
     32 (module+ test
     33   (check string=?
     34          (check-all-documented-message 'foo 8 '(foo1 foo2 foo3))
     35          "Module foo has 8 undocumented bindings:\n\nfoo1\nfoo2\nfoo3"))
     36 
     37 (define-check (check-documented module-name binding)
     38   (fail-check-unless (has-docs? module-name binding)
     39     (check-documented-message module-name binding)))
     40 
     41 (module+ test
     42   (check-not-exn (thunk (check-documented 'racket/match 'match))))
     43 
     44 (define (check-documented-message module-name binding)
     45   (string-append "Module "
     46                  (symbol->string module-name)
     47                  " does not document binding "
     48                  (symbol->string binding)))
     49 
     50 (module+ test
     51   (check string=?
     52          (check-documented-message 'foo 'foo1)
     53          "Module foo does not document binding foo1"))
     54 
     55 (define-check (check-documentation-ratio module-name minimum-ratio)
     56   (let ([actual-ratio (module-documentation-ratio module-name)])
     57     (fail-check-unless (>= actual-ratio minimum-ratio)
     58       (check-documentation-ratio-message module-name minimum-ratio actual-ratio))))
     59 
     60 (define (check-documentation-ratio-message module-name minimum-ratio actual-ratio)
     61   (string-append "Module "
     62                  (symbol->string module-name)
     63                  " does not document at least "
     64                  (number->string (exact->inexact (* 100 minimum-ratio)))
     65                  "% of its bindings, only documents "
     66                  (number->string (exact->inexact (* 100 actual-ratio)))
     67                  "%"))
     68 
     69 (module+ test
     70   (check string=?
     71          (check-documentation-ratio-message 'foo 0.5 0.25)
     72          "Module foo does not document at least 50.0% of its bindings, only documents 25.0%"))