8

Is there a way to compile the "check" target of an autoconf project without running it?

I have Eclipse Juno with the "C/C++ Unit Test" plugin. I would like to be able to make the check target, then run it in the context of the plugin so that I can take advantage of its conveniences.

Currently I have set up the project configuration to build "make check" then run the "test" binary that it creates. This has 2 problems.

1) It is redundant and slows the process (the test runs twice)

2) A test failure causes a build failure. Eclipse doesn't know the difference. I have to pay attention to the output, then run in the unit test plugin anyway to get what I want out of it.

If there is no way to just compile the check target, is there some other way of setting up autoconf / automake to allow me to build the test target without creating a special config that builds the test as part of "make all"? Basically, I want to have all 3 options in a single configuration:

make unitTest (for development)
make check    (for automated testing)
make all      (for release)

EDIT: Just to clarify a bit, I know I can run "make targetName" from the target directory to compile that target (project/src/test> make myUnitTests). I'm looking for a generic way to do it from the project's base directory (project> make check_PROGRAMS).

Ed K
  • 189
  • 2
  • 9

2 Answers2

13
make check TESTS=

will run the check target but not invoke any tests.

William Pursell
  • 204,365
  • 48
  • 270
  • 300
  • 1
    This is the correct answer to my base question, and for the generic use case because most people will probably want to compile the main application before the test. I really like adl's answer and it applies to my specific use case, but it only works if the "check" test is disconnected from the main app. In my case, I have gtests that exercise the app source files without needing the app compiled. – Ed K Apr 29 '13 at 16:19
  • 1
    Nice! This is the best `automake` hack I have found to date to solve the common compilation issue. It works with "foreign" layouts too where the tests are stored in subdirs. – os_ Jun 17 '15 at 18:46
5

How about adding a new rule you your root Makefile.am?

.PHONY: unitTest
unitTest:
        cd src/test && $(MAKE) $(AM_MAKEFLAGS) myUnitTests

and if make myUnitTests should build all $(check_PROGRAMS) from src/test/Makefile.am, just add such a rule in src/test/Makefile.am:

.PHONY: myUnitTests
myUnitTests: $(check_PROGRAMS)
adl
  • 15,627
  • 6
  • 51
  • 65
  • 1
    +1 ... I accepted @WilliamPursell's answer because it answers my top question, but this is the answer for my specific situation where I don't want to compile the main app, just the test app alone. Wish I could accept both. :-) – Ed K Apr 29 '13 at 16:25