catch_amalgamated.hpp 509 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. // Catch v3.6.0
  7. // Generated: 2024-05-05 20:53:27.071502
  8. // ----------------------------------------------------------
  9. // This file is an amalgamation of multiple different files.
  10. // You probably shouldn't edit it directly.
  11. // ----------------------------------------------------------
  12. #ifndef CATCH_AMALGAMATED_HPP_INCLUDED
  13. #define CATCH_AMALGAMATED_HPP_INCLUDED
  14. /** \file
  15. * This is a convenience header for Catch2. It includes **all** of Catch2 headers.
  16. *
  17. * Generally the Catch2 users should use specific includes they need,
  18. * but this header can be used instead for ease-of-experimentation, or
  19. * just plain convenience, at the cost of (significantly) increased
  20. * compilation times.
  21. *
  22. * When a new header is added to either the top level folder, or to the
  23. * corresponding internal subfolder, it should be added here. Headers
  24. * added to the various subparts (e.g. matchers, generators, etc...),
  25. * should go their respective catch-all headers.
  26. */
  27. #ifndef CATCH_ALL_HPP_INCLUDED
  28. #define CATCH_ALL_HPP_INCLUDED
  29. /** \file
  30. * This is a convenience header for Catch2's benchmarking. It includes
  31. * **all** of Catch2 headers related to benchmarking.
  32. *
  33. * Generally the Catch2 users should use specific includes they need,
  34. * but this header can be used instead for ease-of-experimentation, or
  35. * just plain convenience, at the cost of (significantly) increased
  36. * compilation times.
  37. *
  38. * When a new header is added to either the `benchmark` folder, or to
  39. * the corresponding internal (detail) subfolder, it should be added here.
  40. */
  41. #ifndef CATCH_BENCHMARK_ALL_HPP_INCLUDED
  42. #define CATCH_BENCHMARK_ALL_HPP_INCLUDED
  43. // Adapted from donated nonius code.
  44. #ifndef CATCH_BENCHMARK_HPP_INCLUDED
  45. #define CATCH_BENCHMARK_HPP_INCLUDED
  46. #ifndef CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  47. #define CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  48. // Detect a number of compiler features - by compiler
  49. // The following features are defined:
  50. //
  51. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  52. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  53. // CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled?
  54. // ****************
  55. // Note to maintainers: if new toggles are added please document them
  56. // in configuration.md, too
  57. // ****************
  58. // In general each macro has a _NO_<feature name> form
  59. // (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
  60. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  61. // can be combined, en-mass, with the _NO_ forms later.
  62. #ifndef CATCH_PLATFORM_HPP_INCLUDED
  63. #define CATCH_PLATFORM_HPP_INCLUDED
  64. // See e.g.:
  65. // https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
  66. #ifdef __APPLE__
  67. # ifndef __has_extension
  68. # define __has_extension(x) 0
  69. # endif
  70. # include <TargetConditionals.h>
  71. # if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
  72. (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
  73. # define CATCH_PLATFORM_MAC
  74. # elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
  75. # define CATCH_PLATFORM_IPHONE
  76. # endif
  77. #elif defined(linux) || defined(__linux) || defined(__linux__)
  78. # define CATCH_PLATFORM_LINUX
  79. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
  80. # define CATCH_PLATFORM_WINDOWS
  81. # if defined( WINAPI_FAMILY ) && ( WINAPI_FAMILY == WINAPI_FAMILY_APP )
  82. # define CATCH_PLATFORM_WINDOWS_UWP
  83. # endif
  84. #elif defined(__ORBIS__) || defined(__PROSPERO__)
  85. # define CATCH_PLATFORM_PLAYSTATION
  86. #endif
  87. #endif // CATCH_PLATFORM_HPP_INCLUDED
  88. #ifdef __cplusplus
  89. # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
  90. # define CATCH_CPP17_OR_GREATER
  91. # endif
  92. # if (__cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L)
  93. # define CATCH_CPP20_OR_GREATER
  94. # endif
  95. #endif
  96. // Only GCC compiler should be used in this block, so other compilers trying to
  97. // mask themselves as GCC should be ignored.
  98. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) && !defined(__NVCOMPILER)
  99. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
  100. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
  101. // This only works on GCC 9+. so we have to also add a global suppression of Wparentheses
  102. // for older versions of GCC.
  103. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  104. _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" )
  105. # define CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
  106. _Pragma( "GCC diagnostic ignored \"-Wunused-result\"" )
  107. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  108. _Pragma( "GCC diagnostic ignored \"-Wunused-variable\"" )
  109. # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  110. _Pragma( "GCC diagnostic ignored \"-Wuseless-cast\"" )
  111. # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
  112. _Pragma( "GCC diagnostic ignored \"-Wshadow\"" )
  113. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
  114. #endif
  115. #if defined(__NVCOMPILER)
  116. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "diag push" )
  117. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "diag pop" )
  118. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "diag_suppress declared_but_not_referenced" )
  119. #endif
  120. #if defined(__CUDACC__) && !defined(__clang__)
  121. # ifdef __NVCC_DIAG_PRAGMA_SUPPORT__
  122. // New pragmas introduced in CUDA 11.5+
  123. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic push" )
  124. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic pop" )
  125. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "nv_diag_suppress 177" )
  126. # else
  127. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "diag_suppress 177" )
  128. # endif
  129. #endif
  130. // clang-cl defines _MSC_VER as well as __clang__, which could cause the
  131. // start/stop internal suppression macros to be double defined.
  132. #if defined(__clang__) && !defined(_MSC_VER)
  133. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
  134. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
  135. #endif // __clang__ && !_MSC_VER
  136. #if defined(__clang__)
  137. // As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
  138. // which results in calls to destructors being emitted for each temporary,
  139. // without a matching initialization. In practice, this can result in something
  140. // like `std::string::~string` being called on an uninitialized value.
  141. //
  142. // For example, this code will likely segfault under IBM XL:
  143. // ```
  144. // REQUIRE(std::string("12") + "34" == "1234")
  145. // ```
  146. //
  147. // Similarly, NVHPC's implementation of `__builtin_constant_p` has a bug which
  148. // results in calls to the immediately evaluated lambda expressions to be
  149. // reported as unevaluated lambdas.
  150. // https://developer.nvidia.com/nvidia_bug/3321845.
  151. //
  152. // Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
  153. # if !defined(__ibmxl__) && !defined(__CUDACC__) && !defined( __NVCOMPILER )
  154. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */
  155. # endif
  156. # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  157. _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
  158. _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
  159. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  160. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  161. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  162. _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
  163. # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  164. _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
  165. # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  166. _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
  167. # define CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \
  168. _Pragma( "clang diagnostic ignored \"-Wcomma\"" )
  169. # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
  170. _Pragma( "clang diagnostic ignored \"-Wshadow\"" )
  171. #endif // __clang__
  172. ////////////////////////////////////////////////////////////////////////////////
  173. // We know some environments not to support full POSIX signals
  174. #if defined( CATCH_PLATFORM_WINDOWS ) || \
  175. defined( CATCH_PLATFORM_PLAYSTATION ) || \
  176. defined( __CYGWIN__ ) || \
  177. defined( __QNX__ ) || \
  178. defined( __EMSCRIPTEN__ ) || \
  179. defined( __DJGPP__ ) || \
  180. defined( __OS400__ )
  181. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  182. #else
  183. # define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
  184. #endif
  185. ////////////////////////////////////////////////////////////////////////////////
  186. // Assume that some platforms do not support getenv.
  187. #if defined( CATCH_PLATFORM_WINDOWS_UWP ) || \
  188. defined( CATCH_PLATFORM_PLAYSTATION ) || \
  189. defined( _GAMING_XBOX )
  190. # define CATCH_INTERNAL_CONFIG_NO_GETENV
  191. #else
  192. # define CATCH_INTERNAL_CONFIG_GETENV
  193. #endif
  194. ////////////////////////////////////////////////////////////////////////////////
  195. // Android somehow still does not support std::to_string
  196. #if defined(__ANDROID__)
  197. # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
  198. #endif
  199. ////////////////////////////////////////////////////////////////////////////////
  200. // Not all Windows environments support SEH properly
  201. #if defined(__MINGW32__)
  202. # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
  203. #endif
  204. ////////////////////////////////////////////////////////////////////////////////
  205. // PS4
  206. #if defined(__ORBIS__)
  207. # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
  208. #endif
  209. ////////////////////////////////////////////////////////////////////////////////
  210. // Cygwin
  211. #ifdef __CYGWIN__
  212. // Required for some versions of Cygwin to declare gettimeofday
  213. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  214. # define _BSD_SOURCE
  215. // some versions of cygwin (most) do not support std::to_string. Use the libstd check.
  216. // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
  217. # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
  218. && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
  219. # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
  220. # endif
  221. #endif // __CYGWIN__
  222. ////////////////////////////////////////////////////////////////////////////////
  223. // Visual C++
  224. #if defined(_MSC_VER)
  225. // We want to defer to nvcc-specific warning suppression if we are compiled
  226. // with nvcc masquerading for MSVC.
  227. # if !defined( __CUDACC__ )
  228. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  229. __pragma( warning( push ) )
  230. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  231. __pragma( warning( pop ) )
  232. # endif
  233. // Universal Windows platform does not support SEH
  234. // Or console colours (or console at all...)
  235. # if defined(CATCH_PLATFORM_WINDOWS_UWP)
  236. # define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
  237. # else
  238. # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  239. # endif
  240. // MSVC traditional preprocessor needs some workaround for __VA_ARGS__
  241. // _MSVC_TRADITIONAL == 0 means new conformant preprocessor
  242. // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
  243. # if !defined(__clang__) // Handle Clang masquerading for msvc
  244. # if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
  245. # define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  246. # endif // MSVC_TRADITIONAL
  247. # endif // __clang__
  248. #endif // _MSC_VER
  249. #if defined(_REENTRANT) || defined(_MSC_VER)
  250. // Enable async processing, as -pthread is specified or no additional linking is required
  251. # define CATCH_INTERNAL_CONFIG_USE_ASYNC
  252. #endif // _MSC_VER
  253. ////////////////////////////////////////////////////////////////////////////////
  254. // Check if we are compiled with -fno-exceptions or equivalent
  255. #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
  256. # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
  257. #endif
  258. ////////////////////////////////////////////////////////////////////////////////
  259. // Embarcadero C++Build
  260. #if defined(__BORLANDC__)
  261. #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
  262. #endif
  263. ////////////////////////////////////////////////////////////////////////////////
  264. // RTX is a special version of Windows that is real time.
  265. // This means that it is detected as Windows, but does not provide
  266. // the same set of capabilities as real Windows does.
  267. #if defined(UNDER_RTSS) || defined(RTX64_BUILD)
  268. #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
  269. #define CATCH_INTERNAL_CONFIG_NO_ASYNC
  270. #define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
  271. #endif
  272. #if !defined(_GLIBCXX_USE_C99_MATH_TR1)
  273. #define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
  274. #endif
  275. // Various stdlib support checks that require __has_include
  276. #if defined(__has_include)
  277. // Check if string_view is available and usable
  278. #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
  279. # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
  280. #endif
  281. // Check if optional is available and usable
  282. # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
  283. # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
  284. # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
  285. // Check if byte is available and usable
  286. # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
  287. # include <cstddef>
  288. # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
  289. # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
  290. # endif
  291. # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
  292. // Check if variant is available and usable
  293. # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
  294. # if defined(__clang__) && (__clang_major__ < 8)
  295. // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
  296. // fix should be in clang 8, workaround in libstdc++ 8.2
  297. # include <ciso646>
  298. # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
  299. # define CATCH_CONFIG_NO_CPP17_VARIANT
  300. # else
  301. # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
  302. # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
  303. # else
  304. # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
  305. # endif // defined(__clang__) && (__clang_major__ < 8)
  306. # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
  307. #endif // defined(__has_include)
  308. #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
  309. # define CATCH_CONFIG_WINDOWS_SEH
  310. #endif
  311. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  312. #if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
  313. # define CATCH_CONFIG_POSIX_SIGNALS
  314. #endif
  315. #if defined(CATCH_INTERNAL_CONFIG_GETENV) && !defined(CATCH_INTERNAL_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_NO_GETENV) && !defined(CATCH_CONFIG_GETENV)
  316. # define CATCH_CONFIG_GETENV
  317. #endif
  318. #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
  319. # define CATCH_CONFIG_CPP11_TO_STRING
  320. #endif
  321. #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
  322. # define CATCH_CONFIG_CPP17_OPTIONAL
  323. #endif
  324. #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
  325. # define CATCH_CONFIG_CPP17_STRING_VIEW
  326. #endif
  327. #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
  328. # define CATCH_CONFIG_CPP17_VARIANT
  329. #endif
  330. #if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
  331. # define CATCH_CONFIG_CPP17_BYTE
  332. #endif
  333. #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
  334. # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
  335. #endif
  336. #if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
  337. # define CATCH_CONFIG_NEW_CAPTURE
  338. #endif
  339. #if !defined( CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED ) && \
  340. !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) && \
  341. !defined( CATCH_CONFIG_NO_DISABLE_EXCEPTIONS )
  342. # define CATCH_CONFIG_DISABLE_EXCEPTIONS
  343. #endif
  344. #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
  345. # define CATCH_CONFIG_POLYFILL_ISNAN
  346. #endif
  347. #if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
  348. # define CATCH_CONFIG_USE_ASYNC
  349. #endif
  350. #if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
  351. # define CATCH_CONFIG_GLOBAL_NEXTAFTER
  352. #endif
  353. // Even if we do not think the compiler has that warning, we still have
  354. // to provide a macro that can be used by the code.
  355. #if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
  356. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
  357. #endif
  358. #if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
  359. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  360. #endif
  361. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  362. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  363. #endif
  364. #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
  365. # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
  366. #endif
  367. #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT)
  368. # define CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT
  369. #endif
  370. #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS)
  371. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
  372. #endif
  373. #if !defined(CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS)
  374. # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS
  375. #endif
  376. #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
  377. # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
  378. #endif
  379. #if !defined( CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS )
  380. # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  381. #endif
  382. #if !defined( CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS )
  383. # define CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS
  384. #endif
  385. #if !defined( CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS )
  386. # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS
  387. #endif
  388. // The goal of this macro is to avoid evaluation of the arguments, but
  389. // still have the compiler warn on problems inside...
  390. #if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN)
  391. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...)
  392. #endif
  393. #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
  394. # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  395. #elif defined(__clang__) && (__clang_major__ < 5)
  396. # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  397. #endif
  398. #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  399. #define CATCH_TRY if ((true))
  400. #define CATCH_CATCH_ALL if ((false))
  401. #define CATCH_CATCH_ANON(type) if ((false))
  402. #else
  403. #define CATCH_TRY try
  404. #define CATCH_CATCH_ALL catch (...)
  405. #define CATCH_CATCH_ANON(type) catch (type)
  406. #endif
  407. #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
  408. #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  409. #endif
  410. #if defined( CATCH_PLATFORM_WINDOWS ) && \
  411. !defined( CATCH_CONFIG_COLOUR_WIN32 ) && \
  412. !defined( CATCH_CONFIG_NO_COLOUR_WIN32 ) && \
  413. !defined( CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 )
  414. # define CATCH_CONFIG_COLOUR_WIN32
  415. #endif
  416. #if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \
  417. !defined( CATCH_CONFIG_STATIC )
  418. # ifdef Catch2_EXPORTS
  419. # define CATCH_EXPORT //__declspec( dllexport ) // not needed
  420. # else
  421. # define CATCH_EXPORT __declspec( dllimport )
  422. # endif
  423. #else
  424. # define CATCH_EXPORT
  425. #endif
  426. #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  427. #ifndef CATCH_CONTEXT_HPP_INCLUDED
  428. #define CATCH_CONTEXT_HPP_INCLUDED
  429. namespace Catch {
  430. class IResultCapture;
  431. class IConfig;
  432. class Context {
  433. IConfig const* m_config = nullptr;
  434. IResultCapture* m_resultCapture = nullptr;
  435. CATCH_EXPORT static Context* currentContext;
  436. friend Context& getCurrentMutableContext();
  437. friend Context const& getCurrentContext();
  438. static void createContext();
  439. friend void cleanUpContext();
  440. public:
  441. IResultCapture* getResultCapture() const { return m_resultCapture; }
  442. IConfig const* getConfig() const { return m_config; }
  443. void setResultCapture( IResultCapture* resultCapture );
  444. void setConfig( IConfig const* config );
  445. };
  446. Context& getCurrentMutableContext();
  447. inline Context const& getCurrentContext() {
  448. // We duplicate the logic from `getCurrentMutableContext` here,
  449. // to avoid paying the call overhead in debug mode.
  450. if ( !Context::currentContext ) { Context::createContext(); }
  451. // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
  452. return *Context::currentContext;
  453. }
  454. void cleanUpContext();
  455. class SimplePcg32;
  456. SimplePcg32& sharedRng();
  457. }
  458. #endif // CATCH_CONTEXT_HPP_INCLUDED
  459. #ifndef CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  460. #define CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  461. #include <type_traits>
  462. //! Replacement for std::move with better compile time performance
  463. #define CATCH_MOVE(...) static_cast<std::remove_reference_t<decltype(__VA_ARGS__)>&&>(__VA_ARGS__)
  464. //! Replacement for std::forward with better compile time performance
  465. #define CATCH_FORWARD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
  466. #endif // CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  467. #ifndef CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  468. #define CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  469. namespace Catch {
  470. //! Used to signal that an assertion macro failed
  471. struct TestFailureException{};
  472. //! Used to signal that the remainder of a test should be skipped
  473. struct TestSkipException {};
  474. /**
  475. * Outlines throwing of `TestFailureException` into a single TU
  476. *
  477. * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers.
  478. */
  479. [[noreturn]] void throw_test_failure_exception();
  480. /**
  481. * Outlines throwing of `TestSkipException` into a single TU
  482. *
  483. * Also handles `CATCH_CONFIG_DISABLE_EXCEPTIONS` for callers.
  484. */
  485. [[noreturn]] void throw_test_skip_exception();
  486. } // namespace Catch
  487. #endif // CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  488. #ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED
  489. #define CATCH_UNIQUE_NAME_HPP_INCLUDED
  490. /** \file
  491. * Wrapper for the CONFIG configuration option
  492. *
  493. * When generating internal unique names, there are two options. Either
  494. * we mix in the current line number, or mix in an incrementing number.
  495. * We prefer the latter, using `__COUNTER__`, but users might want to
  496. * use the former.
  497. */
  498. #ifndef CATCH_CONFIG_COUNTER_HPP_INCLUDED
  499. #define CATCH_CONFIG_COUNTER_HPP_INCLUDED
  500. #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
  501. #define CATCH_INTERNAL_CONFIG_COUNTER
  502. #endif
  503. #if defined( CATCH_INTERNAL_CONFIG_COUNTER ) && \
  504. !defined( CATCH_CONFIG_NO_COUNTER ) && \
  505. !defined( CATCH_CONFIG_COUNTER )
  506. # define CATCH_CONFIG_COUNTER
  507. #endif
  508. #endif // CATCH_CONFIG_COUNTER_HPP_INCLUDED
  509. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  510. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  511. #ifdef CATCH_CONFIG_COUNTER
  512. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  513. #else
  514. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  515. #endif
  516. #endif // CATCH_UNIQUE_NAME_HPP_INCLUDED
  517. #ifndef CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  518. #define CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  519. #include <string>
  520. #include <chrono>
  521. #ifndef CATCH_STRINGREF_HPP_INCLUDED
  522. #define CATCH_STRINGREF_HPP_INCLUDED
  523. #include <cstddef>
  524. #include <string>
  525. #include <iosfwd>
  526. #include <cassert>
  527. #include <cstring>
  528. namespace Catch {
  529. /// A non-owning string class (similar to the forthcoming std::string_view)
  530. /// Note that, because a StringRef may be a substring of another string,
  531. /// it may not be null terminated.
  532. class StringRef {
  533. public:
  534. using size_type = std::size_t;
  535. using const_iterator = const char*;
  536. static constexpr size_type npos{ static_cast<size_type>( -1 ) };
  537. private:
  538. static constexpr char const* const s_empty = "";
  539. char const* m_start = s_empty;
  540. size_type m_size = 0;
  541. public: // construction
  542. constexpr StringRef() noexcept = default;
  543. StringRef( char const* rawChars ) noexcept;
  544. constexpr StringRef( char const* rawChars, size_type size ) noexcept
  545. : m_start( rawChars ),
  546. m_size( size )
  547. {}
  548. StringRef( std::string const& stdString ) noexcept
  549. : m_start( stdString.c_str() ),
  550. m_size( stdString.size() )
  551. {}
  552. explicit operator std::string() const {
  553. return std::string(m_start, m_size);
  554. }
  555. public: // operators
  556. auto operator == ( StringRef other ) const noexcept -> bool {
  557. return m_size == other.m_size
  558. && (std::memcmp( m_start, other.m_start, m_size ) == 0);
  559. }
  560. auto operator != (StringRef other) const noexcept -> bool {
  561. return !(*this == other);
  562. }
  563. constexpr auto operator[] ( size_type index ) const noexcept -> char {
  564. assert(index < m_size);
  565. return m_start[index];
  566. }
  567. bool operator<(StringRef rhs) const noexcept;
  568. public: // named queries
  569. constexpr auto empty() const noexcept -> bool {
  570. return m_size == 0;
  571. }
  572. constexpr auto size() const noexcept -> size_type {
  573. return m_size;
  574. }
  575. // Returns a substring of [start, start + length).
  576. // If start + length > size(), then the substring is [start, size()).
  577. // If start > size(), then the substring is empty.
  578. constexpr StringRef substr(size_type start, size_type length) const noexcept {
  579. if (start < m_size) {
  580. const auto shortened_size = m_size - start;
  581. return StringRef(m_start + start, (shortened_size < length) ? shortened_size : length);
  582. } else {
  583. return StringRef();
  584. }
  585. }
  586. // Returns the current start pointer. May not be null-terminated.
  587. constexpr char const* data() const noexcept {
  588. return m_start;
  589. }
  590. constexpr const_iterator begin() const { return m_start; }
  591. constexpr const_iterator end() const { return m_start + m_size; }
  592. friend std::string& operator += (std::string& lhs, StringRef rhs);
  593. friend std::ostream& operator << (std::ostream& os, StringRef str);
  594. friend std::string operator+(StringRef lhs, StringRef rhs);
  595. /**
  596. * Provides a three-way comparison with rhs
  597. *
  598. * Returns negative number if lhs < rhs, 0 if lhs == rhs, and a positive
  599. * number if lhs > rhs
  600. */
  601. int compare( StringRef rhs ) const;
  602. };
  603. constexpr auto operator ""_sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
  604. return StringRef( rawChars, size );
  605. }
  606. } // namespace Catch
  607. constexpr auto operator ""_catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
  608. return Catch::StringRef( rawChars, size );
  609. }
  610. #endif // CATCH_STRINGREF_HPP_INCLUDED
  611. #ifndef CATCH_RESULT_TYPE_HPP_INCLUDED
  612. #define CATCH_RESULT_TYPE_HPP_INCLUDED
  613. namespace Catch {
  614. // ResultWas::OfType enum
  615. struct ResultWas { enum OfType {
  616. Unknown = -1,
  617. Ok = 0,
  618. Info = 1,
  619. Warning = 2,
  620. // TODO: Should explicit skip be considered "not OK" (cf. isOk)? I.e., should it have the failure bit?
  621. ExplicitSkip = 4,
  622. FailureBit = 0x10,
  623. ExpressionFailed = FailureBit | 1,
  624. ExplicitFailure = FailureBit | 2,
  625. Exception = 0x100 | FailureBit,
  626. ThrewException = Exception | 1,
  627. DidntThrowException = Exception | 2,
  628. FatalErrorCondition = 0x200 | FailureBit
  629. }; };
  630. bool isOk( ResultWas::OfType resultType );
  631. bool isJustInfo( int flags );
  632. // ResultDisposition::Flags enum
  633. struct ResultDisposition { enum Flags {
  634. Normal = 0x01,
  635. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  636. FalseTest = 0x04, // Prefix expression with !
  637. SuppressFail = 0x08 // Failures are reported but do not fail the test
  638. }; };
  639. ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs );
  640. bool shouldContinueOnFailure( int flags );
  641. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  642. bool shouldSuppressFailure( int flags );
  643. } // end namespace Catch
  644. #endif // CATCH_RESULT_TYPE_HPP_INCLUDED
  645. #ifndef CATCH_UNIQUE_PTR_HPP_INCLUDED
  646. #define CATCH_UNIQUE_PTR_HPP_INCLUDED
  647. #include <cassert>
  648. #include <type_traits>
  649. namespace Catch {
  650. namespace Detail {
  651. /**
  652. * A reimplementation of `std::unique_ptr` for improved compilation performance
  653. *
  654. * Does not support arrays nor custom deleters.
  655. */
  656. template <typename T>
  657. class unique_ptr {
  658. T* m_ptr;
  659. public:
  660. constexpr unique_ptr(std::nullptr_t = nullptr):
  661. m_ptr{}
  662. {}
  663. explicit constexpr unique_ptr(T* ptr):
  664. m_ptr(ptr)
  665. {}
  666. template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
  667. unique_ptr(unique_ptr<U>&& from):
  668. m_ptr(from.release())
  669. {}
  670. template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
  671. unique_ptr& operator=(unique_ptr<U>&& from) {
  672. reset(from.release());
  673. return *this;
  674. }
  675. unique_ptr(unique_ptr const&) = delete;
  676. unique_ptr& operator=(unique_ptr const&) = delete;
  677. unique_ptr(unique_ptr&& rhs) noexcept:
  678. m_ptr(rhs.m_ptr) {
  679. rhs.m_ptr = nullptr;
  680. }
  681. unique_ptr& operator=(unique_ptr&& rhs) noexcept {
  682. reset(rhs.release());
  683. return *this;
  684. }
  685. ~unique_ptr() {
  686. delete m_ptr;
  687. }
  688. T& operator*() {
  689. assert(m_ptr);
  690. return *m_ptr;
  691. }
  692. T const& operator*() const {
  693. assert(m_ptr);
  694. return *m_ptr;
  695. }
  696. T* operator->() noexcept {
  697. assert(m_ptr);
  698. return m_ptr;
  699. }
  700. T const* operator->() const noexcept {
  701. assert(m_ptr);
  702. return m_ptr;
  703. }
  704. T* get() { return m_ptr; }
  705. T const* get() const { return m_ptr; }
  706. void reset(T* ptr = nullptr) {
  707. delete m_ptr;
  708. m_ptr = ptr;
  709. }
  710. T* release() {
  711. auto temp = m_ptr;
  712. m_ptr = nullptr;
  713. return temp;
  714. }
  715. explicit operator bool() const {
  716. return m_ptr;
  717. }
  718. friend void swap(unique_ptr& lhs, unique_ptr& rhs) {
  719. auto temp = lhs.m_ptr;
  720. lhs.m_ptr = rhs.m_ptr;
  721. rhs.m_ptr = temp;
  722. }
  723. };
  724. //! Specialization to cause compile-time error for arrays
  725. template <typename T>
  726. class unique_ptr<T[]>;
  727. template <typename T, typename... Args>
  728. unique_ptr<T> make_unique(Args&&... args) {
  729. return unique_ptr<T>(new T(CATCH_FORWARD(args)...));
  730. }
  731. } // end namespace Detail
  732. } // end namespace Catch
  733. #endif // CATCH_UNIQUE_PTR_HPP_INCLUDED
  734. #ifndef CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
  735. #define CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
  736. // Adapted from donated nonius code.
  737. #ifndef CATCH_CLOCK_HPP_INCLUDED
  738. #define CATCH_CLOCK_HPP_INCLUDED
  739. #include <chrono>
  740. namespace Catch {
  741. namespace Benchmark {
  742. using IDuration = std::chrono::nanoseconds;
  743. using FDuration = std::chrono::duration<double, std::nano>;
  744. template <typename Clock>
  745. using TimePoint = typename Clock::time_point;
  746. using default_clock = std::chrono::steady_clock;
  747. } // namespace Benchmark
  748. } // namespace Catch
  749. #endif // CATCH_CLOCK_HPP_INCLUDED
  750. namespace Catch {
  751. // We cannot forward declare the type with default template argument
  752. // multiple times, so it is split out into a separate header so that
  753. // we can prevent multiple declarations in dependees
  754. template <typename Duration = Benchmark::FDuration>
  755. struct BenchmarkStats;
  756. } // end namespace Catch
  757. #endif // CATCH_BENCHMARK_STATS_FWD_HPP_INCLUDED
  758. namespace Catch {
  759. class AssertionResult;
  760. struct AssertionInfo;
  761. struct SectionInfo;
  762. struct SectionEndInfo;
  763. struct MessageInfo;
  764. struct MessageBuilder;
  765. struct Counts;
  766. struct AssertionReaction;
  767. struct SourceLineInfo;
  768. class ITransientExpression;
  769. class IGeneratorTracker;
  770. struct BenchmarkInfo;
  771. namespace Generators {
  772. class GeneratorUntypedBase;
  773. using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;
  774. }
  775. class IResultCapture {
  776. public:
  777. virtual ~IResultCapture();
  778. virtual void notifyAssertionStarted( AssertionInfo const& info ) = 0;
  779. virtual bool sectionStarted( StringRef sectionName,
  780. SourceLineInfo const& sectionLineInfo,
  781. Counts& assertions ) = 0;
  782. virtual void sectionEnded( SectionEndInfo&& endInfo ) = 0;
  783. virtual void sectionEndedEarly( SectionEndInfo&& endInfo ) = 0;
  784. virtual IGeneratorTracker*
  785. acquireGeneratorTracker( StringRef generatorName,
  786. SourceLineInfo const& lineInfo ) = 0;
  787. virtual IGeneratorTracker*
  788. createGeneratorTracker( StringRef generatorName,
  789. SourceLineInfo lineInfo,
  790. Generators::GeneratorBasePtr&& generator ) = 0;
  791. virtual void benchmarkPreparing( StringRef name ) = 0;
  792. virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
  793. virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
  794. virtual void benchmarkFailed( StringRef error ) = 0;
  795. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  796. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  797. virtual void emplaceUnscopedMessage( MessageBuilder&& builder ) = 0;
  798. virtual void handleFatalErrorCondition( StringRef message ) = 0;
  799. virtual void handleExpr
  800. ( AssertionInfo const& info,
  801. ITransientExpression const& expr,
  802. AssertionReaction& reaction ) = 0;
  803. virtual void handleMessage
  804. ( AssertionInfo const& info,
  805. ResultWas::OfType resultType,
  806. StringRef message,
  807. AssertionReaction& reaction ) = 0;
  808. virtual void handleUnexpectedExceptionNotThrown
  809. ( AssertionInfo const& info,
  810. AssertionReaction& reaction ) = 0;
  811. virtual void handleUnexpectedInflightException
  812. ( AssertionInfo const& info,
  813. std::string&& message,
  814. AssertionReaction& reaction ) = 0;
  815. virtual void handleIncomplete
  816. ( AssertionInfo const& info ) = 0;
  817. virtual void handleNonExpr
  818. ( AssertionInfo const &info,
  819. ResultWas::OfType resultType,
  820. AssertionReaction &reaction ) = 0;
  821. virtual bool lastAssertionPassed() = 0;
  822. virtual void assertionPassed() = 0;
  823. // Deprecated, do not use:
  824. virtual std::string getCurrentTestName() const = 0;
  825. virtual const AssertionResult* getLastResult() const = 0;
  826. virtual void exceptionEarlyReported() = 0;
  827. };
  828. IResultCapture& getResultCapture();
  829. }
  830. #endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  831. #ifndef CATCH_INTERFACES_CONFIG_HPP_INCLUDED
  832. #define CATCH_INTERFACES_CONFIG_HPP_INCLUDED
  833. #ifndef CATCH_NONCOPYABLE_HPP_INCLUDED
  834. #define CATCH_NONCOPYABLE_HPP_INCLUDED
  835. namespace Catch {
  836. namespace Detail {
  837. //! Deriving classes become noncopyable and nonmovable
  838. class NonCopyable {
  839. NonCopyable( NonCopyable const& ) = delete;
  840. NonCopyable( NonCopyable&& ) = delete;
  841. NonCopyable& operator=( NonCopyable const& ) = delete;
  842. NonCopyable& operator=( NonCopyable&& ) = delete;
  843. protected:
  844. NonCopyable() noexcept = default;
  845. };
  846. } // namespace Detail
  847. } // namespace Catch
  848. #endif // CATCH_NONCOPYABLE_HPP_INCLUDED
  849. #include <chrono>
  850. #include <iosfwd>
  851. #include <string>
  852. #include <vector>
  853. namespace Catch {
  854. enum class Verbosity {
  855. Quiet = 0,
  856. Normal,
  857. High
  858. };
  859. struct WarnAbout { enum What {
  860. Nothing = 0x00,
  861. //! A test case or leaf section did not run any assertions
  862. NoAssertions = 0x01,
  863. //! A command line test spec matched no test cases
  864. UnmatchedTestSpec = 0x02,
  865. }; };
  866. enum class ShowDurations {
  867. DefaultForReporter,
  868. Always,
  869. Never
  870. };
  871. enum class TestRunOrder {
  872. Declared,
  873. LexicographicallySorted,
  874. Randomized
  875. };
  876. enum class ColourMode : std::uint8_t {
  877. //! Let Catch2 pick implementation based on platform detection
  878. PlatformDefault,
  879. //! Use ANSI colour code escapes
  880. ANSI,
  881. //! Use Win32 console colour API
  882. Win32,
  883. //! Don't use any colour
  884. None
  885. };
  886. struct WaitForKeypress { enum When {
  887. Never,
  888. BeforeStart = 1,
  889. BeforeExit = 2,
  890. BeforeStartAndExit = BeforeStart | BeforeExit
  891. }; };
  892. class TestSpec;
  893. class IStream;
  894. class IConfig : public Detail::NonCopyable {
  895. public:
  896. virtual ~IConfig();
  897. virtual bool allowThrows() const = 0;
  898. virtual StringRef name() const = 0;
  899. virtual bool includeSuccessfulResults() const = 0;
  900. virtual bool shouldDebugBreak() const = 0;
  901. virtual bool warnAboutMissingAssertions() const = 0;
  902. virtual bool warnAboutUnmatchedTestSpecs() const = 0;
  903. virtual bool zeroTestsCountAsSuccess() const = 0;
  904. virtual int abortAfter() const = 0;
  905. virtual bool showInvisibles() const = 0;
  906. virtual ShowDurations showDurations() const = 0;
  907. virtual double minDuration() const = 0;
  908. virtual TestSpec const& testSpec() const = 0;
  909. virtual bool hasTestFilters() const = 0;
  910. virtual std::vector<std::string> const& getTestsOrTags() const = 0;
  911. virtual TestRunOrder runOrder() const = 0;
  912. virtual uint32_t rngSeed() const = 0;
  913. virtual unsigned int shardCount() const = 0;
  914. virtual unsigned int shardIndex() const = 0;
  915. virtual ColourMode defaultColourMode() const = 0;
  916. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  917. virtual Verbosity verbosity() const = 0;
  918. virtual bool skipBenchmarks() const = 0;
  919. virtual bool benchmarkNoAnalysis() const = 0;
  920. virtual unsigned int benchmarkSamples() const = 0;
  921. virtual double benchmarkConfidenceInterval() const = 0;
  922. virtual unsigned int benchmarkResamples() const = 0;
  923. virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0;
  924. };
  925. }
  926. #endif // CATCH_INTERFACES_CONFIG_HPP_INCLUDED
  927. #ifndef CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  928. #define CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  929. #include <string>
  930. namespace Catch {
  931. class TestCaseHandle;
  932. struct TestCaseInfo;
  933. class ITestCaseRegistry;
  934. class IExceptionTranslatorRegistry;
  935. class IExceptionTranslator;
  936. class ReporterRegistry;
  937. class IReporterFactory;
  938. class ITagAliasRegistry;
  939. class ITestInvoker;
  940. class IMutableEnumValuesRegistry;
  941. struct SourceLineInfo;
  942. class StartupExceptionRegistry;
  943. class EventListenerFactory;
  944. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  945. class IRegistryHub {
  946. public:
  947. virtual ~IRegistryHub(); // = default
  948. virtual ReporterRegistry const& getReporterRegistry() const = 0;
  949. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  950. virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
  951. virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
  952. virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
  953. };
  954. class IMutableRegistryHub {
  955. public:
  956. virtual ~IMutableRegistryHub(); // = default
  957. virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
  958. virtual void registerListener( Detail::unique_ptr<EventListenerFactory> factory ) = 0;
  959. virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
  960. virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
  961. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
  962. virtual void registerStartupException() noexcept = 0;
  963. virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0;
  964. };
  965. IRegistryHub const& getRegistryHub();
  966. IMutableRegistryHub& getMutableRegistryHub();
  967. void cleanUp();
  968. std::string translateActiveException();
  969. }
  970. #endif // CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  971. #ifndef CATCH_BENCHMARK_STATS_HPP_INCLUDED
  972. #define CATCH_BENCHMARK_STATS_HPP_INCLUDED
  973. // Adapted from donated nonius code.
  974. #ifndef CATCH_ESTIMATE_HPP_INCLUDED
  975. #define CATCH_ESTIMATE_HPP_INCLUDED
  976. namespace Catch {
  977. namespace Benchmark {
  978. template <typename Type>
  979. struct Estimate {
  980. Type point;
  981. Type lower_bound;
  982. Type upper_bound;
  983. double confidence_interval;
  984. };
  985. } // namespace Benchmark
  986. } // namespace Catch
  987. #endif // CATCH_ESTIMATE_HPP_INCLUDED
  988. // Adapted from donated nonius code.
  989. #ifndef CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
  990. #define CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
  991. namespace Catch {
  992. namespace Benchmark {
  993. struct OutlierClassification {
  994. int samples_seen = 0;
  995. int low_severe = 0; // more than 3 times IQR below Q1
  996. int low_mild = 0; // 1.5 to 3 times IQR below Q1
  997. int high_mild = 0; // 1.5 to 3 times IQR above Q3
  998. int high_severe = 0; // more than 3 times IQR above Q3
  999. int total() const {
  1000. return low_severe + low_mild + high_mild + high_severe;
  1001. }
  1002. };
  1003. } // namespace Benchmark
  1004. } // namespace Catch
  1005. #endif // CATCH_OUTLIERS_CLASSIFICATION_HPP_INCLUDED
  1006. // The fwd decl & default specialization needs to be seen by VS2017 before
  1007. // BenchmarkStats itself, or VS2017 will report compilation error.
  1008. #include <string>
  1009. #include <vector>
  1010. namespace Catch {
  1011. struct BenchmarkInfo {
  1012. std::string name;
  1013. double estimatedDuration;
  1014. int iterations;
  1015. unsigned int samples;
  1016. unsigned int resamples;
  1017. double clockResolution;
  1018. double clockCost;
  1019. };
  1020. // We need to keep template parameter for backwards compatibility,
  1021. // but we also do not want to use the template paraneter.
  1022. template <class Dummy>
  1023. struct BenchmarkStats {
  1024. BenchmarkInfo info;
  1025. std::vector<Benchmark::FDuration> samples;
  1026. Benchmark::Estimate<Benchmark::FDuration> mean;
  1027. Benchmark::Estimate<Benchmark::FDuration> standardDeviation;
  1028. Benchmark::OutlierClassification outliers;
  1029. double outlierVariance;
  1030. };
  1031. } // end namespace Catch
  1032. #endif // CATCH_BENCHMARK_STATS_HPP_INCLUDED
  1033. // Adapted from donated nonius code.
  1034. #ifndef CATCH_ENVIRONMENT_HPP_INCLUDED
  1035. #define CATCH_ENVIRONMENT_HPP_INCLUDED
  1036. namespace Catch {
  1037. namespace Benchmark {
  1038. struct EnvironmentEstimate {
  1039. FDuration mean;
  1040. OutlierClassification outliers;
  1041. };
  1042. struct Environment {
  1043. EnvironmentEstimate clock_resolution;
  1044. EnvironmentEstimate clock_cost;
  1045. };
  1046. } // namespace Benchmark
  1047. } // namespace Catch
  1048. #endif // CATCH_ENVIRONMENT_HPP_INCLUDED
  1049. // Adapted from donated nonius code.
  1050. #ifndef CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1051. #define CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1052. // Adapted from donated nonius code.
  1053. #ifndef CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1054. #define CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1055. // Adapted from donated nonius code.
  1056. #ifndef CATCH_CHRONOMETER_HPP_INCLUDED
  1057. #define CATCH_CHRONOMETER_HPP_INCLUDED
  1058. // Adapted from donated nonius code.
  1059. #ifndef CATCH_OPTIMIZER_HPP_INCLUDED
  1060. #define CATCH_OPTIMIZER_HPP_INCLUDED
  1061. #if defined(_MSC_VER) || defined(__IAR_SYSTEMS_ICC__)
  1062. # include <atomic> // atomic_thread_fence
  1063. #endif
  1064. #include <type_traits>
  1065. namespace Catch {
  1066. namespace Benchmark {
  1067. #if defined(__GNUC__) || defined(__clang__)
  1068. template <typename T>
  1069. inline void keep_memory(T* p) {
  1070. asm volatile("" : : "g"(p) : "memory");
  1071. }
  1072. inline void keep_memory() {
  1073. asm volatile("" : : : "memory");
  1074. }
  1075. namespace Detail {
  1076. inline void optimizer_barrier() { keep_memory(); }
  1077. } // namespace Detail
  1078. #elif defined(_MSC_VER) || defined(__IAR_SYSTEMS_ICC__)
  1079. #if defined(_MSVC_VER)
  1080. #pragma optimize("", off)
  1081. #elif defined(__IAR_SYSTEMS_ICC__)
  1082. // For IAR the pragma only affects the following function
  1083. #pragma optimize=disable
  1084. #endif
  1085. template <typename T>
  1086. inline void keep_memory(T* p) {
  1087. // thanks @milleniumbug
  1088. *reinterpret_cast<char volatile*>(p) = *reinterpret_cast<char const volatile*>(p);
  1089. }
  1090. // TODO equivalent keep_memory()
  1091. #if defined(_MSVC_VER)
  1092. #pragma optimize("", on)
  1093. #endif
  1094. namespace Detail {
  1095. inline void optimizer_barrier() {
  1096. std::atomic_thread_fence(std::memory_order_seq_cst);
  1097. }
  1098. } // namespace Detail
  1099. #endif
  1100. template <typename T>
  1101. inline void deoptimize_value(T&& x) {
  1102. keep_memory(&x);
  1103. }
  1104. template <typename Fn, typename... Args>
  1105. inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> {
  1106. deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...));
  1107. }
  1108. template <typename Fn, typename... Args>
  1109. inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> {
  1110. CATCH_FORWARD((fn)) (CATCH_FORWARD(args)...);
  1111. }
  1112. } // namespace Benchmark
  1113. } // namespace Catch
  1114. #endif // CATCH_OPTIMIZER_HPP_INCLUDED
  1115. #ifndef CATCH_META_HPP_INCLUDED
  1116. #define CATCH_META_HPP_INCLUDED
  1117. #include <type_traits>
  1118. namespace Catch {
  1119. template <typename>
  1120. struct true_given : std::true_type {};
  1121. struct is_callable_tester {
  1122. template <typename Fun, typename... Args>
  1123. static true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int);
  1124. template <typename...>
  1125. static std::false_type test(...);
  1126. };
  1127. template <typename T>
  1128. struct is_callable;
  1129. template <typename Fun, typename... Args>
  1130. struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
  1131. #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
  1132. // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
  1133. // replaced with std::invoke_result here.
  1134. template <typename Func, typename... U>
  1135. using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
  1136. #else
  1137. template <typename Func, typename... U>
  1138. using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U...)>>>;
  1139. #endif
  1140. } // namespace Catch
  1141. namespace mpl_{
  1142. struct na;
  1143. }
  1144. #endif // CATCH_META_HPP_INCLUDED
  1145. namespace Catch {
  1146. namespace Benchmark {
  1147. namespace Detail {
  1148. struct ChronometerConcept {
  1149. virtual void start() = 0;
  1150. virtual void finish() = 0;
  1151. virtual ~ChronometerConcept(); // = default;
  1152. ChronometerConcept() = default;
  1153. ChronometerConcept(ChronometerConcept const&) = default;
  1154. ChronometerConcept& operator=(ChronometerConcept const&) = default;
  1155. };
  1156. template <typename Clock>
  1157. struct ChronometerModel final : public ChronometerConcept {
  1158. void start() override { started = Clock::now(); }
  1159. void finish() override { finished = Clock::now(); }
  1160. IDuration elapsed() const {
  1161. return std::chrono::duration_cast<std::chrono::nanoseconds>(
  1162. finished - started );
  1163. }
  1164. TimePoint<Clock> started;
  1165. TimePoint<Clock> finished;
  1166. };
  1167. } // namespace Detail
  1168. struct Chronometer {
  1169. public:
  1170. template <typename Fun>
  1171. void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); }
  1172. int runs() const { return repeats; }
  1173. Chronometer(Detail::ChronometerConcept& meter, int repeats_)
  1174. : impl(&meter)
  1175. , repeats(repeats_) {}
  1176. private:
  1177. template <typename Fun>
  1178. void measure(Fun&& fun, std::false_type) {
  1179. measure([&fun](int) { return fun(); }, std::true_type());
  1180. }
  1181. template <typename Fun>
  1182. void measure(Fun&& fun, std::true_type) {
  1183. Detail::optimizer_barrier();
  1184. impl->start();
  1185. for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i);
  1186. impl->finish();
  1187. Detail::optimizer_barrier();
  1188. }
  1189. Detail::ChronometerConcept* impl;
  1190. int repeats;
  1191. };
  1192. } // namespace Benchmark
  1193. } // namespace Catch
  1194. #endif // CATCH_CHRONOMETER_HPP_INCLUDED
  1195. #include <type_traits>
  1196. namespace Catch {
  1197. namespace Benchmark {
  1198. namespace Detail {
  1199. template <typename T, typename U>
  1200. struct is_related
  1201. : std::is_same<std::decay_t<T>, std::decay_t<U>> {};
  1202. /// We need to reinvent std::function because every piece of code that might add overhead
  1203. /// in a measurement context needs to have consistent performance characteristics so that we
  1204. /// can account for it in the measurement.
  1205. /// Implementations of std::function with optimizations that aren't always applicable, like
  1206. /// small buffer optimizations, are not uncommon.
  1207. /// This is effectively an implementation of std::function without any such optimizations;
  1208. /// it may be slow, but it is consistently slow.
  1209. struct BenchmarkFunction {
  1210. private:
  1211. struct callable {
  1212. virtual void call(Chronometer meter) const = 0;
  1213. virtual Catch::Detail::unique_ptr<callable> clone() const = 0;
  1214. virtual ~callable(); // = default;
  1215. callable() = default;
  1216. callable(callable const&) = default;
  1217. callable& operator=(callable const&) = default;
  1218. };
  1219. template <typename Fun>
  1220. struct model : public callable {
  1221. model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {}
  1222. model(Fun const& fun_) : fun(fun_) {}
  1223. Catch::Detail::unique_ptr<callable> clone() const override {
  1224. return Catch::Detail::make_unique<model<Fun>>( *this );
  1225. }
  1226. void call(Chronometer meter) const override {
  1227. call(meter, is_callable<Fun(Chronometer)>());
  1228. }
  1229. void call(Chronometer meter, std::true_type) const {
  1230. fun(meter);
  1231. }
  1232. void call(Chronometer meter, std::false_type) const {
  1233. meter.measure(fun);
  1234. }
  1235. Fun fun;
  1236. };
  1237. struct do_nothing { void operator()() const {} };
  1238. template <typename T>
  1239. BenchmarkFunction(model<T>* c) : f(c) {}
  1240. public:
  1241. BenchmarkFunction()
  1242. : f(new model<do_nothing>{ {} }) {}
  1243. template <typename Fun,
  1244. std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0>
  1245. BenchmarkFunction(Fun&& fun)
  1246. : f(new model<std::decay_t<Fun>>(CATCH_FORWARD(fun))) {}
  1247. BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
  1248. f( CATCH_MOVE( that.f ) ) {}
  1249. BenchmarkFunction(BenchmarkFunction const& that)
  1250. : f(that.f->clone()) {}
  1251. BenchmarkFunction&
  1252. operator=( BenchmarkFunction&& that ) noexcept {
  1253. f = CATCH_MOVE( that.f );
  1254. return *this;
  1255. }
  1256. BenchmarkFunction& operator=(BenchmarkFunction const& that) {
  1257. f = that.f->clone();
  1258. return *this;
  1259. }
  1260. void operator()(Chronometer meter) const { f->call(meter); }
  1261. private:
  1262. Catch::Detail::unique_ptr<callable> f;
  1263. };
  1264. } // namespace Detail
  1265. } // namespace Benchmark
  1266. } // namespace Catch
  1267. #endif // CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1268. // Adapted from donated nonius code.
  1269. #ifndef CATCH_REPEAT_HPP_INCLUDED
  1270. #define CATCH_REPEAT_HPP_INCLUDED
  1271. #include <type_traits>
  1272. namespace Catch {
  1273. namespace Benchmark {
  1274. namespace Detail {
  1275. template <typename Fun>
  1276. struct repeater {
  1277. void operator()(int k) const {
  1278. for (int i = 0; i < k; ++i) {
  1279. fun();
  1280. }
  1281. }
  1282. Fun fun;
  1283. };
  1284. template <typename Fun>
  1285. repeater<std::decay_t<Fun>> repeat(Fun&& fun) {
  1286. return { CATCH_FORWARD(fun) };
  1287. }
  1288. } // namespace Detail
  1289. } // namespace Benchmark
  1290. } // namespace Catch
  1291. #endif // CATCH_REPEAT_HPP_INCLUDED
  1292. // Adapted from donated nonius code.
  1293. #ifndef CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1294. #define CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1295. // Adapted from donated nonius code.
  1296. #ifndef CATCH_MEASURE_HPP_INCLUDED
  1297. #define CATCH_MEASURE_HPP_INCLUDED
  1298. // Adapted from donated nonius code.
  1299. #ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1300. #define CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1301. namespace Catch {
  1302. namespace Benchmark {
  1303. namespace Detail {
  1304. template <typename T>
  1305. struct CompleteType { using type = T; };
  1306. template <>
  1307. struct CompleteType<void> { struct type {}; };
  1308. template <typename T>
  1309. using CompleteType_t = typename CompleteType<T>::type;
  1310. template <typename Result>
  1311. struct CompleteInvoker {
  1312. template <typename Fun, typename... Args>
  1313. static Result invoke(Fun&& fun, Args&&... args) {
  1314. return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
  1315. }
  1316. };
  1317. template <>
  1318. struct CompleteInvoker<void> {
  1319. template <typename Fun, typename... Args>
  1320. static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
  1321. CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
  1322. return {};
  1323. }
  1324. };
  1325. // invoke and not return void :(
  1326. template <typename Fun, typename... Args>
  1327. CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
  1328. return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...);
  1329. }
  1330. } // namespace Detail
  1331. template <typename Fun>
  1332. Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
  1333. return Detail::complete_invoke(CATCH_FORWARD(fun));
  1334. }
  1335. } // namespace Benchmark
  1336. } // namespace Catch
  1337. #endif // CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1338. // Adapted from donated nonius code.
  1339. #ifndef CATCH_TIMING_HPP_INCLUDED
  1340. #define CATCH_TIMING_HPP_INCLUDED
  1341. #include <type_traits>
  1342. namespace Catch {
  1343. namespace Benchmark {
  1344. template <typename Result>
  1345. struct Timing {
  1346. IDuration elapsed;
  1347. Result result;
  1348. int iterations;
  1349. };
  1350. template <typename Func, typename... Args>
  1351. using TimingOf = Timing<Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>;
  1352. } // namespace Benchmark
  1353. } // namespace Catch
  1354. #endif // CATCH_TIMING_HPP_INCLUDED
  1355. namespace Catch {
  1356. namespace Benchmark {
  1357. namespace Detail {
  1358. template <typename Clock, typename Fun, typename... Args>
  1359. TimingOf<Fun, Args...> measure(Fun&& fun, Args&&... args) {
  1360. auto start = Clock::now();
  1361. auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...);
  1362. auto end = Clock::now();
  1363. auto delta = end - start;
  1364. return { delta, CATCH_FORWARD(r), 1 };
  1365. }
  1366. } // namespace Detail
  1367. } // namespace Benchmark
  1368. } // namespace Catch
  1369. #endif // CATCH_MEASURE_HPP_INCLUDED
  1370. #include <type_traits>
  1371. namespace Catch {
  1372. namespace Benchmark {
  1373. namespace Detail {
  1374. template <typename Clock, typename Fun>
  1375. TimingOf<Fun, int> measure_one(Fun&& fun, int iters, std::false_type) {
  1376. return Detail::measure<Clock>(fun, iters);
  1377. }
  1378. template <typename Clock, typename Fun>
  1379. TimingOf<Fun, Chronometer> measure_one(Fun&& fun, int iters, std::true_type) {
  1380. Detail::ChronometerModel<Clock> meter;
  1381. auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
  1382. return { meter.elapsed(), CATCH_MOVE(result), iters };
  1383. }
  1384. template <typename Clock, typename Fun>
  1385. using run_for_at_least_argument_t = std::conditional_t<is_callable<Fun(Chronometer)>::value, Chronometer, int>;
  1386. [[noreturn]]
  1387. void throw_optimized_away_error();
  1388. template <typename Clock, typename Fun>
  1389. TimingOf<Fun, run_for_at_least_argument_t<Clock, Fun>>
  1390. run_for_at_least(IDuration how_long,
  1391. const int initial_iterations,
  1392. Fun&& fun) {
  1393. auto iters = initial_iterations;
  1394. while (iters < (1 << 30)) {
  1395. auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
  1396. if (Timing.elapsed >= how_long) {
  1397. return { Timing.elapsed, CATCH_MOVE(Timing.result), iters };
  1398. }
  1399. iters *= 2;
  1400. }
  1401. throw_optimized_away_error();
  1402. }
  1403. } // namespace Detail
  1404. } // namespace Benchmark
  1405. } // namespace Catch
  1406. #endif // CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1407. #include <vector>
  1408. namespace Catch {
  1409. namespace Benchmark {
  1410. struct ExecutionPlan {
  1411. int iterations_per_sample;
  1412. FDuration estimated_duration;
  1413. Detail::BenchmarkFunction benchmark;
  1414. FDuration warmup_time;
  1415. int warmup_iterations;
  1416. template <typename Clock>
  1417. std::vector<FDuration> run(const IConfig &cfg, Environment env) const {
  1418. // warmup a bit
  1419. Detail::run_for_at_least<Clock>(
  1420. std::chrono::duration_cast<IDuration>( warmup_time ),
  1421. warmup_iterations,
  1422. Detail::repeat( []() { return Clock::now(); } )
  1423. );
  1424. std::vector<FDuration> times;
  1425. const auto num_samples = cfg.benchmarkSamples();
  1426. times.reserve( num_samples );
  1427. for ( size_t i = 0; i < num_samples; ++i ) {
  1428. Detail::ChronometerModel<Clock> model;
  1429. this->benchmark( Chronometer( model, iterations_per_sample ) );
  1430. auto sample_time = model.elapsed() - env.clock_cost.mean;
  1431. if ( sample_time < FDuration::zero() ) {
  1432. sample_time = FDuration::zero();
  1433. }
  1434. times.push_back(sample_time / iterations_per_sample);
  1435. }
  1436. return times;
  1437. }
  1438. };
  1439. } // namespace Benchmark
  1440. } // namespace Catch
  1441. #endif // CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1442. // Adapted from donated nonius code.
  1443. #ifndef CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1444. #define CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1445. // Adapted from donated nonius code.
  1446. #ifndef CATCH_STATS_HPP_INCLUDED
  1447. #define CATCH_STATS_HPP_INCLUDED
  1448. #include <vector>
  1449. namespace Catch {
  1450. namespace Benchmark {
  1451. namespace Detail {
  1452. using sample = std::vector<double>;
  1453. double weighted_average_quantile( int k,
  1454. int q,
  1455. double* first,
  1456. double* last );
  1457. OutlierClassification
  1458. classify_outliers( double const* first, double const* last );
  1459. double mean( double const* first, double const* last );
  1460. double normal_cdf( double x );
  1461. double erfc_inv(double x);
  1462. double normal_quantile(double p);
  1463. Estimate<double>
  1464. bootstrap( double confidence_level,
  1465. double* first,
  1466. double* last,
  1467. sample const& resample,
  1468. double ( *estimator )( double const*, double const* ) );
  1469. struct bootstrap_analysis {
  1470. Estimate<double> mean;
  1471. Estimate<double> standard_deviation;
  1472. double outlier_variance;
  1473. };
  1474. bootstrap_analysis analyse_samples(double confidence_level,
  1475. unsigned int n_resamples,
  1476. double* first,
  1477. double* last);
  1478. } // namespace Detail
  1479. } // namespace Benchmark
  1480. } // namespace Catch
  1481. #endif // CATCH_STATS_HPP_INCLUDED
  1482. #include <algorithm>
  1483. #include <vector>
  1484. #include <cmath>
  1485. namespace Catch {
  1486. namespace Benchmark {
  1487. namespace Detail {
  1488. template <typename Clock>
  1489. std::vector<double> resolution(int k) {
  1490. std::vector<TimePoint<Clock>> times;
  1491. times.reserve(static_cast<size_t>(k + 1));
  1492. for ( int i = 0; i < k + 1; ++i ) {
  1493. times.push_back( Clock::now() );
  1494. }
  1495. std::vector<double> deltas;
  1496. deltas.reserve(static_cast<size_t>(k));
  1497. for ( size_t idx = 1; idx < times.size(); ++idx ) {
  1498. deltas.push_back( static_cast<double>(
  1499. ( times[idx] - times[idx - 1] ).count() ) );
  1500. }
  1501. return deltas;
  1502. }
  1503. constexpr auto warmup_iterations = 10000;
  1504. constexpr auto warmup_time = std::chrono::milliseconds(100);
  1505. constexpr auto minimum_ticks = 1000;
  1506. constexpr auto warmup_seed = 10000;
  1507. constexpr auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
  1508. constexpr auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
  1509. constexpr auto clock_cost_estimation_tick_limit = 100000;
  1510. constexpr auto clock_cost_estimation_time = std::chrono::milliseconds(10);
  1511. constexpr auto clock_cost_estimation_iterations = 10000;
  1512. template <typename Clock>
  1513. int warmup() {
  1514. return run_for_at_least<Clock>(warmup_time, warmup_seed, &resolution<Clock>)
  1515. .iterations;
  1516. }
  1517. template <typename Clock>
  1518. EnvironmentEstimate estimate_clock_resolution(int iterations) {
  1519. auto r = run_for_at_least<Clock>(clock_resolution_estimation_time, iterations, &resolution<Clock>)
  1520. .result;
  1521. return {
  1522. FDuration(mean(r.data(), r.data() + r.size())),
  1523. classify_outliers(r.data(), r.data() + r.size()),
  1524. };
  1525. }
  1526. template <typename Clock>
  1527. EnvironmentEstimate estimate_clock_cost(FDuration resolution) {
  1528. auto time_limit = (std::min)(
  1529. resolution * clock_cost_estimation_tick_limit,
  1530. FDuration(clock_cost_estimation_time_limit));
  1531. auto time_clock = [](int k) {
  1532. return Detail::measure<Clock>([k] {
  1533. for (int i = 0; i < k; ++i) {
  1534. volatile auto ignored = Clock::now();
  1535. (void)ignored;
  1536. }
  1537. }).elapsed;
  1538. };
  1539. time_clock(1);
  1540. int iters = clock_cost_estimation_iterations;
  1541. auto&& r = run_for_at_least<Clock>(clock_cost_estimation_time, iters, time_clock);
  1542. std::vector<double> times;
  1543. int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
  1544. times.reserve(static_cast<size_t>(nsamples));
  1545. for ( int s = 0; s < nsamples; ++s ) {
  1546. times.push_back( static_cast<double>(
  1547. ( time_clock( r.iterations ) / r.iterations )
  1548. .count() ) );
  1549. }
  1550. return {
  1551. FDuration(mean(times.data(), times.data() + times.size())),
  1552. classify_outliers(times.data(), times.data() + times.size()),
  1553. };
  1554. }
  1555. template <typename Clock>
  1556. Environment measure_environment() {
  1557. #if defined(__clang__)
  1558. # pragma clang diagnostic push
  1559. # pragma clang diagnostic ignored "-Wexit-time-destructors"
  1560. #endif
  1561. static Catch::Detail::unique_ptr<Environment> env;
  1562. #if defined(__clang__)
  1563. # pragma clang diagnostic pop
  1564. #endif
  1565. if (env) {
  1566. return *env;
  1567. }
  1568. auto iters = Detail::warmup<Clock>();
  1569. auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
  1570. auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
  1571. env = Catch::Detail::make_unique<Environment>( Environment{resolution, cost} );
  1572. return *env;
  1573. }
  1574. } // namespace Detail
  1575. } // namespace Benchmark
  1576. } // namespace Catch
  1577. #endif // CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1578. // Adapted from donated nonius code.
  1579. #ifndef CATCH_ANALYSE_HPP_INCLUDED
  1580. #define CATCH_ANALYSE_HPP_INCLUDED
  1581. // Adapted from donated nonius code.
  1582. #ifndef CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1583. #define CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1584. #include <vector>
  1585. namespace Catch {
  1586. namespace Benchmark {
  1587. struct SampleAnalysis {
  1588. std::vector<FDuration> samples;
  1589. Estimate<FDuration> mean;
  1590. Estimate<FDuration> standard_deviation;
  1591. OutlierClassification outliers;
  1592. double outlier_variance;
  1593. };
  1594. } // namespace Benchmark
  1595. } // namespace Catch
  1596. #endif // CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1597. namespace Catch {
  1598. class IConfig;
  1599. namespace Benchmark {
  1600. namespace Detail {
  1601. SampleAnalysis analyse(const IConfig &cfg, FDuration* first, FDuration* last);
  1602. } // namespace Detail
  1603. } // namespace Benchmark
  1604. } // namespace Catch
  1605. #endif // CATCH_ANALYSE_HPP_INCLUDED
  1606. #include <algorithm>
  1607. #include <chrono>
  1608. #include <exception>
  1609. #include <string>
  1610. #include <cmath>
  1611. namespace Catch {
  1612. namespace Benchmark {
  1613. struct Benchmark {
  1614. Benchmark(std::string&& benchmarkName)
  1615. : name(CATCH_MOVE(benchmarkName)) {}
  1616. template <class FUN>
  1617. Benchmark(std::string&& benchmarkName , FUN &&func)
  1618. : fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {}
  1619. template <typename Clock>
  1620. ExecutionPlan prepare(const IConfig &cfg, Environment env) const {
  1621. auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
  1622. auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
  1623. auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<IDuration>(run_time), 1, fun);
  1624. int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
  1625. return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FDuration>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
  1626. }
  1627. template <typename Clock = default_clock>
  1628. void run() {
  1629. static_assert( Clock::is_steady,
  1630. "Benchmarking clock should be steady" );
  1631. auto const* cfg = getCurrentContext().getConfig();
  1632. auto env = Detail::measure_environment<Clock>();
  1633. getResultCapture().benchmarkPreparing(name);
  1634. CATCH_TRY{
  1635. auto plan = user_code([&] {
  1636. return prepare<Clock>(*cfg, env);
  1637. });
  1638. BenchmarkInfo info {
  1639. CATCH_MOVE(name),
  1640. plan.estimated_duration.count(),
  1641. plan.iterations_per_sample,
  1642. cfg->benchmarkSamples(),
  1643. cfg->benchmarkResamples(),
  1644. env.clock_resolution.mean.count(),
  1645. env.clock_cost.mean.count()
  1646. };
  1647. getResultCapture().benchmarkStarting(info);
  1648. auto samples = user_code([&] {
  1649. return plan.template run<Clock>(*cfg, env);
  1650. });
  1651. auto analysis = Detail::analyse(*cfg, samples.data(), samples.data() + samples.size());
  1652. BenchmarkStats<> stats{ CATCH_MOVE(info), CATCH_MOVE(analysis.samples), analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
  1653. getResultCapture().benchmarkEnded(stats);
  1654. } CATCH_CATCH_ANON (TestFailureException const&) {
  1655. getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
  1656. } CATCH_CATCH_ALL{
  1657. getResultCapture().benchmarkFailed(translateActiveException());
  1658. // We let the exception go further up so that the
  1659. // test case is marked as failed.
  1660. std::rethrow_exception(std::current_exception());
  1661. }
  1662. }
  1663. // sets lambda to be used in fun *and* executes benchmark!
  1664. template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0>
  1665. Benchmark & operator=(Fun func) {
  1666. auto const* cfg = getCurrentContext().getConfig();
  1667. if (!cfg->skipBenchmarks()) {
  1668. fun = Detail::BenchmarkFunction(func);
  1669. run();
  1670. }
  1671. return *this;
  1672. }
  1673. explicit operator bool() {
  1674. return true;
  1675. }
  1676. private:
  1677. Detail::BenchmarkFunction fun;
  1678. std::string name;
  1679. };
  1680. }
  1681. } // namespace Catch
  1682. #define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1
  1683. #define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2
  1684. #define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\
  1685. if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
  1686. BenchmarkName = [&](int benchmarkIndex)
  1687. #define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\
  1688. if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
  1689. BenchmarkName = [&]
  1690. #if defined(CATCH_CONFIG_PREFIX_ALL)
  1691. #define CATCH_BENCHMARK(...) \
  1692. INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
  1693. #define CATCH_BENCHMARK_ADVANCED(name) \
  1694. INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
  1695. #else
  1696. #define BENCHMARK(...) \
  1697. INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
  1698. #define BENCHMARK_ADVANCED(name) \
  1699. INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
  1700. #endif
  1701. #endif // CATCH_BENCHMARK_HPP_INCLUDED
  1702. // Adapted from donated nonius code.
  1703. #ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED
  1704. #define CATCH_CONSTRUCTOR_HPP_INCLUDED
  1705. #include <type_traits>
  1706. namespace Catch {
  1707. namespace Benchmark {
  1708. namespace Detail {
  1709. template <typename T, bool Destruct>
  1710. struct ObjectStorage
  1711. {
  1712. ObjectStorage() = default;
  1713. ObjectStorage(const ObjectStorage& other)
  1714. {
  1715. new(&data) T(other.stored_object());
  1716. }
  1717. ObjectStorage(ObjectStorage&& other)
  1718. {
  1719. new(data) T(CATCH_MOVE(other.stored_object()));
  1720. }
  1721. ~ObjectStorage() { destruct_on_exit<T>(); }
  1722. template <typename... Args>
  1723. void construct(Args&&... args)
  1724. {
  1725. new (data) T(CATCH_FORWARD(args)...);
  1726. }
  1727. template <bool AllowManualDestruction = !Destruct>
  1728. std::enable_if_t<AllowManualDestruction> destruct()
  1729. {
  1730. stored_object().~T();
  1731. }
  1732. private:
  1733. // If this is a constructor benchmark, destruct the underlying object
  1734. template <typename U>
  1735. void destruct_on_exit(std::enable_if_t<Destruct, U>* = nullptr) { destruct<true>(); }
  1736. // Otherwise, don't
  1737. template <typename U>
  1738. void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { }
  1739. #if defined( __GNUC__ ) && __GNUC__ <= 6
  1740. # pragma GCC diagnostic push
  1741. # pragma GCC diagnostic ignored "-Wstrict-aliasing"
  1742. #endif
  1743. T& stored_object() { return *reinterpret_cast<T*>( data ); }
  1744. T const& stored_object() const {
  1745. return *reinterpret_cast<T const*>( data );
  1746. }
  1747. #if defined( __GNUC__ ) && __GNUC__ <= 6
  1748. # pragma GCC diagnostic pop
  1749. #endif
  1750. alignas( T ) unsigned char data[sizeof( T )]{};
  1751. };
  1752. } // namespace Detail
  1753. template <typename T>
  1754. using storage_for = Detail::ObjectStorage<T, true>;
  1755. template <typename T>
  1756. using destructable_object = Detail::ObjectStorage<T, false>;
  1757. } // namespace Benchmark
  1758. } // namespace Catch
  1759. #endif // CATCH_CONSTRUCTOR_HPP_INCLUDED
  1760. #endif // CATCH_BENCHMARK_ALL_HPP_INCLUDED
  1761. #ifndef CATCH_APPROX_HPP_INCLUDED
  1762. #define CATCH_APPROX_HPP_INCLUDED
  1763. #ifndef CATCH_TOSTRING_HPP_INCLUDED
  1764. #define CATCH_TOSTRING_HPP_INCLUDED
  1765. #include <vector>
  1766. #include <cstddef>
  1767. #include <type_traits>
  1768. #include <string>
  1769. /** \file
  1770. * Wrapper for the WCHAR configuration option
  1771. *
  1772. * We want to support platforms that do not provide `wchar_t`, so we
  1773. * sometimes have to disable providing wchar_t overloads through Catch2,
  1774. * e.g. the StringMaker specialization for `std::wstring`.
  1775. */
  1776. #ifndef CATCH_CONFIG_WCHAR_HPP_INCLUDED
  1777. #define CATCH_CONFIG_WCHAR_HPP_INCLUDED
  1778. // We assume that WCHAR should be enabled by default, and only disabled
  1779. // for a shortlist (so far only DJGPP) of compilers.
  1780. #if defined(__DJGPP__)
  1781. # define CATCH_INTERNAL_CONFIG_NO_WCHAR
  1782. #endif // __DJGPP__
  1783. #if !defined( CATCH_INTERNAL_CONFIG_NO_WCHAR ) && \
  1784. !defined( CATCH_CONFIG_NO_WCHAR ) && \
  1785. !defined( CATCH_CONFIG_WCHAR )
  1786. # define CATCH_CONFIG_WCHAR
  1787. #endif
  1788. #endif // CATCH_CONFIG_WCHAR_HPP_INCLUDED
  1789. #ifndef CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  1790. #define CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  1791. #include <iosfwd>
  1792. #include <cstddef>
  1793. #include <ostream>
  1794. #include <string>
  1795. namespace Catch {
  1796. class ReusableStringStream : Detail::NonCopyable {
  1797. std::size_t m_index;
  1798. std::ostream* m_oss;
  1799. public:
  1800. ReusableStringStream();
  1801. ~ReusableStringStream();
  1802. //! Returns the serialized state
  1803. std::string str() const;
  1804. //! Sets internal state to `str`
  1805. void str(std::string const& str);
  1806. #if defined(__GNUC__) && !defined(__clang__)
  1807. #pragma GCC diagnostic push
  1808. // Old versions of GCC do not understand -Wnonnull-compare
  1809. #pragma GCC diagnostic ignored "-Wpragmas"
  1810. // Streaming a function pointer triggers Waddress and Wnonnull-compare
  1811. // on GCC, because it implicitly converts it to bool and then decides
  1812. // that the check it uses (a? true : false) is tautological and cannot
  1813. // be null...
  1814. #pragma GCC diagnostic ignored "-Waddress"
  1815. #pragma GCC diagnostic ignored "-Wnonnull-compare"
  1816. #endif
  1817. template<typename T>
  1818. auto operator << ( T const& value ) -> ReusableStringStream& {
  1819. *m_oss << value;
  1820. return *this;
  1821. }
  1822. #if defined(__GNUC__) && !defined(__clang__)
  1823. #pragma GCC diagnostic pop
  1824. #endif
  1825. auto get() -> std::ostream& { return *m_oss; }
  1826. };
  1827. }
  1828. #endif // CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  1829. #ifndef CATCH_VOID_TYPE_HPP_INCLUDED
  1830. #define CATCH_VOID_TYPE_HPP_INCLUDED
  1831. namespace Catch {
  1832. namespace Detail {
  1833. template <typename...>
  1834. struct make_void { using type = void; };
  1835. template <typename... Ts>
  1836. using void_t = typename make_void<Ts...>::type;
  1837. } // namespace Detail
  1838. } // namespace Catch
  1839. #endif // CATCH_VOID_TYPE_HPP_INCLUDED
  1840. #ifndef CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  1841. #define CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  1842. #include <vector>
  1843. namespace Catch {
  1844. namespace Detail {
  1845. struct EnumInfo {
  1846. StringRef m_name;
  1847. std::vector<std::pair<int, StringRef>> m_values;
  1848. ~EnumInfo();
  1849. StringRef lookup( int value ) const;
  1850. };
  1851. } // namespace Detail
  1852. class IMutableEnumValuesRegistry {
  1853. public:
  1854. virtual ~IMutableEnumValuesRegistry(); // = default;
  1855. virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
  1856. template<typename E>
  1857. Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
  1858. static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
  1859. std::vector<int> intValues;
  1860. intValues.reserve( values.size() );
  1861. for( auto enumValue : values )
  1862. intValues.push_back( static_cast<int>( enumValue ) );
  1863. return registerEnum( enumName, allEnums, intValues );
  1864. }
  1865. };
  1866. } // Catch
  1867. #endif // CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  1868. #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  1869. #include <string_view>
  1870. #endif
  1871. #ifdef _MSC_VER
  1872. #pragma warning(push)
  1873. #pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
  1874. #endif
  1875. // We need a dummy global operator<< so we can bring it into Catch namespace later
  1876. struct Catch_global_namespace_dummy{};
  1877. std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
  1878. namespace Catch {
  1879. // Bring in global namespace operator<< for ADL lookup in
  1880. // `IsStreamInsertable` below.
  1881. using ::operator<<;
  1882. namespace Detail {
  1883. inline std::size_t catch_strnlen(const char *str, std::size_t n) {
  1884. auto ret = std::char_traits<char>::find(str, n, '\0');
  1885. if (ret != nullptr) {
  1886. return static_cast<std::size_t>(ret - str);
  1887. }
  1888. return n;
  1889. }
  1890. constexpr StringRef unprintableString = "{?}"_sr;
  1891. //! Encases `string in quotes, and optionally escapes invisibles
  1892. std::string convertIntoString( StringRef string, bool escapeInvisibles );
  1893. //! Encases `string` in quotes, and escapes invisibles if user requested
  1894. //! it via CLI
  1895. std::string convertIntoString( StringRef string );
  1896. std::string rawMemoryToString( const void *object, std::size_t size );
  1897. template<typename T>
  1898. std::string rawMemoryToString( const T& object ) {
  1899. return rawMemoryToString( &object, sizeof(object) );
  1900. }
  1901. template<typename T>
  1902. class IsStreamInsertable {
  1903. template<typename Stream, typename U>
  1904. static auto test(int)
  1905. -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
  1906. template<typename, typename>
  1907. static auto test(...)->std::false_type;
  1908. public:
  1909. static const bool value = decltype(test<std::ostream, const T&>(0))::value;
  1910. };
  1911. template<typename E>
  1912. std::string convertUnknownEnumToString( E e );
  1913. template<typename T>
  1914. std::enable_if_t<
  1915. !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
  1916. std::string> convertUnstreamable( T const& ) {
  1917. return std::string(Detail::unprintableString);
  1918. }
  1919. template<typename T>
  1920. std::enable_if_t<
  1921. !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value,
  1922. std::string> convertUnstreamable(T const& ex) {
  1923. return ex.what();
  1924. }
  1925. template<typename T>
  1926. std::enable_if_t<
  1927. std::is_enum<T>::value,
  1928. std::string> convertUnstreamable( T const& value ) {
  1929. return convertUnknownEnumToString( value );
  1930. }
  1931. #if defined(_MANAGED)
  1932. //! Convert a CLR string to a utf8 std::string
  1933. template<typename T>
  1934. std::string clrReferenceToString( T^ ref ) {
  1935. if (ref == nullptr)
  1936. return std::string("null");
  1937. auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
  1938. cli::pin_ptr<System::Byte> p = &bytes[0];
  1939. return std::string(reinterpret_cast<char const *>(p), bytes->Length);
  1940. }
  1941. #endif
  1942. } // namespace Detail
  1943. template <typename T, typename = void>
  1944. struct StringMaker {
  1945. template <typename Fake = T>
  1946. static
  1947. std::enable_if_t<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>
  1948. convert(const Fake& value) {
  1949. ReusableStringStream rss;
  1950. // NB: call using the function-like syntax to avoid ambiguity with
  1951. // user-defined templated operator<< under clang.
  1952. rss.operator<<(value);
  1953. return rss.str();
  1954. }
  1955. template <typename Fake = T>
  1956. static
  1957. std::enable_if_t<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>
  1958. convert( const Fake& value ) {
  1959. #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
  1960. return Detail::convertUnstreamable(value);
  1961. #else
  1962. return CATCH_CONFIG_FALLBACK_STRINGIFIER(value);
  1963. #endif
  1964. }
  1965. };
  1966. namespace Detail {
  1967. // This function dispatches all stringification requests inside of Catch.
  1968. // Should be preferably called fully qualified, like ::Catch::Detail::stringify
  1969. template <typename T>
  1970. std::string stringify(const T& e) {
  1971. return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e);
  1972. }
  1973. template<typename E>
  1974. std::string convertUnknownEnumToString( E e ) {
  1975. return ::Catch::Detail::stringify(static_cast<std::underlying_type_t<E>>(e));
  1976. }
  1977. #if defined(_MANAGED)
  1978. template <typename T>
  1979. std::string stringify( T^ e ) {
  1980. return ::Catch::StringMaker<T^>::convert(e);
  1981. }
  1982. #endif
  1983. } // namespace Detail
  1984. // Some predefined specializations
  1985. template<>
  1986. struct StringMaker<std::string> {
  1987. static std::string convert(const std::string& str);
  1988. };
  1989. #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  1990. template<>
  1991. struct StringMaker<std::string_view> {
  1992. static std::string convert(std::string_view str);
  1993. };
  1994. #endif
  1995. template<>
  1996. struct StringMaker<char const *> {
  1997. static std::string convert(char const * str);
  1998. };
  1999. template<>
  2000. struct StringMaker<char *> {
  2001. static std::string convert(char * str);
  2002. };
  2003. #if defined(CATCH_CONFIG_WCHAR)
  2004. template<>
  2005. struct StringMaker<std::wstring> {
  2006. static std::string convert(const std::wstring& wstr);
  2007. };
  2008. # ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  2009. template<>
  2010. struct StringMaker<std::wstring_view> {
  2011. static std::string convert(std::wstring_view str);
  2012. };
  2013. # endif
  2014. template<>
  2015. struct StringMaker<wchar_t const *> {
  2016. static std::string convert(wchar_t const * str);
  2017. };
  2018. template<>
  2019. struct StringMaker<wchar_t *> {
  2020. static std::string convert(wchar_t * str);
  2021. };
  2022. #endif // CATCH_CONFIG_WCHAR
  2023. template<size_t SZ>
  2024. struct StringMaker<char[SZ]> {
  2025. static std::string convert(char const* str) {
  2026. return Detail::convertIntoString(
  2027. StringRef( str, Detail::catch_strnlen( str, SZ ) ) );
  2028. }
  2029. };
  2030. template<size_t SZ>
  2031. struct StringMaker<signed char[SZ]> {
  2032. static std::string convert(signed char const* str) {
  2033. auto reinterpreted = reinterpret_cast<char const*>(str);
  2034. return Detail::convertIntoString(
  2035. StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
  2036. }
  2037. };
  2038. template<size_t SZ>
  2039. struct StringMaker<unsigned char[SZ]> {
  2040. static std::string convert(unsigned char const* str) {
  2041. auto reinterpreted = reinterpret_cast<char const*>(str);
  2042. return Detail::convertIntoString(
  2043. StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
  2044. }
  2045. };
  2046. #if defined(CATCH_CONFIG_CPP17_BYTE)
  2047. template<>
  2048. struct StringMaker<std::byte> {
  2049. static std::string convert(std::byte value);
  2050. };
  2051. #endif // defined(CATCH_CONFIG_CPP17_BYTE)
  2052. template<>
  2053. struct StringMaker<int> {
  2054. static std::string convert(int value);
  2055. };
  2056. template<>
  2057. struct StringMaker<long> {
  2058. static std::string convert(long value);
  2059. };
  2060. template<>
  2061. struct StringMaker<long long> {
  2062. static std::string convert(long long value);
  2063. };
  2064. template<>
  2065. struct StringMaker<unsigned int> {
  2066. static std::string convert(unsigned int value);
  2067. };
  2068. template<>
  2069. struct StringMaker<unsigned long> {
  2070. static std::string convert(unsigned long value);
  2071. };
  2072. template<>
  2073. struct StringMaker<unsigned long long> {
  2074. static std::string convert(unsigned long long value);
  2075. };
  2076. template<>
  2077. struct StringMaker<bool> {
  2078. static std::string convert(bool b) {
  2079. using namespace std::string_literals;
  2080. return b ? "true"s : "false"s;
  2081. }
  2082. };
  2083. template<>
  2084. struct StringMaker<char> {
  2085. static std::string convert(char c);
  2086. };
  2087. template<>
  2088. struct StringMaker<signed char> {
  2089. static std::string convert(signed char value);
  2090. };
  2091. template<>
  2092. struct StringMaker<unsigned char> {
  2093. static std::string convert(unsigned char value);
  2094. };
  2095. template<>
  2096. struct StringMaker<std::nullptr_t> {
  2097. static std::string convert(std::nullptr_t) {
  2098. using namespace std::string_literals;
  2099. return "nullptr"s;
  2100. }
  2101. };
  2102. template<>
  2103. struct StringMaker<float> {
  2104. static std::string convert(float value);
  2105. CATCH_EXPORT static int precision;
  2106. };
  2107. template<>
  2108. struct StringMaker<double> {
  2109. static std::string convert(double value);
  2110. CATCH_EXPORT static int precision;
  2111. };
  2112. template <typename T>
  2113. struct StringMaker<T*> {
  2114. template <typename U>
  2115. static std::string convert(U* p) {
  2116. if (p) {
  2117. return ::Catch::Detail::rawMemoryToString(p);
  2118. } else {
  2119. return "nullptr";
  2120. }
  2121. }
  2122. };
  2123. template <typename R, typename C>
  2124. struct StringMaker<R C::*> {
  2125. static std::string convert(R C::* p) {
  2126. if (p) {
  2127. return ::Catch::Detail::rawMemoryToString(p);
  2128. } else {
  2129. return "nullptr";
  2130. }
  2131. }
  2132. };
  2133. #if defined(_MANAGED)
  2134. template <typename T>
  2135. struct StringMaker<T^> {
  2136. static std::string convert( T^ ref ) {
  2137. return ::Catch::Detail::clrReferenceToString(ref);
  2138. }
  2139. };
  2140. #endif
  2141. namespace Detail {
  2142. template<typename InputIterator, typename Sentinel = InputIterator>
  2143. std::string rangeToString(InputIterator first, Sentinel last) {
  2144. ReusableStringStream rss;
  2145. rss << "{ ";
  2146. if (first != last) {
  2147. rss << ::Catch::Detail::stringify(*first);
  2148. for (++first; first != last; ++first)
  2149. rss << ", " << ::Catch::Detail::stringify(*first);
  2150. }
  2151. rss << " }";
  2152. return rss.str();
  2153. }
  2154. }
  2155. } // namespace Catch
  2156. //////////////////////////////////////////////////////
  2157. // Separate std-lib types stringification, so it can be selectively enabled
  2158. // This means that we do not bring in their headers
  2159. #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
  2160. # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
  2161. # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  2162. # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
  2163. # define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
  2164. #endif
  2165. // Separate std::pair specialization
  2166. #if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
  2167. #include <utility>
  2168. namespace Catch {
  2169. template<typename T1, typename T2>
  2170. struct StringMaker<std::pair<T1, T2> > {
  2171. static std::string convert(const std::pair<T1, T2>& pair) {
  2172. ReusableStringStream rss;
  2173. rss << "{ "
  2174. << ::Catch::Detail::stringify(pair.first)
  2175. << ", "
  2176. << ::Catch::Detail::stringify(pair.second)
  2177. << " }";
  2178. return rss.str();
  2179. }
  2180. };
  2181. }
  2182. #endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
  2183. #if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL)
  2184. #include <optional>
  2185. namespace Catch {
  2186. template<typename T>
  2187. struct StringMaker<std::optional<T> > {
  2188. static std::string convert(const std::optional<T>& optional) {
  2189. if (optional.has_value()) {
  2190. return ::Catch::Detail::stringify(*optional);
  2191. } else {
  2192. return "{ }";
  2193. }
  2194. }
  2195. };
  2196. template <>
  2197. struct StringMaker<std::nullopt_t> {
  2198. static std::string convert(const std::nullopt_t&) {
  2199. return "{ }";
  2200. }
  2201. };
  2202. }
  2203. #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
  2204. // Separate std::tuple specialization
  2205. #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
  2206. #include <tuple>
  2207. namespace Catch {
  2208. namespace Detail {
  2209. template<
  2210. typename Tuple,
  2211. std::size_t N = 0,
  2212. bool = (N < std::tuple_size<Tuple>::value)
  2213. >
  2214. struct TupleElementPrinter {
  2215. static void print(const Tuple& tuple, std::ostream& os) {
  2216. os << (N ? ", " : " ")
  2217. << ::Catch::Detail::stringify(std::get<N>(tuple));
  2218. TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
  2219. }
  2220. };
  2221. template<
  2222. typename Tuple,
  2223. std::size_t N
  2224. >
  2225. struct TupleElementPrinter<Tuple, N, false> {
  2226. static void print(const Tuple&, std::ostream&) {}
  2227. };
  2228. }
  2229. template<typename ...Types>
  2230. struct StringMaker<std::tuple<Types...>> {
  2231. static std::string convert(const std::tuple<Types...>& tuple) {
  2232. ReusableStringStream rss;
  2233. rss << '{';
  2234. Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
  2235. rss << " }";
  2236. return rss.str();
  2237. }
  2238. };
  2239. }
  2240. #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  2241. #if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
  2242. #include <variant>
  2243. namespace Catch {
  2244. template<>
  2245. struct StringMaker<std::monostate> {
  2246. static std::string convert(const std::monostate&) {
  2247. return "{ }";
  2248. }
  2249. };
  2250. template<typename... Elements>
  2251. struct StringMaker<std::variant<Elements...>> {
  2252. static std::string convert(const std::variant<Elements...>& variant) {
  2253. if (variant.valueless_by_exception()) {
  2254. return "{valueless variant}";
  2255. } else {
  2256. return std::visit(
  2257. [](const auto& value) {
  2258. return ::Catch::Detail::stringify(value);
  2259. },
  2260. variant
  2261. );
  2262. }
  2263. }
  2264. };
  2265. }
  2266. #endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
  2267. namespace Catch {
  2268. // Import begin/ end from std here
  2269. using std::begin;
  2270. using std::end;
  2271. namespace Detail {
  2272. template <typename T, typename = void>
  2273. struct is_range_impl : std::false_type {};
  2274. template <typename T>
  2275. struct is_range_impl<T, void_t<decltype(begin(std::declval<T>()))>> : std::true_type {};
  2276. } // namespace Detail
  2277. template <typename T>
  2278. struct is_range : Detail::is_range_impl<T> {};
  2279. #if defined(_MANAGED) // Managed types are never ranges
  2280. template <typename T>
  2281. struct is_range<T^> {
  2282. static const bool value = false;
  2283. };
  2284. #endif
  2285. template<typename Range>
  2286. std::string rangeToString( Range const& range ) {
  2287. return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
  2288. }
  2289. // Handle vector<bool> specially
  2290. template<typename Allocator>
  2291. std::string rangeToString( std::vector<bool, Allocator> const& v ) {
  2292. ReusableStringStream rss;
  2293. rss << "{ ";
  2294. bool first = true;
  2295. for( bool b : v ) {
  2296. if( first )
  2297. first = false;
  2298. else
  2299. rss << ", ";
  2300. rss << ::Catch::Detail::stringify( b );
  2301. }
  2302. rss << " }";
  2303. return rss.str();
  2304. }
  2305. template<typename R>
  2306. struct StringMaker<R, std::enable_if_t<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>> {
  2307. static std::string convert( R const& range ) {
  2308. return rangeToString( range );
  2309. }
  2310. };
  2311. template <typename T, size_t SZ>
  2312. struct StringMaker<T[SZ]> {
  2313. static std::string convert(T const(&arr)[SZ]) {
  2314. return rangeToString(arr);
  2315. }
  2316. };
  2317. } // namespace Catch
  2318. // Separate std::chrono::duration specialization
  2319. #include <ctime>
  2320. #include <ratio>
  2321. #include <chrono>
  2322. namespace Catch {
  2323. template <class Ratio>
  2324. struct ratio_string {
  2325. static std::string symbol() {
  2326. Catch::ReusableStringStream rss;
  2327. rss << '[' << Ratio::num << '/'
  2328. << Ratio::den << ']';
  2329. return rss.str();
  2330. }
  2331. };
  2332. template <>
  2333. struct ratio_string<std::atto> {
  2334. static char symbol() { return 'a'; }
  2335. };
  2336. template <>
  2337. struct ratio_string<std::femto> {
  2338. static char symbol() { return 'f'; }
  2339. };
  2340. template <>
  2341. struct ratio_string<std::pico> {
  2342. static char symbol() { return 'p'; }
  2343. };
  2344. template <>
  2345. struct ratio_string<std::nano> {
  2346. static char symbol() { return 'n'; }
  2347. };
  2348. template <>
  2349. struct ratio_string<std::micro> {
  2350. static char symbol() { return 'u'; }
  2351. };
  2352. template <>
  2353. struct ratio_string<std::milli> {
  2354. static char symbol() { return 'm'; }
  2355. };
  2356. ////////////
  2357. // std::chrono::duration specializations
  2358. template<typename Value, typename Ratio>
  2359. struct StringMaker<std::chrono::duration<Value, Ratio>> {
  2360. static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
  2361. ReusableStringStream rss;
  2362. rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's';
  2363. return rss.str();
  2364. }
  2365. };
  2366. template<typename Value>
  2367. struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
  2368. static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
  2369. ReusableStringStream rss;
  2370. rss << duration.count() << " s";
  2371. return rss.str();
  2372. }
  2373. };
  2374. template<typename Value>
  2375. struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
  2376. static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
  2377. ReusableStringStream rss;
  2378. rss << duration.count() << " m";
  2379. return rss.str();
  2380. }
  2381. };
  2382. template<typename Value>
  2383. struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
  2384. static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
  2385. ReusableStringStream rss;
  2386. rss << duration.count() << " h";
  2387. return rss.str();
  2388. }
  2389. };
  2390. ////////////
  2391. // std::chrono::time_point specialization
  2392. // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
  2393. template<typename Clock, typename Duration>
  2394. struct StringMaker<std::chrono::time_point<Clock, Duration>> {
  2395. static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
  2396. return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch";
  2397. }
  2398. };
  2399. // std::chrono::time_point<system_clock> specialization
  2400. template<typename Duration>
  2401. struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
  2402. static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
  2403. auto converted = std::chrono::system_clock::to_time_t(time_point);
  2404. #ifdef _MSC_VER
  2405. std::tm timeInfo = {};
  2406. gmtime_s(&timeInfo, &converted);
  2407. #else
  2408. std::tm* timeInfo = std::gmtime(&converted);
  2409. #endif
  2410. auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
  2411. char timeStamp[timeStampSize];
  2412. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  2413. #ifdef _MSC_VER
  2414. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  2415. #else
  2416. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  2417. #endif
  2418. return std::string(timeStamp, timeStampSize - 1);
  2419. }
  2420. };
  2421. }
  2422. #define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \
  2423. namespace Catch { \
  2424. template<> struct StringMaker<enumName> { \
  2425. static std::string convert( enumName value ) { \
  2426. static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \
  2427. return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
  2428. } \
  2429. }; \
  2430. }
  2431. #define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ )
  2432. #ifdef _MSC_VER
  2433. #pragma warning(pop)
  2434. #endif
  2435. #endif // CATCH_TOSTRING_HPP_INCLUDED
  2436. #include <type_traits>
  2437. namespace Catch {
  2438. class Approx {
  2439. private:
  2440. bool equalityComparisonImpl(double other) const;
  2441. // Sets and validates the new margin (margin >= 0)
  2442. void setMargin(double margin);
  2443. // Sets and validates the new epsilon (0 < epsilon < 1)
  2444. void setEpsilon(double epsilon);
  2445. public:
  2446. explicit Approx ( double value );
  2447. static Approx custom();
  2448. Approx operator-() const;
  2449. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2450. Approx operator()( T const& value ) const {
  2451. Approx approx( static_cast<double>(value) );
  2452. approx.m_epsilon = m_epsilon;
  2453. approx.m_margin = m_margin;
  2454. approx.m_scale = m_scale;
  2455. return approx;
  2456. }
  2457. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2458. explicit Approx( T const& value ): Approx(static_cast<double>(value))
  2459. {}
  2460. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2461. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2462. auto lhs_v = static_cast<double>(lhs);
  2463. return rhs.equalityComparisonImpl(lhs_v);
  2464. }
  2465. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2466. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2467. return operator==( rhs, lhs );
  2468. }
  2469. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2470. friend bool operator != ( T const& lhs, Approx const& rhs ) {
  2471. return !operator==( lhs, rhs );
  2472. }
  2473. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2474. friend bool operator != ( Approx const& lhs, T const& rhs ) {
  2475. return !operator==( rhs, lhs );
  2476. }
  2477. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2478. friend bool operator <= ( T const& lhs, Approx const& rhs ) {
  2479. return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
  2480. }
  2481. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2482. friend bool operator <= ( Approx const& lhs, T const& rhs ) {
  2483. return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
  2484. }
  2485. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2486. friend bool operator >= ( T const& lhs, Approx const& rhs ) {
  2487. return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
  2488. }
  2489. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2490. friend bool operator >= ( Approx const& lhs, T const& rhs ) {
  2491. return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
  2492. }
  2493. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2494. Approx& epsilon( T const& newEpsilon ) {
  2495. const auto epsilonAsDouble = static_cast<double>(newEpsilon);
  2496. setEpsilon(epsilonAsDouble);
  2497. return *this;
  2498. }
  2499. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2500. Approx& margin( T const& newMargin ) {
  2501. const auto marginAsDouble = static_cast<double>(newMargin);
  2502. setMargin(marginAsDouble);
  2503. return *this;
  2504. }
  2505. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2506. Approx& scale( T const& newScale ) {
  2507. m_scale = static_cast<double>(newScale);
  2508. return *this;
  2509. }
  2510. std::string toString() const;
  2511. private:
  2512. double m_epsilon;
  2513. double m_margin;
  2514. double m_scale;
  2515. double m_value;
  2516. };
  2517. namespace literals {
  2518. Approx operator ""_a(long double val);
  2519. Approx operator ""_a(unsigned long long val);
  2520. } // end namespace literals
  2521. template<>
  2522. struct StringMaker<Catch::Approx> {
  2523. static std::string convert(Catch::Approx const& value);
  2524. };
  2525. } // end namespace Catch
  2526. #endif // CATCH_APPROX_HPP_INCLUDED
  2527. #ifndef CATCH_ASSERTION_INFO_HPP_INCLUDED
  2528. #define CATCH_ASSERTION_INFO_HPP_INCLUDED
  2529. #ifndef CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  2530. #define CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  2531. #include <cstddef>
  2532. #include <iosfwd>
  2533. namespace Catch {
  2534. struct SourceLineInfo {
  2535. SourceLineInfo() = delete;
  2536. constexpr SourceLineInfo( char const* _file, std::size_t _line ) noexcept:
  2537. file( _file ),
  2538. line( _line )
  2539. {}
  2540. bool operator == ( SourceLineInfo const& other ) const noexcept;
  2541. bool operator < ( SourceLineInfo const& other ) const noexcept;
  2542. char const* file;
  2543. std::size_t line;
  2544. friend std::ostream& operator << (std::ostream& os, SourceLineInfo const& info);
  2545. };
  2546. }
  2547. #define CATCH_INTERNAL_LINEINFO \
  2548. ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  2549. #endif // CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  2550. namespace Catch {
  2551. struct AssertionInfo {
  2552. // AssertionInfo() = delete;
  2553. StringRef macroName;
  2554. SourceLineInfo lineInfo;
  2555. StringRef capturedExpression;
  2556. ResultDisposition::Flags resultDisposition;
  2557. };
  2558. } // end namespace Catch
  2559. #endif // CATCH_ASSERTION_INFO_HPP_INCLUDED
  2560. #ifndef CATCH_ASSERTION_RESULT_HPP_INCLUDED
  2561. #define CATCH_ASSERTION_RESULT_HPP_INCLUDED
  2562. #ifndef CATCH_LAZY_EXPR_HPP_INCLUDED
  2563. #define CATCH_LAZY_EXPR_HPP_INCLUDED
  2564. #include <iosfwd>
  2565. namespace Catch {
  2566. class ITransientExpression;
  2567. class LazyExpression {
  2568. friend class AssertionHandler;
  2569. friend struct AssertionStats;
  2570. friend class RunContext;
  2571. ITransientExpression const* m_transientExpression = nullptr;
  2572. bool m_isNegated;
  2573. public:
  2574. LazyExpression( bool isNegated ):
  2575. m_isNegated(isNegated)
  2576. {}
  2577. LazyExpression(LazyExpression const& other) = default;
  2578. LazyExpression& operator = ( LazyExpression const& ) = delete;
  2579. explicit operator bool() const {
  2580. return m_transientExpression != nullptr;
  2581. }
  2582. friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
  2583. };
  2584. } // namespace Catch
  2585. #endif // CATCH_LAZY_EXPR_HPP_INCLUDED
  2586. #include <string>
  2587. namespace Catch {
  2588. struct AssertionResultData
  2589. {
  2590. AssertionResultData() = delete;
  2591. AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
  2592. std::string message;
  2593. mutable std::string reconstructedExpression;
  2594. LazyExpression lazyExpression;
  2595. ResultWas::OfType resultType;
  2596. std::string reconstructExpression() const;
  2597. };
  2598. class AssertionResult {
  2599. public:
  2600. AssertionResult() = delete;
  2601. AssertionResult( AssertionInfo const& info, AssertionResultData&& data );
  2602. bool isOk() const;
  2603. bool succeeded() const;
  2604. ResultWas::OfType getResultType() const;
  2605. bool hasExpression() const;
  2606. bool hasMessage() const;
  2607. std::string getExpression() const;
  2608. std::string getExpressionInMacro() const;
  2609. bool hasExpandedExpression() const;
  2610. std::string getExpandedExpression() const;
  2611. StringRef getMessage() const;
  2612. SourceLineInfo getSourceInfo() const;
  2613. StringRef getTestMacroName() const;
  2614. //protected:
  2615. AssertionInfo m_info;
  2616. AssertionResultData m_resultData;
  2617. };
  2618. } // end namespace Catch
  2619. #endif // CATCH_ASSERTION_RESULT_HPP_INCLUDED
  2620. #ifndef CATCH_CONFIG_HPP_INCLUDED
  2621. #define CATCH_CONFIG_HPP_INCLUDED
  2622. #ifndef CATCH_TEST_SPEC_HPP_INCLUDED
  2623. #define CATCH_TEST_SPEC_HPP_INCLUDED
  2624. #ifdef __clang__
  2625. #pragma clang diagnostic push
  2626. #pragma clang diagnostic ignored "-Wpadded"
  2627. #endif
  2628. #ifndef CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2629. #define CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2630. #ifndef CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2631. #define CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2632. namespace Catch {
  2633. enum class CaseSensitive { Yes, No };
  2634. } // namespace Catch
  2635. #endif // CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2636. #include <string>
  2637. namespace Catch
  2638. {
  2639. class WildcardPattern {
  2640. enum WildcardPosition {
  2641. NoWildcard = 0,
  2642. WildcardAtStart = 1,
  2643. WildcardAtEnd = 2,
  2644. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2645. };
  2646. public:
  2647. WildcardPattern( std::string const& pattern, CaseSensitive caseSensitivity );
  2648. bool matches( std::string const& str ) const;
  2649. private:
  2650. std::string normaliseString( std::string const& str ) const;
  2651. CaseSensitive m_caseSensitivity;
  2652. WildcardPosition m_wildcard = NoWildcard;
  2653. std::string m_pattern;
  2654. };
  2655. }
  2656. #endif // CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2657. #include <iosfwd>
  2658. #include <string>
  2659. #include <vector>
  2660. namespace Catch {
  2661. class IConfig;
  2662. struct TestCaseInfo;
  2663. class TestCaseHandle;
  2664. class TestSpec {
  2665. class Pattern {
  2666. public:
  2667. explicit Pattern( std::string const& name );
  2668. virtual ~Pattern();
  2669. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2670. std::string const& name() const;
  2671. private:
  2672. virtual void serializeTo( std::ostream& out ) const = 0;
  2673. // Writes string that would be reparsed into the pattern
  2674. friend std::ostream& operator<<(std::ostream& out,
  2675. Pattern const& pattern) {
  2676. pattern.serializeTo( out );
  2677. return out;
  2678. }
  2679. std::string const m_name;
  2680. };
  2681. class NamePattern : public Pattern {
  2682. public:
  2683. explicit NamePattern( std::string const& name, std::string const& filterString );
  2684. bool matches( TestCaseInfo const& testCase ) const override;
  2685. private:
  2686. void serializeTo( std::ostream& out ) const override;
  2687. WildcardPattern m_wildcardPattern;
  2688. };
  2689. class TagPattern : public Pattern {
  2690. public:
  2691. explicit TagPattern( std::string const& tag, std::string const& filterString );
  2692. bool matches( TestCaseInfo const& testCase ) const override;
  2693. private:
  2694. void serializeTo( std::ostream& out ) const override;
  2695. std::string m_tag;
  2696. };
  2697. struct Filter {
  2698. std::vector<Detail::unique_ptr<Pattern>> m_required;
  2699. std::vector<Detail::unique_ptr<Pattern>> m_forbidden;
  2700. //! Serializes this filter into a string that would be parsed into
  2701. //! an equivalent filter
  2702. void serializeTo( std::ostream& out ) const;
  2703. friend std::ostream& operator<<(std::ostream& out, Filter const& f) {
  2704. f.serializeTo( out );
  2705. return out;
  2706. }
  2707. bool matches( TestCaseInfo const& testCase ) const;
  2708. };
  2709. static std::string extractFilterName( Filter const& filter );
  2710. public:
  2711. struct FilterMatch {
  2712. std::string name;
  2713. std::vector<TestCaseHandle const*> tests;
  2714. };
  2715. using Matches = std::vector<FilterMatch>;
  2716. using vectorStrings = std::vector<std::string>;
  2717. bool hasFilters() const;
  2718. bool matches( TestCaseInfo const& testCase ) const;
  2719. Matches matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const;
  2720. const vectorStrings & getInvalidSpecs() const;
  2721. private:
  2722. std::vector<Filter> m_filters;
  2723. std::vector<std::string> m_invalidSpecs;
  2724. friend class TestSpecParser;
  2725. //! Serializes this test spec into a string that would be parsed into
  2726. //! equivalent test spec
  2727. void serializeTo( std::ostream& out ) const;
  2728. friend std::ostream& operator<<(std::ostream& out,
  2729. TestSpec const& spec) {
  2730. spec.serializeTo( out );
  2731. return out;
  2732. }
  2733. };
  2734. }
  2735. #ifdef __clang__
  2736. #pragma clang diagnostic pop
  2737. #endif
  2738. #endif // CATCH_TEST_SPEC_HPP_INCLUDED
  2739. #ifndef CATCH_OPTIONAL_HPP_INCLUDED
  2740. #define CATCH_OPTIONAL_HPP_INCLUDED
  2741. #include <cassert>
  2742. namespace Catch {
  2743. // An optional type
  2744. template<typename T>
  2745. class Optional {
  2746. public:
  2747. Optional(): nullableValue( nullptr ) {}
  2748. ~Optional() { reset(); }
  2749. Optional( T const& _value ):
  2750. nullableValue( new ( storage ) T( _value ) ) {}
  2751. Optional( T&& _value ):
  2752. nullableValue( new ( storage ) T( CATCH_MOVE( _value ) ) ) {}
  2753. Optional& operator=( T const& _value ) {
  2754. reset();
  2755. nullableValue = new ( storage ) T( _value );
  2756. return *this;
  2757. }
  2758. Optional& operator=( T&& _value ) {
  2759. reset();
  2760. nullableValue = new ( storage ) T( CATCH_MOVE( _value ) );
  2761. return *this;
  2762. }
  2763. Optional( Optional const& _other ):
  2764. nullableValue( _other ? new ( storage ) T( *_other ) : nullptr ) {}
  2765. Optional( Optional&& _other ):
  2766. nullableValue( _other ? new ( storage ) T( CATCH_MOVE( *_other ) )
  2767. : nullptr ) {}
  2768. Optional& operator=( Optional const& _other ) {
  2769. if ( &_other != this ) {
  2770. reset();
  2771. if ( _other ) { nullableValue = new ( storage ) T( *_other ); }
  2772. }
  2773. return *this;
  2774. }
  2775. Optional& operator=( Optional&& _other ) {
  2776. if ( &_other != this ) {
  2777. reset();
  2778. if ( _other ) {
  2779. nullableValue = new ( storage ) T( CATCH_MOVE( *_other ) );
  2780. }
  2781. }
  2782. return *this;
  2783. }
  2784. void reset() {
  2785. if ( nullableValue ) { nullableValue->~T(); }
  2786. nullableValue = nullptr;
  2787. }
  2788. T& operator*() {
  2789. assert(nullableValue);
  2790. return *nullableValue;
  2791. }
  2792. T const& operator*() const {
  2793. assert(nullableValue);
  2794. return *nullableValue;
  2795. }
  2796. T* operator->() {
  2797. assert(nullableValue);
  2798. return nullableValue;
  2799. }
  2800. const T* operator->() const {
  2801. assert(nullableValue);
  2802. return nullableValue;
  2803. }
  2804. T valueOr( T const& defaultValue ) const {
  2805. return nullableValue ? *nullableValue : defaultValue;
  2806. }
  2807. bool some() const { return nullableValue != nullptr; }
  2808. bool none() const { return nullableValue == nullptr; }
  2809. bool operator !() const { return nullableValue == nullptr; }
  2810. explicit operator bool() const {
  2811. return some();
  2812. }
  2813. friend bool operator==(Optional const& a, Optional const& b) {
  2814. if (a.none() && b.none()) {
  2815. return true;
  2816. } else if (a.some() && b.some()) {
  2817. return *a == *b;
  2818. } else {
  2819. return false;
  2820. }
  2821. }
  2822. friend bool operator!=(Optional const& a, Optional const& b) {
  2823. return !( a == b );
  2824. }
  2825. private:
  2826. T* nullableValue;
  2827. alignas(alignof(T)) char storage[sizeof(T)];
  2828. };
  2829. } // end namespace Catch
  2830. #endif // CATCH_OPTIONAL_HPP_INCLUDED
  2831. #ifndef CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  2832. #define CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  2833. #include <cstdint>
  2834. namespace Catch {
  2835. enum class GenerateFrom {
  2836. Time,
  2837. RandomDevice,
  2838. //! Currently equivalent to RandomDevice, but can change at any point
  2839. Default
  2840. };
  2841. std::uint32_t generateRandomSeed(GenerateFrom from);
  2842. } // end namespace Catch
  2843. #endif // CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  2844. #ifndef CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  2845. #define CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  2846. #include <map>
  2847. #include <string>
  2848. #include <vector>
  2849. namespace Catch {
  2850. enum class ColourMode : std::uint8_t;
  2851. namespace Detail {
  2852. //! Splits the reporter spec into reporter name and kv-pair options
  2853. std::vector<std::string> splitReporterSpec( StringRef reporterSpec );
  2854. Optional<ColourMode> stringToColourMode( StringRef colourMode );
  2855. }
  2856. /**
  2857. * Structured reporter spec that a reporter can be created from
  2858. *
  2859. * Parsing has been validated, but semantics have not. This means e.g.
  2860. * that the colour mode is known to Catch2, but it might not be
  2861. * compiled into the binary, and the output filename might not be
  2862. * openable.
  2863. */
  2864. class ReporterSpec {
  2865. std::string m_name;
  2866. Optional<std::string> m_outputFileName;
  2867. Optional<ColourMode> m_colourMode;
  2868. std::map<std::string, std::string> m_customOptions;
  2869. friend bool operator==( ReporterSpec const& lhs,
  2870. ReporterSpec const& rhs );
  2871. friend bool operator!=( ReporterSpec const& lhs,
  2872. ReporterSpec const& rhs ) {
  2873. return !( lhs == rhs );
  2874. }
  2875. public:
  2876. ReporterSpec(
  2877. std::string name,
  2878. Optional<std::string> outputFileName,
  2879. Optional<ColourMode> colourMode,
  2880. std::map<std::string, std::string> customOptions );
  2881. std::string const& name() const { return m_name; }
  2882. Optional<std::string> const& outputFile() const {
  2883. return m_outputFileName;
  2884. }
  2885. Optional<ColourMode> const& colourMode() const { return m_colourMode; }
  2886. std::map<std::string, std::string> const& customOptions() const {
  2887. return m_customOptions;
  2888. }
  2889. };
  2890. /**
  2891. * Parses provided reporter spec string into
  2892. *
  2893. * Returns empty optional on errors, e.g.
  2894. * * field that is not first and not a key+value pair
  2895. * * duplicated keys in kv pair
  2896. * * unknown catch reporter option
  2897. * * empty key/value in an custom kv pair
  2898. * * ...
  2899. */
  2900. Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec );
  2901. }
  2902. #endif // CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  2903. #include <chrono>
  2904. #include <map>
  2905. #include <string>
  2906. #include <vector>
  2907. namespace Catch {
  2908. class IStream;
  2909. /**
  2910. * `ReporterSpec` but with the defaults filled in.
  2911. *
  2912. * Like `ReporterSpec`, the semantics are unchecked.
  2913. */
  2914. struct ProcessedReporterSpec {
  2915. std::string name;
  2916. std::string outputFilename;
  2917. ColourMode colourMode;
  2918. std::map<std::string, std::string> customOptions;
  2919. friend bool operator==( ProcessedReporterSpec const& lhs,
  2920. ProcessedReporterSpec const& rhs );
  2921. friend bool operator!=( ProcessedReporterSpec const& lhs,
  2922. ProcessedReporterSpec const& rhs ) {
  2923. return !( lhs == rhs );
  2924. }
  2925. };
  2926. struct ConfigData {
  2927. bool listTests = false;
  2928. bool listTags = false;
  2929. bool listReporters = false;
  2930. bool listListeners = false;
  2931. bool showSuccessfulTests = false;
  2932. bool shouldDebugBreak = false;
  2933. bool noThrow = false;
  2934. bool showHelp = false;
  2935. bool showInvisibles = false;
  2936. bool filenamesAsTags = false;
  2937. bool libIdentify = false;
  2938. bool allowZeroTests = false;
  2939. int abortAfter = -1;
  2940. uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
  2941. unsigned int shardCount = 1;
  2942. unsigned int shardIndex = 0;
  2943. bool skipBenchmarks = false;
  2944. bool benchmarkNoAnalysis = false;
  2945. unsigned int benchmarkSamples = 100;
  2946. double benchmarkConfidenceInterval = 0.95;
  2947. unsigned int benchmarkResamples = 100'000;
  2948. std::chrono::milliseconds::rep benchmarkWarmupTime = 100;
  2949. Verbosity verbosity = Verbosity::Normal;
  2950. WarnAbout::What warnings = WarnAbout::Nothing;
  2951. ShowDurations showDurations = ShowDurations::DefaultForReporter;
  2952. double minDuration = -1;
  2953. TestRunOrder runOrder = TestRunOrder::Declared;
  2954. ColourMode defaultColourMode = ColourMode::PlatformDefault;
  2955. WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
  2956. std::string defaultOutputFilename;
  2957. std::string name;
  2958. std::string processName;
  2959. std::vector<ReporterSpec> reporterSpecifications;
  2960. std::vector<std::string> testsOrTags;
  2961. std::vector<std::string> sectionsToRun;
  2962. };
  2963. class Config : public IConfig {
  2964. public:
  2965. Config() = default;
  2966. Config( ConfigData const& data );
  2967. ~Config() override; // = default in the cpp file
  2968. bool listTests() const;
  2969. bool listTags() const;
  2970. bool listReporters() const;
  2971. bool listListeners() const;
  2972. std::vector<ReporterSpec> const& getReporterSpecs() const;
  2973. std::vector<ProcessedReporterSpec> const&
  2974. getProcessedReporterSpecs() const;
  2975. std::vector<std::string> const& getTestsOrTags() const override;
  2976. std::vector<std::string> const& getSectionsToRun() const override;
  2977. TestSpec const& testSpec() const override;
  2978. bool hasTestFilters() const override;
  2979. bool showHelp() const;
  2980. // IConfig interface
  2981. bool allowThrows() const override;
  2982. StringRef name() const override;
  2983. bool includeSuccessfulResults() const override;
  2984. bool warnAboutMissingAssertions() const override;
  2985. bool warnAboutUnmatchedTestSpecs() const override;
  2986. bool zeroTestsCountAsSuccess() const override;
  2987. ShowDurations showDurations() const override;
  2988. double minDuration() const override;
  2989. TestRunOrder runOrder() const override;
  2990. uint32_t rngSeed() const override;
  2991. unsigned int shardCount() const override;
  2992. unsigned int shardIndex() const override;
  2993. ColourMode defaultColourMode() const override;
  2994. bool shouldDebugBreak() const override;
  2995. int abortAfter() const override;
  2996. bool showInvisibles() const override;
  2997. Verbosity verbosity() const override;
  2998. bool skipBenchmarks() const override;
  2999. bool benchmarkNoAnalysis() const override;
  3000. unsigned int benchmarkSamples() const override;
  3001. double benchmarkConfidenceInterval() const override;
  3002. unsigned int benchmarkResamples() const override;
  3003. std::chrono::milliseconds benchmarkWarmupTime() const override;
  3004. private:
  3005. // Reads Bazel env vars and applies them to the config
  3006. void readBazelEnvVars();
  3007. ConfigData m_data;
  3008. std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
  3009. TestSpec m_testSpec;
  3010. bool m_hasTestFilters = false;
  3011. };
  3012. } // end namespace Catch
  3013. #endif // CATCH_CONFIG_HPP_INCLUDED
  3014. #ifndef CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3015. #define CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3016. #include <cstdint>
  3017. namespace Catch {
  3018. //! Returns Catch2's current RNG seed.
  3019. std::uint32_t getSeed();
  3020. }
  3021. #endif // CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3022. #ifndef CATCH_MESSAGE_HPP_INCLUDED
  3023. #define CATCH_MESSAGE_HPP_INCLUDED
  3024. /** \file
  3025. * Wrapper for the CATCH_CONFIG_PREFIX_MESSAGES configuration option
  3026. *
  3027. * CATCH_CONFIG_PREFIX_ALL can be used to avoid clashes with other macros
  3028. * by prepending CATCH_. This may not be desirable if the only clashes are with
  3029. * logger macros such as INFO and WARN. In this cases
  3030. * CATCH_CONFIG_PREFIX_MESSAGES can be used to only prefix a small subset
  3031. * of relevant macros.
  3032. *
  3033. */
  3034. #ifndef CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED
  3035. #define CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED
  3036. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_PREFIX_MESSAGES)
  3037. #define CATCH_CONFIG_PREFIX_MESSAGES
  3038. #endif
  3039. #endif // CATCH_CONFIG_PREFIX_MESSAGES_HPP_INCLUDED
  3040. #ifndef CATCH_STREAM_END_STOP_HPP_INCLUDED
  3041. #define CATCH_STREAM_END_STOP_HPP_INCLUDED
  3042. namespace Catch {
  3043. // Use this in variadic streaming macros to allow
  3044. // << +StreamEndStop
  3045. // as well as
  3046. // << stuff +StreamEndStop
  3047. struct StreamEndStop {
  3048. constexpr StringRef operator+() const { return StringRef(); }
  3049. template <typename T>
  3050. constexpr friend T const& operator+( T const& value, StreamEndStop ) {
  3051. return value;
  3052. }
  3053. };
  3054. } // namespace Catch
  3055. #endif // CATCH_STREAM_END_STOP_HPP_INCLUDED
  3056. #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED
  3057. #define CATCH_MESSAGE_INFO_HPP_INCLUDED
  3058. #include <string>
  3059. namespace Catch {
  3060. struct MessageInfo {
  3061. MessageInfo( StringRef _macroName,
  3062. SourceLineInfo const& _lineInfo,
  3063. ResultWas::OfType _type );
  3064. StringRef macroName;
  3065. std::string message;
  3066. SourceLineInfo lineInfo;
  3067. ResultWas::OfType type;
  3068. unsigned int sequence;
  3069. bool operator == (MessageInfo const& other) const {
  3070. return sequence == other.sequence;
  3071. }
  3072. bool operator < (MessageInfo const& other) const {
  3073. return sequence < other.sequence;
  3074. }
  3075. private:
  3076. static unsigned int globalCount;
  3077. };
  3078. } // end namespace Catch
  3079. #endif // CATCH_MESSAGE_INFO_HPP_INCLUDED
  3080. #include <string>
  3081. #include <vector>
  3082. namespace Catch {
  3083. struct SourceLineInfo;
  3084. class IResultCapture;
  3085. struct MessageStream {
  3086. template<typename T>
  3087. MessageStream& operator << ( T const& value ) {
  3088. m_stream << value;
  3089. return *this;
  3090. }
  3091. ReusableStringStream m_stream;
  3092. };
  3093. struct MessageBuilder : MessageStream {
  3094. MessageBuilder( StringRef macroName,
  3095. SourceLineInfo const& lineInfo,
  3096. ResultWas::OfType type ):
  3097. m_info(macroName, lineInfo, type) {}
  3098. template<typename T>
  3099. MessageBuilder&& operator << ( T const& value ) && {
  3100. m_stream << value;
  3101. return CATCH_MOVE(*this);
  3102. }
  3103. MessageInfo m_info;
  3104. };
  3105. class ScopedMessage {
  3106. public:
  3107. explicit ScopedMessage( MessageBuilder&& builder );
  3108. ScopedMessage( ScopedMessage& duplicate ) = delete;
  3109. ScopedMessage( ScopedMessage&& old ) noexcept;
  3110. ~ScopedMessage();
  3111. MessageInfo m_info;
  3112. bool m_moved = false;
  3113. };
  3114. class Capturer {
  3115. std::vector<MessageInfo> m_messages;
  3116. IResultCapture& m_resultCapture;
  3117. size_t m_captured = 0;
  3118. public:
  3119. Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
  3120. Capturer(Capturer const&) = delete;
  3121. Capturer& operator=(Capturer const&) = delete;
  3122. ~Capturer();
  3123. void captureValue( size_t index, std::string const& value );
  3124. template<typename T>
  3125. void captureValues( size_t index, T const& value ) {
  3126. captureValue( index, Catch::Detail::stringify( value ) );
  3127. }
  3128. template<typename T, typename... Ts>
  3129. void captureValues( size_t index, T const& value, Ts const&... values ) {
  3130. captureValue( index, Catch::Detail::stringify(value) );
  3131. captureValues( index+1, values... );
  3132. }
  3133. };
  3134. } // end namespace Catch
  3135. ///////////////////////////////////////////////////////////////////////////////
  3136. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
  3137. do { \
  3138. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
  3139. catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
  3140. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  3141. } while( false )
  3142. ///////////////////////////////////////////////////////////////////////////////
  3143. #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
  3144. Catch::Capturer varName( macroName##_catch_sr, \
  3145. CATCH_INTERNAL_LINEINFO, \
  3146. Catch::ResultWas::Info, \
  3147. #__VA_ARGS__##_catch_sr ); \
  3148. varName.captureValues( 0, __VA_ARGS__ )
  3149. ///////////////////////////////////////////////////////////////////////////////
  3150. #define INTERNAL_CATCH_INFO( macroName, log ) \
  3151. const Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
  3152. ///////////////////////////////////////////////////////////////////////////////
  3153. #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
  3154. Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
  3155. #if defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
  3156. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  3157. #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
  3158. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  3159. #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ )
  3160. #elif defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
  3161. #define CATCH_INFO( msg ) (void)(0)
  3162. #define CATCH_UNSCOPED_INFO( msg ) (void)(0)
  3163. #define CATCH_WARN( msg ) (void)(0)
  3164. #define CATCH_CAPTURE( ... ) (void)(0)
  3165. #elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && !defined(CATCH_CONFIG_DISABLE)
  3166. #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  3167. #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
  3168. #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  3169. #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ )
  3170. #elif !defined(CATCH_CONFIG_PREFIX_MESSAGES) && defined(CATCH_CONFIG_DISABLE)
  3171. #define INFO( msg ) (void)(0)
  3172. #define UNSCOPED_INFO( msg ) (void)(0)
  3173. #define WARN( msg ) (void)(0)
  3174. #define CAPTURE( ... ) (void)(0)
  3175. #endif // end of user facing macro declarations
  3176. #endif // CATCH_MESSAGE_HPP_INCLUDED
  3177. #ifndef CATCH_SECTION_INFO_HPP_INCLUDED
  3178. #define CATCH_SECTION_INFO_HPP_INCLUDED
  3179. #ifndef CATCH_TOTALS_HPP_INCLUDED
  3180. #define CATCH_TOTALS_HPP_INCLUDED
  3181. #include <cstdint>
  3182. namespace Catch {
  3183. struct Counts {
  3184. Counts operator - ( Counts const& other ) const;
  3185. Counts& operator += ( Counts const& other );
  3186. std::uint64_t total() const;
  3187. bool allPassed() const;
  3188. bool allOk() const;
  3189. std::uint64_t passed = 0;
  3190. std::uint64_t failed = 0;
  3191. std::uint64_t failedButOk = 0;
  3192. std::uint64_t skipped = 0;
  3193. };
  3194. struct Totals {
  3195. Totals operator - ( Totals const& other ) const;
  3196. Totals& operator += ( Totals const& other );
  3197. Totals delta( Totals const& prevTotals ) const;
  3198. Counts assertions;
  3199. Counts testCases;
  3200. };
  3201. }
  3202. #endif // CATCH_TOTALS_HPP_INCLUDED
  3203. #include <string>
  3204. namespace Catch {
  3205. struct SectionInfo {
  3206. // The last argument is ignored, so that people can write
  3207. // SECTION("ShortName", "Proper description that is long") and
  3208. // still use the `-c` flag comfortably.
  3209. SectionInfo( SourceLineInfo const& _lineInfo, std::string _name,
  3210. const char* const = nullptr ):
  3211. name(CATCH_MOVE(_name)),
  3212. lineInfo(_lineInfo)
  3213. {}
  3214. std::string name;
  3215. SourceLineInfo lineInfo;
  3216. };
  3217. struct SectionEndInfo {
  3218. SectionInfo sectionInfo;
  3219. Counts prevAssertions;
  3220. double durationInSeconds;
  3221. };
  3222. } // end namespace Catch
  3223. #endif // CATCH_SECTION_INFO_HPP_INCLUDED
  3224. #ifndef CATCH_SESSION_HPP_INCLUDED
  3225. #define CATCH_SESSION_HPP_INCLUDED
  3226. #ifndef CATCH_COMMANDLINE_HPP_INCLUDED
  3227. #define CATCH_COMMANDLINE_HPP_INCLUDED
  3228. #ifndef CATCH_CLARA_HPP_INCLUDED
  3229. #define CATCH_CLARA_HPP_INCLUDED
  3230. #if defined( __clang__ )
  3231. # pragma clang diagnostic push
  3232. # pragma clang diagnostic ignored "-Wweak-vtables"
  3233. # pragma clang diagnostic ignored "-Wshadow"
  3234. # pragma clang diagnostic ignored "-Wdeprecated"
  3235. #endif
  3236. #if defined( __GNUC__ )
  3237. # pragma GCC diagnostic push
  3238. # pragma GCC diagnostic ignored "-Wsign-conversion"
  3239. #endif
  3240. #ifndef CLARA_CONFIG_OPTIONAL_TYPE
  3241. # ifdef __has_include
  3242. # if __has_include( <optional>) && __cplusplus >= 201703L
  3243. # include <optional>
  3244. # define CLARA_CONFIG_OPTIONAL_TYPE std::optional
  3245. # endif
  3246. # endif
  3247. #endif
  3248. #include <cassert>
  3249. #include <memory>
  3250. #include <ostream>
  3251. #include <sstream>
  3252. #include <string>
  3253. #include <type_traits>
  3254. #include <vector>
  3255. namespace Catch {
  3256. namespace Clara {
  3257. class Args;
  3258. class Parser;
  3259. // enum of result types from a parse
  3260. enum class ParseResultType {
  3261. Matched,
  3262. NoMatch,
  3263. ShortCircuitAll,
  3264. ShortCircuitSame
  3265. };
  3266. struct accept_many_t {};
  3267. constexpr accept_many_t accept_many {};
  3268. namespace Detail {
  3269. struct fake_arg {
  3270. template <typename T>
  3271. operator T();
  3272. };
  3273. template <typename F, typename = void>
  3274. struct is_unary_function : std::false_type {};
  3275. template <typename F>
  3276. struct is_unary_function<
  3277. F,
  3278. Catch::Detail::void_t<decltype(
  3279. std::declval<F>()( fake_arg() ) )
  3280. >
  3281. > : std::true_type {};
  3282. // Traits for extracting arg and return type of lambdas (for single
  3283. // argument lambdas)
  3284. template <typename L>
  3285. struct UnaryLambdaTraits
  3286. : UnaryLambdaTraits<decltype( &L::operator() )> {};
  3287. template <typename ClassT, typename ReturnT, typename... Args>
  3288. struct UnaryLambdaTraits<ReturnT ( ClassT::* )( Args... ) const> {
  3289. static const bool isValid = false;
  3290. };
  3291. template <typename ClassT, typename ReturnT, typename ArgT>
  3292. struct UnaryLambdaTraits<ReturnT ( ClassT::* )( ArgT ) const> {
  3293. static const bool isValid = true;
  3294. using ArgType = std::remove_const_t<std::remove_reference_t<ArgT>>;
  3295. using ReturnType = ReturnT;
  3296. };
  3297. class TokenStream;
  3298. // Wraps a token coming from a token stream. These may not directly
  3299. // correspond to strings as a single string may encode an option +
  3300. // its argument if the : or = form is used
  3301. enum class TokenType { Option, Argument };
  3302. struct Token {
  3303. TokenType type;
  3304. StringRef token;
  3305. };
  3306. // Abstracts iterators into args as a stream of tokens, with option
  3307. // arguments uniformly handled
  3308. class TokenStream {
  3309. using Iterator = std::vector<StringRef>::const_iterator;
  3310. Iterator it;
  3311. Iterator itEnd;
  3312. std::vector<Token> m_tokenBuffer;
  3313. void loadBuffer();
  3314. public:
  3315. explicit TokenStream( Args const& args );
  3316. TokenStream( Iterator it, Iterator itEnd );
  3317. explicit operator bool() const {
  3318. return !m_tokenBuffer.empty() || it != itEnd;
  3319. }
  3320. size_t count() const {
  3321. return m_tokenBuffer.size() + ( itEnd - it );
  3322. }
  3323. Token operator*() const {
  3324. assert( !m_tokenBuffer.empty() );
  3325. return m_tokenBuffer.front();
  3326. }
  3327. Token const* operator->() const {
  3328. assert( !m_tokenBuffer.empty() );
  3329. return &m_tokenBuffer.front();
  3330. }
  3331. TokenStream& operator++();
  3332. };
  3333. //! Denotes type of a parsing result
  3334. enum class ResultType {
  3335. Ok, ///< No errors
  3336. LogicError, ///< Error in user-specified arguments for
  3337. ///< construction
  3338. RuntimeError ///< Error in parsing inputs
  3339. };
  3340. class ResultBase {
  3341. protected:
  3342. ResultBase( ResultType type ): m_type( type ) {}
  3343. virtual ~ResultBase(); // = default;
  3344. ResultBase(ResultBase const&) = default;
  3345. ResultBase& operator=(ResultBase const&) = default;
  3346. ResultBase(ResultBase&&) = default;
  3347. ResultBase& operator=(ResultBase&&) = default;
  3348. virtual void enforceOk() const = 0;
  3349. ResultType m_type;
  3350. };
  3351. template <typename T>
  3352. class ResultValueBase : public ResultBase {
  3353. public:
  3354. T const& value() const& {
  3355. enforceOk();
  3356. return m_value;
  3357. }
  3358. T&& value() && {
  3359. enforceOk();
  3360. return CATCH_MOVE( m_value );
  3361. }
  3362. protected:
  3363. ResultValueBase( ResultType type ): ResultBase( type ) {}
  3364. ResultValueBase( ResultValueBase const& other ):
  3365. ResultBase( other ) {
  3366. if ( m_type == ResultType::Ok )
  3367. new ( &m_value ) T( other.m_value );
  3368. }
  3369. ResultValueBase( ResultValueBase&& other ):
  3370. ResultBase( other ) {
  3371. if ( m_type == ResultType::Ok )
  3372. new ( &m_value ) T( CATCH_MOVE(other.m_value) );
  3373. }
  3374. ResultValueBase( ResultType, T const& value ):
  3375. ResultBase( ResultType::Ok ) {
  3376. new ( &m_value ) T( value );
  3377. }
  3378. ResultValueBase( ResultType, T&& value ):
  3379. ResultBase( ResultType::Ok ) {
  3380. new ( &m_value ) T( CATCH_MOVE(value) );
  3381. }
  3382. ResultValueBase& operator=( ResultValueBase const& other ) {
  3383. if ( m_type == ResultType::Ok )
  3384. m_value.~T();
  3385. ResultBase::operator=( other );
  3386. if ( m_type == ResultType::Ok )
  3387. new ( &m_value ) T( other.m_value );
  3388. return *this;
  3389. }
  3390. ResultValueBase& operator=( ResultValueBase&& other ) {
  3391. if ( m_type == ResultType::Ok ) m_value.~T();
  3392. ResultBase::operator=( other );
  3393. if ( m_type == ResultType::Ok )
  3394. new ( &m_value ) T( CATCH_MOVE(other.m_value) );
  3395. return *this;
  3396. }
  3397. ~ResultValueBase() override {
  3398. if ( m_type == ResultType::Ok )
  3399. m_value.~T();
  3400. }
  3401. union {
  3402. T m_value;
  3403. };
  3404. };
  3405. template <> class ResultValueBase<void> : public ResultBase {
  3406. protected:
  3407. using ResultBase::ResultBase;
  3408. };
  3409. template <typename T = void>
  3410. class BasicResult : public ResultValueBase<T> {
  3411. public:
  3412. template <typename U>
  3413. explicit BasicResult( BasicResult<U> const& other ):
  3414. ResultValueBase<T>( other.type() ),
  3415. m_errorMessage( other.errorMessage() ) {
  3416. assert( type() != ResultType::Ok );
  3417. }
  3418. template <typename U>
  3419. static auto ok( U&& value ) -> BasicResult {
  3420. return { ResultType::Ok, CATCH_FORWARD(value) };
  3421. }
  3422. static auto ok() -> BasicResult { return { ResultType::Ok }; }
  3423. static auto logicError( std::string&& message )
  3424. -> BasicResult {
  3425. return { ResultType::LogicError, CATCH_MOVE(message) };
  3426. }
  3427. static auto runtimeError( std::string&& message )
  3428. -> BasicResult {
  3429. return { ResultType::RuntimeError, CATCH_MOVE(message) };
  3430. }
  3431. explicit operator bool() const {
  3432. return m_type == ResultType::Ok;
  3433. }
  3434. auto type() const -> ResultType { return m_type; }
  3435. auto errorMessage() const -> std::string const& {
  3436. return m_errorMessage;
  3437. }
  3438. protected:
  3439. void enforceOk() const override {
  3440. // Errors shouldn't reach this point, but if they do
  3441. // the actual error message will be in m_errorMessage
  3442. assert( m_type != ResultType::LogicError );
  3443. assert( m_type != ResultType::RuntimeError );
  3444. if ( m_type != ResultType::Ok )
  3445. std::abort();
  3446. }
  3447. std::string
  3448. m_errorMessage; // Only populated if resultType is an error
  3449. BasicResult( ResultType type,
  3450. std::string&& message ):
  3451. ResultValueBase<T>( type ), m_errorMessage( CATCH_MOVE(message) ) {
  3452. assert( m_type != ResultType::Ok );
  3453. }
  3454. using ResultValueBase<T>::ResultValueBase;
  3455. using ResultBase::m_type;
  3456. };
  3457. class ParseState {
  3458. public:
  3459. ParseState( ParseResultType type,
  3460. TokenStream remainingTokens );
  3461. ParseResultType type() const { return m_type; }
  3462. TokenStream const& remainingTokens() const& {
  3463. return m_remainingTokens;
  3464. }
  3465. TokenStream&& remainingTokens() && {
  3466. return CATCH_MOVE( m_remainingTokens );
  3467. }
  3468. private:
  3469. ParseResultType m_type;
  3470. TokenStream m_remainingTokens;
  3471. };
  3472. using Result = BasicResult<void>;
  3473. using ParserResult = BasicResult<ParseResultType>;
  3474. using InternalParseResult = BasicResult<ParseState>;
  3475. struct HelpColumns {
  3476. std::string left;
  3477. StringRef descriptions;
  3478. };
  3479. template <typename T>
  3480. ParserResult convertInto( std::string const& source, T& target ) {
  3481. std::stringstream ss( source );
  3482. ss >> target;
  3483. if ( ss.fail() ) {
  3484. return ParserResult::runtimeError(
  3485. "Unable to convert '" + source +
  3486. "' to destination type" );
  3487. } else {
  3488. return ParserResult::ok( ParseResultType::Matched );
  3489. }
  3490. }
  3491. ParserResult convertInto( std::string const& source,
  3492. std::string& target );
  3493. ParserResult convertInto( std::string const& source, bool& target );
  3494. #ifdef CLARA_CONFIG_OPTIONAL_TYPE
  3495. template <typename T>
  3496. auto convertInto( std::string const& source,
  3497. CLARA_CONFIG_OPTIONAL_TYPE<T>& target )
  3498. -> ParserResult {
  3499. T temp;
  3500. auto result = convertInto( source, temp );
  3501. if ( result )
  3502. target = CATCH_MOVE( temp );
  3503. return result;
  3504. }
  3505. #endif // CLARA_CONFIG_OPTIONAL_TYPE
  3506. struct BoundRef : Catch::Detail::NonCopyable {
  3507. virtual ~BoundRef() = default;
  3508. virtual bool isContainer() const;
  3509. virtual bool isFlag() const;
  3510. };
  3511. struct BoundValueRefBase : BoundRef {
  3512. virtual auto setValue( std::string const& arg )
  3513. -> ParserResult = 0;
  3514. };
  3515. struct BoundFlagRefBase : BoundRef {
  3516. virtual auto setFlag( bool flag ) -> ParserResult = 0;
  3517. bool isFlag() const override;
  3518. };
  3519. template <typename T> struct BoundValueRef : BoundValueRefBase {
  3520. T& m_ref;
  3521. explicit BoundValueRef( T& ref ): m_ref( ref ) {}
  3522. ParserResult setValue( std::string const& arg ) override {
  3523. return convertInto( arg, m_ref );
  3524. }
  3525. };
  3526. template <typename T>
  3527. struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
  3528. std::vector<T>& m_ref;
  3529. explicit BoundValueRef( std::vector<T>& ref ): m_ref( ref ) {}
  3530. auto isContainer() const -> bool override { return true; }
  3531. auto setValue( std::string const& arg )
  3532. -> ParserResult override {
  3533. T temp;
  3534. auto result = convertInto( arg, temp );
  3535. if ( result )
  3536. m_ref.push_back( temp );
  3537. return result;
  3538. }
  3539. };
  3540. struct BoundFlagRef : BoundFlagRefBase {
  3541. bool& m_ref;
  3542. explicit BoundFlagRef( bool& ref ): m_ref( ref ) {}
  3543. ParserResult setFlag( bool flag ) override;
  3544. };
  3545. template <typename ReturnType> struct LambdaInvoker {
  3546. static_assert(
  3547. std::is_same<ReturnType, ParserResult>::value,
  3548. "Lambda must return void or clara::ParserResult" );
  3549. template <typename L, typename ArgType>
  3550. static auto invoke( L const& lambda, ArgType const& arg )
  3551. -> ParserResult {
  3552. return lambda( arg );
  3553. }
  3554. };
  3555. template <> struct LambdaInvoker<void> {
  3556. template <typename L, typename ArgType>
  3557. static auto invoke( L const& lambda, ArgType const& arg )
  3558. -> ParserResult {
  3559. lambda( arg );
  3560. return ParserResult::ok( ParseResultType::Matched );
  3561. }
  3562. };
  3563. template <typename ArgType, typename L>
  3564. auto invokeLambda( L const& lambda, std::string const& arg )
  3565. -> ParserResult {
  3566. ArgType temp{};
  3567. auto result = convertInto( arg, temp );
  3568. return !result ? result
  3569. : LambdaInvoker<typename UnaryLambdaTraits<
  3570. L>::ReturnType>::invoke( lambda, temp );
  3571. }
  3572. template <typename L> struct BoundLambda : BoundValueRefBase {
  3573. L m_lambda;
  3574. static_assert(
  3575. UnaryLambdaTraits<L>::isValid,
  3576. "Supplied lambda must take exactly one argument" );
  3577. explicit BoundLambda( L const& lambda ): m_lambda( lambda ) {}
  3578. auto setValue( std::string const& arg )
  3579. -> ParserResult override {
  3580. return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>(
  3581. m_lambda, arg );
  3582. }
  3583. };
  3584. template <typename L> struct BoundManyLambda : BoundLambda<L> {
  3585. explicit BoundManyLambda( L const& lambda ): BoundLambda<L>( lambda ) {}
  3586. bool isContainer() const override { return true; }
  3587. };
  3588. template <typename L> struct BoundFlagLambda : BoundFlagRefBase {
  3589. L m_lambda;
  3590. static_assert(
  3591. UnaryLambdaTraits<L>::isValid,
  3592. "Supplied lambda must take exactly one argument" );
  3593. static_assert(
  3594. std::is_same<typename UnaryLambdaTraits<L>::ArgType,
  3595. bool>::value,
  3596. "flags must be boolean" );
  3597. explicit BoundFlagLambda( L const& lambda ):
  3598. m_lambda( lambda ) {}
  3599. auto setFlag( bool flag ) -> ParserResult override {
  3600. return LambdaInvoker<typename UnaryLambdaTraits<
  3601. L>::ReturnType>::invoke( m_lambda, flag );
  3602. }
  3603. };
  3604. enum class Optionality { Optional, Required };
  3605. class ParserBase {
  3606. public:
  3607. virtual ~ParserBase() = default;
  3608. virtual auto validate() const -> Result { return Result::ok(); }
  3609. virtual auto parse( std::string const& exeName,
  3610. TokenStream tokens ) const
  3611. -> InternalParseResult = 0;
  3612. virtual size_t cardinality() const;
  3613. InternalParseResult parse( Args const& args ) const;
  3614. };
  3615. template <typename DerivedT>
  3616. class ComposableParserImpl : public ParserBase {
  3617. public:
  3618. template <typename T>
  3619. auto operator|( T const& other ) const -> Parser;
  3620. };
  3621. // Common code and state for Args and Opts
  3622. template <typename DerivedT>
  3623. class ParserRefImpl : public ComposableParserImpl<DerivedT> {
  3624. protected:
  3625. Optionality m_optionality = Optionality::Optional;
  3626. std::shared_ptr<BoundRef> m_ref;
  3627. StringRef m_hint;
  3628. StringRef m_description;
  3629. explicit ParserRefImpl( std::shared_ptr<BoundRef> const& ref ):
  3630. m_ref( ref ) {}
  3631. public:
  3632. template <typename LambdaT>
  3633. ParserRefImpl( accept_many_t,
  3634. LambdaT const& ref,
  3635. StringRef hint ):
  3636. m_ref( std::make_shared<BoundManyLambda<LambdaT>>( ref ) ),
  3637. m_hint( hint ) {}
  3638. template <typename T,
  3639. typename = typename std::enable_if_t<
  3640. !Detail::is_unary_function<T>::value>>
  3641. ParserRefImpl( T& ref, StringRef hint ):
  3642. m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
  3643. m_hint( hint ) {}
  3644. template <typename LambdaT,
  3645. typename = typename std::enable_if_t<
  3646. Detail::is_unary_function<LambdaT>::value>>
  3647. ParserRefImpl( LambdaT const& ref, StringRef hint ):
  3648. m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
  3649. m_hint( hint ) {}
  3650. DerivedT& operator()( StringRef description ) & {
  3651. m_description = description;
  3652. return static_cast<DerivedT&>( *this );
  3653. }
  3654. DerivedT&& operator()( StringRef description ) && {
  3655. m_description = description;
  3656. return static_cast<DerivedT&&>( *this );
  3657. }
  3658. auto optional() -> DerivedT& {
  3659. m_optionality = Optionality::Optional;
  3660. return static_cast<DerivedT&>( *this );
  3661. }
  3662. auto required() -> DerivedT& {
  3663. m_optionality = Optionality::Required;
  3664. return static_cast<DerivedT&>( *this );
  3665. }
  3666. auto isOptional() const -> bool {
  3667. return m_optionality == Optionality::Optional;
  3668. }
  3669. auto cardinality() const -> size_t override {
  3670. if ( m_ref->isContainer() )
  3671. return 0;
  3672. else
  3673. return 1;
  3674. }
  3675. StringRef hint() const { return m_hint; }
  3676. };
  3677. } // namespace detail
  3678. // A parser for arguments
  3679. class Arg : public Detail::ParserRefImpl<Arg> {
  3680. public:
  3681. using ParserRefImpl::ParserRefImpl;
  3682. using ParserBase::parse;
  3683. Detail::InternalParseResult
  3684. parse(std::string const&,
  3685. Detail::TokenStream tokens) const override;
  3686. };
  3687. // A parser for options
  3688. class Opt : public Detail::ParserRefImpl<Opt> {
  3689. protected:
  3690. std::vector<StringRef> m_optNames;
  3691. public:
  3692. template <typename LambdaT>
  3693. explicit Opt(LambdaT const& ref) :
  3694. ParserRefImpl(
  3695. std::make_shared<Detail::BoundFlagLambda<LambdaT>>(ref)) {}
  3696. explicit Opt(bool& ref);
  3697. template <typename LambdaT,
  3698. typename = typename std::enable_if_t<
  3699. Detail::is_unary_function<LambdaT>::value>>
  3700. Opt( LambdaT const& ref, StringRef hint ):
  3701. ParserRefImpl( ref, hint ) {}
  3702. template <typename LambdaT>
  3703. Opt( accept_many_t, LambdaT const& ref, StringRef hint ):
  3704. ParserRefImpl( accept_many, ref, hint ) {}
  3705. template <typename T,
  3706. typename = typename std::enable_if_t<
  3707. !Detail::is_unary_function<T>::value>>
  3708. Opt( T& ref, StringRef hint ):
  3709. ParserRefImpl( ref, hint ) {}
  3710. Opt& operator[]( StringRef optName ) & {
  3711. m_optNames.push_back(optName);
  3712. return *this;
  3713. }
  3714. Opt&& operator[]( StringRef optName ) && {
  3715. m_optNames.push_back( optName );
  3716. return CATCH_MOVE(*this);
  3717. }
  3718. Detail::HelpColumns getHelpColumns() const;
  3719. bool isMatch(StringRef optToken) const;
  3720. using ParserBase::parse;
  3721. Detail::InternalParseResult
  3722. parse(std::string const&,
  3723. Detail::TokenStream tokens) const override;
  3724. Detail::Result validate() const override;
  3725. };
  3726. // Specifies the name of the executable
  3727. class ExeName : public Detail::ComposableParserImpl<ExeName> {
  3728. std::shared_ptr<std::string> m_name;
  3729. std::shared_ptr<Detail::BoundValueRefBase> m_ref;
  3730. public:
  3731. ExeName();
  3732. explicit ExeName(std::string& ref);
  3733. template <typename LambdaT>
  3734. explicit ExeName(LambdaT const& lambda) : ExeName() {
  3735. m_ref = std::make_shared<Detail::BoundLambda<LambdaT>>(lambda);
  3736. }
  3737. // The exe name is not parsed out of the normal tokens, but is
  3738. // handled specially
  3739. Detail::InternalParseResult
  3740. parse(std::string const&,
  3741. Detail::TokenStream tokens) const override;
  3742. std::string const& name() const { return *m_name; }
  3743. Detail::ParserResult set(std::string const& newName);
  3744. };
  3745. // A Combined parser
  3746. class Parser : Detail::ParserBase {
  3747. mutable ExeName m_exeName;
  3748. std::vector<Opt> m_options;
  3749. std::vector<Arg> m_args;
  3750. public:
  3751. auto operator|=(ExeName const& exeName) -> Parser& {
  3752. m_exeName = exeName;
  3753. return *this;
  3754. }
  3755. auto operator|=(Arg const& arg) -> Parser& {
  3756. m_args.push_back(arg);
  3757. return *this;
  3758. }
  3759. friend Parser& operator|=( Parser& p, Opt const& opt ) {
  3760. p.m_options.push_back( opt );
  3761. return p;
  3762. }
  3763. friend Parser& operator|=( Parser& p, Opt&& opt ) {
  3764. p.m_options.push_back( CATCH_MOVE(opt) );
  3765. return p;
  3766. }
  3767. Parser& operator|=(Parser const& other);
  3768. template <typename T>
  3769. friend Parser operator|( Parser const& p, T&& rhs ) {
  3770. Parser temp( p );
  3771. temp |= rhs;
  3772. return temp;
  3773. }
  3774. template <typename T>
  3775. friend Parser operator|( Parser&& p, T&& rhs ) {
  3776. p |= CATCH_FORWARD(rhs);
  3777. return CATCH_MOVE(p);
  3778. }
  3779. std::vector<Detail::HelpColumns> getHelpColumns() const;
  3780. void writeToStream(std::ostream& os) const;
  3781. friend auto operator<<(std::ostream& os, Parser const& parser)
  3782. -> std::ostream& {
  3783. parser.writeToStream(os);
  3784. return os;
  3785. }
  3786. Detail::Result validate() const override;
  3787. using ParserBase::parse;
  3788. Detail::InternalParseResult
  3789. parse(std::string const& exeName,
  3790. Detail::TokenStream tokens) const override;
  3791. };
  3792. /**
  3793. * Wrapper over argc + argv, assumes that the inputs outlive it
  3794. */
  3795. class Args {
  3796. friend Detail::TokenStream;
  3797. StringRef m_exeName;
  3798. std::vector<StringRef> m_args;
  3799. public:
  3800. Args(int argc, char const* const* argv);
  3801. // Helper constructor for testing
  3802. Args(std::initializer_list<StringRef> args);
  3803. StringRef exeName() const { return m_exeName; }
  3804. };
  3805. // Convenience wrapper for option parser that specifies the help option
  3806. struct Help : Opt {
  3807. Help(bool& showHelpFlag);
  3808. };
  3809. // Result type for parser operation
  3810. using Detail::ParserResult;
  3811. namespace Detail {
  3812. template <typename DerivedT>
  3813. template <typename T>
  3814. Parser
  3815. ComposableParserImpl<DerivedT>::operator|(T const& other) const {
  3816. return Parser() | static_cast<DerivedT const&>(*this) | other;
  3817. }
  3818. }
  3819. } // namespace Clara
  3820. } // namespace Catch
  3821. #if defined( __clang__ )
  3822. # pragma clang diagnostic pop
  3823. #endif
  3824. #if defined( __GNUC__ )
  3825. # pragma GCC diagnostic pop
  3826. #endif
  3827. #endif // CATCH_CLARA_HPP_INCLUDED
  3828. namespace Catch {
  3829. struct ConfigData;
  3830. Clara::Parser makeCommandLineParser( ConfigData& config );
  3831. } // end namespace Catch
  3832. #endif // CATCH_COMMANDLINE_HPP_INCLUDED
  3833. namespace Catch {
  3834. class Session : Detail::NonCopyable {
  3835. public:
  3836. Session();
  3837. ~Session();
  3838. void showHelp() const;
  3839. void libIdentify();
  3840. int applyCommandLine( int argc, char const * const * argv );
  3841. #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
  3842. int applyCommandLine( int argc, wchar_t const * const * argv );
  3843. #endif
  3844. void useConfigData( ConfigData const& configData );
  3845. template<typename CharT>
  3846. int run(int argc, CharT const * const argv[]) {
  3847. if (m_startupExceptions)
  3848. return 1;
  3849. int returnCode = applyCommandLine(argc, argv);
  3850. if (returnCode == 0)
  3851. returnCode = run();
  3852. return returnCode;
  3853. }
  3854. int run();
  3855. Clara::Parser const& cli() const;
  3856. void cli( Clara::Parser const& newParser );
  3857. ConfigData& configData();
  3858. Config& config();
  3859. private:
  3860. int runInternal();
  3861. Clara::Parser m_cli;
  3862. ConfigData m_configData;
  3863. Detail::unique_ptr<Config> m_config;
  3864. bool m_startupExceptions = false;
  3865. };
  3866. } // end namespace Catch
  3867. #endif // CATCH_SESSION_HPP_INCLUDED
  3868. #ifndef CATCH_TAG_ALIAS_HPP_INCLUDED
  3869. #define CATCH_TAG_ALIAS_HPP_INCLUDED
  3870. #include <string>
  3871. namespace Catch {
  3872. struct TagAlias {
  3873. TagAlias(std::string const& _tag, SourceLineInfo _lineInfo):
  3874. tag(_tag),
  3875. lineInfo(_lineInfo)
  3876. {}
  3877. std::string tag;
  3878. SourceLineInfo lineInfo;
  3879. };
  3880. } // end namespace Catch
  3881. #endif // CATCH_TAG_ALIAS_HPP_INCLUDED
  3882. #ifndef CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  3883. #define CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  3884. namespace Catch {
  3885. struct RegistrarForTagAliases {
  3886. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  3887. };
  3888. } // end namespace Catch
  3889. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
  3890. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  3891. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  3892. namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
  3893. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  3894. #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  3895. #ifndef CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  3896. #define CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  3897. // We need this suppression to leak, because it took until GCC 10
  3898. // for the front end to handle local suppression via _Pragma properly
  3899. // inside templates (so `TEMPLATE_TEST_CASE` and co).
  3900. // **THIS IS DIFFERENT FOR STANDARD TESTS, WHERE GCC 9 IS SUFFICIENT**
  3901. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 10
  3902. #pragma GCC diagnostic ignored "-Wparentheses"
  3903. #endif
  3904. #ifndef CATCH_TEST_MACROS_HPP_INCLUDED
  3905. #define CATCH_TEST_MACROS_HPP_INCLUDED
  3906. #ifndef CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  3907. #define CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  3908. #ifndef CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  3909. #define CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  3910. #ifndef CATCH_DECOMPOSER_HPP_INCLUDED
  3911. #define CATCH_DECOMPOSER_HPP_INCLUDED
  3912. #ifndef CATCH_COMPARE_TRAITS_HPP_INCLUDED
  3913. #define CATCH_COMPARE_TRAITS_HPP_INCLUDED
  3914. #include <type_traits>
  3915. namespace Catch {
  3916. namespace Detail {
  3917. #if defined( __GNUC__ ) && !defined( __clang__ )
  3918. # pragma GCC diagnostic push
  3919. // GCC likes to complain about comparing bool with 0, in the decltype()
  3920. // that defines the comparable traits below.
  3921. # pragma GCC diagnostic ignored "-Wbool-compare"
  3922. // "ordered comparison of pointer with integer zero" same as above,
  3923. // but it does not have a separate warning flag to suppress
  3924. # pragma GCC diagnostic ignored "-Wextra"
  3925. // Did you know that comparing floats with `0` directly
  3926. // is super-duper dangerous in unevaluated context?
  3927. # pragma GCC diagnostic ignored "-Wfloat-equal"
  3928. #endif
  3929. #if defined( __clang__ )
  3930. # pragma clang diagnostic push
  3931. // Did you know that comparing floats with `0` directly
  3932. // is super-duper dangerous in unevaluated context?
  3933. # pragma clang diagnostic ignored "-Wfloat-equal"
  3934. #endif
  3935. #define CATCH_DEFINE_COMPARABLE_TRAIT( id, op ) \
  3936. template <typename, typename, typename = void> \
  3937. struct is_##id##_comparable : std::false_type {}; \
  3938. template <typename T, typename U> \
  3939. struct is_##id##_comparable< \
  3940. T, \
  3941. U, \
  3942. void_t<decltype( std::declval<T>() op std::declval<U>() )>> \
  3943. : std::true_type {}; \
  3944. template <typename, typename = void> \
  3945. struct is_##id##_0_comparable : std::false_type {}; \
  3946. template <typename T> \
  3947. struct is_##id##_0_comparable<T, \
  3948. void_t<decltype( std::declval<T>() op 0 )>> \
  3949. : std::true_type {};
  3950. // We need all 6 pre-spaceship comparison ops: <, <=, >, >=, ==, !=
  3951. CATCH_DEFINE_COMPARABLE_TRAIT( lt, < )
  3952. CATCH_DEFINE_COMPARABLE_TRAIT( le, <= )
  3953. CATCH_DEFINE_COMPARABLE_TRAIT( gt, > )
  3954. CATCH_DEFINE_COMPARABLE_TRAIT( ge, >= )
  3955. CATCH_DEFINE_COMPARABLE_TRAIT( eq, == )
  3956. CATCH_DEFINE_COMPARABLE_TRAIT( ne, != )
  3957. #undef CATCH_DEFINE_COMPARABLE_TRAIT
  3958. #if defined( __GNUC__ ) && !defined( __clang__ )
  3959. # pragma GCC diagnostic pop
  3960. #endif
  3961. #if defined( __clang__ )
  3962. # pragma clang diagnostic pop
  3963. #endif
  3964. } // namespace Detail
  3965. } // namespace Catch
  3966. #endif // CATCH_COMPARE_TRAITS_HPP_INCLUDED
  3967. #ifndef CATCH_LOGICAL_TRAITS_HPP_INCLUDED
  3968. #define CATCH_LOGICAL_TRAITS_HPP_INCLUDED
  3969. #include <type_traits>
  3970. namespace Catch {
  3971. namespace Detail {
  3972. #if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510
  3973. using std::conjunction;
  3974. using std::disjunction;
  3975. using std::negation;
  3976. #else
  3977. template <class...> struct conjunction : std::true_type {};
  3978. template <class B1> struct conjunction<B1> : B1 {};
  3979. template <class B1, class... Bn>
  3980. struct conjunction<B1, Bn...>
  3981. : std::conditional_t<bool( B1::value ), conjunction<Bn...>, B1> {};
  3982. template <class...> struct disjunction : std::false_type {};
  3983. template <class B1> struct disjunction<B1> : B1 {};
  3984. template <class B1, class... Bn>
  3985. struct disjunction<B1, Bn...>
  3986. : std::conditional_t<bool( B1::value ), B1, disjunction<Bn...>> {};
  3987. template <class B>
  3988. struct negation : std::integral_constant<bool, !bool(B::value)> {};
  3989. #endif
  3990. } // namespace Detail
  3991. } // namespace Catch
  3992. #endif // CATCH_LOGICAL_TRAITS_HPP_INCLUDED
  3993. #include <type_traits>
  3994. #include <iosfwd>
  3995. /** \file
  3996. * Why does decomposing look the way it does:
  3997. *
  3998. * Conceptually, decomposing is simple. We change `REQUIRE( a == b )` into
  3999. * `Decomposer{} <= a == b`, so that `Decomposer{} <= a` is evaluated first,
  4000. * and our custom operator is used for `a == b`, because `a` is transformed
  4001. * into `ExprLhs<T&>` and then into `BinaryExpr<T&, U&>`.
  4002. *
  4003. * In practice, decomposing ends up a mess, because we have to support
  4004. * various fun things.
  4005. *
  4006. * 1) Types that are only comparable with literal 0, and they do this by
  4007. * comparing against a magic type with pointer constructor and deleted
  4008. * other constructors. Example: `REQUIRE((a <=> b) == 0)` in libstdc++
  4009. *
  4010. * 2) Types that are only comparable with literal 0, and they do this by
  4011. * comparing against a magic type with consteval integer constructor.
  4012. * Example: `REQUIRE((a <=> b) == 0)` in current MSVC STL.
  4013. *
  4014. * 3) Types that have no linkage, and so we cannot form a reference to
  4015. * them. Example: some implementations of traits.
  4016. *
  4017. * 4) Starting with C++20, when the compiler sees `a == b`, it also uses
  4018. * `b == a` when constructing the overload set. For us this means that
  4019. * when the compiler handles `ExprLhs<T> == b`, it also tries to resolve
  4020. * the overload set for `b == ExprLhs<T>`.
  4021. *
  4022. * To accomodate these use cases, decomposer ended up rather complex.
  4023. *
  4024. * 1) These types are handled by adding SFINAE overloads to our comparison
  4025. * operators, checking whether `T == U` are comparable with the given
  4026. * operator, and if not, whether T (or U) are comparable with literal 0.
  4027. * If yes, the overload compares T (or U) with 0 literal inline in the
  4028. * definition.
  4029. *
  4030. * Note that for extra correctness, we check that the other type is
  4031. * either an `int` (literal 0 is captured as `int` by templates), or
  4032. * a `long` (some platforms use 0L for `NULL` and we want to support
  4033. * that for pointer comparisons).
  4034. *
  4035. * 2) For these types, `is_foo_comparable<T, int>` is true, but letting
  4036. * them fall into the overload that actually does `T == int` causes
  4037. * compilation error. Handling them requires that the decomposition
  4038. * is `constexpr`, so that P2564R3 applies and the `consteval` from
  4039. * their accompanying magic type is propagated through the `constexpr`
  4040. * call stack.
  4041. *
  4042. * However this is not enough to handle these types automatically,
  4043. * because our default is to capture types by reference, to avoid
  4044. * runtime copies. While these references cannot become dangling,
  4045. * they outlive the constexpr context and thus the default capture
  4046. * path cannot be actually constexpr.
  4047. *
  4048. * The solution is to capture these types by value, by explicitly
  4049. * specializing `Catch::capture_by_value` for them. Catch2 provides
  4050. * specialization for `std::foo_ordering`s, but users can specialize
  4051. * the trait for their own types as well.
  4052. *
  4053. * 3) If a type has no linkage, we also cannot capture it by reference.
  4054. * The solution is once again to capture them by value. We handle
  4055. * the common cases by using `std::is_arithmetic` as the default
  4056. * for `Catch::capture_by_value`, but that is only a some-effort
  4057. * heuristic. But as with 2), users can specialize `capture_by_value`
  4058. * for their own types as needed.
  4059. *
  4060. * 4) To support C++20 and make the SFINAE on our decomposing operators
  4061. * work, the SFINAE has to happen in return type, rather than in
  4062. * a template type. This is due to our use of logical type traits
  4063. * (`conjunction`/`disjunction`/`negation`), that we use to workaround
  4064. * an issue in older (9-) versions of GCC. I still blame C++20 for
  4065. * this, because without the comparison order switching, the logical
  4066. * traits could still be used in template type.
  4067. *
  4068. * There are also other side concerns, e.g. supporting both `REQUIRE(a)`
  4069. * and `REQUIRE(a == b)`, or making `REQUIRE_THAT(a, IsEqual(b))` slot
  4070. * nicely into the same expression handling logic, but these are rather
  4071. * straightforward and add only a bit of complexity (e.g. common base
  4072. * class for decomposed expressions).
  4073. */
  4074. #ifdef _MSC_VER
  4075. #pragma warning(push)
  4076. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  4077. #pragma warning(disable:4018) // more "signed/unsigned mismatch"
  4078. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  4079. #pragma warning(disable:4180) // qualifier applied to function type has no meaning
  4080. #pragma warning(disable:4800) // Forcing result to true or false
  4081. #endif
  4082. #ifdef __clang__
  4083. # pragma clang diagnostic push
  4084. # pragma clang diagnostic ignored "-Wsign-compare"
  4085. # pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  4086. #elif defined __GNUC__
  4087. # pragma GCC diagnostic push
  4088. # pragma GCC diagnostic ignored "-Wsign-compare"
  4089. # pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
  4090. #endif
  4091. #if defined(CATCH_CPP20_OR_GREATER) && __has_include(<compare>)
  4092. # include <compare>
  4093. # if defined( __cpp_lib_three_way_comparison ) && \
  4094. __cpp_lib_three_way_comparison >= 201907L
  4095. # define CATCH_CONFIG_CPP20_COMPARE_OVERLOADS
  4096. # endif
  4097. #endif
  4098. namespace Catch {
  4099. namespace Detail {
  4100. // This was added in C++20, but we require only C++14 for now.
  4101. template <typename T>
  4102. using RemoveCVRef_t = std::remove_cv_t<std::remove_reference_t<T>>;
  4103. }
  4104. // Note: There is nothing that stops us from extending this,
  4105. // e.g. to `std::is_scalar`, but the more encompassing
  4106. // traits are usually also more expensive. For now we
  4107. // keep this as it used to be and it can be changed later.
  4108. template <typename T>
  4109. struct capture_by_value
  4110. : std::integral_constant<bool, std::is_arithmetic<T>{}> {};
  4111. #if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS )
  4112. template <>
  4113. struct capture_by_value<std::strong_ordering> : std::true_type {};
  4114. template <>
  4115. struct capture_by_value<std::weak_ordering> : std::true_type {};
  4116. template <>
  4117. struct capture_by_value<std::partial_ordering> : std::true_type {};
  4118. #endif
  4119. template <typename T>
  4120. struct always_false : std::false_type {};
  4121. class ITransientExpression {
  4122. bool m_isBinaryExpression;
  4123. bool m_result;
  4124. public:
  4125. constexpr auto isBinaryExpression() const -> bool { return m_isBinaryExpression; }
  4126. constexpr auto getResult() const -> bool { return m_result; }
  4127. //! This function **has** to be overriden by the derived class.
  4128. virtual void streamReconstructedExpression( std::ostream& os ) const;
  4129. constexpr ITransientExpression( bool isBinaryExpression, bool result )
  4130. : m_isBinaryExpression( isBinaryExpression ),
  4131. m_result( result )
  4132. {}
  4133. ITransientExpression() = default;
  4134. ITransientExpression(ITransientExpression const&) = default;
  4135. ITransientExpression& operator=(ITransientExpression const&) = default;
  4136. friend std::ostream& operator<<(std::ostream& out, ITransientExpression const& expr) {
  4137. expr.streamReconstructedExpression(out);
  4138. return out;
  4139. }
  4140. protected:
  4141. ~ITransientExpression() = default;
  4142. };
  4143. void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
  4144. template<typename LhsT, typename RhsT>
  4145. class BinaryExpr : public ITransientExpression {
  4146. LhsT m_lhs;
  4147. StringRef m_op;
  4148. RhsT m_rhs;
  4149. void streamReconstructedExpression( std::ostream &os ) const override {
  4150. formatReconstructedExpression
  4151. ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
  4152. }
  4153. public:
  4154. constexpr BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
  4155. : ITransientExpression{ true, comparisonResult },
  4156. m_lhs( lhs ),
  4157. m_op( op ),
  4158. m_rhs( rhs )
  4159. {}
  4160. template<typename T>
  4161. auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4162. static_assert(always_false<T>::value,
  4163. "chained comparisons are not supported inside assertions, "
  4164. "wrap the expression inside parentheses, or decompose it");
  4165. }
  4166. template<typename T>
  4167. auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4168. static_assert(always_false<T>::value,
  4169. "chained comparisons are not supported inside assertions, "
  4170. "wrap the expression inside parentheses, or decompose it");
  4171. }
  4172. template<typename T>
  4173. auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4174. static_assert(always_false<T>::value,
  4175. "chained comparisons are not supported inside assertions, "
  4176. "wrap the expression inside parentheses, or decompose it");
  4177. }
  4178. template<typename T>
  4179. auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4180. static_assert(always_false<T>::value,
  4181. "chained comparisons are not supported inside assertions, "
  4182. "wrap the expression inside parentheses, or decompose it");
  4183. }
  4184. template<typename T>
  4185. auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4186. static_assert(always_false<T>::value,
  4187. "chained comparisons are not supported inside assertions, "
  4188. "wrap the expression inside parentheses, or decompose it");
  4189. }
  4190. template<typename T>
  4191. auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4192. static_assert(always_false<T>::value,
  4193. "chained comparisons are not supported inside assertions, "
  4194. "wrap the expression inside parentheses, or decompose it");
  4195. }
  4196. template<typename T>
  4197. auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4198. static_assert(always_false<T>::value,
  4199. "chained comparisons are not supported inside assertions, "
  4200. "wrap the expression inside parentheses, or decompose it");
  4201. }
  4202. template<typename T>
  4203. auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4204. static_assert(always_false<T>::value,
  4205. "chained comparisons are not supported inside assertions, "
  4206. "wrap the expression inside parentheses, or decompose it");
  4207. }
  4208. };
  4209. template<typename LhsT>
  4210. class UnaryExpr : public ITransientExpression {
  4211. LhsT m_lhs;
  4212. void streamReconstructedExpression( std::ostream &os ) const override {
  4213. os << Catch::Detail::stringify( m_lhs );
  4214. }
  4215. public:
  4216. explicit constexpr UnaryExpr( LhsT lhs )
  4217. : ITransientExpression{ false, static_cast<bool>(lhs) },
  4218. m_lhs( lhs )
  4219. {}
  4220. };
  4221. template<typename LhsT>
  4222. class ExprLhs {
  4223. LhsT m_lhs;
  4224. public:
  4225. explicit constexpr ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
  4226. #define CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( id, op ) \
  4227. template <typename RhsT> \
  4228. constexpr friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
  4229. -> std::enable_if_t< \
  4230. Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
  4231. Detail::negation<capture_by_value< \
  4232. Detail::RemoveCVRef_t<RhsT>>>>::value, \
  4233. BinaryExpr<LhsT, RhsT const&>> { \
  4234. return { \
  4235. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4236. } \
  4237. template <typename RhsT> \
  4238. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4239. -> std::enable_if_t< \
  4240. Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
  4241. capture_by_value<RhsT>>::value, \
  4242. BinaryExpr<LhsT, RhsT>> { \
  4243. return { \
  4244. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4245. } \
  4246. template <typename RhsT> \
  4247. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4248. -> std::enable_if_t< \
  4249. Detail::conjunction< \
  4250. Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
  4251. Detail::is_eq_0_comparable<LhsT>, \
  4252. /* We allow long because we want `ptr op NULL` to be accepted */ \
  4253. Detail::disjunction<std::is_same<RhsT, int>, \
  4254. std::is_same<RhsT, long>>>::value, \
  4255. BinaryExpr<LhsT, RhsT>> { \
  4256. if ( rhs != 0 ) { throw_test_failure_exception(); } \
  4257. return { \
  4258. static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
  4259. } \
  4260. template <typename RhsT> \
  4261. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4262. -> std::enable_if_t< \
  4263. Detail::conjunction< \
  4264. Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
  4265. Detail::is_eq_0_comparable<RhsT>, \
  4266. /* We allow long because we want `ptr op NULL` to be accepted */ \
  4267. Detail::disjunction<std::is_same<LhsT, int>, \
  4268. std::is_same<LhsT, long>>>::value, \
  4269. BinaryExpr<LhsT, RhsT>> { \
  4270. if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \
  4271. return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4272. }
  4273. CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( eq, == )
  4274. CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR( ne, != )
  4275. #undef CATCH_INTERNAL_DEFINE_EXPRESSION_EQUALITY_OPERATOR
  4276. #define CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( id, op ) \
  4277. template <typename RhsT> \
  4278. constexpr friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
  4279. -> std::enable_if_t< \
  4280. Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
  4281. Detail::negation<capture_by_value< \
  4282. Detail::RemoveCVRef_t<RhsT>>>>::value, \
  4283. BinaryExpr<LhsT, RhsT const&>> { \
  4284. return { \
  4285. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4286. } \
  4287. template <typename RhsT> \
  4288. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4289. -> std::enable_if_t< \
  4290. Detail::conjunction<Detail::is_##id##_comparable<LhsT, RhsT>, \
  4291. capture_by_value<RhsT>>::value, \
  4292. BinaryExpr<LhsT, RhsT>> { \
  4293. return { \
  4294. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4295. } \
  4296. template <typename RhsT> \
  4297. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4298. -> std::enable_if_t< \
  4299. Detail::conjunction< \
  4300. Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
  4301. Detail::is_##id##_0_comparable<LhsT>, \
  4302. std::is_same<RhsT, int>>::value, \
  4303. BinaryExpr<LhsT, RhsT>> { \
  4304. if ( rhs != 0 ) { throw_test_failure_exception(); } \
  4305. return { \
  4306. static_cast<bool>( lhs.m_lhs op 0 ), lhs.m_lhs, #op##_sr, rhs }; \
  4307. } \
  4308. template <typename RhsT> \
  4309. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4310. -> std::enable_if_t< \
  4311. Detail::conjunction< \
  4312. Detail::negation<Detail::is_##id##_comparable<LhsT, RhsT>>, \
  4313. Detail::is_##id##_0_comparable<RhsT>, \
  4314. std::is_same<LhsT, int>>::value, \
  4315. BinaryExpr<LhsT, RhsT>> { \
  4316. if ( lhs.m_lhs != 0 ) { throw_test_failure_exception(); } \
  4317. return { static_cast<bool>( 0 op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4318. }
  4319. CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( lt, < )
  4320. CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( le, <= )
  4321. CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( gt, > )
  4322. CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR( ge, >= )
  4323. #undef CATCH_INTERNAL_DEFINE_EXPRESSION_COMPARISON_OPERATOR
  4324. #define CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR( op ) \
  4325. template <typename RhsT> \
  4326. constexpr friend auto operator op( ExprLhs&& lhs, RhsT&& rhs ) \
  4327. -> std::enable_if_t< \
  4328. !capture_by_value<Detail::RemoveCVRef_t<RhsT>>::value, \
  4329. BinaryExpr<LhsT, RhsT const&>> { \
  4330. return { \
  4331. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4332. } \
  4333. template <typename RhsT> \
  4334. constexpr friend auto operator op( ExprLhs&& lhs, RhsT rhs ) \
  4335. -> std::enable_if_t<capture_by_value<RhsT>::value, \
  4336. BinaryExpr<LhsT, RhsT>> { \
  4337. return { \
  4338. static_cast<bool>( lhs.m_lhs op rhs ), lhs.m_lhs, #op##_sr, rhs }; \
  4339. }
  4340. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(|)
  4341. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(&)
  4342. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(^)
  4343. #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR
  4344. template<typename RhsT>
  4345. friend auto operator && ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
  4346. static_assert(always_false<RhsT>::value,
  4347. "operator&& is not supported inside assertions, "
  4348. "wrap the expression inside parentheses, or decompose it");
  4349. }
  4350. template<typename RhsT>
  4351. friend auto operator || ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
  4352. static_assert(always_false<RhsT>::value,
  4353. "operator|| is not supported inside assertions, "
  4354. "wrap the expression inside parentheses, or decompose it");
  4355. }
  4356. constexpr auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
  4357. return UnaryExpr<LhsT>{ m_lhs };
  4358. }
  4359. };
  4360. struct Decomposer {
  4361. template <typename T,
  4362. std::enable_if_t<!capture_by_value<Detail::RemoveCVRef_t<T>>::value,
  4363. int> = 0>
  4364. constexpr friend auto operator <= ( Decomposer &&, T && lhs ) -> ExprLhs<T const&> {
  4365. return ExprLhs<const T&>{ lhs };
  4366. }
  4367. template <typename T,
  4368. std::enable_if_t<capture_by_value<T>::value, int> = 0>
  4369. constexpr friend auto operator <= ( Decomposer &&, T value ) -> ExprLhs<T> {
  4370. return ExprLhs<T>{ value };
  4371. }
  4372. };
  4373. } // end namespace Catch
  4374. #ifdef _MSC_VER
  4375. #pragma warning(pop)
  4376. #endif
  4377. #ifdef __clang__
  4378. # pragma clang diagnostic pop
  4379. #elif defined __GNUC__
  4380. # pragma GCC diagnostic pop
  4381. #endif
  4382. #endif // CATCH_DECOMPOSER_HPP_INCLUDED
  4383. #include <string>
  4384. namespace Catch {
  4385. struct AssertionReaction {
  4386. bool shouldDebugBreak = false;
  4387. bool shouldThrow = false;
  4388. bool shouldSkip = false;
  4389. };
  4390. class AssertionHandler {
  4391. AssertionInfo m_assertionInfo;
  4392. AssertionReaction m_reaction;
  4393. bool m_completed = false;
  4394. IResultCapture& m_resultCapture;
  4395. public:
  4396. AssertionHandler
  4397. ( StringRef macroName,
  4398. SourceLineInfo const& lineInfo,
  4399. StringRef capturedExpression,
  4400. ResultDisposition::Flags resultDisposition );
  4401. ~AssertionHandler() {
  4402. if ( !m_completed ) {
  4403. m_resultCapture.handleIncomplete( m_assertionInfo );
  4404. }
  4405. }
  4406. template<typename T>
  4407. void handleExpr( ExprLhs<T> const& expr ) {
  4408. handleExpr( expr.makeUnaryExpr() );
  4409. }
  4410. void handleExpr( ITransientExpression const& expr );
  4411. void handleMessage(ResultWas::OfType resultType, StringRef message);
  4412. void handleExceptionThrownAsExpected();
  4413. void handleUnexpectedExceptionNotThrown();
  4414. void handleExceptionNotThrownAsExpected();
  4415. void handleThrowingCallSkipped();
  4416. void handleUnexpectedInflightException();
  4417. void complete();
  4418. // query
  4419. auto allowThrows() const -> bool;
  4420. };
  4421. void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str );
  4422. } // namespace Catch
  4423. #endif // CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  4424. #ifndef CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED
  4425. #define CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED
  4426. #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
  4427. #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__##_catch_sr
  4428. #else
  4429. #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"_catch_sr
  4430. #endif
  4431. #endif // CATCH_PREPROCESSOR_INTERNAL_STRINGIFY_HPP_INCLUDED
  4432. // We need this suppression to leak, because it took until GCC 10
  4433. // for the front end to handle local suppression via _Pragma properly
  4434. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ <= 9
  4435. #pragma GCC diagnostic ignored "-Wparentheses"
  4436. #endif
  4437. #if !defined(CATCH_CONFIG_DISABLE)
  4438. #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  4439. ///////////////////////////////////////////////////////////////////////////////
  4440. // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
  4441. // macros.
  4442. #define INTERNAL_CATCH_TRY
  4443. #define INTERNAL_CATCH_CATCH( capturer )
  4444. #else // CATCH_CONFIG_FAST_COMPILE
  4445. #define INTERNAL_CATCH_TRY try
  4446. #define INTERNAL_CATCH_CATCH( handler ) catch(...) { (handler).handleUnexpectedInflightException(); }
  4447. #endif
  4448. #define INTERNAL_CATCH_REACT( handler ) handler.complete();
  4449. ///////////////////////////////////////////////////////////////////////////////
  4450. #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
  4451. do { /* NOLINT(bugprone-infinite-loop) */ \
  4452. /* The expression should not be evaluated, but warnings should hopefully be checked */ \
  4453. CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
  4454. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
  4455. INTERNAL_CATCH_TRY { \
  4456. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4457. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  4458. catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); /* NOLINT(bugprone-chained-comparison) */ \
  4459. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4460. } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
  4461. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4462. } while( (void)0, (false) && static_cast<const bool&>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
  4463. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  4464. ///////////////////////////////////////////////////////////////////////////////
  4465. #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
  4466. INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
  4467. if( Catch::getResultCapture().lastAssertionPassed() )
  4468. ///////////////////////////////////////////////////////////////////////////////
  4469. #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
  4470. INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
  4471. if( !Catch::getResultCapture().lastAssertionPassed() )
  4472. ///////////////////////////////////////////////////////////////////////////////
  4473. #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
  4474. do { \
  4475. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
  4476. try { \
  4477. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4478. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4479. static_cast<void>(__VA_ARGS__); \
  4480. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4481. catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
  4482. } \
  4483. catch( ... ) { \
  4484. catchAssertionHandler.handleUnexpectedInflightException(); \
  4485. } \
  4486. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4487. } while( false )
  4488. ///////////////////////////////////////////////////////////////////////////////
  4489. #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
  4490. do { \
  4491. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
  4492. if( catchAssertionHandler.allowThrows() ) \
  4493. try { \
  4494. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4495. CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
  4496. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4497. static_cast<void>(__VA_ARGS__); \
  4498. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4499. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4500. } \
  4501. catch( ... ) { \
  4502. catchAssertionHandler.handleExceptionThrownAsExpected(); \
  4503. } \
  4504. else \
  4505. catchAssertionHandler.handleThrowingCallSkipped(); \
  4506. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4507. } while( false )
  4508. ///////////////////////////////////////////////////////////////////////////////
  4509. #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
  4510. do { \
  4511. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
  4512. if( catchAssertionHandler.allowThrows() ) \
  4513. try { \
  4514. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4515. CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
  4516. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4517. static_cast<void>(expr); \
  4518. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4519. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4520. } \
  4521. catch( exceptionType const& ) { \
  4522. catchAssertionHandler.handleExceptionThrownAsExpected(); \
  4523. } \
  4524. catch( ... ) { \
  4525. catchAssertionHandler.handleUnexpectedInflightException(); \
  4526. } \
  4527. else \
  4528. catchAssertionHandler.handleThrowingCallSkipped(); \
  4529. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4530. } while( false )
  4531. ///////////////////////////////////////////////////////////////////////////////
  4532. // Although this is matcher-based, it can be used with just a string
  4533. #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
  4534. do { \
  4535. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  4536. if( catchAssertionHandler.allowThrows() ) \
  4537. try { \
  4538. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4539. CATCH_INTERNAL_SUPPRESS_UNUSED_RESULT \
  4540. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4541. static_cast<void>(__VA_ARGS__); \
  4542. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4543. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4544. } \
  4545. catch( ... ) { \
  4546. Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher ); \
  4547. } \
  4548. else \
  4549. catchAssertionHandler.handleThrowingCallSkipped(); \
  4550. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4551. } while( false )
  4552. #endif // CATCH_CONFIG_DISABLE
  4553. #endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  4554. #ifndef CATCH_SECTION_HPP_INCLUDED
  4555. #define CATCH_SECTION_HPP_INCLUDED
  4556. /** \file
  4557. * Wrapper for the STATIC_ANALYSIS_SUPPORT configuration option
  4558. *
  4559. * Some of Catch2's macros can be defined differently to work better with
  4560. * static analysis tools, like clang-tidy or coverity.
  4561. * Currently the main use case is to show that `SECTION`s are executed
  4562. * exclusively, and not all in one run of a `TEST_CASE`.
  4563. */
  4564. #ifndef CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED
  4565. #define CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED
  4566. #if defined(__clang_analyzer__) || defined(__COVERITY__)
  4567. #define CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT
  4568. #endif
  4569. #if defined( CATCH_INTERNAL_CONFIG_STATIC_ANALYSIS_SUPPORT ) && \
  4570. !defined( CATCH_CONFIG_NO_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT ) && \
  4571. !defined( CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT )
  4572. # define CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT
  4573. #endif
  4574. #endif // CATCH_CONFIG_STATIC_ANALYSIS_SUPPORT_HPP_INCLUDED
  4575. #ifndef CATCH_TIMER_HPP_INCLUDED
  4576. #define CATCH_TIMER_HPP_INCLUDED
  4577. #include <cstdint>
  4578. namespace Catch {
  4579. class Timer {
  4580. uint64_t m_nanoseconds = 0;
  4581. public:
  4582. void start();
  4583. auto getElapsedNanoseconds() const -> uint64_t;
  4584. auto getElapsedMicroseconds() const -> uint64_t;
  4585. auto getElapsedMilliseconds() const -> unsigned int;
  4586. auto getElapsedSeconds() const -> double;
  4587. };
  4588. } // namespace Catch
  4589. #endif // CATCH_TIMER_HPP_INCLUDED
  4590. namespace Catch {
  4591. class Section : Detail::NonCopyable {
  4592. public:
  4593. Section( SectionInfo&& info );
  4594. Section( SourceLineInfo const& _lineInfo,
  4595. StringRef _name,
  4596. const char* const = nullptr );
  4597. ~Section();
  4598. // This indicates whether the section should be executed or not
  4599. explicit operator bool() const;
  4600. private:
  4601. SectionInfo m_info;
  4602. Counts m_assertions;
  4603. bool m_sectionIncluded;
  4604. Timer m_timer;
  4605. };
  4606. } // end namespace Catch
  4607. #if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT)
  4608. # define INTERNAL_CATCH_SECTION( ... ) \
  4609. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4610. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4611. if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \
  4612. catch_internal_Section ) = \
  4613. Catch::Section( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
  4614. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4615. # define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
  4616. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4617. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4618. if ( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( \
  4619. catch_internal_Section ) = \
  4620. Catch::SectionInfo( \
  4621. CATCH_INTERNAL_LINEINFO, \
  4622. ( Catch::ReusableStringStream() << __VA_ARGS__ ) \
  4623. .str() ) ) \
  4624. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4625. #else
  4626. // These section definitions imply that at most one section at one level
  4627. // will be intered (because only one section's __LINE__ can be equal to
  4628. // the dummy `catchInternalSectionHint` variable from `TEST_CASE`).
  4629. namespace Catch {
  4630. namespace Detail {
  4631. // Intentionally without linkage, as it should only be used as a dummy
  4632. // symbol for static analysis.
  4633. // The arguments are used as a dummy for checking warnings in the passed
  4634. // expressions.
  4635. int GetNewSectionHint( StringRef, const char* const = nullptr );
  4636. } // namespace Detail
  4637. } // namespace Catch
  4638. # define INTERNAL_CATCH_SECTION( ... ) \
  4639. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4640. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4641. CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
  4642. if ( [[maybe_unused]] const int catchInternalPreviousSectionHint = \
  4643. catchInternalSectionHint, \
  4644. catchInternalSectionHint = \
  4645. Catch::Detail::GetNewSectionHint(__VA_ARGS__); \
  4646. catchInternalPreviousSectionHint == __LINE__ ) \
  4647. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4648. # define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
  4649. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4650. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4651. CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
  4652. if ( [[maybe_unused]] const int catchInternalPreviousSectionHint = \
  4653. catchInternalSectionHint, \
  4654. catchInternalSectionHint = Catch::Detail::GetNewSectionHint( \
  4655. ( Catch::ReusableStringStream() << __VA_ARGS__ ).str()); \
  4656. catchInternalPreviousSectionHint == __LINE__ ) \
  4657. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4658. #endif
  4659. #endif // CATCH_SECTION_HPP_INCLUDED
  4660. #ifndef CATCH_TEST_REGISTRY_HPP_INCLUDED
  4661. #define CATCH_TEST_REGISTRY_HPP_INCLUDED
  4662. #ifndef CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED
  4663. #define CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED
  4664. namespace Catch {
  4665. class ITestInvoker {
  4666. public:
  4667. virtual void invoke() const = 0;
  4668. virtual ~ITestInvoker(); // = default
  4669. };
  4670. } // namespace Catch
  4671. #endif // CATCH_INTERFACES_TEST_INVOKER_HPP_INCLUDED
  4672. #ifndef CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4673. #define CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4674. #define INTERNAL_CATCH_EXPAND1( param ) INTERNAL_CATCH_EXPAND2( param )
  4675. #define INTERNAL_CATCH_EXPAND2( ... ) INTERNAL_CATCH_NO##__VA_ARGS__
  4676. #define INTERNAL_CATCH_DEF( ... ) INTERNAL_CATCH_DEF __VA_ARGS__
  4677. #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
  4678. #define INTERNAL_CATCH_REMOVE_PARENS( ... ) \
  4679. INTERNAL_CATCH_EXPAND1( INTERNAL_CATCH_DEF __VA_ARGS__ )
  4680. #endif // CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4681. // GCC 5 and older do not properly handle disabling unused-variable warning
  4682. // with a _Pragma. This means that we have to leak the suppression to the
  4683. // user code as well :-(
  4684. #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
  4685. #pragma GCC diagnostic ignored "-Wunused-variable"
  4686. #endif
  4687. namespace Catch {
  4688. template<typename C>
  4689. class TestInvokerAsMethod : public ITestInvoker {
  4690. void (C::*m_testAsMethod)();
  4691. public:
  4692. TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
  4693. void invoke() const override {
  4694. C obj;
  4695. (obj.*m_testAsMethod)();
  4696. }
  4697. };
  4698. Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
  4699. template<typename C>
  4700. Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
  4701. return Detail::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
  4702. }
  4703. struct NameAndTags {
  4704. constexpr NameAndTags( StringRef name_ = StringRef(),
  4705. StringRef tags_ = StringRef() ) noexcept:
  4706. name( name_ ), tags( tags_ ) {}
  4707. StringRef name;
  4708. StringRef tags;
  4709. };
  4710. struct AutoReg : Detail::NonCopyable {
  4711. AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
  4712. };
  4713. } // end namespace Catch
  4714. #if defined(CATCH_CONFIG_DISABLE)
  4715. #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
  4716. static inline void TestName()
  4717. #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
  4718. namespace{ \
  4719. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
  4720. void test(); \
  4721. }; \
  4722. } \
  4723. void TestName::test()
  4724. #endif
  4725. #if !defined(CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT)
  4726. ///////////////////////////////////////////////////////////////////////////////
  4727. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  4728. static void TestName(); \
  4729. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4730. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4731. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4732. namespace{ const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
  4733. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4734. static void TestName()
  4735. #define INTERNAL_CATCH_TESTCASE( ... ) \
  4736. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__ )
  4737. #else // ^^ !CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT | vv CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT
  4738. // Dummy registrator for the dumy test case macros
  4739. namespace Catch {
  4740. namespace Detail {
  4741. struct DummyUse {
  4742. DummyUse( void ( * )( int ), Catch::NameAndTags const& );
  4743. };
  4744. } // namespace Detail
  4745. } // namespace Catch
  4746. // Note that both the presence of the argument and its exact name are
  4747. // necessary for the section support.
  4748. // We provide a shadowed variable so that a `SECTION` inside non-`TEST_CASE`
  4749. // tests can compile. The redefined `TEST_CASE` shadows this with param.
  4750. static int catchInternalSectionHint = 0;
  4751. # define INTERNAL_CATCH_TESTCASE2( fname, ... ) \
  4752. static void fname( int ); \
  4753. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4754. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4755. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4756. static const Catch::Detail::DummyUse INTERNAL_CATCH_UNIQUE_NAME( \
  4757. dummyUser )( &(fname), Catch::NameAndTags{ __VA_ARGS__ } ); \
  4758. CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS \
  4759. static void fname( [[maybe_unused]] int catchInternalSectionHint ) \
  4760. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4761. # define INTERNAL_CATCH_TESTCASE( ... ) \
  4762. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( dummyFunction ), __VA_ARGS__ )
  4763. #endif // CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT
  4764. ///////////////////////////////////////////////////////////////////////////////
  4765. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  4766. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4767. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4768. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4769. namespace{ \
  4770. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
  4771. void test(); \
  4772. }; \
  4773. const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \
  4774. Catch::makeTestInvoker( &TestName::test ), \
  4775. CATCH_INTERNAL_LINEINFO, \
  4776. #ClassName##_catch_sr, \
  4777. Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
  4778. } \
  4779. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4780. void TestName::test()
  4781. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  4782. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ )
  4783. ///////////////////////////////////////////////////////////////////////////////
  4784. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  4785. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4786. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4787. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4788. namespace { \
  4789. const Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( \
  4790. Catch::makeTestInvoker( &QualifiedMethod ), \
  4791. CATCH_INTERNAL_LINEINFO, \
  4792. "&" #QualifiedMethod##_catch_sr, \
  4793. Catch::NameAndTags{ __VA_ARGS__ } ); \
  4794. } /* NOLINT */ \
  4795. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4796. ///////////////////////////////////////////////////////////////////////////////
  4797. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  4798. do { \
  4799. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4800. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4801. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4802. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
  4803. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4804. } while(false)
  4805. #endif // CATCH_TEST_REGISTRY_HPP_INCLUDED
  4806. // All of our user-facing macros support configuration toggle, that
  4807. // forces them to be defined prefixed with CATCH_. We also like to
  4808. // support another toggle that can minimize (disable) their implementation.
  4809. // Given this, we have 4 different configuration options below
  4810. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  4811. #define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4812. #define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4813. #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4814. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  4815. #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4816. #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4817. #define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4818. #define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4819. #define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4820. #define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4821. #define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4822. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  4823. #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4824. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  4825. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  4826. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  4827. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  4828. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  4829. #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
  4830. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4831. #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4832. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4833. #define CATCH_SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4834. #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
  4835. #define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
  4836. #define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
  4837. #define CATCH_STATIC_CHECK( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
  4838. #define CATCH_STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
  4839. #else
  4840. #define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
  4841. #define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
  4842. #define CATCH_STATIC_CHECK( ... ) CATCH_CHECK( __VA_ARGS__ )
  4843. #define CATCH_STATIC_CHECK_FALSE( ... ) CATCH_CHECK_FALSE( __VA_ARGS__ )
  4844. #endif
  4845. // "BDD-style" convenience wrappers
  4846. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  4847. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  4848. #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
  4849. #define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
  4850. #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
  4851. #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
  4852. #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
  4853. #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
  4854. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, implemented | vv prefixed, disabled
  4855. #define CATCH_REQUIRE( ... ) (void)(0)
  4856. #define CATCH_REQUIRE_FALSE( ... ) (void)(0)
  4857. #define CATCH_REQUIRE_THROWS( ... ) (void)(0)
  4858. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
  4859. #define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
  4860. #define CATCH_CHECK( ... ) (void)(0)
  4861. #define CATCH_CHECK_FALSE( ... ) (void)(0)
  4862. #define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
  4863. #define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
  4864. #define CATCH_CHECK_NOFAIL( ... ) (void)(0)
  4865. #define CATCH_CHECK_THROWS( ... ) (void)(0)
  4866. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
  4867. #define CATCH_CHECK_NOTHROW( ... ) (void)(0)
  4868. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4869. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4870. #define CATCH_METHOD_AS_TEST_CASE( method, ... )
  4871. #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
  4872. #define CATCH_SECTION( ... )
  4873. #define CATCH_DYNAMIC_SECTION( ... )
  4874. #define CATCH_FAIL( ... ) (void)(0)
  4875. #define CATCH_FAIL_CHECK( ... ) (void)(0)
  4876. #define CATCH_SUCCEED( ... ) (void)(0)
  4877. #define CATCH_SKIP( ... ) (void)(0)
  4878. #define CATCH_STATIC_REQUIRE( ... ) (void)(0)
  4879. #define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
  4880. #define CATCH_STATIC_CHECK( ... ) (void)(0)
  4881. #define CATCH_STATIC_CHECK_FALSE( ... ) (void)(0)
  4882. // "BDD-style" convenience wrappers
  4883. #define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4884. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
  4885. #define CATCH_GIVEN( desc )
  4886. #define CATCH_AND_GIVEN( desc )
  4887. #define CATCH_WHEN( desc )
  4888. #define CATCH_AND_WHEN( desc )
  4889. #define CATCH_THEN( desc )
  4890. #define CATCH_AND_THEN( desc )
  4891. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, disabled | vv unprefixed, implemented
  4892. #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4893. #define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4894. #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4895. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  4896. #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4897. #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4898. #define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4899. #define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4900. #define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4901. #define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4902. #define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4903. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  4904. #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4905. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  4906. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  4907. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  4908. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  4909. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  4910. #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
  4911. #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4912. #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4913. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4914. #define SKIP( ... ) INTERNAL_CATCH_MSG( "SKIP", Catch::ResultWas::ExplicitSkip, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4915. #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
  4916. #define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
  4917. #define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
  4918. #define STATIC_CHECK( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
  4919. #define STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
  4920. #else
  4921. #define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
  4922. #define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
  4923. #define STATIC_CHECK( ... ) CHECK( __VA_ARGS__ )
  4924. #define STATIC_CHECK_FALSE( ... ) CHECK_FALSE( __VA_ARGS__ )
  4925. #endif
  4926. // "BDD-style" convenience wrappers
  4927. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  4928. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  4929. #define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
  4930. #define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
  4931. #define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
  4932. #define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
  4933. #define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
  4934. #define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
  4935. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ unprefixed, implemented | vv unprefixed, disabled
  4936. #define REQUIRE( ... ) (void)(0)
  4937. #define REQUIRE_FALSE( ... ) (void)(0)
  4938. #define REQUIRE_THROWS( ... ) (void)(0)
  4939. #define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
  4940. #define REQUIRE_NOTHROW( ... ) (void)(0)
  4941. #define CHECK( ... ) (void)(0)
  4942. #define CHECK_FALSE( ... ) (void)(0)
  4943. #define CHECKED_IF( ... ) if (__VA_ARGS__)
  4944. #define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
  4945. #define CHECK_NOFAIL( ... ) (void)(0)
  4946. #define CHECK_THROWS( ... ) (void)(0)
  4947. #define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
  4948. #define CHECK_NOTHROW( ... ) (void)(0)
  4949. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__)
  4950. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4951. #define METHOD_AS_TEST_CASE( method, ... )
  4952. #define REGISTER_TEST_CASE( Function, ... ) (void)(0)
  4953. #define SECTION( ... )
  4954. #define DYNAMIC_SECTION( ... )
  4955. #define FAIL( ... ) (void)(0)
  4956. #define FAIL_CHECK( ... ) (void)(0)
  4957. #define SUCCEED( ... ) (void)(0)
  4958. #define SKIP( ... ) (void)(0)
  4959. #define STATIC_REQUIRE( ... ) (void)(0)
  4960. #define STATIC_REQUIRE_FALSE( ... ) (void)(0)
  4961. #define STATIC_CHECK( ... ) (void)(0)
  4962. #define STATIC_CHECK_FALSE( ... ) (void)(0)
  4963. // "BDD-style" convenience wrappers
  4964. #define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ) )
  4965. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
  4966. #define GIVEN( desc )
  4967. #define AND_GIVEN( desc )
  4968. #define WHEN( desc )
  4969. #define AND_WHEN( desc )
  4970. #define THEN( desc )
  4971. #define AND_THEN( desc )
  4972. #endif // ^^ unprefixed, disabled
  4973. // end of user facing macros
  4974. #endif // CATCH_TEST_MACROS_HPP_INCLUDED
  4975. #ifndef CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  4976. #define CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  4977. #ifndef CATCH_PREPROCESSOR_HPP_INCLUDED
  4978. #define CATCH_PREPROCESSOR_HPP_INCLUDED
  4979. #if defined(__GNUC__)
  4980. // We need to silence "empty __VA_ARGS__ warning", and using just _Pragma does not work
  4981. #pragma GCC system_header
  4982. #endif
  4983. #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__
  4984. #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__)))
  4985. #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__)))
  4986. #define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__)))
  4987. #define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__)))
  4988. #define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__)))
  4989. #ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  4990. #define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__
  4991. // MSVC needs more evaluations
  4992. #define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__)))
  4993. #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__))
  4994. #else
  4995. #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__)
  4996. #endif
  4997. #define CATCH_REC_END(...)
  4998. #define CATCH_REC_OUT
  4999. #define CATCH_EMPTY()
  5000. #define CATCH_DEFER(id) id CATCH_EMPTY()
  5001. #define CATCH_REC_GET_END2() 0, CATCH_REC_END
  5002. #define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2
  5003. #define CATCH_REC_GET_END(...) CATCH_REC_GET_END1
  5004. #define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT
  5005. #define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0)
  5006. #define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next)
  5007. #define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
  5008. #define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ )
  5009. #define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
  5010. #define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
  5011. #define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ )
  5012. #define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ )
  5013. // Applies the function macro `f` to each of the remaining parameters, inserts commas between the results,
  5014. // and passes userdata as the first parameter to each invocation,
  5015. // e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c)
  5016. #define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
  5017. #define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
  5018. #define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__)
  5019. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5020. #define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__
  5021. #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param))
  5022. #else
  5023. // MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
  5024. #define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__)
  5025. #define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__
  5026. #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1)
  5027. #endif
  5028. #define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__
  5029. #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name)
  5030. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5031. #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())
  5032. #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))
  5033. #else
  5034. #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()))
  5035. #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
  5036. #endif
  5037. #define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\
  5038. CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__)
  5039. #define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0)
  5040. #define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1)
  5041. #define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2)
  5042. #define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3)
  5043. #define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4)
  5044. #define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5)
  5045. #define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _3, _4, _5, _6)
  5046. #define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7)
  5047. #define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8)
  5048. #define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9)
  5049. #define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10)
  5050. #define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
  5051. #define INTERNAL_CATCH_TYPE_GEN\
  5052. template<typename...> struct TypeList {};\
  5053. template<typename...Ts>\
  5054. constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\
  5055. template<template<typename...> class...> struct TemplateTypeList{};\
  5056. template<template<typename...> class...Cs>\
  5057. constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\
  5058. template<typename...>\
  5059. struct append;\
  5060. template<typename...>\
  5061. struct rewrap;\
  5062. template<template<typename...> class, typename...>\
  5063. struct create;\
  5064. template<template<typename...> class, typename>\
  5065. struct convert;\
  5066. \
  5067. template<typename T> \
  5068. struct append<T> { using type = T; };\
  5069. template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\
  5070. struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\
  5071. template< template<typename...> class L1, typename...E1, typename...Rest>\
  5072. struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\
  5073. \
  5074. template< template<typename...> class Container, template<typename...> class List, typename...elems>\
  5075. struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\
  5076. template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\
  5077. struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\
  5078. \
  5079. template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\
  5080. struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\
  5081. template<template <typename...> class Final, template <typename...> class List, typename...Ts>\
  5082. struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; };
  5083. #define INTERNAL_CATCH_NTTP_1(signature, ...)\
  5084. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\
  5085. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5086. constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
  5087. template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\
  5088. template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\
  5089. constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \
  5090. \
  5091. template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5092. struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\
  5093. template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
  5094. struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\
  5095. template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\
  5096. struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; };
  5097. #define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
  5098. #define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\
  5099. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5100. static void TestName()
  5101. #define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\
  5102. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5103. static void TestName()
  5104. #define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName)
  5105. #define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\
  5106. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5107. static void TestName()
  5108. #define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\
  5109. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5110. static void TestName()
  5111. #define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\
  5112. template<typename Type>\
  5113. void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\
  5114. {\
  5115. Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
  5116. }
  5117. #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\
  5118. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5119. void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
  5120. {\
  5121. Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
  5122. }
  5123. #define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
  5124. template<typename Type>\
  5125. void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
  5126. {\
  5127. Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
  5128. }
  5129. #define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
  5130. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5131. void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
  5132. {\
  5133. Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
  5134. }
  5135. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName)
  5136. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\
  5137. template<typename TestType> \
  5138. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \
  5139. void test();\
  5140. }
  5141. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\
  5142. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
  5143. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \
  5144. void test();\
  5145. }
  5146. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName)
  5147. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\
  5148. template<typename TestType> \
  5149. void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test()
  5150. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\
  5151. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
  5152. void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test()
  5153. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5154. #define INTERNAL_CATCH_NTTP_0
  5155. #define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1(__VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_1( __VA_ARGS__),INTERNAL_CATCH_NTTP_1( __VA_ARGS__), INTERNAL_CATCH_NTTP_0)
  5156. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__)
  5157. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__)
  5158. #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__)
  5159. #define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__)
  5160. #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__)
  5161. #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__)
  5162. #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__)
  5163. #else
  5164. #define INTERNAL_CATCH_NTTP_0(signature)
  5165. #define INTERNAL_CATCH_NTTP_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_1,INTERNAL_CATCH_NTTP_1, INTERNAL_CATCH_NTTP_0)( __VA_ARGS__))
  5166. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1, INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0)(TestName, __VA_ARGS__))
  5167. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X,INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1, INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0)(TestName, ClassName, __VA_ARGS__))
  5168. #define INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD, INTERNAL_CATCH_NTTP_REGISTER_METHOD0, INTERNAL_CATCH_NTTP_REGISTER_METHOD0)(TestName, __VA_ARGS__))
  5169. #define INTERNAL_CATCH_NTTP_REG_GEN(TestFunc, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER, INTERNAL_CATCH_NTTP_REGISTER0, INTERNAL_CATCH_NTTP_REGISTER0)(TestFunc, __VA_ARGS__))
  5170. #define INTERNAL_CATCH_DEFINE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DEFINE_SIG_TEST1, INTERNAL_CATCH_DEFINE_SIG_TEST0)(TestName, __VA_ARGS__))
  5171. #define INTERNAL_CATCH_DECLARE_SIG_TEST(TestName, ...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL( "dummy", __VA_ARGS__, INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DEFINE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X,INTERNAL_CATCH_DECLARE_SIG_TEST_X, INTERNAL_CATCH_DECLARE_SIG_TEST1, INTERNAL_CATCH_DECLARE_SIG_TEST0)(TestName, __VA_ARGS__))
  5172. #define INTERNAL_CATCH_REMOVE_PARENS_GEN(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_VA_NARGS_IMPL(__VA_ARGS__, INTERNAL_CATCH_REMOVE_PARENS_11_ARG,INTERNAL_CATCH_REMOVE_PARENS_10_ARG,INTERNAL_CATCH_REMOVE_PARENS_9_ARG,INTERNAL_CATCH_REMOVE_PARENS_8_ARG,INTERNAL_CATCH_REMOVE_PARENS_7_ARG,INTERNAL_CATCH_REMOVE_PARENS_6_ARG,INTERNAL_CATCH_REMOVE_PARENS_5_ARG,INTERNAL_CATCH_REMOVE_PARENS_4_ARG,INTERNAL_CATCH_REMOVE_PARENS_3_ARG,INTERNAL_CATCH_REMOVE_PARENS_2_ARG,INTERNAL_CATCH_REMOVE_PARENS_1_ARG)(__VA_ARGS__))
  5173. #endif
  5174. #endif // CATCH_PREPROCESSOR_HPP_INCLUDED
  5175. // GCC 5 and older do not properly handle disabling unused-variable warning
  5176. // with a _Pragma. This means that we have to leak the suppression to the
  5177. // user code as well :-(
  5178. #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
  5179. #pragma GCC diagnostic ignored "-Wunused-variable"
  5180. #endif
  5181. #if defined(CATCH_CONFIG_DISABLE)
  5182. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \
  5183. INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5184. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
  5185. namespace{ \
  5186. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
  5187. INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5188. } \
  5189. } \
  5190. INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5191. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5192. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
  5193. INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ )
  5194. #else
  5195. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
  5196. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
  5197. #endif
  5198. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5199. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
  5200. INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ )
  5201. #else
  5202. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
  5203. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) )
  5204. #endif
  5205. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5206. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
  5207. INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
  5208. #else
  5209. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
  5210. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
  5211. #endif
  5212. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5213. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
  5214. INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
  5215. #else
  5216. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
  5217. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
  5218. #endif
  5219. #endif
  5220. ///////////////////////////////////////////////////////////////////////////////
  5221. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
  5222. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5223. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5224. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5225. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5226. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5227. CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \
  5228. INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5229. namespace {\
  5230. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
  5231. INTERNAL_CATCH_TYPE_GEN\
  5232. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5233. INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5234. template<typename...Types> \
  5235. struct TestName{\
  5236. TestName(){\
  5237. size_t index = 0; \
  5238. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)}; /* NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,hicpp-avoid-c-arrays) */\
  5239. using expander = size_t[]; /* NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,hicpp-avoid-c-arrays) */\
  5240. (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
  5241. }\
  5242. };\
  5243. static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5244. TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
  5245. return 0;\
  5246. }();\
  5247. }\
  5248. }\
  5249. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5250. INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5251. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5252. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
  5253. INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ )
  5254. #else
  5255. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
  5256. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename TestType, __VA_ARGS__ ) )
  5257. #endif
  5258. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5259. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
  5260. INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ )
  5261. #else
  5262. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
  5263. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) )
  5264. #endif
  5265. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
  5266. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5267. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5268. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5269. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5270. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5271. CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \
  5272. template<typename TestType> static void TestFuncName(); \
  5273. namespace {\
  5274. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
  5275. INTERNAL_CATCH_TYPE_GEN \
  5276. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \
  5277. template<typename... Types> \
  5278. struct TestName { \
  5279. void reg_tests() { \
  5280. size_t index = 0; \
  5281. using expander = size_t[]; \
  5282. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
  5283. constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
  5284. constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
  5285. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFuncName<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */\
  5286. } \
  5287. }; \
  5288. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
  5289. using TestInit = typename create<TestName, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type; \
  5290. TestInit t; \
  5291. t.reg_tests(); \
  5292. return 0; \
  5293. }(); \
  5294. } \
  5295. } \
  5296. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5297. template<typename TestType> \
  5298. static void TestFuncName()
  5299. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5300. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
  5301. INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename T,__VA_ARGS__)
  5302. #else
  5303. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
  5304. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, typename T, __VA_ARGS__ ) )
  5305. #endif
  5306. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5307. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
  5308. INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__)
  5309. #else
  5310. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
  5311. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, Signature, __VA_ARGS__ ) )
  5312. #endif
  5313. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
  5314. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5315. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5316. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5317. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5318. CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \
  5319. template<typename TestType> static void TestFunc(); \
  5320. namespace {\
  5321. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
  5322. INTERNAL_CATCH_TYPE_GEN\
  5323. template<typename... Types> \
  5324. struct TestName { \
  5325. void reg_tests() { \
  5326. size_t index = 0; \
  5327. using expander = size_t[]; \
  5328. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
  5329. } \
  5330. };\
  5331. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
  5332. using TestInit = typename convert<TestName, TmplList>::type; \
  5333. TestInit t; \
  5334. t.reg_tests(); \
  5335. return 0; \
  5336. }(); \
  5337. }}\
  5338. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5339. template<typename TestType> \
  5340. static void TestFunc()
  5341. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \
  5342. INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), Name, Tags, TmplList )
  5343. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
  5344. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5345. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5346. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5347. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5348. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5349. namespace {\
  5350. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
  5351. INTERNAL_CATCH_TYPE_GEN\
  5352. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5353. INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5354. INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5355. template<typename...Types> \
  5356. struct TestNameClass{\
  5357. TestNameClass(){\
  5358. size_t index = 0; \
  5359. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
  5360. using expander = size_t[];\
  5361. (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
  5362. }\
  5363. };\
  5364. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5365. TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
  5366. return 0;\
  5367. }();\
  5368. }\
  5369. }\
  5370. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5371. INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5372. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5373. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
  5374. INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ )
  5375. #else
  5376. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
  5377. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, typename T, __VA_ARGS__ ) )
  5378. #endif
  5379. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5380. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
  5381. INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ )
  5382. #else
  5383. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
  5384. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_CLASS_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ) , ClassName, Name, Tags, Signature, __VA_ARGS__ ) )
  5385. #endif
  5386. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
  5387. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5388. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5389. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5390. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5391. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5392. template<typename TestType> \
  5393. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
  5394. void test();\
  5395. };\
  5396. namespace {\
  5397. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\
  5398. INTERNAL_CATCH_TYPE_GEN \
  5399. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5400. template<typename...Types>\
  5401. struct TestNameClass{\
  5402. void reg_tests(){\
  5403. std::size_t index = 0;\
  5404. using expander = std::size_t[];\
  5405. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
  5406. constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
  5407. constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
  5408. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index / num_types]) + '<' + std::string(types_list[index % num_types]) + '>', Tags } ), index++)... };/* NOLINT */ \
  5409. }\
  5410. };\
  5411. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5412. using TestInit = typename create<TestNameClass, decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS(TmplTypes)>()), TypeList<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(INTERNAL_CATCH_REMOVE_PARENS(TypesList))>>::type;\
  5413. TestInit t;\
  5414. t.reg_tests();\
  5415. return 0;\
  5416. }(); \
  5417. }\
  5418. }\
  5419. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5420. template<typename TestType> \
  5421. void TestName<TestType>::test()
  5422. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5423. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
  5424. INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, typename T, __VA_ARGS__ )
  5425. #else
  5426. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
  5427. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, typename T,__VA_ARGS__ ) )
  5428. #endif
  5429. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5430. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
  5431. INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, Signature, __VA_ARGS__ )
  5432. #else
  5433. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
  5434. INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, Signature,__VA_ARGS__ ) )
  5435. #endif
  5436. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
  5437. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5438. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5439. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5440. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5441. CATCH_INTERNAL_SUPPRESS_COMMA_WARNINGS \
  5442. template<typename TestType> \
  5443. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
  5444. void test();\
  5445. };\
  5446. namespace {\
  5447. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
  5448. INTERNAL_CATCH_TYPE_GEN\
  5449. template<typename...Types>\
  5450. struct TestNameClass{\
  5451. void reg_tests(){\
  5452. size_t index = 0;\
  5453. using expander = size_t[];\
  5454. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName##_catch_sr, Catch::NameAndTags{ Name " - " INTERNAL_CATCH_STRINGIZE(TmplList) " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
  5455. }\
  5456. };\
  5457. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5458. using TestInit = typename convert<TestNameClass, TmplList>::type;\
  5459. TestInit t;\
  5460. t.reg_tests();\
  5461. return 0;\
  5462. }(); \
  5463. }}\
  5464. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5465. template<typename TestType> \
  5466. void TestName<TestType>::test()
  5467. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \
  5468. INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEMPLATE_TEST_ ), ClassName, Name, Tags, TmplList )
  5469. #endif // CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  5470. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  5471. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5472. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5473. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
  5474. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5475. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5476. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
  5477. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
  5478. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5479. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5480. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
  5481. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5482. #else
  5483. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
  5484. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
  5485. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5486. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5487. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
  5488. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
  5489. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5490. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5491. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
  5492. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5493. #endif
  5494. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  5495. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5496. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
  5497. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
  5498. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
  5499. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
  5500. #else
  5501. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
  5502. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
  5503. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5504. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5505. #endif
  5506. // When disabled, these can be shared between proper preprocessor and MSVC preprocessor
  5507. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5508. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5509. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5510. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5511. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE(__VA_ARGS__)
  5512. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5513. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  5514. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5515. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5516. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
  5517. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5518. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5519. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
  5520. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
  5521. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5522. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5523. #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
  5524. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5525. #else
  5526. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
  5527. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
  5528. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5529. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5530. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
  5531. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
  5532. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5533. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5534. #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
  5535. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5536. #endif
  5537. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  5538. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5539. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
  5540. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
  5541. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
  5542. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
  5543. #else
  5544. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
  5545. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
  5546. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5547. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5548. #endif
  5549. // When disabled, these can be shared between proper preprocessor and MSVC preprocessor
  5550. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5551. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5552. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5553. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5554. #define TEMPLATE_LIST_TEST_CASE( ... ) TEMPLATE_TEST_CASE(__VA_ARGS__)
  5555. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5556. #endif // end of user facing macro declarations
  5557. #endif // CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  5558. #ifndef CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5559. #define CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5560. #include <cstdint>
  5561. #include <string>
  5562. #include <vector>
  5563. #ifdef __clang__
  5564. #pragma clang diagnostic push
  5565. #pragma clang diagnostic ignored "-Wpadded"
  5566. #endif
  5567. namespace Catch {
  5568. /**
  5569. * A **view** of a tag string that provides case insensitive comparisons
  5570. *
  5571. * Note that in Catch2 internals, the square brackets around tags are
  5572. * not a part of tag's representation, so e.g. "[cool-tag]" is represented
  5573. * as "cool-tag" internally.
  5574. */
  5575. struct Tag {
  5576. constexpr Tag(StringRef original_):
  5577. original(original_)
  5578. {}
  5579. StringRef original;
  5580. friend bool operator< ( Tag const& lhs, Tag const& rhs );
  5581. friend bool operator==( Tag const& lhs, Tag const& rhs );
  5582. };
  5583. class ITestInvoker;
  5584. struct NameAndTags;
  5585. enum class TestCaseProperties : uint8_t {
  5586. None = 0,
  5587. IsHidden = 1 << 1,
  5588. ShouldFail = 1 << 2,
  5589. MayFail = 1 << 3,
  5590. Throws = 1 << 4,
  5591. NonPortable = 1 << 5,
  5592. Benchmark = 1 << 6
  5593. };
  5594. /**
  5595. * Various metadata about the test case.
  5596. *
  5597. * A test case is uniquely identified by its (class)name and tags
  5598. * combination, with source location being ignored, and other properties
  5599. * being determined from tags.
  5600. *
  5601. * Tags are kept sorted.
  5602. */
  5603. struct TestCaseInfo : Detail::NonCopyable {
  5604. TestCaseInfo(StringRef _className,
  5605. NameAndTags const& _nameAndTags,
  5606. SourceLineInfo const& _lineInfo);
  5607. bool isHidden() const;
  5608. bool throws() const;
  5609. bool okToFail() const;
  5610. bool expectedToFail() const;
  5611. // Adds the tag(s) with test's filename (for the -# flag)
  5612. void addFilenameTag();
  5613. //! Orders by name, classname and tags
  5614. friend bool operator<( TestCaseInfo const& lhs,
  5615. TestCaseInfo const& rhs );
  5616. std::string tagsAsString() const;
  5617. std::string name;
  5618. StringRef className;
  5619. private:
  5620. std::string backingTags;
  5621. // Internally we copy tags to the backing storage and then add
  5622. // refs to this storage to the tags vector.
  5623. void internalAppendTag(StringRef tagString);
  5624. public:
  5625. std::vector<Tag> tags;
  5626. SourceLineInfo lineInfo;
  5627. TestCaseProperties properties = TestCaseProperties::None;
  5628. };
  5629. /**
  5630. * Wrapper over the test case information and the test case invoker
  5631. *
  5632. * Does not own either, and is specifically made to be cheap
  5633. * to copy around.
  5634. */
  5635. class TestCaseHandle {
  5636. TestCaseInfo* m_info;
  5637. ITestInvoker* m_invoker;
  5638. public:
  5639. TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) :
  5640. m_info(info), m_invoker(invoker) {}
  5641. void invoke() const {
  5642. m_invoker->invoke();
  5643. }
  5644. TestCaseInfo const& getTestCaseInfo() const;
  5645. };
  5646. Detail::unique_ptr<TestCaseInfo>
  5647. makeTestCaseInfo( StringRef className,
  5648. NameAndTags const& nameAndTags,
  5649. SourceLineInfo const& lineInfo );
  5650. }
  5651. #ifdef __clang__
  5652. #pragma clang diagnostic pop
  5653. #endif
  5654. #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5655. #ifndef CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5656. #define CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5657. #ifndef CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5658. #define CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5659. #include <string>
  5660. #include <vector>
  5661. namespace Catch {
  5662. using exceptionTranslateFunction = std::string(*)();
  5663. class IExceptionTranslator;
  5664. using ExceptionTranslators = std::vector<Detail::unique_ptr<IExceptionTranslator const>>;
  5665. class IExceptionTranslator {
  5666. public:
  5667. virtual ~IExceptionTranslator(); // = default
  5668. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  5669. };
  5670. class IExceptionTranslatorRegistry {
  5671. public:
  5672. virtual ~IExceptionTranslatorRegistry(); // = default
  5673. virtual std::string translateActiveException() const = 0;
  5674. };
  5675. } // namespace Catch
  5676. #endif // CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5677. #include <exception>
  5678. namespace Catch {
  5679. namespace Detail {
  5680. void registerTranslatorImpl(
  5681. Detail::unique_ptr<IExceptionTranslator>&& translator );
  5682. }
  5683. class ExceptionTranslatorRegistrar {
  5684. template<typename T>
  5685. class ExceptionTranslator : public IExceptionTranslator {
  5686. public:
  5687. ExceptionTranslator( std::string(*translateFunction)( T const& ) )
  5688. : m_translateFunction( translateFunction )
  5689. {}
  5690. std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
  5691. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  5692. try {
  5693. if( it == itEnd )
  5694. std::rethrow_exception(std::current_exception());
  5695. else
  5696. return (*it)->translate( it+1, itEnd );
  5697. }
  5698. catch( T const& ex ) {
  5699. return m_translateFunction( ex );
  5700. }
  5701. #else
  5702. return "You should never get here!";
  5703. #endif
  5704. }
  5705. protected:
  5706. std::string(*m_translateFunction)( T const& );
  5707. };
  5708. public:
  5709. template<typename T>
  5710. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) {
  5711. Detail::registerTranslatorImpl(
  5712. Detail::make_unique<ExceptionTranslator<T>>(
  5713. translateFunction ) );
  5714. }
  5715. };
  5716. } // namespace Catch
  5717. ///////////////////////////////////////////////////////////////////////////////
  5718. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  5719. static std::string translatorName( signature ); \
  5720. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5721. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5722. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
  5723. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5724. static std::string translatorName( signature )
  5725. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  5726. #if defined(CATCH_CONFIG_DISABLE)
  5727. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
  5728. static std::string translatorName( signature )
  5729. #endif
  5730. // This macro is always prefixed
  5731. #if !defined(CATCH_CONFIG_DISABLE)
  5732. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  5733. #else
  5734. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  5735. #endif
  5736. #endif // CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5737. #ifndef CATCH_VERSION_HPP_INCLUDED
  5738. #define CATCH_VERSION_HPP_INCLUDED
  5739. #include <iosfwd>
  5740. namespace Catch {
  5741. // Versioning information
  5742. struct Version {
  5743. Version( Version const& ) = delete;
  5744. Version& operator=( Version const& ) = delete;
  5745. Version( unsigned int _majorVersion,
  5746. unsigned int _minorVersion,
  5747. unsigned int _patchNumber,
  5748. char const * const _branchName,
  5749. unsigned int _buildNumber );
  5750. unsigned int const majorVersion;
  5751. unsigned int const minorVersion;
  5752. unsigned int const patchNumber;
  5753. // buildNumber is only used if branchName is not null
  5754. char const * const branchName;
  5755. unsigned int const buildNumber;
  5756. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5757. };
  5758. Version const& libraryVersion();
  5759. }
  5760. #endif // CATCH_VERSION_HPP_INCLUDED
  5761. #ifndef CATCH_VERSION_MACROS_HPP_INCLUDED
  5762. #define CATCH_VERSION_MACROS_HPP_INCLUDED
  5763. #define CATCH_VERSION_MAJOR 3
  5764. #define CATCH_VERSION_MINOR 6
  5765. #define CATCH_VERSION_PATCH 0
  5766. #endif // CATCH_VERSION_MACROS_HPP_INCLUDED
  5767. /** \file
  5768. * This is a convenience header for Catch2's Generator support. It includes
  5769. * **all** of Catch2 headers related to generators.
  5770. *
  5771. * Generally the Catch2 users should use specific includes they need,
  5772. * but this header can be used instead for ease-of-experimentation, or
  5773. * just plain convenience, at the cost of (significantly) increased
  5774. * compilation times.
  5775. *
  5776. * When a new header is added to either the `generators` folder,
  5777. * or to the corresponding internal subfolder, it should be added here.
  5778. */
  5779. #ifndef CATCH_GENERATORS_ALL_HPP_INCLUDED
  5780. #define CATCH_GENERATORS_ALL_HPP_INCLUDED
  5781. #ifndef CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5782. #define CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5783. #include <exception>
  5784. namespace Catch {
  5785. // Exception type to be thrown when a Generator runs into an error,
  5786. // e.g. it cannot initialize the first return value based on
  5787. // runtime information
  5788. class GeneratorException : public std::exception {
  5789. const char* const m_msg = "";
  5790. public:
  5791. GeneratorException(const char* msg):
  5792. m_msg(msg)
  5793. {}
  5794. const char* what() const noexcept override final;
  5795. };
  5796. } // end namespace Catch
  5797. #endif // CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5798. #ifndef CATCH_GENERATORS_HPP_INCLUDED
  5799. #define CATCH_GENERATORS_HPP_INCLUDED
  5800. #ifndef CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5801. #define CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5802. #include <string>
  5803. namespace Catch {
  5804. namespace Generators {
  5805. class GeneratorUntypedBase {
  5806. // Caches result from `toStringImpl`, assume that when it is an
  5807. // empty string, the cache is invalidated.
  5808. mutable std::string m_stringReprCache;
  5809. // Counts based on `next` returning true
  5810. std::size_t m_currentElementIndex = 0;
  5811. /**
  5812. * Attempts to move the generator to the next element
  5813. *
  5814. * Returns true iff the move succeeded (and a valid element
  5815. * can be retrieved).
  5816. */
  5817. virtual bool next() = 0;
  5818. //! Customization point for `currentElementAsString`
  5819. virtual std::string stringifyImpl() const = 0;
  5820. public:
  5821. GeneratorUntypedBase() = default;
  5822. // Generation of copy ops is deprecated (and Clang will complain)
  5823. // if there is a user destructor defined
  5824. GeneratorUntypedBase(GeneratorUntypedBase const&) = default;
  5825. GeneratorUntypedBase& operator=(GeneratorUntypedBase const&) = default;
  5826. virtual ~GeneratorUntypedBase(); // = default;
  5827. /**
  5828. * Attempts to move the generator to the next element
  5829. *
  5830. * Serves as a non-virtual interface to `next`, so that the
  5831. * top level interface can provide sanity checking and shared
  5832. * features.
  5833. *
  5834. * As with `next`, returns true iff the move succeeded and
  5835. * the generator has new valid element to provide.
  5836. */
  5837. bool countedNext();
  5838. std::size_t currentElementIndex() const { return m_currentElementIndex; }
  5839. /**
  5840. * Returns generator's current element as user-friendly string.
  5841. *
  5842. * By default returns string equivalent to calling
  5843. * `Catch::Detail::stringify` on the current element, but generators
  5844. * can customize their implementation as needed.
  5845. *
  5846. * Not thread-safe due to internal caching.
  5847. *
  5848. * The returned ref is valid only until the generator instance
  5849. * is destructed, or it moves onto the next element, whichever
  5850. * comes first.
  5851. */
  5852. StringRef currentElementAsString() const;
  5853. };
  5854. using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;
  5855. } // namespace Generators
  5856. class IGeneratorTracker {
  5857. public:
  5858. virtual ~IGeneratorTracker(); // = default;
  5859. virtual auto hasGenerator() const -> bool = 0;
  5860. virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0;
  5861. virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0;
  5862. };
  5863. } // namespace Catch
  5864. #endif // CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5865. #include <vector>
  5866. #include <tuple>
  5867. namespace Catch {
  5868. namespace Generators {
  5869. namespace Detail {
  5870. //! Throws GeneratorException with the provided message
  5871. [[noreturn]]
  5872. void throw_generator_exception(char const * msg);
  5873. } // end namespace detail
  5874. template<typename T>
  5875. class IGenerator : public GeneratorUntypedBase {
  5876. std::string stringifyImpl() const override {
  5877. return ::Catch::Detail::stringify( get() );
  5878. }
  5879. public:
  5880. // Returns the current element of the generator
  5881. //
  5882. // \Precondition The generator is either freshly constructed,
  5883. // or the last call to `next()` returned true
  5884. virtual T const& get() const = 0;
  5885. using type = T;
  5886. };
  5887. template <typename T>
  5888. using GeneratorPtr = Catch::Detail::unique_ptr<IGenerator<T>>;
  5889. template <typename T>
  5890. class GeneratorWrapper final {
  5891. GeneratorPtr<T> m_generator;
  5892. public:
  5893. //! Takes ownership of the passed pointer.
  5894. GeneratorWrapper(IGenerator<T>* generator):
  5895. m_generator(generator) {}
  5896. GeneratorWrapper(GeneratorPtr<T> generator):
  5897. m_generator(CATCH_MOVE(generator)) {}
  5898. T const& get() const {
  5899. return m_generator->get();
  5900. }
  5901. bool next() {
  5902. return m_generator->countedNext();
  5903. }
  5904. };
  5905. template<typename T>
  5906. class SingleValueGenerator final : public IGenerator<T> {
  5907. T m_value;
  5908. public:
  5909. SingleValueGenerator(T const& value) :
  5910. m_value(value)
  5911. {}
  5912. SingleValueGenerator(T&& value):
  5913. m_value(CATCH_MOVE(value))
  5914. {}
  5915. T const& get() const override {
  5916. return m_value;
  5917. }
  5918. bool next() override {
  5919. return false;
  5920. }
  5921. };
  5922. template<typename T>
  5923. class FixedValuesGenerator final : public IGenerator<T> {
  5924. static_assert(!std::is_same<T, bool>::value,
  5925. "FixedValuesGenerator does not support bools because of std::vector<bool>"
  5926. "specialization, use SingleValue Generator instead.");
  5927. std::vector<T> m_values;
  5928. size_t m_idx = 0;
  5929. public:
  5930. FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {}
  5931. T const& get() const override {
  5932. return m_values[m_idx];
  5933. }
  5934. bool next() override {
  5935. ++m_idx;
  5936. return m_idx < m_values.size();
  5937. }
  5938. };
  5939. template <typename T, typename DecayedT = std::decay_t<T>>
  5940. GeneratorWrapper<DecayedT> value( T&& value ) {
  5941. return GeneratorWrapper<DecayedT>(
  5942. Catch::Detail::make_unique<SingleValueGenerator<DecayedT>>(
  5943. CATCH_FORWARD( value ) ) );
  5944. }
  5945. template <typename T>
  5946. GeneratorWrapper<T> values(std::initializer_list<T> values) {
  5947. return GeneratorWrapper<T>(Catch::Detail::make_unique<FixedValuesGenerator<T>>(values));
  5948. }
  5949. template<typename T>
  5950. class Generators : public IGenerator<T> {
  5951. std::vector<GeneratorWrapper<T>> m_generators;
  5952. size_t m_current = 0;
  5953. void add_generator( GeneratorWrapper<T>&& generator ) {
  5954. m_generators.emplace_back( CATCH_MOVE( generator ) );
  5955. }
  5956. void add_generator( T const& val ) {
  5957. m_generators.emplace_back( value( val ) );
  5958. }
  5959. void add_generator( T&& val ) {
  5960. m_generators.emplace_back( value( CATCH_MOVE( val ) ) );
  5961. }
  5962. template <typename U>
  5963. std::enable_if_t<!std::is_same<std::decay_t<U>, T>::value>
  5964. add_generator( U&& val ) {
  5965. add_generator( T( CATCH_FORWARD( val ) ) );
  5966. }
  5967. template <typename U> void add_generators( U&& valueOrGenerator ) {
  5968. add_generator( CATCH_FORWARD( valueOrGenerator ) );
  5969. }
  5970. template <typename U, typename... Gs>
  5971. void add_generators( U&& valueOrGenerator, Gs&&... moreGenerators ) {
  5972. add_generator( CATCH_FORWARD( valueOrGenerator ) );
  5973. add_generators( CATCH_FORWARD( moreGenerators )... );
  5974. }
  5975. public:
  5976. template <typename... Gs>
  5977. Generators(Gs &&... moreGenerators) {
  5978. m_generators.reserve(sizeof...(Gs));
  5979. add_generators(CATCH_FORWARD(moreGenerators)...);
  5980. }
  5981. T const& get() const override {
  5982. return m_generators[m_current].get();
  5983. }
  5984. bool next() override {
  5985. if (m_current >= m_generators.size()) {
  5986. return false;
  5987. }
  5988. const bool current_status = m_generators[m_current].next();
  5989. if (!current_status) {
  5990. ++m_current;
  5991. }
  5992. return m_current < m_generators.size();
  5993. }
  5994. };
  5995. template <typename... Ts>
  5996. GeneratorWrapper<std::tuple<std::decay_t<Ts>...>>
  5997. table( std::initializer_list<std::tuple<std::decay_t<Ts>...>> tuples ) {
  5998. return values<std::tuple<Ts...>>( tuples );
  5999. }
  6000. // Tag type to signal that a generator sequence should convert arguments to a specific type
  6001. template <typename T>
  6002. struct as {};
  6003. template<typename T, typename... Gs>
  6004. auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> {
  6005. return Generators<T>(CATCH_MOVE(generator), CATCH_FORWARD(moreGenerators)...);
  6006. }
  6007. template<typename T>
  6008. auto makeGenerators( GeneratorWrapper<T>&& generator ) -> Generators<T> {
  6009. return Generators<T>(CATCH_MOVE(generator));
  6010. }
  6011. template<typename T, typename... Gs>
  6012. auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<std::decay_t<T>> {
  6013. return makeGenerators( value( CATCH_FORWARD( val ) ), CATCH_FORWARD( moreGenerators )... );
  6014. }
  6015. template<typename T, typename U, typename... Gs>
  6016. auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> {
  6017. return makeGenerators( value( T( CATCH_FORWARD( val ) ) ), CATCH_FORWARD( moreGenerators )... );
  6018. }
  6019. IGeneratorTracker* acquireGeneratorTracker( StringRef generatorName,
  6020. SourceLineInfo const& lineInfo );
  6021. IGeneratorTracker* createGeneratorTracker( StringRef generatorName,
  6022. SourceLineInfo lineInfo,
  6023. GeneratorBasePtr&& generator );
  6024. template<typename L>
  6025. auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> typename decltype(generatorExpression())::type {
  6026. using UnderlyingType = typename decltype(generatorExpression())::type;
  6027. IGeneratorTracker* tracker = acquireGeneratorTracker( generatorName, lineInfo );
  6028. // Creation of tracker is delayed after generator creation, so
  6029. // that constructing generator can fail without breaking everything.
  6030. if (!tracker) {
  6031. tracker = createGeneratorTracker(
  6032. generatorName,
  6033. lineInfo,
  6034. Catch::Detail::make_unique<Generators<UnderlyingType>>(
  6035. generatorExpression() ) );
  6036. }
  6037. auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker->getGenerator() );
  6038. return generator.get();
  6039. }
  6040. } // namespace Generators
  6041. } // namespace Catch
  6042. #define CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL( ... ) #__VA_ARGS__##_catch_sr
  6043. #define CATCH_INTERNAL_GENERATOR_STRINGIZE(...) CATCH_INTERNAL_GENERATOR_STRINGIZE_IMPL(__VA_ARGS__)
  6044. #define GENERATE( ... ) \
  6045. Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  6046. CATCH_INTERNAL_LINEINFO, \
  6047. [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  6048. #define GENERATE_COPY( ... ) \
  6049. Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  6050. CATCH_INTERNAL_LINEINFO, \
  6051. [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  6052. #define GENERATE_REF( ... ) \
  6053. Catch::Generators::generate( CATCH_INTERNAL_GENERATOR_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  6054. CATCH_INTERNAL_LINEINFO, \
  6055. [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  6056. #endif // CATCH_GENERATORS_HPP_INCLUDED
  6057. #ifndef CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  6058. #define CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  6059. #include <cassert>
  6060. namespace Catch {
  6061. namespace Generators {
  6062. template <typename T>
  6063. class TakeGenerator final : public IGenerator<T> {
  6064. GeneratorWrapper<T> m_generator;
  6065. size_t m_returned = 0;
  6066. size_t m_target;
  6067. public:
  6068. TakeGenerator(size_t target, GeneratorWrapper<T>&& generator):
  6069. m_generator(CATCH_MOVE(generator)),
  6070. m_target(target)
  6071. {
  6072. assert(target != 0 && "Empty generators are not allowed");
  6073. }
  6074. T const& get() const override {
  6075. return m_generator.get();
  6076. }
  6077. bool next() override {
  6078. ++m_returned;
  6079. if (m_returned >= m_target) {
  6080. return false;
  6081. }
  6082. const auto success = m_generator.next();
  6083. // If the underlying generator does not contain enough values
  6084. // then we cut short as well
  6085. if (!success) {
  6086. m_returned = m_target;
  6087. }
  6088. return success;
  6089. }
  6090. };
  6091. template <typename T>
  6092. GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) {
  6093. return GeneratorWrapper<T>(Catch::Detail::make_unique<TakeGenerator<T>>(target, CATCH_MOVE(generator)));
  6094. }
  6095. template <typename T, typename Predicate>
  6096. class FilterGenerator final : public IGenerator<T> {
  6097. GeneratorWrapper<T> m_generator;
  6098. Predicate m_predicate;
  6099. public:
  6100. template <typename P = Predicate>
  6101. FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
  6102. m_generator(CATCH_MOVE(generator)),
  6103. m_predicate(CATCH_FORWARD(pred))
  6104. {
  6105. if (!m_predicate(m_generator.get())) {
  6106. // It might happen that there are no values that pass the
  6107. // filter. In that case we throw an exception.
  6108. auto has_initial_value = next();
  6109. if (!has_initial_value) {
  6110. Detail::throw_generator_exception("No valid value found in filtered generator");
  6111. }
  6112. }
  6113. }
  6114. T const& get() const override {
  6115. return m_generator.get();
  6116. }
  6117. bool next() override {
  6118. bool success = m_generator.next();
  6119. if (!success) {
  6120. return false;
  6121. }
  6122. while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
  6123. return success;
  6124. }
  6125. };
  6126. template <typename T, typename Predicate>
  6127. GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {
  6128. return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, Predicate>>(CATCH_FORWARD(pred), CATCH_MOVE(generator)));
  6129. }
  6130. template <typename T>
  6131. class RepeatGenerator final : public IGenerator<T> {
  6132. static_assert(!std::is_same<T, bool>::value,
  6133. "RepeatGenerator currently does not support bools"
  6134. "because of std::vector<bool> specialization");
  6135. GeneratorWrapper<T> m_generator;
  6136. mutable std::vector<T> m_returned;
  6137. size_t m_target_repeats;
  6138. size_t m_current_repeat = 0;
  6139. size_t m_repeat_index = 0;
  6140. public:
  6141. RepeatGenerator(size_t repeats, GeneratorWrapper<T>&& generator):
  6142. m_generator(CATCH_MOVE(generator)),
  6143. m_target_repeats(repeats)
  6144. {
  6145. assert(m_target_repeats > 0 && "Repeat generator must repeat at least once");
  6146. }
  6147. T const& get() const override {
  6148. if (m_current_repeat == 0) {
  6149. m_returned.push_back(m_generator.get());
  6150. return m_returned.back();
  6151. }
  6152. return m_returned[m_repeat_index];
  6153. }
  6154. bool next() override {
  6155. // There are 2 basic cases:
  6156. // 1) We are still reading the generator
  6157. // 2) We are reading our own cache
  6158. // In the first case, we need to poke the underlying generator.
  6159. // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache
  6160. if (m_current_repeat == 0) {
  6161. const auto success = m_generator.next();
  6162. if (!success) {
  6163. ++m_current_repeat;
  6164. }
  6165. return m_current_repeat < m_target_repeats;
  6166. }
  6167. // In the second case, we need to move indices forward and check that we haven't run up against the end
  6168. ++m_repeat_index;
  6169. if (m_repeat_index == m_returned.size()) {
  6170. m_repeat_index = 0;
  6171. ++m_current_repeat;
  6172. }
  6173. return m_current_repeat < m_target_repeats;
  6174. }
  6175. };
  6176. template <typename T>
  6177. GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) {
  6178. return GeneratorWrapper<T>(Catch::Detail::make_unique<RepeatGenerator<T>>(repeats, CATCH_MOVE(generator)));
  6179. }
  6180. template <typename T, typename U, typename Func>
  6181. class MapGenerator final : public IGenerator<T> {
  6182. // TBD: provide static assert for mapping function, for friendly error message
  6183. GeneratorWrapper<U> m_generator;
  6184. Func m_function;
  6185. // To avoid returning dangling reference, we have to save the values
  6186. T m_cache;
  6187. public:
  6188. template <typename F2 = Func>
  6189. MapGenerator(F2&& function, GeneratorWrapper<U>&& generator) :
  6190. m_generator(CATCH_MOVE(generator)),
  6191. m_function(CATCH_FORWARD(function)),
  6192. m_cache(m_function(m_generator.get()))
  6193. {}
  6194. T const& get() const override {
  6195. return m_cache;
  6196. }
  6197. bool next() override {
  6198. const auto success = m_generator.next();
  6199. if (success) {
  6200. m_cache = m_function(m_generator.get());
  6201. }
  6202. return success;
  6203. }
  6204. };
  6205. template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
  6206. GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
  6207. return GeneratorWrapper<T>(
  6208. Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator))
  6209. );
  6210. }
  6211. template <typename T, typename U, typename Func>
  6212. GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
  6213. return GeneratorWrapper<T>(
  6214. Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator))
  6215. );
  6216. }
  6217. template <typename T>
  6218. class ChunkGenerator final : public IGenerator<std::vector<T>> {
  6219. std::vector<T> m_chunk;
  6220. size_t m_chunk_size;
  6221. GeneratorWrapper<T> m_generator;
  6222. bool m_used_up = false;
  6223. public:
  6224. ChunkGenerator(size_t size, GeneratorWrapper<T> generator) :
  6225. m_chunk_size(size), m_generator(CATCH_MOVE(generator))
  6226. {
  6227. m_chunk.reserve(m_chunk_size);
  6228. if (m_chunk_size != 0) {
  6229. m_chunk.push_back(m_generator.get());
  6230. for (size_t i = 1; i < m_chunk_size; ++i) {
  6231. if (!m_generator.next()) {
  6232. Detail::throw_generator_exception("Not enough values to initialize the first chunk");
  6233. }
  6234. m_chunk.push_back(m_generator.get());
  6235. }
  6236. }
  6237. }
  6238. std::vector<T> const& get() const override {
  6239. return m_chunk;
  6240. }
  6241. bool next() override {
  6242. m_chunk.clear();
  6243. for (size_t idx = 0; idx < m_chunk_size; ++idx) {
  6244. if (!m_generator.next()) {
  6245. return false;
  6246. }
  6247. m_chunk.push_back(m_generator.get());
  6248. }
  6249. return true;
  6250. }
  6251. };
  6252. template <typename T>
  6253. GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) {
  6254. return GeneratorWrapper<std::vector<T>>(
  6255. Catch::Detail::make_unique<ChunkGenerator<T>>(size, CATCH_MOVE(generator))
  6256. );
  6257. }
  6258. } // namespace Generators
  6259. } // namespace Catch
  6260. #endif // CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  6261. #ifndef CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6262. #define CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6263. #ifndef CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6264. #define CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6265. #include <cstdint>
  6266. namespace Catch {
  6267. // This is a simple implementation of C++11 Uniform Random Number
  6268. // Generator. It does not provide all operators, because Catch2
  6269. // does not use it, but it should behave as expected inside stdlib's
  6270. // distributions.
  6271. // The implementation is based on the PCG family (http://pcg-random.org)
  6272. class SimplePcg32 {
  6273. using state_type = std::uint64_t;
  6274. public:
  6275. using result_type = std::uint32_t;
  6276. static constexpr result_type (min)() {
  6277. return 0;
  6278. }
  6279. static constexpr result_type (max)() {
  6280. return static_cast<result_type>(-1);
  6281. }
  6282. // Provide some default initial state for the default constructor
  6283. SimplePcg32():SimplePcg32(0xed743cc4U) {}
  6284. explicit SimplePcg32(result_type seed_);
  6285. void seed(result_type seed_);
  6286. void discard(uint64_t skip);
  6287. result_type operator()();
  6288. private:
  6289. friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
  6290. friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
  6291. // In theory we also need operator<< and operator>>
  6292. // In practice we do not use them, so we will skip them for now
  6293. std::uint64_t m_state;
  6294. // This part of the state determines which "stream" of the numbers
  6295. // is chosen -- we take it as a constant for Catch2, so we only
  6296. // need to deal with seeding the main state.
  6297. // Picked by reading 8 bytes from `/dev/random` :-)
  6298. static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
  6299. };
  6300. } // end namespace Catch
  6301. #endif // CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6302. #ifndef CATCH_UNIFORM_INTEGER_DISTRIBUTION_HPP_INCLUDED
  6303. #define CATCH_UNIFORM_INTEGER_DISTRIBUTION_HPP_INCLUDED
  6304. #ifndef CATCH_RANDOM_INTEGER_HELPERS_HPP_INCLUDED
  6305. #define CATCH_RANDOM_INTEGER_HELPERS_HPP_INCLUDED
  6306. #include <climits>
  6307. #include <cstddef>
  6308. #include <cstdint>
  6309. #include <type_traits>
  6310. // Note: We use the usual enable-disable-autodetect dance here even though
  6311. // we do not support these in CMake configuration options (yet?).
  6312. // It is highly unlikely that we will need to make these actually
  6313. // user-configurable, but this will make it simpler if weend up needing
  6314. // it, and it provides an escape hatch to the users who need it.
  6315. #if defined( __SIZEOF_INT128__ )
  6316. # define CATCH_CONFIG_INTERNAL_UINT128
  6317. // Unlike GCC, MSVC does not polyfill umul as mulh + mul pair on ARM machines.
  6318. // Currently we do not bother doing this ourselves, but we could if it became
  6319. // important for perf.
  6320. #elif defined( _MSC_VER ) && defined( _M_X64 )
  6321. # define CATCH_CONFIG_INTERNAL_MSVC_UMUL128
  6322. #endif
  6323. #if defined( CATCH_CONFIG_INTERNAL_UINT128 ) && \
  6324. !defined( CATCH_CONFIG_NO_UINT128 ) && \
  6325. !defined( CATCH_CONFIG_UINT128 )
  6326. #define CATCH_CONFIG_UINT128
  6327. #endif
  6328. #if defined( CATCH_CONFIG_INTERNAL_MSVC_UMUL128 ) && \
  6329. !defined( CATCH_CONFIG_NO_MSVC_UMUL128 ) && \
  6330. !defined( CATCH_CONFIG_MSVC_UMUL128 )
  6331. # define CATCH_CONFIG_MSVC_UMUL128
  6332. # include <intrin.h>
  6333. #endif
  6334. namespace Catch {
  6335. namespace Detail {
  6336. template <std::size_t>
  6337. struct SizedUnsignedType;
  6338. #define SizedUnsignedTypeHelper( TYPE ) \
  6339. template <> \
  6340. struct SizedUnsignedType<sizeof( TYPE )> { \
  6341. using type = TYPE; \
  6342. }
  6343. SizedUnsignedTypeHelper( std::uint8_t );
  6344. SizedUnsignedTypeHelper( std::uint16_t );
  6345. SizedUnsignedTypeHelper( std::uint32_t );
  6346. SizedUnsignedTypeHelper( std::uint64_t );
  6347. #undef SizedUnsignedTypeHelper
  6348. template <std::size_t sz>
  6349. using SizedUnsignedType_t = typename SizedUnsignedType<sz>::type;
  6350. template <typename T>
  6351. using DoubleWidthUnsignedType_t = SizedUnsignedType_t<2 * sizeof( T )>;
  6352. template <typename T>
  6353. struct ExtendedMultResult {
  6354. T upper;
  6355. T lower;
  6356. bool operator==( ExtendedMultResult const& rhs ) const {
  6357. return upper == rhs.upper && lower == rhs.lower;
  6358. }
  6359. };
  6360. /**
  6361. * Returns 128 bit result of lhs * rhs using portable C++ code
  6362. *
  6363. * This implementation is almost twice as fast as naive long multiplication,
  6364. * and unlike intrinsic-based approach, it supports constexpr evaluation.
  6365. */
  6366. constexpr ExtendedMultResult<std::uint64_t>
  6367. extendedMultPortable(std::uint64_t lhs, std::uint64_t rhs) {
  6368. #define CarryBits( x ) ( x >> 32 )
  6369. #define Digits( x ) ( x & 0xFF'FF'FF'FF )
  6370. std::uint64_t lhs_low = Digits( lhs );
  6371. std::uint64_t rhs_low = Digits( rhs );
  6372. std::uint64_t low_low = ( lhs_low * rhs_low );
  6373. std::uint64_t high_high = CarryBits( lhs ) * CarryBits( rhs );
  6374. // We add in carry bits from low-low already
  6375. std::uint64_t high_low =
  6376. ( CarryBits( lhs ) * rhs_low ) + CarryBits( low_low );
  6377. // Note that we can add only low bits from high_low, to avoid
  6378. // overflow with large inputs
  6379. std::uint64_t low_high =
  6380. ( lhs_low * CarryBits( rhs ) ) + Digits( high_low );
  6381. return { high_high + CarryBits( high_low ) + CarryBits( low_high ),
  6382. ( low_high << 32 ) | Digits( low_low ) };
  6383. #undef CarryBits
  6384. #undef Digits
  6385. }
  6386. //! Returns 128 bit result of lhs * rhs
  6387. inline ExtendedMultResult<std::uint64_t>
  6388. extendedMult( std::uint64_t lhs, std::uint64_t rhs ) {
  6389. #if defined( CATCH_CONFIG_UINT128 )
  6390. auto result = __uint128_t( lhs ) * __uint128_t( rhs );
  6391. return { static_cast<std::uint64_t>( result >> 64 ),
  6392. static_cast<std::uint64_t>( result ) };
  6393. #elif defined( CATCH_CONFIG_MSVC_UMUL128 )
  6394. std::uint64_t high;
  6395. std::uint64_t low = _umul128( lhs, rhs, &high );
  6396. return { high, low };
  6397. #else
  6398. return extendedMultPortable( lhs, rhs );
  6399. #endif
  6400. }
  6401. template <typename UInt>
  6402. constexpr ExtendedMultResult<UInt> extendedMult( UInt lhs, UInt rhs ) {
  6403. static_assert( std::is_unsigned<UInt>::value,
  6404. "extendedMult can only handle unsigned integers" );
  6405. static_assert( sizeof( UInt ) < sizeof( std::uint64_t ),
  6406. "Generic extendedMult can only handle types smaller "
  6407. "than uint64_t" );
  6408. using WideType = DoubleWidthUnsignedType_t<UInt>;
  6409. auto result = WideType( lhs ) * WideType( rhs );
  6410. return {
  6411. static_cast<UInt>( result >> ( CHAR_BIT * sizeof( UInt ) ) ),
  6412. static_cast<UInt>( result & UInt( -1 ) ) };
  6413. }
  6414. template <typename TargetType,
  6415. typename Generator>
  6416. std::enable_if_t<sizeof(typename Generator::result_type) >= sizeof(TargetType),
  6417. TargetType> fillBitsFrom(Generator& gen) {
  6418. using gresult_type = typename Generator::result_type;
  6419. static_assert( std::is_unsigned<TargetType>::value, "Only unsigned integers are supported" );
  6420. static_assert( Generator::min() == 0 &&
  6421. Generator::max() == static_cast<gresult_type>( -1 ),
  6422. "Generator must be able to output all numbers in its result type (effectively it must be a random bit generator)" );
  6423. // We want to return the top bits from a generator, as they are
  6424. // usually considered higher quality.
  6425. constexpr auto generated_bits = sizeof( gresult_type ) * CHAR_BIT;
  6426. constexpr auto return_bits = sizeof( TargetType ) * CHAR_BIT;
  6427. return static_cast<TargetType>( gen() >>
  6428. ( generated_bits - return_bits) );
  6429. }
  6430. template <typename TargetType,
  6431. typename Generator>
  6432. std::enable_if_t<sizeof(typename Generator::result_type) < sizeof(TargetType),
  6433. TargetType> fillBitsFrom(Generator& gen) {
  6434. using gresult_type = typename Generator::result_type;
  6435. static_assert( std::is_unsigned<TargetType>::value,
  6436. "Only unsigned integers are supported" );
  6437. static_assert( Generator::min() == 0 &&
  6438. Generator::max() == static_cast<gresult_type>( -1 ),
  6439. "Generator must be able to output all numbers in its result type (effectively it must be a random bit generator)" );
  6440. constexpr auto generated_bits = sizeof( gresult_type ) * CHAR_BIT;
  6441. constexpr auto return_bits = sizeof( TargetType ) * CHAR_BIT;
  6442. std::size_t filled_bits = 0;
  6443. TargetType ret = 0;
  6444. do {
  6445. ret <<= generated_bits;
  6446. ret |= gen();
  6447. filled_bits += generated_bits;
  6448. } while ( filled_bits < return_bits );
  6449. return ret;
  6450. }
  6451. /*
  6452. * Transposes numbers into unsigned type while keeping their ordering
  6453. *
  6454. * This means that signed types are changed so that the ordering is
  6455. * [INT_MIN, ..., -1, 0, ..., INT_MAX], rather than order we would
  6456. * get by simple casting ([0, ..., INT_MAX, INT_MIN, ..., -1])
  6457. */
  6458. template <typename OriginalType, typename UnsignedType>
  6459. std::enable_if_t<std::is_signed<OriginalType>::value, UnsignedType>
  6460. transposeToNaturalOrder( UnsignedType in ) {
  6461. static_assert(
  6462. sizeof( OriginalType ) == sizeof( UnsignedType ),
  6463. "reordering requires the same sized types on both sides" );
  6464. static_assert( std::is_unsigned<UnsignedType>::value,
  6465. "Input type must be unsigned" );
  6466. // Assuming 2s complement (standardized in current C++), the
  6467. // positive and negative numbers are already internally ordered,
  6468. // and their difference is in the top bit. Swapping it orders
  6469. // them the desired way.
  6470. constexpr auto highest_bit =
  6471. UnsignedType( 1 ) << ( sizeof( UnsignedType ) * CHAR_BIT - 1 );
  6472. return static_cast<UnsignedType>( in ^ highest_bit );
  6473. }
  6474. template <typename OriginalType,
  6475. typename UnsignedType>
  6476. std::enable_if_t<std::is_unsigned<OriginalType>::value, UnsignedType>
  6477. transposeToNaturalOrder(UnsignedType in) {
  6478. static_assert(
  6479. sizeof( OriginalType ) == sizeof( UnsignedType ),
  6480. "reordering requires the same sized types on both sides" );
  6481. static_assert( std::is_unsigned<UnsignedType>::value, "Input type must be unsigned" );
  6482. // No reordering is needed for unsigned -> unsigned
  6483. return in;
  6484. }
  6485. } // namespace Detail
  6486. } // namespace Catch
  6487. #endif // CATCH_RANDOM_INTEGER_HELPERS_HPP_INCLUDED
  6488. namespace Catch {
  6489. /**
  6490. * Implementation of uniform distribution on integers.
  6491. *
  6492. * Unlike `std::uniform_int_distribution`, this implementation supports
  6493. * various 1 byte integral types, including bool (but you should not
  6494. * actually use it for bools).
  6495. *
  6496. * The underlying algorithm is based on the one described in "Fast Random
  6497. * Integer Generation in an Interval" by Daniel Lemire, but has been
  6498. * optimized under the assumption of reuse of the same distribution object.
  6499. */
  6500. template <typename IntegerType>
  6501. class uniform_integer_distribution {
  6502. static_assert(std::is_integral<IntegerType>::value, "...");
  6503. using UnsignedIntegerType = Detail::SizedUnsignedType_t<sizeof(IntegerType)>;
  6504. // Only the left bound is stored, and we store it converted to its
  6505. // unsigned image. This avoids having to do the conversions inside
  6506. // the operator(), at the cost of having to do the conversion in
  6507. // the a() getter. The right bound is only needed in the b() getter,
  6508. // so we recompute it there from other stored data.
  6509. UnsignedIntegerType m_a;
  6510. // How many different values are there in [a, b]. a == b => 1, can be 0 for distribution over all values in the type.
  6511. UnsignedIntegerType m_ab_distance;
  6512. // We hoisted this out of the main generation function. Technically,
  6513. // this means that using this distribution will be slower than Lemire's
  6514. // algorithm if this distribution instance will be used only few times,
  6515. // but it will be faster if it is used many times. Since Catch2 uses
  6516. // distributions only to implement random generators, we assume that each
  6517. // distribution will be reused many times and this is an optimization.
  6518. UnsignedIntegerType m_rejection_threshold = 0;
  6519. UnsignedIntegerType computeDistance(IntegerType a, IntegerType b) const {
  6520. // This overflows and returns 0 if a == 0 and b == TYPE_MAX.
  6521. // We handle that later when generating the number.
  6522. return transposeTo(b) - transposeTo(a) + 1;
  6523. }
  6524. static UnsignedIntegerType computeRejectionThreshold(UnsignedIntegerType ab_distance) {
  6525. // distance == 0 means that we will return all possible values from
  6526. // the type's range, and that we shouldn't reject anything.
  6527. if ( ab_distance == 0 ) { return 0; }
  6528. return ( ~ab_distance + 1 ) % ab_distance;
  6529. }
  6530. static UnsignedIntegerType transposeTo(IntegerType in) {
  6531. return Detail::transposeToNaturalOrder<IntegerType>(
  6532. static_cast<UnsignedIntegerType>( in ) );
  6533. }
  6534. static IntegerType transposeBack(UnsignedIntegerType in) {
  6535. return static_cast<IntegerType>(
  6536. Detail::transposeToNaturalOrder<IntegerType>(in) );
  6537. }
  6538. public:
  6539. using result_type = IntegerType;
  6540. uniform_integer_distribution( IntegerType a, IntegerType b ):
  6541. m_a( transposeTo(a) ),
  6542. m_ab_distance( computeDistance(a, b) ),
  6543. m_rejection_threshold( computeRejectionThreshold(m_ab_distance) ) {
  6544. assert( a <= b );
  6545. }
  6546. template <typename Generator>
  6547. result_type operator()( Generator& g ) {
  6548. // All possible values of result_type are valid.
  6549. if ( m_ab_distance == 0 ) {
  6550. return transposeBack( Detail::fillBitsFrom<UnsignedIntegerType>( g ) );
  6551. }
  6552. auto random_number = Detail::fillBitsFrom<UnsignedIntegerType>( g );
  6553. auto emul = Detail::extendedMult( random_number, m_ab_distance );
  6554. // Unlike Lemire's algorithm we skip the ab_distance check, since
  6555. // we precomputed the rejection threshold, which is always tighter.
  6556. while (emul.lower < m_rejection_threshold) {
  6557. random_number = Detail::fillBitsFrom<UnsignedIntegerType>( g );
  6558. emul = Detail::extendedMult( random_number, m_ab_distance );
  6559. }
  6560. return transposeBack(m_a + emul.upper);
  6561. }
  6562. result_type a() const { return transposeBack(m_a); }
  6563. result_type b() const { return transposeBack(m_ab_distance + m_a - 1); }
  6564. };
  6565. } // end namespace Catch
  6566. #endif // CATCH_UNIFORM_INTEGER_DISTRIBUTION_HPP_INCLUDED
  6567. #ifndef CATCH_UNIFORM_FLOATING_POINT_DISTRIBUTION_HPP_INCLUDED
  6568. #define CATCH_UNIFORM_FLOATING_POINT_DISTRIBUTION_HPP_INCLUDED
  6569. #ifndef CATCH_RANDOM_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6570. #define CATCH_RANDOM_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6571. #ifndef CATCH_POLYFILLS_HPP_INCLUDED
  6572. #define CATCH_POLYFILLS_HPP_INCLUDED
  6573. namespace Catch {
  6574. bool isnan(float f);
  6575. bool isnan(double d);
  6576. float nextafter(float x, float y);
  6577. double nextafter(double x, double y);
  6578. }
  6579. #endif // CATCH_POLYFILLS_HPP_INCLUDED
  6580. #include <cassert>
  6581. #include <cmath>
  6582. #include <cstdint>
  6583. #include <limits>
  6584. #include <type_traits>
  6585. namespace Catch {
  6586. namespace Detail {
  6587. /**
  6588. * Returns the largest magnitude of 1-ULP distance inside the [a, b] range.
  6589. *
  6590. * Assumes `a < b`.
  6591. */
  6592. template <typename FloatType>
  6593. FloatType gamma(FloatType a, FloatType b) {
  6594. static_assert( std::is_floating_point<FloatType>::value,
  6595. "gamma returns the largest ULP magnitude within "
  6596. "floating point range [a, b]. This only makes sense "
  6597. "for floating point types" );
  6598. assert( a <= b );
  6599. const auto gamma_up = Catch::nextafter( a, std::numeric_limits<FloatType>::infinity() ) - a;
  6600. const auto gamma_down = b - Catch::nextafter( b, -std::numeric_limits<FloatType>::infinity() );
  6601. return gamma_up < gamma_down ? gamma_down : gamma_up;
  6602. }
  6603. template <typename FloatingPoint>
  6604. struct DistanceTypePicker;
  6605. template <>
  6606. struct DistanceTypePicker<float> {
  6607. using type = std::uint32_t;
  6608. };
  6609. template <>
  6610. struct DistanceTypePicker<double> {
  6611. using type = std::uint64_t;
  6612. };
  6613. template <typename T>
  6614. using DistanceType = typename DistanceTypePicker<T>::type;
  6615. #if defined( __GNUC__ ) || defined( __clang__ )
  6616. # pragma GCC diagnostic push
  6617. # pragma GCC diagnostic ignored "-Wfloat-equal"
  6618. #endif
  6619. /**
  6620. * Computes the number of equi-distant floats in [a, b]
  6621. *
  6622. * Since not every range can be split into equidistant floats
  6623. * exactly, we actually compute ceil(b/distance - a/distance),
  6624. * because in those cases we want to overcount.
  6625. *
  6626. * Uses modified Dekker's FastTwoSum algorithm to handle rounding.
  6627. */
  6628. template <typename FloatType>
  6629. DistanceType<FloatType>
  6630. count_equidistant_floats( FloatType a, FloatType b, FloatType distance ) {
  6631. assert( a <= b );
  6632. // We get distance as gamma for our uniform float distribution,
  6633. // so this will round perfectly.
  6634. const auto ag = a / distance;
  6635. const auto bg = b / distance;
  6636. const auto s = bg - ag;
  6637. const auto err = ( std::fabs( a ) <= std::fabs( b ) )
  6638. ? -ag - ( s - bg )
  6639. : bg - ( s + ag );
  6640. const auto ceil_s = static_cast<DistanceType<FloatType>>( std::ceil( s ) );
  6641. return ( ceil_s != s ) ? ceil_s : ceil_s + ( err > 0 );
  6642. }
  6643. #if defined( __GNUC__ ) || defined( __clang__ )
  6644. # pragma GCC diagnostic pop
  6645. #endif
  6646. }
  6647. } // end namespace Catch
  6648. #endif // CATCH_RANDOM_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6649. #include <cmath>
  6650. #include <type_traits>
  6651. namespace Catch {
  6652. namespace Detail {
  6653. #if defined( __GNUC__ ) || defined( __clang__ )
  6654. # pragma GCC diagnostic push
  6655. # pragma GCC diagnostic ignored "-Wfloat-equal"
  6656. #endif
  6657. // The issue with overflow only happens with maximal ULP and HUGE
  6658. // distance, e.g. when generating numbers in [-inf, inf] for given
  6659. // type. So we only check for the largest possible ULP in the
  6660. // type, and return something that does not overflow to inf in 1 mult.
  6661. constexpr std::uint64_t calculate_max_steps_in_one_go(double gamma) {
  6662. if ( gamma == 1.99584030953472e+292 ) { return 9007199254740991; }
  6663. return static_cast<std::uint64_t>( -1 );
  6664. }
  6665. constexpr std::uint32_t calculate_max_steps_in_one_go(float gamma) {
  6666. if ( gamma == 2.028241e+31f ) { return 16777215; }
  6667. return static_cast<std::uint32_t>( -1 );
  6668. }
  6669. #if defined( __GNUC__ ) || defined( __clang__ )
  6670. # pragma GCC diagnostic pop
  6671. #endif
  6672. }
  6673. /**
  6674. * Implementation of uniform distribution on floating point numbers.
  6675. *
  6676. * Note that we support only `float` and `double` types, because these
  6677. * usually mean the same thing across different platform. `long double`
  6678. * varies wildly by platform and thus we cannot provide reproducible
  6679. * implementation. Also note that we don't implement all parts of
  6680. * distribution per standard: this distribution is not serializable, nor
  6681. * can the range be arbitrarily reset.
  6682. *
  6683. * The implementation also uses different approach than the one taken by
  6684. * `std::uniform_real_distribution`, where instead of generating a number
  6685. * between [0, 1) and then multiplying the range bounds with it, we first
  6686. * split the [a, b] range into a set of equidistributed floating point
  6687. * numbers, and then use uniform int distribution to pick which one to
  6688. * return.
  6689. *
  6690. * This has the advantage of guaranteeing uniformity (the multiplication
  6691. * method loses uniformity due to rounding when multiplying floats), except
  6692. * for small non-uniformity at one side of the interval, where we have
  6693. * to deal with the fact that not every interval is splittable into
  6694. * equidistributed floats.
  6695. *
  6696. * Based on "Drawing random floating-point numbers from an interval" by
  6697. * Frederic Goualard.
  6698. */
  6699. template <typename FloatType>
  6700. class uniform_floating_point_distribution {
  6701. static_assert(std::is_floating_point<FloatType>::value, "...");
  6702. static_assert(!std::is_same<FloatType, long double>::value,
  6703. "We do not support long double due to inconsistent behaviour between platforms");
  6704. using WidthType = Detail::DistanceType<FloatType>;
  6705. FloatType m_a, m_b;
  6706. FloatType m_ulp_magnitude;
  6707. WidthType m_floats_in_range;
  6708. uniform_integer_distribution<WidthType> m_int_dist;
  6709. // In specific cases, we can overflow into `inf` when computing the
  6710. // `steps * g` offset. To avoid this, we don't offset by more than this
  6711. // in one multiply + addition.
  6712. WidthType m_max_steps_in_one_go;
  6713. // We don't want to do the magnitude check every call to `operator()`
  6714. bool m_a_has_leq_magnitude;
  6715. public:
  6716. using result_type = FloatType;
  6717. uniform_floating_point_distribution( FloatType a, FloatType b ):
  6718. m_a( a ),
  6719. m_b( b ),
  6720. m_ulp_magnitude( Detail::gamma( m_a, m_b ) ),
  6721. m_floats_in_range( Detail::count_equidistant_floats( m_a, m_b, m_ulp_magnitude ) ),
  6722. m_int_dist(0, m_floats_in_range),
  6723. m_max_steps_in_one_go( Detail::calculate_max_steps_in_one_go(m_ulp_magnitude)),
  6724. m_a_has_leq_magnitude(std::fabs(m_a) <= std::fabs(m_b))
  6725. {
  6726. assert( a <= b );
  6727. }
  6728. template <typename Generator>
  6729. result_type operator()( Generator& g ) {
  6730. WidthType steps = m_int_dist( g );
  6731. if ( m_a_has_leq_magnitude ) {
  6732. if ( steps == m_floats_in_range ) { return m_a; }
  6733. auto b = m_b;
  6734. while (steps > m_max_steps_in_one_go) {
  6735. b -= m_max_steps_in_one_go * m_ulp_magnitude;
  6736. steps -= m_max_steps_in_one_go;
  6737. }
  6738. return b - steps * m_ulp_magnitude;
  6739. } else {
  6740. if ( steps == m_floats_in_range ) { return m_b; }
  6741. auto a = m_a;
  6742. while (steps > m_max_steps_in_one_go) {
  6743. a += m_max_steps_in_one_go * m_ulp_magnitude;
  6744. steps -= m_max_steps_in_one_go;
  6745. }
  6746. return a + steps * m_ulp_magnitude;
  6747. }
  6748. }
  6749. result_type a() const { return m_a; }
  6750. result_type b() const { return m_b; }
  6751. };
  6752. } // end namespace Catch
  6753. #endif // CATCH_UNIFORM_FLOATING_POINT_DISTRIBUTION_HPP_INCLUDED
  6754. namespace Catch {
  6755. namespace Generators {
  6756. namespace Detail {
  6757. // Returns a suitable seed for a random floating generator based off
  6758. // the primary internal rng. It does so by taking current value from
  6759. // the rng and returning it as the seed.
  6760. std::uint32_t getSeed();
  6761. }
  6762. template <typename Float>
  6763. class RandomFloatingGenerator final : public IGenerator<Float> {
  6764. Catch::SimplePcg32 m_rng;
  6765. Catch::uniform_floating_point_distribution<Float> m_dist;
  6766. Float m_current_number;
  6767. public:
  6768. RandomFloatingGenerator( Float a, Float b, std::uint32_t seed ):
  6769. m_rng(seed),
  6770. m_dist(a, b) {
  6771. static_cast<void>(next());
  6772. }
  6773. Float const& get() const override {
  6774. return m_current_number;
  6775. }
  6776. bool next() override {
  6777. m_current_number = m_dist(m_rng);
  6778. return true;
  6779. }
  6780. };
  6781. template <>
  6782. class RandomFloatingGenerator<long double> final : public IGenerator<long double> {
  6783. // We still rely on <random> for this specialization, but we don't
  6784. // want to drag it into the header.
  6785. struct PImpl;
  6786. Catch::Detail::unique_ptr<PImpl> m_pimpl;
  6787. long double m_current_number;
  6788. public:
  6789. RandomFloatingGenerator( long double a, long double b, std::uint32_t seed );
  6790. long double const& get() const override { return m_current_number; }
  6791. bool next() override;
  6792. ~RandomFloatingGenerator() override; // = default
  6793. };
  6794. template <typename Integer>
  6795. class RandomIntegerGenerator final : public IGenerator<Integer> {
  6796. Catch::SimplePcg32 m_rng;
  6797. Catch::uniform_integer_distribution<Integer> m_dist;
  6798. Integer m_current_number;
  6799. public:
  6800. RandomIntegerGenerator( Integer a, Integer b, std::uint32_t seed ):
  6801. m_rng(seed),
  6802. m_dist(a, b) {
  6803. static_cast<void>(next());
  6804. }
  6805. Integer const& get() const override {
  6806. return m_current_number;
  6807. }
  6808. bool next() override {
  6809. m_current_number = m_dist(m_rng);
  6810. return true;
  6811. }
  6812. };
  6813. template <typename T>
  6814. std::enable_if_t<std::is_integral<T>::value, GeneratorWrapper<T>>
  6815. random(T a, T b) {
  6816. return GeneratorWrapper<T>(
  6817. Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b, Detail::getSeed())
  6818. );
  6819. }
  6820. template <typename T>
  6821. std::enable_if_t<std::is_floating_point<T>::value,
  6822. GeneratorWrapper<T>>
  6823. random(T a, T b) {
  6824. return GeneratorWrapper<T>(
  6825. Catch::Detail::make_unique<RandomFloatingGenerator<T>>(a, b, Detail::getSeed())
  6826. );
  6827. }
  6828. } // namespace Generators
  6829. } // namespace Catch
  6830. #endif // CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6831. #ifndef CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6832. #define CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6833. #include <iterator>
  6834. #include <type_traits>
  6835. namespace Catch {
  6836. namespace Generators {
  6837. template <typename T>
  6838. class RangeGenerator final : public IGenerator<T> {
  6839. T m_current;
  6840. T m_end;
  6841. T m_step;
  6842. bool m_positive;
  6843. public:
  6844. RangeGenerator(T const& start, T const& end, T const& step):
  6845. m_current(start),
  6846. m_end(end),
  6847. m_step(step),
  6848. m_positive(m_step > T(0))
  6849. {
  6850. assert(m_current != m_end && "Range start and end cannot be equal");
  6851. assert(m_step != T(0) && "Step size cannot be zero");
  6852. assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end");
  6853. }
  6854. RangeGenerator(T const& start, T const& end):
  6855. RangeGenerator(start, end, (start < end) ? T(1) : T(-1))
  6856. {}
  6857. T const& get() const override {
  6858. return m_current;
  6859. }
  6860. bool next() override {
  6861. m_current += m_step;
  6862. return (m_positive) ? (m_current < m_end) : (m_current > m_end);
  6863. }
  6864. };
  6865. template <typename T>
  6866. GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
  6867. static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
  6868. return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end, step));
  6869. }
  6870. template <typename T>
  6871. GeneratorWrapper<T> range(T const& start, T const& end) {
  6872. static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
  6873. return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end));
  6874. }
  6875. template <typename T>
  6876. class IteratorGenerator final : public IGenerator<T> {
  6877. static_assert(!std::is_same<T, bool>::value,
  6878. "IteratorGenerator currently does not support bools"
  6879. "because of std::vector<bool> specialization");
  6880. std::vector<T> m_elems;
  6881. size_t m_current = 0;
  6882. public:
  6883. template <typename InputIterator, typename InputSentinel>
  6884. IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) {
  6885. if (m_elems.empty()) {
  6886. Detail::throw_generator_exception("IteratorGenerator received no valid values");
  6887. }
  6888. }
  6889. T const& get() const override {
  6890. return m_elems[m_current];
  6891. }
  6892. bool next() override {
  6893. ++m_current;
  6894. return m_current != m_elems.size();
  6895. }
  6896. };
  6897. template <typename InputIterator,
  6898. typename InputSentinel,
  6899. typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
  6900. GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
  6901. return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(from, to));
  6902. }
  6903. template <typename Container>
  6904. auto from_range(Container const& cnt) {
  6905. using std::begin;
  6906. using std::end;
  6907. return from_range( begin( cnt ), end( cnt ) );
  6908. }
  6909. } // namespace Generators
  6910. } // namespace Catch
  6911. #endif // CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6912. #endif // CATCH_GENERATORS_ALL_HPP_INCLUDED
  6913. /** \file
  6914. * This is a convenience header for Catch2's interfaces. It includes
  6915. * **all** of Catch2 headers related to interfaces.
  6916. *
  6917. * Generally the Catch2 users should use specific includes they need,
  6918. * but this header can be used instead for ease-of-experimentation, or
  6919. * just plain convenience, at the cost of somewhat increased compilation
  6920. * times.
  6921. *
  6922. * When a new header is added to either the `interfaces` folder, or to
  6923. * the corresponding internal subfolder, it should be added here.
  6924. */
  6925. #ifndef CATCH_INTERFACES_ALL_HPP_INCLUDED
  6926. #define CATCH_INTERFACES_ALL_HPP_INCLUDED
  6927. #ifndef CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  6928. #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  6929. #ifndef CATCH_TEST_RUN_INFO_HPP_INCLUDED
  6930. #define CATCH_TEST_RUN_INFO_HPP_INCLUDED
  6931. namespace Catch {
  6932. struct TestRunInfo {
  6933. constexpr TestRunInfo(StringRef _name) : name(_name) {}
  6934. StringRef name;
  6935. };
  6936. } // end namespace Catch
  6937. #endif // CATCH_TEST_RUN_INFO_HPP_INCLUDED
  6938. #include <map>
  6939. #include <string>
  6940. #include <vector>
  6941. #include <iosfwd>
  6942. namespace Catch {
  6943. struct ReporterDescription;
  6944. struct ListenerDescription;
  6945. struct TagInfo;
  6946. struct TestCaseInfo;
  6947. class TestCaseHandle;
  6948. class IConfig;
  6949. class IStream;
  6950. enum class ColourMode : std::uint8_t;
  6951. struct ReporterConfig {
  6952. ReporterConfig( IConfig const* _fullConfig,
  6953. Detail::unique_ptr<IStream> _stream,
  6954. ColourMode colourMode,
  6955. std::map<std::string, std::string> customOptions );
  6956. ReporterConfig( ReporterConfig&& ) = default;
  6957. ReporterConfig& operator=( ReporterConfig&& ) = default;
  6958. ~ReporterConfig(); // = default
  6959. Detail::unique_ptr<IStream> takeStream() &&;
  6960. IConfig const* fullConfig() const;
  6961. ColourMode colourMode() const;
  6962. std::map<std::string, std::string> const& customOptions() const;
  6963. private:
  6964. Detail::unique_ptr<IStream> m_stream;
  6965. IConfig const* m_fullConfig;
  6966. ColourMode m_colourMode;
  6967. std::map<std::string, std::string> m_customOptions;
  6968. };
  6969. struct AssertionStats {
  6970. AssertionStats( AssertionResult const& _assertionResult,
  6971. std::vector<MessageInfo> const& _infoMessages,
  6972. Totals const& _totals );
  6973. AssertionStats( AssertionStats const& ) = default;
  6974. AssertionStats( AssertionStats && ) = default;
  6975. AssertionStats& operator = ( AssertionStats const& ) = delete;
  6976. AssertionStats& operator = ( AssertionStats && ) = delete;
  6977. AssertionResult assertionResult;
  6978. std::vector<MessageInfo> infoMessages;
  6979. Totals totals;
  6980. };
  6981. struct SectionStats {
  6982. SectionStats( SectionInfo&& _sectionInfo,
  6983. Counts const& _assertions,
  6984. double _durationInSeconds,
  6985. bool _missingAssertions );
  6986. SectionInfo sectionInfo;
  6987. Counts assertions;
  6988. double durationInSeconds;
  6989. bool missingAssertions;
  6990. };
  6991. struct TestCaseStats {
  6992. TestCaseStats( TestCaseInfo const& _testInfo,
  6993. Totals const& _totals,
  6994. std::string&& _stdOut,
  6995. std::string&& _stdErr,
  6996. bool _aborting );
  6997. TestCaseInfo const * testInfo;
  6998. Totals totals;
  6999. std::string stdOut;
  7000. std::string stdErr;
  7001. bool aborting;
  7002. };
  7003. struct TestRunStats {
  7004. TestRunStats( TestRunInfo const& _runInfo,
  7005. Totals const& _totals,
  7006. bool _aborting );
  7007. TestRunInfo runInfo;
  7008. Totals totals;
  7009. bool aborting;
  7010. };
  7011. //! By setting up its preferences, a reporter can modify Catch2's behaviour
  7012. //! in some regards, e.g. it can request Catch2 to capture writes to
  7013. //! stdout/stderr during test execution, and pass them to the reporter.
  7014. struct ReporterPreferences {
  7015. //! Catch2 should redirect writes to stdout and pass them to the
  7016. //! reporter
  7017. bool shouldRedirectStdOut = false;
  7018. //! Catch2 should call `Reporter::assertionEnded` even for passing
  7019. //! assertions
  7020. bool shouldReportAllAssertions = false;
  7021. };
  7022. /**
  7023. * The common base for all reporters and event listeners
  7024. *
  7025. * Implementing classes must also implement:
  7026. *
  7027. * //! User-friendly description of the reporter/listener type
  7028. * static std::string getDescription()
  7029. *
  7030. * Generally shouldn't be derived from by users of Catch2 directly,
  7031. * instead they should derive from one of the utility bases that
  7032. * derive from this class.
  7033. */
  7034. class IEventListener {
  7035. protected:
  7036. //! Derived classes can set up their preferences here
  7037. ReporterPreferences m_preferences;
  7038. //! The test run's config as filled in from CLI and defaults
  7039. IConfig const* m_config;
  7040. public:
  7041. IEventListener( IConfig const* config ): m_config( config ) {}
  7042. virtual ~IEventListener(); // = default;
  7043. // Implementing class must also provide the following static methods:
  7044. // static std::string getDescription();
  7045. ReporterPreferences const& getPreferences() const {
  7046. return m_preferences;
  7047. }
  7048. //! Called when no test cases match provided test spec
  7049. virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0;
  7050. //! Called for all invalid test specs from the cli
  7051. virtual void reportInvalidTestSpec( StringRef invalidArgument ) = 0;
  7052. /**
  7053. * Called once in a testing run before tests are started
  7054. *
  7055. * Not called if tests won't be run (e.g. only listing will happen)
  7056. */
  7057. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  7058. //! Called _once_ for each TEST_CASE, no matter how many times it is entered
  7059. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  7060. //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
  7061. virtual void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber ) = 0;
  7062. //! Called when a `SECTION` is being entered. Not called for skipped sections
  7063. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  7064. //! Called when user-code is being probed before the actual benchmark runs
  7065. virtual void benchmarkPreparing( StringRef benchmarkName ) = 0;
  7066. //! Called after probe but before the user-code is being benchmarked
  7067. virtual void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) = 0;
  7068. //! Called with the benchmark results if benchmark successfully finishes
  7069. virtual void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) = 0;
  7070. //! Called if running the benchmarks fails for any reason
  7071. virtual void benchmarkFailed( StringRef benchmarkName ) = 0;
  7072. //! Called before assertion success/failure is evaluated
  7073. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  7074. //! Called after assertion was fully evaluated
  7075. virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
  7076. //! Called after a `SECTION` has finished running
  7077. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  7078. //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
  7079. virtual void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber ) = 0;
  7080. //! Called _once_ for each TEST_CASE, no matter how many times it is entered
  7081. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  7082. /**
  7083. * Called once after all tests in a testing run are finished
  7084. *
  7085. * Not called if tests weren't run (e.g. only listings happened)
  7086. */
  7087. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  7088. /**
  7089. * Called with test cases that are skipped due to the test run aborting.
  7090. * NOT called for test cases that are explicitly skipped using the `SKIP` macro.
  7091. *
  7092. * Deprecated - will be removed in the next major release.
  7093. */
  7094. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  7095. //! Called if a fatal error (signal/structured exception) occurred
  7096. virtual void fatalErrorEncountered( StringRef error ) = 0;
  7097. //! Writes out information about provided reporters using reporter-specific format
  7098. virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0;
  7099. //! Writes out the provided listeners descriptions using reporter-specific format
  7100. virtual void listListeners(std::vector<ListenerDescription> const& descriptions) = 0;
  7101. //! Writes out information about provided tests using reporter-specific format
  7102. virtual void listTests(std::vector<TestCaseHandle> const& tests) = 0;
  7103. //! Writes out information about the provided tags using reporter-specific format
  7104. virtual void listTags(std::vector<TagInfo> const& tags) = 0;
  7105. };
  7106. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  7107. } // end namespace Catch
  7108. #endif // CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  7109. #ifndef CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  7110. #define CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  7111. #include <string>
  7112. namespace Catch {
  7113. struct ReporterConfig;
  7114. class IConfig;
  7115. class IEventListener;
  7116. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  7117. class IReporterFactory {
  7118. public:
  7119. virtual ~IReporterFactory(); // = default
  7120. virtual IEventListenerPtr
  7121. create( ReporterConfig&& config ) const = 0;
  7122. virtual std::string getDescription() const = 0;
  7123. };
  7124. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  7125. class EventListenerFactory {
  7126. public:
  7127. virtual ~EventListenerFactory(); // = default
  7128. virtual IEventListenerPtr create( IConfig const* config ) const = 0;
  7129. //! Return a meaningful name for the listener, e.g. its type name
  7130. virtual StringRef getName() const = 0;
  7131. //! Return listener's description if available
  7132. virtual std::string getDescription() const = 0;
  7133. };
  7134. } // namespace Catch
  7135. #endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  7136. #ifndef CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7137. #define CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7138. #include <string>
  7139. namespace Catch {
  7140. struct TagAlias;
  7141. class ITagAliasRegistry {
  7142. public:
  7143. virtual ~ITagAliasRegistry(); // = default
  7144. // Nullptr if not present
  7145. virtual TagAlias const* find( std::string const& alias ) const = 0;
  7146. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  7147. static ITagAliasRegistry const& get();
  7148. };
  7149. } // end namespace Catch
  7150. #endif // CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7151. #ifndef CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  7152. #define CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  7153. #include <vector>
  7154. namespace Catch {
  7155. struct TestCaseInfo;
  7156. class TestCaseHandle;
  7157. class IConfig;
  7158. class ITestCaseRegistry {
  7159. public:
  7160. virtual ~ITestCaseRegistry(); // = default
  7161. // TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later
  7162. virtual std::vector<TestCaseInfo* > const& getAllInfos() const = 0;
  7163. virtual std::vector<TestCaseHandle> const& getAllTests() const = 0;
  7164. virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0;
  7165. };
  7166. }
  7167. #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  7168. #endif // CATCH_INTERFACES_ALL_HPP_INCLUDED
  7169. #ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  7170. #define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  7171. namespace Catch {
  7172. namespace Detail {
  7173. //! Provides case-insensitive `op<` semantics when called
  7174. struct CaseInsensitiveLess {
  7175. bool operator()( StringRef lhs,
  7176. StringRef rhs ) const;
  7177. };
  7178. //! Provides case-insensitive `op==` semantics when called
  7179. struct CaseInsensitiveEqualTo {
  7180. bool operator()( StringRef lhs,
  7181. StringRef rhs ) const;
  7182. };
  7183. } // namespace Detail
  7184. } // namespace Catch
  7185. #endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  7186. /** \file
  7187. * Wrapper for ANDROID_LOGWRITE configuration option
  7188. *
  7189. * We want to default to enabling it when compiled for android, but
  7190. * users of the library should also be able to disable it if they want
  7191. * to.
  7192. */
  7193. #ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  7194. #define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  7195. #if defined(__ANDROID__)
  7196. # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
  7197. #endif
  7198. #if defined( CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE ) && \
  7199. !defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) && \
  7200. !defined( CATCH_CONFIG_ANDROID_LOGWRITE )
  7201. # define CATCH_CONFIG_ANDROID_LOGWRITE
  7202. #endif
  7203. #endif // CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  7204. /** \file
  7205. * Wrapper for UNCAUGHT_EXCEPTIONS configuration option
  7206. *
  7207. * For some functionality, Catch2 requires to know whether there is
  7208. * an active exception. Because `std::uncaught_exception` is deprecated
  7209. * in C++17, we want to use `std::uncaught_exceptions` if possible.
  7210. */
  7211. #ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7212. #define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7213. #if defined(_MSC_VER)
  7214. # if _MSC_VER >= 1900 // Visual Studio 2015 or newer
  7215. # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  7216. # endif
  7217. #endif
  7218. #include <exception>
  7219. #if defined(__cpp_lib_uncaught_exceptions) \
  7220. && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
  7221. # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  7222. #endif // __cpp_lib_uncaught_exceptions
  7223. #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
  7224. && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
  7225. && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
  7226. # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  7227. #endif
  7228. #endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7229. #ifndef CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  7230. #define CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  7231. #include <iosfwd>
  7232. #include <cstdint>
  7233. namespace Catch {
  7234. enum class ColourMode : std::uint8_t;
  7235. class IStream;
  7236. struct Colour {
  7237. enum Code {
  7238. None = 0,
  7239. White,
  7240. Red,
  7241. Green,
  7242. Blue,
  7243. Cyan,
  7244. Yellow,
  7245. Grey,
  7246. Bright = 0x10,
  7247. BrightRed = Bright | Red,
  7248. BrightGreen = Bright | Green,
  7249. LightGrey = Bright | Grey,
  7250. BrightWhite = Bright | White,
  7251. BrightYellow = Bright | Yellow,
  7252. // By intention
  7253. FileName = LightGrey,
  7254. Warning = BrightYellow,
  7255. ResultError = BrightRed,
  7256. ResultSuccess = BrightGreen,
  7257. ResultExpectedFailure = Warning,
  7258. Error = BrightRed,
  7259. Success = Green,
  7260. Skip = LightGrey,
  7261. OriginalExpression = Cyan,
  7262. ReconstructedExpression = BrightYellow,
  7263. SecondaryText = LightGrey,
  7264. Headers = White
  7265. };
  7266. };
  7267. class ColourImpl {
  7268. protected:
  7269. //! The associated stream of this ColourImpl instance
  7270. IStream* m_stream;
  7271. public:
  7272. ColourImpl( IStream* stream ): m_stream( stream ) {}
  7273. //! RAII wrapper around writing specific colour of text using specific
  7274. //! colour impl into a stream.
  7275. class ColourGuard {
  7276. ColourImpl const* m_colourImpl;
  7277. Colour::Code m_code;
  7278. bool m_engaged = false;
  7279. public:
  7280. //! Does **not** engage the guard/start the colour
  7281. ColourGuard( Colour::Code code,
  7282. ColourImpl const* colour );
  7283. ColourGuard( ColourGuard const& rhs ) = delete;
  7284. ColourGuard& operator=( ColourGuard const& rhs ) = delete;
  7285. ColourGuard( ColourGuard&& rhs ) noexcept;
  7286. ColourGuard& operator=( ColourGuard&& rhs ) noexcept;
  7287. //! Removes colour _if_ the guard was engaged
  7288. ~ColourGuard();
  7289. /**
  7290. * Explicitly engages colour for given stream.
  7291. *
  7292. * The API based on operator<< should be preferred.
  7293. */
  7294. ColourGuard& engage( std::ostream& stream ) &;
  7295. /**
  7296. * Explicitly engages colour for given stream.
  7297. *
  7298. * The API based on operator<< should be preferred.
  7299. */
  7300. ColourGuard&& engage( std::ostream& stream ) &&;
  7301. private:
  7302. //! Engages the guard and starts using colour
  7303. friend std::ostream& operator<<( std::ostream& lhs,
  7304. ColourGuard& guard ) {
  7305. guard.engageImpl( lhs );
  7306. return lhs;
  7307. }
  7308. //! Engages the guard and starts using colour
  7309. friend std::ostream& operator<<( std::ostream& lhs,
  7310. ColourGuard&& guard) {
  7311. guard.engageImpl( lhs );
  7312. return lhs;
  7313. }
  7314. void engageImpl( std::ostream& stream );
  7315. };
  7316. virtual ~ColourImpl(); // = default
  7317. /**
  7318. * Creates a guard object for given colour and this colour impl
  7319. *
  7320. * **Important:**
  7321. * the guard starts disengaged, and has to be engaged explicitly.
  7322. */
  7323. ColourGuard guardColour( Colour::Code colourCode );
  7324. private:
  7325. virtual void use( Colour::Code colourCode ) const = 0;
  7326. };
  7327. //! Provides ColourImpl based on global config and target compilation platform
  7328. Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
  7329. IStream* stream );
  7330. //! Checks if specific colour impl has been compiled into the binary
  7331. bool isColourImplAvailable( ColourMode colourSelection );
  7332. } // end namespace Catch
  7333. #endif // CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  7334. #ifndef CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  7335. #define CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  7336. // This include must be kept so that user's configured value for CONSOLE_WIDTH
  7337. // is used before we attempt to provide a default value
  7338. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  7339. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  7340. #endif
  7341. #endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  7342. #ifndef CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  7343. #define CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  7344. #include <cstddef>
  7345. #include <initializer_list>
  7346. // We want a simple polyfill over `std::empty`, `std::size` and so on
  7347. // for C++14 or C++ libraries with incomplete support.
  7348. // We also have to handle that MSVC std lib will happily provide these
  7349. // under older standards.
  7350. #if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER)
  7351. // We are already using this header either way, so there shouldn't
  7352. // be much additional overhead in including it to get the feature
  7353. // test macros
  7354. #include <string>
  7355. # if !defined(__cpp_lib_nonmember_container_access)
  7356. # define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  7357. # endif
  7358. #else
  7359. #define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  7360. #endif
  7361. namespace Catch {
  7362. namespace Detail {
  7363. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  7364. template <typename Container>
  7365. constexpr auto empty(Container const& cont) -> decltype(cont.empty()) {
  7366. return cont.empty();
  7367. }
  7368. template <typename T, std::size_t N>
  7369. constexpr bool empty(const T (&)[N]) noexcept {
  7370. // GCC < 7 does not support the const T(&)[] parameter syntax
  7371. // so we have to ignore the length explicitly
  7372. (void)N;
  7373. return false;
  7374. }
  7375. template <typename T>
  7376. constexpr bool empty(std::initializer_list<T> list) noexcept {
  7377. return list.size() > 0;
  7378. }
  7379. template <typename Container>
  7380. constexpr auto size(Container const& cont) -> decltype(cont.size()) {
  7381. return cont.size();
  7382. }
  7383. template <typename T, std::size_t N>
  7384. constexpr std::size_t size(const T(&)[N]) noexcept {
  7385. return N;
  7386. }
  7387. #endif // CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  7388. } // end namespace Detail
  7389. } // end namespace Catch
  7390. #endif // CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  7391. #ifndef CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  7392. #define CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  7393. #include <string>
  7394. namespace Catch {
  7395. void writeToDebugConsole( std::string const& text );
  7396. }
  7397. #endif // CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  7398. #ifndef CATCH_DEBUGGER_HPP_INCLUDED
  7399. #define CATCH_DEBUGGER_HPP_INCLUDED
  7400. namespace Catch {
  7401. bool isDebuggerActive();
  7402. }
  7403. #ifdef CATCH_PLATFORM_MAC
  7404. #if defined(__i386__) || defined(__x86_64__)
  7405. #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
  7406. #elif defined(__aarch64__)
  7407. #define CATCH_TRAP() __asm__(".inst 0xd43e0000")
  7408. #elif defined(__POWERPC__)
  7409. #define CATCH_TRAP() __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  7410. : : : "memory","r0","r3","r4" ) /* NOLINT */
  7411. #endif
  7412. #elif defined(CATCH_PLATFORM_IPHONE)
  7413. // use inline assembler
  7414. #if defined(__i386__) || defined(__x86_64__)
  7415. #define CATCH_TRAP() __asm__("int $3")
  7416. #elif defined(__aarch64__)
  7417. #define CATCH_TRAP() __asm__(".inst 0xd4200000")
  7418. #elif defined(__arm__) && !defined(__thumb__)
  7419. #define CATCH_TRAP() __asm__(".inst 0xe7f001f0")
  7420. #elif defined(__arm__) && defined(__thumb__)
  7421. #define CATCH_TRAP() __asm__(".inst 0xde01")
  7422. #endif
  7423. #elif defined(CATCH_PLATFORM_LINUX)
  7424. // If we can use inline assembler, do it because this allows us to break
  7425. // directly at the location of the failing check instead of breaking inside
  7426. // raise() called from it, i.e. one stack frame below.
  7427. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  7428. #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
  7429. #else // Fall back to the generic way.
  7430. #include <signal.h>
  7431. #define CATCH_TRAP() raise(SIGTRAP)
  7432. #endif
  7433. #elif defined(_MSC_VER)
  7434. #define CATCH_TRAP() __debugbreak()
  7435. #elif defined(__MINGW32__)
  7436. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  7437. #define CATCH_TRAP() DebugBreak()
  7438. #endif
  7439. #ifndef CATCH_BREAK_INTO_DEBUGGER
  7440. #ifdef CATCH_TRAP
  7441. #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
  7442. #else
  7443. #define CATCH_BREAK_INTO_DEBUGGER() []{}()
  7444. #endif
  7445. #endif
  7446. #endif // CATCH_DEBUGGER_HPP_INCLUDED
  7447. #ifndef CATCH_ENFORCE_HPP_INCLUDED
  7448. #define CATCH_ENFORCE_HPP_INCLUDED
  7449. #include <exception>
  7450. namespace Catch {
  7451. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  7452. template <typename Ex>
  7453. [[noreturn]]
  7454. void throw_exception(Ex const& e) {
  7455. throw e;
  7456. }
  7457. #else // ^^ Exceptions are enabled // Exceptions are disabled vv
  7458. [[noreturn]]
  7459. void throw_exception(std::exception const& e);
  7460. #endif
  7461. [[noreturn]]
  7462. void throw_logic_error(std::string const& msg);
  7463. [[noreturn]]
  7464. void throw_domain_error(std::string const& msg);
  7465. [[noreturn]]
  7466. void throw_runtime_error(std::string const& msg);
  7467. } // namespace Catch;
  7468. #define CATCH_MAKE_MSG(...) \
  7469. (Catch::ReusableStringStream() << __VA_ARGS__).str()
  7470. #define CATCH_INTERNAL_ERROR(...) \
  7471. Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
  7472. #define CATCH_ERROR(...) \
  7473. Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
  7474. #define CATCH_RUNTIME_ERROR(...) \
  7475. Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
  7476. #define CATCH_ENFORCE( condition, ... ) \
  7477. do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
  7478. #endif // CATCH_ENFORCE_HPP_INCLUDED
  7479. #ifndef CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  7480. #define CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  7481. #include <vector>
  7482. namespace Catch {
  7483. namespace Detail {
  7484. Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
  7485. class EnumValuesRegistry : public IMutableEnumValuesRegistry {
  7486. std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
  7487. EnumInfo const& registerEnum( StringRef enumName, StringRef allValueNames, std::vector<int> const& values) override;
  7488. };
  7489. std::vector<StringRef> parseEnums( StringRef enums );
  7490. } // Detail
  7491. } // Catch
  7492. #endif // CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  7493. #ifndef CATCH_ERRNO_GUARD_HPP_INCLUDED
  7494. #define CATCH_ERRNO_GUARD_HPP_INCLUDED
  7495. namespace Catch {
  7496. //! Simple RAII class that stores the value of `errno`
  7497. //! at construction and restores it at destruction.
  7498. class ErrnoGuard {
  7499. public:
  7500. // Keep these outlined to avoid dragging in macros from <cerrno>
  7501. ErrnoGuard();
  7502. ~ErrnoGuard();
  7503. private:
  7504. int m_oldErrno;
  7505. };
  7506. }
  7507. #endif // CATCH_ERRNO_GUARD_HPP_INCLUDED
  7508. #ifndef CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  7509. #define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  7510. #include <vector>
  7511. #include <string>
  7512. namespace Catch {
  7513. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  7514. public:
  7515. ~ExceptionTranslatorRegistry() override;
  7516. void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator );
  7517. std::string translateActiveException() const override;
  7518. private:
  7519. ExceptionTranslators m_translators;
  7520. };
  7521. }
  7522. #endif // CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  7523. #ifndef CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  7524. #define CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  7525. #include <cassert>
  7526. namespace Catch {
  7527. /**
  7528. * Wrapper for platform-specific fatal error (signals/SEH) handlers
  7529. *
  7530. * Tries to be cooperative with other handlers, and not step over
  7531. * other handlers. This means that unknown structured exceptions
  7532. * are passed on, previous signal handlers are called, and so on.
  7533. *
  7534. * Can only be instantiated once, and assumes that once a signal
  7535. * is caught, the binary will end up terminating. Thus, there
  7536. */
  7537. class FatalConditionHandler {
  7538. bool m_started = false;
  7539. // Install/disengage implementation for specific platform.
  7540. // Should be if-defed to work on current platform, can assume
  7541. // engage-disengage 1:1 pairing.
  7542. void engage_platform();
  7543. void disengage_platform() noexcept;
  7544. public:
  7545. // Should also have platform-specific implementations as needed
  7546. FatalConditionHandler();
  7547. ~FatalConditionHandler();
  7548. void engage() {
  7549. assert(!m_started && "Handler cannot be installed twice.");
  7550. m_started = true;
  7551. engage_platform();
  7552. }
  7553. void disengage() noexcept {
  7554. assert(m_started && "Handler cannot be uninstalled without being installed first");
  7555. m_started = false;
  7556. disengage_platform();
  7557. }
  7558. };
  7559. //! Simple RAII guard for (dis)engaging the FatalConditionHandler
  7560. class FatalConditionHandlerGuard {
  7561. FatalConditionHandler* m_handler;
  7562. public:
  7563. FatalConditionHandlerGuard(FatalConditionHandler* handler):
  7564. m_handler(handler) {
  7565. m_handler->engage();
  7566. }
  7567. ~FatalConditionHandlerGuard() {
  7568. m_handler->disengage();
  7569. }
  7570. };
  7571. } // end namespace Catch
  7572. #endif // CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  7573. #ifndef CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  7574. #define CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  7575. #include <cassert>
  7576. #include <cmath>
  7577. #include <cstdint>
  7578. #include <utility>
  7579. #include <limits>
  7580. namespace Catch {
  7581. namespace Detail {
  7582. uint32_t convertToBits(float f);
  7583. uint64_t convertToBits(double d);
  7584. // Used when we know we want == comparison of two doubles
  7585. // to centralize warning suppression
  7586. bool directCompare( float lhs, float rhs );
  7587. bool directCompare( double lhs, double rhs );
  7588. } // end namespace Detail
  7589. #if defined( __GNUC__ ) || defined( __clang__ )
  7590. # pragma GCC diagnostic push
  7591. // We do a bunch of direct compensations of floating point numbers,
  7592. // because we know what we are doing and actually do want the direct
  7593. // comparison behaviour.
  7594. # pragma GCC diagnostic ignored "-Wfloat-equal"
  7595. #endif
  7596. /**
  7597. * Calculates the ULP distance between two floating point numbers
  7598. *
  7599. * The ULP distance of two floating point numbers is the count of
  7600. * valid floating point numbers representable between them.
  7601. *
  7602. * There are some exceptions between how this function counts the
  7603. * distance, and the interpretation of the standard as implemented.
  7604. * by e.g. `nextafter`. For this function it always holds that:
  7605. * * `(x == y) => ulpDistance(x, y) == 0` (so `ulpDistance(-0, 0) == 0`)
  7606. * * `ulpDistance(maxFinite, INF) == 1`
  7607. * * `ulpDistance(x, -x) == 2 * ulpDistance(x, 0)`
  7608. *
  7609. * \pre `!isnan( lhs )`
  7610. * \pre `!isnan( rhs )`
  7611. * \pre floating point numbers are represented in IEEE-754 format
  7612. */
  7613. template <typename FP>
  7614. uint64_t ulpDistance( FP lhs, FP rhs ) {
  7615. assert( std::numeric_limits<FP>::is_iec559 &&
  7616. "ulpDistance assumes IEEE-754 format for floating point types" );
  7617. assert( !Catch::isnan( lhs ) &&
  7618. "Distance between NaN and number is not meaningful" );
  7619. assert( !Catch::isnan( rhs ) &&
  7620. "Distance between NaN and number is not meaningful" );
  7621. // We want X == Y to imply 0 ULP distance even if X and Y aren't
  7622. // bit-equal (-0 and 0), or X - Y != 0 (same sign infinities).
  7623. if ( lhs == rhs ) { return 0; }
  7624. // We need a properly typed positive zero for type inference.
  7625. static constexpr FP positive_zero{};
  7626. // We want to ensure that +/- 0 is always represented as positive zero
  7627. if ( lhs == positive_zero ) { lhs = positive_zero; }
  7628. if ( rhs == positive_zero ) { rhs = positive_zero; }
  7629. // If arguments have different signs, we can handle them by summing
  7630. // how far are they from 0 each.
  7631. if ( std::signbit( lhs ) != std::signbit( rhs ) ) {
  7632. return ulpDistance( std::abs( lhs ), positive_zero ) +
  7633. ulpDistance( std::abs( rhs ), positive_zero );
  7634. }
  7635. // When both lhs and rhs are of the same sign, we can just
  7636. // read the numbers bitwise as integers, and then subtract them
  7637. // (assuming IEEE).
  7638. uint64_t lc = Detail::convertToBits( lhs );
  7639. uint64_t rc = Detail::convertToBits( rhs );
  7640. // The ulp distance between two numbers is symmetric, so to avoid
  7641. // dealing with overflows we want the bigger converted number on the lhs
  7642. if ( lc < rc ) {
  7643. std::swap( lc, rc );
  7644. }
  7645. return lc - rc;
  7646. }
  7647. #if defined( __GNUC__ ) || defined( __clang__ )
  7648. # pragma GCC diagnostic pop
  7649. #endif
  7650. } // end namespace Catch
  7651. #endif // CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  7652. #ifndef CATCH_GETENV_HPP_INCLUDED
  7653. #define CATCH_GETENV_HPP_INCLUDED
  7654. namespace Catch {
  7655. namespace Detail {
  7656. //! Wrapper over `std::getenv` that compiles on UWP (and always returns nullptr there)
  7657. char const* getEnv(char const* varName);
  7658. }
  7659. }
  7660. #endif // CATCH_GETENV_HPP_INCLUDED
  7661. #ifndef CATCH_IS_PERMUTATION_HPP_INCLUDED
  7662. #define CATCH_IS_PERMUTATION_HPP_INCLUDED
  7663. #include <algorithm>
  7664. #include <iterator>
  7665. namespace Catch {
  7666. namespace Detail {
  7667. template <typename ForwardIter,
  7668. typename Sentinel,
  7669. typename T,
  7670. typename Comparator>
  7671. ForwardIter find_sentinel( ForwardIter start,
  7672. Sentinel sentinel,
  7673. T const& value,
  7674. Comparator cmp ) {
  7675. while ( start != sentinel ) {
  7676. if ( cmp( *start, value ) ) { break; }
  7677. ++start;
  7678. }
  7679. return start;
  7680. }
  7681. template <typename ForwardIter,
  7682. typename Sentinel,
  7683. typename T,
  7684. typename Comparator>
  7685. std::ptrdiff_t count_sentinel( ForwardIter start,
  7686. Sentinel sentinel,
  7687. T const& value,
  7688. Comparator cmp ) {
  7689. std::ptrdiff_t count = 0;
  7690. while ( start != sentinel ) {
  7691. if ( cmp( *start, value ) ) { ++count; }
  7692. ++start;
  7693. }
  7694. return count;
  7695. }
  7696. template <typename ForwardIter, typename Sentinel>
  7697. std::enable_if_t<!std::is_same<ForwardIter, Sentinel>::value,
  7698. std::ptrdiff_t>
  7699. sentinel_distance( ForwardIter iter, const Sentinel sentinel ) {
  7700. std::ptrdiff_t dist = 0;
  7701. while ( iter != sentinel ) {
  7702. ++iter;
  7703. ++dist;
  7704. }
  7705. return dist;
  7706. }
  7707. template <typename ForwardIter>
  7708. std::ptrdiff_t sentinel_distance( ForwardIter first,
  7709. ForwardIter last ) {
  7710. return std::distance( first, last );
  7711. }
  7712. template <typename ForwardIter1,
  7713. typename Sentinel1,
  7714. typename ForwardIter2,
  7715. typename Sentinel2,
  7716. typename Comparator>
  7717. bool check_element_counts( ForwardIter1 first_1,
  7718. const Sentinel1 end_1,
  7719. ForwardIter2 first_2,
  7720. const Sentinel2 end_2,
  7721. Comparator cmp ) {
  7722. auto cursor = first_1;
  7723. while ( cursor != end_1 ) {
  7724. if ( find_sentinel( first_1, cursor, *cursor, cmp ) ==
  7725. cursor ) {
  7726. // we haven't checked this element yet
  7727. const auto count_in_range_2 =
  7728. count_sentinel( first_2, end_2, *cursor, cmp );
  7729. // Not a single instance in 2nd range, so it cannot be a
  7730. // permutation of 1st range
  7731. if ( count_in_range_2 == 0 ) { return false; }
  7732. const auto count_in_range_1 =
  7733. count_sentinel( cursor, end_1, *cursor, cmp );
  7734. if ( count_in_range_1 != count_in_range_2 ) {
  7735. return false;
  7736. }
  7737. }
  7738. ++cursor;
  7739. }
  7740. return true;
  7741. }
  7742. template <typename ForwardIter1,
  7743. typename Sentinel1,
  7744. typename ForwardIter2,
  7745. typename Sentinel2,
  7746. typename Comparator>
  7747. bool is_permutation( ForwardIter1 first_1,
  7748. const Sentinel1 end_1,
  7749. ForwardIter2 first_2,
  7750. const Sentinel2 end_2,
  7751. Comparator cmp ) {
  7752. // TODO: no optimization for stronger iterators, because we would also have to constrain on sentinel vs not sentinel types
  7753. // TODO: Comparator has to be "both sides", e.g. a == b => b == a
  7754. // This skips shared prefix of the two ranges
  7755. while (first_1 != end_1 && first_2 != end_2 && cmp(*first_1, *first_2)) {
  7756. ++first_1;
  7757. ++first_2;
  7758. }
  7759. // We need to handle case where at least one of the ranges has no more elements
  7760. if (first_1 == end_1 || first_2 == end_2) {
  7761. return first_1 == end_1 && first_2 == end_2;
  7762. }
  7763. // pair counting is n**2, so we pay linear walk to compare the sizes first
  7764. auto dist_1 = sentinel_distance( first_1, end_1 );
  7765. auto dist_2 = sentinel_distance( first_2, end_2 );
  7766. if (dist_1 != dist_2) { return false; }
  7767. // Since we do not try to handle stronger iterators pair (e.g.
  7768. // bidir) optimally, the only thing left to do is to check counts in
  7769. // the remaining ranges.
  7770. return check_element_counts( first_1, end_1, first_2, end_2, cmp );
  7771. }
  7772. } // namespace Detail
  7773. } // namespace Catch
  7774. #endif // CATCH_IS_PERMUTATION_HPP_INCLUDED
  7775. #ifndef CATCH_ISTREAM_HPP_INCLUDED
  7776. #define CATCH_ISTREAM_HPP_INCLUDED
  7777. #include <iosfwd>
  7778. #include <cstddef>
  7779. #include <ostream>
  7780. #include <string>
  7781. namespace Catch {
  7782. class IStream {
  7783. public:
  7784. virtual ~IStream(); // = default
  7785. virtual std::ostream& stream() = 0;
  7786. /**
  7787. * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr)
  7788. *
  7789. * This is useful for e.g. Win32 colour support, because the Win32
  7790. * API manipulates console directly, unlike POSIX escape codes,
  7791. * that can be written anywhere.
  7792. *
  7793. * Due to variety of ways to change where the stdout/stderr is
  7794. * _actually_ being written, users should always assume that
  7795. * the answer might be wrong.
  7796. */
  7797. virtual bool isConsole() const { return false; }
  7798. };
  7799. /**
  7800. * Creates a stream wrapper that writes to specific file.
  7801. *
  7802. * Also recognizes 4 special filenames
  7803. * * `-` for stdout
  7804. * * `%stdout` for stdout
  7805. * * `%stderr` for stderr
  7806. * * `%debug` for platform specific debugging output
  7807. *
  7808. * \throws if passed an unrecognized %-prefixed stream
  7809. */
  7810. auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream>;
  7811. }
  7812. #endif // CATCH_STREAM_HPP_INCLUDED
  7813. #ifndef CATCH_JSONWRITER_HPP_INCLUDED
  7814. #define CATCH_JSONWRITER_HPP_INCLUDED
  7815. #include <cstdint>
  7816. #include <sstream>
  7817. namespace Catch {
  7818. class JsonObjectWriter;
  7819. class JsonArrayWriter;
  7820. struct JsonUtils {
  7821. static void indent( std::ostream& os, std::uint64_t level );
  7822. static void appendCommaNewline( std::ostream& os,
  7823. bool& should_comma,
  7824. std::uint64_t level );
  7825. };
  7826. class JsonValueWriter {
  7827. public:
  7828. JsonValueWriter( std::ostream& os );
  7829. JsonValueWriter( std::ostream& os, std::uint64_t indent_level );
  7830. JsonObjectWriter writeObject() &&;
  7831. JsonArrayWriter writeArray() &&;
  7832. template <typename T>
  7833. void write( T const& value ) && {
  7834. writeImpl( value, !std::is_arithmetic<T>::value );
  7835. }
  7836. void write( StringRef value ) &&;
  7837. void write( bool value ) &&;
  7838. private:
  7839. void writeImpl( StringRef value, bool quote );
  7840. // Without this SFINAE, this overload is a better match
  7841. // for `std::string`, `char const*`, `char const[N]` args.
  7842. // While it would still work, it would cause code bloat
  7843. // and multiple iteration over the strings
  7844. template <typename T,
  7845. typename = typename std::enable_if_t<
  7846. !std::is_convertible<T, StringRef>::value>>
  7847. void writeImpl( T const& value, bool quote_value ) {
  7848. m_sstream << value;
  7849. writeImpl( m_sstream.str(), quote_value );
  7850. }
  7851. std::ostream& m_os;
  7852. std::stringstream m_sstream;
  7853. std::uint64_t m_indent_level;
  7854. };
  7855. class JsonObjectWriter {
  7856. public:
  7857. JsonObjectWriter( std::ostream& os );
  7858. JsonObjectWriter( std::ostream& os, std::uint64_t indent_level );
  7859. JsonObjectWriter( JsonObjectWriter&& source ) noexcept;
  7860. JsonObjectWriter& operator=( JsonObjectWriter&& source ) = delete;
  7861. ~JsonObjectWriter();
  7862. JsonValueWriter write( StringRef key );
  7863. private:
  7864. std::ostream& m_os;
  7865. std::uint64_t m_indent_level;
  7866. bool m_should_comma = false;
  7867. bool m_active = true;
  7868. };
  7869. class JsonArrayWriter {
  7870. public:
  7871. JsonArrayWriter( std::ostream& os );
  7872. JsonArrayWriter( std::ostream& os, std::uint64_t indent_level );
  7873. JsonArrayWriter( JsonArrayWriter&& source ) noexcept;
  7874. JsonArrayWriter& operator=( JsonArrayWriter&& source ) = delete;
  7875. ~JsonArrayWriter();
  7876. JsonObjectWriter writeObject();
  7877. JsonArrayWriter writeArray();
  7878. template <typename T>
  7879. JsonArrayWriter& write( T const& value ) {
  7880. return writeImpl( value );
  7881. }
  7882. JsonArrayWriter& write( bool value );
  7883. private:
  7884. template <typename T>
  7885. JsonArrayWriter& writeImpl( T const& value ) {
  7886. JsonUtils::appendCommaNewline(
  7887. m_os, m_should_comma, m_indent_level + 1 );
  7888. JsonValueWriter{ m_os }.write( value );
  7889. return *this;
  7890. }
  7891. std::ostream& m_os;
  7892. std::uint64_t m_indent_level;
  7893. bool m_should_comma = false;
  7894. bool m_active = true;
  7895. };
  7896. } // namespace Catch
  7897. #endif // CATCH_JSONWRITER_HPP_INCLUDED
  7898. #ifndef CATCH_LEAK_DETECTOR_HPP_INCLUDED
  7899. #define CATCH_LEAK_DETECTOR_HPP_INCLUDED
  7900. namespace Catch {
  7901. struct LeakDetector {
  7902. LeakDetector();
  7903. ~LeakDetector();
  7904. };
  7905. }
  7906. #endif // CATCH_LEAK_DETECTOR_HPP_INCLUDED
  7907. #ifndef CATCH_LIST_HPP_INCLUDED
  7908. #define CATCH_LIST_HPP_INCLUDED
  7909. #include <set>
  7910. #include <string>
  7911. namespace Catch {
  7912. class IEventListener;
  7913. class Config;
  7914. struct ReporterDescription {
  7915. std::string name, description;
  7916. };
  7917. struct ListenerDescription {
  7918. StringRef name;
  7919. std::string description;
  7920. };
  7921. struct TagInfo {
  7922. void add(StringRef spelling);
  7923. std::string all() const;
  7924. std::set<StringRef> spellings;
  7925. std::size_t count = 0;
  7926. };
  7927. bool list( IEventListener& reporter, Config const& config );
  7928. } // end namespace Catch
  7929. #endif // CATCH_LIST_HPP_INCLUDED
  7930. #ifndef CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  7931. #define CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  7932. #include <cstdio>
  7933. #include <iosfwd>
  7934. #include <string>
  7935. namespace Catch {
  7936. class RedirectedStream {
  7937. std::ostream& m_originalStream;
  7938. std::ostream& m_redirectionStream;
  7939. std::streambuf* m_prevBuf;
  7940. public:
  7941. RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream );
  7942. ~RedirectedStream();
  7943. };
  7944. class RedirectedStdOut {
  7945. ReusableStringStream m_rss;
  7946. RedirectedStream m_cout;
  7947. public:
  7948. RedirectedStdOut();
  7949. auto str() const -> std::string;
  7950. };
  7951. // StdErr has two constituent streams in C++, std::cerr and std::clog
  7952. // This means that we need to redirect 2 streams into 1 to keep proper
  7953. // order of writes
  7954. class RedirectedStdErr {
  7955. ReusableStringStream m_rss;
  7956. RedirectedStream m_cerr;
  7957. RedirectedStream m_clog;
  7958. public:
  7959. RedirectedStdErr();
  7960. auto str() const -> std::string;
  7961. };
  7962. class RedirectedStreams {
  7963. public:
  7964. RedirectedStreams(RedirectedStreams const&) = delete;
  7965. RedirectedStreams& operator=(RedirectedStreams const&) = delete;
  7966. RedirectedStreams(RedirectedStreams&&) = delete;
  7967. RedirectedStreams& operator=(RedirectedStreams&&) = delete;
  7968. RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
  7969. ~RedirectedStreams();
  7970. private:
  7971. std::string& m_redirectedCout;
  7972. std::string& m_redirectedCerr;
  7973. RedirectedStdOut m_redirectedStdOut;
  7974. RedirectedStdErr m_redirectedStdErr;
  7975. };
  7976. #if defined(CATCH_CONFIG_NEW_CAPTURE)
  7977. // Windows's implementation of std::tmpfile is terrible (it tries
  7978. // to create a file inside system folder, thus requiring elevated
  7979. // privileges for the binary), so we have to use tmpnam(_s) and
  7980. // create the file ourselves there.
  7981. class TempFile {
  7982. public:
  7983. TempFile(TempFile const&) = delete;
  7984. TempFile& operator=(TempFile const&) = delete;
  7985. TempFile(TempFile&&) = delete;
  7986. TempFile& operator=(TempFile&&) = delete;
  7987. TempFile();
  7988. ~TempFile();
  7989. std::FILE* getFile();
  7990. std::string getContents();
  7991. private:
  7992. std::FILE* m_file = nullptr;
  7993. #if defined(_MSC_VER)
  7994. char m_buffer[L_tmpnam] = { 0 };
  7995. #endif
  7996. };
  7997. class OutputRedirect {
  7998. public:
  7999. OutputRedirect(OutputRedirect const&) = delete;
  8000. OutputRedirect& operator=(OutputRedirect const&) = delete;
  8001. OutputRedirect(OutputRedirect&&) = delete;
  8002. OutputRedirect& operator=(OutputRedirect&&) = delete;
  8003. OutputRedirect(std::string& stdout_dest, std::string& stderr_dest);
  8004. ~OutputRedirect();
  8005. private:
  8006. int m_originalStdout = -1;
  8007. int m_originalStderr = -1;
  8008. TempFile m_stdoutFile;
  8009. TempFile m_stderrFile;
  8010. std::string& m_stdoutDest;
  8011. std::string& m_stderrDest;
  8012. };
  8013. #endif
  8014. } // end namespace Catch
  8015. #endif // CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  8016. #ifndef CATCH_PARSE_NUMBERS_HPP_INCLUDED
  8017. #define CATCH_PARSE_NUMBERS_HPP_INCLUDED
  8018. #include <string>
  8019. namespace Catch {
  8020. /**
  8021. * Parses unsigned int from the input, using provided base
  8022. *
  8023. * Effectively a wrapper around std::stoul but with better error checking
  8024. * e.g. "-1" is rejected, instead of being parsed as UINT_MAX.
  8025. */
  8026. Optional<unsigned int> parseUInt(std::string const& input, int base = 10);
  8027. }
  8028. #endif // CATCH_PARSE_NUMBERS_HPP_INCLUDED
  8029. #ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  8030. #define CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  8031. #include <map>
  8032. #include <string>
  8033. #include <vector>
  8034. namespace Catch {
  8035. class IEventListener;
  8036. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  8037. class IReporterFactory;
  8038. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  8039. struct ReporterConfig;
  8040. class EventListenerFactory;
  8041. class ReporterRegistry {
  8042. struct ReporterRegistryImpl;
  8043. Detail::unique_ptr<ReporterRegistryImpl> m_impl;
  8044. public:
  8045. ReporterRegistry();
  8046. ~ReporterRegistry(); // = default;
  8047. IEventListenerPtr create( std::string const& name,
  8048. ReporterConfig&& config ) const;
  8049. void registerReporter( std::string const& name,
  8050. IReporterFactoryPtr factory );
  8051. void
  8052. registerListener( Detail::unique_ptr<EventListenerFactory> factory );
  8053. std::map<std::string,
  8054. IReporterFactoryPtr,
  8055. Detail::CaseInsensitiveLess> const&
  8056. getFactories() const;
  8057. std::vector<Detail::unique_ptr<EventListenerFactory>> const&
  8058. getListeners() const;
  8059. };
  8060. } // end namespace Catch
  8061. #endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  8062. #ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED
  8063. #define CATCH_RUN_CONTEXT_HPP_INCLUDED
  8064. #ifndef CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  8065. #define CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  8066. #include <string>
  8067. #include <vector>
  8068. namespace Catch {
  8069. namespace TestCaseTracking {
  8070. struct NameAndLocation {
  8071. std::string name;
  8072. SourceLineInfo location;
  8073. NameAndLocation( std::string&& _name, SourceLineInfo const& _location );
  8074. friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) {
  8075. // This is a very cheap check that should have a very high hit rate.
  8076. // If we get to SourceLineInfo::operator==, we will redo it, but the
  8077. // cost of repeating is trivial at that point (we will be paying
  8078. // multiple strcmp/memcmps at that point).
  8079. if ( lhs.location.line != rhs.location.line ) { return false; }
  8080. return lhs.name == rhs.name && lhs.location == rhs.location;
  8081. }
  8082. friend bool operator!=(NameAndLocation const& lhs,
  8083. NameAndLocation const& rhs) {
  8084. return !( lhs == rhs );
  8085. }
  8086. };
  8087. /**
  8088. * This is a variant of `NameAndLocation` that does not own the name string
  8089. *
  8090. * This avoids extra allocations when trying to locate a tracker by its
  8091. * name and location, as long as we make sure that trackers only keep
  8092. * around the owning variant.
  8093. */
  8094. struct NameAndLocationRef {
  8095. StringRef name;
  8096. SourceLineInfo location;
  8097. constexpr NameAndLocationRef( StringRef name_,
  8098. SourceLineInfo location_ ):
  8099. name( name_ ), location( location_ ) {}
  8100. friend bool operator==( NameAndLocation const& lhs,
  8101. NameAndLocationRef const& rhs ) {
  8102. // This is a very cheap check that should have a very high hit rate.
  8103. // If we get to SourceLineInfo::operator==, we will redo it, but the
  8104. // cost of repeating is trivial at that point (we will be paying
  8105. // multiple strcmp/memcmps at that point).
  8106. if ( lhs.location.line != rhs.location.line ) { return false; }
  8107. return StringRef( lhs.name ) == rhs.name &&
  8108. lhs.location == rhs.location;
  8109. }
  8110. friend bool operator==( NameAndLocationRef const& lhs,
  8111. NameAndLocation const& rhs ) {
  8112. return rhs == lhs;
  8113. }
  8114. };
  8115. class ITracker;
  8116. using ITrackerPtr = Catch::Detail::unique_ptr<ITracker>;
  8117. class ITracker {
  8118. NameAndLocation m_nameAndLocation;
  8119. using Children = std::vector<ITrackerPtr>;
  8120. protected:
  8121. enum CycleState {
  8122. NotStarted,
  8123. Executing,
  8124. ExecutingChildren,
  8125. NeedsAnotherRun,
  8126. CompletedSuccessfully,
  8127. Failed
  8128. };
  8129. ITracker* m_parent = nullptr;
  8130. Children m_children;
  8131. CycleState m_runState = NotStarted;
  8132. public:
  8133. ITracker( NameAndLocation&& nameAndLoc, ITracker* parent ):
  8134. m_nameAndLocation( CATCH_MOVE(nameAndLoc) ),
  8135. m_parent( parent )
  8136. {}
  8137. // static queries
  8138. NameAndLocation const& nameAndLocation() const {
  8139. return m_nameAndLocation;
  8140. }
  8141. ITracker* parent() const {
  8142. return m_parent;
  8143. }
  8144. virtual ~ITracker(); // = default
  8145. // dynamic queries
  8146. //! Returns true if tracker run to completion (successfully or not)
  8147. virtual bool isComplete() const = 0;
  8148. //! Returns true if tracker run to completion successfully
  8149. bool isSuccessfullyCompleted() const {
  8150. return m_runState == CompletedSuccessfully;
  8151. }
  8152. //! Returns true if tracker has started but hasn't been completed
  8153. bool isOpen() const;
  8154. //! Returns true iff tracker has started
  8155. bool hasStarted() const;
  8156. // actions
  8157. virtual void close() = 0; // Successfully complete
  8158. virtual void fail() = 0;
  8159. void markAsNeedingAnotherRun();
  8160. //! Register a nested ITracker
  8161. void addChild( ITrackerPtr&& child );
  8162. /**
  8163. * Returns ptr to specific child if register with this tracker.
  8164. *
  8165. * Returns nullptr if not found.
  8166. */
  8167. ITracker* findChild( NameAndLocationRef const& nameAndLocation );
  8168. //! Have any children been added?
  8169. bool hasChildren() const {
  8170. return !m_children.empty();
  8171. }
  8172. //! Marks tracker as executing a child, doing se recursively up the tree
  8173. void openChild();
  8174. /**
  8175. * Returns true if the instance is a section tracker
  8176. *
  8177. * Subclasses should override to true if they are, replaces RTTI
  8178. * for internal debug checks.
  8179. */
  8180. virtual bool isSectionTracker() const;
  8181. /**
  8182. * Returns true if the instance is a generator tracker
  8183. *
  8184. * Subclasses should override to true if they are, replaces RTTI
  8185. * for internal debug checks.
  8186. */
  8187. virtual bool isGeneratorTracker() const;
  8188. };
  8189. class TrackerContext {
  8190. enum RunState {
  8191. NotStarted,
  8192. Executing,
  8193. CompletedCycle
  8194. };
  8195. ITrackerPtr m_rootTracker;
  8196. ITracker* m_currentTracker = nullptr;
  8197. RunState m_runState = NotStarted;
  8198. public:
  8199. ITracker& startRun();
  8200. void startCycle() {
  8201. m_currentTracker = m_rootTracker.get();
  8202. m_runState = Executing;
  8203. }
  8204. void completeCycle();
  8205. bool completedCycle() const;
  8206. ITracker& currentTracker() { return *m_currentTracker; }
  8207. void setCurrentTracker( ITracker* tracker );
  8208. };
  8209. class TrackerBase : public ITracker {
  8210. protected:
  8211. TrackerContext& m_ctx;
  8212. public:
  8213. TrackerBase( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent );
  8214. bool isComplete() const override;
  8215. void open();
  8216. void close() override;
  8217. void fail() override;
  8218. private:
  8219. void moveToParent();
  8220. void moveToThis();
  8221. };
  8222. class SectionTracker : public TrackerBase {
  8223. std::vector<StringRef> m_filters;
  8224. // Note that lifetime-wise we piggy back off the name stored in the `ITracker` parent`.
  8225. // Currently it allocates owns the name, so this is safe. If it is later refactored
  8226. // to not own the name, the name still has to outlive the `ITracker` parent, so
  8227. // this should still be safe.
  8228. StringRef m_trimmed_name;
  8229. public:
  8230. SectionTracker( NameAndLocation&& nameAndLocation, TrackerContext& ctx, ITracker* parent );
  8231. bool isSectionTracker() const override;
  8232. bool isComplete() const override;
  8233. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocationRef const& nameAndLocation );
  8234. void tryOpen();
  8235. void addInitialFilters( std::vector<std::string> const& filters );
  8236. void addNextFilters( std::vector<StringRef> const& filters );
  8237. //! Returns filters active in this tracker
  8238. std::vector<StringRef> const& getFilters() const { return m_filters; }
  8239. //! Returns whitespace-trimmed name of the tracked section
  8240. StringRef trimmedName() const;
  8241. };
  8242. } // namespace TestCaseTracking
  8243. using TestCaseTracking::ITracker;
  8244. using TestCaseTracking::TrackerContext;
  8245. using TestCaseTracking::SectionTracker;
  8246. } // namespace Catch
  8247. #endif // CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  8248. #include <string>
  8249. namespace Catch {
  8250. class IGeneratorTracker;
  8251. class IConfig;
  8252. class IEventListener;
  8253. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  8254. ///////////////////////////////////////////////////////////////////////////
  8255. class RunContext final : public IResultCapture {
  8256. public:
  8257. RunContext( RunContext const& ) = delete;
  8258. RunContext& operator =( RunContext const& ) = delete;
  8259. explicit RunContext( IConfig const* _config, IEventListenerPtr&& reporter );
  8260. ~RunContext() override;
  8261. Totals runTest(TestCaseHandle const& testCase);
  8262. public: // IResultCapture
  8263. // Assertion handlers
  8264. void handleExpr
  8265. ( AssertionInfo const& info,
  8266. ITransientExpression const& expr,
  8267. AssertionReaction& reaction ) override;
  8268. void handleMessage
  8269. ( AssertionInfo const& info,
  8270. ResultWas::OfType resultType,
  8271. StringRef message,
  8272. AssertionReaction& reaction ) override;
  8273. void handleUnexpectedExceptionNotThrown
  8274. ( AssertionInfo const& info,
  8275. AssertionReaction& reaction ) override;
  8276. void handleUnexpectedInflightException
  8277. ( AssertionInfo const& info,
  8278. std::string&& message,
  8279. AssertionReaction& reaction ) override;
  8280. void handleIncomplete
  8281. ( AssertionInfo const& info ) override;
  8282. void handleNonExpr
  8283. ( AssertionInfo const &info,
  8284. ResultWas::OfType resultType,
  8285. AssertionReaction &reaction ) override;
  8286. void notifyAssertionStarted( AssertionInfo const& info ) override;
  8287. bool sectionStarted( StringRef sectionName,
  8288. SourceLineInfo const& sectionLineInfo,
  8289. Counts& assertions ) override;
  8290. void sectionEnded( SectionEndInfo&& endInfo ) override;
  8291. void sectionEndedEarly( SectionEndInfo&& endInfo ) override;
  8292. IGeneratorTracker*
  8293. acquireGeneratorTracker( StringRef generatorName,
  8294. SourceLineInfo const& lineInfo ) override;
  8295. IGeneratorTracker* createGeneratorTracker(
  8296. StringRef generatorName,
  8297. SourceLineInfo lineInfo,
  8298. Generators::GeneratorBasePtr&& generator ) override;
  8299. void benchmarkPreparing( StringRef name ) override;
  8300. void benchmarkStarting( BenchmarkInfo const& info ) override;
  8301. void benchmarkEnded( BenchmarkStats<> const& stats ) override;
  8302. void benchmarkFailed( StringRef error ) override;
  8303. void pushScopedMessage( MessageInfo const& message ) override;
  8304. void popScopedMessage( MessageInfo const& message ) override;
  8305. void emplaceUnscopedMessage( MessageBuilder&& builder ) override;
  8306. std::string getCurrentTestName() const override;
  8307. const AssertionResult* getLastResult() const override;
  8308. void exceptionEarlyReported() override;
  8309. void handleFatalErrorCondition( StringRef message ) override;
  8310. bool lastAssertionPassed() override;
  8311. void assertionPassed() override;
  8312. public:
  8313. // !TBD We need to do this another way!
  8314. bool aborting() const;
  8315. private:
  8316. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
  8317. void invokeActiveTestCase();
  8318. void resetAssertionInfo();
  8319. bool testForMissingAssertions( Counts& assertions );
  8320. void assertionEnded( AssertionResult&& result );
  8321. void reportExpr
  8322. ( AssertionInfo const &info,
  8323. ResultWas::OfType resultType,
  8324. ITransientExpression const *expr,
  8325. bool negated );
  8326. void populateReaction( AssertionReaction& reaction );
  8327. private:
  8328. void handleUnfinishedSections();
  8329. TestRunInfo m_runInfo;
  8330. TestCaseHandle const* m_activeTestCase = nullptr;
  8331. ITracker* m_testCaseTracker = nullptr;
  8332. Optional<AssertionResult> m_lastResult;
  8333. IConfig const* m_config;
  8334. Totals m_totals;
  8335. IEventListenerPtr m_reporter;
  8336. std::vector<MessageInfo> m_messages;
  8337. std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
  8338. AssertionInfo m_lastAssertionInfo;
  8339. std::vector<SectionEndInfo> m_unfinishedSections;
  8340. std::vector<ITracker*> m_activeSections;
  8341. TrackerContext m_trackerContext;
  8342. FatalConditionHandler m_fatalConditionhandler;
  8343. bool m_lastAssertionPassed = false;
  8344. bool m_shouldReportUnexpected = true;
  8345. bool m_includeSuccessfulResults;
  8346. };
  8347. void seedRng(IConfig const& config);
  8348. unsigned int rngSeed();
  8349. } // end namespace Catch
  8350. #endif // CATCH_RUN_CONTEXT_HPP_INCLUDED
  8351. #ifndef CATCH_SHARDING_HPP_INCLUDED
  8352. #define CATCH_SHARDING_HPP_INCLUDED
  8353. #include <cassert>
  8354. #include <cmath>
  8355. #include <algorithm>
  8356. namespace Catch {
  8357. template<typename Container>
  8358. Container createShard(Container const& container, std::size_t const shardCount, std::size_t const shardIndex) {
  8359. assert(shardCount > shardIndex);
  8360. if (shardCount == 1) {
  8361. return container;
  8362. }
  8363. const std::size_t totalTestCount = container.size();
  8364. const std::size_t shardSize = totalTestCount / shardCount;
  8365. const std::size_t leftoverTests = totalTestCount % shardCount;
  8366. const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests);
  8367. const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests);
  8368. auto startIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(startIndex));
  8369. auto endIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(endIndex));
  8370. return Container(startIterator, endIterator);
  8371. }
  8372. }
  8373. #endif // CATCH_SHARDING_HPP_INCLUDED
  8374. #ifndef CATCH_SINGLETONS_HPP_INCLUDED
  8375. #define CATCH_SINGLETONS_HPP_INCLUDED
  8376. namespace Catch {
  8377. struct ISingleton {
  8378. virtual ~ISingleton(); // = default
  8379. };
  8380. void addSingleton( ISingleton* singleton );
  8381. void cleanupSingletons();
  8382. template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
  8383. class Singleton : SingletonImplT, public ISingleton {
  8384. static auto getInternal() -> Singleton* {
  8385. static Singleton* s_instance = nullptr;
  8386. if( !s_instance ) {
  8387. s_instance = new Singleton;
  8388. addSingleton( s_instance );
  8389. }
  8390. return s_instance;
  8391. }
  8392. public:
  8393. static auto get() -> InterfaceT const& {
  8394. return *getInternal();
  8395. }
  8396. static auto getMutable() -> MutableInterfaceT& {
  8397. return *getInternal();
  8398. }
  8399. };
  8400. } // namespace Catch
  8401. #endif // CATCH_SINGLETONS_HPP_INCLUDED
  8402. #ifndef CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  8403. #define CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  8404. #include <vector>
  8405. #include <exception>
  8406. namespace Catch {
  8407. class StartupExceptionRegistry {
  8408. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  8409. public:
  8410. void add(std::exception_ptr const& exception) noexcept;
  8411. std::vector<std::exception_ptr> const& getExceptions() const noexcept;
  8412. private:
  8413. std::vector<std::exception_ptr> m_exceptions;
  8414. #endif
  8415. };
  8416. } // end namespace Catch
  8417. #endif // CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  8418. #ifndef CATCH_STDSTREAMS_HPP_INCLUDED
  8419. #define CATCH_STDSTREAMS_HPP_INCLUDED
  8420. #include <iosfwd>
  8421. namespace Catch {
  8422. std::ostream& cout();
  8423. std::ostream& cerr();
  8424. std::ostream& clog();
  8425. } // namespace Catch
  8426. #endif
  8427. #ifndef CATCH_STRING_MANIP_HPP_INCLUDED
  8428. #define CATCH_STRING_MANIP_HPP_INCLUDED
  8429. #include <cstdint>
  8430. #include <string>
  8431. #include <iosfwd>
  8432. #include <vector>
  8433. namespace Catch {
  8434. bool startsWith( std::string const& s, std::string const& prefix );
  8435. bool startsWith( StringRef s, char prefix );
  8436. bool endsWith( std::string const& s, std::string const& suffix );
  8437. bool endsWith( std::string const& s, char suffix );
  8438. bool contains( std::string const& s, std::string const& infix );
  8439. void toLowerInPlace( std::string& s );
  8440. std::string toLower( std::string const& s );
  8441. char toLower( char c );
  8442. //! Returns a new string without whitespace at the start/end
  8443. std::string trim( std::string const& str );
  8444. //! Returns a substring of the original ref without whitespace. Beware lifetimes!
  8445. StringRef trim(StringRef ref);
  8446. // !!! Be aware, returns refs into original string - make sure original string outlives them
  8447. std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
  8448. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  8449. /**
  8450. * Helper for streaming a "count [maybe-plural-of-label]" human-friendly string
  8451. *
  8452. * Usage example:
  8453. * ```cpp
  8454. * std::cout << "Found " << pluralise(count, "error") << '\n';
  8455. * ```
  8456. *
  8457. * **Important:** The provided string must outlive the instance
  8458. */
  8459. class pluralise {
  8460. std::uint64_t m_count;
  8461. StringRef m_label;
  8462. public:
  8463. constexpr pluralise(std::uint64_t count, StringRef label):
  8464. m_count(count),
  8465. m_label(label)
  8466. {}
  8467. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  8468. };
  8469. }
  8470. #endif // CATCH_STRING_MANIP_HPP_INCLUDED
  8471. #ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  8472. #define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  8473. #include <map>
  8474. #include <string>
  8475. namespace Catch {
  8476. struct SourceLineInfo;
  8477. class TagAliasRegistry : public ITagAliasRegistry {
  8478. public:
  8479. ~TagAliasRegistry() override;
  8480. TagAlias const* find( std::string const& alias ) const override;
  8481. std::string expandAliases( std::string const& unexpandedTestSpec ) const override;
  8482. void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
  8483. private:
  8484. std::map<std::string, TagAlias> m_registry;
  8485. };
  8486. } // end namespace Catch
  8487. #endif // CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  8488. #ifndef CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED
  8489. #define CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED
  8490. #include <cstdint>
  8491. namespace Catch {
  8492. struct TestCaseInfo;
  8493. class TestCaseInfoHasher {
  8494. public:
  8495. using hash_t = std::uint64_t;
  8496. TestCaseInfoHasher( hash_t seed );
  8497. uint32_t operator()( TestCaseInfo const& t ) const;
  8498. private:
  8499. hash_t m_seed;
  8500. };
  8501. } // namespace Catch
  8502. #endif /* CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED */
  8503. #ifndef CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  8504. #define CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  8505. #include <vector>
  8506. namespace Catch {
  8507. class IConfig;
  8508. class ITestInvoker;
  8509. class TestCaseHandle;
  8510. class TestSpec;
  8511. std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases );
  8512. bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config );
  8513. std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config );
  8514. std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config );
  8515. class TestRegistry : public ITestCaseRegistry {
  8516. public:
  8517. void registerTest( Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker );
  8518. std::vector<TestCaseInfo*> const& getAllInfos() const override;
  8519. std::vector<TestCaseHandle> const& getAllTests() const override;
  8520. std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override;
  8521. ~TestRegistry() override; // = default
  8522. private:
  8523. std::vector<Detail::unique_ptr<TestCaseInfo>> m_owned_test_infos;
  8524. // Keeps a materialized vector for `getAllInfos`.
  8525. // We should get rid of that eventually (see interface note)
  8526. std::vector<TestCaseInfo*> m_viewed_test_infos;
  8527. std::vector<Detail::unique_ptr<ITestInvoker>> m_invokers;
  8528. std::vector<TestCaseHandle> m_handles;
  8529. mutable TestRunOrder m_currentSortOrder = TestRunOrder::Declared;
  8530. mutable std::vector<TestCaseHandle> m_sortedFunctions;
  8531. };
  8532. ///////////////////////////////////////////////////////////////////////////
  8533. } // end namespace Catch
  8534. #endif // CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  8535. #ifndef CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  8536. #define CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  8537. #ifdef __clang__
  8538. #pragma clang diagnostic push
  8539. #pragma clang diagnostic ignored "-Wpadded"
  8540. #endif
  8541. #include <vector>
  8542. #include <string>
  8543. namespace Catch {
  8544. class ITagAliasRegistry;
  8545. class TestSpecParser {
  8546. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  8547. Mode m_mode = None;
  8548. Mode lastMode = None;
  8549. bool m_exclusion = false;
  8550. std::size_t m_pos = 0;
  8551. std::size_t m_realPatternPos = 0;
  8552. std::string m_arg;
  8553. std::string m_substring;
  8554. std::string m_patternName;
  8555. std::vector<std::size_t> m_escapeChars;
  8556. TestSpec::Filter m_currentFilter;
  8557. TestSpec m_testSpec;
  8558. ITagAliasRegistry const* m_tagAliases = nullptr;
  8559. public:
  8560. TestSpecParser( ITagAliasRegistry const& tagAliases );
  8561. TestSpecParser& parse( std::string const& arg );
  8562. TestSpec testSpec();
  8563. private:
  8564. bool visitChar( char c );
  8565. void startNewMode( Mode mode );
  8566. bool processNoneChar( char c );
  8567. void processNameChar( char c );
  8568. bool processOtherChar( char c );
  8569. void endMode();
  8570. void escape();
  8571. bool isControlChar( char c ) const;
  8572. void saveLastMode();
  8573. void revertBackToLastMode();
  8574. void addFilter();
  8575. bool separate();
  8576. // Handles common preprocessing of the pattern for name/tag patterns
  8577. std::string preprocessPattern();
  8578. // Adds the current pattern as a test name
  8579. void addNamePattern();
  8580. // Adds the current pattern as a tag
  8581. void addTagPattern();
  8582. inline void addCharToPattern(char c) {
  8583. m_substring += c;
  8584. m_patternName += c;
  8585. m_realPatternPos++;
  8586. }
  8587. };
  8588. } // namespace Catch
  8589. #ifdef __clang__
  8590. #pragma clang diagnostic pop
  8591. #endif
  8592. #endif // CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  8593. #ifndef CATCH_TEXTFLOW_HPP_INCLUDED
  8594. #define CATCH_TEXTFLOW_HPP_INCLUDED
  8595. #include <cassert>
  8596. #include <string>
  8597. #include <vector>
  8598. namespace Catch {
  8599. namespace TextFlow {
  8600. class Columns;
  8601. /**
  8602. * Abstraction for a string with ansi escape sequences that
  8603. * automatically skips over escapes when iterating. Only graphical
  8604. * escape sequences are considered.
  8605. *
  8606. * Internal representation:
  8607. * An escape sequence looks like \033[39;49m
  8608. * We need bidirectional iteration and the unbound length of escape
  8609. * sequences poses a problem for operator-- To make this work we'll
  8610. * replace the last `m` with a 0xff (this is a codepoint that won't have
  8611. * any utf-8 meaning).
  8612. */
  8613. class AnsiSkippingString {
  8614. std::string m_string;
  8615. std::size_t m_size = 0;
  8616. // perform 0xff replacement and calculate m_size
  8617. void preprocessString();
  8618. public:
  8619. class const_iterator;
  8620. using iterator = const_iterator;
  8621. // note: must be u-suffixed or this will cause a "truncation of
  8622. // constant value" warning on MSVC
  8623. static constexpr char sentinel = static_cast<char>( 0xffu );
  8624. explicit AnsiSkippingString( std::string const& text );
  8625. explicit AnsiSkippingString( std::string&& text );
  8626. const_iterator begin() const;
  8627. const_iterator end() const;
  8628. size_t size() const { return m_size; }
  8629. std::string substring( const_iterator begin,
  8630. const_iterator end ) const;
  8631. };
  8632. class AnsiSkippingString::const_iterator {
  8633. friend AnsiSkippingString;
  8634. struct EndTag {};
  8635. const std::string* m_string;
  8636. std::string::const_iterator m_it;
  8637. explicit const_iterator( const std::string& string, EndTag ):
  8638. m_string( &string ), m_it( string.end() ) {}
  8639. void tryParseAnsiEscapes();
  8640. void advance();
  8641. void unadvance();
  8642. public:
  8643. using difference_type = std::ptrdiff_t;
  8644. using value_type = char;
  8645. using pointer = value_type*;
  8646. using reference = value_type&;
  8647. using iterator_category = std::bidirectional_iterator_tag;
  8648. explicit const_iterator( const std::string& string ):
  8649. m_string( &string ), m_it( string.begin() ) {
  8650. tryParseAnsiEscapes();
  8651. }
  8652. char operator*() const { return *m_it; }
  8653. const_iterator& operator++() {
  8654. advance();
  8655. return *this;
  8656. }
  8657. const_iterator operator++( int ) {
  8658. iterator prev( *this );
  8659. operator++();
  8660. return prev;
  8661. }
  8662. const_iterator& operator--() {
  8663. unadvance();
  8664. return *this;
  8665. }
  8666. const_iterator operator--( int ) {
  8667. iterator prev( *this );
  8668. operator--();
  8669. return prev;
  8670. }
  8671. bool operator==( const_iterator const& other ) const {
  8672. return m_it == other.m_it;
  8673. }
  8674. bool operator!=( const_iterator const& other ) const {
  8675. return !operator==( other );
  8676. }
  8677. bool operator<=( const_iterator const& other ) const {
  8678. return m_it <= other.m_it;
  8679. }
  8680. const_iterator oneBefore() const {
  8681. auto it = *this;
  8682. return --it;
  8683. }
  8684. };
  8685. /**
  8686. * Represents a column of text with specific width and indentation
  8687. *
  8688. * When written out to a stream, it will perform linebreaking
  8689. * of the provided text so that the written lines fit within
  8690. * target width.
  8691. */
  8692. class Column {
  8693. // String to be written out
  8694. AnsiSkippingString m_string;
  8695. // Width of the column for linebreaking
  8696. size_t m_width = CATCH_CONFIG_CONSOLE_WIDTH - 1;
  8697. // Indentation of other lines (including first if initial indent is
  8698. // unset)
  8699. size_t m_indent = 0;
  8700. // Indentation of the first line
  8701. size_t m_initialIndent = std::string::npos;
  8702. public:
  8703. /**
  8704. * Iterates "lines" in `Column` and returns them
  8705. */
  8706. class const_iterator {
  8707. friend Column;
  8708. struct EndTag {};
  8709. Column const& m_column;
  8710. // Where does the current line start?
  8711. AnsiSkippingString::const_iterator m_lineStart;
  8712. // How long should the current line be?
  8713. AnsiSkippingString::const_iterator m_lineEnd;
  8714. // How far have we checked the string to iterate?
  8715. AnsiSkippingString::const_iterator m_parsedTo;
  8716. // Should a '-' be appended to the line?
  8717. bool m_addHyphen = false;
  8718. const_iterator( Column const& column, EndTag ):
  8719. m_column( column ),
  8720. m_lineStart( m_column.m_string.end() ),
  8721. m_lineEnd( column.m_string.end() ),
  8722. m_parsedTo( column.m_string.end() ) {}
  8723. // Calculates the length of the current line
  8724. void calcLength();
  8725. // Returns current indentation width
  8726. size_t indentSize() const;
  8727. // Creates an indented and (optionally) suffixed string from
  8728. // current iterator position, indentation and length.
  8729. std::string addIndentAndSuffix(
  8730. AnsiSkippingString::const_iterator start,
  8731. AnsiSkippingString::const_iterator end ) const;
  8732. public:
  8733. using difference_type = std::ptrdiff_t;
  8734. using value_type = std::string;
  8735. using pointer = value_type*;
  8736. using reference = value_type&;
  8737. using iterator_category = std::forward_iterator_tag;
  8738. explicit const_iterator( Column const& column );
  8739. std::string operator*() const;
  8740. const_iterator& operator++();
  8741. const_iterator operator++( int );
  8742. bool operator==( const_iterator const& other ) const {
  8743. return m_lineStart == other.m_lineStart &&
  8744. &m_column == &other.m_column;
  8745. }
  8746. bool operator!=( const_iterator const& other ) const {
  8747. return !operator==( other );
  8748. }
  8749. };
  8750. using iterator = const_iterator;
  8751. explicit Column( std::string const& text ): m_string( text ) {}
  8752. explicit Column( std::string&& text ):
  8753. m_string( CATCH_MOVE( text ) ) {}
  8754. Column& width( size_t newWidth ) & {
  8755. assert( newWidth > 0 );
  8756. m_width = newWidth;
  8757. return *this;
  8758. }
  8759. Column&& width( size_t newWidth ) && {
  8760. assert( newWidth > 0 );
  8761. m_width = newWidth;
  8762. return CATCH_MOVE( *this );
  8763. }
  8764. Column& indent( size_t newIndent ) & {
  8765. m_indent = newIndent;
  8766. return *this;
  8767. }
  8768. Column&& indent( size_t newIndent ) && {
  8769. m_indent = newIndent;
  8770. return CATCH_MOVE( *this );
  8771. }
  8772. Column& initialIndent( size_t newIndent ) & {
  8773. m_initialIndent = newIndent;
  8774. return *this;
  8775. }
  8776. Column&& initialIndent( size_t newIndent ) && {
  8777. m_initialIndent = newIndent;
  8778. return CATCH_MOVE( *this );
  8779. }
  8780. size_t width() const { return m_width; }
  8781. const_iterator begin() const { return const_iterator( *this ); }
  8782. const_iterator end() const {
  8783. return { *this, const_iterator::EndTag{} };
  8784. }
  8785. friend std::ostream& operator<<( std::ostream& os,
  8786. Column const& col );
  8787. friend Columns operator+( Column const& lhs, Column const& rhs );
  8788. friend Columns operator+( Column&& lhs, Column&& rhs );
  8789. };
  8790. //! Creates a column that serves as an empty space of specific width
  8791. Column Spacer( size_t spaceWidth );
  8792. class Columns {
  8793. std::vector<Column> m_columns;
  8794. public:
  8795. class iterator {
  8796. friend Columns;
  8797. struct EndTag {};
  8798. std::vector<Column> const& m_columns;
  8799. std::vector<Column::const_iterator> m_iterators;
  8800. size_t m_activeIterators;
  8801. iterator( Columns const& columns, EndTag );
  8802. public:
  8803. using difference_type = std::ptrdiff_t;
  8804. using value_type = std::string;
  8805. using pointer = value_type*;
  8806. using reference = value_type&;
  8807. using iterator_category = std::forward_iterator_tag;
  8808. explicit iterator( Columns const& columns );
  8809. auto operator==( iterator const& other ) const -> bool {
  8810. return m_iterators == other.m_iterators;
  8811. }
  8812. auto operator!=( iterator const& other ) const -> bool {
  8813. return m_iterators != other.m_iterators;
  8814. }
  8815. std::string operator*() const;
  8816. iterator& operator++();
  8817. iterator operator++( int );
  8818. };
  8819. using const_iterator = iterator;
  8820. iterator begin() const { return iterator( *this ); }
  8821. iterator end() const { return { *this, iterator::EndTag() }; }
  8822. friend Columns& operator+=( Columns& lhs, Column const& rhs );
  8823. friend Columns& operator+=( Columns& lhs, Column&& rhs );
  8824. friend Columns operator+( Columns const& lhs, Column const& rhs );
  8825. friend Columns operator+( Columns&& lhs, Column&& rhs );
  8826. friend std::ostream& operator<<( std::ostream& os,
  8827. Columns const& cols );
  8828. };
  8829. } // namespace TextFlow
  8830. } // namespace Catch
  8831. #endif // CATCH_TEXTFLOW_HPP_INCLUDED
  8832. #ifndef CATCH_TO_STRING_HPP_INCLUDED
  8833. #define CATCH_TO_STRING_HPP_INCLUDED
  8834. #include <string>
  8835. namespace Catch {
  8836. template <typename T>
  8837. std::string to_string(T const& t) {
  8838. #if defined(CATCH_CONFIG_CPP11_TO_STRING)
  8839. return std::to_string(t);
  8840. #else
  8841. ReusableStringStream rss;
  8842. rss << t;
  8843. return rss.str();
  8844. #endif
  8845. }
  8846. } // end namespace Catch
  8847. #endif // CATCH_TO_STRING_HPP_INCLUDED
  8848. #ifndef CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  8849. #define CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  8850. namespace Catch {
  8851. bool uncaught_exceptions();
  8852. } // end namespace Catch
  8853. #endif // CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  8854. #ifndef CATCH_XMLWRITER_HPP_INCLUDED
  8855. #define CATCH_XMLWRITER_HPP_INCLUDED
  8856. #include <iosfwd>
  8857. #include <vector>
  8858. namespace Catch {
  8859. enum class XmlFormatting {
  8860. None = 0x00,
  8861. Indent = 0x01,
  8862. Newline = 0x02,
  8863. };
  8864. XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs);
  8865. XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
  8866. /**
  8867. * Helper for XML-encoding text (escaping angle brackets, quotes, etc)
  8868. *
  8869. * Note: doesn't take ownership of passed strings, and thus the
  8870. * encoded string must outlive the encoding instance.
  8871. */
  8872. class XmlEncode {
  8873. public:
  8874. enum ForWhat { ForTextNodes, ForAttributes };
  8875. XmlEncode( StringRef str, ForWhat forWhat = ForTextNodes );
  8876. void encodeTo( std::ostream& os ) const;
  8877. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
  8878. private:
  8879. StringRef m_str;
  8880. ForWhat m_forWhat;
  8881. };
  8882. class XmlWriter {
  8883. public:
  8884. class ScopedElement {
  8885. public:
  8886. ScopedElement( XmlWriter* writer, XmlFormatting fmt );
  8887. ScopedElement( ScopedElement&& other ) noexcept;
  8888. ScopedElement& operator=( ScopedElement&& other ) noexcept;
  8889. ~ScopedElement();
  8890. ScopedElement&
  8891. writeText( StringRef text,
  8892. XmlFormatting fmt = XmlFormatting::Newline |
  8893. XmlFormatting::Indent );
  8894. ScopedElement& writeAttribute( StringRef name,
  8895. StringRef attribute );
  8896. template <typename T,
  8897. // Without this SFINAE, this overload is a better match
  8898. // for `std::string`, `char const*`, `char const[N]` args.
  8899. // While it would still work, it would cause code bloat
  8900. // and multiple iteration over the strings
  8901. typename = typename std::enable_if_t<
  8902. !std::is_convertible<T, StringRef>::value>>
  8903. ScopedElement& writeAttribute( StringRef name,
  8904. T const& attribute ) {
  8905. m_writer->writeAttribute( name, attribute );
  8906. return *this;
  8907. }
  8908. private:
  8909. XmlWriter* m_writer = nullptr;
  8910. XmlFormatting m_fmt;
  8911. };
  8912. XmlWriter( std::ostream& os );
  8913. ~XmlWriter();
  8914. XmlWriter( XmlWriter const& ) = delete;
  8915. XmlWriter& operator=( XmlWriter const& ) = delete;
  8916. XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  8917. ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  8918. XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  8919. //! The attribute content is XML-encoded
  8920. XmlWriter& writeAttribute( StringRef name, StringRef attribute );
  8921. //! Writes the attribute as "true/false"
  8922. XmlWriter& writeAttribute( StringRef name, bool attribute );
  8923. //! The attribute content is XML-encoded
  8924. XmlWriter& writeAttribute( StringRef name, char const* attribute );
  8925. //! The attribute value must provide op<<(ostream&, T). The resulting
  8926. //! serialization is XML-encoded
  8927. template <typename T,
  8928. // Without this SFINAE, this overload is a better match
  8929. // for `std::string`, `char const*`, `char const[N]` args.
  8930. // While it would still work, it would cause code bloat
  8931. // and multiple iteration over the strings
  8932. typename = typename std::enable_if_t<
  8933. !std::is_convertible<T, StringRef>::value>>
  8934. XmlWriter& writeAttribute( StringRef name, T const& attribute ) {
  8935. ReusableStringStream rss;
  8936. rss << attribute;
  8937. return writeAttribute( name, rss.str() );
  8938. }
  8939. //! Writes escaped `text` in a element
  8940. XmlWriter& writeText( StringRef text,
  8941. XmlFormatting fmt = XmlFormatting::Newline |
  8942. XmlFormatting::Indent );
  8943. //! Writes XML comment as "<!-- text -->"
  8944. XmlWriter& writeComment( StringRef text,
  8945. XmlFormatting fmt = XmlFormatting::Newline |
  8946. XmlFormatting::Indent );
  8947. void writeStylesheetRef( StringRef url );
  8948. void ensureTagClosed();
  8949. private:
  8950. void applyFormatting(XmlFormatting fmt);
  8951. void writeDeclaration();
  8952. void newlineIfNecessary();
  8953. bool m_tagIsOpen = false;
  8954. bool m_needsNewline = false;
  8955. std::vector<std::string> m_tags;
  8956. std::string m_indent;
  8957. std::ostream& m_os;
  8958. };
  8959. }
  8960. #endif // CATCH_XMLWRITER_HPP_INCLUDED
  8961. /** \file
  8962. * This is a convenience header for Catch2's Matcher support. It includes
  8963. * **all** of Catch2 headers related to matchers.
  8964. *
  8965. * Generally the Catch2 users should use specific includes they need,
  8966. * but this header can be used instead for ease-of-experimentation, or
  8967. * just plain convenience, at the cost of increased compilation times.
  8968. *
  8969. * When a new header is added to either the `matchers` folder, or to
  8970. * the corresponding internal subfolder, it should be added here.
  8971. */
  8972. #ifndef CATCH_MATCHERS_ALL_HPP_INCLUDED
  8973. #define CATCH_MATCHERS_ALL_HPP_INCLUDED
  8974. #ifndef CATCH_MATCHERS_HPP_INCLUDED
  8975. #define CATCH_MATCHERS_HPP_INCLUDED
  8976. #ifndef CATCH_MATCHERS_IMPL_HPP_INCLUDED
  8977. #define CATCH_MATCHERS_IMPL_HPP_INCLUDED
  8978. #include <string>
  8979. namespace Catch {
  8980. #ifdef __clang__
  8981. # pragma clang diagnostic push
  8982. # pragma clang diagnostic ignored "-Wsign-compare"
  8983. # pragma clang diagnostic ignored "-Wnon-virtual-dtor"
  8984. #elif defined __GNUC__
  8985. # pragma GCC diagnostic push
  8986. # pragma GCC diagnostic ignored "-Wsign-compare"
  8987. # pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
  8988. #endif
  8989. template<typename ArgT, typename MatcherT>
  8990. class MatchExpr : public ITransientExpression {
  8991. ArgT && m_arg;
  8992. MatcherT const& m_matcher;
  8993. public:
  8994. MatchExpr( ArgT && arg, MatcherT const& matcher )
  8995. : ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose
  8996. m_arg( CATCH_FORWARD(arg) ),
  8997. m_matcher( matcher )
  8998. {}
  8999. void streamReconstructedExpression( std::ostream& os ) const override {
  9000. os << Catch::Detail::stringify( m_arg )
  9001. << ' '
  9002. << m_matcher.toString();
  9003. }
  9004. };
  9005. #ifdef __clang__
  9006. # pragma clang diagnostic pop
  9007. #elif defined __GNUC__
  9008. # pragma GCC diagnostic pop
  9009. #endif
  9010. namespace Matchers {
  9011. template <typename ArgT>
  9012. class MatcherBase;
  9013. }
  9014. using StringMatcher = Matchers::MatcherBase<std::string>;
  9015. void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher );
  9016. template<typename ArgT, typename MatcherT>
  9017. auto makeMatchExpr( ArgT && arg, MatcherT const& matcher ) -> MatchExpr<ArgT, MatcherT> {
  9018. return MatchExpr<ArgT, MatcherT>( CATCH_FORWARD(arg), matcher );
  9019. }
  9020. } // namespace Catch
  9021. ///////////////////////////////////////////////////////////////////////////////
  9022. #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
  9023. do { \
  9024. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  9025. INTERNAL_CATCH_TRY { \
  9026. catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher ) ); \
  9027. } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
  9028. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  9029. } while( false )
  9030. ///////////////////////////////////////////////////////////////////////////////
  9031. #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
  9032. do { \
  9033. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  9034. if( catchAssertionHandler.allowThrows() ) \
  9035. try { \
  9036. static_cast<void>(__VA_ARGS__ ); \
  9037. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  9038. } \
  9039. catch( exceptionType const& ex ) { \
  9040. catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher ) ); \
  9041. } \
  9042. catch( ... ) { \
  9043. catchAssertionHandler.handleUnexpectedInflightException(); \
  9044. } \
  9045. else \
  9046. catchAssertionHandler.handleThrowingCallSkipped(); \
  9047. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  9048. } while( false )
  9049. #endif // CATCH_MATCHERS_IMPL_HPP_INCLUDED
  9050. #include <string>
  9051. #include <vector>
  9052. namespace Catch {
  9053. namespace Matchers {
  9054. class MatcherUntypedBase {
  9055. public:
  9056. MatcherUntypedBase() = default;
  9057. MatcherUntypedBase(MatcherUntypedBase const&) = default;
  9058. MatcherUntypedBase(MatcherUntypedBase&&) = default;
  9059. MatcherUntypedBase& operator = (MatcherUntypedBase const&) = delete;
  9060. MatcherUntypedBase& operator = (MatcherUntypedBase&&) = delete;
  9061. std::string toString() const;
  9062. protected:
  9063. virtual ~MatcherUntypedBase(); // = default;
  9064. virtual std::string describe() const = 0;
  9065. mutable std::string m_cachedToString;
  9066. };
  9067. template<typename T>
  9068. class MatcherBase : public MatcherUntypedBase {
  9069. public:
  9070. virtual bool match( T const& arg ) const = 0;
  9071. };
  9072. namespace Detail {
  9073. template<typename ArgT>
  9074. class MatchAllOf final : public MatcherBase<ArgT> {
  9075. std::vector<MatcherBase<ArgT> const*> m_matchers;
  9076. public:
  9077. MatchAllOf() = default;
  9078. MatchAllOf(MatchAllOf const&) = delete;
  9079. MatchAllOf& operator=(MatchAllOf const&) = delete;
  9080. MatchAllOf(MatchAllOf&&) = default;
  9081. MatchAllOf& operator=(MatchAllOf&&) = default;
  9082. bool match( ArgT const& arg ) const override {
  9083. for( auto matcher : m_matchers ) {
  9084. if (!matcher->match(arg))
  9085. return false;
  9086. }
  9087. return true;
  9088. }
  9089. std::string describe() const override {
  9090. std::string description;
  9091. description.reserve( 4 + m_matchers.size()*32 );
  9092. description += "( ";
  9093. bool first = true;
  9094. for( auto matcher : m_matchers ) {
  9095. if( first )
  9096. first = false;
  9097. else
  9098. description += " and ";
  9099. description += matcher->toString();
  9100. }
  9101. description += " )";
  9102. return description;
  9103. }
  9104. friend MatchAllOf operator&& (MatchAllOf&& lhs, MatcherBase<ArgT> const& rhs) {
  9105. lhs.m_matchers.push_back(&rhs);
  9106. return CATCH_MOVE(lhs);
  9107. }
  9108. friend MatchAllOf operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf&& rhs) {
  9109. rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
  9110. return CATCH_MOVE(rhs);
  9111. }
  9112. };
  9113. //! lvalue overload is intentionally deleted, users should
  9114. //! not be trying to compose stored composition matchers
  9115. template<typename ArgT>
  9116. MatchAllOf<ArgT> operator&& (MatchAllOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete;
  9117. //! lvalue overload is intentionally deleted, users should
  9118. //! not be trying to compose stored composition matchers
  9119. template<typename ArgT>
  9120. MatchAllOf<ArgT> operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf<ArgT> const& rhs) = delete;
  9121. template<typename ArgT>
  9122. class MatchAnyOf final : public MatcherBase<ArgT> {
  9123. std::vector<MatcherBase<ArgT> const*> m_matchers;
  9124. public:
  9125. MatchAnyOf() = default;
  9126. MatchAnyOf(MatchAnyOf const&) = delete;
  9127. MatchAnyOf& operator=(MatchAnyOf const&) = delete;
  9128. MatchAnyOf(MatchAnyOf&&) = default;
  9129. MatchAnyOf& operator=(MatchAnyOf&&) = default;
  9130. bool match( ArgT const& arg ) const override {
  9131. for( auto matcher : m_matchers ) {
  9132. if (matcher->match(arg))
  9133. return true;
  9134. }
  9135. return false;
  9136. }
  9137. std::string describe() const override {
  9138. std::string description;
  9139. description.reserve( 4 + m_matchers.size()*32 );
  9140. description += "( ";
  9141. bool first = true;
  9142. for( auto matcher : m_matchers ) {
  9143. if( first )
  9144. first = false;
  9145. else
  9146. description += " or ";
  9147. description += matcher->toString();
  9148. }
  9149. description += " )";
  9150. return description;
  9151. }
  9152. friend MatchAnyOf operator|| (MatchAnyOf&& lhs, MatcherBase<ArgT> const& rhs) {
  9153. lhs.m_matchers.push_back(&rhs);
  9154. return CATCH_MOVE(lhs);
  9155. }
  9156. friend MatchAnyOf operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf&& rhs) {
  9157. rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
  9158. return CATCH_MOVE(rhs);
  9159. }
  9160. };
  9161. //! lvalue overload is intentionally deleted, users should
  9162. //! not be trying to compose stored composition matchers
  9163. template<typename ArgT>
  9164. MatchAnyOf<ArgT> operator|| (MatchAnyOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete;
  9165. //! lvalue overload is intentionally deleted, users should
  9166. //! not be trying to compose stored composition matchers
  9167. template<typename ArgT>
  9168. MatchAnyOf<ArgT> operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf<ArgT> const& rhs) = delete;
  9169. template<typename ArgT>
  9170. class MatchNotOf final : public MatcherBase<ArgT> {
  9171. MatcherBase<ArgT> const& m_underlyingMatcher;
  9172. public:
  9173. explicit MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ):
  9174. m_underlyingMatcher( underlyingMatcher )
  9175. {}
  9176. bool match( ArgT const& arg ) const override {
  9177. return !m_underlyingMatcher.match( arg );
  9178. }
  9179. std::string describe() const override {
  9180. return "not " + m_underlyingMatcher.toString();
  9181. }
  9182. };
  9183. } // namespace Detail
  9184. template <typename T>
  9185. Detail::MatchAllOf<T> operator&& (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) {
  9186. return Detail::MatchAllOf<T>{} && lhs && rhs;
  9187. }
  9188. template <typename T>
  9189. Detail::MatchAnyOf<T> operator|| (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) {
  9190. return Detail::MatchAnyOf<T>{} || lhs || rhs;
  9191. }
  9192. template <typename T>
  9193. Detail::MatchNotOf<T> operator! (MatcherBase<T> const& matcher) {
  9194. return Detail::MatchNotOf<T>{ matcher };
  9195. }
  9196. } // namespace Matchers
  9197. } // namespace Catch
  9198. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  9199. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9200. #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
  9201. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9202. #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9203. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9204. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9205. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  9206. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
  9207. #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  9208. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
  9209. #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  9210. #define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
  9211. #define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
  9212. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  9213. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9214. #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
  9215. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9216. #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9217. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9218. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9219. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  9220. #define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
  9221. #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  9222. #define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
  9223. #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  9224. #define CHECK_THAT( arg, matcher ) (void)(0)
  9225. #define REQUIRE_THAT( arg, matcher ) (void)(0)
  9226. #endif // end of user facing macro declarations
  9227. #endif // CATCH_MATCHERS_HPP_INCLUDED
  9228. #ifndef CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  9229. #define CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  9230. #ifndef CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  9231. #define CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  9232. #include <array>
  9233. #include <algorithm>
  9234. #include <string>
  9235. #include <type_traits>
  9236. namespace Catch {
  9237. namespace Matchers {
  9238. class MatcherGenericBase : public MatcherUntypedBase {
  9239. public:
  9240. MatcherGenericBase() = default;
  9241. ~MatcherGenericBase() override; // = default;
  9242. MatcherGenericBase(MatcherGenericBase const&) = default;
  9243. MatcherGenericBase(MatcherGenericBase&&) = default;
  9244. MatcherGenericBase& operator=(MatcherGenericBase const&) = delete;
  9245. MatcherGenericBase& operator=(MatcherGenericBase&&) = delete;
  9246. };
  9247. namespace Detail {
  9248. template<std::size_t N, std::size_t M>
  9249. std::array<void const*, N + M> array_cat(std::array<void const*, N> && lhs, std::array<void const*, M> && rhs) {
  9250. std::array<void const*, N + M> arr{};
  9251. std::copy_n(lhs.begin(), N, arr.begin());
  9252. std::copy_n(rhs.begin(), M, arr.begin() + N);
  9253. return arr;
  9254. }
  9255. template<std::size_t N>
  9256. std::array<void const*, N+1> array_cat(std::array<void const*, N> && lhs, void const* rhs) {
  9257. std::array<void const*, N+1> arr{};
  9258. std::copy_n(lhs.begin(), N, arr.begin());
  9259. arr[N] = rhs;
  9260. return arr;
  9261. }
  9262. template<std::size_t N>
  9263. std::array<void const*, N+1> array_cat(void const* lhs, std::array<void const*, N> && rhs) {
  9264. std::array<void const*, N + 1> arr{ {lhs} };
  9265. std::copy_n(rhs.begin(), N, arr.begin() + 1);
  9266. return arr;
  9267. }
  9268. template<typename T>
  9269. using is_generic_matcher = std::is_base_of<
  9270. Catch::Matchers::MatcherGenericBase,
  9271. std::remove_cv_t<std::remove_reference_t<T>>
  9272. >;
  9273. template<typename... Ts>
  9274. using are_generic_matchers = Catch::Detail::conjunction<is_generic_matcher<Ts>...>;
  9275. template<typename T>
  9276. using is_matcher = std::is_base_of<
  9277. Catch::Matchers::MatcherUntypedBase,
  9278. std::remove_cv_t<std::remove_reference_t<T>>
  9279. >;
  9280. template<std::size_t N, typename Arg>
  9281. bool match_all_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) {
  9282. return true;
  9283. }
  9284. template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices>
  9285. bool match_all_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) {
  9286. return static_cast<T const*>(matchers[Idx])->match(arg) && match_all_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{});
  9287. }
  9288. template<std::size_t N, typename Arg>
  9289. bool match_any_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) {
  9290. return false;
  9291. }
  9292. template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices>
  9293. bool match_any_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) {
  9294. return static_cast<T const*>(matchers[Idx])->match(arg) || match_any_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{});
  9295. }
  9296. std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end);
  9297. template<typename... MatcherTs, std::size_t... Idx>
  9298. std::string describe_multi_matcher(StringRef combine, std::array<void const*, sizeof...(MatcherTs)> const& matchers, std::index_sequence<Idx...>) {
  9299. std::array<std::string, sizeof...(MatcherTs)> descriptions {{
  9300. static_cast<MatcherTs const*>(matchers[Idx])->toString()...
  9301. }};
  9302. return describe_multi_matcher(combine, descriptions.data(), descriptions.data() + descriptions.size());
  9303. }
  9304. template<typename... MatcherTs>
  9305. class MatchAllOfGeneric final : public MatcherGenericBase {
  9306. public:
  9307. MatchAllOfGeneric(MatchAllOfGeneric const&) = delete;
  9308. MatchAllOfGeneric& operator=(MatchAllOfGeneric const&) = delete;
  9309. MatchAllOfGeneric(MatchAllOfGeneric&&) = default;
  9310. MatchAllOfGeneric& operator=(MatchAllOfGeneric&&) = default;
  9311. MatchAllOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {}
  9312. explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
  9313. template<typename Arg>
  9314. bool match(Arg&& arg) const {
  9315. return match_all_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{});
  9316. }
  9317. std::string describe() const override {
  9318. return describe_multi_matcher<MatcherTs...>(" and "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{});
  9319. }
  9320. // Has to be public to enable the concatenating operators
  9321. // below, because they are not friend of the RHS, only LHS,
  9322. // and thus cannot access private fields of RHS
  9323. std::array<void const*, sizeof...( MatcherTs )> m_matchers;
  9324. //! Avoids type nesting for `GenericAllOf && GenericAllOf` case
  9325. template<typename... MatchersRHS>
  9326. friend
  9327. MatchAllOfGeneric<MatcherTs..., MatchersRHS...> operator && (
  9328. MatchAllOfGeneric<MatcherTs...>&& lhs,
  9329. MatchAllOfGeneric<MatchersRHS...>&& rhs) {
  9330. return MatchAllOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
  9331. }
  9332. //! Avoids type nesting for `GenericAllOf && some matcher` case
  9333. template<typename MatcherRHS>
  9334. friend std::enable_if_t<is_matcher<MatcherRHS>::value,
  9335. MatchAllOfGeneric<MatcherTs..., MatcherRHS>> operator && (
  9336. MatchAllOfGeneric<MatcherTs...>&& lhs,
  9337. MatcherRHS const& rhs) {
  9338. return MatchAllOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(&rhs))};
  9339. }
  9340. //! Avoids type nesting for `some matcher && GenericAllOf` case
  9341. template<typename MatcherLHS>
  9342. friend std::enable_if_t<is_matcher<MatcherLHS>::value,
  9343. MatchAllOfGeneric<MatcherLHS, MatcherTs...>> operator && (
  9344. MatcherLHS const& lhs,
  9345. MatchAllOfGeneric<MatcherTs...>&& rhs) {
  9346. return MatchAllOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
  9347. }
  9348. };
  9349. template<typename... MatcherTs>
  9350. class MatchAnyOfGeneric final : public MatcherGenericBase {
  9351. public:
  9352. MatchAnyOfGeneric(MatchAnyOfGeneric const&) = delete;
  9353. MatchAnyOfGeneric& operator=(MatchAnyOfGeneric const&) = delete;
  9354. MatchAnyOfGeneric(MatchAnyOfGeneric&&) = default;
  9355. MatchAnyOfGeneric& operator=(MatchAnyOfGeneric&&) = default;
  9356. MatchAnyOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {}
  9357. explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
  9358. template<typename Arg>
  9359. bool match(Arg&& arg) const {
  9360. return match_any_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{});
  9361. }
  9362. std::string describe() const override {
  9363. return describe_multi_matcher<MatcherTs...>(" or "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{});
  9364. }
  9365. // Has to be public to enable the concatenating operators
  9366. // below, because they are not friend of the RHS, only LHS,
  9367. // and thus cannot access private fields of RHS
  9368. std::array<void const*, sizeof...( MatcherTs )> m_matchers;
  9369. //! Avoids type nesting for `GenericAnyOf || GenericAnyOf` case
  9370. template<typename... MatchersRHS>
  9371. friend MatchAnyOfGeneric<MatcherTs..., MatchersRHS...> operator || (
  9372. MatchAnyOfGeneric<MatcherTs...>&& lhs,
  9373. MatchAnyOfGeneric<MatchersRHS...>&& rhs) {
  9374. return MatchAnyOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
  9375. }
  9376. //! Avoids type nesting for `GenericAnyOf || some matcher` case
  9377. template<typename MatcherRHS>
  9378. friend std::enable_if_t<is_matcher<MatcherRHS>::value,
  9379. MatchAnyOfGeneric<MatcherTs..., MatcherRHS>> operator || (
  9380. MatchAnyOfGeneric<MatcherTs...>&& lhs,
  9381. MatcherRHS const& rhs) {
  9382. return MatchAnyOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))};
  9383. }
  9384. //! Avoids type nesting for `some matcher || GenericAnyOf` case
  9385. template<typename MatcherLHS>
  9386. friend std::enable_if_t<is_matcher<MatcherLHS>::value,
  9387. MatchAnyOfGeneric<MatcherLHS, MatcherTs...>> operator || (
  9388. MatcherLHS const& lhs,
  9389. MatchAnyOfGeneric<MatcherTs...>&& rhs) {
  9390. return MatchAnyOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
  9391. }
  9392. };
  9393. template<typename MatcherT>
  9394. class MatchNotOfGeneric final : public MatcherGenericBase {
  9395. MatcherT const& m_matcher;
  9396. public:
  9397. MatchNotOfGeneric(MatchNotOfGeneric const&) = delete;
  9398. MatchNotOfGeneric& operator=(MatchNotOfGeneric const&) = delete;
  9399. MatchNotOfGeneric(MatchNotOfGeneric&&) = default;
  9400. MatchNotOfGeneric& operator=(MatchNotOfGeneric&&) = default;
  9401. explicit MatchNotOfGeneric(MatcherT const& matcher) : m_matcher{matcher} {}
  9402. template<typename Arg>
  9403. bool match(Arg&& arg) const {
  9404. return !m_matcher.match(arg);
  9405. }
  9406. std::string describe() const override {
  9407. return "not " + m_matcher.toString();
  9408. }
  9409. //! Negating negation can just unwrap and return underlying matcher
  9410. friend MatcherT const& operator ! (MatchNotOfGeneric<MatcherT> const& matcher) {
  9411. return matcher.m_matcher;
  9412. }
  9413. };
  9414. } // namespace Detail
  9415. // compose only generic matchers
  9416. template<typename MatcherLHS, typename MatcherRHS>
  9417. std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>>
  9418. operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) {
  9419. return { lhs, rhs };
  9420. }
  9421. template<typename MatcherLHS, typename MatcherRHS>
  9422. std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherRHS>>
  9423. operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) {
  9424. return { lhs, rhs };
  9425. }
  9426. //! Wrap provided generic matcher in generic negator
  9427. template<typename MatcherT>
  9428. std::enable_if_t<Detail::is_generic_matcher<MatcherT>::value, Detail::MatchNotOfGeneric<MatcherT>>
  9429. operator ! (MatcherT const& matcher) {
  9430. return Detail::MatchNotOfGeneric<MatcherT>{matcher};
  9431. }
  9432. // compose mixed generic and non-generic matchers
  9433. template<typename MatcherLHS, typename ArgRHS>
  9434. std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
  9435. operator && (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) {
  9436. return { lhs, rhs };
  9437. }
  9438. template<typename ArgLHS, typename MatcherRHS>
  9439. std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
  9440. operator && (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) {
  9441. return { lhs, rhs };
  9442. }
  9443. template<typename MatcherLHS, typename ArgRHS>
  9444. std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
  9445. operator || (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) {
  9446. return { lhs, rhs };
  9447. }
  9448. template<typename ArgLHS, typename MatcherRHS>
  9449. std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
  9450. operator || (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) {
  9451. return { lhs, rhs };
  9452. }
  9453. } // namespace Matchers
  9454. } // namespace Catch
  9455. #endif // CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  9456. namespace Catch {
  9457. namespace Matchers {
  9458. class IsEmptyMatcher final : public MatcherGenericBase {
  9459. public:
  9460. template <typename RangeLike>
  9461. bool match(RangeLike&& rng) const {
  9462. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  9463. using Catch::Detail::empty;
  9464. #else
  9465. using std::empty;
  9466. #endif
  9467. return empty(rng);
  9468. }
  9469. std::string describe() const override;
  9470. };
  9471. class HasSizeMatcher final : public MatcherGenericBase {
  9472. std::size_t m_target_size;
  9473. public:
  9474. explicit HasSizeMatcher(std::size_t target_size):
  9475. m_target_size(target_size)
  9476. {}
  9477. template <typename RangeLike>
  9478. bool match(RangeLike&& rng) const {
  9479. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  9480. using Catch::Detail::size;
  9481. #else
  9482. using std::size;
  9483. #endif
  9484. return size(rng) == m_target_size;
  9485. }
  9486. std::string describe() const override;
  9487. };
  9488. template <typename Matcher>
  9489. class SizeMatchesMatcher final : public MatcherGenericBase {
  9490. Matcher m_matcher;
  9491. public:
  9492. explicit SizeMatchesMatcher(Matcher m):
  9493. m_matcher(CATCH_MOVE(m))
  9494. {}
  9495. template <typename RangeLike>
  9496. bool match(RangeLike&& rng) const {
  9497. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  9498. using Catch::Detail::size;
  9499. #else
  9500. using std::size;
  9501. #endif
  9502. return m_matcher.match(size(rng));
  9503. }
  9504. std::string describe() const override {
  9505. return "size matches " + m_matcher.describe();
  9506. }
  9507. };
  9508. //! Creates a matcher that accepts empty ranges/containers
  9509. IsEmptyMatcher IsEmpty();
  9510. //! Creates a matcher that accepts ranges/containers with specific size
  9511. HasSizeMatcher SizeIs(std::size_t sz);
  9512. template <typename Matcher>
  9513. std::enable_if_t<Detail::is_matcher<Matcher>::value,
  9514. SizeMatchesMatcher<Matcher>> SizeIs(Matcher&& m) {
  9515. return SizeMatchesMatcher<Matcher>{CATCH_FORWARD(m)};
  9516. }
  9517. } // end namespace Matchers
  9518. } // end namespace Catch
  9519. #endif // CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  9520. #ifndef CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  9521. #define CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  9522. #include <algorithm>
  9523. #include <functional>
  9524. namespace Catch {
  9525. namespace Matchers {
  9526. //! Matcher for checking that an element in range is equal to specific element
  9527. template <typename T, typename Equality>
  9528. class ContainsElementMatcher final : public MatcherGenericBase {
  9529. T m_desired;
  9530. Equality m_eq;
  9531. public:
  9532. template <typename T2, typename Equality2>
  9533. ContainsElementMatcher(T2&& target, Equality2&& predicate):
  9534. m_desired(CATCH_FORWARD(target)),
  9535. m_eq(CATCH_FORWARD(predicate))
  9536. {}
  9537. std::string describe() const override {
  9538. return "contains element " + Catch::Detail::stringify(m_desired);
  9539. }
  9540. template <typename RangeLike>
  9541. bool match( RangeLike&& rng ) const {
  9542. for ( auto&& elem : rng ) {
  9543. if ( m_eq( elem, m_desired ) ) { return true; }
  9544. }
  9545. return false;
  9546. }
  9547. };
  9548. //! Meta-matcher for checking that an element in a range matches a specific matcher
  9549. template <typename Matcher>
  9550. class ContainsMatcherMatcher final : public MatcherGenericBase {
  9551. Matcher m_matcher;
  9552. public:
  9553. // Note that we do a copy+move to avoid having to SFINAE this
  9554. // constructor (and also avoid some perfect forwarding failure
  9555. // cases)
  9556. ContainsMatcherMatcher(Matcher matcher):
  9557. m_matcher(CATCH_MOVE(matcher))
  9558. {}
  9559. template <typename RangeLike>
  9560. bool match(RangeLike&& rng) const {
  9561. for (auto&& elem : rng) {
  9562. if (m_matcher.match(elem)) {
  9563. return true;
  9564. }
  9565. }
  9566. return false;
  9567. }
  9568. std::string describe() const override {
  9569. return "contains element matching " + m_matcher.describe();
  9570. }
  9571. };
  9572. /**
  9573. * Creates a matcher that checks whether a range contains a specific element.
  9574. *
  9575. * Uses `std::equal_to` to do the comparison
  9576. */
  9577. template <typename T>
  9578. std::enable_if_t<!Detail::is_matcher<T>::value,
  9579. ContainsElementMatcher<T, std::equal_to<>>> Contains(T&& elem) {
  9580. return { CATCH_FORWARD(elem), std::equal_to<>{} };
  9581. }
  9582. //! Creates a matcher that checks whether a range contains element matching a matcher
  9583. template <typename Matcher>
  9584. std::enable_if_t<Detail::is_matcher<Matcher>::value,
  9585. ContainsMatcherMatcher<Matcher>> Contains(Matcher&& matcher) {
  9586. return { CATCH_FORWARD(matcher) };
  9587. }
  9588. /**
  9589. * Creates a matcher that checks whether a range contains a specific element.
  9590. *
  9591. * Uses `eq` to do the comparisons, the element is provided on the rhs
  9592. */
  9593. template <typename T, typename Equality>
  9594. ContainsElementMatcher<T, Equality> Contains(T&& elem, Equality&& eq) {
  9595. return { CATCH_FORWARD(elem), CATCH_FORWARD(eq) };
  9596. }
  9597. }
  9598. }
  9599. #endif // CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  9600. #ifndef CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  9601. #define CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  9602. namespace Catch {
  9603. namespace Matchers {
  9604. class ExceptionMessageMatcher final : public MatcherBase<std::exception> {
  9605. std::string m_message;
  9606. public:
  9607. ExceptionMessageMatcher(std::string const& message):
  9608. m_message(message)
  9609. {}
  9610. bool match(std::exception const& ex) const override;
  9611. std::string describe() const override;
  9612. };
  9613. //! Creates a matcher that checks whether a std derived exception has the provided message
  9614. ExceptionMessageMatcher Message(std::string const& message);
  9615. template <typename StringMatcherType>
  9616. class ExceptionMessageMatchesMatcher final
  9617. : public MatcherBase<std::exception> {
  9618. StringMatcherType m_matcher;
  9619. public:
  9620. ExceptionMessageMatchesMatcher( StringMatcherType matcher ):
  9621. m_matcher( CATCH_MOVE( matcher ) ) {}
  9622. bool match( std::exception const& ex ) const override {
  9623. return m_matcher.match( ex.what() );
  9624. }
  9625. std::string describe() const override {
  9626. return " matches \"" + m_matcher.describe() + '"';
  9627. }
  9628. };
  9629. //! Creates a matcher that checks whether a message from an std derived
  9630. //! exception matches a provided matcher
  9631. template <typename StringMatcherType>
  9632. ExceptionMessageMatchesMatcher<StringMatcherType>
  9633. MessageMatches( StringMatcherType&& matcher ) {
  9634. return { CATCH_FORWARD( matcher ) };
  9635. }
  9636. } // namespace Matchers
  9637. } // namespace Catch
  9638. #endif // CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  9639. #ifndef CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  9640. #define CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  9641. namespace Catch {
  9642. namespace Matchers {
  9643. namespace Detail {
  9644. enum class FloatingPointKind : uint8_t;
  9645. }
  9646. class WithinAbsMatcher final : public MatcherBase<double> {
  9647. public:
  9648. WithinAbsMatcher(double target, double margin);
  9649. bool match(double const& matchee) const override;
  9650. std::string describe() const override;
  9651. private:
  9652. double m_target;
  9653. double m_margin;
  9654. };
  9655. //! Creates a matcher that accepts numbers within certain range of target
  9656. WithinAbsMatcher WithinAbs( double target, double margin );
  9657. class WithinUlpsMatcher final : public MatcherBase<double> {
  9658. public:
  9659. WithinUlpsMatcher( double target,
  9660. uint64_t ulps,
  9661. Detail::FloatingPointKind baseType );
  9662. bool match(double const& matchee) const override;
  9663. std::string describe() const override;
  9664. private:
  9665. double m_target;
  9666. uint64_t m_ulps;
  9667. Detail::FloatingPointKind m_type;
  9668. };
  9669. //! Creates a matcher that accepts doubles within certain ULP range of target
  9670. WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
  9671. //! Creates a matcher that accepts floats within certain ULP range of target
  9672. WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
  9673. // Given IEEE-754 format for floats and doubles, we can assume
  9674. // that float -> double promotion is lossless. Given this, we can
  9675. // assume that if we do the standard relative comparison of
  9676. // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
  9677. // the same result if we do this for floats, as if we do this for
  9678. // doubles that were promoted from floats.
  9679. class WithinRelMatcher final : public MatcherBase<double> {
  9680. public:
  9681. WithinRelMatcher( double target, double epsilon );
  9682. bool match(double const& matchee) const override;
  9683. std::string describe() const override;
  9684. private:
  9685. double m_target;
  9686. double m_epsilon;
  9687. };
  9688. //! Creates a matcher that accepts doubles within certain relative range of target
  9689. WithinRelMatcher WithinRel(double target, double eps);
  9690. //! Creates a matcher that accepts doubles within 100*DBL_EPS relative range of target
  9691. WithinRelMatcher WithinRel(double target);
  9692. //! Creates a matcher that accepts doubles within certain relative range of target
  9693. WithinRelMatcher WithinRel(float target, float eps);
  9694. //! Creates a matcher that accepts floats within 100*FLT_EPS relative range of target
  9695. WithinRelMatcher WithinRel(float target);
  9696. class IsNaNMatcher final : public MatcherBase<double> {
  9697. public:
  9698. IsNaNMatcher() = default;
  9699. bool match( double const& matchee ) const override;
  9700. std::string describe() const override;
  9701. };
  9702. IsNaNMatcher IsNaN();
  9703. } // namespace Matchers
  9704. } // namespace Catch
  9705. #endif // CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  9706. #ifndef CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  9707. #define CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  9708. #include <string>
  9709. namespace Catch {
  9710. namespace Matchers {
  9711. namespace Detail {
  9712. std::string finalizeDescription(const std::string& desc);
  9713. } // namespace Detail
  9714. template <typename T, typename Predicate>
  9715. class PredicateMatcher final : public MatcherBase<T> {
  9716. Predicate m_predicate;
  9717. std::string m_description;
  9718. public:
  9719. PredicateMatcher(Predicate&& elem, std::string const& descr)
  9720. :m_predicate(CATCH_FORWARD(elem)),
  9721. m_description(Detail::finalizeDescription(descr))
  9722. {}
  9723. bool match( T const& item ) const override {
  9724. return m_predicate(item);
  9725. }
  9726. std::string describe() const override {
  9727. return m_description;
  9728. }
  9729. };
  9730. /**
  9731. * Creates a matcher that calls delegates `match` to the provided predicate.
  9732. *
  9733. * The user has to explicitly specify the argument type to the matcher
  9734. */
  9735. template<typename T, typename Pred>
  9736. PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") {
  9737. static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T");
  9738. static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool");
  9739. return PredicateMatcher<T, Pred>(CATCH_FORWARD(predicate), description);
  9740. }
  9741. } // namespace Matchers
  9742. } // namespace Catch
  9743. #endif // CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  9744. #ifndef CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  9745. #define CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  9746. namespace Catch {
  9747. namespace Matchers {
  9748. // Matcher for checking that all elements in range matches a given matcher.
  9749. template <typename Matcher>
  9750. class AllMatchMatcher final : public MatcherGenericBase {
  9751. Matcher m_matcher;
  9752. public:
  9753. AllMatchMatcher(Matcher matcher):
  9754. m_matcher(CATCH_MOVE(matcher))
  9755. {}
  9756. std::string describe() const override {
  9757. return "all match " + m_matcher.describe();
  9758. }
  9759. template <typename RangeLike>
  9760. bool match(RangeLike&& rng) const {
  9761. for (auto&& elem : rng) {
  9762. if (!m_matcher.match(elem)) {
  9763. return false;
  9764. }
  9765. }
  9766. return true;
  9767. }
  9768. };
  9769. // Matcher for checking that no element in range matches a given matcher.
  9770. template <typename Matcher>
  9771. class NoneMatchMatcher final : public MatcherGenericBase {
  9772. Matcher m_matcher;
  9773. public:
  9774. NoneMatchMatcher(Matcher matcher):
  9775. m_matcher(CATCH_MOVE(matcher))
  9776. {}
  9777. std::string describe() const override {
  9778. return "none match " + m_matcher.describe();
  9779. }
  9780. template <typename RangeLike>
  9781. bool match(RangeLike&& rng) const {
  9782. for (auto&& elem : rng) {
  9783. if (m_matcher.match(elem)) {
  9784. return false;
  9785. }
  9786. }
  9787. return true;
  9788. }
  9789. };
  9790. // Matcher for checking that at least one element in range matches a given matcher.
  9791. template <typename Matcher>
  9792. class AnyMatchMatcher final : public MatcherGenericBase {
  9793. Matcher m_matcher;
  9794. public:
  9795. AnyMatchMatcher(Matcher matcher):
  9796. m_matcher(CATCH_MOVE(matcher))
  9797. {}
  9798. std::string describe() const override {
  9799. return "any match " + m_matcher.describe();
  9800. }
  9801. template <typename RangeLike>
  9802. bool match(RangeLike&& rng) const {
  9803. for (auto&& elem : rng) {
  9804. if (m_matcher.match(elem)) {
  9805. return true;
  9806. }
  9807. }
  9808. return false;
  9809. }
  9810. };
  9811. // Matcher for checking that all elements in range are true.
  9812. class AllTrueMatcher final : public MatcherGenericBase {
  9813. public:
  9814. std::string describe() const override;
  9815. template <typename RangeLike>
  9816. bool match(RangeLike&& rng) const {
  9817. for (auto&& elem : rng) {
  9818. if (!elem) {
  9819. return false;
  9820. }
  9821. }
  9822. return true;
  9823. }
  9824. };
  9825. // Matcher for checking that no element in range is true.
  9826. class NoneTrueMatcher final : public MatcherGenericBase {
  9827. public:
  9828. std::string describe() const override;
  9829. template <typename RangeLike>
  9830. bool match(RangeLike&& rng) const {
  9831. for (auto&& elem : rng) {
  9832. if (elem) {
  9833. return false;
  9834. }
  9835. }
  9836. return true;
  9837. }
  9838. };
  9839. // Matcher for checking that any element in range is true.
  9840. class AnyTrueMatcher final : public MatcherGenericBase {
  9841. public:
  9842. std::string describe() const override;
  9843. template <typename RangeLike>
  9844. bool match(RangeLike&& rng) const {
  9845. for (auto&& elem : rng) {
  9846. if (elem) {
  9847. return true;
  9848. }
  9849. }
  9850. return false;
  9851. }
  9852. };
  9853. // Creates a matcher that checks whether all elements in a range match a matcher
  9854. template <typename Matcher>
  9855. AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
  9856. return { CATCH_FORWARD(matcher) };
  9857. }
  9858. // Creates a matcher that checks whether no element in a range matches a matcher.
  9859. template <typename Matcher>
  9860. NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
  9861. return { CATCH_FORWARD(matcher) };
  9862. }
  9863. // Creates a matcher that checks whether any element in a range matches a matcher.
  9864. template <typename Matcher>
  9865. AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
  9866. return { CATCH_FORWARD(matcher) };
  9867. }
  9868. // Creates a matcher that checks whether all elements in a range are true
  9869. AllTrueMatcher AllTrue();
  9870. // Creates a matcher that checks whether no element in a range is true
  9871. NoneTrueMatcher NoneTrue();
  9872. // Creates a matcher that checks whether any element in a range is true
  9873. AnyTrueMatcher AnyTrue();
  9874. }
  9875. }
  9876. #endif // CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  9877. #ifndef CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED
  9878. #define CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED
  9879. #include <algorithm>
  9880. #include <utility>
  9881. namespace Catch {
  9882. namespace Matchers {
  9883. /**
  9884. * Matcher for checking that an element contains the same
  9885. * elements in the same order
  9886. */
  9887. template <typename TargetRangeLike, typename Equality>
  9888. class RangeEqualsMatcher final : public MatcherGenericBase {
  9889. TargetRangeLike m_desired;
  9890. Equality m_predicate;
  9891. public:
  9892. template <typename TargetRangeLike2, typename Equality2>
  9893. RangeEqualsMatcher( TargetRangeLike2&& range,
  9894. Equality2&& predicate ):
  9895. m_desired( CATCH_FORWARD( range ) ),
  9896. m_predicate( CATCH_FORWARD( predicate ) ) {}
  9897. template <typename RangeLike>
  9898. bool match( RangeLike&& rng ) const {
  9899. auto rng_start = begin( rng );
  9900. const auto rng_end = end( rng );
  9901. auto target_start = begin( m_desired );
  9902. const auto target_end = end( m_desired );
  9903. while (rng_start != rng_end && target_start != target_end) {
  9904. if (!m_predicate(*rng_start, *target_start)) {
  9905. return false;
  9906. }
  9907. ++rng_start;
  9908. ++target_start;
  9909. }
  9910. return rng_start == rng_end && target_start == target_end;
  9911. }
  9912. std::string describe() const override {
  9913. return "elements are " + Catch::Detail::stringify( m_desired );
  9914. }
  9915. };
  9916. /**
  9917. * Matcher for checking that an element contains the same
  9918. * elements (but not necessarily in the same order)
  9919. */
  9920. template <typename TargetRangeLike, typename Equality>
  9921. class UnorderedRangeEqualsMatcher final : public MatcherGenericBase {
  9922. TargetRangeLike m_desired;
  9923. Equality m_predicate;
  9924. public:
  9925. template <typename TargetRangeLike2, typename Equality2>
  9926. UnorderedRangeEqualsMatcher( TargetRangeLike2&& range,
  9927. Equality2&& predicate ):
  9928. m_desired( CATCH_FORWARD( range ) ),
  9929. m_predicate( CATCH_FORWARD( predicate ) ) {}
  9930. template <typename RangeLike>
  9931. bool match( RangeLike&& rng ) const {
  9932. using std::begin;
  9933. using std::end;
  9934. return Catch::Detail::is_permutation( begin( m_desired ),
  9935. end( m_desired ),
  9936. begin( rng ),
  9937. end( rng ),
  9938. m_predicate );
  9939. }
  9940. std::string describe() const override {
  9941. return "unordered elements are " +
  9942. ::Catch::Detail::stringify( m_desired );
  9943. }
  9944. };
  9945. /**
  9946. * Creates a matcher that checks if all elements in a range are equal
  9947. * to all elements in another range.
  9948. *
  9949. * Uses `std::equal_to` to do the comparison
  9950. */
  9951. template <typename RangeLike>
  9952. std::enable_if_t<!Detail::is_matcher<RangeLike>::value,
  9953. RangeEqualsMatcher<RangeLike, std::equal_to<>>>
  9954. RangeEquals( RangeLike&& range ) {
  9955. return { CATCH_FORWARD( range ), std::equal_to<>{} };
  9956. }
  9957. /**
  9958. * Creates a matcher that checks if all elements in a range are equal
  9959. * to all elements in another range.
  9960. *
  9961. * Uses to provided predicate `predicate` to do the comparisons
  9962. */
  9963. template <typename RangeLike, typename Equality>
  9964. RangeEqualsMatcher<RangeLike, Equality>
  9965. RangeEquals( RangeLike&& range, Equality&& predicate ) {
  9966. return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
  9967. }
  9968. /**
  9969. * Creates a matcher that checks if all elements in a range are equal
  9970. * to all elements in another range, in some permutation
  9971. *
  9972. * Uses `std::equal_to` to do the comparison
  9973. */
  9974. template <typename RangeLike>
  9975. std::enable_if_t<
  9976. !Detail::is_matcher<RangeLike>::value,
  9977. UnorderedRangeEqualsMatcher<RangeLike, std::equal_to<>>>
  9978. UnorderedRangeEquals( RangeLike&& range ) {
  9979. return { CATCH_FORWARD( range ), std::equal_to<>{} };
  9980. }
  9981. /**
  9982. * Creates a matcher that checks if all elements in a range are equal
  9983. * to all elements in another range, in some permutation.
  9984. *
  9985. * Uses to provided predicate `predicate` to do the comparisons
  9986. */
  9987. template <typename RangeLike, typename Equality>
  9988. UnorderedRangeEqualsMatcher<RangeLike, Equality>
  9989. UnorderedRangeEquals( RangeLike&& range, Equality&& predicate ) {
  9990. return { CATCH_FORWARD( range ), CATCH_FORWARD( predicate ) };
  9991. }
  9992. } // namespace Matchers
  9993. } // namespace Catch
  9994. #endif // CATCH_MATCHERS_RANGE_EQUALS_HPP_INCLUDED
  9995. #ifndef CATCH_MATCHERS_STRING_HPP_INCLUDED
  9996. #define CATCH_MATCHERS_STRING_HPP_INCLUDED
  9997. #include <string>
  9998. namespace Catch {
  9999. namespace Matchers {
  10000. struct CasedString {
  10001. CasedString( std::string const& str, CaseSensitive caseSensitivity );
  10002. std::string adjustString( std::string const& str ) const;
  10003. StringRef caseSensitivitySuffix() const;
  10004. CaseSensitive m_caseSensitivity;
  10005. std::string m_str;
  10006. };
  10007. class StringMatcherBase : public MatcherBase<std::string> {
  10008. protected:
  10009. CasedString m_comparator;
  10010. StringRef m_operation;
  10011. public:
  10012. StringMatcherBase( StringRef operation,
  10013. CasedString const& comparator );
  10014. std::string describe() const override;
  10015. };
  10016. class StringEqualsMatcher final : public StringMatcherBase {
  10017. public:
  10018. StringEqualsMatcher( CasedString const& comparator );
  10019. bool match( std::string const& source ) const override;
  10020. };
  10021. class StringContainsMatcher final : public StringMatcherBase {
  10022. public:
  10023. StringContainsMatcher( CasedString const& comparator );
  10024. bool match( std::string const& source ) const override;
  10025. };
  10026. class StartsWithMatcher final : public StringMatcherBase {
  10027. public:
  10028. StartsWithMatcher( CasedString const& comparator );
  10029. bool match( std::string const& source ) const override;
  10030. };
  10031. class EndsWithMatcher final : public StringMatcherBase {
  10032. public:
  10033. EndsWithMatcher( CasedString const& comparator );
  10034. bool match( std::string const& source ) const override;
  10035. };
  10036. class RegexMatcher final : public MatcherBase<std::string> {
  10037. std::string m_regex;
  10038. CaseSensitive m_caseSensitivity;
  10039. public:
  10040. RegexMatcher( std::string regex, CaseSensitive caseSensitivity );
  10041. bool match( std::string const& matchee ) const override;
  10042. std::string describe() const override;
  10043. };
  10044. //! Creates matcher that accepts strings that are exactly equal to `str`
  10045. StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  10046. //! Creates matcher that accepts strings that contain `str`
  10047. StringContainsMatcher ContainsSubstring( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  10048. //! Creates matcher that accepts strings that _end_ with `str`
  10049. EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  10050. //! Creates matcher that accepts strings that _start_ with `str`
  10051. StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  10052. //! Creates matcher that accepts strings matching `regex`
  10053. RegexMatcher Matches( std::string const& regex, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  10054. } // namespace Matchers
  10055. } // namespace Catch
  10056. #endif // CATCH_MATCHERS_STRING_HPP_INCLUDED
  10057. #ifndef CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  10058. #define CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  10059. #include <algorithm>
  10060. namespace Catch {
  10061. namespace Matchers {
  10062. template<typename T, typename Alloc>
  10063. class VectorContainsElementMatcher final : public MatcherBase<std::vector<T, Alloc>> {
  10064. T const& m_comparator;
  10065. public:
  10066. VectorContainsElementMatcher(T const& comparator):
  10067. m_comparator(comparator)
  10068. {}
  10069. bool match(std::vector<T, Alloc> const& v) const override {
  10070. for (auto const& el : v) {
  10071. if (el == m_comparator) {
  10072. return true;
  10073. }
  10074. }
  10075. return false;
  10076. }
  10077. std::string describe() const override {
  10078. return "Contains: " + ::Catch::Detail::stringify( m_comparator );
  10079. }
  10080. };
  10081. template<typename T, typename AllocComp, typename AllocMatch>
  10082. class ContainsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  10083. std::vector<T, AllocComp> const& m_comparator;
  10084. public:
  10085. ContainsMatcher(std::vector<T, AllocComp> const& comparator):
  10086. m_comparator( comparator )
  10087. {}
  10088. bool match(std::vector<T, AllocMatch> const& v) const override {
  10089. // !TBD: see note in EqualsMatcher
  10090. if (m_comparator.size() > v.size())
  10091. return false;
  10092. for (auto const& comparator : m_comparator) {
  10093. auto present = false;
  10094. for (const auto& el : v) {
  10095. if (el == comparator) {
  10096. present = true;
  10097. break;
  10098. }
  10099. }
  10100. if (!present) {
  10101. return false;
  10102. }
  10103. }
  10104. return true;
  10105. }
  10106. std::string describe() const override {
  10107. return "Contains: " + ::Catch::Detail::stringify( m_comparator );
  10108. }
  10109. };
  10110. template<typename T, typename AllocComp, typename AllocMatch>
  10111. class EqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  10112. std::vector<T, AllocComp> const& m_comparator;
  10113. public:
  10114. EqualsMatcher(std::vector<T, AllocComp> const& comparator):
  10115. m_comparator( comparator )
  10116. {}
  10117. bool match(std::vector<T, AllocMatch> const& v) const override {
  10118. // !TBD: This currently works if all elements can be compared using !=
  10119. // - a more general approach would be via a compare template that defaults
  10120. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  10121. // - then just call that directly
  10122. if ( m_comparator.size() != v.size() ) { return false; }
  10123. for ( std::size_t i = 0; i < v.size(); ++i ) {
  10124. if ( !( m_comparator[i] == v[i] ) ) { return false; }
  10125. }
  10126. return true;
  10127. }
  10128. std::string describe() const override {
  10129. return "Equals: " + ::Catch::Detail::stringify( m_comparator );
  10130. }
  10131. };
  10132. template<typename T, typename AllocComp, typename AllocMatch>
  10133. class ApproxMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  10134. std::vector<T, AllocComp> const& m_comparator;
  10135. mutable Catch::Approx approx = Catch::Approx::custom();
  10136. public:
  10137. ApproxMatcher(std::vector<T, AllocComp> const& comparator):
  10138. m_comparator( comparator )
  10139. {}
  10140. bool match(std::vector<T, AllocMatch> const& v) const override {
  10141. if (m_comparator.size() != v.size())
  10142. return false;
  10143. for (std::size_t i = 0; i < v.size(); ++i)
  10144. if (m_comparator[i] != approx(v[i]))
  10145. return false;
  10146. return true;
  10147. }
  10148. std::string describe() const override {
  10149. return "is approx: " + ::Catch::Detail::stringify( m_comparator );
  10150. }
  10151. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  10152. ApproxMatcher& epsilon( T const& newEpsilon ) {
  10153. approx.epsilon(static_cast<double>(newEpsilon));
  10154. return *this;
  10155. }
  10156. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  10157. ApproxMatcher& margin( T const& newMargin ) {
  10158. approx.margin(static_cast<double>(newMargin));
  10159. return *this;
  10160. }
  10161. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  10162. ApproxMatcher& scale( T const& newScale ) {
  10163. approx.scale(static_cast<double>(newScale));
  10164. return *this;
  10165. }
  10166. };
  10167. template<typename T, typename AllocComp, typename AllocMatch>
  10168. class UnorderedEqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  10169. std::vector<T, AllocComp> const& m_target;
  10170. public:
  10171. UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target):
  10172. m_target(target)
  10173. {}
  10174. bool match(std::vector<T, AllocMatch> const& vec) const override {
  10175. if (m_target.size() != vec.size()) {
  10176. return false;
  10177. }
  10178. return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
  10179. }
  10180. std::string describe() const override {
  10181. return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
  10182. }
  10183. };
  10184. // The following functions create the actual matcher objects.
  10185. // This allows the types to be inferred
  10186. //! Creates a matcher that matches vectors that contain all elements in `comparator`
  10187. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  10188. ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) {
  10189. return ContainsMatcher<T, AllocComp, AllocMatch>(comparator);
  10190. }
  10191. //! Creates a matcher that matches vectors that contain `comparator` as an element
  10192. template<typename T, typename Alloc = std::allocator<T>>
  10193. VectorContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) {
  10194. return VectorContainsElementMatcher<T, Alloc>(comparator);
  10195. }
  10196. //! Creates a matcher that matches vectors that are exactly equal to `comparator`
  10197. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  10198. EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) {
  10199. return EqualsMatcher<T, AllocComp, AllocMatch>(comparator);
  10200. }
  10201. //! Creates a matcher that matches vectors that `comparator` as an element
  10202. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  10203. ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) {
  10204. return ApproxMatcher<T, AllocComp, AllocMatch>(comparator);
  10205. }
  10206. //! Creates a matcher that matches vectors that is equal to `target` modulo permutation
  10207. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  10208. UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) {
  10209. return UnorderedEqualsMatcher<T, AllocComp, AllocMatch>(target);
  10210. }
  10211. } // namespace Matchers
  10212. } // namespace Catch
  10213. #endif // CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  10214. #endif // CATCH_MATCHERS_ALL_HPP_INCLUDED
  10215. /** \file
  10216. * This is a convenience header for Catch2's Reporter support. It includes
  10217. * **all** of Catch2 headers related to reporters, including all reporters.
  10218. *
  10219. * Generally the Catch2 users should use specific includes they need,
  10220. * but this header can be used instead for ease-of-experimentation, or
  10221. * just plain convenience, at the cost of (significantly) increased
  10222. * compilation times.
  10223. *
  10224. * When a new header (reporter) is added to either the `reporter` folder,
  10225. * or to the corresponding internal subfolder, it should be added here.
  10226. */
  10227. #ifndef CATCH_REPORTERS_ALL_HPP_INCLUDED
  10228. #define CATCH_REPORTERS_ALL_HPP_INCLUDED
  10229. #ifndef CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  10230. #define CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  10231. #ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  10232. #define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  10233. #ifndef CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  10234. #define CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  10235. #include <map>
  10236. #include <string>
  10237. namespace Catch {
  10238. class ColourImpl;
  10239. /**
  10240. * This is the base class for all reporters.
  10241. *
  10242. * If are writing a reporter, you must derive from this type, or one
  10243. * of the helper reporter bases that are derived from this type.
  10244. *
  10245. * ReporterBase centralizes handling of various common tasks in reporters,
  10246. * like storing the right stream for the reporters to write to, and
  10247. * providing the default implementation of the different listing events.
  10248. */
  10249. class ReporterBase : public IEventListener {
  10250. protected:
  10251. //! The stream wrapper as passed to us by outside code
  10252. Detail::unique_ptr<IStream> m_wrapped_stream;
  10253. //! Cached output stream from `m_wrapped_stream` to reduce
  10254. //! number of indirect calls needed to write output.
  10255. std::ostream& m_stream;
  10256. //! Colour implementation this reporter was configured for
  10257. Detail::unique_ptr<ColourImpl> m_colour;
  10258. //! The custom reporter options user passed down to the reporter
  10259. std::map<std::string, std::string> m_customOptions;
  10260. public:
  10261. ReporterBase( ReporterConfig&& config );
  10262. ~ReporterBase() override; // = default;
  10263. /**
  10264. * Provides a simple default listing of reporters.
  10265. *
  10266. * Should look roughly like the reporter listing in v2 and earlier
  10267. * versions of Catch2.
  10268. */
  10269. void listReporters(
  10270. std::vector<ReporterDescription> const& descriptions ) override;
  10271. /**
  10272. * Provides a simple default listing of listeners
  10273. *
  10274. * Looks similarly to listing of reporters, but with listener type
  10275. * instead of reporter name.
  10276. */
  10277. void listListeners(
  10278. std::vector<ListenerDescription> const& descriptions ) override;
  10279. /**
  10280. * Provides a simple default listing of tests.
  10281. *
  10282. * Should look roughly like the test listing in v2 and earlier versions
  10283. * of Catch2. Especially supports low-verbosity listing that mimics the
  10284. * old `--list-test-names-only` output.
  10285. */
  10286. void listTests( std::vector<TestCaseHandle> const& tests ) override;
  10287. /**
  10288. * Provides a simple default listing of tags.
  10289. *
  10290. * Should look roughly like the tag listing in v2 and earlier versions
  10291. * of Catch2.
  10292. */
  10293. void listTags( std::vector<TagInfo> const& tags ) override;
  10294. };
  10295. } // namespace Catch
  10296. #endif // CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  10297. #include <vector>
  10298. namespace Catch {
  10299. class StreamingReporterBase : public ReporterBase {
  10300. public:
  10301. // GCC5 compat: we cannot use inherited constructor, because it
  10302. // doesn't implement backport of P0136
  10303. StreamingReporterBase(ReporterConfig&& _config):
  10304. ReporterBase(CATCH_MOVE(_config))
  10305. {}
  10306. ~StreamingReporterBase() override;
  10307. void benchmarkPreparing( StringRef ) override {}
  10308. void benchmarkStarting( BenchmarkInfo const& ) override {}
  10309. void benchmarkEnded( BenchmarkStats<> const& ) override {}
  10310. void benchmarkFailed( StringRef ) override {}
  10311. void fatalErrorEncountered( StringRef /*error*/ ) override {}
  10312. void noMatchingTestCases( StringRef /*unmatchedSpec*/ ) override {}
  10313. void reportInvalidTestSpec( StringRef /*invalidArgument*/ ) override {}
  10314. void testRunStarting( TestRunInfo const& _testRunInfo ) override;
  10315. void testCaseStarting(TestCaseInfo const& _testInfo) override {
  10316. currentTestCaseInfo = &_testInfo;
  10317. }
  10318. void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
  10319. void sectionStarting(SectionInfo const& _sectionInfo) override {
  10320. m_sectionStack.push_back(_sectionInfo);
  10321. }
  10322. void assertionStarting( AssertionInfo const& ) override {}
  10323. void assertionEnded( AssertionStats const& ) override {}
  10324. void sectionEnded(SectionStats const& /* _sectionStats */) override {
  10325. m_sectionStack.pop_back();
  10326. }
  10327. void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
  10328. void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
  10329. currentTestCaseInfo = nullptr;
  10330. }
  10331. void testRunEnded( TestRunStats const& /* _testRunStats */ ) override;
  10332. void skipTest(TestCaseInfo const&) override {
  10333. // Don't do anything with this by default.
  10334. // It can optionally be overridden in the derived class.
  10335. }
  10336. protected:
  10337. TestRunInfo currentTestRunInfo{ "test run has not started yet"_sr };
  10338. TestCaseInfo const* currentTestCaseInfo = nullptr;
  10339. //! Stack of all _active_ sections in the _current_ test case
  10340. std::vector<SectionInfo> m_sectionStack;
  10341. };
  10342. } // end namespace Catch
  10343. #endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  10344. #include <string>
  10345. namespace Catch {
  10346. class AutomakeReporter final : public StreamingReporterBase {
  10347. public:
  10348. // GCC5 compat: we cannot use inherited constructor, because it
  10349. // doesn't implement backport of P0136
  10350. AutomakeReporter(ReporterConfig&& _config):
  10351. StreamingReporterBase(CATCH_MOVE(_config))
  10352. {}
  10353. ~AutomakeReporter() override;
  10354. static std::string getDescription() {
  10355. using namespace std::string_literals;
  10356. return "Reports test results in the format of Automake .trs files"s;
  10357. }
  10358. void testCaseEnded(TestCaseStats const& _testCaseStats) override;
  10359. void skipTest(TestCaseInfo const& testInfo) override;
  10360. };
  10361. } // end namespace Catch
  10362. #endif // CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  10363. #ifndef CATCH_REPORTER_COMPACT_HPP_INCLUDED
  10364. #define CATCH_REPORTER_COMPACT_HPP_INCLUDED
  10365. namespace Catch {
  10366. class CompactReporter final : public StreamingReporterBase {
  10367. public:
  10368. using StreamingReporterBase::StreamingReporterBase;
  10369. ~CompactReporter() override;
  10370. static std::string getDescription();
  10371. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  10372. void testRunStarting( TestRunInfo const& _testInfo ) override;
  10373. void assertionEnded(AssertionStats const& _assertionStats) override;
  10374. void sectionEnded(SectionStats const& _sectionStats) override;
  10375. void testRunEnded(TestRunStats const& _testRunStats) override;
  10376. };
  10377. } // end namespace Catch
  10378. #endif // CATCH_REPORTER_COMPACT_HPP_INCLUDED
  10379. #ifndef CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  10380. #define CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  10381. namespace Catch {
  10382. // Fwd decls
  10383. class TablePrinter;
  10384. class ConsoleReporter final : public StreamingReporterBase {
  10385. Detail::unique_ptr<TablePrinter> m_tablePrinter;
  10386. public:
  10387. ConsoleReporter(ReporterConfig&& config);
  10388. ~ConsoleReporter() override;
  10389. static std::string getDescription();
  10390. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  10391. void reportInvalidTestSpec( StringRef arg ) override;
  10392. void assertionStarting(AssertionInfo const&) override;
  10393. void assertionEnded(AssertionStats const& _assertionStats) override;
  10394. void sectionStarting(SectionInfo const& _sectionInfo) override;
  10395. void sectionEnded(SectionStats const& _sectionStats) override;
  10396. void benchmarkPreparing( StringRef name ) override;
  10397. void benchmarkStarting(BenchmarkInfo const& info) override;
  10398. void benchmarkEnded(BenchmarkStats<> const& stats) override;
  10399. void benchmarkFailed( StringRef error ) override;
  10400. void testCaseEnded(TestCaseStats const& _testCaseStats) override;
  10401. void testRunEnded(TestRunStats const& _testRunStats) override;
  10402. void testRunStarting(TestRunInfo const& _testRunInfo) override;
  10403. private:
  10404. void lazyPrint();
  10405. void lazyPrintWithoutClosingBenchmarkTable();
  10406. void lazyPrintRunInfo();
  10407. void printTestCaseAndSectionHeader();
  10408. void printClosedHeader(std::string const& _name);
  10409. void printOpenHeader(std::string const& _name);
  10410. // if string has a : in first line will set indent to follow it on
  10411. // subsequent lines
  10412. void printHeaderString(std::string const& _string, std::size_t indent = 0);
  10413. void printTotalsDivider(Totals const& totals);
  10414. bool m_headerPrinted = false;
  10415. bool m_testRunInfoPrinted = false;
  10416. };
  10417. } // end namespace Catch
  10418. #endif // CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  10419. #ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  10420. #define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  10421. #include <string>
  10422. #include <vector>
  10423. namespace Catch {
  10424. namespace Detail {
  10425. //! Represents either an assertion or a benchmark result to be handled by cumulative reporter later
  10426. class AssertionOrBenchmarkResult {
  10427. // This should really be a variant, but this is much faster
  10428. // to write and the data layout here is already terrible
  10429. // enough that we do not have to care about the object size.
  10430. Optional<AssertionStats> m_assertion;
  10431. Optional<BenchmarkStats<>> m_benchmark;
  10432. public:
  10433. AssertionOrBenchmarkResult(AssertionStats const& assertion);
  10434. AssertionOrBenchmarkResult(BenchmarkStats<> const& benchmark);
  10435. bool isAssertion() const;
  10436. bool isBenchmark() const;
  10437. AssertionStats const& asAssertion() const;
  10438. BenchmarkStats<> const& asBenchmark() const;
  10439. };
  10440. }
  10441. /**
  10442. * Utility base for reporters that need to handle all results at once
  10443. *
  10444. * It stores tree of all test cases, sections and assertions, and after the
  10445. * test run is finished, calls into `testRunEndedCumulative` to pass the
  10446. * control to the deriving class.
  10447. *
  10448. * If you are deriving from this class and override any testing related
  10449. * member functions, you should first call into the base's implementation to
  10450. * avoid breaking the tree construction.
  10451. *
  10452. * Due to the way this base functions, it has to expand assertions up-front,
  10453. * even if they are later unused (e.g. because the deriving reporter does
  10454. * not report successful assertions, or because the deriving reporter does
  10455. * not use assertion expansion at all). Derived classes can use two
  10456. * customization points, `m_shouldStoreSuccesfulAssertions` and
  10457. * `m_shouldStoreFailedAssertions`, to disable the expansion and gain extra
  10458. * performance. **Accessing the assertion expansions if it wasn't stored is
  10459. * UB.**
  10460. */
  10461. class CumulativeReporterBase : public ReporterBase {
  10462. public:
  10463. template<typename T, typename ChildNodeT>
  10464. struct Node {
  10465. explicit Node( T const& _value ) : value( _value ) {}
  10466. using ChildNodes = std::vector<Detail::unique_ptr<ChildNodeT>>;
  10467. T value;
  10468. ChildNodes children;
  10469. };
  10470. struct SectionNode {
  10471. explicit SectionNode(SectionStats const& _stats) : stats(_stats) {}
  10472. bool operator == (SectionNode const& other) const {
  10473. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  10474. }
  10475. bool hasAnyAssertions() const;
  10476. SectionStats stats;
  10477. std::vector<Detail::unique_ptr<SectionNode>> childSections;
  10478. std::vector<Detail::AssertionOrBenchmarkResult> assertionsAndBenchmarks;
  10479. std::string stdOut;
  10480. std::string stdErr;
  10481. };
  10482. using TestCaseNode = Node<TestCaseStats, SectionNode>;
  10483. using TestRunNode = Node<TestRunStats, TestCaseNode>;
  10484. // GCC5 compat: we cannot use inherited constructor, because it
  10485. // doesn't implement backport of P0136
  10486. CumulativeReporterBase(ReporterConfig&& _config):
  10487. ReporterBase(CATCH_MOVE(_config))
  10488. {}
  10489. ~CumulativeReporterBase() override;
  10490. void benchmarkPreparing( StringRef ) override {}
  10491. void benchmarkStarting( BenchmarkInfo const& ) override {}
  10492. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  10493. void benchmarkFailed( StringRef ) override {}
  10494. void noMatchingTestCases( StringRef ) override {}
  10495. void reportInvalidTestSpec( StringRef ) override {}
  10496. void fatalErrorEncountered( StringRef /*error*/ ) override {}
  10497. void testRunStarting( TestRunInfo const& ) override {}
  10498. void testCaseStarting( TestCaseInfo const& ) override {}
  10499. void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
  10500. void sectionStarting( SectionInfo const& sectionInfo ) override;
  10501. void assertionStarting( AssertionInfo const& ) override {}
  10502. void assertionEnded( AssertionStats const& assertionStats ) override;
  10503. void sectionEnded( SectionStats const& sectionStats ) override;
  10504. void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
  10505. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  10506. void testRunEnded( TestRunStats const& testRunStats ) override;
  10507. //! Customization point: called after last test finishes (testRunEnded has been handled)
  10508. virtual void testRunEndedCumulative() = 0;
  10509. void skipTest(TestCaseInfo const&) override {}
  10510. protected:
  10511. //! Should the cumulative base store the assertion expansion for successful assertions?
  10512. bool m_shouldStoreSuccesfulAssertions = true;
  10513. //! Should the cumulative base store the assertion expansion for failed assertions?
  10514. bool m_shouldStoreFailedAssertions = true;
  10515. // We need lazy construction here. We should probably refactor it
  10516. // later, after the events are redone.
  10517. //! The root node of the test run tree.
  10518. Detail::unique_ptr<TestRunNode> m_testRun;
  10519. private:
  10520. // Note: We rely on pointer identity being stable, which is why
  10521. // we store pointers to the nodes rather than the values.
  10522. std::vector<Detail::unique_ptr<TestCaseNode>> m_testCases;
  10523. // Root section of the _current_ test case
  10524. Detail::unique_ptr<SectionNode> m_rootSection;
  10525. // Deepest section of the _current_ test case
  10526. SectionNode* m_deepestSection = nullptr;
  10527. // Stack of _active_ sections in the _current_ test case
  10528. std::vector<SectionNode*> m_sectionStack;
  10529. };
  10530. } // end namespace Catch
  10531. #endif // CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  10532. #ifndef CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  10533. #define CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  10534. namespace Catch {
  10535. /**
  10536. * Base class to simplify implementing listeners.
  10537. *
  10538. * Provides empty default implementation for all IEventListener member
  10539. * functions, so that a listener implementation can pick which
  10540. * member functions it actually cares about.
  10541. */
  10542. class EventListenerBase : public IEventListener {
  10543. public:
  10544. using IEventListener::IEventListener;
  10545. void reportInvalidTestSpec( StringRef unmatchedSpec ) override;
  10546. void fatalErrorEncountered( StringRef error ) override;
  10547. void benchmarkPreparing( StringRef name ) override;
  10548. void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
  10549. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  10550. void benchmarkFailed( StringRef error ) override;
  10551. void assertionStarting( AssertionInfo const& assertionInfo ) override;
  10552. void assertionEnded( AssertionStats const& assertionStats ) override;
  10553. void listReporters(
  10554. std::vector<ReporterDescription> const& descriptions ) override;
  10555. void listListeners(
  10556. std::vector<ListenerDescription> const& descriptions ) override;
  10557. void listTests( std::vector<TestCaseHandle> const& tests ) override;
  10558. void listTags( std::vector<TagInfo> const& tagInfos ) override;
  10559. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  10560. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  10561. void testCaseStarting( TestCaseInfo const& testInfo ) override;
  10562. void testCasePartialStarting( TestCaseInfo const& testInfo,
  10563. uint64_t partNumber ) override;
  10564. void sectionStarting( SectionInfo const& sectionInfo ) override;
  10565. void sectionEnded( SectionStats const& sectionStats ) override;
  10566. void testCasePartialEnded( TestCaseStats const& testCaseStats,
  10567. uint64_t partNumber ) override;
  10568. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  10569. void testRunEnded( TestRunStats const& testRunStats ) override;
  10570. void skipTest( TestCaseInfo const& testInfo ) override;
  10571. };
  10572. } // end namespace Catch
  10573. #endif // CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  10574. #ifndef CATCH_REPORTER_HELPERS_HPP_INCLUDED
  10575. #define CATCH_REPORTER_HELPERS_HPP_INCLUDED
  10576. #include <iosfwd>
  10577. #include <string>
  10578. #include <vector>
  10579. namespace Catch {
  10580. class IConfig;
  10581. class TestCaseHandle;
  10582. class ColourImpl;
  10583. // Returns double formatted as %.3f (format expected on output)
  10584. std::string getFormattedDuration( double duration );
  10585. //! Should the reporter show duration of test given current configuration?
  10586. bool shouldShowDuration( IConfig const& config, double duration );
  10587. std::string serializeFilters( std::vector<std::string> const& filters );
  10588. struct lineOfChars {
  10589. char c;
  10590. constexpr lineOfChars( char c_ ): c( c_ ) {}
  10591. friend std::ostream& operator<<( std::ostream& out, lineOfChars value );
  10592. };
  10593. /**
  10594. * Lists reporter descriptions to the provided stream in user-friendly
  10595. * format
  10596. *
  10597. * Used as the default listing implementation by the first party reporter
  10598. * bases. The output should be backwards compatible with the output of
  10599. * Catch2 v2 binaries.
  10600. */
  10601. void
  10602. defaultListReporters( std::ostream& out,
  10603. std::vector<ReporterDescription> const& descriptions,
  10604. Verbosity verbosity );
  10605. /**
  10606. * Lists listeners descriptions to the provided stream in user-friendly
  10607. * format
  10608. */
  10609. void defaultListListeners( std::ostream& out,
  10610. std::vector<ListenerDescription> const& descriptions );
  10611. /**
  10612. * Lists tag information to the provided stream in user-friendly format
  10613. *
  10614. * Used as the default listing implementation by the first party reporter
  10615. * bases. The output should be backwards compatible with the output of
  10616. * Catch2 v2 binaries.
  10617. */
  10618. void defaultListTags( std::ostream& out, std::vector<TagInfo> const& tags, bool isFiltered );
  10619. /**
  10620. * Lists test case information to the provided stream in user-friendly
  10621. * format
  10622. *
  10623. * Used as the default listing implementation by the first party reporter
  10624. * bases. The output is backwards compatible with the output of Catch2
  10625. * v2 binaries, and also supports the format specific to the old
  10626. * `--list-test-names-only` option, for people who used it in integrations.
  10627. */
  10628. void defaultListTests( std::ostream& out,
  10629. ColourImpl* streamColour,
  10630. std::vector<TestCaseHandle> const& tests,
  10631. bool isFiltered,
  10632. Verbosity verbosity );
  10633. /**
  10634. * Prints test run totals to the provided stream in user-friendly format
  10635. *
  10636. * Used by the console and compact reporters.
  10637. */
  10638. void printTestRunTotals( std::ostream& stream,
  10639. ColourImpl& streamColour,
  10640. Totals const& totals );
  10641. } // end namespace Catch
  10642. #endif // CATCH_REPORTER_HELPERS_HPP_INCLUDED
  10643. #ifndef CATCH_REPORTER_JSON_HPP_INCLUDED
  10644. #define CATCH_REPORTER_JSON_HPP_INCLUDED
  10645. #include <stack>
  10646. namespace Catch {
  10647. class JsonReporter : public StreamingReporterBase {
  10648. public:
  10649. JsonReporter( ReporterConfig&& config );
  10650. ~JsonReporter() override;
  10651. static std::string getDescription();
  10652. public: // StreamingReporterBase
  10653. void testRunStarting( TestRunInfo const& runInfo ) override;
  10654. void testRunEnded( TestRunStats const& runStats ) override;
  10655. void testCaseStarting( TestCaseInfo const& tcInfo ) override;
  10656. void testCaseEnded( TestCaseStats const& tcStats ) override;
  10657. void testCasePartialStarting( TestCaseInfo const& tcInfo,
  10658. uint64_t index ) override;
  10659. void testCasePartialEnded( TestCaseStats const& tcStats,
  10660. uint64_t index ) override;
  10661. void sectionStarting( SectionInfo const& sectionInfo ) override;
  10662. void sectionEnded( SectionStats const& sectionStats ) override;
  10663. void assertionStarting( AssertionInfo const& assertionInfo ) override;
  10664. void assertionEnded( AssertionStats const& assertionStats ) override;
  10665. //void testRunEndedCumulative() override;
  10666. void benchmarkPreparing( StringRef name ) override;
  10667. void benchmarkStarting( BenchmarkInfo const& ) override;
  10668. void benchmarkEnded( BenchmarkStats<> const& ) override;
  10669. void benchmarkFailed( StringRef error ) override;
  10670. void listReporters(
  10671. std::vector<ReporterDescription> const& descriptions ) override;
  10672. void listListeners(
  10673. std::vector<ListenerDescription> const& descriptions ) override;
  10674. void listTests( std::vector<TestCaseHandle> const& tests ) override;
  10675. void listTags( std::vector<TagInfo> const& tags ) override;
  10676. private:
  10677. Timer m_testCaseTimer;
  10678. enum class Writer {
  10679. Object,
  10680. Array
  10681. };
  10682. JsonArrayWriter& startArray();
  10683. JsonArrayWriter& startArray( StringRef key );
  10684. JsonObjectWriter& startObject();
  10685. JsonObjectWriter& startObject( StringRef key );
  10686. void endObject();
  10687. void endArray();
  10688. bool isInside( Writer writer );
  10689. void startListing();
  10690. void endListing();
  10691. // Invariant:
  10692. // When m_writers is not empty and its top element is
  10693. // - Writer::Object, then m_objectWriters is not be empty
  10694. // - Writer::Array, then m_arrayWriters shall not be empty
  10695. std::stack<JsonObjectWriter> m_objectWriters{};
  10696. std::stack<JsonArrayWriter> m_arrayWriters{};
  10697. std::stack<Writer> m_writers{};
  10698. bool m_startedListing = false;
  10699. // std::size_t m_sectionDepth = 0;
  10700. // std::size_t m_sectionStarted = 0;
  10701. };
  10702. } // namespace Catch
  10703. #endif // CATCH_REPORTER_JSON_HPP_INCLUDED
  10704. #ifndef CATCH_REPORTER_JUNIT_HPP_INCLUDED
  10705. #define CATCH_REPORTER_JUNIT_HPP_INCLUDED
  10706. namespace Catch {
  10707. class JunitReporter final : public CumulativeReporterBase {
  10708. public:
  10709. JunitReporter(ReporterConfig&& _config);
  10710. static std::string getDescription();
  10711. void testRunStarting(TestRunInfo const& runInfo) override;
  10712. void testCaseStarting(TestCaseInfo const& testCaseInfo) override;
  10713. void assertionEnded(AssertionStats const& assertionStats) override;
  10714. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  10715. void testRunEndedCumulative() override;
  10716. private:
  10717. void writeRun(TestRunNode const& testRunNode, double suiteTime);
  10718. void writeTestCase(TestCaseNode const& testCaseNode);
  10719. void writeSection( std::string const& className,
  10720. std::string const& rootName,
  10721. SectionNode const& sectionNode,
  10722. bool testOkToFail );
  10723. void writeAssertions(SectionNode const& sectionNode);
  10724. void writeAssertion(AssertionStats const& stats);
  10725. XmlWriter xml;
  10726. Timer suiteTimer;
  10727. std::string stdOutForSuite;
  10728. std::string stdErrForSuite;
  10729. unsigned int unexpectedExceptions = 0;
  10730. bool m_okToFail = false;
  10731. };
  10732. } // end namespace Catch
  10733. #endif // CATCH_REPORTER_JUNIT_HPP_INCLUDED
  10734. #ifndef CATCH_REPORTER_MULTI_HPP_INCLUDED
  10735. #define CATCH_REPORTER_MULTI_HPP_INCLUDED
  10736. namespace Catch {
  10737. class MultiReporter final : public IEventListener {
  10738. /*
  10739. * Stores all added reporters and listeners
  10740. *
  10741. * All Listeners are stored before all reporters, and individual
  10742. * listeners/reporters are stored in order of insertion.
  10743. */
  10744. std::vector<IEventListenerPtr> m_reporterLikes;
  10745. bool m_haveNoncapturingReporters = false;
  10746. // Keep track of how many listeners we have already inserted,
  10747. // so that we can insert them into the main vector at the right place
  10748. size_t m_insertedListeners = 0;
  10749. void updatePreferences(IEventListener const& reporterish);
  10750. public:
  10751. using IEventListener::IEventListener;
  10752. void addListener( IEventListenerPtr&& listener );
  10753. void addReporter( IEventListenerPtr&& reporter );
  10754. public: // IEventListener
  10755. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  10756. void fatalErrorEncountered( StringRef error ) override;
  10757. void reportInvalidTestSpec( StringRef arg ) override;
  10758. void benchmarkPreparing( StringRef name ) override;
  10759. void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
  10760. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  10761. void benchmarkFailed( StringRef error ) override;
  10762. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  10763. void testCaseStarting( TestCaseInfo const& testInfo ) override;
  10764. void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override;
  10765. void sectionStarting( SectionInfo const& sectionInfo ) override;
  10766. void assertionStarting( AssertionInfo const& assertionInfo ) override;
  10767. void assertionEnded( AssertionStats const& assertionStats ) override;
  10768. void sectionEnded( SectionStats const& sectionStats ) override;
  10769. void testCasePartialEnded(TestCaseStats const& testStats, uint64_t partNumber) override;
  10770. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  10771. void testRunEnded( TestRunStats const& testRunStats ) override;
  10772. void skipTest( TestCaseInfo const& testInfo ) override;
  10773. void listReporters(std::vector<ReporterDescription> const& descriptions) override;
  10774. void listListeners(std::vector<ListenerDescription> const& descriptions) override;
  10775. void listTests(std::vector<TestCaseHandle> const& tests) override;
  10776. void listTags(std::vector<TagInfo> const& tags) override;
  10777. };
  10778. } // end namespace Catch
  10779. #endif // CATCH_REPORTER_MULTI_HPP_INCLUDED
  10780. #ifndef CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  10781. #define CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  10782. #include <type_traits>
  10783. namespace Catch {
  10784. namespace Detail {
  10785. template <typename T, typename = void>
  10786. struct has_description : std::false_type {};
  10787. template <typename T>
  10788. struct has_description<
  10789. T,
  10790. void_t<decltype( T::getDescription() )>>
  10791. : std::true_type {};
  10792. //! Indirection for reporter registration, so that the error handling is
  10793. //! independent on the reporter's concrete type
  10794. void registerReporterImpl( std::string const& name,
  10795. IReporterFactoryPtr reporterPtr );
  10796. //! Actually registers the factory, independent on listener's concrete type
  10797. void registerListenerImpl( Detail::unique_ptr<EventListenerFactory> listenerFactory );
  10798. } // namespace Detail
  10799. class IEventListener;
  10800. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  10801. template <typename T>
  10802. class ReporterFactory : public IReporterFactory {
  10803. IEventListenerPtr create( ReporterConfig&& config ) const override {
  10804. return Detail::make_unique<T>( CATCH_MOVE(config) );
  10805. }
  10806. std::string getDescription() const override {
  10807. return T::getDescription();
  10808. }
  10809. };
  10810. template<typename T>
  10811. class ReporterRegistrar {
  10812. public:
  10813. explicit ReporterRegistrar( std::string const& name ) {
  10814. registerReporterImpl( name,
  10815. Detail::make_unique<ReporterFactory<T>>() );
  10816. }
  10817. };
  10818. template<typename T>
  10819. class ListenerRegistrar {
  10820. class TypedListenerFactory : public EventListenerFactory {
  10821. StringRef m_listenerName;
  10822. std::string getDescriptionImpl( std::true_type ) const {
  10823. return T::getDescription();
  10824. }
  10825. std::string getDescriptionImpl( std::false_type ) const {
  10826. return "(No description provided)";
  10827. }
  10828. public:
  10829. TypedListenerFactory( StringRef listenerName ):
  10830. m_listenerName( listenerName ) {}
  10831. IEventListenerPtr create( IConfig const* config ) const override {
  10832. return Detail::make_unique<T>( config );
  10833. }
  10834. StringRef getName() const override {
  10835. return m_listenerName;
  10836. }
  10837. std::string getDescription() const override {
  10838. return getDescriptionImpl( Detail::has_description<T>{} );
  10839. }
  10840. };
  10841. public:
  10842. ListenerRegistrar(StringRef listenerName) {
  10843. registerListenerImpl( Detail::make_unique<TypedListenerFactory>(listenerName) );
  10844. }
  10845. };
  10846. }
  10847. #if !defined(CATCH_CONFIG_DISABLE)
  10848. # define CATCH_REGISTER_REPORTER( name, reporterType ) \
  10849. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  10850. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  10851. namespace { \
  10852. Catch::ReporterRegistrar<reporterType> INTERNAL_CATCH_UNIQUE_NAME( \
  10853. catch_internal_RegistrarFor )( name ); \
  10854. } \
  10855. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  10856. # define CATCH_REGISTER_LISTENER( listenerType ) \
  10857. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  10858. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  10859. namespace { \
  10860. Catch::ListenerRegistrar<listenerType> INTERNAL_CATCH_UNIQUE_NAME( \
  10861. catch_internal_RegistrarFor )( #listenerType##_catch_sr ); \
  10862. } \
  10863. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  10864. #else // CATCH_CONFIG_DISABLE
  10865. #define CATCH_REGISTER_REPORTER(name, reporterType)
  10866. #define CATCH_REGISTER_LISTENER(listenerType)
  10867. #endif // CATCH_CONFIG_DISABLE
  10868. #endif // CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  10869. #ifndef CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  10870. #define CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  10871. namespace Catch {
  10872. class SonarQubeReporter final : public CumulativeReporterBase {
  10873. public:
  10874. SonarQubeReporter(ReporterConfig&& config)
  10875. : CumulativeReporterBase(CATCH_MOVE(config))
  10876. , xml(m_stream) {
  10877. m_preferences.shouldRedirectStdOut = true;
  10878. m_preferences.shouldReportAllAssertions = true;
  10879. m_shouldStoreSuccesfulAssertions = false;
  10880. }
  10881. static std::string getDescription() {
  10882. using namespace std::string_literals;
  10883. return "Reports test results in the Generic Test Data SonarQube XML format"s;
  10884. }
  10885. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  10886. void testRunEndedCumulative() override {
  10887. writeRun( *m_testRun );
  10888. xml.endElement();
  10889. }
  10890. void writeRun( TestRunNode const& runNode );
  10891. void writeTestFile(StringRef filename, std::vector<TestCaseNode const*> const& testCaseNodes);
  10892. void writeTestCase(TestCaseNode const& testCaseNode);
  10893. void writeSection(std::string const& rootName, SectionNode const& sectionNode, bool okToFail);
  10894. void writeAssertions(SectionNode const& sectionNode, bool okToFail);
  10895. void writeAssertion(AssertionStats const& stats, bool okToFail);
  10896. private:
  10897. XmlWriter xml;
  10898. };
  10899. } // end namespace Catch
  10900. #endif // CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  10901. #ifndef CATCH_REPORTER_TAP_HPP_INCLUDED
  10902. #define CATCH_REPORTER_TAP_HPP_INCLUDED
  10903. namespace Catch {
  10904. class TAPReporter final : public StreamingReporterBase {
  10905. public:
  10906. TAPReporter( ReporterConfig&& config ):
  10907. StreamingReporterBase( CATCH_MOVE(config) ) {
  10908. m_preferences.shouldReportAllAssertions = true;
  10909. }
  10910. static std::string getDescription() {
  10911. using namespace std::string_literals;
  10912. return "Reports test results in TAP format, suitable for test harnesses"s;
  10913. }
  10914. void testRunStarting( TestRunInfo const& testInfo ) override;
  10915. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  10916. void assertionEnded(AssertionStats const& _assertionStats) override;
  10917. void testRunEnded(TestRunStats const& _testRunStats) override;
  10918. private:
  10919. std::size_t counter = 0;
  10920. };
  10921. } // end namespace Catch
  10922. #endif // CATCH_REPORTER_TAP_HPP_INCLUDED
  10923. #ifndef CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  10924. #define CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  10925. #include <cstring>
  10926. #ifdef __clang__
  10927. # pragma clang diagnostic push
  10928. # pragma clang diagnostic ignored "-Wpadded"
  10929. #endif
  10930. namespace Catch {
  10931. class TeamCityReporter final : public StreamingReporterBase {
  10932. public:
  10933. TeamCityReporter( ReporterConfig&& _config )
  10934. : StreamingReporterBase( CATCH_MOVE(_config) )
  10935. {
  10936. m_preferences.shouldRedirectStdOut = true;
  10937. }
  10938. ~TeamCityReporter() override;
  10939. static std::string getDescription() {
  10940. using namespace std::string_literals;
  10941. return "Reports test results as TeamCity service messages"s;
  10942. }
  10943. void testRunStarting( TestRunInfo const& runInfo ) override;
  10944. void testRunEnded( TestRunStats const& runStats ) override;
  10945. void assertionEnded(AssertionStats const& assertionStats) override;
  10946. void sectionStarting(SectionInfo const& sectionInfo) override {
  10947. m_headerPrintedForThisSection = false;
  10948. StreamingReporterBase::sectionStarting( sectionInfo );
  10949. }
  10950. void testCaseStarting(TestCaseInfo const& testInfo) override;
  10951. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  10952. private:
  10953. void printSectionHeader(std::ostream& os);
  10954. bool m_headerPrintedForThisSection = false;
  10955. Timer m_testTimer;
  10956. };
  10957. } // end namespace Catch
  10958. #ifdef __clang__
  10959. # pragma clang diagnostic pop
  10960. #endif
  10961. #endif // CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  10962. #ifndef CATCH_REPORTER_XML_HPP_INCLUDED
  10963. #define CATCH_REPORTER_XML_HPP_INCLUDED
  10964. namespace Catch {
  10965. class XmlReporter : public StreamingReporterBase {
  10966. public:
  10967. XmlReporter(ReporterConfig&& _config);
  10968. ~XmlReporter() override;
  10969. static std::string getDescription();
  10970. virtual std::string getStylesheetRef() const;
  10971. void writeSourceInfo(SourceLineInfo const& sourceInfo);
  10972. public: // StreamingReporterBase
  10973. void testRunStarting(TestRunInfo const& testInfo) override;
  10974. void testCaseStarting(TestCaseInfo const& testInfo) override;
  10975. void sectionStarting(SectionInfo const& sectionInfo) override;
  10976. void assertionStarting(AssertionInfo const&) override;
  10977. void assertionEnded(AssertionStats const& assertionStats) override;
  10978. void sectionEnded(SectionStats const& sectionStats) override;
  10979. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  10980. void testRunEnded(TestRunStats const& testRunStats) override;
  10981. void benchmarkPreparing( StringRef name ) override;
  10982. void benchmarkStarting(BenchmarkInfo const&) override;
  10983. void benchmarkEnded(BenchmarkStats<> const&) override;
  10984. void benchmarkFailed( StringRef error ) override;
  10985. void listReporters(std::vector<ReporterDescription> const& descriptions) override;
  10986. void listListeners(std::vector<ListenerDescription> const& descriptions) override;
  10987. void listTests(std::vector<TestCaseHandle> const& tests) override;
  10988. void listTags(std::vector<TagInfo> const& tags) override;
  10989. private:
  10990. Timer m_testCaseTimer;
  10991. XmlWriter m_xml;
  10992. int m_sectionDepth = 0;
  10993. };
  10994. } // end namespace Catch
  10995. #endif // CATCH_REPORTER_XML_HPP_INCLUDED
  10996. #endif // CATCH_REPORTERS_ALL_HPP_INCLUDED
  10997. #endif // CATCH_ALL_HPP_INCLUDED
  10998. #endif // CATCH_AMALGAMATED_HPP_INCLUDED