help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with prerequisites for unit testing rule


From: Paul D. Smith
Subject: Re: Help with prerequisites for unit testing rule
Date: Mon, 14 Feb 2005 07:56:27 -0500

%% address@hidden (Björn Lindström) writes:

  bl> %.class: %.java
  bl>   $(JAVAC) $<

  bl> test: $(TESTCLASSES)
  bl> $(TESTCLASSES): Test%: %
  bl>   $(JUNIT) $(patsubst %.class,%,$@)

  bl> Now, if I run 'make test', make will start out building
  bl> BetterTray.class, like it should, and then go on to run $(JUNIT)
  bl> on TestBetterTray.class. So, what's missing is that it doesn't
  bl> actually build TestBetterTray.class in between those steps. How
  bl> would I make the

  bl> $(TESTCLASSES): Test%: %

  bl> rule also depend on the build rule for the corresponding test
  bl> class?  (The %.class: %.java rule.)

You can't do it that way: a given target can only have one command
script to build it (unless you use double-colons but that's a while
different story).

You'll need to either add the JAVAC line to the same script as the JUNIT
line, like:

 $(TESTCLASSES): Test%: %
        $(JAVAC) $<
        $(JUNIT) $(patsubst %.class,%,$@)

The disadvantage here is if the unit test fails, the class is still
created so it won't be run again.  You could, of course, write shell
commands to delete the file for you when the unit test fails.

Or you could put the unit test into another rule, something like:

    RUNTESTCLASSES = $(TESTCLASSES:%=run.%)
    test: $(RUNTESTCLASSES)

    $(RUNTESTCLASSES): run.% : %
            $(JUNIT) $(patsubst %.class,%,$<)
            @touch $@

or whatever.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]