Make autoconf "check" target without running it
Asked Answered
E

2

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).

Eveliaevelin answered 26/4, 2013 at 15:25 Comment(0)
O
13
make check TESTS=

will run the check target but not invoke any tests.

Offense answered 28/4, 2013 at 13:17 Comment(2)
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.Eveliaevelin
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.Eartha
S
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)
Straitlaced answered 27/4, 2013 at 6:46 Comment(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. :-)Eveliaevelin

© 2022 - 2024 — McMap. All rights reserved.