Files
racket-makefile/tests/engine.rkt
T

54 lines
1.4 KiB
Racket

#lang racket
(require rackunit
racket/file
"../private/engine.rkt")
(define tmp (make-temporary-file "racket-makefile-engine~a" 'directory))
(dynamic-wind
void
(λ ()
(parameterize ([current-directory tmp]
[current-command-line-arguments #()])
(call-with-output-file "input.txt"
(λ (out) (display "one" out)))
(define build-count 0)
(reset-makefiles!)
(begin-makefile! 'demo)
(set-default-target! 'demo 'all)
(mark-phony! 'demo 'all)
(register-target!
'demo
"result.txt"
'("input.txt")
(λ ()
(set! build-count (add1 build-count))
(copy-file "input.txt" "result.txt" #t)))
(register-target!
'demo
'all
(list (list "result.txt"))
void)
(current-makefile-prefix 'demo)
(make-targets!)
(check-equal? build-count 1)
(check-true (file-exists? "result.txt"))
;; Nothing changed, so the file target remains up to date.
(make-targets!)
(check-equal? build-count 1)
;; Make the input newer than the output and verify that it rebuilds.
(define result-time (file-or-directory-modify-seconds "result.txt"))
(file-or-directory-modify-seconds "input.txt" (+ result-time 2))
(make-targets!)
(check-equal? build-count 2)))
(λ ()
(delete-directory/files tmp #:must-exist? #f)))