Why does this usage of boost test - single header variant crash? - c++

I use the boost Unit Test Framework (version 1.59) using the Single Header Variant. By running the code underneath in Visual Studio 2013 I get a debug assertion. (Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Any idea why?
http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/adv_scenarios/single_header_customizations/entry_point.html
#define BOOST_TEST_MODULE MyTest
#define BOOST_TEST_NO_MAIN
#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(boo)
{
}
int main(int argc, char* argv[])
{
return boost::unit_test::unit_test_main(init_unit_test, argc, argv);
}

So I left a command line parameter in the Project's Configuration Properties. For some reason the boost unit test framework crashes when running this program with command line parameter 'boo'...

Related

Visual Studio Community Edition 2019 doesn't find any tests

I have created a C++ project called Googletest in Visual Studio 2019 Community Edition. In the project I have installed Gmock as a nugget(gmock 1.11.0). I have two cpp files(Googletest.cpp and Test.cpp).
Googletest.cpp
#include "gtest/gtest.h"
#include <iostream>
int main(int argc, char** argv) {
if (strcmp("test", argv[1]) == 0)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
else
{
std::cout << "Hello!" << std::endl;
}
}
Test.cpp
#include "gtest/gtest.h"
TEST(FooTestSuite, Foo1) {
ASSERT_EQ(1, 1);
}
The executable works properly. It runs the test or just says "Hello". The problem is that VS doesn't find any test, so that I can't use the test explorer. Does anyone know how to fix the issue? I have uploaded the project on github: https://github.com/tellass567/vs-googletest
If you have installed Test Adapter for Google Test and it can't discover Google tests, be sure the test names end with Test or Tests, otherwise Test Adapter is not able to discover unit tests
TEST(FooTests, Foo1) {
ASSERT_EQ(1, 1);
}
You may add alternative test name RegExes in Tools > Options > Test Adapter for Google Test to help Test Adapter to discover unit tests, see Trait Regexes.

How can I make catch2 run tests that reside in a static library?

My usual workflow with catch2 is to have a single console application that contains all the test cases and the tests 'runner'.
For example:
file1.cpp, file2.cpp contains tests:
#include <catch2/catch.hpp>
TEST_CASE("test", "[test]")
{
CHECK(true);
}
A single file main.cpp would contain the runner code:
#define CATCH_CONFIG_RUNNER
#include <catch2/catch.hpp>
int main(int argc, char* argv[])
{
return Catch::Session().run(argc, argv); // run tests
}
In order to reduce compilation time, I tried to move all files containing the tests (file1, file2 etc) to a separate static library project (Visual Studio).
But after doing this, catch fails to find any test cases:
catch main started..
Filters: [test]
===============================================================================
No tests ran
I tried putting the runner code inside a function that resides inside the static library, but that didn't help.
Questions:
How exactly does catch finds its test cases?
Why is this failing?
How can I fix it?

Can I make google test return 0 even when tests fail?

I am calling a googletest in the post-build step of a C++ project in VS 2012.
Naturally, when any of the tests fail, the googletest command returns failure (-1), and the entire project is marked as a failure by Visual Studio.
I do not want that. I want the googletest to be run, and I want to see the results in the output, but I do not want to fail the project if not all tests pass.
Is there any flag that I can pass into googletest so that it always returns success (zero)?
Yes, you can make the test return 0 if you write your own main function.
I imagine you're linking your test executable with the special gtest_main library which is a very basic helper to allow you to avoid having to write your own main function.
It's pretty much just doing:
int main(int argc, char **argv) {
printf("Running main() from gtest_main.cc\n");
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The RUN_ALL_TESTS macro is the culprit which is returning -1, so all you need to do is stop linking with gtest_main and write your own main more like:
int main(int argc, char **argv) {
testing::InitGoogleTest(&argc, argv);
RUN_ALL_TESTS();
return 0;
}
For more info on this topic, see the GoogleTest docs.

GoogleTest run_all_tests not finding test fixtures

I have a C++ project that is going to be made up of only google tests. This project references another project (the project it is testing). I have a include and source folder for the header and implementation files. I am creating google test fixtures classes and split the header and implementation into the include and source folders. I have a main.cpp that contains the following code:
//main.cpp
#include "../inc/zeroEstimatorTest.h"
#include "gtest/gtest.h"
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The problem I am having is that the RUN_ALL_TESTS() call is not calling my google test fixture. The test fixture is located in the implementation of the test class. It looks like this:
//zeroEstimatorTest.cpp
class zeroEstimatorTest : public ::testing:Test
{
...
};
TEST_F(zeroEstimatorTest, zeroTest)
{
...
}
The project builds and runs but the output is the following:
[0;32m[==========] [mRunning 0 tests from 0 test cases.
[0;32m[==========] [m0 tests from 0 test cases ran. (0 ms total)
[0;32m[ PASSED ] [m0 tests.
I am currently using Eclipse (for the first time) and I am on a Linux 64 machine.
Things I have done:
The zeroEstimatorTest class includes the "zeroEstimatorTest.h" at the top.
The #include "gtest/gtest.h" is at the top of all three files (main.cpp, zeroEstimatorTest.h, and zeroEstimatorTest.cpp)
Can anyone help?
Thank you very much!
The problem is that you're not setting the tests filter name try initializing google test with --gtest_filter= it can be done using the main function parameters . 

"Using OS scope before setting MAKEFILE_GENERATOR" in Qt

I have downloaded and installed Qt and I'm learning how to use it.
So, I created a new project myfristqt (empty project). I then added a main.cpp file with this code:
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
return app.exec();
}
First thing I noticed #include <QApplication> line is hightlighted with a red line as if QApplication was an unknown identifier. So, I compiled it to see what happens and here's the error I got:
(internal):1: error : Using OS scope before setting MAKEFILE_GENERATOR
Any idea why this is happening ? I'm using Windows XP
MAKEFILE_GENERATOR is a qmake variable.
This variable contains the name of the Makefile generator to use when generating a Makefile. The value of this variable is typically handled internally by qmake and rarely needs to be modified.
It define in QTDIR/mkspecs/PLATFORM/qmake.conf. Where PLATFORM is maybe cygwin-g++, win32-msvc200x on your Windows XP.