ApprovalTests.cpp | Native ApprovalTests for C on Linux , Mac and Windows | Testing library
kandi X-RAY | ApprovalTests.cpp Summary
kandi X-RAY | ApprovalTests.cpp Summary
:arrow_down: Download the latest version (v.10.12.1) of the single header file here. :book: Read the Docs.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ApprovalTests.cpp
ApprovalTests.cpp Key Features
ApprovalTests.cpp Examples and Code Snippets
Community Discussions
Trending Discussions on ApprovalTests.cpp
QUESTION
I'm writing approval tests using the excellent ApprovalTests.cpp library. This library automates generation of "snapshots" of results from a function. Snapshots are generated serializing results of type T
to a file using the ostream& operator<< (T val)
.
This operator has always been the C++ convention for formatting some value to a textual representation. While primitive types support this operator and you can write your own implementation for custom types, there isn't a standard implementation for STL containers like std::vector
.
You can implement your own, even using other libraries like fmt
or pprint
. Here are some example with similar outputs. I use the generic type STREAM
as parameter instead of the concrete type ostream
as recommended by ApprovalTests.cpp but the idea doesn't change.
ANSWER
Answered 2020-Apr-22 at 15:29I'm not aware of any convention or standard proposal for printing containers. However the {fmt} library can print anything range- and tuple-like: https://fmt.dev/latest/api.html#ranges-and-tuple-formatting so you could probably integrate it with ApprovalTests and avoid defining ostream insertion operators yourself.
Disclaimer: I'm the author of {fmt}.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ApprovalTests.cpp
Download The Approval.cpp Starter Project
Read the Getting Started page
Set up your main file.
Read the User Guide on Read the Docs or on GitHub.
Watch the Videos
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page