[racket] Autotest like tool help
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:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> 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/
>
> - --
> Eduardo Bellani
>
> omnia mutantur, nihil interit.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEUEARECAAYFAk05dI0ACgkQSbLl0kCTjGmzIQCcD7SjqJra553GRU1GxTMfLZl+
> lfgAl1PunTBD+rB24KZOofwsEGhgiIs=
> =UNuE
> -----END PGP SIGNATURE-----
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users