79 lines
2.5 KiB
Racket
79 lines
2.5 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))
|
|
|
|
;; The public inspection API preserves definition order and original values.
|
|
(check-equal? (makefile-prefixes) '(first))
|
|
(check-equal? (makefile-targets) '(status all context))
|
|
(check-true (makefile-target-exists? 'status))
|
|
(check-false (makefile-target-exists? 'missing))
|
|
(check-eq? (makefile-target-procedure 'status)
|
|
makefile-target-first-status)
|
|
|
|
;; 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))
|
|
|
|
;; Both prefixes remain inspectable after switching the active makefile.
|
|
(check-equal? (makefile-prefixes) '(first second))
|
|
(check-equal? (makefile-targets 'first) '(status all context))
|
|
(check-equal? (makefile-targets 'second) '(status))
|
|
(check-true (makefile-target-exists? 'first 'status))
|
|
(check-false (makefile-target-exists? 'first 'missing))
|
|
(check-eq? (makefile-target-procedure 'first 'status)
|
|
makefile-target-first-status)
|