This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 216501 - NetBeans creates bad makefile for UnitTests
Summary: NetBeans creates bad makefile for UnitTests
Status: RESOLVED FIXED
Alias: None
Product: cnd
Classification: Unclassified
Component: Project (show other bugs)
Version: 7.2
Hardware: All All
: P2 normal (vote)
Assignee: Andrew Krasny
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-08 02:02 UTC by zachsaw
Modified: 2012-09-17 12:39 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Proposed patch (11.27 KB, patch)
2012-09-06 09:18 UTC, Andrew Krasny
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description zachsaw 2012-08-08 02:02:14 UTC
Steps to replicate the issue:

1) Create a new C++ application project.
2) Create a new unit test (right click on test files, new CppUnit Test.
3) Finish the wizard with default values.
4) Open Makefile-Release.mk, verify that test target is the main application executable instead of the correct one in Makefile-Debug.mk which is ${TESTDIR}/TestFiles/f1
5) Change project config to Release in the IDE.
6) Right-click on "Test Files" and hit Test.
7) Notice that it is trying to run the main application instead of the unit test.

* If you originally had your project config set to Release, creating Unit Tests while in that config will cause the symptoms to appear the other way around (i.e. you can unit test in Release mode, but not in Debug mode).



--------------------------

e.g. Makefile-Debug.mk (this is the correct makefile)

# Test Directory
TESTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tests

# Test Files
TESTFILES= \
	${TESTDIR}/TestFiles/f1

# Build Test Targets
.build-tests-conf: .build-conf ${TESTFILES}
${TESTDIR}/TestFiles/f1: ${TESTDIR}/tests/EmployeeServiceTest.o ${TESTDIR}/tests/TestRunner.o ${OBJECTFILES:%.o=%_nomain.o}
	${MKDIR} -p ${TESTDIR}/TestFiles
	${LINK.cc}   -o ${TESTDIR}/TestFiles/f1 $^ ${LDLIBSOPTIONS} -lcppunit 

# Run Test Targets
.test-conf:
	@if [ "${TEST}" = "" ]; \
	then  \
	    ${TESTDIR}/TestFiles/f1 || true; \
	else  \
	    ./${TEST} || true; \
	fi


--------------------------


e.g. Makefile-Release.mk (IDE stuffed this one up. Note: rcftestserver is the main app executable)

# Test Directory
TESTDIR=${CND_BUILDDIR}/${CND_CONF}/${CND_PLATFORM}/tests

# Test Files
TESTFILES= \
	${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/rcftestserver

# Build Test Targets
.build-tests-conf: .build-conf ${TESTFILES}
${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/rcftestserver: ${TESTDIR}/tests/EmployeeServiceTest.o ${TESTDIR}/tests/TestRunner.o ${OBJECTFILES:%.o=%_nomain.o}
	${MKDIR} -p ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}
	${LINK.cc}   -o ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/rcftestserver $^ ${LDLIBSOPTIONS} 

# Run Test Targets
.test-conf:
	@if [ "${TEST}" = "" ]; \
	then  \
	    ${CND_DISTDIR}/${CND_CONF}/${CND_PLATFORM}/rcftestserver || true; \
	else  \
	    ./${TEST} || true; \
	fi
Comment 1 hadrabap 2012-08-17 21:57:45 UTC
The same behavior here on OS X as well too.

Have got CppUnit from MacPorts (not recognized by NetBeans; have been forced to re-configure the project to take in account /opt/local/{include|lib} as well, BTW). I have changed Makefile-Release.mk manually, no big deal, everything works perfectly from command line. Unfortunately, invocation of build system from NetBeans has restored the original (wrong) Makefile-Release.mk which has led to BUILD FAILED message.
Comment 2 Andrew Krasny 2012-09-06 08:48:45 UTC
zachsaw,

indeed the reason is that only active configuration is configured for unit tests.

You can work-around this problem though... 

For this:

- Switch to a 'broken' configuration;
- Right-click on a test folder (first-level under 'Test Files');
- in both C/C++ compile categories add '.' (dot) to the 'Include Directories' field;
- In 'Linker' category - 
  'Output' - ${TESTDIR}/TestFiles/f1 (you could copy from 'Debug' configuration)
  'Libraries' - click '...' => 'Add Option...' => 'Other Option' => '-lcppunit'
Comment 3 Andrew Krasny 2012-09-06 09:18:19 UTC
Created attachment 123978 [details]
Proposed patch
Comment 4 Andrew Krasny 2012-09-06 09:20:00 UTC
Nik, 

take a look at the proposed patch, please... 

=Andrew
Comment 5 Andrew Krasny 2012-09-11 10:49:18 UTC
The fix with a code that adds needed options to all (not active only) configuration is http://hg.netbeans.org/cnd-main/rev/212ffca66bd4

However see http://netbeans.org/bugzilla/show_bug.cgi?id=218121
Comment 6 Alexander Pepin 2012-09-17 12:14:21 UTC
QE have to add editor tests into cnd.unittest test suite
Comment 7 Alexander Pepin 2012-09-17 12:39:32 UTC
QE have to cover the testcase in cnd.unittest test suite