Thursday, April 2, 2009

modest makefile for rapid Java testing

This makefile is designed to help test several Java programs, each one in its own self-contained source file, for example "hello.java" If you type "make hello.test", the program will be compiled and executed. To test everything in the directory, type "make test-all". To rebuild everything then re-test, do "make clean test-all".

To test a new program, just start writing it. When "make test-fast" is executed, the class file will be built, then run. That is, you never have to update the Makefile -- it picks up the most recent Java source file automatically.

I bind "make test-fast" to the big keypad Enter key, but that's for another blog post.

RECENT_JAVA := $(shell ls -1t *.java | head -1)

all test-fast: $(basename $(RECENT_JAVA)).test

test-all: $(patsubst %.java,%.test,$(wildcard *.java))

%.class: %.java
javac $<
%.test: %.class
env CLASSPATH=.:$(CLASSPATH) java $(basename $<)

check-syntax:
javac -Xlint $(CHK_SOURCES)

clean:
rm *.class

No comments:

Post a Comment