Files
racket-makefile/tests/make.rkt
T

67 lines
1.8 KiB
Racket

#lang racket
(require rackunit
racket-makefile
(only-in "../private/engine.rkt" reset-makefiles!))
(reset-makefiles!)
(define calls '())
(define context #f)
(makefile first
(default-target status)
(phony status all context)
(target status
(set! calls (append calls '(first-status))))
(target all
(deps status)
(set! calls (append calls '(first-all))))
(target context
(deps input.txt other.txt)
(set! context (list $target $deps $<))))
(check-equal? (current-makefile-prefix) 'first)
(check-true (procedure? make))
(check-true (procedure? makefile-target-first-status))
(check-true (procedure? makefile-target-first-all))
(check-true (procedure? makefile-target-first-context))
;; make resolves the target procedure through the active prefix.
(make 'all)
(check-equal? calls '(first-status first-all))
;; The generated target is a real Racket procedure and can be called directly.
(makefile-target-first-status)
(check-equal? calls '(first-status first-all first-status))
;; Direct procedure calls still get the automatic target variables.
(makefile-target-first-context)
(check-equal? context '("context" ("input.txt" "other.txt") "input.txt"))
(makefile second
(default-target status)
(phony status)
(target status
(set! calls (append calls '(second-status)))))
;; The last makefile definition becomes active.
(check-equal? (current-makefile-prefix) 'second)
(make)
(check-equal? calls '(first-status first-all first-status second-status))
;; Both prefixes remain registered and can be selected explicitly.
(current-makefile-prefix 'first)
(make 'status)
(check-equal?
calls
'(first-status first-all first-status second-status first-status))
;; The registry stores the generated procedure itself.
(check-eq?
(hash-ref makefile-targets '("first" . "status"))
makefile-target-first-status)