#lang racket (require rackunit racket/file racket/system) (define racket-executable (find-system-path 'exec-file)) (define tmp (make-temporary-file "racket-makefile-refresh~a" 'directory)) (define (write-lines path . lines) (call-with-output-file path #:exists 'truncate/replace (λ (out) (for ([line (in-list lines)]) (displayln line out))))) (dynamic-wind void (λ () (write-lines (build-path tmp "slow.rkt") "#lang racket/base" "(require racket/file)" "(define count-file \"slow-count.txt\")" "(define count (if (file-exists? count-file) (string->number (file->string count-file)) 0))" "(call-with-output-file count-file #:exists 'truncate/replace (lambda (out) (display (add1 count) out)))" "(provide slow-value)" "(define slow-value \"loaded\")") (write-lines (build-path tmp "Makefile.rkt") "#lang racket" "(require racket-makefile \"slow.rkt\")" "(makefile 'demo" " (phony 'change 'old)" " (target 'old (displayln \"old\"))" " (target 'change (copy-file \"NewMakefile.rkt\" \"Makefile.rkt\" #t)))") (write-lines (build-path tmp "NewMakefile.rkt") "#lang racket" "(require racket-makefile \"slow.rkt\")" "(makefile 'demo" " (phony 'changed)" " (target 'changed" " (call-with-output-file \"result.txt\" #:exists 'truncate/replace" " (lambda (out) (display slow-value out)))))") (write-lines (build-path tmp "driver.rkt") "#lang racket" "(require racket-makefile)" "(dynamic-require \"Makefile.rkt\" #f)" "(make 'change)" "(refresh-makefile)" "(make 'changed)" "(define old-removed?" " (with-handlers ([exn:fail? (lambda (e) #t)])" " (make 'old)" " #f))" "(unless old-removed?" " (error 'refresh-test \"old target survived refresh\"))") (parameterize ([current-directory tmp]) (check-true (system* racket-executable "driver.rkt"))) (check-equal? (file->string (build-path tmp "result.txt")) "loaded") (check-equal? (file->string (build-path tmp "slow-count.txt")) "1")) (λ () (delete-directory/files tmp #:must-exist? #f)))