Troubleshooting Misconfigured Main
April 23, 2021 ยท View on GitHub
Troubleshooting Misconfigured Main
Contents
Symptoms
Linker errors about missing symbols
When you link your test program - using ApprovalTest v.10.1.1 or later - you get linker errors about missing symbols, such as these:
ApprovalTests::FileApprover::verify(...)ApprovalTests::StringWriter::StringWriter(...)ApprovalTests::DefaultNamerFactory::getDefaultNamer()ApprovalTests::Options::defaultReporter()ApprovalTests::Scrubbers::doNothing(...)ApprovalTests::Options::FileOptions::getFileExtension() constApprovalTests::Options::fileOptions() constApprovalTests::Options::getReporter() constApprovalTests::Options::scrub(...) const
Error when running tests
Running tests - using ApprovalTest v.10.1.0 or earlier - gives the following output:
*****************************************************************************
* *
* Welcome to Approval Tests.
*
* You have forgotten to configure your test framework for Approval Tests.
*
* To do this in Catch, add the following to your main.cpp:
*
* #define APPROVALS_CATCH
* #include "ApprovalTests.hpp"
*
* To do this in Google Test, add the following to your main.cpp:
*
* #define APPROVALS_GOOGLETEST
* #include "ApprovalTests.hpp"
*
* To do this in doctest, add the following to your main.cpp:
*
* #define APPROVALS_DOCTEST
* #include "ApprovalTests.hpp"
*
* To do this in Boost.Test, add the following to your main.cpp:
*
* #define APPROVALS_BOOSTTEST
* #include "ApprovalTests.hpp"
*
* To do this in CppUTest, add the following to your main.cpp:
*
* #define APPROVALS_CPPUTEST
* #include "ApprovalTests.hpp"
*
* To do this in [Boost].UT, add the following to your main.cpp:
*
* #define APPROVALS_UT
* #include "ApprovalTests.hpp"
*
* For more information, please visit:
* https://github.com/approvals/ApprovalTests.cpp/blob/master/doc/TroubleshootingMisconfiguredMain.md
* *
*****************************************************************************
Solutions
These are the things to check.
Check the instructions for your test framework
Approval Tests needs to know which test framework to connect to, and that usually involves making small changes to the main() function for your test program.
This error usually indicates that a problem in your test program's main() means that ApprovalTests.cpp is not correctly set up for your test framework.
The following resources should help:
- The text in the error message above may be enough to get you going.
- If not, see Getting Started - Creating your main() to find out what you need to do for your chosen test framework, or to select one, if you have not yet done so.
Check Google Test Framework
- Have you created a
main.cppthat sets up ApprovalTests?- If not, the default Google Test
main()will be used, which will not set up Approval Tests - To fix, copy in the non-comment code from tests/GoogleTest_Tests/main.cpp
- If not, the default Google Test
- Is your
main.cppincluded in your project's build?- If not, the default Google Test
main()will be used, which will not set up Approval Tests - To fix, e.g. check your
CMakeLists.txtfile
- If not, the default Google Test
- Does your Google Test have its own custom
main.cpp?- If so, perhaps you haven't yet added the code to set up Approval Tests?
- To fix, copy in the Approvals-specific lines from examples/googletest_existing_main/main.cpp
Other Issues
- Is your code calling
Approvals::verify()or any other methods in this library from outside a Google Test?- This is much less likely to be the cause, but the file-naming code in Approval Tests (
ApprovalTestNamer) does require that approvals are used from inside a test method in a supported test framework.
- This is much less likely to be the cause, but the file-naming code in Approval Tests (