Comments (7)
I may have better for you: making the context variadic, like this:
for (int i = 8; i < 24; ++i) {
BOOST_TEST_CONTEXT("With level " << i, "Random value=" << some other value){
}
}
Would that work for you? You can try it on the branch topic/GH-197-plural-context-in-single-scope
from test.
Unfortunately that doesn't actually do what I want it to. I need to build the context up as I generate data I want included in it so I can debug test failures. What I'm doing is something like this:
std::vector<uint8_t> data = ...; // generate data
MY_BOOST_TEST_CONTEXT("data = " << data);
session->SendData(data, ... /* packet header fields */);
// RequirePacket() reads the data from the stream including the length header.
// It also does a few other checks to make sure the data isn't garbage.
const std::vector<uint32_t> packet = RequirePacket(numWords);
MY_BOOST_TEST_CONTEXT("packet = " << packet);
// ... Do some other checks on the packet. ...
WriteSingleWord(TESTING_ACK); // Acknowledge the packet.
std::vector<uint8_t> parseData;
// ParsePacket() returns false if the packet was badly formatted or failed integrity checks.
BOOST_TEST(ParsePacket(packet, parseData, ... /* output parameters to receive header fields */));
MY_BOOST_TEST_CONTEXT("parseData = " << parseData);
// With all of the above context I can manually inspect the original data, sent packet, and parsed
// data in case this comparison fails.
BOOST_TEST(data == parseData, boost::test_tools::per_element());
I also use it to remove an extra level of indentation from the entire body of Require*()
functions (like RequirePacket()
above) like so:
#define RequirePacket(numWords) \
Internal_RequirePacket((numWords), BOOST_TEST_L(__FILE__), static_cast<std::size_t>(__LINE__))
std::vector<uint32_t>
Internal_RequirePacket(unsigned numWords, boost::unit_test::const_string file, std::size_t line) {
MY_BOOST_TEST_CONTEXT("RequirePacket() call-site: " << file << "(" << line << ")");
// Code to read packet from stream and validate length and some other things.
...
}
from test.
I guess you have considered the assertion bound context ?
If a context needs to span several assertions, we need a scope, otherwise it will confuse users. If a context is associated to only one assertion, then BOOST_TEST_INFO
is doing just fine.
What I did here is to have several information going into a single BOOST_TEST_CONTEXT
, to avoid precisely having several scopes for a single context.
from test.
Yes. I need the context to span several assertions. I understand why you made BOOST_TEST_CONTEXT
create a scope that the context will apply to. However, in my case I want the context to last for the rest of the enclosing scope. Is your last statement supposed to mean that adding context to the enclosing scope is an explicit non-goal?
from test.
It is not an explicit non-goal, but I need to think about it.
from test.
Ok, I implemented this via a new macro BOOST_TEST_INFO_SCOPE
. Example of use
for(int i = 0; i < 50; i++) {
BOOST_TEST_INFO_SCOPE("trial " << i+1);
int root1 = dis(gen);
int root2 = dis(gen);
if(root1 > root2) {
std::swap(root1, root2);
}
BOOST_TEST_INFO_SCOPE("root1 = " << root1);
BOOST_TEST_INFO_SCOPE("root2 = " << root2);
std::pair<double, double> estimated = estimate_polynomial_roots(
gen,
[root1, root2](double x) -> double { return (x - root1) * (x - root2); });
BOOST_TEST(estimated.first == double(root1), 10. % boost::test_tools::tolerance());
BOOST_TEST(estimated.second == double(root2), 10. % boost::test_tools::tolerance());
}
Let me know if that corresponds to what you asked (same branch as before if you want to give a try).
from test.
That fix does the trick. I'll work on getting everyone here using an upgraded or patched version. Thanks!
from test.
Related Issues (20)
- BOOST_DATA_TEST_CASE doesn't compile when a variable `t` is present
- execution_monitor.ipp dosn't compile with glibc 2.17 HOT 1
- BOOST_TEST_LOG_FORMAT=XML not generating valid XML HOT 2
- Missing formats for --list_content
- Overflow warning in `print_helper.hpp`
- Unexpected behavior with `--run_test` HOT 2
- When using MSVC, collections always require their element type to be comparable
- Unit-test runs for 30 minutes when BOOST_TEST used in the loop
- question: how to correctly create print helpers for '<<' explicitly removed in C++20? HOT 2
- Implement benchmark support
- Problems to read the documentation
- Bug in documentation formatting
- free(): invalid pointer at test exit HOT 8
- Invalid free/delete error in Boost.Test with minimal test case on Boost 1.85 HOT 1
- Report the exception text from BOOST_CHECK_NO_THROW
- Documentation: outdated links
- Documentation: no changhe log since 1.79.0
- Spectre mitigation warning on progress_monitor code
- Warnings on Windows Clang in header code
- Warnings on Windows GCC in header code
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from test.