[racket] Autotest like tool help

From: Eduardo Bellani (ebellani at gmail.com)
Date: Mon Jan 24 07:57:15 EST 2011

Hello Matthias.

Thanks for the help. Your code, unsurprisingly, is much superior. This
module is now closer to what I had in mind when I started. There is
still a lot to be desired by the output but it is useful for me, which
according to my metric is a great result. Here is your version with some
retouches:

#lang racket

;; run all the tests on the system
(define (enter-all-from-root (pause-time 2))
  (define test-dirs-white-list '("controller.*" "model.*" "lib.*"))
  (define module-white-list    (pregexp ".*\\.rkt$"))
  (for ((module-path (in-directory)))
    (with-handlers ([exn? (lambda (any-exn)
                            (printf "~a: ~a\n" module-path (exn-message
any-exn)))])
      (when (and (ormap (λ (dir-pattern)
                           (regexp-match? dir-pattern module-path))
                        test-dirs-white-list)
                 (regexp-match? module-white-list (path->string
module-path)))
        (eval `(enter! ,(path->string module-path)))
        (sleep pause-time)))))



;; start :  ->
(define (main (nap-interval 10))
  (enter-all-from-root)
  (sleep nap-interval)
  (main))

(main)

To run this I have to use this command line instead of yours:

racket -e '(enter! "auto-test.rkt")'

I would specially with regards as to how to not print things such as

[loading /usr/racket/collects/scheme/compiled/main_rkt.zo]


Or, in other words, how to isolate the data shown to the app being tested.
Thanks again for your time, it was very much appreciated.


On 01/21/2011 05:11 PM, Matthias Felleisen wrote:
> 
> 
> Eduardo, I believe you want something like this, though you should probably ensure that the path to the module somehow includes test-dir (say via a regexp match or something like that): 
> 
> #lang racket
> 
> ;; run as racket -t auto-test.rkt -m 
> 
> (provide start)
> 
> ;; run all the tests on the system 
> (define (enter-all-from-root)
>   (define test-dirs '("2" "4"))
>   [define module-white-list (pregexp ".*\\.rkt$")] 
>   (for ((module-path (in-directory)))
>     (with-handlers ([exn? (lambda (any-exn)
>                             (printf "~a: ~a\n" module-path (exn-message any-exn)))])
>       (when (regexp-match? module-white-list (path->string module-path))
>         (eval `(enter! ,(path->string module-path)))))))
> 
> 
> 
> ;; start :  ->
> (define (start (nap-interval 10))
>   (enter-all-from-root)
>   (sleep nap-interval)
>   (start))
> 
> On a direct note on your code: (not (false? (member ...))) is really the same as (member ...) in Racket. -- Matthias
> 
> 
> 
> On Jan 21, 2011, at 6:57 AM, Eduardo Bellani wrote:
> 
> Hello list.
> 
> I am trying to build something like autotest[1] for a racket project I
> am working on. It is a tool that I like very much on my rails
> development and I am trying to patch together one for racket. I did
> manage to get one working, but on my opinion it is ugly as hell and its
> output, well, could use a little polishing. So, I am fishing for
> suggestions on how to improve this code. I would very much appreciate
> any opinions, and I guess this could be transformed into a package for
> planet on the future. Here is the code:
> 
> ;;autotest.rkt
> #lang racket
> 
> (require racket/path
>         racket/enter)
> 
> (provide start)
> 
> ;; enter-all-from-root :  -> void
> ;; run all the tests on the system.
> (define (enter-all-from-root)
>  (let* ([test-dirs '("controller" "model" "lib")]
>         [root-test-files-and-dirs (directory-list)])
>    (for-each (? (found-dir-or-file)
>                 (when (and (directory-exists? found-dir-or-file)
>                            (not (false? (member (path->string
> found-dir-or-file)
>                                                 test-dirs))))
>                   (enter-all-in-directory found-dir-or-file)))
>              root-test-files-and-dirs)))
> 
> ;; enter-all-in-directory : path -> void
> ;; dynamically loads all modules in the given directory.
> (define (enter-all-in-directory a-directory)
>  (let ([modules (directory-list a-directory)]
>        [old-current-dir (current-directory)]
>        [module-white-list (pregexp ".*\\.rkt$")])
>    (with-handlers ([exn? (? (any-exn)
>                             (displayln (exn-message any-exn))
>                             (current-directory old-current-dir))])
>      (current-directory a-directory)
>      (for-each (? (module-path)
>                   (when (and (file-exists? module-path)
>                              (regexp-match? module-white-list
>                                             (path->string module-path)))
>                     (eval `(enter! ,(path->string module-path)))))
>                modules)
>      (current-directory old-current-dir))))
> 
> ;; start :  ->
> (define (start (nap-interval 10))
>  (enter-all-from-root)
>  (sleep nap-interval)
>  (start))
> 
> 
> (start)
> 
> 
> Thanks for the attention.
> 
> [1] http://zentest.rubyforge.org/ZenTest/
> 
_________________________________________________
 For list-related administrative tasks:
 http://lists.racket-lang.org/listinfo/users

-- 
Eduardo Bellani

omnia mutantur, nihil interit.


Posted on the users mailing list.