diff --git a/CHANGELOG b/CHANGELOG index 215c6df..e8c3bfd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,11 @@ +0.1.6 + +Fixed the raco helper test for the Racket package build service: raco help +legitimately writes usage text to stderr, while raco test --drdr treats any +stderr output as a test failure. The test now captures child stdout/stderr. +Changed list-dir/files so its regexp matches only the entry name returned by +file-name-from-path, instead of the complete path. + 0.1.5 Added raco helper for invoking Racket tools from makefile recipes. diff --git a/Makefile.rkt b/Makefile.rkt index 612b74d..e07ec06 100644 --- a/Makefile.rkt +++ b/Makefile.rkt @@ -1,7 +1,10 @@ #lang racket (require "main.rkt" - racket/string) + racket/string + git + package-zipper + ) (target all (displayln "use (make clean) or (make package) or (make commit/push") @@ -22,10 +25,19 @@ (run '(git push))) (target status - (run '(git status))) + (void (dgit 'status)) + ) (target pull (run '(git pull))) - +(target clean + (for-each (λ (f) (displayln f) (rm-f f)) (list-files "." #px"([.]bak|~)$" #:recursive #t)) + (for-each (λ (d) (displayln d) (rm-rf d)) (list-dirs "." #px"(compiled|doc)$" #:recursive #t)) + (for-each (λ (f) (displayln f) (rm-f f)) (list-files "scrbl" #px"[.](css|js|html)$")) + ) + +(target package + (deps clean) + (zip-package)) \ No newline at end of file diff --git a/README.md b/README.md index 4d8d029..e760c34 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ raco pkg install For a versioned archive, give the package name explicitly: ```text -raco pkg install --name racket-makefile racket-makefile-0.1.5.zip +raco pkg install --name racket-makefile racket-makefile-0.1.6.zip ``` ## Running targets @@ -127,10 +127,11 @@ so they can be passed directly to `rm-f` and `rm-rf` with `apply`: (displayln "done.")) ``` -`list-dir/files` returns matching files and directories. `list-files` and -`list-dirs` restrict the result to files or directories. All three scan one -directory level by default; use `#:recursive #t` to walk the complete tree. -Non-recursive results are returned as complete paths, so the lists can be fed +`list-dir/files` returns matching files and directories. The regexp is matched +against the file or directory name itself, not against the complete path. +`list-files` and `list-dirs` restrict the result to files or directories. All +three scan one directory level by default; use `#:recursive #t` to walk the +complete tree. Results are returned as usable paths, so the lists can be fed directly to `rm-f` or `rm-rf` with `apply`. ## Generated targets diff --git a/info.rkt b/info.rkt index 69c4761..7062a65 100644 --- a/info.rkt +++ b/info.rkt @@ -1,7 +1,7 @@ #lang info (define pkg-authors '(hnmdijkema)) -(define version "0.1.5") +(define version "0.1.6") (define license 'MIT) (define collection "racket-makefile") (define pkg-desc diff --git a/private/commands.rkt b/private/commands.rkt index 37ec6cd..47abc16 100644 --- a/private/commands.rkt +++ b/private/commands.rkt @@ -141,8 +141,9 @@ (define (list-dir/files directory regexp #:recursive [recursive #f]) (filter (lambda (path) - (let ((fn (file-name-from-path path))) - (regexp-match? regexp fn))) + (define filename (file-name-from-path path)) + (and filename + (regexp-match? regexp filename))) (if recursive (for/list ([path (in-directory directory)]) path) diff --git a/scrbl/racket-makefile.scrbl b/scrbl/racket-makefile.scrbl index 7a99640..cad35c5 100644 --- a/scrbl/racket-makefile.scrbl +++ b/scrbl/racket-makefile.scrbl @@ -31,7 +31,7 @@ raco pkg install For a versioned archive, specify the package name explicitly: @verbatim{ -raco pkg install --name racket-makefile racket-makefile-0.1.5.zip +raco pkg install --name racket-makefile racket-makefile-0.1.6.zip } After installation a makefile can start with: @@ -260,10 +260,12 @@ For example: [regexp regexp?] [#:recursive recursive any/c #f]) list?]{ -Returns entries below @racket[directory] that match @racket[regexp]. By default -only the direct contents of @racket[directory] are inspected. With -@racket[#:recursive #t], the complete tree is walked using -@racket[in-directory], and both files and directories can be returned. +Returns entries below @racket[directory] whose file or directory name matches +@racket[regexp]. The regexp is applied to @racket[(file-name-from-path path)], +not to the complete path. By default only the direct contents of +@racket[directory] are inspected. With @racket[#:recursive #t], the complete +tree is walked using @racket[in-directory], and both files and directories can +be returned. For a non-recursive listing, complete paths are built from @racket[directory], so the result can be passed directly to file operations such as diff --git a/tests/helpers.rkt b/tests/helpers.rkt index a5b364d..b438ab7 100644 --- a/tests/helpers.rkt +++ b/tests/helpers.rkt @@ -41,6 +41,15 @@ (check-equal? (list-dirs tmp #px"a$") (list (build-path tmp "a"))) + ;; Matching is against the entry name, not against parent directories. + (define misleading-parent (build-path tmp "compiled-parent")) + (make-directory* misleading-parent) + (define ordinary-file (build-path misleading-parent "ordinary.txt")) + (call-with-output-file ordinary-file (lambda (out) (display "ordinary" out))) + (check-false + (member ordinary-file + (list-dir/files tmp #px"compiled" #:recursive #t))) + ;; Recursive variants select the requested kind directly. (define recursive-baks (list-files tmp #px"(?i:[.]bak$)" #:recursive #t)) diff --git a/tests/raco.rkt b/tests/raco.rkt index f32bc16..6a72f78 100644 --- a/tests/raco.rkt +++ b/tests/raco.rkt @@ -3,15 +3,23 @@ (require rackunit (only-in racket-makefile raco)) -(check-not-exn - (lambda () - (raco '(help)))) +;; DrDr (used by the package build service) counts any output on stderr as a +;; test failure. `raco help` legitimately writes its usage text to stderr, so +;; keep the child process output local to this test. +(define (check-raco-help) + (define out (open-output-string)) + (define err (open-output-string)) + (parameterize ([current-output-port out] + [current-error-port err]) + (check-not-exn + (lambda () + (raco '(help)))))) + +(check-raco-help) ;; It must not require raco to be on PATH. The current Racket installation ;; should locate its own raco first. (define env (environment-variables-copy (current-environment-variables))) (environment-variables-set! env #"PATH" #f) (parameterize ([current-environment-variables env]) - (check-not-exn - (lambda () - (raco '(help))))) + (check-raco-help))