Posts

Showing posts from August, 2020

Cleaning up log files for C++ Approval Tests

I wrote about the Gilded Rose kata a while back ( https://barneydellar.blogspot.com/2020/07/gilded-rose-katas.html ) and one thing I looked at was the use of Approval Testing to get the code under control.  And I went further, and investigated using the same library to test logging behaviour.  Approval Testing relies on consistent output given consistent input. But logging code typically adds the date and time to the log file. This is desired behaviour, but it makes testing against the log file hard. The C++ Approval Test library ( https://github.com/approvals/ApprovalTests.cpp ) always had support for dealing with this, but it was quite verbose. You had to create a derived TextFileComparator, override the contentsAreEquivalent() method, and then use regex to find and replace the date and time with something hard-coded. class  SpdLogComparator :  public  TextFileComparator { public:     [[nodiscard]]      bool  contentsAreEquivalent(         std::string receivedPath,         std::strin