[SERVER-70815] extend ASSERT macros to stringify literally anything Created: 24/Oct/22  Updated: 29/Oct/23  Resolved: 26/Oct/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.2.0-rc0

Type: Task Priority: Major - P3
Reporter: Henrik Edin Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-77863 Backport ASSERT_DOES_NOT_THROW to v6.0 Backlog
Backwards Compatibility: Fully Compatible
Sprint: Service Arch 2022-10-31
Participants:

 Description   

To use enum class when asserting in unit tests using ASSERT_EQ (or anything built on ASSERT_COMPARE) you also need to define an operator<< for your enum class type.

It would be nice if the assertion macros had a fallback for enum class that explicitly casts to the underlying type so the user does not have to add operator<< (or explicitly casting in unit tests)

Another workaround exists which is to useĀ ASSERT_THAT(..., Eq(...)); which is also clunky.



 Comments   
Comment by Githook User [ 26/Oct/22 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-70815 unittest unify string formatting, support enums
Branch: master
https://github.com/mongodb/mongo/commit/2672f2830edd8813ffec94f737bbfdfee246d078

Comment by Billy Donahue [ 25/Oct/22 ]

This is quite easy to patch in, but I think we have a bigger goal for not much more effort, of just having the ASSERT_THAT and the ASSERT_EQ... facilities share a quality stringification component.
It just takes a litte decomposition of the `unittest` library.

This is a very quick one.

Comment by Billy Donahue [ 24/Oct/22 ]

Wouldn't it be nice if the ASSERT_EQ-family of macros someday worked as well as those "clunky" ASSERT_THAT matchers?

Generated at Thu Feb 08 06:17:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.