-
Notifications
You must be signed in to change notification settings - Fork 85
Open
Description
Overview
I have a dynamically instantiated test suite that contains a createSuite() method.
I call cxxtestgen with --no-static-init.
The resulting code misbehaves during execution as follows:
- An instance A of my test-suite object gets created.
- Another instance B of my test-suite object gets created.
setUp()is called on B.- The test-case methods are called on A, which is obviously uninitialised.
tearDown()is called on B.- B is destroyed.
Minimal example
Save this as bug.h:
#include <cxxtest/TestSuite.h>
class BuggyTestSuite : public CxxTest::TestSuite {
public:
void setUp() override {
std::cerr << "Calling setUp() on " << this << std::endl;
}
void tearDown() override {
std::cerr << "Calling tearDown() on " << this << std::endl;
}
void testBreakage() {
std::cerr << "Calling testBreakage() on " << this << " <- !!"
<< std::endl;
}
static BuggyTestSuite *createSuite() {
BuggyTestSuite *suite = new BuggyTestSuite();
std::cerr << "Created " << suite << std::endl;
return suite;
}
static void destroySuite(BuggyTestSuite *suite) {
std::cerr << "Destroying " << suite << std::endl;
delete suite;
}
};Steps to reproduce
cxxtestgen --error-printer --no-static-init -o bug.cpp bug.h
c++ -o bug bug.cpp
./bug
Example output
Created 0x557bfb48be70
Running cxxtest tests (1 test)Created 0x557bfb48c2c0
Calling setUp() on 0x557bfb48c2c0
Calling testBreakage() on 0x557bfb48be70 <- !!
Calling tearDown() on 0x557bfb48c2c0
.Destroying 0x557bfb48c2c0
OK!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels