catch_amalgamated.hpp 442 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. // Catch v3.1.1
  7. // Generated: 2022-10-17 18:47:20.510385
  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_INTERFACES_CONFIG_HPP_INCLUDED
  47. #define CATCH_INTERFACES_CONFIG_HPP_INCLUDED
  48. #ifndef CATCH_NONCOPYABLE_HPP_INCLUDED
  49. #define CATCH_NONCOPYABLE_HPP_INCLUDED
  50. namespace Catch {
  51. namespace Detail {
  52. //! Deriving classes become noncopyable and nonmovable
  53. class NonCopyable {
  54. NonCopyable( NonCopyable const& ) = delete;
  55. NonCopyable( NonCopyable&& ) = delete;
  56. NonCopyable& operator=( NonCopyable const& ) = delete;
  57. NonCopyable& operator=( NonCopyable&& ) = delete;
  58. protected:
  59. NonCopyable() noexcept = default;
  60. };
  61. } // namespace Detail
  62. } // namespace Catch
  63. #endif // CATCH_NONCOPYABLE_HPP_INCLUDED
  64. #ifndef CATCH_STRINGREF_HPP_INCLUDED
  65. #define CATCH_STRINGREF_HPP_INCLUDED
  66. #include <cstddef>
  67. #include <string>
  68. #include <iosfwd>
  69. #include <cassert>
  70. namespace Catch {
  71. /// A non-owning string class (similar to the forthcoming std::string_view)
  72. /// Note that, because a StringRef may be a substring of another string,
  73. /// it may not be null terminated.
  74. class StringRef {
  75. public:
  76. using size_type = std::size_t;
  77. using const_iterator = const char*;
  78. private:
  79. static constexpr char const* const s_empty = "";
  80. char const* m_start = s_empty;
  81. size_type m_size = 0;
  82. public: // construction
  83. constexpr StringRef() noexcept = default;
  84. StringRef( char const* rawChars ) noexcept;
  85. constexpr StringRef( char const* rawChars, size_type size ) noexcept
  86. : m_start( rawChars ),
  87. m_size( size )
  88. {}
  89. StringRef( std::string const& stdString ) noexcept
  90. : m_start( stdString.c_str() ),
  91. m_size( stdString.size() )
  92. {}
  93. explicit operator std::string() const {
  94. return std::string(m_start, m_size);
  95. }
  96. public: // operators
  97. auto operator == ( StringRef other ) const noexcept -> bool;
  98. auto operator != (StringRef other) const noexcept -> bool {
  99. return !(*this == other);
  100. }
  101. constexpr auto operator[] ( size_type index ) const noexcept -> char {
  102. assert(index < m_size);
  103. return m_start[index];
  104. }
  105. bool operator<(StringRef rhs) const noexcept;
  106. public: // named queries
  107. constexpr auto empty() const noexcept -> bool {
  108. return m_size == 0;
  109. }
  110. constexpr auto size() const noexcept -> size_type {
  111. return m_size;
  112. }
  113. // Returns a substring of [start, start + length).
  114. // If start + length > size(), then the substring is [start, start + size()).
  115. // If start > size(), then the substring is empty.
  116. constexpr StringRef substr(size_type start, size_type length) const noexcept {
  117. if (start < m_size) {
  118. const auto shortened_size = m_size - start;
  119. return StringRef(m_start + start, (shortened_size < length) ? shortened_size : length);
  120. } else {
  121. return StringRef();
  122. }
  123. }
  124. // Returns the current start pointer. May not be null-terminated.
  125. constexpr char const* data() const noexcept {
  126. return m_start;
  127. }
  128. constexpr const_iterator begin() const { return m_start; }
  129. constexpr const_iterator end() const { return m_start + m_size; }
  130. friend std::string& operator += (std::string& lhs, StringRef sr);
  131. friend std::ostream& operator << (std::ostream& os, StringRef sr);
  132. friend std::string operator+(StringRef lhs, StringRef rhs);
  133. /**
  134. * Provides a three-way comparison with rhs
  135. *
  136. * Returns negative number if lhs < rhs, 0 if lhs == rhs, and a positive
  137. * number if lhs > rhs
  138. */
  139. int compare( StringRef rhs ) const;
  140. };
  141. constexpr auto operator ""_sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
  142. return StringRef( rawChars, size );
  143. }
  144. } // namespace Catch
  145. constexpr auto operator ""_catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
  146. return Catch::StringRef( rawChars, size );
  147. }
  148. #endif // CATCH_STRINGREF_HPP_INCLUDED
  149. #include <chrono>
  150. #include <iosfwd>
  151. #include <string>
  152. #include <vector>
  153. namespace Catch {
  154. enum class Verbosity {
  155. Quiet = 0,
  156. Normal,
  157. High
  158. };
  159. struct WarnAbout { enum What {
  160. Nothing = 0x00,
  161. //! A test case or leaf section did not run any assertions
  162. NoAssertions = 0x01,
  163. //! A command line test spec matched no test cases
  164. UnmatchedTestSpec = 0x02,
  165. }; };
  166. enum class ShowDurations {
  167. DefaultForReporter,
  168. Always,
  169. Never
  170. };
  171. enum class TestRunOrder {
  172. Declared,
  173. LexicographicallySorted,
  174. Randomized
  175. };
  176. enum class ColourMode : std::uint8_t {
  177. //! Let Catch2 pick implementation based on platform detection
  178. PlatformDefault,
  179. //! Use ANSI colour code escapes
  180. ANSI,
  181. //! Use Win32 console colour API
  182. Win32,
  183. //! Don't use any colour
  184. None
  185. };
  186. struct WaitForKeypress { enum When {
  187. Never,
  188. BeforeStart = 1,
  189. BeforeExit = 2,
  190. BeforeStartAndExit = BeforeStart | BeforeExit
  191. }; };
  192. class TestSpec;
  193. class IStream;
  194. class IConfig : public Detail::NonCopyable {
  195. public:
  196. virtual ~IConfig();
  197. virtual bool allowThrows() const = 0;
  198. virtual StringRef name() const = 0;
  199. virtual bool includeSuccessfulResults() const = 0;
  200. virtual bool shouldDebugBreak() const = 0;
  201. virtual bool warnAboutMissingAssertions() const = 0;
  202. virtual bool warnAboutUnmatchedTestSpecs() const = 0;
  203. virtual bool zeroTestsCountAsSuccess() const = 0;
  204. virtual int abortAfter() const = 0;
  205. virtual bool showInvisibles() const = 0;
  206. virtual ShowDurations showDurations() const = 0;
  207. virtual double minDuration() const = 0;
  208. virtual TestSpec const& testSpec() const = 0;
  209. virtual bool hasTestFilters() const = 0;
  210. virtual std::vector<std::string> const& getTestsOrTags() const = 0;
  211. virtual TestRunOrder runOrder() const = 0;
  212. virtual uint32_t rngSeed() const = 0;
  213. virtual unsigned int shardCount() const = 0;
  214. virtual unsigned int shardIndex() const = 0;
  215. virtual ColourMode defaultColourMode() const = 0;
  216. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  217. virtual Verbosity verbosity() const = 0;
  218. virtual bool skipBenchmarks() const = 0;
  219. virtual bool benchmarkNoAnalysis() const = 0;
  220. virtual unsigned int benchmarkSamples() const = 0;
  221. virtual double benchmarkConfidenceInterval() const = 0;
  222. virtual unsigned int benchmarkResamples() const = 0;
  223. virtual std::chrono::milliseconds benchmarkWarmupTime() const = 0;
  224. };
  225. }
  226. #endif // CATCH_INTERFACES_CONFIG_HPP_INCLUDED
  227. #ifndef CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  228. #define CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  229. // Detect a number of compiler features - by compiler
  230. // The following features are defined:
  231. //
  232. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  233. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  234. // CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled?
  235. // ****************
  236. // Note to maintainers: if new toggles are added please document them
  237. // in configuration.md, too
  238. // ****************
  239. // In general each macro has a _NO_<feature name> form
  240. // (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
  241. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  242. // can be combined, en-mass, with the _NO_ forms later.
  243. #ifndef CATCH_PLATFORM_HPP_INCLUDED
  244. #define CATCH_PLATFORM_HPP_INCLUDED
  245. // See e.g.:
  246. // https://opensource.apple.com/source/CarbonHeaders/CarbonHeaders-18.1/TargetConditionals.h.auto.html
  247. #ifdef __APPLE__
  248. # include <TargetConditionals.h>
  249. # if (defined(TARGET_OS_OSX) && TARGET_OS_OSX == 1) || \
  250. (defined(TARGET_OS_MAC) && TARGET_OS_MAC == 1)
  251. # define CATCH_PLATFORM_MAC
  252. # elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE == 1)
  253. # define CATCH_PLATFORM_IPHONE
  254. # endif
  255. #elif defined(linux) || defined(__linux) || defined(__linux__)
  256. # define CATCH_PLATFORM_LINUX
  257. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
  258. # define CATCH_PLATFORM_WINDOWS
  259. # if defined( WINAPI_FAMILY ) && ( WINAPI_FAMILY == WINAPI_FAMILY_APP )
  260. # define CATCH_PLATFORM_WINDOWS_UWP
  261. # endif
  262. #endif
  263. #endif // CATCH_PLATFORM_HPP_INCLUDED
  264. #ifdef __cplusplus
  265. # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
  266. # define CATCH_CPP14_OR_GREATER
  267. # endif
  268. # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
  269. # define CATCH_CPP17_OR_GREATER
  270. # endif
  271. #endif
  272. // Only GCC compiler should be used in this block, so other compilers trying to
  273. // mask themselves as GCC should be ignored.
  274. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__)
  275. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
  276. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
  277. // This only works on GCC 9+. so we have to also add a global suppression of Wparentheses
  278. // for older versions of GCC.
  279. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  280. _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" )
  281. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  282. _Pragma( "GCC diagnostic ignored \"-Wunused-variable\"" )
  283. # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  284. _Pragma( "GCC diagnostic ignored \"-Wuseless-cast\"" )
  285. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__)
  286. #endif
  287. #if defined(__CUDACC__) && !defined(__clang__)
  288. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic push" )
  289. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "nv_diagnostic pop" )
  290. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS _Pragma( "nv_diag_suppress 177" )
  291. #endif
  292. // clang-cl defines _MSC_VER as well as __clang__, which could cause the
  293. // start/stop internal suppression macros to be double defined.
  294. #if defined(__clang__) && !defined(_MSC_VER)
  295. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
  296. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
  297. #endif // __clang__ && !_MSC_VER
  298. #if defined(__clang__)
  299. // As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
  300. // which results in calls to destructors being emitted for each temporary,
  301. // without a matching initialization. In practice, this can result in something
  302. // like `std::string::~string` being called on an uninitialized value.
  303. //
  304. // For example, this code will likely segfault under IBM XL:
  305. // ```
  306. // REQUIRE(std::string("12") + "34" == "1234")
  307. // ```
  308. //
  309. // Similarly, NVHPC's implementation of `__builtin_constant_p` has a bug which
  310. // results in calls to the immediately evaluated lambda expressions to be
  311. // reported as unevaluated lambdas.
  312. // https://developer.nvidia.com/nvidia_bug/3321845.
  313. //
  314. // Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
  315. # if !defined(__ibmxl__) && !defined(__CUDACC__) && !defined( __NVCOMPILER )
  316. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg, hicpp-vararg) */
  317. # endif
  318. # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  319. _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
  320. _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
  321. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  322. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  323. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  324. _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
  325. # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  326. _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
  327. # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  328. _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
  329. #endif // __clang__
  330. ////////////////////////////////////////////////////////////////////////////////
  331. // Assume that non-Windows platforms support posix signals by default
  332. #if !defined(CATCH_PLATFORM_WINDOWS)
  333. #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
  334. #endif
  335. ////////////////////////////////////////////////////////////////////////////////
  336. // We know some environments not to support full POSIX signals
  337. #if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
  338. #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  339. #endif
  340. #ifdef __OS400__
  341. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  342. #endif
  343. ////////////////////////////////////////////////////////////////////////////////
  344. // Android somehow still does not support std::to_string
  345. #if defined(__ANDROID__)
  346. # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
  347. #endif
  348. ////////////////////////////////////////////////////////////////////////////////
  349. // Not all Windows environments support SEH properly
  350. #if defined(__MINGW32__)
  351. # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
  352. #endif
  353. ////////////////////////////////////////////////////////////////////////////////
  354. // PS4
  355. #if defined(__ORBIS__)
  356. # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
  357. #endif
  358. ////////////////////////////////////////////////////////////////////////////////
  359. // Cygwin
  360. #ifdef __CYGWIN__
  361. // Required for some versions of Cygwin to declare gettimeofday
  362. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  363. # define _BSD_SOURCE
  364. // some versions of cygwin (most) do not support std::to_string. Use the libstd check.
  365. // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
  366. # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
  367. && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
  368. # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
  369. # endif
  370. #endif // __CYGWIN__
  371. ////////////////////////////////////////////////////////////////////////////////
  372. // Visual C++
  373. #if defined(_MSC_VER)
  374. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
  375. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
  376. // Universal Windows platform does not support SEH
  377. // Or console colours (or console at all...)
  378. # if defined(CATCH_PLATFORM_WINDOWS_UWP)
  379. # define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
  380. # else
  381. # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  382. # endif
  383. // MSVC traditional preprocessor needs some workaround for __VA_ARGS__
  384. // _MSVC_TRADITIONAL == 0 means new conformant preprocessor
  385. // _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor
  386. # if !defined(__clang__) // Handle Clang masquerading for msvc
  387. # if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL)
  388. # define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  389. # endif // MSVC_TRADITIONAL
  390. # endif // __clang__
  391. #endif // _MSC_VER
  392. #if defined(_REENTRANT) || defined(_MSC_VER)
  393. // Enable async processing, as -pthread is specified or no additional linking is required
  394. # define CATCH_INTERNAL_CONFIG_USE_ASYNC
  395. #endif // _MSC_VER
  396. ////////////////////////////////////////////////////////////////////////////////
  397. // Check if we are compiled with -fno-exceptions or equivalent
  398. #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
  399. # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
  400. #endif
  401. ////////////////////////////////////////////////////////////////////////////////
  402. // Embarcadero C++Build
  403. #if defined(__BORLANDC__)
  404. #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN
  405. #endif
  406. ////////////////////////////////////////////////////////////////////////////////
  407. // RTX is a special version of Windows that is real time.
  408. // This means that it is detected as Windows, but does not provide
  409. // the same set of capabilities as real Windows does.
  410. #if defined(UNDER_RTSS) || defined(RTX64_BUILD)
  411. #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
  412. #define CATCH_INTERNAL_CONFIG_NO_ASYNC
  413. #define CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32
  414. #endif
  415. #if !defined(_GLIBCXX_USE_C99_MATH_TR1)
  416. #define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER
  417. #endif
  418. // Various stdlib support checks that require __has_include
  419. #if defined(__has_include)
  420. // Check if string_view is available and usable
  421. #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
  422. # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
  423. #endif
  424. // Check if optional is available and usable
  425. # if __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
  426. # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL
  427. # endif // __has_include(<optional>) && defined(CATCH_CPP17_OR_GREATER)
  428. // Check if byte is available and usable
  429. # if __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
  430. # include <cstddef>
  431. # if defined(__cpp_lib_byte) && (__cpp_lib_byte > 0)
  432. # define CATCH_INTERNAL_CONFIG_CPP17_BYTE
  433. # endif
  434. # endif // __has_include(<cstddef>) && defined(CATCH_CPP17_OR_GREATER)
  435. // Check if variant is available and usable
  436. # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
  437. # if defined(__clang__) && (__clang_major__ < 8)
  438. // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
  439. // fix should be in clang 8, workaround in libstdc++ 8.2
  440. # include <ciso646>
  441. # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
  442. # define CATCH_CONFIG_NO_CPP17_VARIANT
  443. # else
  444. # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
  445. # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
  446. # else
  447. # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
  448. # endif // defined(__clang__) && (__clang_major__ < 8)
  449. # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
  450. #endif // defined(__has_include)
  451. #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)
  452. # define CATCH_CONFIG_WINDOWS_SEH
  453. #endif
  454. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  455. #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)
  456. # define CATCH_CONFIG_POSIX_SIGNALS
  457. #endif
  458. #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
  459. # define CATCH_CONFIG_CPP11_TO_STRING
  460. #endif
  461. #if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL)
  462. # define CATCH_CONFIG_CPP17_OPTIONAL
  463. #endif
  464. #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
  465. # define CATCH_CONFIG_CPP17_STRING_VIEW
  466. #endif
  467. #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
  468. # define CATCH_CONFIG_CPP17_VARIANT
  469. #endif
  470. #if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE)
  471. # define CATCH_CONFIG_CPP17_BYTE
  472. #endif
  473. #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
  474. # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
  475. #endif
  476. #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)
  477. # define CATCH_CONFIG_NEW_CAPTURE
  478. #endif
  479. #if !defined( CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED ) && \
  480. !defined( CATCH_CONFIG_DISABLE_EXCEPTIONS ) && \
  481. !defined( CATCH_CONFIG_NO_DISABLE_EXCEPTIONS )
  482. # define CATCH_CONFIG_DISABLE_EXCEPTIONS
  483. #endif
  484. #if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN)
  485. # define CATCH_CONFIG_POLYFILL_ISNAN
  486. #endif
  487. #if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC)
  488. # define CATCH_CONFIG_USE_ASYNC
  489. #endif
  490. #if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER)
  491. # define CATCH_CONFIG_GLOBAL_NEXTAFTER
  492. #endif
  493. // Even if we do not think the compiler has that warning, we still have
  494. // to provide a macro that can be used by the code.
  495. #if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
  496. # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
  497. #endif
  498. #if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
  499. # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  500. #endif
  501. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  502. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  503. #endif
  504. #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
  505. # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
  506. #endif
  507. #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS)
  508. # define CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS
  509. #endif
  510. #if !defined(CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS)
  511. # define CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS
  512. #endif
  513. #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
  514. # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
  515. #endif
  516. // The goal of this macro is to avoid evaluation of the arguments, but
  517. // still have the compiler warn on problems inside...
  518. #if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN)
  519. # define CATCH_INTERNAL_IGNORE_BUT_WARN(...)
  520. #endif
  521. #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
  522. # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  523. #elif defined(__clang__) && (__clang_major__ < 5)
  524. # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  525. #endif
  526. #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
  527. # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
  528. #endif
  529. #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  530. #define CATCH_TRY if ((true))
  531. #define CATCH_CATCH_ALL if ((false))
  532. #define CATCH_CATCH_ANON(type) if ((false))
  533. #else
  534. #define CATCH_TRY try
  535. #define CATCH_CATCH_ALL catch (...)
  536. #define CATCH_CATCH_ANON(type) catch (type)
  537. #endif
  538. #if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR)
  539. #define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  540. #endif
  541. #if defined( CATCH_PLATFORM_WINDOWS ) && \
  542. !defined( CATCH_CONFIG_COLOUR_WIN32 ) && \
  543. !defined( CATCH_CONFIG_NO_COLOUR_WIN32 ) && \
  544. !defined( CATCH_INTERNAL_CONFIG_NO_COLOUR_WIN32 )
  545. # define CATCH_CONFIG_COLOUR_WIN32
  546. #endif
  547. #if defined( CATCH_CONFIG_SHARED_LIBRARY ) && defined( _MSC_VER ) && \
  548. !defined( CATCH_CONFIG_STATIC )
  549. # ifdef Catch2_EXPORTS
  550. # define CATCH_EXPORT //__declspec( dllexport ) // not needed
  551. # else
  552. # define CATCH_EXPORT __declspec( dllimport )
  553. # endif
  554. #else
  555. # define CATCH_EXPORT
  556. #endif
  557. #endif // CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  558. #ifndef CATCH_CONTEXT_HPP_INCLUDED
  559. #define CATCH_CONTEXT_HPP_INCLUDED
  560. namespace Catch {
  561. class IResultCapture;
  562. class IConfig;
  563. class IContext {
  564. public:
  565. virtual ~IContext(); // = default
  566. virtual IResultCapture* getResultCapture() = 0;
  567. virtual IConfig const* getConfig() const = 0;
  568. };
  569. class IMutableContext : public IContext {
  570. public:
  571. ~IMutableContext() override; // = default
  572. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  573. virtual void setConfig( IConfig const* config ) = 0;
  574. private:
  575. CATCH_EXPORT static IMutableContext* currentContext;
  576. friend IMutableContext& getCurrentMutableContext();
  577. friend void cleanUpContext();
  578. static void createContext();
  579. };
  580. inline IMutableContext& getCurrentMutableContext()
  581. {
  582. if( !IMutableContext::currentContext )
  583. IMutableContext::createContext();
  584. // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
  585. return *IMutableContext::currentContext;
  586. }
  587. inline IContext& getCurrentContext()
  588. {
  589. return getCurrentMutableContext();
  590. }
  591. void cleanUpContext();
  592. class SimplePcg32;
  593. SimplePcg32& sharedRng();
  594. }
  595. #endif // CATCH_CONTEXT_HPP_INCLUDED
  596. #ifndef CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  597. #define CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  598. #ifndef CATCH_SECTION_INFO_HPP_INCLUDED
  599. #define CATCH_SECTION_INFO_HPP_INCLUDED
  600. #ifndef CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  601. #define CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  602. #include <type_traits>
  603. //! Replacement for std::move with better compile time performance
  604. #define CATCH_MOVE(...) static_cast<std::remove_reference_t<decltype(__VA_ARGS__)>&&>(__VA_ARGS__)
  605. //! Replacement for std::forward with better compile time performance
  606. #define CATCH_FORWARD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
  607. #endif // CATCH_MOVE_AND_FORWARD_HPP_INCLUDED
  608. #ifndef CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  609. #define CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  610. #include <cstddef>
  611. #include <iosfwd>
  612. namespace Catch {
  613. struct SourceLineInfo {
  614. SourceLineInfo() = delete;
  615. constexpr SourceLineInfo( char const* _file, std::size_t _line ) noexcept:
  616. file( _file ),
  617. line( _line )
  618. {}
  619. bool operator == ( SourceLineInfo const& other ) const noexcept;
  620. bool operator < ( SourceLineInfo const& other ) const noexcept;
  621. char const* file;
  622. std::size_t line;
  623. friend std::ostream& operator << (std::ostream& os, SourceLineInfo const& info);
  624. };
  625. }
  626. #define CATCH_INTERNAL_LINEINFO \
  627. ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  628. #endif // CATCH_SOURCE_LINE_INFO_HPP_INCLUDED
  629. #ifndef CATCH_TOTALS_HPP_INCLUDED
  630. #define CATCH_TOTALS_HPP_INCLUDED
  631. #include <cstdint>
  632. namespace Catch {
  633. struct Counts {
  634. Counts operator - ( Counts const& other ) const;
  635. Counts& operator += ( Counts const& other );
  636. std::uint64_t total() const;
  637. bool allPassed() const;
  638. bool allOk() const;
  639. std::uint64_t passed = 0;
  640. std::uint64_t failed = 0;
  641. std::uint64_t failedButOk = 0;
  642. };
  643. struct Totals {
  644. Totals operator - ( Totals const& other ) const;
  645. Totals& operator += ( Totals const& other );
  646. Totals delta( Totals const& prevTotals ) const;
  647. Counts assertions;
  648. Counts testCases;
  649. };
  650. }
  651. #endif // CATCH_TOTALS_HPP_INCLUDED
  652. #include <string>
  653. namespace Catch {
  654. struct SectionInfo {
  655. // The last argument is ignored, so that people can write
  656. // SECTION("ShortName", "Proper description that is long") and
  657. // still use the `-c` flag comfortably.
  658. SectionInfo( SourceLineInfo const& _lineInfo, std::string _name,
  659. const char* const = nullptr ):
  660. name(CATCH_MOVE(_name)),
  661. lineInfo(_lineInfo)
  662. {}
  663. std::string name;
  664. SourceLineInfo lineInfo;
  665. };
  666. struct SectionEndInfo {
  667. SectionInfo sectionInfo;
  668. Counts prevAssertions;
  669. double durationInSeconds;
  670. };
  671. } // end namespace Catch
  672. #endif // CATCH_SECTION_INFO_HPP_INCLUDED
  673. #ifndef CATCH_ASSERTION_RESULT_HPP_INCLUDED
  674. #define CATCH_ASSERTION_RESULT_HPP_INCLUDED
  675. #ifndef CATCH_ASSERTION_INFO_HPP_INCLUDED
  676. #define CATCH_ASSERTION_INFO_HPP_INCLUDED
  677. #ifndef CATCH_RESULT_TYPE_HPP_INCLUDED
  678. #define CATCH_RESULT_TYPE_HPP_INCLUDED
  679. namespace Catch {
  680. // ResultWas::OfType enum
  681. struct ResultWas { enum OfType {
  682. Unknown = -1,
  683. Ok = 0,
  684. Info = 1,
  685. Warning = 2,
  686. FailureBit = 0x10,
  687. ExpressionFailed = FailureBit | 1,
  688. ExplicitFailure = FailureBit | 2,
  689. Exception = 0x100 | FailureBit,
  690. ThrewException = Exception | 1,
  691. DidntThrowException = Exception | 2,
  692. FatalErrorCondition = 0x200 | FailureBit
  693. }; };
  694. bool isOk( ResultWas::OfType resultType );
  695. bool isJustInfo( int flags );
  696. // ResultDisposition::Flags enum
  697. struct ResultDisposition { enum Flags {
  698. Normal = 0x01,
  699. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  700. FalseTest = 0x04, // Prefix expression with !
  701. SuppressFail = 0x08 // Failures are reported but do not fail the test
  702. }; };
  703. ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs );
  704. bool shouldContinueOnFailure( int flags );
  705. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  706. bool shouldSuppressFailure( int flags );
  707. } // end namespace Catch
  708. #endif // CATCH_RESULT_TYPE_HPP_INCLUDED
  709. namespace Catch {
  710. struct AssertionInfo {
  711. // AssertionInfo() = delete;
  712. StringRef macroName;
  713. SourceLineInfo lineInfo;
  714. StringRef capturedExpression;
  715. ResultDisposition::Flags resultDisposition;
  716. };
  717. } // end namespace Catch
  718. #endif // CATCH_ASSERTION_INFO_HPP_INCLUDED
  719. #ifndef CATCH_LAZY_EXPR_HPP_INCLUDED
  720. #define CATCH_LAZY_EXPR_HPP_INCLUDED
  721. #include <iosfwd>
  722. namespace Catch {
  723. class ITransientExpression;
  724. class LazyExpression {
  725. friend class AssertionHandler;
  726. friend struct AssertionStats;
  727. friend class RunContext;
  728. ITransientExpression const* m_transientExpression = nullptr;
  729. bool m_isNegated;
  730. public:
  731. LazyExpression( bool isNegated ):
  732. m_isNegated(isNegated)
  733. {}
  734. LazyExpression(LazyExpression const& other) = default;
  735. LazyExpression& operator = ( LazyExpression const& ) = delete;
  736. explicit operator bool() const {
  737. return m_transientExpression != nullptr;
  738. }
  739. friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
  740. };
  741. } // namespace Catch
  742. #endif // CATCH_LAZY_EXPR_HPP_INCLUDED
  743. #include <string>
  744. namespace Catch {
  745. struct AssertionResultData
  746. {
  747. AssertionResultData() = delete;
  748. AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
  749. std::string message;
  750. mutable std::string reconstructedExpression;
  751. LazyExpression lazyExpression;
  752. ResultWas::OfType resultType;
  753. std::string reconstructExpression() const;
  754. };
  755. class AssertionResult {
  756. public:
  757. AssertionResult() = delete;
  758. AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
  759. bool isOk() const;
  760. bool succeeded() const;
  761. ResultWas::OfType getResultType() const;
  762. bool hasExpression() const;
  763. bool hasMessage() const;
  764. std::string getExpression() const;
  765. std::string getExpressionInMacro() const;
  766. bool hasExpandedExpression() const;
  767. std::string getExpandedExpression() const;
  768. StringRef getMessage() const;
  769. SourceLineInfo getSourceInfo() const;
  770. StringRef getTestMacroName() const;
  771. //protected:
  772. AssertionInfo m_info;
  773. AssertionResultData m_resultData;
  774. };
  775. } // end namespace Catch
  776. #endif // CATCH_ASSERTION_RESULT_HPP_INCLUDED
  777. #ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED
  778. #define CATCH_MESSAGE_INFO_HPP_INCLUDED
  779. #ifndef CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  780. #define CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  781. #include <string>
  782. #include <chrono>
  783. namespace Catch {
  784. class AssertionResult;
  785. struct AssertionInfo;
  786. struct SectionInfo;
  787. struct SectionEndInfo;
  788. struct MessageInfo;
  789. struct MessageBuilder;
  790. struct Counts;
  791. struct AssertionReaction;
  792. struct SourceLineInfo;
  793. class ITransientExpression;
  794. class IGeneratorTracker;
  795. struct BenchmarkInfo;
  796. template <typename Duration = std::chrono::duration<double, std::nano>>
  797. struct BenchmarkStats;
  798. class IResultCapture {
  799. public:
  800. virtual ~IResultCapture();
  801. virtual bool sectionStarted( SectionInfo const& sectionInfo,
  802. Counts& assertions ) = 0;
  803. virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
  804. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
  805. virtual auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0;
  806. virtual void benchmarkPreparing( StringRef name ) = 0;
  807. virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
  808. virtual void benchmarkEnded( BenchmarkStats<> const& stats ) = 0;
  809. virtual void benchmarkFailed( StringRef error ) = 0;
  810. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  811. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  812. virtual void emplaceUnscopedMessage( MessageBuilder const& builder ) = 0;
  813. virtual void handleFatalErrorCondition( StringRef message ) = 0;
  814. virtual void handleExpr
  815. ( AssertionInfo const& info,
  816. ITransientExpression const& expr,
  817. AssertionReaction& reaction ) = 0;
  818. virtual void handleMessage
  819. ( AssertionInfo const& info,
  820. ResultWas::OfType resultType,
  821. StringRef message,
  822. AssertionReaction& reaction ) = 0;
  823. virtual void handleUnexpectedExceptionNotThrown
  824. ( AssertionInfo const& info,
  825. AssertionReaction& reaction ) = 0;
  826. virtual void handleUnexpectedInflightException
  827. ( AssertionInfo const& info,
  828. std::string const& message,
  829. AssertionReaction& reaction ) = 0;
  830. virtual void handleIncomplete
  831. ( AssertionInfo const& info ) = 0;
  832. virtual void handleNonExpr
  833. ( AssertionInfo const &info,
  834. ResultWas::OfType resultType,
  835. AssertionReaction &reaction ) = 0;
  836. virtual bool lastAssertionPassed() = 0;
  837. virtual void assertionPassed() = 0;
  838. // Deprecated, do not use:
  839. virtual std::string getCurrentTestName() const = 0;
  840. virtual const AssertionResult* getLastResult() const = 0;
  841. virtual void exceptionEarlyReported() = 0;
  842. };
  843. IResultCapture& getResultCapture();
  844. }
  845. #endif // CATCH_INTERFACES_CAPTURE_HPP_INCLUDED
  846. #include <string>
  847. namespace Catch {
  848. struct MessageInfo {
  849. MessageInfo( StringRef _macroName,
  850. SourceLineInfo const& _lineInfo,
  851. ResultWas::OfType _type );
  852. StringRef macroName;
  853. std::string message;
  854. SourceLineInfo lineInfo;
  855. ResultWas::OfType type;
  856. unsigned int sequence;
  857. bool operator == (MessageInfo const& other) const {
  858. return sequence == other.sequence;
  859. }
  860. bool operator < (MessageInfo const& other) const {
  861. return sequence < other.sequence;
  862. }
  863. private:
  864. static unsigned int globalCount;
  865. };
  866. } // end namespace Catch
  867. #endif // CATCH_MESSAGE_INFO_HPP_INCLUDED
  868. #ifndef CATCH_UNIQUE_PTR_HPP_INCLUDED
  869. #define CATCH_UNIQUE_PTR_HPP_INCLUDED
  870. #include <cassert>
  871. #include <type_traits>
  872. namespace Catch {
  873. namespace Detail {
  874. /**
  875. * A reimplementation of `std::unique_ptr` for improved compilation performance
  876. *
  877. * Does not support arrays nor custom deleters.
  878. */
  879. template <typename T>
  880. class unique_ptr {
  881. T* m_ptr;
  882. public:
  883. constexpr unique_ptr(std::nullptr_t = nullptr):
  884. m_ptr{}
  885. {}
  886. explicit constexpr unique_ptr(T* ptr):
  887. m_ptr(ptr)
  888. {}
  889. template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
  890. unique_ptr(unique_ptr<U>&& from):
  891. m_ptr(from.release())
  892. {}
  893. template <typename U, typename = std::enable_if_t<std::is_base_of<T, U>::value>>
  894. unique_ptr& operator=(unique_ptr<U>&& from) {
  895. reset(from.release());
  896. return *this;
  897. }
  898. unique_ptr(unique_ptr const&) = delete;
  899. unique_ptr& operator=(unique_ptr const&) = delete;
  900. unique_ptr(unique_ptr&& rhs) noexcept:
  901. m_ptr(rhs.m_ptr) {
  902. rhs.m_ptr = nullptr;
  903. }
  904. unique_ptr& operator=(unique_ptr&& rhs) noexcept {
  905. reset(rhs.release());
  906. return *this;
  907. }
  908. ~unique_ptr() {
  909. delete m_ptr;
  910. }
  911. T& operator*() {
  912. assert(m_ptr);
  913. return *m_ptr;
  914. }
  915. T const& operator*() const {
  916. assert(m_ptr);
  917. return *m_ptr;
  918. }
  919. T* operator->() noexcept {
  920. assert(m_ptr);
  921. return m_ptr;
  922. }
  923. T const* operator->() const noexcept {
  924. assert(m_ptr);
  925. return m_ptr;
  926. }
  927. T* get() { return m_ptr; }
  928. T const* get() const { return m_ptr; }
  929. void reset(T* ptr = nullptr) {
  930. delete m_ptr;
  931. m_ptr = ptr;
  932. }
  933. T* release() {
  934. auto temp = m_ptr;
  935. m_ptr = nullptr;
  936. return temp;
  937. }
  938. explicit operator bool() const {
  939. return m_ptr;
  940. }
  941. friend void swap(unique_ptr& lhs, unique_ptr& rhs) {
  942. auto temp = lhs.m_ptr;
  943. lhs.m_ptr = rhs.m_ptr;
  944. rhs.m_ptr = temp;
  945. }
  946. };
  947. //! Specialization to cause compile-time error for arrays
  948. template <typename T>
  949. class unique_ptr<T[]>;
  950. template <typename T, typename... Args>
  951. unique_ptr<T> make_unique(Args&&... args) {
  952. return unique_ptr<T>(new T(CATCH_FORWARD(args)...));
  953. }
  954. } // end namespace Detail
  955. } // end namespace Catch
  956. #endif // CATCH_UNIQUE_PTR_HPP_INCLUDED
  957. // Adapted from donated nonius code.
  958. #ifndef CATCH_ESTIMATE_HPP_INCLUDED
  959. #define CATCH_ESTIMATE_HPP_INCLUDED
  960. namespace Catch {
  961. namespace Benchmark {
  962. template <typename Duration>
  963. struct Estimate {
  964. Duration point;
  965. Duration lower_bound;
  966. Duration upper_bound;
  967. double confidence_interval;
  968. template <typename Duration2>
  969. operator Estimate<Duration2>() const {
  970. return { point, lower_bound, upper_bound, confidence_interval };
  971. }
  972. };
  973. } // namespace Benchmark
  974. } // namespace Catch
  975. #endif // CATCH_ESTIMATE_HPP_INCLUDED
  976. // Adapted from donated nonius code.
  977. #ifndef CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
  978. #define CATCH_OUTLIER_CLASSIFICATION_HPP_INCLUDED
  979. namespace Catch {
  980. namespace Benchmark {
  981. struct OutlierClassification {
  982. int samples_seen = 0;
  983. int low_severe = 0; // more than 3 times IQR below Q1
  984. int low_mild = 0; // 1.5 to 3 times IQR below Q1
  985. int high_mild = 0; // 1.5 to 3 times IQR above Q3
  986. int high_severe = 0; // more than 3 times IQR above Q3
  987. int total() const {
  988. return low_severe + low_mild + high_mild + high_severe;
  989. }
  990. };
  991. } // namespace Benchmark
  992. } // namespace Catch
  993. #endif // CATCH_OUTLIERS_CLASSIFICATION_HPP_INCLUDED
  994. #include <map>
  995. #include <string>
  996. #include <vector>
  997. #include <iosfwd>
  998. namespace Catch {
  999. struct ReporterDescription;
  1000. struct ListenerDescription;
  1001. struct TagInfo;
  1002. struct TestCaseInfo;
  1003. class TestCaseHandle;
  1004. class IConfig;
  1005. class IStream;
  1006. enum class ColourMode : std::uint8_t;
  1007. struct ReporterConfig {
  1008. ReporterConfig( IConfig const* _fullConfig,
  1009. Detail::unique_ptr<IStream> _stream,
  1010. ColourMode colourMode,
  1011. std::map<std::string, std::string> customOptions );
  1012. ReporterConfig( ReporterConfig&& ) = default;
  1013. ReporterConfig& operator=( ReporterConfig&& ) = default;
  1014. ~ReporterConfig(); // = default
  1015. Detail::unique_ptr<IStream> takeStream() &&;
  1016. IConfig const* fullConfig() const;
  1017. ColourMode colourMode() const;
  1018. std::map<std::string, std::string> const& customOptions() const;
  1019. private:
  1020. Detail::unique_ptr<IStream> m_stream;
  1021. IConfig const* m_fullConfig;
  1022. ColourMode m_colourMode;
  1023. std::map<std::string, std::string> m_customOptions;
  1024. };
  1025. struct TestRunInfo {
  1026. constexpr TestRunInfo(StringRef _name) : name(_name) {}
  1027. StringRef name;
  1028. };
  1029. struct AssertionStats {
  1030. AssertionStats( AssertionResult const& _assertionResult,
  1031. std::vector<MessageInfo> const& _infoMessages,
  1032. Totals const& _totals );
  1033. AssertionStats( AssertionStats const& ) = default;
  1034. AssertionStats( AssertionStats && ) = default;
  1035. AssertionStats& operator = ( AssertionStats const& ) = delete;
  1036. AssertionStats& operator = ( AssertionStats && ) = delete;
  1037. AssertionResult assertionResult;
  1038. std::vector<MessageInfo> infoMessages;
  1039. Totals totals;
  1040. };
  1041. struct SectionStats {
  1042. SectionStats( SectionInfo const& _sectionInfo,
  1043. Counts const& _assertions,
  1044. double _durationInSeconds,
  1045. bool _missingAssertions );
  1046. SectionInfo sectionInfo;
  1047. Counts assertions;
  1048. double durationInSeconds;
  1049. bool missingAssertions;
  1050. };
  1051. struct TestCaseStats {
  1052. TestCaseStats( TestCaseInfo const& _testInfo,
  1053. Totals const& _totals,
  1054. std::string const& _stdOut,
  1055. std::string const& _stdErr,
  1056. bool _aborting );
  1057. TestCaseInfo const * testInfo;
  1058. Totals totals;
  1059. std::string stdOut;
  1060. std::string stdErr;
  1061. bool aborting;
  1062. };
  1063. struct TestRunStats {
  1064. TestRunStats( TestRunInfo const& _runInfo,
  1065. Totals const& _totals,
  1066. bool _aborting );
  1067. TestRunInfo runInfo;
  1068. Totals totals;
  1069. bool aborting;
  1070. };
  1071. struct BenchmarkInfo {
  1072. std::string name;
  1073. double estimatedDuration;
  1074. int iterations;
  1075. unsigned int samples;
  1076. unsigned int resamples;
  1077. double clockResolution;
  1078. double clockCost;
  1079. };
  1080. template <class Duration>
  1081. struct BenchmarkStats {
  1082. BenchmarkInfo info;
  1083. std::vector<Duration> samples;
  1084. Benchmark::Estimate<Duration> mean;
  1085. Benchmark::Estimate<Duration> standardDeviation;
  1086. Benchmark::OutlierClassification outliers;
  1087. double outlierVariance;
  1088. template <typename Duration2>
  1089. operator BenchmarkStats<Duration2>() const {
  1090. std::vector<Duration2> samples2;
  1091. samples2.reserve(samples.size());
  1092. for (auto const& sample : samples) {
  1093. samples2.push_back(Duration2(sample));
  1094. }
  1095. return {
  1096. info,
  1097. CATCH_MOVE(samples2),
  1098. mean,
  1099. standardDeviation,
  1100. outliers,
  1101. outlierVariance,
  1102. };
  1103. }
  1104. };
  1105. //! By setting up its preferences, a reporter can modify Catch2's behaviour
  1106. //! in some regards, e.g. it can request Catch2 to capture writes to
  1107. //! stdout/stderr during test execution, and pass them to the reporter.
  1108. struct ReporterPreferences {
  1109. //! Catch2 should redirect writes to stdout and pass them to the
  1110. //! reporter
  1111. bool shouldRedirectStdOut = false;
  1112. //! Catch2 should call `Reporter::assertionEnded` even for passing
  1113. //! assertions
  1114. bool shouldReportAllAssertions = false;
  1115. };
  1116. /**
  1117. * The common base for all reporters and event listeners
  1118. *
  1119. * Implementing classes must also implement:
  1120. *
  1121. * //! User-friendly description of the reporter/listener type
  1122. * static std::string getDescription()
  1123. *
  1124. * Generally shouldn't be derived from by users of Catch2 directly,
  1125. * instead they should derive from one of the utility bases that
  1126. * derive from this class.
  1127. */
  1128. class IEventListener {
  1129. protected:
  1130. //! Derived classes can set up their preferences here
  1131. ReporterPreferences m_preferences;
  1132. //! The test run's config as filled in from CLI and defaults
  1133. IConfig const* m_config;
  1134. public:
  1135. IEventListener( IConfig const* config ): m_config( config ) {}
  1136. virtual ~IEventListener(); // = default;
  1137. // Implementing class must also provide the following static methods:
  1138. // static std::string getDescription();
  1139. ReporterPreferences const& getPreferences() const {
  1140. return m_preferences;
  1141. }
  1142. //! Called when no test cases match provided test spec
  1143. virtual void noMatchingTestCases( StringRef unmatchedSpec ) = 0;
  1144. //! Called for all invalid test specs from the cli
  1145. virtual void reportInvalidTestSpec( StringRef invalidArgument ) = 0;
  1146. /**
  1147. * Called once in a testing run before tests are started
  1148. *
  1149. * Not called if tests won't be run (e.g. only listing will happen)
  1150. */
  1151. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  1152. //! Called _once_ for each TEST_CASE, no matter how many times it is entered
  1153. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  1154. //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
  1155. virtual void testCasePartialStarting( TestCaseInfo const& testInfo, uint64_t partNumber ) = 0;
  1156. //! Called when a `SECTION` is being entered. Not called for skipped sections
  1157. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  1158. //! Called when user-code is being probed before the actual benchmark runs
  1159. virtual void benchmarkPreparing( StringRef benchmarkName ) = 0;
  1160. //! Called after probe but before the user-code is being benchmarked
  1161. virtual void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) = 0;
  1162. //! Called with the benchmark results if benchmark successfully finishes
  1163. virtual void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) = 0;
  1164. //! Called if running the benchmarks fails for any reason
  1165. virtual void benchmarkFailed( StringRef benchmarkName ) = 0;
  1166. //! Called before assertion success/failure is evaluated
  1167. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  1168. //! Called after assertion was fully evaluated
  1169. virtual void assertionEnded( AssertionStats const& assertionStats ) = 0;
  1170. //! Called after a `SECTION` has finished running
  1171. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  1172. //! Called _every time_ a TEST_CASE is entered, including repeats (due to sections)
  1173. virtual void testCasePartialEnded(TestCaseStats const& testCaseStats, uint64_t partNumber ) = 0;
  1174. //! Called _once_ for each TEST_CASE, no matter how many times it is entered
  1175. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  1176. /**
  1177. * Called once after all tests in a testing run are finished
  1178. *
  1179. * Not called if tests weren't run (e.g. only listings happened)
  1180. */
  1181. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  1182. //! Called with test cases that are skipped due to the test run aborting
  1183. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  1184. //! Called if a fatal error (signal/structured exception) occured
  1185. virtual void fatalErrorEncountered( StringRef error ) = 0;
  1186. //! Writes out information about provided reporters using reporter-specific format
  1187. virtual void listReporters(std::vector<ReporterDescription> const& descriptions) = 0;
  1188. //! Writes out the provided listeners descriptions using reporter-specific format
  1189. virtual void listListeners(std::vector<ListenerDescription> const& descriptions) = 0;
  1190. //! Writes out information about provided tests using reporter-specific format
  1191. virtual void listTests(std::vector<TestCaseHandle> const& tests) = 0;
  1192. //! Writes out information about the provided tags using reporter-specific format
  1193. virtual void listTags(std::vector<TagInfo> const& tags) = 0;
  1194. };
  1195. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  1196. } // end namespace Catch
  1197. #endif // CATCH_INTERFACES_REPORTER_HPP_INCLUDED
  1198. #ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED
  1199. #define CATCH_UNIQUE_NAME_HPP_INCLUDED
  1200. /** \file
  1201. * Wrapper for the CONFIG configuration option
  1202. *
  1203. * When generating internal unique names, there are two options. Either
  1204. * we mix in the current line number, or mix in an incrementing number.
  1205. * We prefer the latter, using `__COUNTER__`, but users might want to
  1206. * use the former.
  1207. */
  1208. #ifndef CATCH_CONFIG_COUNTER_HPP_INCLUDED
  1209. #define CATCH_CONFIG_COUNTER_HPP_INCLUDED
  1210. #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
  1211. #define CATCH_INTERNAL_CONFIG_COUNTER
  1212. #endif
  1213. #if defined( CATCH_INTERNAL_CONFIG_COUNTER ) && \
  1214. !defined( CATCH_CONFIG_NO_COUNTER ) && \
  1215. !defined( CATCH_CONFIG_COUNTER )
  1216. # define CATCH_CONFIG_COUNTER
  1217. #endif
  1218. #endif // CATCH_CONFIG_COUNTER_HPP_INCLUDED
  1219. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  1220. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  1221. #ifdef CATCH_CONFIG_COUNTER
  1222. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  1223. #else
  1224. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  1225. #endif
  1226. #endif // CATCH_UNIQUE_NAME_HPP_INCLUDED
  1227. // Adapted from donated nonius code.
  1228. #ifndef CATCH_CHRONOMETER_HPP_INCLUDED
  1229. #define CATCH_CHRONOMETER_HPP_INCLUDED
  1230. // Adapted from donated nonius code.
  1231. #ifndef CATCH_CLOCK_HPP_INCLUDED
  1232. #define CATCH_CLOCK_HPP_INCLUDED
  1233. #include <chrono>
  1234. #include <ratio>
  1235. namespace Catch {
  1236. namespace Benchmark {
  1237. template <typename Clock>
  1238. using ClockDuration = typename Clock::duration;
  1239. template <typename Clock>
  1240. using FloatDuration = std::chrono::duration<double, typename Clock::period>;
  1241. template <typename Clock>
  1242. using TimePoint = typename Clock::time_point;
  1243. using default_clock = std::chrono::steady_clock;
  1244. template <typename Clock>
  1245. struct now {
  1246. TimePoint<Clock> operator()() const {
  1247. return Clock::now();
  1248. }
  1249. };
  1250. using fp_seconds = std::chrono::duration<double, std::ratio<1>>;
  1251. } // namespace Benchmark
  1252. } // namespace Catch
  1253. #endif // CATCH_CLOCK_HPP_INCLUDED
  1254. // Adapted from donated nonius code.
  1255. #ifndef CATCH_OPTIMIZER_HPP_INCLUDED
  1256. #define CATCH_OPTIMIZER_HPP_INCLUDED
  1257. #if defined(_MSC_VER)
  1258. # include <atomic> // atomic_thread_fence
  1259. #endif
  1260. #include <type_traits>
  1261. namespace Catch {
  1262. namespace Benchmark {
  1263. #if defined(__GNUC__) || defined(__clang__)
  1264. template <typename T>
  1265. inline void keep_memory(T* p) {
  1266. asm volatile("" : : "g"(p) : "memory");
  1267. }
  1268. inline void keep_memory() {
  1269. asm volatile("" : : : "memory");
  1270. }
  1271. namespace Detail {
  1272. inline void optimizer_barrier() { keep_memory(); }
  1273. } // namespace Detail
  1274. #elif defined(_MSC_VER)
  1275. #pragma optimize("", off)
  1276. template <typename T>
  1277. inline void keep_memory(T* p) {
  1278. // thanks @milleniumbug
  1279. *reinterpret_cast<char volatile*>(p) = *reinterpret_cast<char const volatile*>(p);
  1280. }
  1281. // TODO equivalent keep_memory()
  1282. #pragma optimize("", on)
  1283. namespace Detail {
  1284. inline void optimizer_barrier() {
  1285. std::atomic_thread_fence(std::memory_order_seq_cst);
  1286. }
  1287. } // namespace Detail
  1288. #endif
  1289. template <typename T>
  1290. inline void deoptimize_value(T&& x) {
  1291. keep_memory(&x);
  1292. }
  1293. template <typename Fn, typename... Args>
  1294. inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<!std::is_same<void, decltype(fn(args...))>::value> {
  1295. deoptimize_value(CATCH_FORWARD(fn) (CATCH_FORWARD(args)...));
  1296. }
  1297. template <typename Fn, typename... Args>
  1298. inline auto invoke_deoptimized(Fn&& fn, Args&&... args) -> std::enable_if_t<std::is_same<void, decltype(fn(args...))>::value> {
  1299. CATCH_FORWARD(fn) (CATCH_FORWARD(args)...);
  1300. }
  1301. } // namespace Benchmark
  1302. } // namespace Catch
  1303. #endif // CATCH_OPTIMIZER_HPP_INCLUDED
  1304. // Adapted from donated nonius code.
  1305. #ifndef CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1306. #define CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1307. #ifndef CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  1308. #define CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  1309. namespace Catch {
  1310. //! Used to signal that an assertion macro failed
  1311. struct TestFailureException{};
  1312. } // namespace Catch
  1313. #endif // CATCH_TEST_FAILURE_EXCEPTION_HPP_INCLUDED
  1314. #ifndef CATCH_META_HPP_INCLUDED
  1315. #define CATCH_META_HPP_INCLUDED
  1316. #include <type_traits>
  1317. namespace Catch {
  1318. template<typename T>
  1319. struct always_false : std::false_type {};
  1320. template <typename> struct true_given : std::true_type {};
  1321. struct is_callable_tester {
  1322. template <typename Fun, typename... Args>
  1323. static true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> test(int);
  1324. template <typename...>
  1325. static std::false_type test(...);
  1326. };
  1327. template <typename T>
  1328. struct is_callable;
  1329. template <typename Fun, typename... Args>
  1330. struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
  1331. #if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
  1332. // std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
  1333. // replaced with std::invoke_result here.
  1334. template <typename Func, typename... U>
  1335. using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U...>>>;
  1336. #else
  1337. template <typename Func, typename... U>
  1338. using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::result_of_t<Func(U...)>>>;
  1339. #endif
  1340. } // namespace Catch
  1341. namespace mpl_{
  1342. struct na;
  1343. }
  1344. #endif // CATCH_META_HPP_INCLUDED
  1345. #ifndef CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  1346. #define CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  1347. #include <string>
  1348. namespace Catch {
  1349. class TestCaseHandle;
  1350. struct TestCaseInfo;
  1351. class ITestCaseRegistry;
  1352. class IExceptionTranslatorRegistry;
  1353. class IExceptionTranslator;
  1354. class IReporterRegistry;
  1355. class IReporterFactory;
  1356. class ITagAliasRegistry;
  1357. class ITestInvoker;
  1358. class IMutableEnumValuesRegistry;
  1359. struct SourceLineInfo;
  1360. class StartupExceptionRegistry;
  1361. class EventListenerFactory;
  1362. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  1363. class IRegistryHub {
  1364. public:
  1365. virtual ~IRegistryHub(); // = default
  1366. virtual IReporterRegistry const& getReporterRegistry() const = 0;
  1367. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  1368. virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
  1369. virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
  1370. virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
  1371. };
  1372. class IMutableRegistryHub {
  1373. public:
  1374. virtual ~IMutableRegistryHub(); // = default
  1375. virtual void registerReporter( std::string const& name, IReporterFactoryPtr factory ) = 0;
  1376. virtual void registerListener( Detail::unique_ptr<EventListenerFactory> factory ) = 0;
  1377. virtual void registerTest(Detail::unique_ptr<TestCaseInfo>&& testInfo, Detail::unique_ptr<ITestInvoker>&& invoker) = 0;
  1378. virtual void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator ) = 0;
  1379. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
  1380. virtual void registerStartupException() noexcept = 0;
  1381. virtual IMutableEnumValuesRegistry& getMutableEnumValuesRegistry() = 0;
  1382. };
  1383. IRegistryHub const& getRegistryHub();
  1384. IMutableRegistryHub& getMutableRegistryHub();
  1385. void cleanUp();
  1386. std::string translateActiveException();
  1387. }
  1388. #endif // CATCH_INTERFACES_REGISTRY_HUB_HPP_INCLUDED
  1389. #include <type_traits>
  1390. namespace Catch {
  1391. namespace Benchmark {
  1392. namespace Detail {
  1393. template <typename T>
  1394. struct CompleteType { using type = T; };
  1395. template <>
  1396. struct CompleteType<void> { struct type {}; };
  1397. template <typename T>
  1398. using CompleteType_t = typename CompleteType<T>::type;
  1399. template <typename Result>
  1400. struct CompleteInvoker {
  1401. template <typename Fun, typename... Args>
  1402. static Result invoke(Fun&& fun, Args&&... args) {
  1403. return CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
  1404. }
  1405. };
  1406. template <>
  1407. struct CompleteInvoker<void> {
  1408. template <typename Fun, typename... Args>
  1409. static CompleteType_t<void> invoke(Fun&& fun, Args&&... args) {
  1410. CATCH_FORWARD(fun)(CATCH_FORWARD(args)...);
  1411. return {};
  1412. }
  1413. };
  1414. // invoke and not return void :(
  1415. template <typename Fun, typename... Args>
  1416. CompleteType_t<FunctionReturnType<Fun, Args...>> complete_invoke(Fun&& fun, Args&&... args) {
  1417. return CompleteInvoker<FunctionReturnType<Fun, Args...>>::invoke(CATCH_FORWARD(fun), CATCH_FORWARD(args)...);
  1418. }
  1419. } // namespace Detail
  1420. template <typename Fun>
  1421. Detail::CompleteType_t<FunctionReturnType<Fun>> user_code(Fun&& fun) {
  1422. return Detail::complete_invoke(CATCH_FORWARD(fun));
  1423. }
  1424. } // namespace Benchmark
  1425. } // namespace Catch
  1426. #endif // CATCH_COMPLETE_INVOKE_HPP_INCLUDED
  1427. namespace Catch {
  1428. namespace Benchmark {
  1429. namespace Detail {
  1430. struct ChronometerConcept {
  1431. virtual void start() = 0;
  1432. virtual void finish() = 0;
  1433. virtual ~ChronometerConcept(); // = default;
  1434. ChronometerConcept() = default;
  1435. ChronometerConcept(ChronometerConcept const&) = default;
  1436. ChronometerConcept& operator=(ChronometerConcept const&) = default;
  1437. };
  1438. template <typename Clock>
  1439. struct ChronometerModel final : public ChronometerConcept {
  1440. void start() override { started = Clock::now(); }
  1441. void finish() override { finished = Clock::now(); }
  1442. ClockDuration<Clock> elapsed() const { return finished - started; }
  1443. TimePoint<Clock> started;
  1444. TimePoint<Clock> finished;
  1445. };
  1446. } // namespace Detail
  1447. struct Chronometer {
  1448. public:
  1449. template <typename Fun>
  1450. void measure(Fun&& fun) { measure(CATCH_FORWARD(fun), is_callable<Fun(int)>()); }
  1451. int runs() const { return repeats; }
  1452. Chronometer(Detail::ChronometerConcept& meter, int repeats_)
  1453. : impl(&meter)
  1454. , repeats(repeats_) {}
  1455. private:
  1456. template <typename Fun>
  1457. void measure(Fun&& fun, std::false_type) {
  1458. measure([&fun](int) { return fun(); }, std::true_type());
  1459. }
  1460. template <typename Fun>
  1461. void measure(Fun&& fun, std::true_type) {
  1462. Detail::optimizer_barrier();
  1463. impl->start();
  1464. for (int i = 0; i < repeats; ++i) invoke_deoptimized(fun, i);
  1465. impl->finish();
  1466. Detail::optimizer_barrier();
  1467. }
  1468. Detail::ChronometerConcept* impl;
  1469. int repeats;
  1470. };
  1471. } // namespace Benchmark
  1472. } // namespace Catch
  1473. #endif // CATCH_CHRONOMETER_HPP_INCLUDED
  1474. // Adapted from donated nonius code.
  1475. #ifndef CATCH_ENVIRONMENT_HPP_INCLUDED
  1476. #define CATCH_ENVIRONMENT_HPP_INCLUDED
  1477. namespace Catch {
  1478. namespace Benchmark {
  1479. template <typename Duration>
  1480. struct EnvironmentEstimate {
  1481. Duration mean;
  1482. OutlierClassification outliers;
  1483. template <typename Duration2>
  1484. operator EnvironmentEstimate<Duration2>() const {
  1485. return { mean, outliers };
  1486. }
  1487. };
  1488. template <typename Clock>
  1489. struct Environment {
  1490. using clock_type = Clock;
  1491. EnvironmentEstimate<FloatDuration<Clock>> clock_resolution;
  1492. EnvironmentEstimate<FloatDuration<Clock>> clock_cost;
  1493. };
  1494. } // namespace Benchmark
  1495. } // namespace Catch
  1496. #endif // CATCH_ENVIRONMENT_HPP_INCLUDED
  1497. // Adapted from donated nonius code.
  1498. #ifndef CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1499. #define CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1500. // Adapted from donated nonius code.
  1501. #ifndef CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1502. #define CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1503. #include <type_traits>
  1504. namespace Catch {
  1505. namespace Benchmark {
  1506. namespace Detail {
  1507. template <typename T, typename U>
  1508. struct is_related
  1509. : std::is_same<std::decay_t<T>, std::decay_t<U>> {};
  1510. /// We need to reinvent std::function because every piece of code that might add overhead
  1511. /// in a measurement context needs to have consistent performance characteristics so that we
  1512. /// can account for it in the measurement.
  1513. /// Implementations of std::function with optimizations that aren't always applicable, like
  1514. /// small buffer optimizations, are not uncommon.
  1515. /// This is effectively an implementation of std::function without any such optimizations;
  1516. /// it may be slow, but it is consistently slow.
  1517. struct BenchmarkFunction {
  1518. private:
  1519. struct callable {
  1520. virtual void call(Chronometer meter) const = 0;
  1521. virtual Catch::Detail::unique_ptr<callable> clone() const = 0;
  1522. virtual ~callable(); // = default;
  1523. callable() = default;
  1524. callable(callable const&) = default;
  1525. callable& operator=(callable const&) = default;
  1526. };
  1527. template <typename Fun>
  1528. struct model : public callable {
  1529. model(Fun&& fun_) : fun(CATCH_MOVE(fun_)) {}
  1530. model(Fun const& fun_) : fun(fun_) {}
  1531. Catch::Detail::unique_ptr<callable> clone() const override {
  1532. return Catch::Detail::make_unique<model<Fun>>( *this );
  1533. }
  1534. void call(Chronometer meter) const override {
  1535. call(meter, is_callable<Fun(Chronometer)>());
  1536. }
  1537. void call(Chronometer meter, std::true_type) const {
  1538. fun(meter);
  1539. }
  1540. void call(Chronometer meter, std::false_type) const {
  1541. meter.measure(fun);
  1542. }
  1543. Fun fun;
  1544. };
  1545. struct do_nothing { void operator()() const {} };
  1546. template <typename T>
  1547. BenchmarkFunction(model<T>* c) : f(c) {}
  1548. public:
  1549. BenchmarkFunction()
  1550. : f(new model<do_nothing>{ {} }) {}
  1551. template <typename Fun,
  1552. std::enable_if_t<!is_related<Fun, BenchmarkFunction>::value, int> = 0>
  1553. BenchmarkFunction(Fun&& fun)
  1554. : f(new model<std::decay_t<Fun>>(CATCH_FORWARD(fun))) {}
  1555. BenchmarkFunction( BenchmarkFunction&& that ) noexcept:
  1556. f( CATCH_MOVE( that.f ) ) {}
  1557. BenchmarkFunction(BenchmarkFunction const& that)
  1558. : f(that.f->clone()) {}
  1559. BenchmarkFunction&
  1560. operator=( BenchmarkFunction&& that ) noexcept {
  1561. f = CATCH_MOVE( that.f );
  1562. return *this;
  1563. }
  1564. BenchmarkFunction& operator=(BenchmarkFunction const& that) {
  1565. f = that.f->clone();
  1566. return *this;
  1567. }
  1568. void operator()(Chronometer meter) const { f->call(meter); }
  1569. private:
  1570. Catch::Detail::unique_ptr<callable> f;
  1571. };
  1572. } // namespace Detail
  1573. } // namespace Benchmark
  1574. } // namespace Catch
  1575. #endif // CATCH_BENCHMARK_FUNCTION_HPP_INCLUDED
  1576. // Adapted from donated nonius code.
  1577. #ifndef CATCH_REPEAT_HPP_INCLUDED
  1578. #define CATCH_REPEAT_HPP_INCLUDED
  1579. #include <type_traits>
  1580. namespace Catch {
  1581. namespace Benchmark {
  1582. namespace Detail {
  1583. template <typename Fun>
  1584. struct repeater {
  1585. void operator()(int k) const {
  1586. for (int i = 0; i < k; ++i) {
  1587. fun();
  1588. }
  1589. }
  1590. Fun fun;
  1591. };
  1592. template <typename Fun>
  1593. repeater<std::decay_t<Fun>> repeat(Fun&& fun) {
  1594. return { CATCH_FORWARD(fun) };
  1595. }
  1596. } // namespace Detail
  1597. } // namespace Benchmark
  1598. } // namespace Catch
  1599. #endif // CATCH_REPEAT_HPP_INCLUDED
  1600. // Adapted from donated nonius code.
  1601. #ifndef CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1602. #define CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1603. // Adapted from donated nonius code.
  1604. #ifndef CATCH_MEASURE_HPP_INCLUDED
  1605. #define CATCH_MEASURE_HPP_INCLUDED
  1606. // Adapted from donated nonius code.
  1607. #ifndef CATCH_TIMING_HPP_INCLUDED
  1608. #define CATCH_TIMING_HPP_INCLUDED
  1609. #include <type_traits>
  1610. namespace Catch {
  1611. namespace Benchmark {
  1612. template <typename Duration, typename Result>
  1613. struct Timing {
  1614. Duration elapsed;
  1615. Result result;
  1616. int iterations;
  1617. };
  1618. template <typename Clock, typename Func, typename... Args>
  1619. using TimingOf = Timing<ClockDuration<Clock>, Detail::CompleteType_t<FunctionReturnType<Func, Args...>>>;
  1620. } // namespace Benchmark
  1621. } // namespace Catch
  1622. #endif // CATCH_TIMING_HPP_INCLUDED
  1623. namespace Catch {
  1624. namespace Benchmark {
  1625. namespace Detail {
  1626. template <typename Clock, typename Fun, typename... Args>
  1627. TimingOf<Clock, Fun, Args...> measure(Fun&& fun, Args&&... args) {
  1628. auto start = Clock::now();
  1629. auto&& r = Detail::complete_invoke(fun, CATCH_FORWARD(args)...);
  1630. auto end = Clock::now();
  1631. auto delta = end - start;
  1632. return { delta, CATCH_FORWARD(r), 1 };
  1633. }
  1634. } // namespace Detail
  1635. } // namespace Benchmark
  1636. } // namespace Catch
  1637. #endif // CATCH_MEASURE_HPP_INCLUDED
  1638. #include <type_traits>
  1639. namespace Catch {
  1640. namespace Benchmark {
  1641. namespace Detail {
  1642. template <typename Clock, typename Fun>
  1643. TimingOf<Clock, Fun, int> measure_one(Fun&& fun, int iters, std::false_type) {
  1644. return Detail::measure<Clock>(fun, iters);
  1645. }
  1646. template <typename Clock, typename Fun>
  1647. TimingOf<Clock, Fun, Chronometer> measure_one(Fun&& fun, int iters, std::true_type) {
  1648. Detail::ChronometerModel<Clock> meter;
  1649. auto&& result = Detail::complete_invoke(fun, Chronometer(meter, iters));
  1650. return { meter.elapsed(), CATCH_MOVE(result), iters };
  1651. }
  1652. template <typename Clock, typename Fun>
  1653. using run_for_at_least_argument_t = std::conditional_t<is_callable<Fun(Chronometer)>::value, Chronometer, int>;
  1654. [[noreturn]]
  1655. void throw_optimized_away_error();
  1656. template <typename Clock, typename Fun>
  1657. TimingOf<Clock, Fun, run_for_at_least_argument_t<Clock, Fun>>
  1658. run_for_at_least(ClockDuration<Clock> how_long,
  1659. const int initial_iterations,
  1660. Fun&& fun) {
  1661. auto iters = initial_iterations;
  1662. while (iters < (1 << 30)) {
  1663. auto&& Timing = measure_one<Clock>(fun, iters, is_callable<Fun(Chronometer)>());
  1664. if (Timing.elapsed >= how_long) {
  1665. return { Timing.elapsed, CATCH_MOVE(Timing.result), iters };
  1666. }
  1667. iters *= 2;
  1668. }
  1669. throw_optimized_away_error();
  1670. }
  1671. } // namespace Detail
  1672. } // namespace Benchmark
  1673. } // namespace Catch
  1674. #endif // CATCH_RUN_FOR_AT_LEAST_HPP_INCLUDED
  1675. #include <algorithm>
  1676. #include <iterator>
  1677. namespace Catch {
  1678. namespace Benchmark {
  1679. template <typename Duration>
  1680. struct ExecutionPlan {
  1681. int iterations_per_sample;
  1682. Duration estimated_duration;
  1683. Detail::BenchmarkFunction benchmark;
  1684. Duration warmup_time;
  1685. int warmup_iterations;
  1686. template <typename Duration2>
  1687. operator ExecutionPlan<Duration2>() const {
  1688. return { iterations_per_sample, estimated_duration, benchmark, warmup_time, warmup_iterations };
  1689. }
  1690. template <typename Clock>
  1691. std::vector<FloatDuration<Clock>> run(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
  1692. // warmup a bit
  1693. Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_iterations, Detail::repeat(now<Clock>{}));
  1694. std::vector<FloatDuration<Clock>> times;
  1695. times.reserve(cfg.benchmarkSamples());
  1696. std::generate_n(std::back_inserter(times), cfg.benchmarkSamples(), [this, env] {
  1697. Detail::ChronometerModel<Clock> model;
  1698. this->benchmark(Chronometer(model, iterations_per_sample));
  1699. auto sample_time = model.elapsed() - env.clock_cost.mean;
  1700. if (sample_time < FloatDuration<Clock>::zero()) sample_time = FloatDuration<Clock>::zero();
  1701. return sample_time / iterations_per_sample;
  1702. });
  1703. return times;
  1704. }
  1705. };
  1706. } // namespace Benchmark
  1707. } // namespace Catch
  1708. #endif // CATCH_EXECUTION_PLAN_HPP_INCLUDED
  1709. // Adapted from donated nonius code.
  1710. #ifndef CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1711. #define CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1712. // Adapted from donated nonius code.
  1713. #ifndef CATCH_STATS_HPP_INCLUDED
  1714. #define CATCH_STATS_HPP_INCLUDED
  1715. #include <algorithm>
  1716. #include <vector>
  1717. #include <numeric>
  1718. #include <tuple>
  1719. #include <cmath>
  1720. namespace Catch {
  1721. namespace Benchmark {
  1722. namespace Detail {
  1723. using sample = std::vector<double>;
  1724. // Used when we know we want == comparison of two doubles
  1725. // to centralize warning suppression
  1726. bool directCompare( double lhs, double rhs );
  1727. double weighted_average_quantile(int k, int q, std::vector<double>::iterator first, std::vector<double>::iterator last);
  1728. template <typename Iterator>
  1729. OutlierClassification classify_outliers(Iterator first, Iterator last) {
  1730. std::vector<double> copy(first, last);
  1731. auto q1 = weighted_average_quantile(1, 4, copy.begin(), copy.end());
  1732. auto q3 = weighted_average_quantile(3, 4, copy.begin(), copy.end());
  1733. auto iqr = q3 - q1;
  1734. auto los = q1 - (iqr * 3.);
  1735. auto lom = q1 - (iqr * 1.5);
  1736. auto him = q3 + (iqr * 1.5);
  1737. auto his = q3 + (iqr * 3.);
  1738. OutlierClassification o;
  1739. for (; first != last; ++first) {
  1740. auto&& t = *first;
  1741. if (t < los) ++o.low_severe;
  1742. else if (t < lom) ++o.low_mild;
  1743. else if (t > his) ++o.high_severe;
  1744. else if (t > him) ++o.high_mild;
  1745. ++o.samples_seen;
  1746. }
  1747. return o;
  1748. }
  1749. template <typename Iterator>
  1750. double mean(Iterator first, Iterator last) {
  1751. auto count = last - first;
  1752. double sum = std::accumulate(first, last, 0.);
  1753. return sum / static_cast<double>(count);
  1754. }
  1755. template <typename Estimator, typename Iterator>
  1756. sample jackknife(Estimator&& estimator, Iterator first, Iterator last) {
  1757. auto n = static_cast<size_t>(last - first);
  1758. auto second = first;
  1759. ++second;
  1760. sample results;
  1761. results.reserve(n);
  1762. for (auto it = first; it != last; ++it) {
  1763. std::iter_swap(it, first);
  1764. results.push_back(estimator(second, last));
  1765. }
  1766. return results;
  1767. }
  1768. inline double normal_cdf(double x) {
  1769. return std::erfc(-x / std::sqrt(2.0)) / 2.0;
  1770. }
  1771. double erfc_inv(double x);
  1772. double normal_quantile(double p);
  1773. template <typename Iterator, typename Estimator>
  1774. Estimate<double> bootstrap(double confidence_level, Iterator first, Iterator last, sample const& resample, Estimator&& estimator) {
  1775. auto n_samples = last - first;
  1776. double point = estimator(first, last);
  1777. // Degenerate case with a single sample
  1778. if (n_samples == 1) return { point, point, point, confidence_level };
  1779. sample jack = jackknife(estimator, first, last);
  1780. double jack_mean = mean(jack.begin(), jack.end());
  1781. double sum_squares, sum_cubes;
  1782. std::tie(sum_squares, sum_cubes) = std::accumulate(jack.begin(), jack.end(), std::make_pair(0., 0.), [jack_mean](std::pair<double, double> sqcb, double x) -> std::pair<double, double> {
  1783. auto d = jack_mean - x;
  1784. auto d2 = d * d;
  1785. auto d3 = d2 * d;
  1786. return { sqcb.first + d2, sqcb.second + d3 };
  1787. });
  1788. double accel = sum_cubes / (6 * std::pow(sum_squares, 1.5));
  1789. long n = static_cast<long>(resample.size());
  1790. double prob_n = std::count_if(resample.begin(), resample.end(), [point](double x) { return x < point; }) / static_cast<double>(n);
  1791. // degenerate case with uniform samples
  1792. if ( directCompare( prob_n, 0. ) ) {
  1793. return { point, point, point, confidence_level };
  1794. }
  1795. double bias = normal_quantile(prob_n);
  1796. double z1 = normal_quantile((1. - confidence_level) / 2.);
  1797. auto cumn = [n]( double x ) -> long {
  1798. return std::lround( normal_cdf( x ) * static_cast<double>(n) );
  1799. };
  1800. auto a = [bias, accel](double b) { return bias + b / (1. - accel * b); };
  1801. double b1 = bias + z1;
  1802. double b2 = bias - z1;
  1803. double a1 = a(b1);
  1804. double a2 = a(b2);
  1805. auto lo = static_cast<size_t>((std::max)(cumn(a1), 0l));
  1806. auto hi = static_cast<size_t>((std::min)(cumn(a2), n - 1));
  1807. return { point, resample[lo], resample[hi], confidence_level };
  1808. }
  1809. double outlier_variance(Estimate<double> mean, Estimate<double> stddev, int n);
  1810. struct bootstrap_analysis {
  1811. Estimate<double> mean;
  1812. Estimate<double> standard_deviation;
  1813. double outlier_variance;
  1814. };
  1815. bootstrap_analysis analyse_samples(double confidence_level, unsigned int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last);
  1816. } // namespace Detail
  1817. } // namespace Benchmark
  1818. } // namespace Catch
  1819. #endif // CATCH_STATS_HPP_INCLUDED
  1820. #include <algorithm>
  1821. #include <iterator>
  1822. #include <vector>
  1823. #include <cmath>
  1824. namespace Catch {
  1825. namespace Benchmark {
  1826. namespace Detail {
  1827. template <typename Clock>
  1828. std::vector<double> resolution(int k) {
  1829. std::vector<TimePoint<Clock>> times;
  1830. times.reserve(static_cast<size_t>(k + 1));
  1831. std::generate_n(std::back_inserter(times), k + 1, now<Clock>{});
  1832. std::vector<double> deltas;
  1833. deltas.reserve(static_cast<size_t>(k));
  1834. std::transform(std::next(times.begin()), times.end(), times.begin(),
  1835. std::back_inserter(deltas),
  1836. [](TimePoint<Clock> a, TimePoint<Clock> b) { return static_cast<double>((a - b).count()); });
  1837. return deltas;
  1838. }
  1839. const auto warmup_iterations = 10000;
  1840. const auto warmup_time = std::chrono::milliseconds(100);
  1841. const auto minimum_ticks = 1000;
  1842. const auto warmup_seed = 10000;
  1843. const auto clock_resolution_estimation_time = std::chrono::milliseconds(500);
  1844. const auto clock_cost_estimation_time_limit = std::chrono::seconds(1);
  1845. const auto clock_cost_estimation_tick_limit = 100000;
  1846. const auto clock_cost_estimation_time = std::chrono::milliseconds(10);
  1847. const auto clock_cost_estimation_iterations = 10000;
  1848. template <typename Clock>
  1849. int warmup() {
  1850. return run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(warmup_time), warmup_seed, &resolution<Clock>)
  1851. .iterations;
  1852. }
  1853. template <typename Clock>
  1854. EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_resolution(int iterations) {
  1855. auto r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_resolution_estimation_time), iterations, &resolution<Clock>)
  1856. .result;
  1857. return {
  1858. FloatDuration<Clock>(mean(r.begin(), r.end())),
  1859. classify_outliers(r.begin(), r.end()),
  1860. };
  1861. }
  1862. template <typename Clock>
  1863. EnvironmentEstimate<FloatDuration<Clock>> estimate_clock_cost(FloatDuration<Clock> resolution) {
  1864. auto time_limit = (std::min)(
  1865. resolution * clock_cost_estimation_tick_limit,
  1866. FloatDuration<Clock>(clock_cost_estimation_time_limit));
  1867. auto time_clock = [](int k) {
  1868. return Detail::measure<Clock>([k] {
  1869. for (int i = 0; i < k; ++i) {
  1870. volatile auto ignored = Clock::now();
  1871. (void)ignored;
  1872. }
  1873. }).elapsed;
  1874. };
  1875. time_clock(1);
  1876. int iters = clock_cost_estimation_iterations;
  1877. auto&& r = run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(clock_cost_estimation_time), iters, time_clock);
  1878. std::vector<double> times;
  1879. int nsamples = static_cast<int>(std::ceil(time_limit / r.elapsed));
  1880. times.reserve(static_cast<size_t>(nsamples));
  1881. std::generate_n(std::back_inserter(times), nsamples, [time_clock, &r] {
  1882. return static_cast<double>((time_clock(r.iterations) / r.iterations).count());
  1883. });
  1884. return {
  1885. FloatDuration<Clock>(mean(times.begin(), times.end())),
  1886. classify_outliers(times.begin(), times.end()),
  1887. };
  1888. }
  1889. template <typename Clock>
  1890. Environment<FloatDuration<Clock>> measure_environment() {
  1891. #if defined(__clang__)
  1892. # pragma clang diagnostic push
  1893. # pragma clang diagnostic ignored "-Wexit-time-destructors"
  1894. #endif
  1895. static Catch::Detail::unique_ptr<Environment<FloatDuration<Clock>>> env;
  1896. #if defined(__clang__)
  1897. # pragma clang diagnostic pop
  1898. #endif
  1899. if (env) {
  1900. return *env;
  1901. }
  1902. auto iters = Detail::warmup<Clock>();
  1903. auto resolution = Detail::estimate_clock_resolution<Clock>(iters);
  1904. auto cost = Detail::estimate_clock_cost<Clock>(resolution.mean);
  1905. env = Catch::Detail::make_unique<Environment<FloatDuration<Clock>>>( Environment<FloatDuration<Clock>>{resolution, cost} );
  1906. return *env;
  1907. }
  1908. } // namespace Detail
  1909. } // namespace Benchmark
  1910. } // namespace Catch
  1911. #endif // CATCH_ESTIMATE_CLOCK_HPP_INCLUDED
  1912. // Adapted from donated nonius code.
  1913. #ifndef CATCH_ANALYSE_HPP_INCLUDED
  1914. #define CATCH_ANALYSE_HPP_INCLUDED
  1915. // Adapted from donated nonius code.
  1916. #ifndef CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1917. #define CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1918. #include <algorithm>
  1919. #include <vector>
  1920. #include <iterator>
  1921. namespace Catch {
  1922. namespace Benchmark {
  1923. template <typename Duration>
  1924. struct SampleAnalysis {
  1925. std::vector<Duration> samples;
  1926. Estimate<Duration> mean;
  1927. Estimate<Duration> standard_deviation;
  1928. OutlierClassification outliers;
  1929. double outlier_variance;
  1930. template <typename Duration2>
  1931. operator SampleAnalysis<Duration2>() const {
  1932. std::vector<Duration2> samples2;
  1933. samples2.reserve(samples.size());
  1934. std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](Duration d) { return Duration2(d); });
  1935. return {
  1936. CATCH_MOVE(samples2),
  1937. mean,
  1938. standard_deviation,
  1939. outliers,
  1940. outlier_variance,
  1941. };
  1942. }
  1943. };
  1944. } // namespace Benchmark
  1945. } // namespace Catch
  1946. #endif // CATCH_SAMPLE_ANALYSIS_HPP_INCLUDED
  1947. #include <algorithm>
  1948. #include <iterator>
  1949. #include <vector>
  1950. namespace Catch {
  1951. namespace Benchmark {
  1952. namespace Detail {
  1953. template <typename Duration, typename Iterator>
  1954. SampleAnalysis<Duration> analyse(const IConfig &cfg, Environment<Duration>, Iterator first, Iterator last) {
  1955. if (!cfg.benchmarkNoAnalysis()) {
  1956. std::vector<double> samples;
  1957. samples.reserve(static_cast<size_t>(last - first));
  1958. std::transform(first, last, std::back_inserter(samples), [](Duration d) { return d.count(); });
  1959. auto analysis = Catch::Benchmark::Detail::analyse_samples(cfg.benchmarkConfidenceInterval(), cfg.benchmarkResamples(), samples.begin(), samples.end());
  1960. auto outliers = Catch::Benchmark::Detail::classify_outliers(samples.begin(), samples.end());
  1961. auto wrap_estimate = [](Estimate<double> e) {
  1962. return Estimate<Duration> {
  1963. Duration(e.point),
  1964. Duration(e.lower_bound),
  1965. Duration(e.upper_bound),
  1966. e.confidence_interval,
  1967. };
  1968. };
  1969. std::vector<Duration> samples2;
  1970. samples2.reserve(samples.size());
  1971. std::transform(samples.begin(), samples.end(), std::back_inserter(samples2), [](double d) { return Duration(d); });
  1972. return {
  1973. CATCH_MOVE(samples2),
  1974. wrap_estimate(analysis.mean),
  1975. wrap_estimate(analysis.standard_deviation),
  1976. outliers,
  1977. analysis.outlier_variance,
  1978. };
  1979. } else {
  1980. std::vector<Duration> samples;
  1981. samples.reserve(static_cast<size_t>(last - first));
  1982. Duration mean = Duration(0);
  1983. int i = 0;
  1984. for (auto it = first; it < last; ++it, ++i) {
  1985. samples.push_back(Duration(*it));
  1986. mean += Duration(*it);
  1987. }
  1988. mean /= i;
  1989. return {
  1990. CATCH_MOVE(samples),
  1991. Estimate<Duration>{mean, mean, mean, 0.0},
  1992. Estimate<Duration>{Duration(0), Duration(0), Duration(0), 0.0},
  1993. OutlierClassification{},
  1994. 0.0
  1995. };
  1996. }
  1997. }
  1998. } // namespace Detail
  1999. } // namespace Benchmark
  2000. } // namespace Catch
  2001. #endif // CATCH_ANALYSE_HPP_INCLUDED
  2002. #include <algorithm>
  2003. #include <functional>
  2004. #include <string>
  2005. #include <vector>
  2006. #include <cmath>
  2007. namespace Catch {
  2008. namespace Benchmark {
  2009. struct Benchmark {
  2010. Benchmark(std::string&& benchmarkName)
  2011. : name(CATCH_MOVE(benchmarkName)) {}
  2012. template <class FUN>
  2013. Benchmark(std::string&& benchmarkName , FUN &&func)
  2014. : fun(CATCH_MOVE(func)), name(CATCH_MOVE(benchmarkName)) {}
  2015. template <typename Clock>
  2016. ExecutionPlan<FloatDuration<Clock>> prepare(const IConfig &cfg, Environment<FloatDuration<Clock>> env) const {
  2017. auto min_time = env.clock_resolution.mean * Detail::minimum_ticks;
  2018. auto run_time = std::max(min_time, std::chrono::duration_cast<decltype(min_time)>(cfg.benchmarkWarmupTime()));
  2019. auto&& test = Detail::run_for_at_least<Clock>(std::chrono::duration_cast<ClockDuration<Clock>>(run_time), 1, fun);
  2020. int new_iters = static_cast<int>(std::ceil(min_time * test.iterations / test.elapsed));
  2021. return { new_iters, test.elapsed / test.iterations * new_iters * cfg.benchmarkSamples(), fun, std::chrono::duration_cast<FloatDuration<Clock>>(cfg.benchmarkWarmupTime()), Detail::warmup_iterations };
  2022. }
  2023. template <typename Clock = default_clock>
  2024. void run() {
  2025. auto const* cfg = getCurrentContext().getConfig();
  2026. auto env = Detail::measure_environment<Clock>();
  2027. getResultCapture().benchmarkPreparing(name);
  2028. CATCH_TRY{
  2029. auto plan = user_code([&] {
  2030. return prepare<Clock>(*cfg, env);
  2031. });
  2032. BenchmarkInfo info {
  2033. name,
  2034. plan.estimated_duration.count(),
  2035. plan.iterations_per_sample,
  2036. cfg->benchmarkSamples(),
  2037. cfg->benchmarkResamples(),
  2038. env.clock_resolution.mean.count(),
  2039. env.clock_cost.mean.count()
  2040. };
  2041. getResultCapture().benchmarkStarting(info);
  2042. auto samples = user_code([&] {
  2043. return plan.template run<Clock>(*cfg, env);
  2044. });
  2045. auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
  2046. BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
  2047. getResultCapture().benchmarkEnded(stats);
  2048. } CATCH_CATCH_ANON (TestFailureException) {
  2049. getResultCapture().benchmarkFailed("Benchmark failed due to failed assertion"_sr);
  2050. } CATCH_CATCH_ALL{
  2051. getResultCapture().benchmarkFailed(translateActiveException());
  2052. // We let the exception go further up so that the
  2053. // test case is marked as failed.
  2054. std::rethrow_exception(std::current_exception());
  2055. }
  2056. }
  2057. // sets lambda to be used in fun *and* executes benchmark!
  2058. template <typename Fun, std::enable_if_t<!Detail::is_related<Fun, Benchmark>::value, int> = 0>
  2059. Benchmark & operator=(Fun func) {
  2060. auto const* cfg = getCurrentContext().getConfig();
  2061. if (!cfg->skipBenchmarks()) {
  2062. fun = Detail::BenchmarkFunction(func);
  2063. run();
  2064. }
  2065. return *this;
  2066. }
  2067. explicit operator bool() {
  2068. return true;
  2069. }
  2070. private:
  2071. Detail::BenchmarkFunction fun;
  2072. std::string name;
  2073. };
  2074. }
  2075. } // namespace Catch
  2076. #define INTERNAL_CATCH_GET_1_ARG(arg1, arg2, ...) arg1
  2077. #define INTERNAL_CATCH_GET_2_ARG(arg1, arg2, ...) arg2
  2078. #define INTERNAL_CATCH_BENCHMARK(BenchmarkName, name, benchmarkIndex)\
  2079. if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
  2080. BenchmarkName = [&](int benchmarkIndex)
  2081. #define INTERNAL_CATCH_BENCHMARK_ADVANCED(BenchmarkName, name)\
  2082. if( Catch::Benchmark::Benchmark BenchmarkName{name} ) \
  2083. BenchmarkName = [&]
  2084. #if defined(CATCH_CONFIG_PREFIX_ALL)
  2085. #define CATCH_BENCHMARK(...) \
  2086. INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
  2087. #define CATCH_BENCHMARK_ADVANCED(name) \
  2088. INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
  2089. #else
  2090. #define BENCHMARK(...) \
  2091. INTERNAL_CATCH_BENCHMARK(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), INTERNAL_CATCH_GET_1_ARG(__VA_ARGS__,,), INTERNAL_CATCH_GET_2_ARG(__VA_ARGS__,,))
  2092. #define BENCHMARK_ADVANCED(name) \
  2093. INTERNAL_CATCH_BENCHMARK_ADVANCED(INTERNAL_CATCH_UNIQUE_NAME(CATCH2_INTERNAL_BENCHMARK_), name)
  2094. #endif
  2095. #endif // CATCH_BENCHMARK_HPP_INCLUDED
  2096. // Adapted from donated nonius code.
  2097. #ifndef CATCH_CONSTRUCTOR_HPP_INCLUDED
  2098. #define CATCH_CONSTRUCTOR_HPP_INCLUDED
  2099. #include <type_traits>
  2100. namespace Catch {
  2101. namespace Benchmark {
  2102. namespace Detail {
  2103. template <typename T, bool Destruct>
  2104. struct ObjectStorage
  2105. {
  2106. ObjectStorage() = default;
  2107. ObjectStorage(const ObjectStorage& other)
  2108. {
  2109. new(&data) T(other.stored_object());
  2110. }
  2111. ObjectStorage(ObjectStorage&& other)
  2112. {
  2113. new(data) T(CATCH_MOVE(other.stored_object()));
  2114. }
  2115. ~ObjectStorage() { destruct_on_exit<T>(); }
  2116. template <typename... Args>
  2117. void construct(Args&&... args)
  2118. {
  2119. new (data) T(CATCH_FORWARD(args)...);
  2120. }
  2121. template <bool AllowManualDestruction = !Destruct>
  2122. std::enable_if_t<AllowManualDestruction> destruct()
  2123. {
  2124. stored_object().~T();
  2125. }
  2126. private:
  2127. // If this is a constructor benchmark, destruct the underlying object
  2128. template <typename U>
  2129. void destruct_on_exit(std::enable_if_t<Destruct, U>* = nullptr) { destruct<true>(); }
  2130. // Otherwise, don't
  2131. template <typename U>
  2132. void destruct_on_exit(std::enable_if_t<!Destruct, U>* = nullptr) { }
  2133. #if defined( __GNUC__ ) && __GNUC__ <= 6
  2134. # pragma GCC diagnostic push
  2135. # pragma GCC diagnostic ignored "-Wstrict-aliasing"
  2136. #endif
  2137. T& stored_object() { return *reinterpret_cast<T*>( data ); }
  2138. T const& stored_object() const {
  2139. return *reinterpret_cast<T const*>( data );
  2140. }
  2141. #if defined( __GNUC__ ) && __GNUC__ <= 6
  2142. # pragma GCC diagnostic pop
  2143. #endif
  2144. alignas( T ) unsigned char data[sizeof( T )]{};
  2145. };
  2146. } // namespace Detail
  2147. template <typename T>
  2148. using storage_for = Detail::ObjectStorage<T, true>;
  2149. template <typename T>
  2150. using destructable_object = Detail::ObjectStorage<T, false>;
  2151. } // namespace Benchmark
  2152. } // namespace Catch
  2153. #endif // CATCH_CONSTRUCTOR_HPP_INCLUDED
  2154. #endif // CATCH_BENCHMARK_ALL_HPP_INCLUDED
  2155. #ifndef CATCH_APPROX_HPP_INCLUDED
  2156. #define CATCH_APPROX_HPP_INCLUDED
  2157. #ifndef CATCH_TOSTRING_HPP_INCLUDED
  2158. #define CATCH_TOSTRING_HPP_INCLUDED
  2159. #include <vector>
  2160. #include <cstddef>
  2161. #include <type_traits>
  2162. #include <string>
  2163. /** \file
  2164. * Wrapper for the WCHAR configuration option
  2165. *
  2166. * We want to support platforms that do not provide `wchar_t`, so we
  2167. * sometimes have to disable providing wchar_t overloads through Catch2,
  2168. * e.g. the StringMaker specialization for `std::wstring`.
  2169. */
  2170. #ifndef CATCH_CONFIG_WCHAR_HPP_INCLUDED
  2171. #define CATCH_CONFIG_WCHAR_HPP_INCLUDED
  2172. // We assume that WCHAR should be enabled by default, and only disabled
  2173. // for a shortlist (so far only DJGPP) of compilers.
  2174. #if defined(__DJGPP__)
  2175. # define CATCH_INTERNAL_CONFIG_NO_WCHAR
  2176. #endif // __DJGPP__
  2177. #if !defined( CATCH_INTERNAL_CONFIG_NO_WCHAR ) && \
  2178. !defined( CATCH_CONFIG_NO_WCHAR ) && \
  2179. !defined( CATCH_CONFIG_WCHAR )
  2180. # define CATCH_CONFIG_WCHAR
  2181. #endif
  2182. #endif // CATCH_CONFIG_WCHAR_HPP_INCLUDED
  2183. #ifndef CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  2184. #define CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  2185. #include <iosfwd>
  2186. #include <cstddef>
  2187. #include <ostream>
  2188. #include <string>
  2189. namespace Catch {
  2190. class ReusableStringStream : Detail::NonCopyable {
  2191. std::size_t m_index;
  2192. std::ostream* m_oss;
  2193. public:
  2194. ReusableStringStream();
  2195. ~ReusableStringStream();
  2196. //! Returns the serialized state
  2197. std::string str() const;
  2198. //! Sets internal state to `str`
  2199. void str(std::string const& str);
  2200. #if defined(__GNUC__) && !defined(__clang__)
  2201. #pragma GCC diagnostic push
  2202. // Old versions of GCC do not understand -Wnonnull-compare
  2203. #pragma GCC diagnostic ignored "-Wpragmas"
  2204. // Streaming a function pointer triggers Waddress and Wnonnull-compare
  2205. // on GCC, because it implicitly converts it to bool and then decides
  2206. // that the check it uses (a? true : false) is tautological and cannot
  2207. // be null...
  2208. #pragma GCC diagnostic ignored "-Waddress"
  2209. #pragma GCC diagnostic ignored "-Wnonnull-compare"
  2210. #endif
  2211. template<typename T>
  2212. auto operator << ( T const& value ) -> ReusableStringStream& {
  2213. *m_oss << value;
  2214. return *this;
  2215. }
  2216. #if defined(__GNUC__) && !defined(__clang__)
  2217. #pragma GCC diagnostic pop
  2218. #endif
  2219. auto get() -> std::ostream& { return *m_oss; }
  2220. };
  2221. }
  2222. #endif // CATCH_REUSABLE_STRING_STREAM_HPP_INCLUDED
  2223. #ifndef CATCH_VOID_TYPE_HPP_INCLUDED
  2224. #define CATCH_VOID_TYPE_HPP_INCLUDED
  2225. namespace Catch {
  2226. namespace Detail {
  2227. template <typename...>
  2228. struct make_void { using type = void; };
  2229. template <typename... Ts>
  2230. using void_t = typename make_void<Ts...>::type;
  2231. } // namespace Detail
  2232. } // namespace Catch
  2233. #endif // CATCH_VOID_TYPE_HPP_INCLUDED
  2234. #ifndef CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  2235. #define CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  2236. #include <vector>
  2237. namespace Catch {
  2238. namespace Detail {
  2239. struct EnumInfo {
  2240. StringRef m_name;
  2241. std::vector<std::pair<int, StringRef>> m_values;
  2242. ~EnumInfo();
  2243. StringRef lookup( int value ) const;
  2244. };
  2245. } // namespace Detail
  2246. class IMutableEnumValuesRegistry {
  2247. public:
  2248. virtual ~IMutableEnumValuesRegistry(); // = default;
  2249. virtual Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values ) = 0;
  2250. template<typename E>
  2251. Detail::EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::initializer_list<E> values ) {
  2252. static_assert(sizeof(int) >= sizeof(E), "Cannot serialize enum to int");
  2253. std::vector<int> intValues;
  2254. intValues.reserve( values.size() );
  2255. for( auto enumValue : values )
  2256. intValues.push_back( static_cast<int>( enumValue ) );
  2257. return registerEnum( enumName, allEnums, intValues );
  2258. }
  2259. };
  2260. } // Catch
  2261. #endif // CATCH_INTERFACES_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  2262. #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  2263. #include <string_view>
  2264. #endif
  2265. #ifdef _MSC_VER
  2266. #pragma warning(push)
  2267. #pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
  2268. #endif
  2269. // We need a dummy global operator<< so we can bring it into Catch namespace later
  2270. struct Catch_global_namespace_dummy{};
  2271. std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
  2272. namespace Catch {
  2273. // Bring in global namespace operator<< for ADL lookup in
  2274. // `IsStreamInsertable` below.
  2275. using ::operator<<;
  2276. namespace Detail {
  2277. inline std::size_t catch_strnlen(const char *str, std::size_t n) {
  2278. auto ret = std::char_traits<char>::find(str, n, '\0');
  2279. if (ret != nullptr) {
  2280. return static_cast<std::size_t>(ret - str);
  2281. }
  2282. return n;
  2283. }
  2284. constexpr StringRef unprintableString = "{?}"_sr;
  2285. //! Encases `string in quotes, and optionally escapes invisibles
  2286. std::string convertIntoString( StringRef string, bool escapeInvisibles );
  2287. //! Encases `string` in quotes, and escapes invisibles if user requested
  2288. //! it via CLI
  2289. std::string convertIntoString( StringRef string );
  2290. std::string rawMemoryToString( const void *object, std::size_t size );
  2291. template<typename T>
  2292. std::string rawMemoryToString( const T& object ) {
  2293. return rawMemoryToString( &object, sizeof(object) );
  2294. }
  2295. template<typename T>
  2296. class IsStreamInsertable {
  2297. template<typename Stream, typename U>
  2298. static auto test(int)
  2299. -> decltype(std::declval<Stream&>() << std::declval<U>(), std::true_type());
  2300. template<typename, typename>
  2301. static auto test(...)->std::false_type;
  2302. public:
  2303. static const bool value = decltype(test<std::ostream, const T&>(0))::value;
  2304. };
  2305. template<typename E>
  2306. std::string convertUnknownEnumToString( E e );
  2307. template<typename T>
  2308. std::enable_if_t<
  2309. !std::is_enum<T>::value && !std::is_base_of<std::exception, T>::value,
  2310. std::string> convertUnstreamable( T const& ) {
  2311. return std::string(Detail::unprintableString);
  2312. }
  2313. template<typename T>
  2314. std::enable_if_t<
  2315. !std::is_enum<T>::value && std::is_base_of<std::exception, T>::value,
  2316. std::string> convertUnstreamable(T const& ex) {
  2317. return ex.what();
  2318. }
  2319. template<typename T>
  2320. std::enable_if_t<
  2321. std::is_enum<T>::value,
  2322. std::string> convertUnstreamable( T const& value ) {
  2323. return convertUnknownEnumToString( value );
  2324. }
  2325. #if defined(_MANAGED)
  2326. //! Convert a CLR string to a utf8 std::string
  2327. template<typename T>
  2328. std::string clrReferenceToString( T^ ref ) {
  2329. if (ref == nullptr)
  2330. return std::string("null");
  2331. auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
  2332. cli::pin_ptr<System::Byte> p = &bytes[0];
  2333. return std::string(reinterpret_cast<char const *>(p), bytes->Length);
  2334. }
  2335. #endif
  2336. } // namespace Detail
  2337. // If we decide for C++14, change these to enable_if_ts
  2338. template <typename T, typename = void>
  2339. struct StringMaker {
  2340. template <typename Fake = T>
  2341. static
  2342. std::enable_if_t<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>
  2343. convert(const Fake& value) {
  2344. ReusableStringStream rss;
  2345. // NB: call using the function-like syntax to avoid ambiguity with
  2346. // user-defined templated operator<< under clang.
  2347. rss.operator<<(value);
  2348. return rss.str();
  2349. }
  2350. template <typename Fake = T>
  2351. static
  2352. std::enable_if_t<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>
  2353. convert( const Fake& value ) {
  2354. #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
  2355. return Detail::convertUnstreamable(value);
  2356. #else
  2357. return CATCH_CONFIG_FALLBACK_STRINGIFIER(value);
  2358. #endif
  2359. }
  2360. };
  2361. namespace Detail {
  2362. // This function dispatches all stringification requests inside of Catch.
  2363. // Should be preferably called fully qualified, like ::Catch::Detail::stringify
  2364. template <typename T>
  2365. std::string stringify(const T& e) {
  2366. return ::Catch::StringMaker<std::remove_cv_t<std::remove_reference_t<T>>>::convert(e);
  2367. }
  2368. template<typename E>
  2369. std::string convertUnknownEnumToString( E e ) {
  2370. return ::Catch::Detail::stringify(static_cast<std::underlying_type_t<E>>(e));
  2371. }
  2372. #if defined(_MANAGED)
  2373. template <typename T>
  2374. std::string stringify( T^ e ) {
  2375. return ::Catch::StringMaker<T^>::convert(e);
  2376. }
  2377. #endif
  2378. } // namespace Detail
  2379. // Some predefined specializations
  2380. template<>
  2381. struct StringMaker<std::string> {
  2382. static std::string convert(const std::string& str);
  2383. };
  2384. #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  2385. template<>
  2386. struct StringMaker<std::string_view> {
  2387. static std::string convert(std::string_view str);
  2388. };
  2389. #endif
  2390. template<>
  2391. struct StringMaker<char const *> {
  2392. static std::string convert(char const * str);
  2393. };
  2394. template<>
  2395. struct StringMaker<char *> {
  2396. static std::string convert(char * str);
  2397. };
  2398. #if defined(CATCH_CONFIG_WCHAR)
  2399. template<>
  2400. struct StringMaker<std::wstring> {
  2401. static std::string convert(const std::wstring& wstr);
  2402. };
  2403. # ifdef CATCH_CONFIG_CPP17_STRING_VIEW
  2404. template<>
  2405. struct StringMaker<std::wstring_view> {
  2406. static std::string convert(std::wstring_view str);
  2407. };
  2408. # endif
  2409. template<>
  2410. struct StringMaker<wchar_t const *> {
  2411. static std::string convert(wchar_t const * str);
  2412. };
  2413. template<>
  2414. struct StringMaker<wchar_t *> {
  2415. static std::string convert(wchar_t * str);
  2416. };
  2417. #endif // CATCH_CONFIG_WCHAR
  2418. template<size_t SZ>
  2419. struct StringMaker<char[SZ]> {
  2420. static std::string convert(char const* str) {
  2421. return Detail::convertIntoString(
  2422. StringRef( str, Detail::catch_strnlen( str, SZ ) ) );
  2423. }
  2424. };
  2425. template<size_t SZ>
  2426. struct StringMaker<signed char[SZ]> {
  2427. static std::string convert(signed char const* str) {
  2428. auto reinterpreted = reinterpret_cast<char const*>(str);
  2429. return Detail::convertIntoString(
  2430. StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
  2431. }
  2432. };
  2433. template<size_t SZ>
  2434. struct StringMaker<unsigned char[SZ]> {
  2435. static std::string convert(unsigned char const* str) {
  2436. auto reinterpreted = reinterpret_cast<char const*>(str);
  2437. return Detail::convertIntoString(
  2438. StringRef(reinterpreted, Detail::catch_strnlen(reinterpreted, SZ)));
  2439. }
  2440. };
  2441. #if defined(CATCH_CONFIG_CPP17_BYTE)
  2442. template<>
  2443. struct StringMaker<std::byte> {
  2444. static std::string convert(std::byte value);
  2445. };
  2446. #endif // defined(CATCH_CONFIG_CPP17_BYTE)
  2447. template<>
  2448. struct StringMaker<int> {
  2449. static std::string convert(int value);
  2450. };
  2451. template<>
  2452. struct StringMaker<long> {
  2453. static std::string convert(long value);
  2454. };
  2455. template<>
  2456. struct StringMaker<long long> {
  2457. static std::string convert(long long value);
  2458. };
  2459. template<>
  2460. struct StringMaker<unsigned int> {
  2461. static std::string convert(unsigned int value);
  2462. };
  2463. template<>
  2464. struct StringMaker<unsigned long> {
  2465. static std::string convert(unsigned long value);
  2466. };
  2467. template<>
  2468. struct StringMaker<unsigned long long> {
  2469. static std::string convert(unsigned long long value);
  2470. };
  2471. template<>
  2472. struct StringMaker<bool> {
  2473. static std::string convert(bool b) {
  2474. using namespace std::string_literals;
  2475. return b ? "true"s : "false"s;
  2476. }
  2477. };
  2478. template<>
  2479. struct StringMaker<char> {
  2480. static std::string convert(char c);
  2481. };
  2482. template<>
  2483. struct StringMaker<signed char> {
  2484. static std::string convert(signed char c);
  2485. };
  2486. template<>
  2487. struct StringMaker<unsigned char> {
  2488. static std::string convert(unsigned char c);
  2489. };
  2490. template<>
  2491. struct StringMaker<std::nullptr_t> {
  2492. static std::string convert(std::nullptr_t) {
  2493. using namespace std::string_literals;
  2494. return "nullptr"s;
  2495. }
  2496. };
  2497. template<>
  2498. struct StringMaker<float> {
  2499. static std::string convert(float value);
  2500. CATCH_EXPORT static int precision;
  2501. };
  2502. template<>
  2503. struct StringMaker<double> {
  2504. static std::string convert(double value);
  2505. CATCH_EXPORT static int precision;
  2506. };
  2507. template <typename T>
  2508. struct StringMaker<T*> {
  2509. template <typename U>
  2510. static std::string convert(U* p) {
  2511. if (p) {
  2512. return ::Catch::Detail::rawMemoryToString(p);
  2513. } else {
  2514. return "nullptr";
  2515. }
  2516. }
  2517. };
  2518. template <typename R, typename C>
  2519. struct StringMaker<R C::*> {
  2520. static std::string convert(R C::* p) {
  2521. if (p) {
  2522. return ::Catch::Detail::rawMemoryToString(p);
  2523. } else {
  2524. return "nullptr";
  2525. }
  2526. }
  2527. };
  2528. #if defined(_MANAGED)
  2529. template <typename T>
  2530. struct StringMaker<T^> {
  2531. static std::string convert( T^ ref ) {
  2532. return ::Catch::Detail::clrReferenceToString(ref);
  2533. }
  2534. };
  2535. #endif
  2536. namespace Detail {
  2537. template<typename InputIterator, typename Sentinel = InputIterator>
  2538. std::string rangeToString(InputIterator first, Sentinel last) {
  2539. ReusableStringStream rss;
  2540. rss << "{ ";
  2541. if (first != last) {
  2542. rss << ::Catch::Detail::stringify(*first);
  2543. for (++first; first != last; ++first)
  2544. rss << ", " << ::Catch::Detail::stringify(*first);
  2545. }
  2546. rss << " }";
  2547. return rss.str();
  2548. }
  2549. }
  2550. } // namespace Catch
  2551. //////////////////////////////////////////////////////
  2552. // Separate std-lib types stringification, so it can be selectively enabled
  2553. // This means that we do not bring in their headers
  2554. #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
  2555. # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
  2556. # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  2557. # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
  2558. # define CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
  2559. #endif
  2560. // Separate std::pair specialization
  2561. #if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
  2562. #include <utility>
  2563. namespace Catch {
  2564. template<typename T1, typename T2>
  2565. struct StringMaker<std::pair<T1, T2> > {
  2566. static std::string convert(const std::pair<T1, T2>& pair) {
  2567. ReusableStringStream rss;
  2568. rss << "{ "
  2569. << ::Catch::Detail::stringify(pair.first)
  2570. << ", "
  2571. << ::Catch::Detail::stringify(pair.second)
  2572. << " }";
  2573. return rss.str();
  2574. }
  2575. };
  2576. }
  2577. #endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
  2578. #if defined(CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_OPTIONAL)
  2579. #include <optional>
  2580. namespace Catch {
  2581. template<typename T>
  2582. struct StringMaker<std::optional<T> > {
  2583. static std::string convert(const std::optional<T>& optional) {
  2584. if (optional.has_value()) {
  2585. return ::Catch::Detail::stringify(*optional);
  2586. } else {
  2587. return "{ }";
  2588. }
  2589. }
  2590. };
  2591. }
  2592. #endif // CATCH_CONFIG_ENABLE_OPTIONAL_STRINGMAKER
  2593. // Separate std::tuple specialization
  2594. #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
  2595. #include <tuple>
  2596. namespace Catch {
  2597. namespace Detail {
  2598. template<
  2599. typename Tuple,
  2600. std::size_t N = 0,
  2601. bool = (N < std::tuple_size<Tuple>::value)
  2602. >
  2603. struct TupleElementPrinter {
  2604. static void print(const Tuple& tuple, std::ostream& os) {
  2605. os << (N ? ", " : " ")
  2606. << ::Catch::Detail::stringify(std::get<N>(tuple));
  2607. TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
  2608. }
  2609. };
  2610. template<
  2611. typename Tuple,
  2612. std::size_t N
  2613. >
  2614. struct TupleElementPrinter<Tuple, N, false> {
  2615. static void print(const Tuple&, std::ostream&) {}
  2616. };
  2617. }
  2618. template<typename ...Types>
  2619. struct StringMaker<std::tuple<Types...>> {
  2620. static std::string convert(const std::tuple<Types...>& tuple) {
  2621. ReusableStringStream rss;
  2622. rss << '{';
  2623. Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
  2624. rss << " }";
  2625. return rss.str();
  2626. }
  2627. };
  2628. }
  2629. #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
  2630. #if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
  2631. #include <variant>
  2632. namespace Catch {
  2633. template<>
  2634. struct StringMaker<std::monostate> {
  2635. static std::string convert(const std::monostate&) {
  2636. return "{ }";
  2637. }
  2638. };
  2639. template<typename... Elements>
  2640. struct StringMaker<std::variant<Elements...>> {
  2641. static std::string convert(const std::variant<Elements...>& variant) {
  2642. if (variant.valueless_by_exception()) {
  2643. return "{valueless variant}";
  2644. } else {
  2645. return std::visit(
  2646. [](const auto& value) {
  2647. return ::Catch::Detail::stringify(value);
  2648. },
  2649. variant
  2650. );
  2651. }
  2652. }
  2653. };
  2654. }
  2655. #endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
  2656. namespace Catch {
  2657. // Import begin/ end from std here
  2658. using std::begin;
  2659. using std::end;
  2660. namespace Detail {
  2661. template <typename T, typename = void>
  2662. struct is_range_impl : std::false_type {};
  2663. template <typename T>
  2664. struct is_range_impl<T, void_t<decltype(begin(std::declval<T>()))>> : std::true_type {};
  2665. } // namespace Detail
  2666. template <typename T>
  2667. struct is_range : Detail::is_range_impl<T> {};
  2668. #if defined(_MANAGED) // Managed types are never ranges
  2669. template <typename T>
  2670. struct is_range<T^> {
  2671. static const bool value = false;
  2672. };
  2673. #endif
  2674. template<typename Range>
  2675. std::string rangeToString( Range const& range ) {
  2676. return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
  2677. }
  2678. // Handle vector<bool> specially
  2679. template<typename Allocator>
  2680. std::string rangeToString( std::vector<bool, Allocator> const& v ) {
  2681. ReusableStringStream rss;
  2682. rss << "{ ";
  2683. bool first = true;
  2684. for( bool b : v ) {
  2685. if( first )
  2686. first = false;
  2687. else
  2688. rss << ", ";
  2689. rss << ::Catch::Detail::stringify( b );
  2690. }
  2691. rss << " }";
  2692. return rss.str();
  2693. }
  2694. template<typename R>
  2695. struct StringMaker<R, std::enable_if_t<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>> {
  2696. static std::string convert( R const& range ) {
  2697. return rangeToString( range );
  2698. }
  2699. };
  2700. template <typename T, size_t SZ>
  2701. struct StringMaker<T[SZ]> {
  2702. static std::string convert(T const(&arr)[SZ]) {
  2703. return rangeToString(arr);
  2704. }
  2705. };
  2706. } // namespace Catch
  2707. // Separate std::chrono::duration specialization
  2708. #include <ctime>
  2709. #include <ratio>
  2710. #include <chrono>
  2711. namespace Catch {
  2712. template <class Ratio>
  2713. struct ratio_string {
  2714. static std::string symbol() {
  2715. Catch::ReusableStringStream rss;
  2716. rss << '[' << Ratio::num << '/'
  2717. << Ratio::den << ']';
  2718. return rss.str();
  2719. }
  2720. };
  2721. template <>
  2722. struct ratio_string<std::atto> {
  2723. static char symbol() { return 'a'; }
  2724. };
  2725. template <>
  2726. struct ratio_string<std::femto> {
  2727. static char symbol() { return 'f'; }
  2728. };
  2729. template <>
  2730. struct ratio_string<std::pico> {
  2731. static char symbol() { return 'p'; }
  2732. };
  2733. template <>
  2734. struct ratio_string<std::nano> {
  2735. static char symbol() { return 'n'; }
  2736. };
  2737. template <>
  2738. struct ratio_string<std::micro> {
  2739. static char symbol() { return 'u'; }
  2740. };
  2741. template <>
  2742. struct ratio_string<std::milli> {
  2743. static char symbol() { return 'm'; }
  2744. };
  2745. ////////////
  2746. // std::chrono::duration specializations
  2747. template<typename Value, typename Ratio>
  2748. struct StringMaker<std::chrono::duration<Value, Ratio>> {
  2749. static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
  2750. ReusableStringStream rss;
  2751. rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's';
  2752. return rss.str();
  2753. }
  2754. };
  2755. template<typename Value>
  2756. struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
  2757. static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
  2758. ReusableStringStream rss;
  2759. rss << duration.count() << " s";
  2760. return rss.str();
  2761. }
  2762. };
  2763. template<typename Value>
  2764. struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
  2765. static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
  2766. ReusableStringStream rss;
  2767. rss << duration.count() << " m";
  2768. return rss.str();
  2769. }
  2770. };
  2771. template<typename Value>
  2772. struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
  2773. static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
  2774. ReusableStringStream rss;
  2775. rss << duration.count() << " h";
  2776. return rss.str();
  2777. }
  2778. };
  2779. ////////////
  2780. // std::chrono::time_point specialization
  2781. // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
  2782. template<typename Clock, typename Duration>
  2783. struct StringMaker<std::chrono::time_point<Clock, Duration>> {
  2784. static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
  2785. return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch";
  2786. }
  2787. };
  2788. // std::chrono::time_point<system_clock> specialization
  2789. template<typename Duration>
  2790. struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
  2791. static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
  2792. auto converted = std::chrono::system_clock::to_time_t(time_point);
  2793. #ifdef _MSC_VER
  2794. std::tm timeInfo = {};
  2795. gmtime_s(&timeInfo, &converted);
  2796. #else
  2797. std::tm* timeInfo = std::gmtime(&converted);
  2798. #endif
  2799. auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
  2800. char timeStamp[timeStampSize];
  2801. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  2802. #ifdef _MSC_VER
  2803. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  2804. #else
  2805. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  2806. #endif
  2807. return std::string(timeStamp, timeStampSize - 1);
  2808. }
  2809. };
  2810. }
  2811. #define INTERNAL_CATCH_REGISTER_ENUM( enumName, ... ) \
  2812. namespace Catch { \
  2813. template<> struct StringMaker<enumName> { \
  2814. static std::string convert( enumName value ) { \
  2815. static const auto& enumInfo = ::Catch::getMutableRegistryHub().getMutableEnumValuesRegistry().registerEnum( #enumName, #__VA_ARGS__, { __VA_ARGS__ } ); \
  2816. return static_cast<std::string>(enumInfo.lookup( static_cast<int>( value ) )); \
  2817. } \
  2818. }; \
  2819. }
  2820. #define CATCH_REGISTER_ENUM( enumName, ... ) INTERNAL_CATCH_REGISTER_ENUM( enumName, __VA_ARGS__ )
  2821. #ifdef _MSC_VER
  2822. #pragma warning(pop)
  2823. #endif
  2824. #endif // CATCH_TOSTRING_HPP_INCLUDED
  2825. #include <type_traits>
  2826. namespace Catch {
  2827. class Approx {
  2828. private:
  2829. bool equalityComparisonImpl(double other) const;
  2830. // Sets and validates the new margin (margin >= 0)
  2831. void setMargin(double margin);
  2832. // Sets and validates the new epsilon (0 < epsilon < 1)
  2833. void setEpsilon(double epsilon);
  2834. public:
  2835. explicit Approx ( double value );
  2836. static Approx custom();
  2837. Approx operator-() const;
  2838. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2839. Approx operator()( T const& value ) const {
  2840. Approx approx( static_cast<double>(value) );
  2841. approx.m_epsilon = m_epsilon;
  2842. approx.m_margin = m_margin;
  2843. approx.m_scale = m_scale;
  2844. return approx;
  2845. }
  2846. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2847. explicit Approx( T const& value ): Approx(static_cast<double>(value))
  2848. {}
  2849. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2850. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2851. auto lhs_v = static_cast<double>(lhs);
  2852. return rhs.equalityComparisonImpl(lhs_v);
  2853. }
  2854. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2855. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2856. return operator==( rhs, lhs );
  2857. }
  2858. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2859. friend bool operator != ( T const& lhs, Approx const& rhs ) {
  2860. return !operator==( lhs, rhs );
  2861. }
  2862. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2863. friend bool operator != ( Approx const& lhs, T const& rhs ) {
  2864. return !operator==( rhs, lhs );
  2865. }
  2866. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2867. friend bool operator <= ( T const& lhs, Approx const& rhs ) {
  2868. return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
  2869. }
  2870. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2871. friend bool operator <= ( Approx const& lhs, T const& rhs ) {
  2872. return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
  2873. }
  2874. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2875. friend bool operator >= ( T const& lhs, Approx const& rhs ) {
  2876. return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
  2877. }
  2878. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2879. friend bool operator >= ( Approx const& lhs, T const& rhs ) {
  2880. return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
  2881. }
  2882. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2883. Approx& epsilon( T const& newEpsilon ) {
  2884. const auto epsilonAsDouble = static_cast<double>(newEpsilon);
  2885. setEpsilon(epsilonAsDouble);
  2886. return *this;
  2887. }
  2888. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2889. Approx& margin( T const& newMargin ) {
  2890. const auto marginAsDouble = static_cast<double>(newMargin);
  2891. setMargin(marginAsDouble);
  2892. return *this;
  2893. }
  2894. template <typename T, typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  2895. Approx& scale( T const& newScale ) {
  2896. m_scale = static_cast<double>(newScale);
  2897. return *this;
  2898. }
  2899. std::string toString() const;
  2900. private:
  2901. double m_epsilon;
  2902. double m_margin;
  2903. double m_scale;
  2904. double m_value;
  2905. };
  2906. namespace literals {
  2907. Approx operator ""_a(long double val);
  2908. Approx operator ""_a(unsigned long long val);
  2909. } // end namespace literals
  2910. template<>
  2911. struct StringMaker<Catch::Approx> {
  2912. static std::string convert(Catch::Approx const& value);
  2913. };
  2914. } // end namespace Catch
  2915. #endif // CATCH_APPROX_HPP_INCLUDED
  2916. #ifndef CATCH_CONFIG_HPP_INCLUDED
  2917. #define CATCH_CONFIG_HPP_INCLUDED
  2918. #ifndef CATCH_TEST_SPEC_HPP_INCLUDED
  2919. #define CATCH_TEST_SPEC_HPP_INCLUDED
  2920. #ifdef __clang__
  2921. #pragma clang diagnostic push
  2922. #pragma clang diagnostic ignored "-Wpadded"
  2923. #endif
  2924. #ifndef CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2925. #define CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2926. #ifndef CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2927. #define CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2928. namespace Catch {
  2929. enum class CaseSensitive { Yes, No };
  2930. } // namespace Catch
  2931. #endif // CATCH_CASE_SENSITIVE_HPP_INCLUDED
  2932. #include <string>
  2933. namespace Catch
  2934. {
  2935. class WildcardPattern {
  2936. enum WildcardPosition {
  2937. NoWildcard = 0,
  2938. WildcardAtStart = 1,
  2939. WildcardAtEnd = 2,
  2940. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2941. };
  2942. public:
  2943. WildcardPattern( std::string const& pattern, CaseSensitive caseSensitivity );
  2944. bool matches( std::string const& str ) const;
  2945. private:
  2946. std::string normaliseString( std::string const& str ) const;
  2947. CaseSensitive m_caseSensitivity;
  2948. WildcardPosition m_wildcard = NoWildcard;
  2949. std::string m_pattern;
  2950. };
  2951. }
  2952. #endif // CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2953. #include <string>
  2954. #include <vector>
  2955. namespace Catch {
  2956. class IConfig;
  2957. struct TestCaseInfo;
  2958. class TestCaseHandle;
  2959. class TestSpec {
  2960. class Pattern {
  2961. public:
  2962. explicit Pattern( std::string const& name );
  2963. virtual ~Pattern();
  2964. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2965. std::string const& name() const;
  2966. private:
  2967. std::string const m_name;
  2968. };
  2969. class NamePattern : public Pattern {
  2970. public:
  2971. explicit NamePattern( std::string const& name, std::string const& filterString );
  2972. bool matches( TestCaseInfo const& testCase ) const override;
  2973. private:
  2974. WildcardPattern m_wildcardPattern;
  2975. };
  2976. class TagPattern : public Pattern {
  2977. public:
  2978. explicit TagPattern( std::string const& tag, std::string const& filterString );
  2979. bool matches( TestCaseInfo const& testCase ) const override;
  2980. private:
  2981. std::string m_tag;
  2982. };
  2983. struct Filter {
  2984. std::vector<Detail::unique_ptr<Pattern>> m_required;
  2985. std::vector<Detail::unique_ptr<Pattern>> m_forbidden;
  2986. bool matches( TestCaseInfo const& testCase ) const;
  2987. std::string name() const;
  2988. };
  2989. public:
  2990. struct FilterMatch {
  2991. std::string name;
  2992. std::vector<TestCaseHandle const*> tests;
  2993. };
  2994. using Matches = std::vector<FilterMatch>;
  2995. using vectorStrings = std::vector<std::string>;
  2996. bool hasFilters() const;
  2997. bool matches( TestCaseInfo const& testCase ) const;
  2998. Matches matchesByFilter( std::vector<TestCaseHandle> const& testCases, IConfig const& config ) const;
  2999. const vectorStrings & getInvalidSpecs() const;
  3000. private:
  3001. std::vector<Filter> m_filters;
  3002. std::vector<std::string> m_invalidSpecs;
  3003. friend class TestSpecParser;
  3004. };
  3005. }
  3006. #ifdef __clang__
  3007. #pragma clang diagnostic pop
  3008. #endif
  3009. #endif // CATCH_TEST_SPEC_HPP_INCLUDED
  3010. #ifndef CATCH_OPTIONAL_HPP_INCLUDED
  3011. #define CATCH_OPTIONAL_HPP_INCLUDED
  3012. #include <cassert>
  3013. namespace Catch {
  3014. // An optional type
  3015. template<typename T>
  3016. class Optional {
  3017. public:
  3018. Optional() : nullableValue( nullptr ) {}
  3019. Optional( T const& _value )
  3020. : nullableValue( new( storage ) T( _value ) )
  3021. {}
  3022. Optional( Optional const& _other )
  3023. : nullableValue( _other ? new( storage ) T( *_other ) : nullptr )
  3024. {}
  3025. ~Optional() {
  3026. reset();
  3027. }
  3028. Optional& operator= ( Optional const& _other ) {
  3029. if( &_other != this ) {
  3030. reset();
  3031. if( _other )
  3032. nullableValue = new( storage ) T( *_other );
  3033. }
  3034. return *this;
  3035. }
  3036. Optional& operator = ( T const& _value ) {
  3037. reset();
  3038. nullableValue = new( storage ) T( _value );
  3039. return *this;
  3040. }
  3041. void reset() {
  3042. if( nullableValue )
  3043. nullableValue->~T();
  3044. nullableValue = nullptr;
  3045. }
  3046. T& operator*() {
  3047. assert(nullableValue);
  3048. return *nullableValue;
  3049. }
  3050. T const& operator*() const {
  3051. assert(nullableValue);
  3052. return *nullableValue;
  3053. }
  3054. T* operator->() {
  3055. assert(nullableValue);
  3056. return nullableValue;
  3057. }
  3058. const T* operator->() const {
  3059. assert(nullableValue);
  3060. return nullableValue;
  3061. }
  3062. T valueOr( T const& defaultValue ) const {
  3063. return nullableValue ? *nullableValue : defaultValue;
  3064. }
  3065. bool some() const { return nullableValue != nullptr; }
  3066. bool none() const { return nullableValue == nullptr; }
  3067. bool operator !() const { return nullableValue == nullptr; }
  3068. explicit operator bool() const {
  3069. return some();
  3070. }
  3071. friend bool operator==(Optional const& a, Optional const& b) {
  3072. if (a.none() && b.none()) {
  3073. return true;
  3074. } else if (a.some() && b.some()) {
  3075. return *a == *b;
  3076. } else {
  3077. return false;
  3078. }
  3079. }
  3080. friend bool operator!=(Optional const& a, Optional const& b) {
  3081. return !( a == b );
  3082. }
  3083. private:
  3084. T *nullableValue;
  3085. alignas(alignof(T)) char storage[sizeof(T)];
  3086. };
  3087. } // end namespace Catch
  3088. #endif // CATCH_OPTIONAL_HPP_INCLUDED
  3089. #ifndef CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  3090. #define CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  3091. #include <cstdint>
  3092. namespace Catch {
  3093. enum class GenerateFrom {
  3094. Time,
  3095. RandomDevice,
  3096. //! Currently equivalent to RandomDevice, but can change at any point
  3097. Default
  3098. };
  3099. std::uint32_t generateRandomSeed(GenerateFrom from);
  3100. } // end namespace Catch
  3101. #endif // CATCH_RANDOM_SEED_GENERATION_HPP_INCLUDED
  3102. #ifndef CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  3103. #define CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  3104. #ifndef CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  3105. #define CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  3106. #include <iosfwd>
  3107. #include <cstdint>
  3108. namespace Catch {
  3109. enum class ColourMode : std::uint8_t;
  3110. class IStream;
  3111. struct Colour {
  3112. enum Code {
  3113. None = 0,
  3114. White,
  3115. Red,
  3116. Green,
  3117. Blue,
  3118. Cyan,
  3119. Yellow,
  3120. Grey,
  3121. Bright = 0x10,
  3122. BrightRed = Bright | Red,
  3123. BrightGreen = Bright | Green,
  3124. LightGrey = Bright | Grey,
  3125. BrightWhite = Bright | White,
  3126. BrightYellow = Bright | Yellow,
  3127. // By intention
  3128. FileName = LightGrey,
  3129. Warning = BrightYellow,
  3130. ResultError = BrightRed,
  3131. ResultSuccess = BrightGreen,
  3132. ResultExpectedFailure = Warning,
  3133. Error = BrightRed,
  3134. Success = Green,
  3135. OriginalExpression = Cyan,
  3136. ReconstructedExpression = BrightYellow,
  3137. SecondaryText = LightGrey,
  3138. Headers = White
  3139. };
  3140. };
  3141. class ColourImpl {
  3142. protected:
  3143. //! The associated stream of this ColourImpl instance
  3144. IStream* m_stream;
  3145. public:
  3146. ColourImpl( IStream* stream ): m_stream( stream ) {}
  3147. //! RAII wrapper around writing specific colour of text using specific
  3148. //! colour impl into a stream.
  3149. class ColourGuard {
  3150. ColourImpl const* m_colourImpl;
  3151. Colour::Code m_code;
  3152. bool m_engaged = false;
  3153. public:
  3154. //! Does **not** engage the guard/start the colour
  3155. ColourGuard( Colour::Code code,
  3156. ColourImpl const* colour );
  3157. ColourGuard( ColourGuard const& rhs ) = delete;
  3158. ColourGuard& operator=( ColourGuard const& rhs ) = delete;
  3159. ColourGuard( ColourGuard&& rhs ) noexcept;
  3160. ColourGuard& operator=( ColourGuard&& rhs ) noexcept;
  3161. //! Removes colour _if_ the guard was engaged
  3162. ~ColourGuard();
  3163. /**
  3164. * Explicitly engages colour for given stream.
  3165. *
  3166. * The API based on operator<< should be preferred.
  3167. */
  3168. ColourGuard& engage( std::ostream& stream ) &;
  3169. /**
  3170. * Explicitly engages colour for given stream.
  3171. *
  3172. * The API based on operator<< should be preferred.
  3173. */
  3174. ColourGuard&& engage( std::ostream& stream ) &&;
  3175. private:
  3176. //! Engages the guard and starts using colour
  3177. friend std::ostream& operator<<( std::ostream& lhs,
  3178. ColourGuard& guard ) {
  3179. guard.engageImpl( lhs );
  3180. return lhs;
  3181. }
  3182. //! Engages the guard and starts using colour
  3183. friend std::ostream& operator<<( std::ostream& lhs,
  3184. ColourGuard&& guard) {
  3185. guard.engageImpl( lhs );
  3186. return lhs;
  3187. }
  3188. void engageImpl( std::ostream& stream );
  3189. };
  3190. virtual ~ColourImpl(); // = default
  3191. /**
  3192. * Creates a guard object for given colour and this colour impl
  3193. *
  3194. * **Important:**
  3195. * the guard starts disengaged, and has to be engaged explicitly.
  3196. */
  3197. ColourGuard guardColour( Colour::Code colourCode );
  3198. private:
  3199. virtual void use( Colour::Code colourCode ) const = 0;
  3200. };
  3201. //! Provides ColourImpl based on global config and target compilation platform
  3202. Detail::unique_ptr<ColourImpl> makeColourImpl( ColourMode colourSelection,
  3203. IStream* stream );
  3204. //! Checks if specific colour impl has been compiled into the binary
  3205. bool isColourImplAvailable( ColourMode colourSelection );
  3206. } // end namespace Catch
  3207. #endif // CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  3208. #include <map>
  3209. #include <string>
  3210. #include <vector>
  3211. namespace Catch {
  3212. enum class ColourMode : std::uint8_t;
  3213. namespace Detail {
  3214. //! Splits the reporter spec into reporter name and kv-pair options
  3215. std::vector<std::string> splitReporterSpec( StringRef reporterSpec );
  3216. Optional<ColourMode> stringToColourMode( StringRef colourMode );
  3217. }
  3218. /**
  3219. * Structured reporter spec that a reporter can be created from
  3220. *
  3221. * Parsing has been validated, but semantics have not. This means e.g.
  3222. * that the colour mode is known to Catch2, but it might not be
  3223. * compiled into the binary, and the output filename might not be
  3224. * openable.
  3225. */
  3226. class ReporterSpec {
  3227. std::string m_name;
  3228. Optional<std::string> m_outputFileName;
  3229. Optional<ColourMode> m_colourMode;
  3230. std::map<std::string, std::string> m_customOptions;
  3231. friend bool operator==( ReporterSpec const& lhs,
  3232. ReporterSpec const& rhs );
  3233. friend bool operator!=( ReporterSpec const& lhs,
  3234. ReporterSpec const& rhs ) {
  3235. return !( lhs == rhs );
  3236. }
  3237. public:
  3238. ReporterSpec(
  3239. std::string name,
  3240. Optional<std::string> outputFileName,
  3241. Optional<ColourMode> colourMode,
  3242. std::map<std::string, std::string> customOptions );
  3243. std::string const& name() const { return m_name; }
  3244. Optional<std::string> const& outputFile() const {
  3245. return m_outputFileName;
  3246. }
  3247. Optional<ColourMode> const& colourMode() const { return m_colourMode; }
  3248. std::map<std::string, std::string> const& customOptions() const {
  3249. return m_customOptions;
  3250. }
  3251. };
  3252. /**
  3253. * Parses provided reporter spec string into
  3254. *
  3255. * Returns empty optional on errors, e.g.
  3256. * * field that is not first and not a key+value pair
  3257. * * duplicated keys in kv pair
  3258. * * unknown catch reporter option
  3259. * * empty key/value in an custom kv pair
  3260. * * ...
  3261. */
  3262. Optional<ReporterSpec> parseReporterSpec( StringRef reporterSpec );
  3263. }
  3264. #endif // CATCH_REPORTER_SPEC_PARSER_HPP_INCLUDED
  3265. #include <chrono>
  3266. #include <map>
  3267. #include <string>
  3268. #include <vector>
  3269. namespace Catch {
  3270. class IStream;
  3271. /**
  3272. * `ReporterSpec` but with the defaults filled in.
  3273. *
  3274. * Like `ReporterSpec`, the semantics are unchecked.
  3275. */
  3276. struct ProcessedReporterSpec {
  3277. std::string name;
  3278. std::string outputFilename;
  3279. ColourMode colourMode;
  3280. std::map<std::string, std::string> customOptions;
  3281. friend bool operator==( ProcessedReporterSpec const& lhs,
  3282. ProcessedReporterSpec const& rhs );
  3283. friend bool operator!=( ProcessedReporterSpec const& lhs,
  3284. ProcessedReporterSpec const& rhs ) {
  3285. return !( lhs == rhs );
  3286. }
  3287. };
  3288. struct ConfigData {
  3289. bool listTests = false;
  3290. bool listTags = false;
  3291. bool listReporters = false;
  3292. bool listListeners = false;
  3293. bool showSuccessfulTests = false;
  3294. bool shouldDebugBreak = false;
  3295. bool noThrow = false;
  3296. bool showHelp = false;
  3297. bool showInvisibles = false;
  3298. bool filenamesAsTags = false;
  3299. bool libIdentify = false;
  3300. bool allowZeroTests = false;
  3301. int abortAfter = -1;
  3302. uint32_t rngSeed = generateRandomSeed(GenerateFrom::Default);
  3303. unsigned int shardCount = 1;
  3304. unsigned int shardIndex = 0;
  3305. bool skipBenchmarks = false;
  3306. bool benchmarkNoAnalysis = false;
  3307. unsigned int benchmarkSamples = 100;
  3308. double benchmarkConfidenceInterval = 0.95;
  3309. unsigned int benchmarkResamples = 100000;
  3310. std::chrono::milliseconds::rep benchmarkWarmupTime = 100;
  3311. Verbosity verbosity = Verbosity::Normal;
  3312. WarnAbout::What warnings = WarnAbout::Nothing;
  3313. ShowDurations showDurations = ShowDurations::DefaultForReporter;
  3314. double minDuration = -1;
  3315. TestRunOrder runOrder = TestRunOrder::Declared;
  3316. ColourMode defaultColourMode = ColourMode::PlatformDefault;
  3317. WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
  3318. std::string defaultOutputFilename;
  3319. std::string name;
  3320. std::string processName;
  3321. std::vector<ReporterSpec> reporterSpecifications;
  3322. std::vector<std::string> testsOrTags;
  3323. std::vector<std::string> sectionsToRun;
  3324. };
  3325. class Config : public IConfig {
  3326. public:
  3327. Config() = default;
  3328. Config( ConfigData const& data );
  3329. ~Config() override; // = default in the cpp file
  3330. bool listTests() const;
  3331. bool listTags() const;
  3332. bool listReporters() const;
  3333. bool listListeners() const;
  3334. std::vector<ReporterSpec> const& getReporterSpecs() const;
  3335. std::vector<ProcessedReporterSpec> const&
  3336. getProcessedReporterSpecs() const;
  3337. std::vector<std::string> const& getTestsOrTags() const override;
  3338. std::vector<std::string> const& getSectionsToRun() const override;
  3339. TestSpec const& testSpec() const override;
  3340. bool hasTestFilters() const override;
  3341. bool showHelp() const;
  3342. // IConfig interface
  3343. bool allowThrows() const override;
  3344. StringRef name() const override;
  3345. bool includeSuccessfulResults() const override;
  3346. bool warnAboutMissingAssertions() const override;
  3347. bool warnAboutUnmatchedTestSpecs() const override;
  3348. bool zeroTestsCountAsSuccess() const override;
  3349. ShowDurations showDurations() const override;
  3350. double minDuration() const override;
  3351. TestRunOrder runOrder() const override;
  3352. uint32_t rngSeed() const override;
  3353. unsigned int shardCount() const override;
  3354. unsigned int shardIndex() const override;
  3355. ColourMode defaultColourMode() const override;
  3356. bool shouldDebugBreak() const override;
  3357. int abortAfter() const override;
  3358. bool showInvisibles() const override;
  3359. Verbosity verbosity() const override;
  3360. bool skipBenchmarks() const override;
  3361. bool benchmarkNoAnalysis() const override;
  3362. unsigned int benchmarkSamples() const override;
  3363. double benchmarkConfidenceInterval() const override;
  3364. unsigned int benchmarkResamples() const override;
  3365. std::chrono::milliseconds benchmarkWarmupTime() const override;
  3366. private:
  3367. ConfigData m_data;
  3368. std::vector<ProcessedReporterSpec> m_processedReporterSpecs;
  3369. TestSpec m_testSpec;
  3370. bool m_hasTestFilters = false;
  3371. };
  3372. } // end namespace Catch
  3373. #endif // CATCH_CONFIG_HPP_INCLUDED
  3374. #ifndef CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3375. #define CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3376. #include <cstdint>
  3377. namespace Catch {
  3378. //! Returns Catch2's current RNG seed.
  3379. std::uint32_t getSeed();
  3380. }
  3381. #endif // CATCH_GET_RANDOM_SEED_HPP_INCLUDED
  3382. #ifndef CATCH_MESSAGE_HPP_INCLUDED
  3383. #define CATCH_MESSAGE_HPP_INCLUDED
  3384. #ifndef CATCH_STREAM_END_STOP_HPP_INCLUDED
  3385. #define CATCH_STREAM_END_STOP_HPP_INCLUDED
  3386. namespace Catch {
  3387. // Use this in variadic streaming macros to allow
  3388. // << +StreamEndStop
  3389. // as well as
  3390. // << stuff +StreamEndStop
  3391. struct StreamEndStop {
  3392. StringRef operator+() const { return StringRef(); }
  3393. template <typename T>
  3394. friend T const& operator+( T const& value, StreamEndStop ) {
  3395. return value;
  3396. }
  3397. };
  3398. } // namespace Catch
  3399. #endif // CATCH_STREAM_END_STOP_HPP_INCLUDED
  3400. #include <string>
  3401. #include <vector>
  3402. namespace Catch {
  3403. struct SourceLineInfo;
  3404. struct MessageStream {
  3405. template<typename T>
  3406. MessageStream& operator << ( T const& value ) {
  3407. m_stream << value;
  3408. return *this;
  3409. }
  3410. ReusableStringStream m_stream;
  3411. };
  3412. struct MessageBuilder : MessageStream {
  3413. MessageBuilder( StringRef macroName,
  3414. SourceLineInfo const& lineInfo,
  3415. ResultWas::OfType type ):
  3416. m_info(macroName, lineInfo, type) {}
  3417. template<typename T>
  3418. MessageBuilder& operator << ( T const& value ) {
  3419. m_stream << value;
  3420. return *this;
  3421. }
  3422. MessageInfo m_info;
  3423. };
  3424. class ScopedMessage {
  3425. public:
  3426. explicit ScopedMessage( MessageBuilder const& builder );
  3427. ScopedMessage( ScopedMessage& duplicate ) = delete;
  3428. ScopedMessage( ScopedMessage&& old ) noexcept;
  3429. ~ScopedMessage();
  3430. MessageInfo m_info;
  3431. bool m_moved = false;
  3432. };
  3433. class Capturer {
  3434. std::vector<MessageInfo> m_messages;
  3435. IResultCapture& m_resultCapture = getResultCapture();
  3436. size_t m_captured = 0;
  3437. public:
  3438. Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
  3439. Capturer(Capturer const&) = delete;
  3440. Capturer& operator=(Capturer const&) = delete;
  3441. ~Capturer();
  3442. void captureValue( size_t index, std::string const& value );
  3443. template<typename T>
  3444. void captureValues( size_t index, T const& value ) {
  3445. captureValue( index, Catch::Detail::stringify( value ) );
  3446. }
  3447. template<typename T, typename... Ts>
  3448. void captureValues( size_t index, T const& value, Ts const&... values ) {
  3449. captureValue( index, Catch::Detail::stringify(value) );
  3450. captureValues( index+1, values... );
  3451. }
  3452. };
  3453. } // end namespace Catch
  3454. ///////////////////////////////////////////////////////////////////////////////
  3455. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
  3456. do { \
  3457. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
  3458. catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
  3459. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  3460. } while( false )
  3461. ///////////////////////////////////////////////////////////////////////////////
  3462. #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
  3463. Catch::Capturer varName( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
  3464. varName.captureValues( 0, __VA_ARGS__ )
  3465. ///////////////////////////////////////////////////////////////////////////////
  3466. #define INTERNAL_CATCH_INFO( macroName, log ) \
  3467. Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
  3468. ///////////////////////////////////////////////////////////////////////////////
  3469. #define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
  3470. Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
  3471. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  3472. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  3473. #define CATCH_UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "CATCH_UNSCOPED_INFO", msg )
  3474. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  3475. #define CATCH_CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CATCH_CAPTURE", __VA_ARGS__ )
  3476. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  3477. #define CATCH_INFO( msg ) (void)(0)
  3478. #define CATCH_UNSCOPED_INFO( msg ) (void)(0)
  3479. #define CATCH_WARN( msg ) (void)(0)
  3480. #define CATCH_CAPTURE( ... ) (void)(0)
  3481. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  3482. #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  3483. #define UNSCOPED_INFO( msg ) INTERNAL_CATCH_UNSCOPED_INFO( "UNSCOPED_INFO", msg )
  3484. #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  3485. #define CAPTURE( ... ) INTERNAL_CATCH_CAPTURE( INTERNAL_CATCH_UNIQUE_NAME(capturer), "CAPTURE", __VA_ARGS__ )
  3486. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  3487. #define INFO( msg ) (void)(0)
  3488. #define UNSCOPED_INFO( msg ) (void)(0)
  3489. #define WARN( msg ) (void)(0)
  3490. #define CAPTURE( ... ) (void)(0)
  3491. #endif // end of user facing macro declarations
  3492. #endif // CATCH_MESSAGE_HPP_INCLUDED
  3493. #ifndef CATCH_SESSION_HPP_INCLUDED
  3494. #define CATCH_SESSION_HPP_INCLUDED
  3495. #ifndef CATCH_COMMANDLINE_HPP_INCLUDED
  3496. #define CATCH_COMMANDLINE_HPP_INCLUDED
  3497. #ifndef CATCH_CLARA_HPP_INCLUDED
  3498. #define CATCH_CLARA_HPP_INCLUDED
  3499. #if defined( __clang__ )
  3500. # pragma clang diagnostic push
  3501. # pragma clang diagnostic ignored "-Wweak-vtables"
  3502. # pragma clang diagnostic ignored "-Wshadow"
  3503. # pragma clang diagnostic ignored "-Wdeprecated"
  3504. #endif
  3505. #if defined( __GNUC__ )
  3506. # pragma GCC diagnostic push
  3507. # pragma GCC diagnostic ignored "-Wsign-conversion"
  3508. #endif
  3509. #ifndef CLARA_CONFIG_OPTIONAL_TYPE
  3510. # ifdef __has_include
  3511. # if __has_include( <optional>) && __cplusplus >= 201703L
  3512. # include <optional>
  3513. # define CLARA_CONFIG_OPTIONAL_TYPE std::optional
  3514. # endif
  3515. # endif
  3516. #endif
  3517. #include <cassert>
  3518. #include <memory>
  3519. #include <ostream>
  3520. #include <sstream>
  3521. #include <string>
  3522. #include <type_traits>
  3523. #include <vector>
  3524. namespace Catch {
  3525. namespace Clara {
  3526. class Args;
  3527. class Parser;
  3528. // enum of result types from a parse
  3529. enum class ParseResultType {
  3530. Matched,
  3531. NoMatch,
  3532. ShortCircuitAll,
  3533. ShortCircuitSame
  3534. };
  3535. struct accept_many_t {};
  3536. constexpr accept_many_t accept_many {};
  3537. namespace Detail {
  3538. struct fake_arg {
  3539. template <typename T>
  3540. operator T();
  3541. };
  3542. template <typename F, typename = void>
  3543. struct is_unary_function : std::false_type {};
  3544. template <typename F>
  3545. struct is_unary_function<
  3546. F,
  3547. Catch::Detail::void_t<decltype(
  3548. std::declval<F>()( fake_arg() ) )
  3549. >
  3550. > : std::true_type {};
  3551. // Traits for extracting arg and return type of lambdas (for single
  3552. // argument lambdas)
  3553. template <typename L>
  3554. struct UnaryLambdaTraits
  3555. : UnaryLambdaTraits<decltype( &L::operator() )> {};
  3556. template <typename ClassT, typename ReturnT, typename... Args>
  3557. struct UnaryLambdaTraits<ReturnT ( ClassT::* )( Args... ) const> {
  3558. static const bool isValid = false;
  3559. };
  3560. template <typename ClassT, typename ReturnT, typename ArgT>
  3561. struct UnaryLambdaTraits<ReturnT ( ClassT::* )( ArgT ) const> {
  3562. static const bool isValid = true;
  3563. using ArgType = std::remove_const_t<std::remove_reference_t<ArgT>>;
  3564. using ReturnType = ReturnT;
  3565. };
  3566. class TokenStream;
  3567. // Wraps a token coming from a token stream. These may not directly
  3568. // correspond to strings as a single string may encode an option +
  3569. // its argument if the : or = form is used
  3570. enum class TokenType { Option, Argument };
  3571. struct Token {
  3572. TokenType type;
  3573. std::string token;
  3574. };
  3575. // Abstracts iterators into args as a stream of tokens, with option
  3576. // arguments uniformly handled
  3577. class TokenStream {
  3578. using Iterator = std::vector<std::string>::const_iterator;
  3579. Iterator it;
  3580. Iterator itEnd;
  3581. std::vector<Token> m_tokenBuffer;
  3582. void loadBuffer();
  3583. public:
  3584. explicit TokenStream( Args const& args );
  3585. TokenStream( Iterator it, Iterator itEnd );
  3586. explicit operator bool() const {
  3587. return !m_tokenBuffer.empty() || it != itEnd;
  3588. }
  3589. size_t count() const {
  3590. return m_tokenBuffer.size() + ( itEnd - it );
  3591. }
  3592. Token operator*() const {
  3593. assert( !m_tokenBuffer.empty() );
  3594. return m_tokenBuffer.front();
  3595. }
  3596. Token const* operator->() const {
  3597. assert( !m_tokenBuffer.empty() );
  3598. return &m_tokenBuffer.front();
  3599. }
  3600. TokenStream& operator++();
  3601. };
  3602. //! Denotes type of a parsing result
  3603. enum class ResultType {
  3604. Ok, ///< No errors
  3605. LogicError, ///< Error in user-specified arguments for
  3606. ///< construction
  3607. RuntimeError ///< Error in parsing inputs
  3608. };
  3609. class ResultBase {
  3610. protected:
  3611. ResultBase( ResultType type ): m_type( type ) {}
  3612. virtual ~ResultBase(); // = default;
  3613. ResultBase(ResultBase const&) = default;
  3614. ResultBase& operator=(ResultBase const&) = default;
  3615. ResultBase(ResultBase&&) = default;
  3616. ResultBase& operator=(ResultBase&&) = default;
  3617. virtual void enforceOk() const = 0;
  3618. ResultType m_type;
  3619. };
  3620. template <typename T> class ResultValueBase : public ResultBase {
  3621. public:
  3622. auto value() const -> T const& {
  3623. enforceOk();
  3624. return m_value;
  3625. }
  3626. protected:
  3627. ResultValueBase( ResultType type ): ResultBase( type ) {}
  3628. ResultValueBase( ResultValueBase const& other ):
  3629. ResultBase( other ) {
  3630. if ( m_type == ResultType::Ok )
  3631. new ( &m_value ) T( other.m_value );
  3632. }
  3633. ResultValueBase( ResultType, T const& value ): ResultBase( ResultType::Ok ) {
  3634. new ( &m_value ) T( value );
  3635. }
  3636. auto operator=( ResultValueBase const& other )
  3637. -> ResultValueBase& {
  3638. if ( m_type == ResultType::Ok )
  3639. m_value.~T();
  3640. ResultBase::operator=( other );
  3641. if ( m_type == ResultType::Ok )
  3642. new ( &m_value ) T( other.m_value );
  3643. return *this;
  3644. }
  3645. ~ResultValueBase() override {
  3646. if ( m_type == ResultType::Ok )
  3647. m_value.~T();
  3648. }
  3649. union {
  3650. T m_value;
  3651. };
  3652. };
  3653. template <> class ResultValueBase<void> : public ResultBase {
  3654. protected:
  3655. using ResultBase::ResultBase;
  3656. };
  3657. template <typename T = void>
  3658. class BasicResult : public ResultValueBase<T> {
  3659. public:
  3660. template <typename U>
  3661. explicit BasicResult( BasicResult<U> const& other ):
  3662. ResultValueBase<T>( other.type() ),
  3663. m_errorMessage( other.errorMessage() ) {
  3664. assert( type() != ResultType::Ok );
  3665. }
  3666. template <typename U>
  3667. static auto ok( U const& value ) -> BasicResult {
  3668. return { ResultType::Ok, value };
  3669. }
  3670. static auto ok() -> BasicResult { return { ResultType::Ok }; }
  3671. static auto logicError( std::string&& message )
  3672. -> BasicResult {
  3673. return { ResultType::LogicError, CATCH_MOVE(message) };
  3674. }
  3675. static auto runtimeError( std::string&& message )
  3676. -> BasicResult {
  3677. return { ResultType::RuntimeError, CATCH_MOVE(message) };
  3678. }
  3679. explicit operator bool() const {
  3680. return m_type == ResultType::Ok;
  3681. }
  3682. auto type() const -> ResultType { return m_type; }
  3683. auto errorMessage() const -> std::string const& {
  3684. return m_errorMessage;
  3685. }
  3686. protected:
  3687. void enforceOk() const override {
  3688. // Errors shouldn't reach this point, but if they do
  3689. // the actual error message will be in m_errorMessage
  3690. assert( m_type != ResultType::LogicError );
  3691. assert( m_type != ResultType::RuntimeError );
  3692. if ( m_type != ResultType::Ok )
  3693. std::abort();
  3694. }
  3695. std::string
  3696. m_errorMessage; // Only populated if resultType is an error
  3697. BasicResult( ResultType type,
  3698. std::string&& message ):
  3699. ResultValueBase<T>( type ), m_errorMessage( CATCH_MOVE(message) ) {
  3700. assert( m_type != ResultType::Ok );
  3701. }
  3702. using ResultValueBase<T>::ResultValueBase;
  3703. using ResultBase::m_type;
  3704. };
  3705. class ParseState {
  3706. public:
  3707. ParseState( ParseResultType type,
  3708. TokenStream const& remainingTokens );
  3709. ParseResultType type() const { return m_type; }
  3710. TokenStream const& remainingTokens() const {
  3711. return m_remainingTokens;
  3712. }
  3713. private:
  3714. ParseResultType m_type;
  3715. TokenStream m_remainingTokens;
  3716. };
  3717. using Result = BasicResult<void>;
  3718. using ParserResult = BasicResult<ParseResultType>;
  3719. using InternalParseResult = BasicResult<ParseState>;
  3720. struct HelpColumns {
  3721. std::string left;
  3722. std::string right;
  3723. };
  3724. template <typename T>
  3725. ParserResult convertInto( std::string const& source, T& target ) {
  3726. std::stringstream ss( source );
  3727. ss >> target;
  3728. if ( ss.fail() ) {
  3729. return ParserResult::runtimeError(
  3730. "Unable to convert '" + source +
  3731. "' to destination type" );
  3732. } else {
  3733. return ParserResult::ok( ParseResultType::Matched );
  3734. }
  3735. }
  3736. ParserResult convertInto( std::string const& source,
  3737. std::string& target );
  3738. ParserResult convertInto( std::string const& source, bool& target );
  3739. #ifdef CLARA_CONFIG_OPTIONAL_TYPE
  3740. template <typename T>
  3741. auto convertInto( std::string const& source,
  3742. CLARA_CONFIG_OPTIONAL_TYPE<T>& target )
  3743. -> ParserResult {
  3744. T temp;
  3745. auto result = convertInto( source, temp );
  3746. if ( result )
  3747. target = CATCH_MOVE( temp );
  3748. return result;
  3749. }
  3750. #endif // CLARA_CONFIG_OPTIONAL_TYPE
  3751. struct BoundRef : Catch::Detail::NonCopyable {
  3752. virtual ~BoundRef() = default;
  3753. virtual bool isContainer() const;
  3754. virtual bool isFlag() const;
  3755. };
  3756. struct BoundValueRefBase : BoundRef {
  3757. virtual auto setValue( std::string const& arg )
  3758. -> ParserResult = 0;
  3759. };
  3760. struct BoundFlagRefBase : BoundRef {
  3761. virtual auto setFlag( bool flag ) -> ParserResult = 0;
  3762. bool isFlag() const override;
  3763. };
  3764. template <typename T> struct BoundValueRef : BoundValueRefBase {
  3765. T& m_ref;
  3766. explicit BoundValueRef( T& ref ): m_ref( ref ) {}
  3767. ParserResult setValue( std::string const& arg ) override {
  3768. return convertInto( arg, m_ref );
  3769. }
  3770. };
  3771. template <typename T>
  3772. struct BoundValueRef<std::vector<T>> : BoundValueRefBase {
  3773. std::vector<T>& m_ref;
  3774. explicit BoundValueRef( std::vector<T>& ref ): m_ref( ref ) {}
  3775. auto isContainer() const -> bool override { return true; }
  3776. auto setValue( std::string const& arg )
  3777. -> ParserResult override {
  3778. T temp;
  3779. auto result = convertInto( arg, temp );
  3780. if ( result )
  3781. m_ref.push_back( temp );
  3782. return result;
  3783. }
  3784. };
  3785. struct BoundFlagRef : BoundFlagRefBase {
  3786. bool& m_ref;
  3787. explicit BoundFlagRef( bool& ref ): m_ref( ref ) {}
  3788. ParserResult setFlag( bool flag ) override;
  3789. };
  3790. template <typename ReturnType> struct LambdaInvoker {
  3791. static_assert(
  3792. std::is_same<ReturnType, ParserResult>::value,
  3793. "Lambda must return void or clara::ParserResult" );
  3794. template <typename L, typename ArgType>
  3795. static auto invoke( L const& lambda, ArgType const& arg )
  3796. -> ParserResult {
  3797. return lambda( arg );
  3798. }
  3799. };
  3800. template <> struct LambdaInvoker<void> {
  3801. template <typename L, typename ArgType>
  3802. static auto invoke( L const& lambda, ArgType const& arg )
  3803. -> ParserResult {
  3804. lambda( arg );
  3805. return ParserResult::ok( ParseResultType::Matched );
  3806. }
  3807. };
  3808. template <typename ArgType, typename L>
  3809. auto invokeLambda( L const& lambda, std::string const& arg )
  3810. -> ParserResult {
  3811. ArgType temp{};
  3812. auto result = convertInto( arg, temp );
  3813. return !result ? result
  3814. : LambdaInvoker<typename UnaryLambdaTraits<
  3815. L>::ReturnType>::invoke( lambda, temp );
  3816. }
  3817. template <typename L> struct BoundLambda : BoundValueRefBase {
  3818. L m_lambda;
  3819. static_assert(
  3820. UnaryLambdaTraits<L>::isValid,
  3821. "Supplied lambda must take exactly one argument" );
  3822. explicit BoundLambda( L const& lambda ): m_lambda( lambda ) {}
  3823. auto setValue( std::string const& arg )
  3824. -> ParserResult override {
  3825. return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>(
  3826. m_lambda, arg );
  3827. }
  3828. };
  3829. template <typename L> struct BoundManyLambda : BoundLambda<L> {
  3830. explicit BoundManyLambda( L const& lambda ): BoundLambda<L>( lambda ) {}
  3831. bool isContainer() const override { return true; }
  3832. };
  3833. template <typename L> struct BoundFlagLambda : BoundFlagRefBase {
  3834. L m_lambda;
  3835. static_assert(
  3836. UnaryLambdaTraits<L>::isValid,
  3837. "Supplied lambda must take exactly one argument" );
  3838. static_assert(
  3839. std::is_same<typename UnaryLambdaTraits<L>::ArgType,
  3840. bool>::value,
  3841. "flags must be boolean" );
  3842. explicit BoundFlagLambda( L const& lambda ):
  3843. m_lambda( lambda ) {}
  3844. auto setFlag( bool flag ) -> ParserResult override {
  3845. return LambdaInvoker<typename UnaryLambdaTraits<
  3846. L>::ReturnType>::invoke( m_lambda, flag );
  3847. }
  3848. };
  3849. enum class Optionality { Optional, Required };
  3850. class ParserBase {
  3851. public:
  3852. virtual ~ParserBase() = default;
  3853. virtual auto validate() const -> Result { return Result::ok(); }
  3854. virtual auto parse( std::string const& exeName,
  3855. TokenStream const& tokens ) const
  3856. -> InternalParseResult = 0;
  3857. virtual size_t cardinality() const;
  3858. InternalParseResult parse( Args const& args ) const;
  3859. };
  3860. template <typename DerivedT>
  3861. class ComposableParserImpl : public ParserBase {
  3862. public:
  3863. template <typename T>
  3864. auto operator|( T const& other ) const -> Parser;
  3865. };
  3866. // Common code and state for Args and Opts
  3867. template <typename DerivedT>
  3868. class ParserRefImpl : public ComposableParserImpl<DerivedT> {
  3869. protected:
  3870. Optionality m_optionality = Optionality::Optional;
  3871. std::shared_ptr<BoundRef> m_ref;
  3872. std::string m_hint;
  3873. std::string m_description;
  3874. explicit ParserRefImpl( std::shared_ptr<BoundRef> const& ref ):
  3875. m_ref( ref ) {}
  3876. public:
  3877. template <typename LambdaT>
  3878. ParserRefImpl( accept_many_t,
  3879. LambdaT const& ref,
  3880. std::string const& hint ):
  3881. m_ref( std::make_shared<BoundManyLambda<LambdaT>>( ref ) ),
  3882. m_hint( hint ) {}
  3883. template <typename T,
  3884. typename = typename std::enable_if_t<
  3885. !Detail::is_unary_function<T>::value>>
  3886. ParserRefImpl( T& ref, std::string const& hint ):
  3887. m_ref( std::make_shared<BoundValueRef<T>>( ref ) ),
  3888. m_hint( hint ) {}
  3889. template <typename LambdaT,
  3890. typename = typename std::enable_if_t<
  3891. Detail::is_unary_function<LambdaT>::value>>
  3892. ParserRefImpl( LambdaT const& ref, std::string const& hint ):
  3893. m_ref( std::make_shared<BoundLambda<LambdaT>>( ref ) ),
  3894. m_hint( hint ) {}
  3895. auto operator()( std::string const& description ) -> DerivedT& {
  3896. m_description = description;
  3897. return static_cast<DerivedT&>( *this );
  3898. }
  3899. auto optional() -> DerivedT& {
  3900. m_optionality = Optionality::Optional;
  3901. return static_cast<DerivedT&>( *this );
  3902. }
  3903. auto required() -> DerivedT& {
  3904. m_optionality = Optionality::Required;
  3905. return static_cast<DerivedT&>( *this );
  3906. }
  3907. auto isOptional() const -> bool {
  3908. return m_optionality == Optionality::Optional;
  3909. }
  3910. auto cardinality() const -> size_t override {
  3911. if ( m_ref->isContainer() )
  3912. return 0;
  3913. else
  3914. return 1;
  3915. }
  3916. std::string const& hint() const { return m_hint; }
  3917. };
  3918. } // namespace detail
  3919. // A parser for arguments
  3920. class Arg : public Detail::ParserRefImpl<Arg> {
  3921. public:
  3922. using ParserRefImpl::ParserRefImpl;
  3923. using ParserBase::parse;
  3924. Detail::InternalParseResult
  3925. parse(std::string const&,
  3926. Detail::TokenStream const& tokens) const override;
  3927. };
  3928. // A parser for options
  3929. class Opt : public Detail::ParserRefImpl<Opt> {
  3930. protected:
  3931. std::vector<std::string> m_optNames;
  3932. public:
  3933. template <typename LambdaT>
  3934. explicit Opt(LambdaT const& ref) :
  3935. ParserRefImpl(
  3936. std::make_shared<Detail::BoundFlagLambda<LambdaT>>(ref)) {}
  3937. explicit Opt(bool& ref);
  3938. template <typename LambdaT,
  3939. typename = typename std::enable_if_t<
  3940. Detail::is_unary_function<LambdaT>::value>>
  3941. Opt( LambdaT const& ref, std::string const& hint ):
  3942. ParserRefImpl( ref, hint ) {}
  3943. template <typename LambdaT>
  3944. Opt( accept_many_t, LambdaT const& ref, std::string const& hint ):
  3945. ParserRefImpl( accept_many, ref, hint ) {}
  3946. template <typename T,
  3947. typename = typename std::enable_if_t<
  3948. !Detail::is_unary_function<T>::value>>
  3949. Opt( T& ref, std::string const& hint ):
  3950. ParserRefImpl( ref, hint ) {}
  3951. auto operator[](std::string const& optName) -> Opt& {
  3952. m_optNames.push_back(optName);
  3953. return *this;
  3954. }
  3955. std::vector<Detail::HelpColumns> getHelpColumns() const;
  3956. bool isMatch(std::string const& optToken) const;
  3957. using ParserBase::parse;
  3958. Detail::InternalParseResult
  3959. parse(std::string const&,
  3960. Detail::TokenStream const& tokens) const override;
  3961. Detail::Result validate() const override;
  3962. };
  3963. // Specifies the name of the executable
  3964. class ExeName : public Detail::ComposableParserImpl<ExeName> {
  3965. std::shared_ptr<std::string> m_name;
  3966. std::shared_ptr<Detail::BoundValueRefBase> m_ref;
  3967. public:
  3968. ExeName();
  3969. explicit ExeName(std::string& ref);
  3970. template <typename LambdaT>
  3971. explicit ExeName(LambdaT const& lambda) : ExeName() {
  3972. m_ref = std::make_shared<Detail::BoundLambda<LambdaT>>(lambda);
  3973. }
  3974. // The exe name is not parsed out of the normal tokens, but is
  3975. // handled specially
  3976. Detail::InternalParseResult
  3977. parse(std::string const&,
  3978. Detail::TokenStream const& tokens) const override;
  3979. std::string const& name() const { return *m_name; }
  3980. Detail::ParserResult set(std::string const& newName);
  3981. };
  3982. // A Combined parser
  3983. class Parser : Detail::ParserBase {
  3984. mutable ExeName m_exeName;
  3985. std::vector<Opt> m_options;
  3986. std::vector<Arg> m_args;
  3987. public:
  3988. auto operator|=(ExeName const& exeName) -> Parser& {
  3989. m_exeName = exeName;
  3990. return *this;
  3991. }
  3992. auto operator|=(Arg const& arg) -> Parser& {
  3993. m_args.push_back(arg);
  3994. return *this;
  3995. }
  3996. auto operator|=(Opt const& opt) -> Parser& {
  3997. m_options.push_back(opt);
  3998. return *this;
  3999. }
  4000. Parser& operator|=(Parser const& other);
  4001. template <typename T>
  4002. auto operator|(T const& other) const -> Parser {
  4003. return Parser(*this) |= other;
  4004. }
  4005. std::vector<Detail::HelpColumns> getHelpColumns() const;
  4006. void writeToStream(std::ostream& os) const;
  4007. friend auto operator<<(std::ostream& os, Parser const& parser)
  4008. -> std::ostream& {
  4009. parser.writeToStream(os);
  4010. return os;
  4011. }
  4012. Detail::Result validate() const override;
  4013. using ParserBase::parse;
  4014. Detail::InternalParseResult
  4015. parse(std::string const& exeName,
  4016. Detail::TokenStream const& tokens) const override;
  4017. };
  4018. // Transport for raw args (copied from main args, or supplied via
  4019. // init list for testing)
  4020. class Args {
  4021. friend Detail::TokenStream;
  4022. std::string m_exeName;
  4023. std::vector<std::string> m_args;
  4024. public:
  4025. Args(int argc, char const* const* argv);
  4026. Args(std::initializer_list<std::string> args);
  4027. std::string const& exeName() const { return m_exeName; }
  4028. };
  4029. // Convenience wrapper for option parser that specifies the help option
  4030. struct Help : Opt {
  4031. Help(bool& showHelpFlag);
  4032. };
  4033. // Result type for parser operation
  4034. using Detail::ParserResult;
  4035. namespace Detail {
  4036. template <typename DerivedT>
  4037. template <typename T>
  4038. Parser
  4039. ComposableParserImpl<DerivedT>::operator|(T const& other) const {
  4040. return Parser() | static_cast<DerivedT const&>(*this) | other;
  4041. }
  4042. }
  4043. } // namespace Clara
  4044. } // namespace Catch
  4045. #if defined( __clang__ )
  4046. # pragma clang diagnostic pop
  4047. #endif
  4048. #if defined( __GNUC__ )
  4049. # pragma GCC diagnostic pop
  4050. #endif
  4051. #endif // CATCH_CLARA_HPP_INCLUDED
  4052. namespace Catch {
  4053. struct ConfigData;
  4054. Clara::Parser makeCommandLineParser( ConfigData& config );
  4055. } // end namespace Catch
  4056. #endif // CATCH_COMMANDLINE_HPP_INCLUDED
  4057. namespace Catch {
  4058. class Session : Detail::NonCopyable {
  4059. public:
  4060. Session();
  4061. ~Session();
  4062. void showHelp() const;
  4063. void libIdentify();
  4064. int applyCommandLine( int argc, char const * const * argv );
  4065. #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
  4066. int applyCommandLine( int argc, wchar_t const * const * argv );
  4067. #endif
  4068. void useConfigData( ConfigData const& configData );
  4069. template<typename CharT>
  4070. int run(int argc, CharT const * const argv[]) {
  4071. if (m_startupExceptions)
  4072. return 1;
  4073. int returnCode = applyCommandLine(argc, argv);
  4074. if (returnCode == 0)
  4075. returnCode = run();
  4076. return returnCode;
  4077. }
  4078. int run();
  4079. Clara::Parser const& cli() const;
  4080. void cli( Clara::Parser const& newParser );
  4081. ConfigData& configData();
  4082. Config& config();
  4083. private:
  4084. int runInternal();
  4085. Clara::Parser m_cli;
  4086. ConfigData m_configData;
  4087. Detail::unique_ptr<Config> m_config;
  4088. bool m_startupExceptions = false;
  4089. };
  4090. } // end namespace Catch
  4091. #endif // CATCH_SESSION_HPP_INCLUDED
  4092. #ifndef CATCH_TAG_ALIAS_HPP_INCLUDED
  4093. #define CATCH_TAG_ALIAS_HPP_INCLUDED
  4094. #include <string>
  4095. namespace Catch {
  4096. struct TagAlias {
  4097. TagAlias(std::string const& _tag, SourceLineInfo _lineInfo):
  4098. tag(_tag),
  4099. lineInfo(_lineInfo)
  4100. {}
  4101. std::string tag;
  4102. SourceLineInfo lineInfo;
  4103. };
  4104. } // end namespace Catch
  4105. #endif // CATCH_TAG_ALIAS_HPP_INCLUDED
  4106. #ifndef CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  4107. #define CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  4108. namespace Catch {
  4109. struct RegistrarForTagAliases {
  4110. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  4111. };
  4112. } // end namespace Catch
  4113. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
  4114. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4115. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4116. namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
  4117. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4118. #endif // CATCH_TAG_ALIAS_AUTOREGISTRAR_HPP_INCLUDED
  4119. #ifndef CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  4120. #define CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  4121. // We need this suppression to leak, because it took until GCC 10
  4122. // for the front end to handle local suppression via _Pragma properly
  4123. // inside templates (so `TEMPLATE_TEST_CASE` and co).
  4124. // **THIS IS DIFFERENT FOR STANDARD TESTS, WHERE GCC 9 IS SUFFICIENT**
  4125. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 10
  4126. #pragma GCC diagnostic ignored "-Wparentheses"
  4127. #endif
  4128. #ifndef CATCH_TEST_MACROS_HPP_INCLUDED
  4129. #define CATCH_TEST_MACROS_HPP_INCLUDED
  4130. #ifndef CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  4131. #define CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  4132. #ifndef CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  4133. #define CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  4134. #ifndef CATCH_DECOMPOSER_HPP_INCLUDED
  4135. #define CATCH_DECOMPOSER_HPP_INCLUDED
  4136. #include <iosfwd>
  4137. #ifdef _MSC_VER
  4138. #pragma warning(push)
  4139. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  4140. #pragma warning(disable:4018) // more "signed/unsigned mismatch"
  4141. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  4142. #pragma warning(disable:4180) // qualifier applied to function type has no meaning
  4143. #pragma warning(disable:4800) // Forcing result to true or false
  4144. #endif
  4145. #ifdef __clang__
  4146. # pragma clang diagnostic push
  4147. # pragma clang diagnostic ignored "-Wsign-compare"
  4148. #elif defined __GNUC__
  4149. # pragma GCC diagnostic push
  4150. # pragma GCC diagnostic ignored "-Wsign-compare"
  4151. #endif
  4152. namespace Catch {
  4153. class ITransientExpression {
  4154. bool m_isBinaryExpression;
  4155. bool m_result;
  4156. public:
  4157. auto isBinaryExpression() const -> bool { return m_isBinaryExpression; }
  4158. auto getResult() const -> bool { return m_result; }
  4159. virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
  4160. ITransientExpression( bool isBinaryExpression, bool result )
  4161. : m_isBinaryExpression( isBinaryExpression ),
  4162. m_result( result )
  4163. {}
  4164. ITransientExpression() = default;
  4165. ITransientExpression(ITransientExpression const&) = default;
  4166. ITransientExpression& operator=(ITransientExpression const&) = default;
  4167. // We don't actually need a virtual destructor, but many static analysers
  4168. // complain if it's not here :-(
  4169. virtual ~ITransientExpression(); // = default;
  4170. friend std::ostream& operator<<(std::ostream& out, ITransientExpression const& expr) {
  4171. expr.streamReconstructedExpression(out);
  4172. return out;
  4173. }
  4174. };
  4175. void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
  4176. template<typename LhsT, typename RhsT>
  4177. class BinaryExpr : public ITransientExpression {
  4178. LhsT m_lhs;
  4179. StringRef m_op;
  4180. RhsT m_rhs;
  4181. void streamReconstructedExpression( std::ostream &os ) const override {
  4182. formatReconstructedExpression
  4183. ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
  4184. }
  4185. public:
  4186. BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
  4187. : ITransientExpression{ true, comparisonResult },
  4188. m_lhs( lhs ),
  4189. m_op( op ),
  4190. m_rhs( rhs )
  4191. {}
  4192. template<typename T>
  4193. auto operator && ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4194. static_assert(always_false<T>::value,
  4195. "chained comparisons are not supported inside assertions, "
  4196. "wrap the expression inside parentheses, or decompose it");
  4197. }
  4198. template<typename T>
  4199. auto operator || ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4200. static_assert(always_false<T>::value,
  4201. "chained comparisons are not supported inside assertions, "
  4202. "wrap the expression inside parentheses, or decompose it");
  4203. }
  4204. template<typename T>
  4205. auto operator == ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4206. static_assert(always_false<T>::value,
  4207. "chained comparisons are not supported inside assertions, "
  4208. "wrap the expression inside parentheses, or decompose it");
  4209. }
  4210. template<typename T>
  4211. auto operator != ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4212. static_assert(always_false<T>::value,
  4213. "chained comparisons are not supported inside assertions, "
  4214. "wrap the expression inside parentheses, or decompose it");
  4215. }
  4216. template<typename T>
  4217. auto operator > ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4218. static_assert(always_false<T>::value,
  4219. "chained comparisons are not supported inside assertions, "
  4220. "wrap the expression inside parentheses, or decompose it");
  4221. }
  4222. template<typename T>
  4223. auto operator < ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4224. static_assert(always_false<T>::value,
  4225. "chained comparisons are not supported inside assertions, "
  4226. "wrap the expression inside parentheses, or decompose it");
  4227. }
  4228. template<typename T>
  4229. auto operator >= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4230. static_assert(always_false<T>::value,
  4231. "chained comparisons are not supported inside assertions, "
  4232. "wrap the expression inside parentheses, or decompose it");
  4233. }
  4234. template<typename T>
  4235. auto operator <= ( T ) const -> BinaryExpr<LhsT, RhsT const&> const {
  4236. static_assert(always_false<T>::value,
  4237. "chained comparisons are not supported inside assertions, "
  4238. "wrap the expression inside parentheses, or decompose it");
  4239. }
  4240. };
  4241. template<typename LhsT>
  4242. class UnaryExpr : public ITransientExpression {
  4243. LhsT m_lhs;
  4244. void streamReconstructedExpression( std::ostream &os ) const override {
  4245. os << Catch::Detail::stringify( m_lhs );
  4246. }
  4247. public:
  4248. explicit UnaryExpr( LhsT lhs )
  4249. : ITransientExpression{ false, static_cast<bool>(lhs) },
  4250. m_lhs( lhs )
  4251. {}
  4252. };
  4253. // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
  4254. template<typename LhsT, typename RhsT>
  4255. auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); }
  4256. template<typename T>
  4257. auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
  4258. template<typename T>
  4259. auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
  4260. template<typename T>
  4261. auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
  4262. template<typename T>
  4263. auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
  4264. template<typename LhsT, typename RhsT>
  4265. auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); }
  4266. template<typename T>
  4267. auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
  4268. template<typename T>
  4269. auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
  4270. template<typename T>
  4271. auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
  4272. template<typename T>
  4273. auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
  4274. template<typename LhsT>
  4275. class ExprLhs {
  4276. LhsT m_lhs;
  4277. public:
  4278. explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
  4279. template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0>
  4280. friend auto operator == ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> {
  4281. return { compareEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "=="_sr, rhs };
  4282. }
  4283. template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0>
  4284. friend auto operator == ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> {
  4285. return { compareEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "=="_sr, rhs };
  4286. }
  4287. template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0>
  4288. friend auto operator != ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> {
  4289. return { compareNotEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "!="_sr, rhs };
  4290. }
  4291. template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0>
  4292. friend auto operator != ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> {
  4293. return { compareNotEqual( lhs.m_lhs, rhs ), lhs.m_lhs, "!="_sr, rhs };
  4294. }
  4295. #define CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(op) \
  4296. template<typename RhsT, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<RhsT>>::value, int> = 0> \
  4297. friend auto operator op ( ExprLhs && lhs, RhsT && rhs ) -> BinaryExpr<LhsT, RhsT const&> { \
  4298. return { static_cast<bool>(lhs.m_lhs op rhs), lhs.m_lhs, #op##_sr, rhs }; \
  4299. } \
  4300. template<typename RhsT, std::enable_if_t<std::is_arithmetic<RhsT>::value, int> = 0> \
  4301. friend auto operator op ( ExprLhs && lhs, RhsT rhs ) -> BinaryExpr<LhsT, RhsT> { \
  4302. return { static_cast<bool>(lhs.m_lhs op rhs), lhs.m_lhs, #op##_sr, rhs }; \
  4303. }
  4304. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(<)
  4305. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(>)
  4306. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(<=)
  4307. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(>=)
  4308. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(|)
  4309. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(&)
  4310. CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR(^)
  4311. #undef CATCH_INTERNAL_DEFINE_EXPRESSION_OPERATOR
  4312. template<typename RhsT>
  4313. friend auto operator && ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
  4314. static_assert(always_false<RhsT>::value,
  4315. "operator&& is not supported inside assertions, "
  4316. "wrap the expression inside parentheses, or decompose it");
  4317. }
  4318. template<typename RhsT>
  4319. friend auto operator || ( ExprLhs &&, RhsT && ) -> BinaryExpr<LhsT, RhsT const&> {
  4320. static_assert(always_false<RhsT>::value,
  4321. "operator|| is not supported inside assertions, "
  4322. "wrap the expression inside parentheses, or decompose it");
  4323. }
  4324. auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
  4325. return UnaryExpr<LhsT>{ m_lhs };
  4326. }
  4327. };
  4328. struct Decomposer {
  4329. template<typename T, std::enable_if_t<!std::is_arithmetic<std::remove_reference_t<T>>::value, int> = 0>
  4330. friend auto operator <= ( Decomposer &&, T && lhs ) -> ExprLhs<T const&> {
  4331. return ExprLhs<const T&>{ lhs };
  4332. }
  4333. template<typename T, std::enable_if_t<std::is_arithmetic<T>::value, int> = 0>
  4334. friend auto operator <= ( Decomposer &&, T value ) -> ExprLhs<T> {
  4335. return ExprLhs<T>{ value };
  4336. }
  4337. };
  4338. } // end namespace Catch
  4339. #ifdef _MSC_VER
  4340. #pragma warning(pop)
  4341. #endif
  4342. #ifdef __clang__
  4343. # pragma clang diagnostic pop
  4344. #elif defined __GNUC__
  4345. # pragma GCC diagnostic pop
  4346. #endif
  4347. #endif // CATCH_DECOMPOSER_HPP_INCLUDED
  4348. #include <string>
  4349. namespace Catch {
  4350. class IResultCapture;
  4351. struct AssertionReaction {
  4352. bool shouldDebugBreak = false;
  4353. bool shouldThrow = false;
  4354. };
  4355. class AssertionHandler {
  4356. AssertionInfo m_assertionInfo;
  4357. AssertionReaction m_reaction;
  4358. bool m_completed = false;
  4359. IResultCapture& m_resultCapture;
  4360. public:
  4361. AssertionHandler
  4362. ( StringRef macroName,
  4363. SourceLineInfo const& lineInfo,
  4364. StringRef capturedExpression,
  4365. ResultDisposition::Flags resultDisposition );
  4366. ~AssertionHandler() {
  4367. if ( !m_completed ) {
  4368. m_resultCapture.handleIncomplete( m_assertionInfo );
  4369. }
  4370. }
  4371. template<typename T>
  4372. void handleExpr( ExprLhs<T> const& expr ) {
  4373. handleExpr( expr.makeUnaryExpr() );
  4374. }
  4375. void handleExpr( ITransientExpression const& expr );
  4376. void handleMessage(ResultWas::OfType resultType, StringRef message);
  4377. void handleExceptionThrownAsExpected();
  4378. void handleUnexpectedExceptionNotThrown();
  4379. void handleExceptionNotThrownAsExpected();
  4380. void handleThrowingCallSkipped();
  4381. void handleUnexpectedInflightException();
  4382. void complete();
  4383. void setCompleted();
  4384. // query
  4385. auto allowThrows() const -> bool;
  4386. };
  4387. void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
  4388. } // namespace Catch
  4389. #endif // CATCH_ASSERTION_HANDLER_HPP_INCLUDED
  4390. // We need this suppression to leak, because it took until GCC 10
  4391. // for the front end to handle local suppression via _Pragma properly
  4392. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ <= 9
  4393. #pragma GCC diagnostic ignored "-Wparentheses"
  4394. #endif
  4395. #if !defined(CATCH_CONFIG_DISABLE)
  4396. #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
  4397. #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
  4398. #else
  4399. #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  4400. #endif
  4401. #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  4402. ///////////////////////////////////////////////////////////////////////////////
  4403. // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
  4404. // macros.
  4405. #define INTERNAL_CATCH_TRY
  4406. #define INTERNAL_CATCH_CATCH( capturer )
  4407. #else // CATCH_CONFIG_FAST_COMPILE
  4408. #define INTERNAL_CATCH_TRY try
  4409. #define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
  4410. #endif
  4411. #define INTERNAL_CATCH_REACT( handler ) handler.complete();
  4412. ///////////////////////////////////////////////////////////////////////////////
  4413. #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
  4414. do { /* NOLINT(bugprone-infinite-loop) */ \
  4415. /* The expression should not be evaluated, but warnings should hopefully be checked */ \
  4416. CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
  4417. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
  4418. INTERNAL_CATCH_TRY { \
  4419. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4420. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  4421. catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
  4422. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4423. } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
  4424. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4425. } 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
  4426. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  4427. ///////////////////////////////////////////////////////////////////////////////
  4428. #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
  4429. INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
  4430. if( Catch::getResultCapture().lastAssertionPassed() )
  4431. ///////////////////////////////////////////////////////////////////////////////
  4432. #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
  4433. INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
  4434. if( !Catch::getResultCapture().lastAssertionPassed() )
  4435. ///////////////////////////////////////////////////////////////////////////////
  4436. #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
  4437. do { \
  4438. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
  4439. try { \
  4440. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4441. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4442. static_cast<void>(__VA_ARGS__); \
  4443. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4444. catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
  4445. } \
  4446. catch( ... ) { \
  4447. catchAssertionHandler.handleUnexpectedInflightException(); \
  4448. } \
  4449. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4450. } while( false )
  4451. ///////////////////////////////////////////////////////////////////////////////
  4452. #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
  4453. do { \
  4454. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
  4455. if( catchAssertionHandler.allowThrows() ) \
  4456. try { \
  4457. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4458. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4459. static_cast<void>(__VA_ARGS__); \
  4460. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4461. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4462. } \
  4463. catch( ... ) { \
  4464. catchAssertionHandler.handleExceptionThrownAsExpected(); \
  4465. } \
  4466. else \
  4467. catchAssertionHandler.handleThrowingCallSkipped(); \
  4468. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4469. } while( false )
  4470. ///////////////////////////////////////////////////////////////////////////////
  4471. #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
  4472. do { \
  4473. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
  4474. if( catchAssertionHandler.allowThrows() ) \
  4475. try { \
  4476. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4477. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4478. static_cast<void>(expr); \
  4479. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4480. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4481. } \
  4482. catch( exceptionType const& ) { \
  4483. catchAssertionHandler.handleExceptionThrownAsExpected(); \
  4484. } \
  4485. catch( ... ) { \
  4486. catchAssertionHandler.handleUnexpectedInflightException(); \
  4487. } \
  4488. else \
  4489. catchAssertionHandler.handleThrowingCallSkipped(); \
  4490. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4491. } while( false )
  4492. ///////////////////////////////////////////////////////////////////////////////
  4493. // Although this is matcher-based, it can be used with just a string
  4494. #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
  4495. do { \
  4496. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  4497. if( catchAssertionHandler.allowThrows() ) \
  4498. try { \
  4499. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4500. CATCH_INTERNAL_SUPPRESS_USELESS_CAST_WARNINGS \
  4501. static_cast<void>(__VA_ARGS__); \
  4502. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4503. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  4504. } \
  4505. catch( ... ) { \
  4506. Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \
  4507. } \
  4508. else \
  4509. catchAssertionHandler.handleThrowingCallSkipped(); \
  4510. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  4511. } while( false )
  4512. #endif // CATCH_CONFIG_DISABLE
  4513. #endif // CATCH_TEST_MACRO_IMPL_HPP_INCLUDED
  4514. #ifndef CATCH_SECTION_HPP_INCLUDED
  4515. #define CATCH_SECTION_HPP_INCLUDED
  4516. #ifndef CATCH_TIMER_HPP_INCLUDED
  4517. #define CATCH_TIMER_HPP_INCLUDED
  4518. #include <cstdint>
  4519. namespace Catch {
  4520. class Timer {
  4521. uint64_t m_nanoseconds = 0;
  4522. public:
  4523. void start();
  4524. auto getElapsedNanoseconds() const -> uint64_t;
  4525. auto getElapsedMicroseconds() const -> uint64_t;
  4526. auto getElapsedMilliseconds() const -> unsigned int;
  4527. auto getElapsedSeconds() const -> double;
  4528. };
  4529. } // namespace Catch
  4530. #endif // CATCH_TIMER_HPP_INCLUDED
  4531. namespace Catch {
  4532. class Section : Detail::NonCopyable {
  4533. public:
  4534. Section( SectionInfo&& info );
  4535. ~Section();
  4536. // This indicates whether the section should be executed or not
  4537. explicit operator bool() const;
  4538. private:
  4539. SectionInfo m_info;
  4540. Counts m_assertions;
  4541. bool m_sectionIncluded;
  4542. Timer m_timer;
  4543. };
  4544. } // end namespace Catch
  4545. #define INTERNAL_CATCH_SECTION( ... ) \
  4546. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4547. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4548. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
  4549. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4550. #define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
  4551. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4552. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4553. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \
  4554. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4555. #endif // CATCH_SECTION_HPP_INCLUDED
  4556. #ifndef CATCH_TEST_REGISTRY_HPP_INCLUDED
  4557. #define CATCH_TEST_REGISTRY_HPP_INCLUDED
  4558. #ifndef CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  4559. #define CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  4560. #include <vector>
  4561. namespace Catch {
  4562. class TestSpec;
  4563. struct TestCaseInfo;
  4564. class ITestInvoker {
  4565. public:
  4566. virtual void invoke () const = 0;
  4567. virtual ~ITestInvoker(); // = default
  4568. };
  4569. class TestCaseHandle;
  4570. class IConfig;
  4571. class ITestCaseRegistry {
  4572. public:
  4573. virtual ~ITestCaseRegistry(); // = default
  4574. // TODO: this exists only for adding filenames to test cases -- let's expose this in a saner way later
  4575. virtual std::vector<TestCaseInfo* > const& getAllInfos() const = 0;
  4576. virtual std::vector<TestCaseHandle> const& getAllTests() const = 0;
  4577. virtual std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const = 0;
  4578. };
  4579. bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config );
  4580. bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config );
  4581. std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config );
  4582. std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config );
  4583. }
  4584. #endif // CATCH_INTERFACES_TESTCASE_HPP_INCLUDED
  4585. #ifndef CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4586. #define CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4587. #define INTERNAL_CATCH_EXPAND1( param ) INTERNAL_CATCH_EXPAND2( param )
  4588. #define INTERNAL_CATCH_EXPAND2( ... ) INTERNAL_CATCH_NO##__VA_ARGS__
  4589. #define INTERNAL_CATCH_DEF( ... ) INTERNAL_CATCH_DEF __VA_ARGS__
  4590. #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
  4591. #define INTERNAL_CATCH_REMOVE_PARENS( ... ) \
  4592. INTERNAL_CATCH_EXPAND1( INTERNAL_CATCH_DEF __VA_ARGS__ )
  4593. #endif // CATCH_PREPROCESSOR_REMOVE_PARENS_HPP_INCLUDED
  4594. // GCC 5 and older do not properly handle disabling unused-variable warning
  4595. // with a _Pragma. This means that we have to leak the suppression to the
  4596. // user code as well :-(
  4597. #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
  4598. #pragma GCC diagnostic ignored "-Wunused-variable"
  4599. #endif
  4600. namespace Catch {
  4601. template<typename C>
  4602. class TestInvokerAsMethod : public ITestInvoker {
  4603. void (C::*m_testAsMethod)();
  4604. public:
  4605. TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
  4606. void invoke() const override {
  4607. C obj;
  4608. (obj.*m_testAsMethod)();
  4609. }
  4610. };
  4611. Detail::unique_ptr<ITestInvoker> makeTestInvoker( void(*testAsFunction)() );
  4612. template<typename C>
  4613. Detail::unique_ptr<ITestInvoker> makeTestInvoker( void (C::*testAsMethod)() ) {
  4614. return Detail::make_unique<TestInvokerAsMethod<C>>( testAsMethod );
  4615. }
  4616. struct NameAndTags {
  4617. constexpr NameAndTags( StringRef name_ = StringRef(),
  4618. StringRef tags_ = StringRef() ) noexcept:
  4619. name( name_ ), tags( tags_ ) {}
  4620. StringRef name;
  4621. StringRef tags;
  4622. };
  4623. struct AutoReg : Detail::NonCopyable {
  4624. AutoReg( Detail::unique_ptr<ITestInvoker> invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept;
  4625. };
  4626. } // end namespace Catch
  4627. #if defined(CATCH_CONFIG_DISABLE)
  4628. #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
  4629. static inline void TestName()
  4630. #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
  4631. namespace{ \
  4632. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
  4633. void test(); \
  4634. }; \
  4635. } \
  4636. void TestName::test()
  4637. #endif
  4638. ///////////////////////////////////////////////////////////////////////////////
  4639. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  4640. static void TestName(); \
  4641. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4642. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4643. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4644. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
  4645. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4646. static void TestName()
  4647. #define INTERNAL_CATCH_TESTCASE( ... ) \
  4648. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__ )
  4649. ///////////////////////////////////////////////////////////////////////////////
  4650. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  4651. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4652. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4653. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4654. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
  4655. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  4656. ///////////////////////////////////////////////////////////////////////////////
  4657. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  4658. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4659. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4660. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4661. namespace{ \
  4662. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
  4663. void test(); \
  4664. }; \
  4665. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
  4666. } \
  4667. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4668. void TestName::test()
  4669. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  4670. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), ClassName, __VA_ARGS__ )
  4671. ///////////////////////////////////////////////////////////////////////////////
  4672. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  4673. do { \
  4674. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  4675. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  4676. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  4677. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
  4678. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  4679. } while(false)
  4680. #endif // CATCH_TEST_REGISTRY_HPP_INCLUDED
  4681. // All of our user-facing macros support configuration toggle, that
  4682. // forces them to be defined prefixed with CATCH_. We also like to
  4683. // support another toggle that can minimize (disable) their implementation.
  4684. // Given this, we have 4 different configuration options below
  4685. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  4686. #define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4687. #define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4688. #define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4689. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  4690. #define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4691. #define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4692. #define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4693. #define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4694. #define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4695. #define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4696. #define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4697. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  4698. #define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4699. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  4700. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  4701. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  4702. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  4703. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  4704. #define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
  4705. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4706. #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4707. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4708. #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
  4709. #define CATCH_STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
  4710. #define CATCH_STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
  4711. #define CATCH_STATIC_CHECK( ... ) static_assert( __VA_ARGS__ , #__VA_ARGS__ ); CATCH_SUCCEED( #__VA_ARGS__ )
  4712. #define CATCH_STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); CATCH_SUCCEED( #__VA_ARGS__ )
  4713. #else
  4714. #define CATCH_STATIC_REQUIRE( ... ) CATCH_REQUIRE( __VA_ARGS__ )
  4715. #define CATCH_STATIC_REQUIRE_FALSE( ... ) CATCH_REQUIRE_FALSE( __VA_ARGS__ )
  4716. #define CATCH_STATIC_CHECK( ... ) CATCH_CHECK( __VA_ARGS__ )
  4717. #define CATCH_STATIC_CHECK_FALSE( ... ) CATCH_CHECK_FALSE( __VA_ARGS__ )
  4718. #endif
  4719. // "BDD-style" convenience wrappers
  4720. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  4721. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  4722. #define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
  4723. #define CATCH_AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
  4724. #define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
  4725. #define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
  4726. #define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
  4727. #define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
  4728. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, implemented | vv prefixed, disabled
  4729. #define CATCH_REQUIRE( ... ) (void)(0)
  4730. #define CATCH_REQUIRE_FALSE( ... ) (void)(0)
  4731. #define CATCH_REQUIRE_THROWS( ... ) (void)(0)
  4732. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
  4733. #define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
  4734. #define CATCH_CHECK( ... ) (void)(0)
  4735. #define CATCH_CHECK_FALSE( ... ) (void)(0)
  4736. #define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
  4737. #define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
  4738. #define CATCH_CHECK_NOFAIL( ... ) (void)(0)
  4739. #define CATCH_CHECK_THROWS( ... ) (void)(0)
  4740. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
  4741. #define CATCH_CHECK_NOTHROW( ... ) (void)(0)
  4742. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4743. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4744. #define CATCH_METHOD_AS_TEST_CASE( method, ... )
  4745. #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
  4746. #define CATCH_SECTION( ... )
  4747. #define CATCH_DYNAMIC_SECTION( ... )
  4748. #define CATCH_FAIL( ... ) (void)(0)
  4749. #define CATCH_FAIL_CHECK( ... ) (void)(0)
  4750. #define CATCH_SUCCEED( ... ) (void)(0)
  4751. #define CATCH_STATIC_REQUIRE( ... ) (void)(0)
  4752. #define CATCH_STATIC_REQUIRE_FALSE( ... ) (void)(0)
  4753. #define CATCH_STATIC_CHECK( ... ) (void)(0)
  4754. #define CATCH_STATIC_CHECK_FALSE( ... ) (void)(0)
  4755. // "BDD-style" convenience wrappers
  4756. #define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4757. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
  4758. #define CATCH_GIVEN( desc )
  4759. #define CATCH_AND_GIVEN( desc )
  4760. #define CATCH_WHEN( desc )
  4761. #define CATCH_AND_WHEN( desc )
  4762. #define CATCH_THEN( desc )
  4763. #define CATCH_AND_THEN( desc )
  4764. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE) // ^^ prefixed, disabled | vv unprefixed, implemented
  4765. #define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4766. #define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4767. #define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4768. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  4769. #define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4770. #define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4771. #define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
  4772. #define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4773. #define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4774. #define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
  4775. #define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4776. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  4777. #define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4778. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  4779. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  4780. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  4781. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  4782. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  4783. #define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ )
  4784. #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  4785. #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4786. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  4787. #if !defined(CATCH_CONFIG_RUNTIME_STATIC_REQUIRE)
  4788. #define STATIC_REQUIRE( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
  4789. #define STATIC_REQUIRE_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
  4790. #define STATIC_CHECK( ... ) static_assert( __VA_ARGS__, #__VA_ARGS__ ); SUCCEED( #__VA_ARGS__ )
  4791. #define STATIC_CHECK_FALSE( ... ) static_assert( !(__VA_ARGS__), "!(" #__VA_ARGS__ ")" ); SUCCEED( "!(" #__VA_ARGS__ ")" )
  4792. #else
  4793. #define STATIC_REQUIRE( ... ) REQUIRE( __VA_ARGS__ )
  4794. #define STATIC_REQUIRE_FALSE( ... ) REQUIRE_FALSE( __VA_ARGS__ )
  4795. #define STATIC_CHECK( ... ) CHECK( __VA_ARGS__ )
  4796. #define STATIC_CHECK_FALSE( ... ) CHECK_FALSE( __VA_ARGS__ )
  4797. #endif
  4798. // "BDD-style" convenience wrappers
  4799. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  4800. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  4801. #define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc )
  4802. #define AND_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And given: " << desc )
  4803. #define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc )
  4804. #define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And when: " << desc )
  4805. #define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc )
  4806. #define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc )
  4807. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE) // ^^ unprefixed, implemented | vv unprefixed, disabled
  4808. #define REQUIRE( ... ) (void)(0)
  4809. #define REQUIRE_FALSE( ... ) (void)(0)
  4810. #define REQUIRE_THROWS( ... ) (void)(0)
  4811. #define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
  4812. #define REQUIRE_NOTHROW( ... ) (void)(0)
  4813. #define CHECK( ... ) (void)(0)
  4814. #define CHECK_FALSE( ... ) (void)(0)
  4815. #define CHECKED_IF( ... ) if (__VA_ARGS__)
  4816. #define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
  4817. #define CHECK_NOFAIL( ... ) (void)(0)
  4818. #define CHECK_THROWS( ... ) (void)(0)
  4819. #define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
  4820. #define CHECK_NOTHROW( ... ) (void)(0)
  4821. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), __VA_ARGS__)
  4822. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ))
  4823. #define METHOD_AS_TEST_CASE( method, ... )
  4824. #define REGISTER_TEST_CASE( Function, ... ) (void)(0)
  4825. #define SECTION( ... )
  4826. #define DYNAMIC_SECTION( ... )
  4827. #define FAIL( ... ) (void)(0)
  4828. #define FAIL_CHECK( ... ) (void)(0)
  4829. #define SUCCEED( ... ) (void)(0)
  4830. #define STATIC_REQUIRE( ... ) (void)(0)
  4831. #define STATIC_REQUIRE_FALSE( ... ) (void)(0)
  4832. #define STATIC_CHECK( ... ) (void)(0)
  4833. #define STATIC_CHECK_FALSE( ... ) (void)(0)
  4834. // "BDD-style" convenience wrappers
  4835. #define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ) )
  4836. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( CATCH2_INTERNAL_TEST_ ), className )
  4837. #define GIVEN( desc )
  4838. #define AND_GIVEN( desc )
  4839. #define WHEN( desc )
  4840. #define AND_WHEN( desc )
  4841. #define THEN( desc )
  4842. #define AND_THEN( desc )
  4843. #endif // ^^ unprefixed, disabled
  4844. // end of user facing macros
  4845. #endif // CATCH_TEST_MACROS_HPP_INCLUDED
  4846. #ifndef CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  4847. #define CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  4848. #ifndef CATCH_PREPROCESSOR_HPP_INCLUDED
  4849. #define CATCH_PREPROCESSOR_HPP_INCLUDED
  4850. #if defined(__GNUC__)
  4851. // We need to silence "empty __VA_ARGS__ warning", and using just _Pragma does not work
  4852. #pragma GCC system_header
  4853. #endif
  4854. #define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__
  4855. #define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__)))
  4856. #define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__)))
  4857. #define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__)))
  4858. #define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__)))
  4859. #define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__)))
  4860. #ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  4861. #define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__
  4862. // MSVC needs more evaluations
  4863. #define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__)))
  4864. #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__))
  4865. #else
  4866. #define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__)
  4867. #endif
  4868. #define CATCH_REC_END(...)
  4869. #define CATCH_REC_OUT
  4870. #define CATCH_EMPTY()
  4871. #define CATCH_DEFER(id) id CATCH_EMPTY()
  4872. #define CATCH_REC_GET_END2() 0, CATCH_REC_END
  4873. #define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2
  4874. #define CATCH_REC_GET_END(...) CATCH_REC_GET_END1
  4875. #define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT
  4876. #define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0)
  4877. #define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next)
  4878. #define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
  4879. #define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ )
  4880. #define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ )
  4881. #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__ )
  4882. #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__ )
  4883. #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__ )
  4884. // Applies the function macro `f` to each of the remaining parameters, inserts commas between the results,
  4885. // and passes userdata as the first parameter to each invocation,
  4886. // e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c)
  4887. #define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
  4888. #define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
  4889. #define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__)
  4890. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  4891. #define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__
  4892. #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param))
  4893. #else
  4894. // MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
  4895. #define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__)
  4896. #define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__
  4897. #define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1)
  4898. #endif
  4899. #define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__
  4900. #define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name)
  4901. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  4902. #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>())
  4903. #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))
  4904. #else
  4905. #define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper<INTERNAL_CATCH_REMOVE_PARENS_GEN(__VA_ARGS__)>()))
  4906. #define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)))
  4907. #endif
  4908. #define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\
  4909. CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__)
  4910. #define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0)
  4911. #define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1)
  4912. #define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2)
  4913. #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)
  4914. #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)
  4915. #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)
  4916. #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)
  4917. #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)
  4918. #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)
  4919. #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)
  4920. #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)
  4921. #define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N
  4922. #define INTERNAL_CATCH_TYPE_GEN\
  4923. template<typename...> struct TypeList {};\
  4924. template<typename...Ts>\
  4925. constexpr auto get_wrapper() noexcept -> TypeList<Ts...> { return {}; }\
  4926. template<template<typename...> class...> struct TemplateTypeList{};\
  4927. template<template<typename...> class...Cs>\
  4928. constexpr auto get_wrapper() noexcept -> TemplateTypeList<Cs...> { return {}; }\
  4929. template<typename...>\
  4930. struct append;\
  4931. template<typename...>\
  4932. struct rewrap;\
  4933. template<template<typename...> class, typename...>\
  4934. struct create;\
  4935. template<template<typename...> class, typename>\
  4936. struct convert;\
  4937. \
  4938. template<typename T> \
  4939. struct append<T> { using type = T; };\
  4940. template< template<typename...> class L1, typename...E1, template<typename...> class L2, typename...E2, typename...Rest>\
  4941. struct append<L1<E1...>, L2<E2...>, Rest...> { using type = typename append<L1<E1...,E2...>, Rest...>::type; };\
  4942. template< template<typename...> class L1, typename...E1, typename...Rest>\
  4943. struct append<L1<E1...>, TypeList<mpl_::na>, Rest...> { using type = L1<E1...>; };\
  4944. \
  4945. template< template<typename...> class Container, template<typename...> class List, typename...elems>\
  4946. struct rewrap<TemplateTypeList<Container>, List<elems...>> { using type = TypeList<Container<elems...>>; };\
  4947. template< template<typename...> class Container, template<typename...> class List, class...Elems, typename...Elements>\
  4948. struct rewrap<TemplateTypeList<Container>, List<Elems...>, Elements...> { using type = typename append<TypeList<Container<Elems...>>, typename rewrap<TemplateTypeList<Container>, Elements...>::type>::type; };\
  4949. \
  4950. template<template <typename...> class Final, template< typename...> class...Containers, typename...Types>\
  4951. struct create<Final, TemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<TemplateTypeList<Containers>, Types...>::type...>::type; };\
  4952. template<template <typename...> class Final, template <typename...> class List, typename...Ts>\
  4953. struct convert<Final, List<Ts...>> { using type = typename append<Final<>,TypeList<Ts>...>::type; };
  4954. #define INTERNAL_CATCH_NTTP_1(signature, ...)\
  4955. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> struct Nttp{};\
  4956. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4957. constexpr auto get_wrapper() noexcept -> Nttp<__VA_ARGS__> { return {}; } \
  4958. template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...> struct NttpTemplateTypeList{};\
  4959. template<template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Cs>\
  4960. constexpr auto get_wrapper() noexcept -> NttpTemplateTypeList<Cs...> { return {}; } \
  4961. \
  4962. template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4963. struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>> { using type = TypeList<Container<__VA_ARGS__>>; };\
  4964. template< template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class Container, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class List, INTERNAL_CATCH_REMOVE_PARENS(signature), typename...Elements>\
  4965. struct rewrap<NttpTemplateTypeList<Container>, List<__VA_ARGS__>, Elements...> { using type = typename append<TypeList<Container<__VA_ARGS__>>, typename rewrap<NttpTemplateTypeList<Container>, Elements...>::type>::type; };\
  4966. template<template <typename...> class Final, template<INTERNAL_CATCH_REMOVE_PARENS(signature)> class...Containers, typename...Types>\
  4967. struct create<Final, NttpTemplateTypeList<Containers...>, TypeList<Types...>> { using type = typename append<Final<>, typename rewrap<NttpTemplateTypeList<Containers>, Types...>::type...>::type; };
  4968. #define INTERNAL_CATCH_DECLARE_SIG_TEST0(TestName)
  4969. #define INTERNAL_CATCH_DECLARE_SIG_TEST1(TestName, signature)\
  4970. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4971. static void TestName()
  4972. #define INTERNAL_CATCH_DECLARE_SIG_TEST_X(TestName, signature, ...)\
  4973. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4974. static void TestName()
  4975. #define INTERNAL_CATCH_DEFINE_SIG_TEST0(TestName)
  4976. #define INTERNAL_CATCH_DEFINE_SIG_TEST1(TestName, signature)\
  4977. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4978. static void TestName()
  4979. #define INTERNAL_CATCH_DEFINE_SIG_TEST_X(TestName, signature,...)\
  4980. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4981. static void TestName()
  4982. #define INTERNAL_CATCH_NTTP_REGISTER0(TestFunc, signature)\
  4983. template<typename Type>\
  4984. void reg_test(TypeList<Type>, Catch::NameAndTags nameAndTags)\
  4985. {\
  4986. Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<Type>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
  4987. }
  4988. #define INTERNAL_CATCH_NTTP_REGISTER(TestFunc, signature, ...)\
  4989. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  4990. void reg_test(Nttp<__VA_ARGS__>, Catch::NameAndTags nameAndTags)\
  4991. {\
  4992. Catch::AutoReg( Catch::makeTestInvoker(&TestFunc<__VA_ARGS__>), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), nameAndTags);\
  4993. }
  4994. #define INTERNAL_CATCH_NTTP_REGISTER_METHOD0(TestName, signature, ...)\
  4995. template<typename Type>\
  4996. void reg_test(TypeList<Type>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
  4997. {\
  4998. Catch::AutoReg( Catch::makeTestInvoker(&TestName<Type>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
  4999. }
  5000. #define INTERNAL_CATCH_NTTP_REGISTER_METHOD(TestName, signature, ...)\
  5001. template<INTERNAL_CATCH_REMOVE_PARENS(signature)>\
  5002. void reg_test(Nttp<__VA_ARGS__>, Catch::StringRef className, Catch::NameAndTags nameAndTags)\
  5003. {\
  5004. Catch::AutoReg( Catch::makeTestInvoker(&TestName<__VA_ARGS__>::test), CATCH_INTERNAL_LINEINFO, className, nameAndTags);\
  5005. }
  5006. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD0(TestName, ClassName)
  5007. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD1(TestName, ClassName, signature)\
  5008. template<typename TestType> \
  5009. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<TestType> { \
  5010. void test();\
  5011. }
  5012. #define INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD_X(TestName, ClassName, signature, ...)\
  5013. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
  5014. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName)<__VA_ARGS__> { \
  5015. void test();\
  5016. }
  5017. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD0(TestName)
  5018. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD1(TestName, signature)\
  5019. template<typename TestType> \
  5020. void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<TestType>::test()
  5021. #define INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD_X(TestName, signature, ...)\
  5022. template<INTERNAL_CATCH_REMOVE_PARENS(signature)> \
  5023. void INTERNAL_CATCH_MAKE_NAMESPACE(TestName)::TestName<__VA_ARGS__>::test()
  5024. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5025. #define INTERNAL_CATCH_NTTP_0
  5026. #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)
  5027. #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__)
  5028. #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__)
  5029. #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__)
  5030. #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__)
  5031. #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__)
  5032. #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__)
  5033. #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__)
  5034. #else
  5035. #define INTERNAL_CATCH_NTTP_0(signature)
  5036. #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__))
  5037. #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__))
  5038. #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__))
  5039. #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__))
  5040. #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__))
  5041. #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__))
  5042. #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__))
  5043. #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__))
  5044. #endif
  5045. #endif // CATCH_PREPROCESSOR_HPP_INCLUDED
  5046. // GCC 5 and older do not properly handle disabling unused-variable warning
  5047. // with a _Pragma. This means that we have to leak the suppression to the
  5048. // user code as well :-(
  5049. #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5
  5050. #pragma GCC diagnostic ignored "-Wunused-variable"
  5051. #endif
  5052. #if defined(CATCH_CONFIG_DISABLE)
  5053. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION_2( TestName, TestFunc, Name, Tags, Signature, ... ) \
  5054. INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5055. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
  5056. namespace{ \
  5057. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
  5058. INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5059. } \
  5060. } \
  5061. INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5062. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5063. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
  5064. 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__ )
  5065. #else
  5066. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(Name, Tags, ...) \
  5067. 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__ ) )
  5068. #endif
  5069. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5070. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
  5071. 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__ )
  5072. #else
  5073. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(Name, Tags, Signature, ...) \
  5074. 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__ ) )
  5075. #endif
  5076. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5077. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
  5078. 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__ )
  5079. #else
  5080. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION( ClassName, Name, Tags,... ) \
  5081. 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__ ) )
  5082. #endif
  5083. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5084. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
  5085. 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__ )
  5086. #else
  5087. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION( ClassName, Name, Tags, Signature, ... ) \
  5088. 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__ ) )
  5089. #endif
  5090. #endif
  5091. ///////////////////////////////////////////////////////////////////////////////
  5092. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
  5093. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5094. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5095. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5096. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5097. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5098. INTERNAL_CATCH_DECLARE_SIG_TEST(TestFunc, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5099. namespace {\
  5100. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
  5101. INTERNAL_CATCH_TYPE_GEN\
  5102. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5103. INTERNAL_CATCH_NTTP_REG_GEN(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5104. template<typename...Types> \
  5105. struct TestName{\
  5106. TestName(){\
  5107. size_t index = 0; \
  5108. 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) */\
  5109. using expander = size_t[]; /* NOLINT(cppcoreguidelines-avoid-c-arrays,modernize-avoid-c-arrays,hicpp-avoid-c-arrays) */\
  5110. (void)expander{(reg_test(Types{}, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
  5111. }\
  5112. };\
  5113. static const int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5114. TestName<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
  5115. return 0;\
  5116. }();\
  5117. }\
  5118. }\
  5119. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5120. INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5121. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5122. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
  5123. 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__ )
  5124. #else
  5125. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE(Name, Tags, ...) \
  5126. 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__ ) )
  5127. #endif
  5128. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5129. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
  5130. 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__ )
  5131. #else
  5132. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG(Name, Tags, Signature, ...) \
  5133. 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__ ) )
  5134. #endif
  5135. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
  5136. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5137. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5138. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5139. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5140. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5141. template<typename TestType> static void TestFuncName(); \
  5142. namespace {\
  5143. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName) { \
  5144. INTERNAL_CATCH_TYPE_GEN \
  5145. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature)) \
  5146. template<typename... Types> \
  5147. struct TestName { \
  5148. void reg_tests() { \
  5149. size_t index = 0; \
  5150. using expander = size_t[]; \
  5151. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
  5152. constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
  5153. constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
  5154. (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 */\
  5155. } \
  5156. }; \
  5157. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
  5158. 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; \
  5159. TestInit t; \
  5160. t.reg_tests(); \
  5161. return 0; \
  5162. }(); \
  5163. } \
  5164. } \
  5165. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5166. template<typename TestType> \
  5167. static void TestFuncName()
  5168. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5169. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
  5170. 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__)
  5171. #else
  5172. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE(Name, Tags, ...)\
  5173. 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__ ) )
  5174. #endif
  5175. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5176. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
  5177. 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__)
  5178. #else
  5179. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG(Name, Tags, Signature, ...)\
  5180. 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__ ) )
  5181. #endif
  5182. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
  5183. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5184. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5185. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5186. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5187. template<typename TestType> static void TestFunc(); \
  5188. namespace {\
  5189. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){\
  5190. INTERNAL_CATCH_TYPE_GEN\
  5191. template<typename... Types> \
  5192. struct TestName { \
  5193. void reg_tests() { \
  5194. size_t index = 0; \
  5195. using expander = size_t[]; \
  5196. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestFunc<Types> ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */\
  5197. } \
  5198. };\
  5199. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){ \
  5200. using TestInit = typename convert<TestName, TmplList>::type; \
  5201. TestInit t; \
  5202. t.reg_tests(); \
  5203. return 0; \
  5204. }(); \
  5205. }}\
  5206. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5207. template<typename TestType> \
  5208. static void TestFunc()
  5209. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(Name, Tags, TmplList) \
  5210. 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 )
  5211. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
  5212. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5213. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5214. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5215. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5216. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5217. namespace {\
  5218. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
  5219. INTERNAL_CATCH_TYPE_GEN\
  5220. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5221. INTERNAL_CATCH_DECLARE_SIG_TEST_METHOD(TestName, ClassName, INTERNAL_CATCH_REMOVE_PARENS(Signature));\
  5222. INTERNAL_CATCH_NTTP_REG_METHOD_GEN(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5223. template<typename...Types> \
  5224. struct TestNameClass{\
  5225. TestNameClass(){\
  5226. size_t index = 0; \
  5227. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, __VA_ARGS__)};\
  5228. using expander = size_t[];\
  5229. (void)expander{(reg_test(Types{}, #ClassName, Catch::NameAndTags{ Name " - " + std::string(tmpl_types[index]), Tags } ), index++)... };/* NOLINT */ \
  5230. }\
  5231. };\
  5232. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5233. TestNameClass<INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(__VA_ARGS__)>();\
  5234. return 0;\
  5235. }();\
  5236. }\
  5237. }\
  5238. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5239. INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
  5240. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5241. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
  5242. 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__ )
  5243. #else
  5244. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( ClassName, Name, Tags,... ) \
  5245. 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__ ) )
  5246. #endif
  5247. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5248. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
  5249. 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__ )
  5250. #else
  5251. #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... ) \
  5252. 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__ ) )
  5253. #endif
  5254. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
  5255. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5256. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5257. CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
  5258. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5259. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5260. template<typename TestType> \
  5261. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
  5262. void test();\
  5263. };\
  5264. namespace {\
  5265. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestNameClass) {\
  5266. INTERNAL_CATCH_TYPE_GEN \
  5267. INTERNAL_CATCH_NTTP_GEN(INTERNAL_CATCH_REMOVE_PARENS(Signature))\
  5268. template<typename...Types>\
  5269. struct TestNameClass{\
  5270. void reg_tests(){\
  5271. std::size_t index = 0;\
  5272. using expander = std::size_t[];\
  5273. constexpr char const* tmpl_types[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TmplTypes))};\
  5274. constexpr char const* types_list[] = {CATCH_REC_LIST(INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS, INTERNAL_CATCH_REMOVE_PARENS(TypesList))};\
  5275. constexpr auto num_types = sizeof(types_list) / sizeof(types_list[0]);\
  5276. (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 */ \
  5277. }\
  5278. };\
  5279. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5280. 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;\
  5281. TestInit t;\
  5282. t.reg_tests();\
  5283. return 0;\
  5284. }(); \
  5285. }\
  5286. }\
  5287. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5288. template<typename TestType> \
  5289. void TestName<TestType>::test()
  5290. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5291. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
  5292. 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__ )
  5293. #else
  5294. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( ClassName, Name, Tags, ... )\
  5295. 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__ ) )
  5296. #endif
  5297. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5298. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
  5299. 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__ )
  5300. #else
  5301. #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( ClassName, Name, Tags, Signature, ... )\
  5302. 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__ ) )
  5303. #endif
  5304. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
  5305. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5306. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5307. CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
  5308. CATCH_INTERNAL_SUPPRESS_UNUSED_VARIABLE_WARNINGS \
  5309. template<typename TestType> \
  5310. struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName <TestType>) { \
  5311. void test();\
  5312. };\
  5313. namespace {\
  5314. namespace INTERNAL_CATCH_MAKE_NAMESPACE(TestName){ \
  5315. INTERNAL_CATCH_TYPE_GEN\
  5316. template<typename...Types>\
  5317. struct TestNameClass{\
  5318. void reg_tests(){\
  5319. size_t index = 0;\
  5320. using expander = size_t[];\
  5321. (void)expander{(Catch::AutoReg( Catch::makeTestInvoker( &TestName<Types>::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ Name " - " + std::string(INTERNAL_CATCH_STRINGIZE(TmplList)) + " - " + std::to_string(index), Tags } ), index++)... };/* NOLINT */ \
  5322. }\
  5323. };\
  5324. static int INTERNAL_CATCH_UNIQUE_NAME( globalRegistrar ) = [](){\
  5325. using TestInit = typename convert<TestNameClass, TmplList>::type;\
  5326. TestInit t;\
  5327. t.reg_tests();\
  5328. return 0;\
  5329. }(); \
  5330. }}\
  5331. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5332. template<typename TestType> \
  5333. void TestName<TestType>::test()
  5334. #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD(ClassName, Name, Tags, TmplList) \
  5335. 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 )
  5336. #endif // CATCH_TEMPLATE_TEST_REGISTRY_HPP_INCLUDED
  5337. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  5338. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5339. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5340. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
  5341. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5342. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5343. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
  5344. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
  5345. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5346. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5347. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
  5348. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5349. #else
  5350. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
  5351. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
  5352. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5353. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5354. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
  5355. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
  5356. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5357. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5358. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
  5359. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5360. #endif
  5361. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  5362. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5363. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
  5364. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
  5365. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
  5366. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
  5367. #else
  5368. #define CATCH_TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
  5369. #define CATCH_TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
  5370. #define CATCH_TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5371. #define CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5372. #endif
  5373. // When disabled, these can be shared between proper preprocessor and MSVC preprocessor
  5374. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5375. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5376. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5377. #define CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5378. #define CATCH_TEMPLATE_LIST_TEST_CASE( ... ) CATCH_TEMPLATE_TEST_CASE(__VA_ARGS__)
  5379. #define CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5380. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  5381. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5382. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5383. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ )
  5384. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5385. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5386. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ )
  5387. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ )
  5388. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5389. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ )
  5390. #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE(__VA_ARGS__)
  5391. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5392. #else
  5393. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE( __VA_ARGS__ ) )
  5394. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG( __VA_ARGS__ ) )
  5395. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5396. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5397. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE( __VA_ARGS__ ) )
  5398. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_SIG( __VA_ARGS__ ) )
  5399. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5400. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, __VA_ARGS__ ) )
  5401. #define TEMPLATE_LIST_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE( __VA_ARGS__ ) )
  5402. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD( className, __VA_ARGS__ ) )
  5403. #endif
  5404. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  5405. #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
  5406. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__)
  5407. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__)
  5408. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__)
  5409. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ )
  5410. #else
  5411. #define TEMPLATE_TEST_CASE( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_NO_REGISTRATION(__VA_ARGS__) )
  5412. #define TEMPLATE_TEST_CASE_SIG( ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_SIG_NO_REGISTRATION(__VA_ARGS__) )
  5413. #define TEMPLATE_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5414. #define TEMPLATE_TEST_CASE_METHOD_SIG( className, ... ) INTERNAL_CATCH_EXPAND_VARGS( INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_SIG_NO_REGISTRATION(className, __VA_ARGS__ ) )
  5415. #endif
  5416. // When disabled, these can be shared between proper preprocessor and MSVC preprocessor
  5417. #define TEMPLATE_PRODUCT_TEST_CASE( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5418. #define TEMPLATE_PRODUCT_TEST_CASE_SIG( ... ) TEMPLATE_TEST_CASE( __VA_ARGS__ )
  5419. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5420. #define TEMPLATE_PRODUCT_TEST_CASE_METHOD_SIG( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5421. #define TEMPLATE_LIST_TEST_CASE( ... ) TEMPLATE_TEST_CASE(__VA_ARGS__)
  5422. #define TEMPLATE_LIST_TEST_CASE_METHOD( className, ... ) TEMPLATE_TEST_CASE_METHOD( className, __VA_ARGS__ )
  5423. #endif // end of user facing macro declarations
  5424. #endif // CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED
  5425. #ifndef CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5426. #define CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5427. #include <string>
  5428. #include <vector>
  5429. #ifdef __clang__
  5430. #pragma clang diagnostic push
  5431. #pragma clang diagnostic ignored "-Wpadded"
  5432. #endif
  5433. namespace Catch {
  5434. /**
  5435. * A **view** of a tag string that provides case insensitive comparisons
  5436. *
  5437. * Note that in Catch2 internals, the square brackets around tags are
  5438. * not a part of tag's representation, so e.g. "[cool-tag]" is represented
  5439. * as "cool-tag" internally.
  5440. */
  5441. struct Tag {
  5442. constexpr Tag(StringRef original_):
  5443. original(original_)
  5444. {}
  5445. StringRef original;
  5446. friend bool operator< ( Tag const& lhs, Tag const& rhs );
  5447. friend bool operator==( Tag const& lhs, Tag const& rhs );
  5448. };
  5449. class ITestInvoker;
  5450. enum class TestCaseProperties : uint8_t {
  5451. None = 0,
  5452. IsHidden = 1 << 1,
  5453. ShouldFail = 1 << 2,
  5454. MayFail = 1 << 3,
  5455. Throws = 1 << 4,
  5456. NonPortable = 1 << 5,
  5457. Benchmark = 1 << 6
  5458. };
  5459. /**
  5460. * Various metadata about the test case.
  5461. *
  5462. * A test case is uniquely identified by its (class)name and tags
  5463. * combination, with source location being ignored, and other properties
  5464. * being determined from tags.
  5465. *
  5466. * Tags are kept sorted.
  5467. */
  5468. struct TestCaseInfo : Detail::NonCopyable {
  5469. TestCaseInfo(StringRef _className,
  5470. NameAndTags const& _tags,
  5471. SourceLineInfo const& _lineInfo);
  5472. bool isHidden() const;
  5473. bool throws() const;
  5474. bool okToFail() const;
  5475. bool expectedToFail() const;
  5476. // Adds the tag(s) with test's filename (for the -# flag)
  5477. void addFilenameTag();
  5478. //! Orders by name, classname and tags
  5479. friend bool operator<( TestCaseInfo const& lhs,
  5480. TestCaseInfo const& rhs );
  5481. std::string tagsAsString() const;
  5482. std::string name;
  5483. StringRef className;
  5484. private:
  5485. std::string backingTags;
  5486. // Internally we copy tags to the backing storage and then add
  5487. // refs to this storage to the tags vector.
  5488. void internalAppendTag(StringRef tagString);
  5489. public:
  5490. std::vector<Tag> tags;
  5491. SourceLineInfo lineInfo;
  5492. TestCaseProperties properties = TestCaseProperties::None;
  5493. };
  5494. /**
  5495. * Wrapper over the test case information and the test case invoker
  5496. *
  5497. * Does not own either, and is specifically made to be cheap
  5498. * to copy around.
  5499. */
  5500. class TestCaseHandle {
  5501. TestCaseInfo* m_info;
  5502. ITestInvoker* m_invoker;
  5503. public:
  5504. TestCaseHandle(TestCaseInfo* info, ITestInvoker* invoker) :
  5505. m_info(info), m_invoker(invoker) {}
  5506. void invoke() const {
  5507. m_invoker->invoke();
  5508. }
  5509. TestCaseInfo const& getTestCaseInfo() const;
  5510. };
  5511. Detail::unique_ptr<TestCaseInfo>
  5512. makeTestCaseInfo( StringRef className,
  5513. NameAndTags const& nameAndTags,
  5514. SourceLineInfo const& lineInfo );
  5515. }
  5516. #ifdef __clang__
  5517. #pragma clang diagnostic pop
  5518. #endif
  5519. #endif // CATCH_TEST_CASE_INFO_HPP_INCLUDED
  5520. #ifndef CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5521. #define CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5522. #ifndef CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5523. #define CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5524. #include <string>
  5525. #include <vector>
  5526. namespace Catch {
  5527. using exceptionTranslateFunction = std::string(*)();
  5528. class IExceptionTranslator;
  5529. using ExceptionTranslators = std::vector<Detail::unique_ptr<IExceptionTranslator const>>;
  5530. class IExceptionTranslator {
  5531. public:
  5532. virtual ~IExceptionTranslator(); // = default
  5533. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  5534. };
  5535. class IExceptionTranslatorRegistry {
  5536. public:
  5537. virtual ~IExceptionTranslatorRegistry(); // = default
  5538. virtual std::string translateActiveException() const = 0;
  5539. };
  5540. } // namespace Catch
  5541. #endif // CATCH_INTERFACES_EXCEPTION_HPP_INCLUDED
  5542. #include <exception>
  5543. namespace Catch {
  5544. class ExceptionTranslatorRegistrar {
  5545. template<typename T>
  5546. class ExceptionTranslator : public IExceptionTranslator {
  5547. public:
  5548. ExceptionTranslator( std::string(*translateFunction)( T const& ) )
  5549. : m_translateFunction( translateFunction )
  5550. {}
  5551. std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
  5552. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  5553. try {
  5554. if( it == itEnd )
  5555. std::rethrow_exception(std::current_exception());
  5556. else
  5557. return (*it)->translate( it+1, itEnd );
  5558. }
  5559. catch( T const& ex ) {
  5560. return m_translateFunction( ex );
  5561. }
  5562. #else
  5563. return "You should never get here!";
  5564. #endif
  5565. }
  5566. protected:
  5567. std::string(*m_translateFunction)( T const& );
  5568. };
  5569. public:
  5570. template<typename T>
  5571. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T const& ) ) {
  5572. getMutableRegistryHub().registerTranslator(
  5573. Detail::make_unique<ExceptionTranslator<T>>(translateFunction)
  5574. );
  5575. }
  5576. };
  5577. } // namespace Catch
  5578. ///////////////////////////////////////////////////////////////////////////////
  5579. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  5580. static std::string translatorName( signature ); \
  5581. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  5582. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  5583. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
  5584. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
  5585. static std::string translatorName( signature )
  5586. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  5587. #if defined(CATCH_CONFIG_DISABLE)
  5588. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
  5589. static std::string translatorName( signature )
  5590. #endif
  5591. // This macro is always prefixed
  5592. #if !defined(CATCH_CONFIG_DISABLE)
  5593. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  5594. #else
  5595. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  5596. #endif
  5597. #endif // CATCH_TRANSLATE_EXCEPTION_HPP_INCLUDED
  5598. #ifndef CATCH_VERSION_HPP_INCLUDED
  5599. #define CATCH_VERSION_HPP_INCLUDED
  5600. #include <iosfwd>
  5601. namespace Catch {
  5602. // Versioning information
  5603. struct Version {
  5604. Version( Version const& ) = delete;
  5605. Version& operator=( Version const& ) = delete;
  5606. Version( unsigned int _majorVersion,
  5607. unsigned int _minorVersion,
  5608. unsigned int _patchNumber,
  5609. char const * const _branchName,
  5610. unsigned int _buildNumber );
  5611. unsigned int const majorVersion;
  5612. unsigned int const minorVersion;
  5613. unsigned int const patchNumber;
  5614. // buildNumber is only used if branchName is not null
  5615. char const * const branchName;
  5616. unsigned int const buildNumber;
  5617. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5618. };
  5619. Version const& libraryVersion();
  5620. }
  5621. #endif // CATCH_VERSION_HPP_INCLUDED
  5622. #ifndef CATCH_VERSION_MACROS_HPP_INCLUDED
  5623. #define CATCH_VERSION_MACROS_HPP_INCLUDED
  5624. #define CATCH_VERSION_MAJOR 3
  5625. #define CATCH_VERSION_MINOR 1
  5626. #define CATCH_VERSION_PATCH 1
  5627. #endif // CATCH_VERSION_MACROS_HPP_INCLUDED
  5628. /** \file
  5629. * This is a convenience header for Catch2's Generator support. It includes
  5630. * **all** of Catch2 headers related to generators.
  5631. *
  5632. * Generally the Catch2 users should use specific includes they need,
  5633. * but this header can be used instead for ease-of-experimentation, or
  5634. * just plain convenience, at the cost of (significantly) increased
  5635. * compilation times.
  5636. *
  5637. * When a new header is added to either the `generators` folder,
  5638. * or to the corresponding internal subfolder, it should be added here.
  5639. */
  5640. #ifndef CATCH_GENERATORS_ALL_HPP_INCLUDED
  5641. #define CATCH_GENERATORS_ALL_HPP_INCLUDED
  5642. #ifndef CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5643. #define CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5644. #include <exception>
  5645. namespace Catch {
  5646. // Exception type to be thrown when a Generator runs into an error,
  5647. // e.g. it cannot initialize the first return value based on
  5648. // runtime information
  5649. class GeneratorException : public std::exception {
  5650. const char* const m_msg = "";
  5651. public:
  5652. GeneratorException(const char* msg):
  5653. m_msg(msg)
  5654. {}
  5655. const char* what() const noexcept override final;
  5656. };
  5657. } // end namespace Catch
  5658. #endif // CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED
  5659. #ifndef CATCH_GENERATORS_HPP_INCLUDED
  5660. #define CATCH_GENERATORS_HPP_INCLUDED
  5661. #ifndef CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5662. #define CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5663. #include <string>
  5664. namespace Catch {
  5665. namespace Generators {
  5666. class GeneratorUntypedBase {
  5667. // Caches result from `toStringImpl`, assume that when it is an
  5668. // empty string, the cache is invalidated.
  5669. mutable std::string m_stringReprCache;
  5670. // Counts based on `next` returning true
  5671. std::size_t m_currentElementIndex = 0;
  5672. /**
  5673. * Attempts to move the generator to the next element
  5674. *
  5675. * Returns true iff the move succeeded (and a valid element
  5676. * can be retrieved).
  5677. */
  5678. virtual bool next() = 0;
  5679. //! Customization point for `currentElementAsString`
  5680. virtual std::string stringifyImpl() const = 0;
  5681. public:
  5682. GeneratorUntypedBase() = default;
  5683. // Generation of copy ops is deprecated (and Clang will complain)
  5684. // if there is a user destructor defined
  5685. GeneratorUntypedBase(GeneratorUntypedBase const&) = default;
  5686. GeneratorUntypedBase& operator=(GeneratorUntypedBase const&) = default;
  5687. virtual ~GeneratorUntypedBase(); // = default;
  5688. /**
  5689. * Attempts to move the generator to the next element
  5690. *
  5691. * Serves as a non-virtual interface to `next`, so that the
  5692. * top level interface can provide sanity checking and shared
  5693. * features.
  5694. *
  5695. * As with `next`, returns true iff the move succeeded and
  5696. * the generator has new valid element to provide.
  5697. */
  5698. bool countedNext();
  5699. std::size_t currentElementIndex() const { return m_currentElementIndex; }
  5700. /**
  5701. * Returns generator's current element as user-friendly string.
  5702. *
  5703. * By default returns string equivalent to calling
  5704. * `Catch::Detail::stringify` on the current element, but generators
  5705. * can customize their implementation as needed.
  5706. *
  5707. * Not thread-safe due to internal caching.
  5708. *
  5709. * The returned ref is valid only until the generator instance
  5710. * is destructed, or it moves onto the next element, whichever
  5711. * comes first.
  5712. */
  5713. StringRef currentElementAsString() const;
  5714. };
  5715. using GeneratorBasePtr = Catch::Detail::unique_ptr<GeneratorUntypedBase>;
  5716. } // namespace Generators
  5717. class IGeneratorTracker {
  5718. public:
  5719. virtual ~IGeneratorTracker(); // = default;
  5720. virtual auto hasGenerator() const -> bool = 0;
  5721. virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0;
  5722. virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0;
  5723. };
  5724. } // namespace Catch
  5725. #endif // CATCH_INTERFACES_GENERATORTRACKER_HPP_INCLUDED
  5726. #include <vector>
  5727. #include <tuple>
  5728. namespace Catch {
  5729. namespace Generators {
  5730. namespace Detail {
  5731. //! Throws GeneratorException with the provided message
  5732. [[noreturn]]
  5733. void throw_generator_exception(char const * msg);
  5734. } // end namespace detail
  5735. template<typename T>
  5736. class IGenerator : public GeneratorUntypedBase {
  5737. std::string stringifyImpl() const override {
  5738. return ::Catch::Detail::stringify( get() );
  5739. }
  5740. public:
  5741. ~IGenerator() override = default;
  5742. IGenerator() = default;
  5743. IGenerator(IGenerator const&) = default;
  5744. IGenerator& operator=(IGenerator const&) = default;
  5745. // Returns the current element of the generator
  5746. //
  5747. // \Precondition The generator is either freshly constructed,
  5748. // or the last call to `next()` returned true
  5749. virtual T const& get() const = 0;
  5750. using type = T;
  5751. };
  5752. template <typename T>
  5753. using GeneratorPtr = Catch::Detail::unique_ptr<IGenerator<T>>;
  5754. template <typename T>
  5755. class GeneratorWrapper final {
  5756. GeneratorPtr<T> m_generator;
  5757. public:
  5758. //! Takes ownership of the passed pointer.
  5759. GeneratorWrapper(IGenerator<T>* generator):
  5760. m_generator(generator) {}
  5761. GeneratorWrapper(GeneratorPtr<T> generator):
  5762. m_generator(CATCH_MOVE(generator)) {}
  5763. T const& get() const {
  5764. return m_generator->get();
  5765. }
  5766. bool next() {
  5767. return m_generator->countedNext();
  5768. }
  5769. };
  5770. template<typename T>
  5771. class SingleValueGenerator final : public IGenerator<T> {
  5772. T m_value;
  5773. public:
  5774. SingleValueGenerator(T const& value) :
  5775. m_value(value)
  5776. {}
  5777. SingleValueGenerator(T&& value):
  5778. m_value(CATCH_MOVE(value))
  5779. {}
  5780. T const& get() const override {
  5781. return m_value;
  5782. }
  5783. bool next() override {
  5784. return false;
  5785. }
  5786. };
  5787. template<typename T>
  5788. class FixedValuesGenerator final : public IGenerator<T> {
  5789. static_assert(!std::is_same<T, bool>::value,
  5790. "FixedValuesGenerator does not support bools because of std::vector<bool>"
  5791. "specialization, use SingleValue Generator instead.");
  5792. std::vector<T> m_values;
  5793. size_t m_idx = 0;
  5794. public:
  5795. FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {}
  5796. T const& get() const override {
  5797. return m_values[m_idx];
  5798. }
  5799. bool next() override {
  5800. ++m_idx;
  5801. return m_idx < m_values.size();
  5802. }
  5803. };
  5804. template <typename T, typename DecayedT = std::decay_t<T>>
  5805. GeneratorWrapper<DecayedT> value( T&& value ) {
  5806. return GeneratorWrapper<DecayedT>(
  5807. Catch::Detail::make_unique<SingleValueGenerator<DecayedT>>(
  5808. CATCH_FORWARD( value ) ) );
  5809. }
  5810. template <typename T>
  5811. GeneratorWrapper<T> values(std::initializer_list<T> values) {
  5812. return GeneratorWrapper<T>(Catch::Detail::make_unique<FixedValuesGenerator<T>>(values));
  5813. }
  5814. template<typename T>
  5815. class Generators : public IGenerator<T> {
  5816. std::vector<GeneratorWrapper<T>> m_generators;
  5817. size_t m_current = 0;
  5818. void add_generator( GeneratorWrapper<T>&& generator ) {
  5819. m_generators.emplace_back( CATCH_MOVE( generator ) );
  5820. }
  5821. void add_generator( T const& val ) {
  5822. m_generators.emplace_back( value( val ) );
  5823. }
  5824. void add_generator( T&& val ) {
  5825. m_generators.emplace_back( value( CATCH_MOVE( val ) ) );
  5826. }
  5827. template <typename U>
  5828. std::enable_if_t<!std::is_same<std::decay_t<U>, T>::value>
  5829. add_generator( U&& val ) {
  5830. add_generator( T( CATCH_FORWARD( val ) ) );
  5831. }
  5832. template <typename U> void add_generators( U&& valueOrGenerator ) {
  5833. add_generator( CATCH_FORWARD( valueOrGenerator ) );
  5834. }
  5835. template <typename U, typename... Gs>
  5836. void add_generators( U&& valueOrGenerator, Gs&&... moreGenerators ) {
  5837. add_generator( CATCH_FORWARD( valueOrGenerator ) );
  5838. add_generators( CATCH_FORWARD( moreGenerators )... );
  5839. }
  5840. public:
  5841. template <typename... Gs>
  5842. Generators(Gs &&... moreGenerators) {
  5843. m_generators.reserve(sizeof...(Gs));
  5844. add_generators(CATCH_FORWARD(moreGenerators)...);
  5845. }
  5846. T const& get() const override {
  5847. return m_generators[m_current].get();
  5848. }
  5849. bool next() override {
  5850. if (m_current >= m_generators.size()) {
  5851. return false;
  5852. }
  5853. const bool current_status = m_generators[m_current].next();
  5854. if (!current_status) {
  5855. ++m_current;
  5856. }
  5857. return m_current < m_generators.size();
  5858. }
  5859. };
  5860. template <typename... Ts>
  5861. GeneratorWrapper<std::tuple<std::decay_t<Ts>...>>
  5862. table( std::initializer_list<std::tuple<std::decay_t<Ts>...>> tuples ) {
  5863. return values<std::tuple<Ts...>>( tuples );
  5864. }
  5865. // Tag type to signal that a generator sequence should convert arguments to a specific type
  5866. template <typename T>
  5867. struct as {};
  5868. template<typename T, typename... Gs>
  5869. auto makeGenerators( GeneratorWrapper<T>&& generator, Gs &&... moreGenerators ) -> Generators<T> {
  5870. return Generators<T>(CATCH_MOVE(generator), CATCH_FORWARD(moreGenerators)...);
  5871. }
  5872. template<typename T>
  5873. auto makeGenerators( GeneratorWrapper<T>&& generator ) -> Generators<T> {
  5874. return Generators<T>(CATCH_MOVE(generator));
  5875. }
  5876. template<typename T, typename... Gs>
  5877. auto makeGenerators( T&& val, Gs &&... moreGenerators ) -> Generators<std::decay_t<T>> {
  5878. return makeGenerators( value( CATCH_FORWARD( val ) ), CATCH_FORWARD( moreGenerators )... );
  5879. }
  5880. template<typename T, typename U, typename... Gs>
  5881. auto makeGenerators( as<T>, U&& val, Gs &&... moreGenerators ) -> Generators<T> {
  5882. return makeGenerators( value( T( CATCH_FORWARD( val ) ) ), CATCH_FORWARD( moreGenerators )... );
  5883. }
  5884. auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker&;
  5885. template<typename L>
  5886. // Note: The type after -> is weird, because VS2015 cannot parse
  5887. // the expression used in the typedef inside, when it is in
  5888. // return type. Yeah.
  5889. auto generate( StringRef generatorName, SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>().get()) {
  5890. using UnderlyingType = typename decltype(generatorExpression())::type;
  5891. IGeneratorTracker& tracker = acquireGeneratorTracker( generatorName, lineInfo );
  5892. if (!tracker.hasGenerator()) {
  5893. tracker.setGenerator(Catch::Detail::make_unique<Generators<UnderlyingType>>(generatorExpression()));
  5894. }
  5895. auto const& generator = static_cast<IGenerator<UnderlyingType> const&>( *tracker.getGenerator() );
  5896. return generator.get();
  5897. }
  5898. } // namespace Generators
  5899. } // namespace Catch
  5900. #define GENERATE( ... ) \
  5901. Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  5902. CATCH_INTERNAL_LINEINFO, \
  5903. [ ]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  5904. #define GENERATE_COPY( ... ) \
  5905. Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  5906. CATCH_INTERNAL_LINEINFO, \
  5907. [=]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  5908. #define GENERATE_REF( ... ) \
  5909. Catch::Generators::generate( INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_UNIQUE_NAME(generator)), \
  5910. CATCH_INTERNAL_LINEINFO, \
  5911. [&]{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } ) //NOLINT(google-build-using-namespace)
  5912. #endif // CATCH_GENERATORS_HPP_INCLUDED
  5913. #ifndef CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  5914. #define CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  5915. #include <cassert>
  5916. namespace Catch {
  5917. namespace Generators {
  5918. template <typename T>
  5919. class TakeGenerator final : public IGenerator<T> {
  5920. GeneratorWrapper<T> m_generator;
  5921. size_t m_returned = 0;
  5922. size_t m_target;
  5923. public:
  5924. TakeGenerator(size_t target, GeneratorWrapper<T>&& generator):
  5925. m_generator(CATCH_MOVE(generator)),
  5926. m_target(target)
  5927. {
  5928. assert(target != 0 && "Empty generators are not allowed");
  5929. }
  5930. T const& get() const override {
  5931. return m_generator.get();
  5932. }
  5933. bool next() override {
  5934. ++m_returned;
  5935. if (m_returned >= m_target) {
  5936. return false;
  5937. }
  5938. const auto success = m_generator.next();
  5939. // If the underlying generator does not contain enough values
  5940. // then we cut short as well
  5941. if (!success) {
  5942. m_returned = m_target;
  5943. }
  5944. return success;
  5945. }
  5946. };
  5947. template <typename T>
  5948. GeneratorWrapper<T> take(size_t target, GeneratorWrapper<T>&& generator) {
  5949. return GeneratorWrapper<T>(Catch::Detail::make_unique<TakeGenerator<T>>(target, CATCH_MOVE(generator)));
  5950. }
  5951. template <typename T, typename Predicate>
  5952. class FilterGenerator final : public IGenerator<T> {
  5953. GeneratorWrapper<T> m_generator;
  5954. Predicate m_predicate;
  5955. public:
  5956. template <typename P = Predicate>
  5957. FilterGenerator(P&& pred, GeneratorWrapper<T>&& generator):
  5958. m_generator(CATCH_MOVE(generator)),
  5959. m_predicate(CATCH_FORWARD(pred))
  5960. {
  5961. if (!m_predicate(m_generator.get())) {
  5962. // It might happen that there are no values that pass the
  5963. // filter. In that case we throw an exception.
  5964. auto has_initial_value = next();
  5965. if (!has_initial_value) {
  5966. Detail::throw_generator_exception("No valid value found in filtered generator");
  5967. }
  5968. }
  5969. }
  5970. T const& get() const override {
  5971. return m_generator.get();
  5972. }
  5973. bool next() override {
  5974. bool success = m_generator.next();
  5975. if (!success) {
  5976. return false;
  5977. }
  5978. while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true);
  5979. return success;
  5980. }
  5981. };
  5982. template <typename T, typename Predicate>
  5983. GeneratorWrapper<T> filter(Predicate&& pred, GeneratorWrapper<T>&& generator) {
  5984. return GeneratorWrapper<T>(Catch::Detail::make_unique<FilterGenerator<T, Predicate>>(CATCH_FORWARD(pred), CATCH_MOVE(generator)));
  5985. }
  5986. template <typename T>
  5987. class RepeatGenerator final : public IGenerator<T> {
  5988. static_assert(!std::is_same<T, bool>::value,
  5989. "RepeatGenerator currently does not support bools"
  5990. "because of std::vector<bool> specialization");
  5991. GeneratorWrapper<T> m_generator;
  5992. mutable std::vector<T> m_returned;
  5993. size_t m_target_repeats;
  5994. size_t m_current_repeat = 0;
  5995. size_t m_repeat_index = 0;
  5996. public:
  5997. RepeatGenerator(size_t repeats, GeneratorWrapper<T>&& generator):
  5998. m_generator(CATCH_MOVE(generator)),
  5999. m_target_repeats(repeats)
  6000. {
  6001. assert(m_target_repeats > 0 && "Repeat generator must repeat at least once");
  6002. }
  6003. T const& get() const override {
  6004. if (m_current_repeat == 0) {
  6005. m_returned.push_back(m_generator.get());
  6006. return m_returned.back();
  6007. }
  6008. return m_returned[m_repeat_index];
  6009. }
  6010. bool next() override {
  6011. // There are 2 basic cases:
  6012. // 1) We are still reading the generator
  6013. // 2) We are reading our own cache
  6014. // In the first case, we need to poke the underlying generator.
  6015. // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache
  6016. if (m_current_repeat == 0) {
  6017. const auto success = m_generator.next();
  6018. if (!success) {
  6019. ++m_current_repeat;
  6020. }
  6021. return m_current_repeat < m_target_repeats;
  6022. }
  6023. // In the second case, we need to move indices forward and check that we haven't run up against the end
  6024. ++m_repeat_index;
  6025. if (m_repeat_index == m_returned.size()) {
  6026. m_repeat_index = 0;
  6027. ++m_current_repeat;
  6028. }
  6029. return m_current_repeat < m_target_repeats;
  6030. }
  6031. };
  6032. template <typename T>
  6033. GeneratorWrapper<T> repeat(size_t repeats, GeneratorWrapper<T>&& generator) {
  6034. return GeneratorWrapper<T>(Catch::Detail::make_unique<RepeatGenerator<T>>(repeats, CATCH_MOVE(generator)));
  6035. }
  6036. template <typename T, typename U, typename Func>
  6037. class MapGenerator final : public IGenerator<T> {
  6038. // TBD: provide static assert for mapping function, for friendly error message
  6039. GeneratorWrapper<U> m_generator;
  6040. Func m_function;
  6041. // To avoid returning dangling reference, we have to save the values
  6042. T m_cache;
  6043. public:
  6044. template <typename F2 = Func>
  6045. MapGenerator(F2&& function, GeneratorWrapper<U>&& generator) :
  6046. m_generator(CATCH_MOVE(generator)),
  6047. m_function(CATCH_FORWARD(function)),
  6048. m_cache(m_function(m_generator.get()))
  6049. {}
  6050. T const& get() const override {
  6051. return m_cache;
  6052. }
  6053. bool next() override {
  6054. const auto success = m_generator.next();
  6055. if (success) {
  6056. m_cache = m_function(m_generator.get());
  6057. }
  6058. return success;
  6059. }
  6060. };
  6061. template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
  6062. GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
  6063. return GeneratorWrapper<T>(
  6064. Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator))
  6065. );
  6066. }
  6067. template <typename T, typename U, typename Func>
  6068. GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
  6069. return GeneratorWrapper<T>(
  6070. Catch::Detail::make_unique<MapGenerator<T, U, Func>>(CATCH_FORWARD(function), CATCH_MOVE(generator))
  6071. );
  6072. }
  6073. template <typename T>
  6074. class ChunkGenerator final : public IGenerator<std::vector<T>> {
  6075. std::vector<T> m_chunk;
  6076. size_t m_chunk_size;
  6077. GeneratorWrapper<T> m_generator;
  6078. bool m_used_up = false;
  6079. public:
  6080. ChunkGenerator(size_t size, GeneratorWrapper<T> generator) :
  6081. m_chunk_size(size), m_generator(CATCH_MOVE(generator))
  6082. {
  6083. m_chunk.reserve(m_chunk_size);
  6084. if (m_chunk_size != 0) {
  6085. m_chunk.push_back(m_generator.get());
  6086. for (size_t i = 1; i < m_chunk_size; ++i) {
  6087. if (!m_generator.next()) {
  6088. Detail::throw_generator_exception("Not enough values to initialize the first chunk");
  6089. }
  6090. m_chunk.push_back(m_generator.get());
  6091. }
  6092. }
  6093. }
  6094. std::vector<T> const& get() const override {
  6095. return m_chunk;
  6096. }
  6097. bool next() override {
  6098. m_chunk.clear();
  6099. for (size_t idx = 0; idx < m_chunk_size; ++idx) {
  6100. if (!m_generator.next()) {
  6101. return false;
  6102. }
  6103. m_chunk.push_back(m_generator.get());
  6104. }
  6105. return true;
  6106. }
  6107. };
  6108. template <typename T>
  6109. GeneratorWrapper<std::vector<T>> chunk(size_t size, GeneratorWrapper<T>&& generator) {
  6110. return GeneratorWrapper<std::vector<T>>(
  6111. Catch::Detail::make_unique<ChunkGenerator<T>>(size, CATCH_MOVE(generator))
  6112. );
  6113. }
  6114. } // namespace Generators
  6115. } // namespace Catch
  6116. #endif // CATCH_GENERATORS_ADAPTERS_HPP_INCLUDED
  6117. #ifndef CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6118. #define CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6119. #ifndef CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6120. #define CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6121. #include <cstdint>
  6122. namespace Catch {
  6123. // This is a simple implementation of C++11 Uniform Random Number
  6124. // Generator. It does not provide all operators, because Catch2
  6125. // does not use it, but it should behave as expected inside stdlib's
  6126. // distributions.
  6127. // The implementation is based on the PCG family (http://pcg-random.org)
  6128. class SimplePcg32 {
  6129. using state_type = std::uint64_t;
  6130. public:
  6131. using result_type = std::uint32_t;
  6132. static constexpr result_type (min)() {
  6133. return 0;
  6134. }
  6135. static constexpr result_type (max)() {
  6136. return static_cast<result_type>(-1);
  6137. }
  6138. // Provide some default initial state for the default constructor
  6139. SimplePcg32():SimplePcg32(0xed743cc4U) {}
  6140. explicit SimplePcg32(result_type seed_);
  6141. void seed(result_type seed_);
  6142. void discard(uint64_t skip);
  6143. result_type operator()();
  6144. private:
  6145. friend bool operator==(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
  6146. friend bool operator!=(SimplePcg32 const& lhs, SimplePcg32 const& rhs);
  6147. // In theory we also need operator<< and operator>>
  6148. // In practice we do not use them, so we will skip them for now
  6149. std::uint64_t m_state;
  6150. // This part of the state determines which "stream" of the numbers
  6151. // is chosen -- we take it as a constant for Catch2, so we only
  6152. // need to deal with seeding the main state.
  6153. // Picked by reading 8 bytes from `/dev/random` :-)
  6154. static const std::uint64_t s_inc = (0x13ed0cc53f939476ULL << 1ULL) | 1ULL;
  6155. };
  6156. } // end namespace Catch
  6157. #endif // CATCH_RANDOM_NUMBER_GENERATOR_HPP_INCLUDED
  6158. #include <random>
  6159. namespace Catch {
  6160. namespace Generators {
  6161. namespace Detail {
  6162. // Returns a suitable seed for a random floating generator based off
  6163. // the primary internal rng. It does so by taking current value from
  6164. // the rng and returning it as the seed.
  6165. std::uint32_t getSeed();
  6166. }
  6167. template <typename Float>
  6168. class RandomFloatingGenerator final : public IGenerator<Float> {
  6169. Catch::SimplePcg32 m_rng;
  6170. std::uniform_real_distribution<Float> m_dist;
  6171. Float m_current_number;
  6172. public:
  6173. RandomFloatingGenerator( Float a, Float b, std::uint32_t seed ):
  6174. m_rng(seed),
  6175. m_dist(a, b) {
  6176. static_cast<void>(next());
  6177. }
  6178. Float const& get() const override {
  6179. return m_current_number;
  6180. }
  6181. bool next() override {
  6182. m_current_number = m_dist(m_rng);
  6183. return true;
  6184. }
  6185. };
  6186. template <typename Integer>
  6187. class RandomIntegerGenerator final : public IGenerator<Integer> {
  6188. Catch::SimplePcg32 m_rng;
  6189. std::uniform_int_distribution<Integer> m_dist;
  6190. Integer m_current_number;
  6191. public:
  6192. RandomIntegerGenerator( Integer a, Integer b, std::uint32_t seed ):
  6193. m_rng(seed),
  6194. m_dist(a, b) {
  6195. static_cast<void>(next());
  6196. }
  6197. Integer const& get() const override {
  6198. return m_current_number;
  6199. }
  6200. bool next() override {
  6201. m_current_number = m_dist(m_rng);
  6202. return true;
  6203. }
  6204. };
  6205. template <typename T>
  6206. std::enable_if_t<std::is_integral<T>::value, GeneratorWrapper<T>>
  6207. random(T a, T b) {
  6208. static_assert(
  6209. !std::is_same<T, char>::value &&
  6210. !std::is_same<T, int8_t>::value &&
  6211. !std::is_same<T, uint8_t>::value &&
  6212. !std::is_same<T, signed char>::value &&
  6213. !std::is_same<T, unsigned char>::value &&
  6214. !std::is_same<T, bool>::value,
  6215. "The requested type is not supported by the underlying random distributions from std" );
  6216. return GeneratorWrapper<T>(
  6217. Catch::Detail::make_unique<RandomIntegerGenerator<T>>(a, b, Detail::getSeed())
  6218. );
  6219. }
  6220. template <typename T>
  6221. std::enable_if_t<std::is_floating_point<T>::value,
  6222. GeneratorWrapper<T>>
  6223. random(T a, T b) {
  6224. return GeneratorWrapper<T>(
  6225. Catch::Detail::make_unique<RandomFloatingGenerator<T>>(a, b, Detail::getSeed())
  6226. );
  6227. }
  6228. } // namespace Generators
  6229. } // namespace Catch
  6230. #endif // CATCH_GENERATORS_RANDOM_HPP_INCLUDED
  6231. #ifndef CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6232. #define CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6233. #include <iterator>
  6234. #include <type_traits>
  6235. namespace Catch {
  6236. namespace Generators {
  6237. template <typename T>
  6238. class RangeGenerator final : public IGenerator<T> {
  6239. T m_current;
  6240. T m_end;
  6241. T m_step;
  6242. bool m_positive;
  6243. public:
  6244. RangeGenerator(T const& start, T const& end, T const& step):
  6245. m_current(start),
  6246. m_end(end),
  6247. m_step(step),
  6248. m_positive(m_step > T(0))
  6249. {
  6250. assert(m_current != m_end && "Range start and end cannot be equal");
  6251. assert(m_step != T(0) && "Step size cannot be zero");
  6252. assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end");
  6253. }
  6254. RangeGenerator(T const& start, T const& end):
  6255. RangeGenerator(start, end, (start < end) ? T(1) : T(-1))
  6256. {}
  6257. T const& get() const override {
  6258. return m_current;
  6259. }
  6260. bool next() override {
  6261. m_current += m_step;
  6262. return (m_positive) ? (m_current < m_end) : (m_current > m_end);
  6263. }
  6264. };
  6265. template <typename T>
  6266. GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
  6267. static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
  6268. return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end, step));
  6269. }
  6270. template <typename T>
  6271. GeneratorWrapper<T> range(T const& start, T const& end) {
  6272. static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer");
  6273. return GeneratorWrapper<T>(Catch::Detail::make_unique<RangeGenerator<T>>(start, end));
  6274. }
  6275. template <typename T>
  6276. class IteratorGenerator final : public IGenerator<T> {
  6277. static_assert(!std::is_same<T, bool>::value,
  6278. "IteratorGenerator currently does not support bools"
  6279. "because of std::vector<bool> specialization");
  6280. std::vector<T> m_elems;
  6281. size_t m_current = 0;
  6282. public:
  6283. template <typename InputIterator, typename InputSentinel>
  6284. IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) {
  6285. if (m_elems.empty()) {
  6286. Detail::throw_generator_exception("IteratorGenerator received no valid values");
  6287. }
  6288. }
  6289. T const& get() const override {
  6290. return m_elems[m_current];
  6291. }
  6292. bool next() override {
  6293. ++m_current;
  6294. return m_current != m_elems.size();
  6295. }
  6296. };
  6297. template <typename InputIterator,
  6298. typename InputSentinel,
  6299. typename ResultType = typename std::iterator_traits<InputIterator>::value_type>
  6300. GeneratorWrapper<ResultType> from_range(InputIterator from, InputSentinel to) {
  6301. return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(from, to));
  6302. }
  6303. template <typename Container,
  6304. typename ResultType = typename Container::value_type>
  6305. GeneratorWrapper<ResultType> from_range(Container const& cnt) {
  6306. return GeneratorWrapper<ResultType>(Catch::Detail::make_unique<IteratorGenerator<ResultType>>(cnt.begin(), cnt.end()));
  6307. }
  6308. } // namespace Generators
  6309. } // namespace Catch
  6310. #endif // CATCH_GENERATORS_RANGE_HPP_INCLUDED
  6311. #endif // CATCH_GENERATORS_ALL_HPP_INCLUDED
  6312. /** \file
  6313. * This is a convenience header for Catch2's interfaces. It includes
  6314. * **all** of Catch2 headers related to interfaces.
  6315. *
  6316. * Generally the Catch2 users should use specific includes they need,
  6317. * but this header can be used instead for ease-of-experimentation, or
  6318. * just plain convenience, at the cost of somewhat increased compilation
  6319. * times.
  6320. *
  6321. * When a new header is added to either the `interfaces` folder, or to
  6322. * the corresponding internal subfolder, it should be added here.
  6323. */
  6324. #ifndef CATCH_INTERFACES_ALL_HPP_INCLUDED
  6325. #define CATCH_INTERFACES_ALL_HPP_INCLUDED
  6326. #ifndef CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  6327. #define CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  6328. #include <string>
  6329. namespace Catch {
  6330. struct ReporterConfig;
  6331. class IConfig;
  6332. class IEventListener;
  6333. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  6334. class IReporterFactory {
  6335. public:
  6336. virtual ~IReporterFactory(); // = default
  6337. virtual IEventListenerPtr
  6338. create( ReporterConfig&& config ) const = 0;
  6339. virtual std::string getDescription() const = 0;
  6340. };
  6341. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  6342. class EventListenerFactory {
  6343. public:
  6344. virtual ~EventListenerFactory(); // = default
  6345. virtual IEventListenerPtr create( IConfig const* config ) const = 0;
  6346. //! Return a meaningful name for the listener, e.g. its type name
  6347. virtual StringRef getName() const = 0;
  6348. //! Return listener's description if available
  6349. virtual std::string getDescription() const = 0;
  6350. };
  6351. } // namespace Catch
  6352. #endif // CATCH_INTERFACES_REPORTER_FACTORY_HPP_INCLUDED
  6353. #ifndef CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
  6354. #define CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
  6355. #ifndef CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  6356. #define CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  6357. namespace Catch {
  6358. namespace Detail {
  6359. //! Provides case-insensitive `op<` semantics when called
  6360. struct CaseInsensitiveLess {
  6361. bool operator()( StringRef lhs,
  6362. StringRef rhs ) const;
  6363. };
  6364. //! Provides case-insensitive `op==` semantics when called
  6365. struct CaseInsensitiveEqualTo {
  6366. bool operator()( StringRef lhs,
  6367. StringRef rhs ) const;
  6368. };
  6369. } // namespace Detail
  6370. } // namespace Catch
  6371. #endif // CATCH_CASE_INSENSITIVE_COMPARISONS_HPP_INCLUDED
  6372. #include <string>
  6373. #include <vector>
  6374. #include <map>
  6375. namespace Catch {
  6376. class IConfig;
  6377. class IEventListener;
  6378. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  6379. class IReporterFactory;
  6380. using IReporterFactoryPtr = Detail::unique_ptr<IReporterFactory>;
  6381. struct ReporterConfig;
  6382. class EventListenerFactory;
  6383. class IReporterRegistry {
  6384. public:
  6385. using FactoryMap = std::map<std::string, IReporterFactoryPtr, Detail::CaseInsensitiveLess>;
  6386. using Listeners = std::vector<Detail::unique_ptr<EventListenerFactory>>;
  6387. virtual ~IReporterRegistry(); // = default
  6388. virtual IEventListenerPtr create( std::string const& name, ReporterConfig&& config ) const = 0;
  6389. virtual FactoryMap const& getFactories() const = 0;
  6390. virtual Listeners const& getListeners() const = 0;
  6391. };
  6392. } // end namespace Catch
  6393. #endif // CATCH_INTERFACES_REPORTER_REGISTRY_HPP_INCLUDED
  6394. #ifndef CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  6395. #define CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  6396. #include <string>
  6397. namespace Catch {
  6398. struct TagAlias;
  6399. class ITagAliasRegistry {
  6400. public:
  6401. virtual ~ITagAliasRegistry(); // = default
  6402. // Nullptr if not present
  6403. virtual TagAlias const* find( std::string const& alias ) const = 0;
  6404. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  6405. static ITagAliasRegistry const& get();
  6406. };
  6407. } // end namespace Catch
  6408. #endif // CATCH_INTERFACES_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  6409. #endif // CATCH_INTERFACES_ALL_HPP_INCLUDED
  6410. /** \file
  6411. * Wrapper for ANDROID_LOGWRITE configuration option
  6412. *
  6413. * We want to default to enabling it when compiled for android, but
  6414. * users of the library should also be able to disable it if they want
  6415. * to.
  6416. */
  6417. #ifndef CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  6418. #define CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  6419. #if defined(__ANDROID__)
  6420. # define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE
  6421. #endif
  6422. #if defined( CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE ) && \
  6423. !defined( CATCH_CONFIG_NO_ANDROID_LOGWRITE ) && \
  6424. !defined( CATCH_CONFIG_ANDROID_LOGWRITE )
  6425. # define CATCH_CONFIG_ANDROID_LOGWRITE
  6426. #endif
  6427. #endif // CATCH_CONFIG_ANDROID_LOGWRITE_HPP_INCLUDED
  6428. /** \file
  6429. * Wrapper for UNCAUGHT_EXCEPTIONS configuration option
  6430. *
  6431. * For some functionality, Catch2 requires to know whether there is
  6432. * an active exception. Because `std::uncaught_exception` is deprecated
  6433. * in C++17, we want to use `std::uncaught_exceptions` if possible.
  6434. */
  6435. #ifndef CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  6436. #define CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  6437. #if defined(_MSC_VER)
  6438. # if _MSC_VER >= 1900 // Visual Studio 2015 or newer
  6439. # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  6440. # endif
  6441. #endif
  6442. #include <exception>
  6443. #if defined(__cpp_lib_uncaught_exceptions) \
  6444. && !defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
  6445. # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  6446. #endif // __cpp_lib_uncaught_exceptions
  6447. #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) \
  6448. && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) \
  6449. && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
  6450. # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
  6451. #endif
  6452. #endif // CATCH_CONFIG_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  6453. #ifndef CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  6454. #define CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  6455. // This include must be kept so that user's configured value for CONSOLE_WIDTH
  6456. // is used before we attempt to provide a default value
  6457. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  6458. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  6459. #endif
  6460. #endif // CATCH_CONSOLE_WIDTH_HPP_INCLUDED
  6461. #ifndef CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  6462. #define CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  6463. #include <cstddef>
  6464. #include <initializer_list>
  6465. // We want a simple polyfill over `std::empty`, `std::size` and so on
  6466. // for C++14 or C++ libraries with incomplete support.
  6467. // We also have to handle that MSVC std lib will happily provide these
  6468. // under older standards.
  6469. #if defined(CATCH_CPP17_OR_GREATER) || defined(_MSC_VER)
  6470. // We are already using this header either way, so there shouldn't
  6471. // be much additional overhead in including it to get the feature
  6472. // test macros
  6473. #include <string>
  6474. # if !defined(__cpp_lib_nonmember_container_access)
  6475. # define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  6476. # endif
  6477. #else
  6478. #define CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  6479. #endif
  6480. namespace Catch {
  6481. namespace Detail {
  6482. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  6483. template <typename Container>
  6484. constexpr auto empty(Container const& cont) -> decltype(cont.empty()) {
  6485. return cont.empty();
  6486. }
  6487. template <typename T, std::size_t N>
  6488. constexpr bool empty(const T (&)[N]) noexcept {
  6489. // GCC < 7 does not support the const T(&)[] parameter syntax
  6490. // so we have to ignore the length explicitly
  6491. (void)N;
  6492. return false;
  6493. }
  6494. template <typename T>
  6495. constexpr bool empty(std::initializer_list<T> list) noexcept {
  6496. return list.size() > 0;
  6497. }
  6498. template <typename Container>
  6499. constexpr auto size(Container const& cont) -> decltype(cont.size()) {
  6500. return cont.size();
  6501. }
  6502. template <typename T, std::size_t N>
  6503. constexpr std::size_t size(const T(&)[N]) noexcept {
  6504. return N;
  6505. }
  6506. #endif // CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS
  6507. } // end namespace Detail
  6508. } // end namespace Catch
  6509. #endif // CATCH_CONTAINER_NONMEMBERS_HPP_INCLUDED
  6510. #ifndef CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  6511. #define CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  6512. #include <string>
  6513. namespace Catch {
  6514. void writeToDebugConsole( std::string const& text );
  6515. }
  6516. #endif // CATCH_DEBUG_CONSOLE_HPP_INCLUDED
  6517. #ifndef CATCH_DEBUGGER_HPP_INCLUDED
  6518. #define CATCH_DEBUGGER_HPP_INCLUDED
  6519. namespace Catch {
  6520. bool isDebuggerActive();
  6521. }
  6522. #ifdef CATCH_PLATFORM_MAC
  6523. #if defined(__i386__) || defined(__x86_64__)
  6524. #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
  6525. #elif defined(__aarch64__)
  6526. #define CATCH_TRAP() __asm__(".inst 0xd43e0000")
  6527. #endif
  6528. #elif defined(CATCH_PLATFORM_IPHONE)
  6529. // use inline assembler
  6530. #if defined(__i386__) || defined(__x86_64__)
  6531. #define CATCH_TRAP() __asm__("int $3")
  6532. #elif defined(__aarch64__)
  6533. #define CATCH_TRAP() __asm__(".inst 0xd4200000")
  6534. #elif defined(__arm__) && !defined(__thumb__)
  6535. #define CATCH_TRAP() __asm__(".inst 0xe7f001f0")
  6536. #elif defined(__arm__) && defined(__thumb__)
  6537. #define CATCH_TRAP() __asm__(".inst 0xde01")
  6538. #endif
  6539. #elif defined(CATCH_PLATFORM_LINUX)
  6540. // If we can use inline assembler, do it because this allows us to break
  6541. // directly at the location of the failing check instead of breaking inside
  6542. // raise() called from it, i.e. one stack frame below.
  6543. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  6544. #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
  6545. #else // Fall back to the generic way.
  6546. #include <signal.h>
  6547. #define CATCH_TRAP() raise(SIGTRAP)
  6548. #endif
  6549. #elif defined(_MSC_VER)
  6550. #define CATCH_TRAP() __debugbreak()
  6551. #elif defined(__MINGW32__)
  6552. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  6553. #define CATCH_TRAP() DebugBreak()
  6554. #endif
  6555. #ifndef CATCH_BREAK_INTO_DEBUGGER
  6556. #ifdef CATCH_TRAP
  6557. #define CATCH_BREAK_INTO_DEBUGGER() []{ if( Catch::isDebuggerActive() ) { CATCH_TRAP(); } }()
  6558. #else
  6559. #define CATCH_BREAK_INTO_DEBUGGER() []{}()
  6560. #endif
  6561. #endif
  6562. #endif // CATCH_DEBUGGER_HPP_INCLUDED
  6563. #ifndef CATCH_ENFORCE_HPP_INCLUDED
  6564. #define CATCH_ENFORCE_HPP_INCLUDED
  6565. #include <exception>
  6566. namespace Catch {
  6567. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  6568. template <typename Ex>
  6569. [[noreturn]]
  6570. void throw_exception(Ex const& e) {
  6571. throw e;
  6572. }
  6573. #else // ^^ Exceptions are enabled // Exceptions are disabled vv
  6574. [[noreturn]]
  6575. void throw_exception(std::exception const& e);
  6576. #endif
  6577. [[noreturn]]
  6578. void throw_logic_error(std::string const& msg);
  6579. [[noreturn]]
  6580. void throw_domain_error(std::string const& msg);
  6581. [[noreturn]]
  6582. void throw_runtime_error(std::string const& msg);
  6583. } // namespace Catch;
  6584. #define CATCH_MAKE_MSG(...) \
  6585. (Catch::ReusableStringStream() << __VA_ARGS__).str()
  6586. #define CATCH_INTERNAL_ERROR(...) \
  6587. Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
  6588. #define CATCH_ERROR(...) \
  6589. Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
  6590. #define CATCH_RUNTIME_ERROR(...) \
  6591. Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
  6592. #define CATCH_ENFORCE( condition, ... ) \
  6593. do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
  6594. #endif // CATCH_ENFORCE_HPP_INCLUDED
  6595. #ifndef CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  6596. #define CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  6597. #include <vector>
  6598. namespace Catch {
  6599. namespace Detail {
  6600. Catch::Detail::unique_ptr<EnumInfo> makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector<int> const& values );
  6601. class EnumValuesRegistry : public IMutableEnumValuesRegistry {
  6602. std::vector<Catch::Detail::unique_ptr<EnumInfo>> m_enumInfos;
  6603. EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector<int> const& values) override;
  6604. };
  6605. std::vector<StringRef> parseEnums( StringRef enums );
  6606. } // Detail
  6607. } // Catch
  6608. #endif // CATCH_ENUM_VALUES_REGISTRY_HPP_INCLUDED
  6609. #ifndef CATCH_ERRNO_GUARD_HPP_INCLUDED
  6610. #define CATCH_ERRNO_GUARD_HPP_INCLUDED
  6611. namespace Catch {
  6612. //! Simple RAII class that stores the value of `errno`
  6613. //! at construction and restores it at destruction.
  6614. class ErrnoGuard {
  6615. public:
  6616. // Keep these outlined to avoid dragging in macros from <cerrno>
  6617. ErrnoGuard();
  6618. ~ErrnoGuard();
  6619. private:
  6620. int m_oldErrno;
  6621. };
  6622. }
  6623. #endif // CATCH_ERRNO_GUARD_HPP_INCLUDED
  6624. #ifndef CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6625. #define CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6626. #include <vector>
  6627. #include <string>
  6628. namespace Catch {
  6629. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  6630. public:
  6631. ~ExceptionTranslatorRegistry() override;
  6632. void registerTranslator( Detail::unique_ptr<IExceptionTranslator>&& translator );
  6633. std::string translateActiveException() const override;
  6634. std::string tryTranslators() const;
  6635. private:
  6636. ExceptionTranslators m_translators;
  6637. };
  6638. }
  6639. #endif // CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6640. #ifndef CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  6641. #define CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  6642. #include <cassert>
  6643. namespace Catch {
  6644. /**
  6645. * Wrapper for platform-specific fatal error (signals/SEH) handlers
  6646. *
  6647. * Tries to be cooperative with other handlers, and not step over
  6648. * other handlers. This means that unknown structured exceptions
  6649. * are passed on, previous signal handlers are called, and so on.
  6650. *
  6651. * Can only be instantiated once, and assumes that once a signal
  6652. * is caught, the binary will end up terminating. Thus, there
  6653. */
  6654. class FatalConditionHandler {
  6655. bool m_started = false;
  6656. // Install/disengage implementation for specific platform.
  6657. // Should be if-defed to work on current platform, can assume
  6658. // engage-disengage 1:1 pairing.
  6659. void engage_platform();
  6660. void disengage_platform() noexcept;
  6661. public:
  6662. // Should also have platform-specific implementations as needed
  6663. FatalConditionHandler();
  6664. ~FatalConditionHandler();
  6665. void engage() {
  6666. assert(!m_started && "Handler cannot be installed twice.");
  6667. m_started = true;
  6668. engage_platform();
  6669. }
  6670. void disengage() noexcept {
  6671. assert(m_started && "Handler cannot be uninstalled without being installed first");
  6672. m_started = false;
  6673. disengage_platform();
  6674. }
  6675. };
  6676. //! Simple RAII guard for (dis)engaging the FatalConditionHandler
  6677. class FatalConditionHandlerGuard {
  6678. FatalConditionHandler* m_handler;
  6679. public:
  6680. FatalConditionHandlerGuard(FatalConditionHandler* handler):
  6681. m_handler(handler) {
  6682. m_handler->engage();
  6683. }
  6684. ~FatalConditionHandlerGuard() {
  6685. m_handler->disengage();
  6686. }
  6687. };
  6688. } // end namespace Catch
  6689. #endif // CATCH_FATAL_CONDITION_HANDLER_HPP_INCLUDED
  6690. #ifndef CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6691. #define CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6692. #ifndef CATCH_POLYFILLS_HPP_INCLUDED
  6693. #define CATCH_POLYFILLS_HPP_INCLUDED
  6694. namespace Catch {
  6695. bool isnan(float f);
  6696. bool isnan(double d);
  6697. }
  6698. #endif // CATCH_POLYFILLS_HPP_INCLUDED
  6699. #include <cassert>
  6700. #include <cmath>
  6701. #include <cstdint>
  6702. #include <utility>
  6703. #include <limits>
  6704. namespace Catch {
  6705. namespace Detail {
  6706. uint32_t convertToBits(float f);
  6707. uint64_t convertToBits(double d);
  6708. } // end namespace Detail
  6709. #if defined( __GNUC__ ) || defined( __clang__ )
  6710. # pragma GCC diagnostic push
  6711. // We do a bunch of direct compensations of floating point numbers,
  6712. // because we know what we are doing and actually do want the direct
  6713. // comparison behaviour.
  6714. # pragma GCC diagnostic ignored "-Wfloat-equal"
  6715. #endif
  6716. /**
  6717. * Calculates the ULP distance between two floating point numbers
  6718. *
  6719. * The ULP distance of two floating point numbers is the count of
  6720. * valid floating point numbers representable between them.
  6721. *
  6722. * There are some exceptions between how this function counts the
  6723. * distance, and the interpretation of the standard as implemented.
  6724. * by e.g. `nextafter`. For this function it always holds that:
  6725. * * `(x == y) => ulpDistance(x, y) == 0` (so `ulpDistance(-0, 0) == 0`)
  6726. * * `ulpDistance(maxFinite, INF) == 1`
  6727. * * `ulpDistance(x, -x) == 2 * ulpDistance(x, 0)`
  6728. *
  6729. * \pre `!isnan( lhs )`
  6730. * \pre `!isnan( rhs )`
  6731. * \pre floating point numbers are represented in IEEE-754 format
  6732. */
  6733. template <typename FP>
  6734. uint64_t ulpDistance( FP lhs, FP rhs ) {
  6735. assert( std::numeric_limits<FP>::is_iec559 &&
  6736. "ulpDistance assumes IEEE-754 format for floating point types" );
  6737. assert( !Catch::isnan( lhs ) &&
  6738. "Distance between NaN and number is not meaningful" );
  6739. assert( !Catch::isnan( rhs ) &&
  6740. "Distance between NaN and number is not meaningful" );
  6741. // We want X == Y to imply 0 ULP distance even if X and Y aren't
  6742. // bit-equal (-0 and 0), or X - Y != 0 (same sign infinities).
  6743. if ( lhs == rhs ) { return 0; }
  6744. // We need a properly typed positive zero for type inference.
  6745. static constexpr FP positive_zero{};
  6746. // We want to ensure that +/- 0 is always represented as positive zero
  6747. if ( lhs == positive_zero ) { lhs = positive_zero; }
  6748. if ( rhs == positive_zero ) { rhs = positive_zero; }
  6749. // If arguments have different signs, we can handle them by summing
  6750. // how far are they from 0 each.
  6751. if ( std::signbit( lhs ) != std::signbit( rhs ) ) {
  6752. return ulpDistance( std::abs( lhs ), positive_zero ) +
  6753. ulpDistance( std::abs( rhs ), positive_zero );
  6754. }
  6755. // When both lhs and rhs are of the same sign, we can just
  6756. // read the numbers bitwise as integers, and then subtract them
  6757. // (assuming IEEE).
  6758. uint64_t lc = Detail::convertToBits( lhs );
  6759. uint64_t rc = Detail::convertToBits( rhs );
  6760. // The ulp distance between two numbers is symmetric, so to avoid
  6761. // dealing with overflows we want the bigger converted number on the lhs
  6762. if ( lc < rc ) {
  6763. std::swap( lc, rc );
  6764. }
  6765. return lc - rc;
  6766. }
  6767. #if defined( __GNUC__ ) || defined( __clang__ )
  6768. # pragma GCC diagnostic pop
  6769. #endif
  6770. } // end namespace Catch
  6771. #endif // CATCH_FLOATING_POINT_HELPERS_HPP_INCLUDED
  6772. #ifndef CATCH_ISTREAM_HPP_INCLUDED
  6773. #define CATCH_ISTREAM_HPP_INCLUDED
  6774. #include <iosfwd>
  6775. #include <cstddef>
  6776. #include <ostream>
  6777. #include <string>
  6778. namespace Catch {
  6779. class IStream {
  6780. public:
  6781. virtual ~IStream(); // = default
  6782. virtual std::ostream& stream() = 0;
  6783. /**
  6784. * Best guess on whether the instance is writing to a console (e.g. via stdout/stderr)
  6785. *
  6786. * This is useful for e.g. Win32 colour support, because the Win32
  6787. * API manipulates console directly, unlike POSIX escape codes,
  6788. * that can be written anywhere.
  6789. *
  6790. * Due to variety of ways to change where the stdout/stderr is
  6791. * _actually_ being written, users should always assume that
  6792. * the answer might be wrong.
  6793. */
  6794. virtual bool isConsole() const { return false; }
  6795. };
  6796. /**
  6797. * Creates a stream wrapper that writes to specific file.
  6798. *
  6799. * Also recognizes 4 special filenames
  6800. * * `-` for stdout
  6801. * * `%stdout` for stdout
  6802. * * `%stderr` for stderr
  6803. * * `%debug` for platform specific debugging output
  6804. *
  6805. * \throws if passed an unrecognized %-prefixed stream
  6806. */
  6807. auto makeStream( std::string const& filename ) -> Detail::unique_ptr<IStream>;
  6808. }
  6809. #endif // CATCH_STREAM_HPP_INCLUDED
  6810. #ifndef CATCH_LEAK_DETECTOR_HPP_INCLUDED
  6811. #define CATCH_LEAK_DETECTOR_HPP_INCLUDED
  6812. namespace Catch {
  6813. struct LeakDetector {
  6814. LeakDetector();
  6815. ~LeakDetector();
  6816. };
  6817. }
  6818. #endif // CATCH_LEAK_DETECTOR_HPP_INCLUDED
  6819. #ifndef CATCH_LIST_HPP_INCLUDED
  6820. #define CATCH_LIST_HPP_INCLUDED
  6821. #include <set>
  6822. #include <string>
  6823. namespace Catch {
  6824. class IEventListener;
  6825. class Config;
  6826. struct ReporterDescription {
  6827. std::string name, description;
  6828. };
  6829. struct ListenerDescription {
  6830. StringRef name;
  6831. std::string description;
  6832. };
  6833. struct TagInfo {
  6834. void add(StringRef spelling);
  6835. std::string all() const;
  6836. std::set<StringRef> spellings;
  6837. std::size_t count = 0;
  6838. };
  6839. bool list( IEventListener& reporter, Config const& config );
  6840. } // end namespace Catch
  6841. #endif // CATCH_LIST_HPP_INCLUDED
  6842. #ifndef CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  6843. #define CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  6844. #include <cstdio>
  6845. #include <iosfwd>
  6846. #include <string>
  6847. namespace Catch {
  6848. class RedirectedStream {
  6849. std::ostream& m_originalStream;
  6850. std::ostream& m_redirectionStream;
  6851. std::streambuf* m_prevBuf;
  6852. public:
  6853. RedirectedStream( std::ostream& originalStream, std::ostream& redirectionStream );
  6854. ~RedirectedStream();
  6855. };
  6856. class RedirectedStdOut {
  6857. ReusableStringStream m_rss;
  6858. RedirectedStream m_cout;
  6859. public:
  6860. RedirectedStdOut();
  6861. auto str() const -> std::string;
  6862. };
  6863. // StdErr has two constituent streams in C++, std::cerr and std::clog
  6864. // This means that we need to redirect 2 streams into 1 to keep proper
  6865. // order of writes
  6866. class RedirectedStdErr {
  6867. ReusableStringStream m_rss;
  6868. RedirectedStream m_cerr;
  6869. RedirectedStream m_clog;
  6870. public:
  6871. RedirectedStdErr();
  6872. auto str() const -> std::string;
  6873. };
  6874. class RedirectedStreams {
  6875. public:
  6876. RedirectedStreams(RedirectedStreams const&) = delete;
  6877. RedirectedStreams& operator=(RedirectedStreams const&) = delete;
  6878. RedirectedStreams(RedirectedStreams&&) = delete;
  6879. RedirectedStreams& operator=(RedirectedStreams&&) = delete;
  6880. RedirectedStreams(std::string& redirectedCout, std::string& redirectedCerr);
  6881. ~RedirectedStreams();
  6882. private:
  6883. std::string& m_redirectedCout;
  6884. std::string& m_redirectedCerr;
  6885. RedirectedStdOut m_redirectedStdOut;
  6886. RedirectedStdErr m_redirectedStdErr;
  6887. };
  6888. #if defined(CATCH_CONFIG_NEW_CAPTURE)
  6889. // Windows's implementation of std::tmpfile is terrible (it tries
  6890. // to create a file inside system folder, thus requiring elevated
  6891. // privileges for the binary), so we have to use tmpnam(_s) and
  6892. // create the file ourselves there.
  6893. class TempFile {
  6894. public:
  6895. TempFile(TempFile const&) = delete;
  6896. TempFile& operator=(TempFile const&) = delete;
  6897. TempFile(TempFile&&) = delete;
  6898. TempFile& operator=(TempFile&&) = delete;
  6899. TempFile();
  6900. ~TempFile();
  6901. std::FILE* getFile();
  6902. std::string getContents();
  6903. private:
  6904. std::FILE* m_file = nullptr;
  6905. #if defined(_MSC_VER)
  6906. char m_buffer[L_tmpnam] = { 0 };
  6907. #endif
  6908. };
  6909. class OutputRedirect {
  6910. public:
  6911. OutputRedirect(OutputRedirect const&) = delete;
  6912. OutputRedirect& operator=(OutputRedirect const&) = delete;
  6913. OutputRedirect(OutputRedirect&&) = delete;
  6914. OutputRedirect& operator=(OutputRedirect&&) = delete;
  6915. OutputRedirect(std::string& stdout_dest, std::string& stderr_dest);
  6916. ~OutputRedirect();
  6917. private:
  6918. int m_originalStdout = -1;
  6919. int m_originalStderr = -1;
  6920. TempFile m_stdoutFile;
  6921. TempFile m_stderrFile;
  6922. std::string& m_stdoutDest;
  6923. std::string& m_stderrDest;
  6924. };
  6925. #endif
  6926. } // end namespace Catch
  6927. #endif // CATCH_OUTPUT_REDIRECT_HPP_INCLUDED
  6928. #ifndef CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6929. #define CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6930. #include <map>
  6931. namespace Catch {
  6932. class ReporterRegistry : public IReporterRegistry {
  6933. public:
  6934. ReporterRegistry();
  6935. ~ReporterRegistry() override; // = default, out of line to allow fwd decl
  6936. IEventListenerPtr create( std::string const& name, ReporterConfig&& config ) const override;
  6937. void registerReporter( std::string const& name, IReporterFactoryPtr factory );
  6938. void registerListener( Detail::unique_ptr<EventListenerFactory> factory );
  6939. FactoryMap const& getFactories() const override;
  6940. Listeners const& getListeners() const override;
  6941. private:
  6942. FactoryMap m_factories;
  6943. Listeners m_listeners;
  6944. };
  6945. }
  6946. #endif // CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6947. #ifndef CATCH_RUN_CONTEXT_HPP_INCLUDED
  6948. #define CATCH_RUN_CONTEXT_HPP_INCLUDED
  6949. #ifndef CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  6950. #define CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  6951. #include <string>
  6952. #include <vector>
  6953. namespace Catch {
  6954. namespace TestCaseTracking {
  6955. struct NameAndLocation {
  6956. std::string name;
  6957. SourceLineInfo location;
  6958. NameAndLocation( std::string const& _name, SourceLineInfo const& _location );
  6959. friend bool operator==(NameAndLocation const& lhs, NameAndLocation const& rhs) {
  6960. return lhs.name == rhs.name
  6961. && lhs.location == rhs.location;
  6962. }
  6963. };
  6964. class ITracker;
  6965. using ITrackerPtr = Catch::Detail::unique_ptr<ITracker>;
  6966. class ITracker {
  6967. NameAndLocation m_nameAndLocation;
  6968. using Children = std::vector<ITrackerPtr>;
  6969. protected:
  6970. enum CycleState {
  6971. NotStarted,
  6972. Executing,
  6973. ExecutingChildren,
  6974. NeedsAnotherRun,
  6975. CompletedSuccessfully,
  6976. Failed
  6977. };
  6978. ITracker* m_parent = nullptr;
  6979. Children m_children;
  6980. CycleState m_runState = NotStarted;
  6981. public:
  6982. ITracker( NameAndLocation const& nameAndLoc, ITracker* parent ):
  6983. m_nameAndLocation( nameAndLoc ),
  6984. m_parent( parent )
  6985. {}
  6986. // static queries
  6987. NameAndLocation const& nameAndLocation() const {
  6988. return m_nameAndLocation;
  6989. }
  6990. ITracker* parent() const {
  6991. return m_parent;
  6992. }
  6993. virtual ~ITracker(); // = default
  6994. // dynamic queries
  6995. //! Returns true if tracker run to completion (successfully or not)
  6996. virtual bool isComplete() const = 0;
  6997. //! Returns true if tracker run to completion succesfully
  6998. bool isSuccessfullyCompleted() const;
  6999. //! Returns true if tracker has started but hasn't been completed
  7000. bool isOpen() const;
  7001. //! Returns true iff tracker has started
  7002. bool hasStarted() const;
  7003. // actions
  7004. virtual void close() = 0; // Successfully complete
  7005. virtual void fail() = 0;
  7006. void markAsNeedingAnotherRun();
  7007. //! Register a nested ITracker
  7008. void addChild( ITrackerPtr&& child );
  7009. /**
  7010. * Returns ptr to specific child if register with this tracker.
  7011. *
  7012. * Returns nullptr if not found.
  7013. */
  7014. ITracker* findChild( NameAndLocation const& nameAndLocation );
  7015. //! Have any children been added?
  7016. bool hasChildren() const {
  7017. return !m_children.empty();
  7018. }
  7019. //! Marks tracker as executing a child, doing se recursively up the tree
  7020. void openChild();
  7021. /**
  7022. * Returns true if the instance is a section tracker
  7023. *
  7024. * Subclasses should override to true if they are, replaces RTTI
  7025. * for internal debug checks.
  7026. */
  7027. virtual bool isSectionTracker() const;
  7028. /**
  7029. * Returns true if the instance is a generator tracker
  7030. *
  7031. * Subclasses should override to true if they are, replaces RTTI
  7032. * for internal debug checks.
  7033. */
  7034. virtual bool isGeneratorTracker() const;
  7035. };
  7036. class TrackerContext {
  7037. enum RunState {
  7038. NotStarted,
  7039. Executing,
  7040. CompletedCycle
  7041. };
  7042. ITrackerPtr m_rootTracker;
  7043. ITracker* m_currentTracker = nullptr;
  7044. RunState m_runState = NotStarted;
  7045. public:
  7046. ITracker& startRun();
  7047. void endRun();
  7048. void startCycle();
  7049. void completeCycle();
  7050. bool completedCycle() const;
  7051. ITracker& currentTracker();
  7052. void setCurrentTracker( ITracker* tracker );
  7053. };
  7054. class TrackerBase : public ITracker {
  7055. protected:
  7056. TrackerContext& m_ctx;
  7057. public:
  7058. TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
  7059. bool isComplete() const override;
  7060. void open();
  7061. void close() override;
  7062. void fail() override;
  7063. private:
  7064. void moveToParent();
  7065. void moveToThis();
  7066. };
  7067. class SectionTracker : public TrackerBase {
  7068. std::vector<StringRef> m_filters;
  7069. std::string m_trimmed_name;
  7070. public:
  7071. SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
  7072. bool isSectionTracker() const override;
  7073. bool isComplete() const override;
  7074. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
  7075. void tryOpen();
  7076. void addInitialFilters( std::vector<std::string> const& filters );
  7077. void addNextFilters( std::vector<StringRef> const& filters );
  7078. //! Returns filters active in this tracker
  7079. std::vector<StringRef> const& getFilters() const;
  7080. //! Returns whitespace-trimmed name of the tracked section
  7081. StringRef trimmedName() const;
  7082. };
  7083. } // namespace TestCaseTracking
  7084. using TestCaseTracking::ITracker;
  7085. using TestCaseTracking::TrackerContext;
  7086. using TestCaseTracking::SectionTracker;
  7087. } // namespace Catch
  7088. #endif // CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  7089. #include <string>
  7090. namespace Catch {
  7091. class IMutableContext;
  7092. class IGeneratorTracker;
  7093. class IConfig;
  7094. ///////////////////////////////////////////////////////////////////////////
  7095. class RunContext : public IResultCapture {
  7096. public:
  7097. RunContext( RunContext const& ) = delete;
  7098. RunContext& operator =( RunContext const& ) = delete;
  7099. explicit RunContext( IConfig const* _config, IEventListenerPtr&& reporter );
  7100. ~RunContext() override;
  7101. Totals runTest(TestCaseHandle const& testCase);
  7102. public: // IResultCapture
  7103. // Assertion handlers
  7104. void handleExpr
  7105. ( AssertionInfo const& info,
  7106. ITransientExpression const& expr,
  7107. AssertionReaction& reaction ) override;
  7108. void handleMessage
  7109. ( AssertionInfo const& info,
  7110. ResultWas::OfType resultType,
  7111. StringRef message,
  7112. AssertionReaction& reaction ) override;
  7113. void handleUnexpectedExceptionNotThrown
  7114. ( AssertionInfo const& info,
  7115. AssertionReaction& reaction ) override;
  7116. void handleUnexpectedInflightException
  7117. ( AssertionInfo const& info,
  7118. std::string const& message,
  7119. AssertionReaction& reaction ) override;
  7120. void handleIncomplete
  7121. ( AssertionInfo const& info ) override;
  7122. void handleNonExpr
  7123. ( AssertionInfo const &info,
  7124. ResultWas::OfType resultType,
  7125. AssertionReaction &reaction ) override;
  7126. bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
  7127. void sectionEnded( SectionEndInfo const& endInfo ) override;
  7128. void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
  7129. auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
  7130. void benchmarkPreparing( StringRef name ) override;
  7131. void benchmarkStarting( BenchmarkInfo const& info ) override;
  7132. void benchmarkEnded( BenchmarkStats<> const& stats ) override;
  7133. void benchmarkFailed( StringRef error ) override;
  7134. void pushScopedMessage( MessageInfo const& message ) override;
  7135. void popScopedMessage( MessageInfo const& message ) override;
  7136. void emplaceUnscopedMessage( MessageBuilder const& builder ) override;
  7137. std::string getCurrentTestName() const override;
  7138. const AssertionResult* getLastResult() const override;
  7139. void exceptionEarlyReported() override;
  7140. void handleFatalErrorCondition( StringRef message ) override;
  7141. bool lastAssertionPassed() override;
  7142. void assertionPassed() override;
  7143. public:
  7144. // !TBD We need to do this another way!
  7145. bool aborting() const;
  7146. private:
  7147. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
  7148. void invokeActiveTestCase();
  7149. void resetAssertionInfo();
  7150. bool testForMissingAssertions( Counts& assertions );
  7151. void assertionEnded( AssertionResult const& result );
  7152. void reportExpr
  7153. ( AssertionInfo const &info,
  7154. ResultWas::OfType resultType,
  7155. ITransientExpression const *expr,
  7156. bool negated );
  7157. void populateReaction( AssertionReaction& reaction );
  7158. private:
  7159. void handleUnfinishedSections();
  7160. TestRunInfo m_runInfo;
  7161. IMutableContext& m_context;
  7162. TestCaseHandle const* m_activeTestCase = nullptr;
  7163. ITracker* m_testCaseTracker = nullptr;
  7164. Optional<AssertionResult> m_lastResult;
  7165. IConfig const* m_config;
  7166. Totals m_totals;
  7167. IEventListenerPtr m_reporter;
  7168. std::vector<MessageInfo> m_messages;
  7169. std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
  7170. AssertionInfo m_lastAssertionInfo;
  7171. std::vector<SectionEndInfo> m_unfinishedSections;
  7172. std::vector<ITracker*> m_activeSections;
  7173. TrackerContext m_trackerContext;
  7174. FatalConditionHandler m_fatalConditionhandler;
  7175. bool m_lastAssertionPassed = false;
  7176. bool m_shouldReportUnexpected = true;
  7177. bool m_includeSuccessfulResults;
  7178. };
  7179. void seedRng(IConfig const& config);
  7180. unsigned int rngSeed();
  7181. } // end namespace Catch
  7182. #endif // CATCH_RUN_CONTEXT_HPP_INCLUDED
  7183. #ifndef CATCH_SHARDING_HPP_INCLUDED
  7184. #define CATCH_SHARDING_HPP_INCLUDED
  7185. #include <cmath>
  7186. #include <algorithm>
  7187. namespace Catch {
  7188. template<typename Container>
  7189. Container createShard(Container const& container, std::size_t const shardCount, std::size_t const shardIndex) {
  7190. assert(shardCount > shardIndex);
  7191. if (shardCount == 1) {
  7192. return container;
  7193. }
  7194. const std::size_t totalTestCount = container.size();
  7195. const std::size_t shardSize = totalTestCount / shardCount;
  7196. const std::size_t leftoverTests = totalTestCount % shardCount;
  7197. const std::size_t startIndex = shardIndex * shardSize + (std::min)(shardIndex, leftoverTests);
  7198. const std::size_t endIndex = (shardIndex + 1) * shardSize + (std::min)(shardIndex + 1, leftoverTests);
  7199. auto startIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(startIndex));
  7200. auto endIterator = std::next(container.begin(), static_cast<std::ptrdiff_t>(endIndex));
  7201. return Container(startIterator, endIterator);
  7202. }
  7203. }
  7204. #endif // CATCH_SHARDING_HPP_INCLUDED
  7205. #ifndef CATCH_SINGLETONS_HPP_INCLUDED
  7206. #define CATCH_SINGLETONS_HPP_INCLUDED
  7207. namespace Catch {
  7208. struct ISingleton {
  7209. virtual ~ISingleton(); // = default
  7210. };
  7211. void addSingleton( ISingleton* singleton );
  7212. void cleanupSingletons();
  7213. template<typename SingletonImplT, typename InterfaceT = SingletonImplT, typename MutableInterfaceT = InterfaceT>
  7214. class Singleton : SingletonImplT, public ISingleton {
  7215. static auto getInternal() -> Singleton* {
  7216. static Singleton* s_instance = nullptr;
  7217. if( !s_instance ) {
  7218. s_instance = new Singleton;
  7219. addSingleton( s_instance );
  7220. }
  7221. return s_instance;
  7222. }
  7223. public:
  7224. static auto get() -> InterfaceT const& {
  7225. return *getInternal();
  7226. }
  7227. static auto getMutable() -> MutableInterfaceT& {
  7228. return *getInternal();
  7229. }
  7230. };
  7231. } // namespace Catch
  7232. #endif // CATCH_SINGLETONS_HPP_INCLUDED
  7233. #ifndef CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  7234. #define CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  7235. #include <vector>
  7236. #include <exception>
  7237. namespace Catch {
  7238. class StartupExceptionRegistry {
  7239. #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
  7240. public:
  7241. void add(std::exception_ptr const& exception) noexcept;
  7242. std::vector<std::exception_ptr> const& getExceptions() const noexcept;
  7243. private:
  7244. std::vector<std::exception_ptr> m_exceptions;
  7245. #endif
  7246. };
  7247. } // end namespace Catch
  7248. #endif // CATCH_STARTUP_EXCEPTION_REGISTRY_HPP_INCLUDED
  7249. #ifndef CATCH_STDSTREAMS_HPP_INCLUDED
  7250. #define CATCH_STDSTREAMS_HPP_INCLUDED
  7251. #include <iosfwd>
  7252. namespace Catch {
  7253. std::ostream& cout();
  7254. std::ostream& cerr();
  7255. std::ostream& clog();
  7256. } // namespace Catch
  7257. #endif
  7258. #ifndef CATCH_STRING_MANIP_HPP_INCLUDED
  7259. #define CATCH_STRING_MANIP_HPP_INCLUDED
  7260. #include <string>
  7261. #include <iosfwd>
  7262. #include <vector>
  7263. namespace Catch {
  7264. bool startsWith( std::string const& s, std::string const& prefix );
  7265. bool startsWith( StringRef s, char prefix );
  7266. bool endsWith( std::string const& s, std::string const& suffix );
  7267. bool endsWith( std::string const& s, char suffix );
  7268. bool contains( std::string const& s, std::string const& infix );
  7269. void toLowerInPlace( std::string& s );
  7270. std::string toLower( std::string const& s );
  7271. char toLower( char c );
  7272. //! Returns a new string without whitespace at the start/end
  7273. std::string trim( std::string const& str );
  7274. //! Returns a substring of the original ref without whitespace. Beware lifetimes!
  7275. StringRef trim(StringRef ref);
  7276. // !!! Be aware, returns refs into original string - make sure original string outlives them
  7277. std::vector<StringRef> splitStringRef( StringRef str, char delimiter );
  7278. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  7279. /**
  7280. * Helper for streaming a "count [maybe-plural-of-label]" human-friendly string
  7281. *
  7282. * Usage example:
  7283. * ```cpp
  7284. * std::cout << "Found " << pluralise(count, "error") << '\n';
  7285. * ```
  7286. *
  7287. * **Important:** The provided string must outlive the instance
  7288. */
  7289. class pluralise {
  7290. std::uint64_t m_count;
  7291. StringRef m_label;
  7292. public:
  7293. constexpr pluralise(std::uint64_t count, StringRef label):
  7294. m_count(count),
  7295. m_label(label)
  7296. {}
  7297. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  7298. };
  7299. }
  7300. #endif // CATCH_STRING_MANIP_HPP_INCLUDED
  7301. #ifndef CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7302. #define CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7303. #include <map>
  7304. #include <string>
  7305. namespace Catch {
  7306. struct SourceLineInfo;
  7307. class TagAliasRegistry : public ITagAliasRegistry {
  7308. public:
  7309. ~TagAliasRegistry() override;
  7310. TagAlias const* find( std::string const& alias ) const override;
  7311. std::string expandAliases( std::string const& unexpandedTestSpec ) const override;
  7312. void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
  7313. private:
  7314. std::map<std::string, TagAlias> m_registry;
  7315. };
  7316. } // end namespace Catch
  7317. #endif // CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7318. #ifndef CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED
  7319. #define CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED
  7320. #include <cstdint>
  7321. namespace Catch {
  7322. struct TestCaseInfo;
  7323. class TestCaseInfoHasher {
  7324. public:
  7325. using hash_t = std::uint64_t;
  7326. TestCaseInfoHasher( hash_t seed );
  7327. uint32_t operator()( TestCaseInfo const& t ) const;
  7328. private:
  7329. hash_t m_seed;
  7330. };
  7331. } // namespace Catch
  7332. #endif /* CATCH_TEST_CASE_INFO_HASHER_HPP_INCLUDED */
  7333. #ifndef CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  7334. #define CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  7335. #include <vector>
  7336. namespace Catch {
  7337. class TestCaseHandle;
  7338. class IConfig;
  7339. class TestSpec;
  7340. std::vector<TestCaseHandle> sortTests( IConfig const& config, std::vector<TestCaseHandle> const& unsortedTestCases );
  7341. bool isThrowSafe( TestCaseHandle const& testCase, IConfig const& config );
  7342. bool matchTest( TestCaseHandle const& testCase, TestSpec const& testSpec, IConfig const& config );
  7343. void enforceNoDuplicateTestCases( std::vector<TestCaseHandle> const& functions );
  7344. std::vector<TestCaseHandle> filterTests( std::vector<TestCaseHandle> const& testCases, TestSpec const& testSpec, IConfig const& config );
  7345. std::vector<TestCaseHandle> const& getAllTestCasesSorted( IConfig const& config );
  7346. class TestRegistry : public ITestCaseRegistry {
  7347. public:
  7348. ~TestRegistry() override = default;
  7349. void registerTest( Detail::unique_ptr<TestCaseInfo> testInfo, Detail::unique_ptr<ITestInvoker> testInvoker );
  7350. std::vector<TestCaseInfo*> const& getAllInfos() const override;
  7351. std::vector<TestCaseHandle> const& getAllTests() const override;
  7352. std::vector<TestCaseHandle> const& getAllTestsSorted( IConfig const& config ) const override;
  7353. private:
  7354. std::vector<Detail::unique_ptr<TestCaseInfo>> m_owned_test_infos;
  7355. // Keeps a materialized vector for `getAllInfos`.
  7356. // We should get rid of that eventually (see interface note)
  7357. std::vector<TestCaseInfo*> m_viewed_test_infos;
  7358. std::vector<Detail::unique_ptr<ITestInvoker>> m_invokers;
  7359. std::vector<TestCaseHandle> m_handles;
  7360. mutable TestRunOrder m_currentSortOrder = TestRunOrder::Declared;
  7361. mutable std::vector<TestCaseHandle> m_sortedFunctions;
  7362. };
  7363. ///////////////////////////////////////////////////////////////////////////
  7364. class TestInvokerAsFunction final : public ITestInvoker {
  7365. using TestType = void(*)();
  7366. TestType m_testAsFunction;
  7367. public:
  7368. TestInvokerAsFunction(TestType testAsFunction) noexcept:
  7369. m_testAsFunction(testAsFunction) {}
  7370. void invoke() const override;
  7371. };
  7372. ///////////////////////////////////////////////////////////////////////////
  7373. } // end namespace Catch
  7374. #endif // CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  7375. #ifndef CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  7376. #define CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  7377. #ifdef __clang__
  7378. #pragma clang diagnostic push
  7379. #pragma clang diagnostic ignored "-Wpadded"
  7380. #endif
  7381. #include <vector>
  7382. #include <string>
  7383. namespace Catch {
  7384. class ITagAliasRegistry;
  7385. class TestSpecParser {
  7386. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  7387. Mode m_mode = None;
  7388. Mode lastMode = None;
  7389. bool m_exclusion = false;
  7390. std::size_t m_pos = 0;
  7391. std::size_t m_realPatternPos = 0;
  7392. std::string m_arg;
  7393. std::string m_substring;
  7394. std::string m_patternName;
  7395. std::vector<std::size_t> m_escapeChars;
  7396. TestSpec::Filter m_currentFilter;
  7397. TestSpec m_testSpec;
  7398. ITagAliasRegistry const* m_tagAliases = nullptr;
  7399. public:
  7400. TestSpecParser( ITagAliasRegistry const& tagAliases );
  7401. TestSpecParser& parse( std::string const& arg );
  7402. TestSpec testSpec();
  7403. private:
  7404. bool visitChar( char c );
  7405. void startNewMode( Mode mode );
  7406. bool processNoneChar( char c );
  7407. void processNameChar( char c );
  7408. bool processOtherChar( char c );
  7409. void endMode();
  7410. void escape();
  7411. bool isControlChar( char c ) const;
  7412. void saveLastMode();
  7413. void revertBackToLastMode();
  7414. void addFilter();
  7415. bool separate();
  7416. // Handles common preprocessing of the pattern for name/tag patterns
  7417. std::string preprocessPattern();
  7418. // Adds the current pattern as a test name
  7419. void addNamePattern();
  7420. // Adds the current pattern as a tag
  7421. void addTagPattern();
  7422. inline void addCharToPattern(char c) {
  7423. m_substring += c;
  7424. m_patternName += c;
  7425. m_realPatternPos++;
  7426. }
  7427. };
  7428. TestSpec parseTestSpec( std::string const& arg );
  7429. } // namespace Catch
  7430. #ifdef __clang__
  7431. #pragma clang diagnostic pop
  7432. #endif
  7433. #endif // CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  7434. #ifndef CATCH_TEXTFLOW_HPP_INCLUDED
  7435. #define CATCH_TEXTFLOW_HPP_INCLUDED
  7436. #include <cassert>
  7437. #include <string>
  7438. #include <vector>
  7439. namespace Catch {
  7440. namespace TextFlow {
  7441. class Columns;
  7442. /**
  7443. * Represents a column of text with specific width and indentation
  7444. *
  7445. * When written out to a stream, it will perform linebreaking
  7446. * of the provided text so that the written lines fit within
  7447. * target width.
  7448. */
  7449. class Column {
  7450. // String to be written out
  7451. std::string m_string;
  7452. // Width of the column for linebreaking
  7453. size_t m_width = CATCH_CONFIG_CONSOLE_WIDTH - 1;
  7454. // Indentation of other lines (including first if initial indent is unset)
  7455. size_t m_indent = 0;
  7456. // Indentation of the first line
  7457. size_t m_initialIndent = std::string::npos;
  7458. public:
  7459. /**
  7460. * Iterates "lines" in `Column` and return sthem
  7461. */
  7462. class const_iterator {
  7463. friend Column;
  7464. struct EndTag {};
  7465. Column const& m_column;
  7466. // Where does the current line start?
  7467. size_t m_lineStart = 0;
  7468. // How long should the current line be?
  7469. size_t m_lineLength = 0;
  7470. // How far have we checked the string to iterate?
  7471. size_t m_parsedTo = 0;
  7472. // Should a '-' be appended to the line?
  7473. bool m_addHyphen = false;
  7474. const_iterator( Column const& column, EndTag ):
  7475. m_column( column ), m_lineStart( m_column.m_string.size() ) {}
  7476. // Calculates the length of the current line
  7477. void calcLength();
  7478. // Returns current indention width
  7479. size_t indentSize() const;
  7480. // Creates an indented and (optionally) suffixed string from
  7481. // current iterator position, indentation and length.
  7482. std::string addIndentAndSuffix( size_t position,
  7483. size_t length ) const;
  7484. public:
  7485. using difference_type = std::ptrdiff_t;
  7486. using value_type = std::string;
  7487. using pointer = value_type*;
  7488. using reference = value_type&;
  7489. using iterator_category = std::forward_iterator_tag;
  7490. explicit const_iterator( Column const& column );
  7491. std::string operator*() const;
  7492. const_iterator& operator++();
  7493. const_iterator operator++( int );
  7494. bool operator==( const_iterator const& other ) const {
  7495. return m_lineStart == other.m_lineStart && &m_column == &other.m_column;
  7496. }
  7497. bool operator!=( const_iterator const& other ) const {
  7498. return !operator==( other );
  7499. }
  7500. };
  7501. using iterator = const_iterator;
  7502. explicit Column( std::string const& text ): m_string( text ) {}
  7503. Column& width( size_t newWidth ) {
  7504. assert( newWidth > 0 );
  7505. m_width = newWidth;
  7506. return *this;
  7507. }
  7508. Column& indent( size_t newIndent ) {
  7509. m_indent = newIndent;
  7510. return *this;
  7511. }
  7512. Column& initialIndent( size_t newIndent ) {
  7513. m_initialIndent = newIndent;
  7514. return *this;
  7515. }
  7516. size_t width() const { return m_width; }
  7517. const_iterator begin() const { return const_iterator( *this ); }
  7518. const_iterator end() const { return { *this, const_iterator::EndTag{} }; }
  7519. friend std::ostream& operator<<( std::ostream& os,
  7520. Column const& col );
  7521. Columns operator+( Column const& other );
  7522. };
  7523. //! Creates a column that serves as an empty space of specific width
  7524. Column Spacer( size_t spaceWidth );
  7525. class Columns {
  7526. std::vector<Column> m_columns;
  7527. public:
  7528. class iterator {
  7529. friend Columns;
  7530. struct EndTag {};
  7531. std::vector<Column> const& m_columns;
  7532. std::vector<Column::const_iterator> m_iterators;
  7533. size_t m_activeIterators;
  7534. iterator( Columns const& columns, EndTag );
  7535. public:
  7536. using difference_type = std::ptrdiff_t;
  7537. using value_type = std::string;
  7538. using pointer = value_type*;
  7539. using reference = value_type&;
  7540. using iterator_category = std::forward_iterator_tag;
  7541. explicit iterator( Columns const& columns );
  7542. auto operator==( iterator const& other ) const -> bool {
  7543. return m_iterators == other.m_iterators;
  7544. }
  7545. auto operator!=( iterator const& other ) const -> bool {
  7546. return m_iterators != other.m_iterators;
  7547. }
  7548. std::string operator*() const;
  7549. iterator& operator++();
  7550. iterator operator++( int );
  7551. };
  7552. using const_iterator = iterator;
  7553. iterator begin() const { return iterator( *this ); }
  7554. iterator end() const { return { *this, iterator::EndTag() }; }
  7555. Columns& operator+=( Column const& col );
  7556. Columns operator+( Column const& col );
  7557. friend std::ostream& operator<<( std::ostream& os,
  7558. Columns const& cols );
  7559. };
  7560. } // namespace TextFlow
  7561. } // namespace Catch
  7562. #endif // CATCH_TEXTFLOW_HPP_INCLUDED
  7563. #ifndef CATCH_TO_STRING_HPP_INCLUDED
  7564. #define CATCH_TO_STRING_HPP_INCLUDED
  7565. #include <string>
  7566. namespace Catch {
  7567. template <typename T>
  7568. std::string to_string(T const& t) {
  7569. #if defined(CATCH_CONFIG_CPP11_TO_STRING)
  7570. return std::to_string(t);
  7571. #else
  7572. ReusableStringStream rss;
  7573. rss << t;
  7574. return rss.str();
  7575. #endif
  7576. }
  7577. } // end namespace Catch
  7578. #endif // CATCH_TO_STRING_HPP_INCLUDED
  7579. #ifndef CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7580. #define CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7581. namespace Catch {
  7582. bool uncaught_exceptions();
  7583. } // end namespace Catch
  7584. #endif // CATCH_UNCAUGHT_EXCEPTIONS_HPP_INCLUDED
  7585. #ifndef CATCH_XMLWRITER_HPP_INCLUDED
  7586. #define CATCH_XMLWRITER_HPP_INCLUDED
  7587. #include <iosfwd>
  7588. #include <vector>
  7589. namespace Catch {
  7590. enum class XmlFormatting {
  7591. None = 0x00,
  7592. Indent = 0x01,
  7593. Newline = 0x02,
  7594. };
  7595. XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs);
  7596. XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
  7597. /**
  7598. * Helper for XML-encoding text (escaping angle brackets, quotes, etc)
  7599. *
  7600. * Note: doesn't take ownership of passed strings, and thus the
  7601. * encoded string must outlive the encoding instance.
  7602. */
  7603. class XmlEncode {
  7604. public:
  7605. enum ForWhat { ForTextNodes, ForAttributes };
  7606. XmlEncode( StringRef str, ForWhat forWhat = ForTextNodes );
  7607. void encodeTo( std::ostream& os ) const;
  7608. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
  7609. private:
  7610. StringRef m_str;
  7611. ForWhat m_forWhat;
  7612. };
  7613. class XmlWriter {
  7614. public:
  7615. class ScopedElement {
  7616. public:
  7617. ScopedElement( XmlWriter* writer, XmlFormatting fmt );
  7618. ScopedElement( ScopedElement&& other ) noexcept;
  7619. ScopedElement& operator=( ScopedElement&& other ) noexcept;
  7620. ~ScopedElement();
  7621. ScopedElement&
  7622. writeText( StringRef text,
  7623. XmlFormatting fmt = XmlFormatting::Newline |
  7624. XmlFormatting::Indent );
  7625. ScopedElement& writeAttribute( StringRef name,
  7626. StringRef attribute );
  7627. template <typename T,
  7628. // Without this SFINAE, this overload is a better match
  7629. // for `std::string`, `char const*`, `char const[N]` args.
  7630. // While it would still work, it would cause code bloat
  7631. // and multiple iteration over the strings
  7632. typename = typename std::enable_if_t<
  7633. !std::is_convertible<T, StringRef>::value>>
  7634. ScopedElement& writeAttribute( StringRef name,
  7635. T const& attribute ) {
  7636. m_writer->writeAttribute( name, attribute );
  7637. return *this;
  7638. }
  7639. private:
  7640. XmlWriter* m_writer = nullptr;
  7641. XmlFormatting m_fmt;
  7642. };
  7643. XmlWriter( std::ostream& os );
  7644. ~XmlWriter();
  7645. XmlWriter( XmlWriter const& ) = delete;
  7646. XmlWriter& operator=( XmlWriter const& ) = delete;
  7647. XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  7648. ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  7649. XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
  7650. //! The attribute content is XML-encoded
  7651. XmlWriter& writeAttribute( StringRef name, StringRef attribute );
  7652. //! Writes the attribute as "true/false"
  7653. XmlWriter& writeAttribute( StringRef name, bool attribute );
  7654. //! The attribute content is XML-encoded
  7655. XmlWriter& writeAttribute( StringRef name, char const* attribute );
  7656. //! The attribute value must provide op<<(ostream&, T). The resulting
  7657. //! serialization is XML-encoded
  7658. template <typename T,
  7659. // Without this SFINAE, this overload is a better match
  7660. // for `std::string`, `char const*`, `char const[N]` args.
  7661. // While it would still work, it would cause code bloat
  7662. // and multiple iteration over the strings
  7663. typename = typename std::enable_if_t<
  7664. !std::is_convertible<T, StringRef>::value>>
  7665. XmlWriter& writeAttribute( StringRef name, T const& attribute ) {
  7666. ReusableStringStream rss;
  7667. rss << attribute;
  7668. return writeAttribute( name, rss.str() );
  7669. }
  7670. //! Writes escaped `text` in a element
  7671. XmlWriter& writeText( StringRef text,
  7672. XmlFormatting fmt = XmlFormatting::Newline |
  7673. XmlFormatting::Indent );
  7674. //! Writes XML comment as "<!-- text -->"
  7675. XmlWriter& writeComment( StringRef text,
  7676. XmlFormatting fmt = XmlFormatting::Newline |
  7677. XmlFormatting::Indent );
  7678. void writeStylesheetRef( StringRef url );
  7679. void ensureTagClosed();
  7680. private:
  7681. void applyFormatting(XmlFormatting fmt);
  7682. void writeDeclaration();
  7683. void newlineIfNecessary();
  7684. bool m_tagIsOpen = false;
  7685. bool m_needsNewline = false;
  7686. std::vector<std::string> m_tags;
  7687. std::string m_indent;
  7688. std::ostream& m_os;
  7689. };
  7690. }
  7691. #endif // CATCH_XMLWRITER_HPP_INCLUDED
  7692. /** \file
  7693. * This is a convenience header for Catch2's Matcher support. It includes
  7694. * **all** of Catch2 headers related to matchers.
  7695. *
  7696. * Generally the Catch2 users should use specific includes they need,
  7697. * but this header can be used instead for ease-of-experimentation, or
  7698. * just plain convenience, at the cost of increased compilation times.
  7699. *
  7700. * When a new header is added to either the `matchers` folder, or to
  7701. * the corresponding internal subfolder, it should be added here.
  7702. */
  7703. #ifndef CATCH_MATCHERS_ALL_HPP_INCLUDED
  7704. #define CATCH_MATCHERS_ALL_HPP_INCLUDED
  7705. #ifndef CATCH_MATCHERS_HPP_INCLUDED
  7706. #define CATCH_MATCHERS_HPP_INCLUDED
  7707. #ifndef CATCH_MATCHERS_IMPL_HPP_INCLUDED
  7708. #define CATCH_MATCHERS_IMPL_HPP_INCLUDED
  7709. namespace Catch {
  7710. template<typename ArgT, typename MatcherT>
  7711. class MatchExpr : public ITransientExpression {
  7712. ArgT && m_arg;
  7713. MatcherT const& m_matcher;
  7714. StringRef m_matcherString;
  7715. public:
  7716. MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef matcherString )
  7717. : ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose
  7718. m_arg( CATCH_FORWARD(arg) ),
  7719. m_matcher( matcher ),
  7720. m_matcherString( matcherString )
  7721. {}
  7722. void streamReconstructedExpression( std::ostream& os ) const override {
  7723. os << Catch::Detail::stringify( m_arg )
  7724. << ' '
  7725. << m_matcher.toString();
  7726. }
  7727. };
  7728. namespace Matchers {
  7729. template <typename ArgT>
  7730. class MatcherBase;
  7731. }
  7732. using StringMatcher = Matchers::MatcherBase<std::string>;
  7733. void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString );
  7734. template<typename ArgT, typename MatcherT>
  7735. auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr<ArgT, MatcherT> {
  7736. return MatchExpr<ArgT, MatcherT>( CATCH_FORWARD(arg), matcher, matcherString );
  7737. }
  7738. } // namespace Catch
  7739. ///////////////////////////////////////////////////////////////////////////////
  7740. #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
  7741. do { \
  7742. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  7743. INTERNAL_CATCH_TRY { \
  7744. catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
  7745. } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
  7746. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  7747. } while( false )
  7748. ///////////////////////////////////////////////////////////////////////////////
  7749. #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
  7750. do { \
  7751. Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  7752. if( catchAssertionHandler.allowThrows() ) \
  7753. try { \
  7754. static_cast<void>(__VA_ARGS__ ); \
  7755. catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
  7756. } \
  7757. catch( exceptionType const& ex ) { \
  7758. catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \
  7759. } \
  7760. catch( ... ) { \
  7761. catchAssertionHandler.handleUnexpectedInflightException(); \
  7762. } \
  7763. else \
  7764. catchAssertionHandler.handleThrowingCallSkipped(); \
  7765. INTERNAL_CATCH_REACT( catchAssertionHandler ) \
  7766. } while( false )
  7767. #endif // CATCH_MATCHERS_IMPL_HPP_INCLUDED
  7768. #include <string>
  7769. #include <vector>
  7770. namespace Catch {
  7771. namespace Matchers {
  7772. class MatcherUntypedBase {
  7773. public:
  7774. MatcherUntypedBase() = default;
  7775. MatcherUntypedBase(MatcherUntypedBase const&) = default;
  7776. MatcherUntypedBase(MatcherUntypedBase&&) = default;
  7777. MatcherUntypedBase& operator = (MatcherUntypedBase const&) = delete;
  7778. MatcherUntypedBase& operator = (MatcherUntypedBase&&) = delete;
  7779. std::string toString() const;
  7780. protected:
  7781. virtual ~MatcherUntypedBase(); // = default;
  7782. virtual std::string describe() const = 0;
  7783. mutable std::string m_cachedToString;
  7784. };
  7785. template<typename T>
  7786. class MatcherBase : public MatcherUntypedBase {
  7787. public:
  7788. virtual bool match( T const& arg ) const = 0;
  7789. };
  7790. namespace Detail {
  7791. template<typename ArgT>
  7792. class MatchAllOf final : public MatcherBase<ArgT> {
  7793. std::vector<MatcherBase<ArgT> const*> m_matchers;
  7794. public:
  7795. MatchAllOf() = default;
  7796. MatchAllOf(MatchAllOf const&) = delete;
  7797. MatchAllOf& operator=(MatchAllOf const&) = delete;
  7798. MatchAllOf(MatchAllOf&&) = default;
  7799. MatchAllOf& operator=(MatchAllOf&&) = default;
  7800. bool match( ArgT const& arg ) const override {
  7801. for( auto matcher : m_matchers ) {
  7802. if (!matcher->match(arg))
  7803. return false;
  7804. }
  7805. return true;
  7806. }
  7807. std::string describe() const override {
  7808. std::string description;
  7809. description.reserve( 4 + m_matchers.size()*32 );
  7810. description += "( ";
  7811. bool first = true;
  7812. for( auto matcher : m_matchers ) {
  7813. if( first )
  7814. first = false;
  7815. else
  7816. description += " and ";
  7817. description += matcher->toString();
  7818. }
  7819. description += " )";
  7820. return description;
  7821. }
  7822. friend MatchAllOf operator&& (MatchAllOf&& lhs, MatcherBase<ArgT> const& rhs) {
  7823. lhs.m_matchers.push_back(&rhs);
  7824. return CATCH_MOVE(lhs);
  7825. }
  7826. friend MatchAllOf operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf&& rhs) {
  7827. rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
  7828. return CATCH_MOVE(rhs);
  7829. }
  7830. };
  7831. //! lvalue overload is intentionally deleted, users should
  7832. //! not be trying to compose stored composition matchers
  7833. template<typename ArgT>
  7834. MatchAllOf<ArgT> operator&& (MatchAllOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete;
  7835. //! lvalue overload is intentionally deleted, users should
  7836. //! not be trying to compose stored composition matchers
  7837. template<typename ArgT>
  7838. MatchAllOf<ArgT> operator&& (MatcherBase<ArgT> const& lhs, MatchAllOf<ArgT> const& rhs) = delete;
  7839. template<typename ArgT>
  7840. class MatchAnyOf final : public MatcherBase<ArgT> {
  7841. std::vector<MatcherBase<ArgT> const*> m_matchers;
  7842. public:
  7843. MatchAnyOf() = default;
  7844. MatchAnyOf(MatchAnyOf const&) = delete;
  7845. MatchAnyOf& operator=(MatchAnyOf const&) = delete;
  7846. MatchAnyOf(MatchAnyOf&&) = default;
  7847. MatchAnyOf& operator=(MatchAnyOf&&) = default;
  7848. bool match( ArgT const& arg ) const override {
  7849. for( auto matcher : m_matchers ) {
  7850. if (matcher->match(arg))
  7851. return true;
  7852. }
  7853. return false;
  7854. }
  7855. std::string describe() const override {
  7856. std::string description;
  7857. description.reserve( 4 + m_matchers.size()*32 );
  7858. description += "( ";
  7859. bool first = true;
  7860. for( auto matcher : m_matchers ) {
  7861. if( first )
  7862. first = false;
  7863. else
  7864. description += " or ";
  7865. description += matcher->toString();
  7866. }
  7867. description += " )";
  7868. return description;
  7869. }
  7870. friend MatchAnyOf operator|| (MatchAnyOf&& lhs, MatcherBase<ArgT> const& rhs) {
  7871. lhs.m_matchers.push_back(&rhs);
  7872. return CATCH_MOVE(lhs);
  7873. }
  7874. friend MatchAnyOf operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf&& rhs) {
  7875. rhs.m_matchers.insert(rhs.m_matchers.begin(), &lhs);
  7876. return CATCH_MOVE(rhs);
  7877. }
  7878. };
  7879. //! lvalue overload is intentionally deleted, users should
  7880. //! not be trying to compose stored composition matchers
  7881. template<typename ArgT>
  7882. MatchAnyOf<ArgT> operator|| (MatchAnyOf<ArgT> const& lhs, MatcherBase<ArgT> const& rhs) = delete;
  7883. //! lvalue overload is intentionally deleted, users should
  7884. //! not be trying to compose stored composition matchers
  7885. template<typename ArgT>
  7886. MatchAnyOf<ArgT> operator|| (MatcherBase<ArgT> const& lhs, MatchAnyOf<ArgT> const& rhs) = delete;
  7887. template<typename ArgT>
  7888. class MatchNotOf final : public MatcherBase<ArgT> {
  7889. MatcherBase<ArgT> const& m_underlyingMatcher;
  7890. public:
  7891. explicit MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ):
  7892. m_underlyingMatcher( underlyingMatcher )
  7893. {}
  7894. bool match( ArgT const& arg ) const override {
  7895. return !m_underlyingMatcher.match( arg );
  7896. }
  7897. std::string describe() const override {
  7898. return "not " + m_underlyingMatcher.toString();
  7899. }
  7900. };
  7901. } // namespace Detail
  7902. template <typename T>
  7903. Detail::MatchAllOf<T> operator&& (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) {
  7904. return Detail::MatchAllOf<T>{} && lhs && rhs;
  7905. }
  7906. template <typename T>
  7907. Detail::MatchAnyOf<T> operator|| (MatcherBase<T> const& lhs, MatcherBase<T> const& rhs) {
  7908. return Detail::MatchAnyOf<T>{} || lhs || rhs;
  7909. }
  7910. template <typename T>
  7911. Detail::MatchNotOf<T> operator! (MatcherBase<T> const& matcher) {
  7912. return Detail::MatchNotOf<T>{ matcher };
  7913. }
  7914. } // namespace Matchers
  7915. } // namespace Catch
  7916. #if defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  7917. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  7918. #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
  7919. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  7920. #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  7921. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  7922. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  7923. #elif defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  7924. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
  7925. #define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  7926. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
  7927. #define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  7928. #define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
  7929. #define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
  7930. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && !defined(CATCH_CONFIG_DISABLE)
  7931. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  7932. #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
  7933. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  7934. #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  7935. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  7936. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  7937. #elif !defined(CATCH_CONFIG_PREFIX_ALL) && defined(CATCH_CONFIG_DISABLE)
  7938. #define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
  7939. #define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  7940. #define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
  7941. #define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
  7942. #define CHECK_THAT( arg, matcher ) (void)(0)
  7943. #define REQUIRE_THAT( arg, matcher ) (void)(0)
  7944. #endif // end of user facing macro declarations
  7945. #endif // CATCH_MATCHERS_HPP_INCLUDED
  7946. #ifndef CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  7947. #define CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  7948. #ifndef CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  7949. #define CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  7950. #include <array>
  7951. #include <algorithm>
  7952. #include <string>
  7953. #include <type_traits>
  7954. namespace Catch {
  7955. namespace Matchers {
  7956. class MatcherGenericBase : public MatcherUntypedBase {
  7957. public:
  7958. MatcherGenericBase() = default;
  7959. ~MatcherGenericBase() override; // = default;
  7960. MatcherGenericBase(MatcherGenericBase&) = default;
  7961. MatcherGenericBase(MatcherGenericBase&&) = default;
  7962. MatcherGenericBase& operator=(MatcherGenericBase const&) = delete;
  7963. MatcherGenericBase& operator=(MatcherGenericBase&&) = delete;
  7964. };
  7965. namespace Detail {
  7966. template<std::size_t N, std::size_t M>
  7967. std::array<void const*, N + M> array_cat(std::array<void const*, N> && lhs, std::array<void const*, M> && rhs) {
  7968. std::array<void const*, N + M> arr{};
  7969. std::copy_n(lhs.begin(), N, arr.begin());
  7970. std::copy_n(rhs.begin(), M, arr.begin() + N);
  7971. return arr;
  7972. }
  7973. template<std::size_t N>
  7974. std::array<void const*, N+1> array_cat(std::array<void const*, N> && lhs, void const* rhs) {
  7975. std::array<void const*, N+1> arr{};
  7976. std::copy_n(lhs.begin(), N, arr.begin());
  7977. arr[N] = rhs;
  7978. return arr;
  7979. }
  7980. template<std::size_t N>
  7981. std::array<void const*, N+1> array_cat(void const* lhs, std::array<void const*, N> && rhs) {
  7982. std::array<void const*, N + 1> arr{ {lhs} };
  7983. std::copy_n(rhs.begin(), N, arr.begin() + 1);
  7984. return arr;
  7985. }
  7986. #if defined( __cpp_lib_logical_traits ) && __cpp_lib_logical_traits >= 201510
  7987. using std::conjunction;
  7988. #else // __cpp_lib_logical_traits
  7989. template<typename... Cond>
  7990. struct conjunction : std::true_type {};
  7991. template<typename Cond, typename... Rest>
  7992. struct conjunction<Cond, Rest...> : std::integral_constant<bool, Cond::value && conjunction<Rest...>::value> {};
  7993. #endif // __cpp_lib_logical_traits
  7994. template<typename T>
  7995. using is_generic_matcher = std::is_base_of<
  7996. Catch::Matchers::MatcherGenericBase,
  7997. std::remove_cv_t<std::remove_reference_t<T>>
  7998. >;
  7999. template<typename... Ts>
  8000. using are_generic_matchers = conjunction<is_generic_matcher<Ts>...>;
  8001. template<typename T>
  8002. using is_matcher = std::is_base_of<
  8003. Catch::Matchers::MatcherUntypedBase,
  8004. std::remove_cv_t<std::remove_reference_t<T>>
  8005. >;
  8006. template<std::size_t N, typename Arg>
  8007. bool match_all_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) {
  8008. return true;
  8009. }
  8010. template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices>
  8011. bool match_all_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) {
  8012. return static_cast<T const*>(matchers[Idx])->match(arg) && match_all_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{});
  8013. }
  8014. template<std::size_t N, typename Arg>
  8015. bool match_any_of(Arg&&, std::array<void const*, N> const&, std::index_sequence<>) {
  8016. return false;
  8017. }
  8018. template<typename T, typename... MatcherTs, std::size_t N, typename Arg, std::size_t Idx, std::size_t... Indices>
  8019. bool match_any_of(Arg&& arg, std::array<void const*, N> const& matchers, std::index_sequence<Idx, Indices...>) {
  8020. return static_cast<T const*>(matchers[Idx])->match(arg) || match_any_of<MatcherTs...>(arg, matchers, std::index_sequence<Indices...>{});
  8021. }
  8022. std::string describe_multi_matcher(StringRef combine, std::string const* descriptions_begin, std::string const* descriptions_end);
  8023. template<typename... MatcherTs, std::size_t... Idx>
  8024. std::string describe_multi_matcher(StringRef combine, std::array<void const*, sizeof...(MatcherTs)> const& matchers, std::index_sequence<Idx...>) {
  8025. std::array<std::string, sizeof...(MatcherTs)> descriptions {{
  8026. static_cast<MatcherTs const*>(matchers[Idx])->toString()...
  8027. }};
  8028. return describe_multi_matcher(combine, descriptions.data(), descriptions.data() + descriptions.size());
  8029. }
  8030. template<typename... MatcherTs>
  8031. class MatchAllOfGeneric final : public MatcherGenericBase {
  8032. public:
  8033. MatchAllOfGeneric(MatchAllOfGeneric const&) = delete;
  8034. MatchAllOfGeneric& operator=(MatchAllOfGeneric const&) = delete;
  8035. MatchAllOfGeneric(MatchAllOfGeneric&&) = default;
  8036. MatchAllOfGeneric& operator=(MatchAllOfGeneric&&) = default;
  8037. MatchAllOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {}
  8038. explicit MatchAllOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
  8039. template<typename Arg>
  8040. bool match(Arg&& arg) const {
  8041. return match_all_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{});
  8042. }
  8043. std::string describe() const override {
  8044. return describe_multi_matcher<MatcherTs...>(" and "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{});
  8045. }
  8046. // Has to be public to enable the concatenating operators
  8047. // below, because they are not friend of the RHS, only LHS,
  8048. // and thus cannot access private fields of RHS
  8049. std::array<void const*, sizeof...( MatcherTs )> m_matchers;
  8050. //! Avoids type nesting for `GenericAllOf && GenericAllOf` case
  8051. template<typename... MatchersRHS>
  8052. friend
  8053. MatchAllOfGeneric<MatcherTs..., MatchersRHS...> operator && (
  8054. MatchAllOfGeneric<MatcherTs...>&& lhs,
  8055. MatchAllOfGeneric<MatchersRHS...>&& rhs) {
  8056. return MatchAllOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
  8057. }
  8058. //! Avoids type nesting for `GenericAllOf && some matcher` case
  8059. template<typename MatcherRHS>
  8060. friend std::enable_if_t<is_matcher<MatcherRHS>::value,
  8061. MatchAllOfGeneric<MatcherTs..., MatcherRHS>> operator && (
  8062. MatchAllOfGeneric<MatcherTs...>&& lhs,
  8063. MatcherRHS const& rhs) {
  8064. return MatchAllOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(&rhs))};
  8065. }
  8066. //! Avoids type nesting for `some matcher && GenericAllOf` case
  8067. template<typename MatcherLHS>
  8068. friend std::enable_if_t<is_matcher<MatcherLHS>::value,
  8069. MatchAllOfGeneric<MatcherLHS, MatcherTs...>> operator && (
  8070. MatcherLHS const& lhs,
  8071. MatchAllOfGeneric<MatcherTs...>&& rhs) {
  8072. return MatchAllOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
  8073. }
  8074. };
  8075. template<typename... MatcherTs>
  8076. class MatchAnyOfGeneric final : public MatcherGenericBase {
  8077. public:
  8078. MatchAnyOfGeneric(MatchAnyOfGeneric const&) = delete;
  8079. MatchAnyOfGeneric& operator=(MatchAnyOfGeneric const&) = delete;
  8080. MatchAnyOfGeneric(MatchAnyOfGeneric&&) = default;
  8081. MatchAnyOfGeneric& operator=(MatchAnyOfGeneric&&) = default;
  8082. MatchAnyOfGeneric(MatcherTs const&... matchers) : m_matchers{ {std::addressof(matchers)...} } {}
  8083. explicit MatchAnyOfGeneric(std::array<void const*, sizeof...(MatcherTs)> matchers) : m_matchers{matchers} {}
  8084. template<typename Arg>
  8085. bool match(Arg&& arg) const {
  8086. return match_any_of<MatcherTs...>(arg, m_matchers, std::index_sequence_for<MatcherTs...>{});
  8087. }
  8088. std::string describe() const override {
  8089. return describe_multi_matcher<MatcherTs...>(" or "_sr, m_matchers, std::index_sequence_for<MatcherTs...>{});
  8090. }
  8091. // Has to be public to enable the concatenating operators
  8092. // below, because they are not friend of the RHS, only LHS,
  8093. // and thus cannot access private fields of RHS
  8094. std::array<void const*, sizeof...( MatcherTs )> m_matchers;
  8095. //! Avoids type nesting for `GenericAnyOf || GenericAnyOf` case
  8096. template<typename... MatchersRHS>
  8097. friend MatchAnyOfGeneric<MatcherTs..., MatchersRHS...> operator || (
  8098. MatchAnyOfGeneric<MatcherTs...>&& lhs,
  8099. MatchAnyOfGeneric<MatchersRHS...>&& rhs) {
  8100. return MatchAnyOfGeneric<MatcherTs..., MatchersRHS...>{array_cat(CATCH_MOVE(lhs.m_matchers), CATCH_MOVE(rhs.m_matchers))};
  8101. }
  8102. //! Avoids type nesting for `GenericAnyOf || some matcher` case
  8103. template<typename MatcherRHS>
  8104. friend std::enable_if_t<is_matcher<MatcherRHS>::value,
  8105. MatchAnyOfGeneric<MatcherTs..., MatcherRHS>> operator || (
  8106. MatchAnyOfGeneric<MatcherTs...>&& lhs,
  8107. MatcherRHS const& rhs) {
  8108. return MatchAnyOfGeneric<MatcherTs..., MatcherRHS>{array_cat(CATCH_MOVE(lhs.m_matchers), static_cast<void const*>(std::addressof(rhs)))};
  8109. }
  8110. //! Avoids type nesting for `some matcher || GenericAnyOf` case
  8111. template<typename MatcherLHS>
  8112. friend std::enable_if_t<is_matcher<MatcherLHS>::value,
  8113. MatchAnyOfGeneric<MatcherLHS, MatcherTs...>> operator || (
  8114. MatcherLHS const& lhs,
  8115. MatchAnyOfGeneric<MatcherTs...>&& rhs) {
  8116. return MatchAnyOfGeneric<MatcherLHS, MatcherTs...>{array_cat(static_cast<void const*>(std::addressof(lhs)), CATCH_MOVE(rhs.m_matchers))};
  8117. }
  8118. };
  8119. template<typename MatcherT>
  8120. class MatchNotOfGeneric final : public MatcherGenericBase {
  8121. MatcherT const& m_matcher;
  8122. public:
  8123. MatchNotOfGeneric(MatchNotOfGeneric const&) = delete;
  8124. MatchNotOfGeneric& operator=(MatchNotOfGeneric const&) = delete;
  8125. MatchNotOfGeneric(MatchNotOfGeneric&&) = default;
  8126. MatchNotOfGeneric& operator=(MatchNotOfGeneric&&) = default;
  8127. explicit MatchNotOfGeneric(MatcherT const& matcher) : m_matcher{matcher} {}
  8128. template<typename Arg>
  8129. bool match(Arg&& arg) const {
  8130. return !m_matcher.match(arg);
  8131. }
  8132. std::string describe() const override {
  8133. return "not " + m_matcher.toString();
  8134. }
  8135. //! Negating negation can just unwrap and return underlying matcher
  8136. friend MatcherT const& operator ! (MatchNotOfGeneric<MatcherT> const& matcher) {
  8137. return matcher.m_matcher;
  8138. }
  8139. };
  8140. } // namespace Detail
  8141. // compose only generic matchers
  8142. template<typename MatcherLHS, typename MatcherRHS>
  8143. std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherRHS>>
  8144. operator && (MatcherLHS const& lhs, MatcherRHS const& rhs) {
  8145. return { lhs, rhs };
  8146. }
  8147. template<typename MatcherLHS, typename MatcherRHS>
  8148. std::enable_if_t<Detail::are_generic_matchers<MatcherLHS, MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherRHS>>
  8149. operator || (MatcherLHS const& lhs, MatcherRHS const& rhs) {
  8150. return { lhs, rhs };
  8151. }
  8152. //! Wrap provided generic matcher in generic negator
  8153. template<typename MatcherT>
  8154. std::enable_if_t<Detail::is_generic_matcher<MatcherT>::value, Detail::MatchNotOfGeneric<MatcherT>>
  8155. operator ! (MatcherT const& matcher) {
  8156. return Detail::MatchNotOfGeneric<MatcherT>{matcher};
  8157. }
  8158. // compose mixed generic and non-generic matchers
  8159. template<typename MatcherLHS, typename ArgRHS>
  8160. std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAllOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
  8161. operator && (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) {
  8162. return { lhs, rhs };
  8163. }
  8164. template<typename ArgLHS, typename MatcherRHS>
  8165. std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAllOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
  8166. operator && (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) {
  8167. return { lhs, rhs };
  8168. }
  8169. template<typename MatcherLHS, typename ArgRHS>
  8170. std::enable_if_t<Detail::is_generic_matcher<MatcherLHS>::value, Detail::MatchAnyOfGeneric<MatcherLHS, MatcherBase<ArgRHS>>>
  8171. operator || (MatcherLHS const& lhs, MatcherBase<ArgRHS> const& rhs) {
  8172. return { lhs, rhs };
  8173. }
  8174. template<typename ArgLHS, typename MatcherRHS>
  8175. std::enable_if_t<Detail::is_generic_matcher<MatcherRHS>::value, Detail::MatchAnyOfGeneric<MatcherBase<ArgLHS>, MatcherRHS>>
  8176. operator || (MatcherBase<ArgLHS> const& lhs, MatcherRHS const& rhs) {
  8177. return { lhs, rhs };
  8178. }
  8179. } // namespace Matchers
  8180. } // namespace Catch
  8181. #endif // CATCH_MATCHERS_TEMPLATED_HPP_INCLUDED
  8182. namespace Catch {
  8183. namespace Matchers {
  8184. class IsEmptyMatcher final : public MatcherGenericBase {
  8185. public:
  8186. template <typename RangeLike>
  8187. bool match(RangeLike&& rng) const {
  8188. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  8189. using Catch::Detail::empty;
  8190. #else
  8191. using std::empty;
  8192. #endif
  8193. return empty(rng);
  8194. }
  8195. std::string describe() const override;
  8196. };
  8197. class HasSizeMatcher final : public MatcherGenericBase {
  8198. std::size_t m_target_size;
  8199. public:
  8200. explicit HasSizeMatcher(std::size_t target_size):
  8201. m_target_size(target_size)
  8202. {}
  8203. template <typename RangeLike>
  8204. bool match(RangeLike&& rng) const {
  8205. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  8206. using Catch::Detail::size;
  8207. #else
  8208. using std::size;
  8209. #endif
  8210. return size(rng) == m_target_size;
  8211. }
  8212. std::string describe() const override;
  8213. };
  8214. template <typename Matcher>
  8215. class SizeMatchesMatcher final : public MatcherGenericBase {
  8216. Matcher m_matcher;
  8217. public:
  8218. explicit SizeMatchesMatcher(Matcher m):
  8219. m_matcher(CATCH_MOVE(m))
  8220. {}
  8221. template <typename RangeLike>
  8222. bool match(RangeLike&& rng) const {
  8223. #if defined(CATCH_CONFIG_POLYFILL_NONMEMBER_CONTAINER_ACCESS)
  8224. using Catch::Detail::size;
  8225. #else
  8226. using std::size;
  8227. #endif
  8228. return m_matcher.match(size(rng));
  8229. }
  8230. std::string describe() const override {
  8231. return "size matches " + m_matcher.describe();
  8232. }
  8233. };
  8234. //! Creates a matcher that accepts empty ranges/containers
  8235. IsEmptyMatcher IsEmpty();
  8236. //! Creates a matcher that accepts ranges/containers with specific size
  8237. HasSizeMatcher SizeIs(std::size_t sz);
  8238. template <typename Matcher>
  8239. std::enable_if_t<Detail::is_matcher<Matcher>::value,
  8240. SizeMatchesMatcher<Matcher>> SizeIs(Matcher&& m) {
  8241. return SizeMatchesMatcher<Matcher>{CATCH_FORWARD(m)};
  8242. }
  8243. } // end namespace Matchers
  8244. } // end namespace Catch
  8245. #endif // CATCH_MATCHERS_CONTAINER_PROPERTIES_HPP_INCLUDED
  8246. #ifndef CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  8247. #define CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  8248. #include <algorithm>
  8249. #include <functional>
  8250. namespace Catch {
  8251. namespace Matchers {
  8252. //! Matcher for checking that an element in range is equal to specific element
  8253. template <typename T, typename Equality>
  8254. class ContainsElementMatcher final : public MatcherGenericBase {
  8255. T m_desired;
  8256. Equality m_eq;
  8257. public:
  8258. template <typename T2, typename Equality2>
  8259. ContainsElementMatcher(T2&& target, Equality2&& predicate):
  8260. m_desired(CATCH_FORWARD(target)),
  8261. m_eq(CATCH_FORWARD(predicate))
  8262. {}
  8263. std::string describe() const override {
  8264. return "contains element " + Catch::Detail::stringify(m_desired);
  8265. }
  8266. template <typename RangeLike>
  8267. bool match(RangeLike&& rng) const {
  8268. using std::begin; using std::end;
  8269. return end(rng) != std::find_if(begin(rng), end(rng),
  8270. [&](auto const& elem) {
  8271. return m_eq(elem, m_desired);
  8272. });
  8273. }
  8274. };
  8275. //! Meta-matcher for checking that an element in a range matches a specific matcher
  8276. template <typename Matcher>
  8277. class ContainsMatcherMatcher final : public MatcherGenericBase {
  8278. Matcher m_matcher;
  8279. public:
  8280. // Note that we do a copy+move to avoid having to SFINAE this
  8281. // constructor (and also avoid some perfect forwarding failure
  8282. // cases)
  8283. ContainsMatcherMatcher(Matcher matcher):
  8284. m_matcher(CATCH_MOVE(matcher))
  8285. {}
  8286. template <typename RangeLike>
  8287. bool match(RangeLike&& rng) const {
  8288. for (auto&& elem : rng) {
  8289. if (m_matcher.match(elem)) {
  8290. return true;
  8291. }
  8292. }
  8293. return false;
  8294. }
  8295. std::string describe() const override {
  8296. return "contains element matching " + m_matcher.describe();
  8297. }
  8298. };
  8299. /**
  8300. * Creates a matcher that checks whether a range contains a specific element.
  8301. *
  8302. * Uses `std::equal_to` to do the comparison
  8303. */
  8304. template <typename T>
  8305. std::enable_if_t<!Detail::is_matcher<T>::value,
  8306. ContainsElementMatcher<T, std::equal_to<>>> Contains(T&& elem) {
  8307. return { CATCH_FORWARD(elem), std::equal_to<>{} };
  8308. }
  8309. //! Creates a matcher that checks whether a range contains element matching a matcher
  8310. template <typename Matcher>
  8311. std::enable_if_t<Detail::is_matcher<Matcher>::value,
  8312. ContainsMatcherMatcher<Matcher>> Contains(Matcher&& matcher) {
  8313. return { CATCH_FORWARD(matcher) };
  8314. }
  8315. /**
  8316. * Creates a matcher that checks whether a range contains a specific element.
  8317. *
  8318. * Uses `eq` to do the comparisons
  8319. */
  8320. template <typename T, typename Equality>
  8321. ContainsElementMatcher<T, Equality> Contains(T&& elem, Equality&& eq) {
  8322. return { CATCH_FORWARD(elem), CATCH_FORWARD(eq) };
  8323. }
  8324. }
  8325. }
  8326. #endif // CATCH_MATCHERS_CONTAINS_HPP_INCLUDED
  8327. #ifndef CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  8328. #define CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  8329. namespace Catch {
  8330. namespace Matchers {
  8331. class ExceptionMessageMatcher final : public MatcherBase<std::exception> {
  8332. std::string m_message;
  8333. public:
  8334. ExceptionMessageMatcher(std::string const& message):
  8335. m_message(message)
  8336. {}
  8337. bool match(std::exception const& ex) const override;
  8338. std::string describe() const override;
  8339. };
  8340. //! Creates a matcher that checks whether a std derived exception has the provided message
  8341. ExceptionMessageMatcher Message(std::string const& message);
  8342. } // namespace Matchers
  8343. } // namespace Catch
  8344. #endif // CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
  8345. #ifndef CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  8346. #define CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  8347. namespace Catch {
  8348. namespace Matchers {
  8349. namespace Detail {
  8350. enum class FloatingPointKind : uint8_t;
  8351. }
  8352. class WithinAbsMatcher final : public MatcherBase<double> {
  8353. public:
  8354. WithinAbsMatcher(double target, double margin);
  8355. bool match(double const& matchee) const override;
  8356. std::string describe() const override;
  8357. private:
  8358. double m_target;
  8359. double m_margin;
  8360. };
  8361. class WithinUlpsMatcher final : public MatcherBase<double> {
  8362. public:
  8363. WithinUlpsMatcher( double target,
  8364. uint64_t ulps,
  8365. Detail::FloatingPointKind baseType );
  8366. bool match(double const& matchee) const override;
  8367. std::string describe() const override;
  8368. private:
  8369. double m_target;
  8370. uint64_t m_ulps;
  8371. Detail::FloatingPointKind m_type;
  8372. };
  8373. // Given IEEE-754 format for floats and doubles, we can assume
  8374. // that float -> double promotion is lossless. Given this, we can
  8375. // assume that if we do the standard relative comparison of
  8376. // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get
  8377. // the same result if we do this for floats, as if we do this for
  8378. // doubles that were promoted from floats.
  8379. class WithinRelMatcher final : public MatcherBase<double> {
  8380. public:
  8381. WithinRelMatcher( double target, double epsilon );
  8382. bool match(double const& matchee) const override;
  8383. std::string describe() const override;
  8384. private:
  8385. double m_target;
  8386. double m_epsilon;
  8387. };
  8388. //! Creates a matcher that accepts doubles within certain ULP range of target
  8389. WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff);
  8390. //! Creates a matcher that accepts floats within certain ULP range of target
  8391. WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff);
  8392. //! Creates a matcher that accepts numbers within certain range of target
  8393. WithinAbsMatcher WithinAbs(double target, double margin);
  8394. //! Creates a matcher that accepts doubles within certain relative range of target
  8395. WithinRelMatcher WithinRel(double target, double eps);
  8396. //! Creates a matcher that accepts doubles within 100*DBL_EPS relative range of target
  8397. WithinRelMatcher WithinRel(double target);
  8398. //! Creates a matcher that accepts doubles within certain relative range of target
  8399. WithinRelMatcher WithinRel(float target, float eps);
  8400. //! Creates a matcher that accepts floats within 100*FLT_EPS relative range of target
  8401. WithinRelMatcher WithinRel(float target);
  8402. } // namespace Matchers
  8403. } // namespace Catch
  8404. #endif // CATCH_MATCHERS_FLOATING_POINT_HPP_INCLUDED
  8405. #ifndef CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  8406. #define CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  8407. #include <string>
  8408. namespace Catch {
  8409. namespace Matchers {
  8410. namespace Detail {
  8411. std::string finalizeDescription(const std::string& desc);
  8412. } // namespace Detail
  8413. template <typename T, typename Predicate>
  8414. class PredicateMatcher final : public MatcherBase<T> {
  8415. Predicate m_predicate;
  8416. std::string m_description;
  8417. public:
  8418. PredicateMatcher(Predicate&& elem, std::string const& descr)
  8419. :m_predicate(CATCH_FORWARD(elem)),
  8420. m_description(Detail::finalizeDescription(descr))
  8421. {}
  8422. bool match( T const& item ) const override {
  8423. return m_predicate(item);
  8424. }
  8425. std::string describe() const override {
  8426. return m_description;
  8427. }
  8428. };
  8429. /**
  8430. * Creates a matcher that calls delegates `match` to the provided predicate.
  8431. *
  8432. * The user has to explicitly specify the argument type to the matcher
  8433. */
  8434. template<typename T, typename Pred>
  8435. PredicateMatcher<T, Pred> Predicate(Pred&& predicate, std::string const& description = "") {
  8436. static_assert(is_callable<Pred(T)>::value, "Predicate not callable with argument T");
  8437. static_assert(std::is_same<bool, FunctionReturnType<Pred, T>>::value, "Predicate does not return bool");
  8438. return PredicateMatcher<T, Pred>(CATCH_FORWARD(predicate), description);
  8439. }
  8440. } // namespace Matchers
  8441. } // namespace Catch
  8442. #endif // CATCH_MATCHERS_PREDICATE_HPP_INCLUDED
  8443. #ifndef CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  8444. #define CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  8445. namespace Catch {
  8446. namespace Matchers {
  8447. // Matcher for checking that all elements in range matches a given matcher.
  8448. template <typename Matcher>
  8449. class AllMatchMatcher final : public MatcherGenericBase {
  8450. Matcher m_matcher;
  8451. public:
  8452. AllMatchMatcher(Matcher matcher):
  8453. m_matcher(CATCH_MOVE(matcher))
  8454. {}
  8455. std::string describe() const override {
  8456. return "all match " + m_matcher.describe();
  8457. }
  8458. template <typename RangeLike>
  8459. bool match(RangeLike&& rng) const {
  8460. for (auto&& elem : rng) {
  8461. if (!m_matcher.match(elem)) {
  8462. return false;
  8463. }
  8464. }
  8465. return true;
  8466. }
  8467. };
  8468. // Matcher for checking that no element in range matches a given matcher.
  8469. template <typename Matcher>
  8470. class NoneMatchMatcher final : public MatcherGenericBase {
  8471. Matcher m_matcher;
  8472. public:
  8473. NoneMatchMatcher(Matcher matcher):
  8474. m_matcher(CATCH_MOVE(matcher))
  8475. {}
  8476. std::string describe() const override {
  8477. return "none match " + m_matcher.describe();
  8478. }
  8479. template <typename RangeLike>
  8480. bool match(RangeLike&& rng) const {
  8481. for (auto&& elem : rng) {
  8482. if (m_matcher.match(elem)) {
  8483. return false;
  8484. }
  8485. }
  8486. return true;
  8487. }
  8488. };
  8489. // Matcher for checking that at least one element in range matches a given matcher.
  8490. template <typename Matcher>
  8491. class AnyMatchMatcher final : public MatcherGenericBase {
  8492. Matcher m_matcher;
  8493. public:
  8494. AnyMatchMatcher(Matcher matcher):
  8495. m_matcher(CATCH_MOVE(matcher))
  8496. {}
  8497. std::string describe() const override {
  8498. return "any match " + m_matcher.describe();
  8499. }
  8500. template <typename RangeLike>
  8501. bool match(RangeLike&& rng) const {
  8502. for (auto&& elem : rng) {
  8503. if (m_matcher.match(elem)) {
  8504. return true;
  8505. }
  8506. }
  8507. return false;
  8508. }
  8509. };
  8510. // Matcher for checking that all elements in range are true.
  8511. class AllTrueMatcher final : public MatcherGenericBase {
  8512. public:
  8513. std::string describe() const override;
  8514. template <typename RangeLike>
  8515. bool match(RangeLike&& rng) const {
  8516. for (auto&& elem : rng) {
  8517. if (!elem) {
  8518. return false;
  8519. }
  8520. }
  8521. return true;
  8522. }
  8523. };
  8524. // Matcher for checking that no element in range is true.
  8525. class NoneTrueMatcher final : public MatcherGenericBase {
  8526. public:
  8527. std::string describe() const override;
  8528. template <typename RangeLike>
  8529. bool match(RangeLike&& rng) const {
  8530. for (auto&& elem : rng) {
  8531. if (elem) {
  8532. return false;
  8533. }
  8534. }
  8535. return true;
  8536. }
  8537. };
  8538. // Matcher for checking that any element in range is true.
  8539. class AnyTrueMatcher final : public MatcherGenericBase {
  8540. public:
  8541. std::string describe() const override;
  8542. template <typename RangeLike>
  8543. bool match(RangeLike&& rng) const {
  8544. for (auto&& elem : rng) {
  8545. if (elem) {
  8546. return true;
  8547. }
  8548. }
  8549. return false;
  8550. }
  8551. };
  8552. // Creates a matcher that checks whether all elements in a range match a matcher
  8553. template <typename Matcher>
  8554. AllMatchMatcher<Matcher> AllMatch(Matcher&& matcher) {
  8555. return { CATCH_FORWARD(matcher) };
  8556. }
  8557. // Creates a matcher that checks whether no element in a range matches a matcher.
  8558. template <typename Matcher>
  8559. NoneMatchMatcher<Matcher> NoneMatch(Matcher&& matcher) {
  8560. return { CATCH_FORWARD(matcher) };
  8561. }
  8562. // Creates a matcher that checks whether any element in a range matches a matcher.
  8563. template <typename Matcher>
  8564. AnyMatchMatcher<Matcher> AnyMatch(Matcher&& matcher) {
  8565. return { CATCH_FORWARD(matcher) };
  8566. }
  8567. // Creates a matcher that checks whether all elements in a range are true
  8568. AllTrueMatcher AllTrue();
  8569. // Creates a matcher that checks whether no element in a range is true
  8570. NoneTrueMatcher NoneTrue();
  8571. // Creates a matcher that checks whether any element in a range is true
  8572. AnyTrueMatcher AnyTrue();
  8573. }
  8574. }
  8575. #endif // CATCH_MATCHERS_QUANTIFIERS_HPP_INCLUDED
  8576. #ifndef CATCH_MATCHERS_STRING_HPP_INCLUDED
  8577. #define CATCH_MATCHERS_STRING_HPP_INCLUDED
  8578. #include <string>
  8579. namespace Catch {
  8580. namespace Matchers {
  8581. struct CasedString {
  8582. CasedString( std::string const& str, CaseSensitive caseSensitivity );
  8583. std::string adjustString( std::string const& str ) const;
  8584. StringRef caseSensitivitySuffix() const;
  8585. CaseSensitive m_caseSensitivity;
  8586. std::string m_str;
  8587. };
  8588. class StringMatcherBase : public MatcherBase<std::string> {
  8589. protected:
  8590. CasedString m_comparator;
  8591. StringRef m_operation;
  8592. public:
  8593. StringMatcherBase( StringRef operation,
  8594. CasedString const& comparator );
  8595. std::string describe() const override;
  8596. };
  8597. class StringEqualsMatcher final : public StringMatcherBase {
  8598. public:
  8599. StringEqualsMatcher( CasedString const& comparator );
  8600. bool match( std::string const& source ) const override;
  8601. };
  8602. class StringContainsMatcher final : public StringMatcherBase {
  8603. public:
  8604. StringContainsMatcher( CasedString const& comparator );
  8605. bool match( std::string const& source ) const override;
  8606. };
  8607. class StartsWithMatcher final : public StringMatcherBase {
  8608. public:
  8609. StartsWithMatcher( CasedString const& comparator );
  8610. bool match( std::string const& source ) const override;
  8611. };
  8612. class EndsWithMatcher final : public StringMatcherBase {
  8613. public:
  8614. EndsWithMatcher( CasedString const& comparator );
  8615. bool match( std::string const& source ) const override;
  8616. };
  8617. class RegexMatcher final : public MatcherBase<std::string> {
  8618. std::string m_regex;
  8619. CaseSensitive m_caseSensitivity;
  8620. public:
  8621. RegexMatcher( std::string regex, CaseSensitive caseSensitivity );
  8622. bool match( std::string const& matchee ) const override;
  8623. std::string describe() const override;
  8624. };
  8625. //! Creates matcher that accepts strings that are exactly equal to `str`
  8626. StringEqualsMatcher Equals( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  8627. //! Creates matcher that accepts strings that contain `str`
  8628. StringContainsMatcher ContainsSubstring( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  8629. //! Creates matcher that accepts strings that _end_ with `str`
  8630. EndsWithMatcher EndsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  8631. //! Creates matcher that accepts strings that _start_ with `str`
  8632. StartsWithMatcher StartsWith( std::string const& str, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  8633. //! Creates matcher that accepts strings matching `regex`
  8634. RegexMatcher Matches( std::string const& regex, CaseSensitive caseSensitivity = CaseSensitive::Yes );
  8635. } // namespace Matchers
  8636. } // namespace Catch
  8637. #endif // CATCH_MATCHERS_STRING_HPP_INCLUDED
  8638. #ifndef CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  8639. #define CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  8640. #include <algorithm>
  8641. namespace Catch {
  8642. namespace Matchers {
  8643. template<typename T, typename Alloc>
  8644. class VectorContainsElementMatcher final : public MatcherBase<std::vector<T, Alloc>> {
  8645. T const& m_comparator;
  8646. public:
  8647. VectorContainsElementMatcher(T const& comparator):
  8648. m_comparator(comparator)
  8649. {}
  8650. bool match(std::vector<T, Alloc> const& v) const override {
  8651. for (auto const& el : v) {
  8652. if (el == m_comparator) {
  8653. return true;
  8654. }
  8655. }
  8656. return false;
  8657. }
  8658. std::string describe() const override {
  8659. return "Contains: " + ::Catch::Detail::stringify( m_comparator );
  8660. }
  8661. };
  8662. template<typename T, typename AllocComp, typename AllocMatch>
  8663. class ContainsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  8664. std::vector<T, AllocComp> const& m_comparator;
  8665. public:
  8666. ContainsMatcher(std::vector<T, AllocComp> const& comparator):
  8667. m_comparator( comparator )
  8668. {}
  8669. bool match(std::vector<T, AllocMatch> const& v) const override {
  8670. // !TBD: see note in EqualsMatcher
  8671. if (m_comparator.size() > v.size())
  8672. return false;
  8673. for (auto const& comparator : m_comparator) {
  8674. auto present = false;
  8675. for (const auto& el : v) {
  8676. if (el == comparator) {
  8677. present = true;
  8678. break;
  8679. }
  8680. }
  8681. if (!present) {
  8682. return false;
  8683. }
  8684. }
  8685. return true;
  8686. }
  8687. std::string describe() const override {
  8688. return "Contains: " + ::Catch::Detail::stringify( m_comparator );
  8689. }
  8690. };
  8691. template<typename T, typename AllocComp, typename AllocMatch>
  8692. class EqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  8693. std::vector<T, AllocComp> const& m_comparator;
  8694. public:
  8695. EqualsMatcher(std::vector<T, AllocComp> const& comparator):
  8696. m_comparator( comparator )
  8697. {}
  8698. bool match(std::vector<T, AllocMatch> const& v) const override {
  8699. // !TBD: This currently works if all elements can be compared using !=
  8700. // - a more general approach would be via a compare template that defaults
  8701. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  8702. // - then just call that directly
  8703. if (m_comparator.size() != v.size())
  8704. return false;
  8705. for (std::size_t i = 0; i < v.size(); ++i)
  8706. if (m_comparator[i] != v[i])
  8707. return false;
  8708. return true;
  8709. }
  8710. std::string describe() const override {
  8711. return "Equals: " + ::Catch::Detail::stringify( m_comparator );
  8712. }
  8713. };
  8714. template<typename T, typename AllocComp, typename AllocMatch>
  8715. class ApproxMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  8716. std::vector<T, AllocComp> const& m_comparator;
  8717. mutable Catch::Approx approx = Catch::Approx::custom();
  8718. public:
  8719. ApproxMatcher(std::vector<T, AllocComp> const& comparator):
  8720. m_comparator( comparator )
  8721. {}
  8722. bool match(std::vector<T, AllocMatch> const& v) const override {
  8723. if (m_comparator.size() != v.size())
  8724. return false;
  8725. for (std::size_t i = 0; i < v.size(); ++i)
  8726. if (m_comparator[i] != approx(v[i]))
  8727. return false;
  8728. return true;
  8729. }
  8730. std::string describe() const override {
  8731. return "is approx: " + ::Catch::Detail::stringify( m_comparator );
  8732. }
  8733. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  8734. ApproxMatcher& epsilon( T const& newEpsilon ) {
  8735. approx.epsilon(static_cast<double>(newEpsilon));
  8736. return *this;
  8737. }
  8738. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  8739. ApproxMatcher& margin( T const& newMargin ) {
  8740. approx.margin(static_cast<double>(newMargin));
  8741. return *this;
  8742. }
  8743. template <typename = std::enable_if_t<std::is_constructible<double, T>::value>>
  8744. ApproxMatcher& scale( T const& newScale ) {
  8745. approx.scale(static_cast<double>(newScale));
  8746. return *this;
  8747. }
  8748. };
  8749. template<typename T, typename AllocComp, typename AllocMatch>
  8750. class UnorderedEqualsMatcher final : public MatcherBase<std::vector<T, AllocMatch>> {
  8751. std::vector<T, AllocComp> const& m_target;
  8752. public:
  8753. UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target):
  8754. m_target(target)
  8755. {}
  8756. bool match(std::vector<T, AllocMatch> const& vec) const override {
  8757. if (m_target.size() != vec.size()) {
  8758. return false;
  8759. }
  8760. return std::is_permutation(m_target.begin(), m_target.end(), vec.begin());
  8761. }
  8762. std::string describe() const override {
  8763. return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
  8764. }
  8765. };
  8766. // The following functions create the actual matcher objects.
  8767. // This allows the types to be inferred
  8768. //! Creates a matcher that matches vectors that contain all elements in `comparator`
  8769. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  8770. ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) {
  8771. return ContainsMatcher<T, AllocComp, AllocMatch>(comparator);
  8772. }
  8773. //! Creates a matcher that matches vectors that contain `comparator` as an element
  8774. template<typename T, typename Alloc = std::allocator<T>>
  8775. VectorContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) {
  8776. return VectorContainsElementMatcher<T, Alloc>(comparator);
  8777. }
  8778. //! Creates a matcher that matches vectors that are exactly equal to `comparator`
  8779. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  8780. EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) {
  8781. return EqualsMatcher<T, AllocComp, AllocMatch>(comparator);
  8782. }
  8783. //! Creates a matcher that matches vectors that `comparator` as an element
  8784. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  8785. ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) {
  8786. return ApproxMatcher<T, AllocComp, AllocMatch>(comparator);
  8787. }
  8788. //! Creates a matcher that matches vectors that is equal to `target` modulo permutation
  8789. template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
  8790. UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) {
  8791. return UnorderedEqualsMatcher<T, AllocComp, AllocMatch>(target);
  8792. }
  8793. } // namespace Matchers
  8794. } // namespace Catch
  8795. #endif // CATCH_MATCHERS_VECTOR_HPP_INCLUDED
  8796. #endif // CATCH_MATCHERS_ALL_HPP_INCLUDED
  8797. /** \file
  8798. * This is a convenience header for Catch2's Reporter support. It includes
  8799. * **all** of Catch2 headers related to reporters, including all reporters.
  8800. *
  8801. * Generally the Catch2 users should use specific includes they need,
  8802. * but this header can be used instead for ease-of-experimentation, or
  8803. * just plain convenience, at the cost of (significantly) increased
  8804. * compilation times.
  8805. *
  8806. * When a new header (reporter) is added to either the `reporter` folder,
  8807. * or to the corresponding internal subfolder, it should be added here.
  8808. */
  8809. #ifndef CATCH_REPORTERS_ALL_HPP_INCLUDED
  8810. #define CATCH_REPORTERS_ALL_HPP_INCLUDED
  8811. #ifndef CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  8812. #define CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  8813. #ifndef CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  8814. #define CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  8815. #ifndef CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  8816. #define CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  8817. #include <map>
  8818. #include <string>
  8819. namespace Catch {
  8820. class ColourImpl;
  8821. /**
  8822. * This is the base class for all reporters.
  8823. *
  8824. * If are writing a reporter, you must derive from this type, or one
  8825. * of the helper reporter bases that are derived from this type.
  8826. *
  8827. * ReporterBase centralizes handling of various common tasks in reporters,
  8828. * like storing the right stream for the reporters to write to, and
  8829. * providing the default implementation of the different listing events.
  8830. */
  8831. class ReporterBase : public IEventListener {
  8832. protected:
  8833. //! The stream wrapper as passed to us by outside code
  8834. Detail::unique_ptr<IStream> m_wrapped_stream;
  8835. //! Cached output stream from `m_wrapped_stream` to reduce
  8836. //! number of indirect calls needed to write output.
  8837. std::ostream& m_stream;
  8838. //! Colour implementation this reporter was configured for
  8839. Detail::unique_ptr<ColourImpl> m_colour;
  8840. //! The custom reporter options user passed down to the reporter
  8841. std::map<std::string, std::string> m_customOptions;
  8842. public:
  8843. ReporterBase( ReporterConfig&& config );
  8844. ~ReporterBase() override; // = default;
  8845. /**
  8846. * Provides a simple default listing of reporters.
  8847. *
  8848. * Should look roughly like the reporter listing in v2 and earlier
  8849. * versions of Catch2.
  8850. */
  8851. void listReporters(
  8852. std::vector<ReporterDescription> const& descriptions ) override;
  8853. /**
  8854. * Provides a simple default listing of listeners
  8855. *
  8856. * Looks similarly to listing of reporters, but with listener type
  8857. * instead of reporter name.
  8858. */
  8859. void listListeners(
  8860. std::vector<ListenerDescription> const& descriptions ) override;
  8861. /**
  8862. * Provides a simple default listing of tests.
  8863. *
  8864. * Should look roughly like the test listing in v2 and earlier versions
  8865. * of Catch2. Especially supports low-verbosity listing that mimics the
  8866. * old `--list-test-names-only` output.
  8867. */
  8868. void listTests( std::vector<TestCaseHandle> const& tests ) override;
  8869. /**
  8870. * Provides a simple default listing of tags.
  8871. *
  8872. * Should look roughly like the tag listing in v2 and earlier versions
  8873. * of Catch2.
  8874. */
  8875. void listTags( std::vector<TagInfo> const& tags ) override;
  8876. };
  8877. } // namespace Catch
  8878. #endif // CATCH_REPORTER_COMMON_BASE_HPP_INCLUDED
  8879. #include <vector>
  8880. namespace Catch {
  8881. class StreamingReporterBase : public ReporterBase {
  8882. public:
  8883. // GCC5 compat: we cannot use inherited constructor, because it
  8884. // doesn't implement backport of P0136
  8885. StreamingReporterBase(ReporterConfig&& _config):
  8886. ReporterBase(CATCH_MOVE(_config))
  8887. {}
  8888. ~StreamingReporterBase() override;
  8889. void benchmarkPreparing( StringRef ) override {}
  8890. void benchmarkStarting( BenchmarkInfo const& ) override {}
  8891. void benchmarkEnded( BenchmarkStats<> const& ) override {}
  8892. void benchmarkFailed( StringRef ) override {}
  8893. void fatalErrorEncountered( StringRef /*error*/ ) override {}
  8894. void noMatchingTestCases( StringRef /*unmatchedSpec*/ ) override {}
  8895. void reportInvalidTestSpec( StringRef /*invalidArgument*/ ) override {}
  8896. void testRunStarting( TestRunInfo const& _testRunInfo ) override;
  8897. void testCaseStarting(TestCaseInfo const& _testInfo) override {
  8898. currentTestCaseInfo = &_testInfo;
  8899. }
  8900. void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
  8901. void sectionStarting(SectionInfo const& _sectionInfo) override {
  8902. m_sectionStack.push_back(_sectionInfo);
  8903. }
  8904. void assertionStarting( AssertionInfo const& ) override {}
  8905. void assertionEnded( AssertionStats const& ) override {}
  8906. void sectionEnded(SectionStats const& /* _sectionStats */) override {
  8907. m_sectionStack.pop_back();
  8908. }
  8909. void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
  8910. void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
  8911. currentTestCaseInfo = nullptr;
  8912. }
  8913. void testRunEnded( TestRunStats const& /* _testRunStats */ ) override;
  8914. void skipTest(TestCaseInfo const&) override {
  8915. // Don't do anything with this by default.
  8916. // It can optionally be overridden in the derived class.
  8917. }
  8918. protected:
  8919. TestRunInfo currentTestRunInfo{ "test run has not started yet"_sr };
  8920. TestCaseInfo const* currentTestCaseInfo = nullptr;
  8921. //! Stack of all _active_ sections in the _current_ test case
  8922. std::vector<SectionInfo> m_sectionStack;
  8923. };
  8924. } // end namespace Catch
  8925. #endif // CATCH_REPORTER_STREAMING_BASE_HPP_INCLUDED
  8926. #include <string>
  8927. namespace Catch {
  8928. class AutomakeReporter final : public StreamingReporterBase {
  8929. public:
  8930. // GCC5 compat: we cannot use inherited constructor, because it
  8931. // doesn't implement backport of P0136
  8932. AutomakeReporter(ReporterConfig&& _config):
  8933. StreamingReporterBase(CATCH_MOVE(_config))
  8934. {}
  8935. ~AutomakeReporter() override;
  8936. static std::string getDescription() {
  8937. using namespace std::string_literals;
  8938. return "Reports test results in the format of Automake .trs files"s;
  8939. }
  8940. void testCaseEnded(TestCaseStats const& _testCaseStats) override;
  8941. void skipTest(TestCaseInfo const& testInfo) override;
  8942. };
  8943. } // end namespace Catch
  8944. #endif // CATCH_REPORTER_AUTOMAKE_HPP_INCLUDED
  8945. #ifndef CATCH_REPORTER_COMPACT_HPP_INCLUDED
  8946. #define CATCH_REPORTER_COMPACT_HPP_INCLUDED
  8947. namespace Catch {
  8948. class CompactReporter final : public StreamingReporterBase {
  8949. public:
  8950. using StreamingReporterBase::StreamingReporterBase;
  8951. ~CompactReporter() override;
  8952. static std::string getDescription();
  8953. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  8954. void testRunStarting( TestRunInfo const& _testInfo ) override;
  8955. void assertionEnded(AssertionStats const& _assertionStats) override;
  8956. void sectionEnded(SectionStats const& _sectionStats) override;
  8957. void testRunEnded(TestRunStats const& _testRunStats) override;
  8958. };
  8959. } // end namespace Catch
  8960. #endif // CATCH_REPORTER_COMPACT_HPP_INCLUDED
  8961. #ifndef CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8962. #define CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8963. namespace Catch {
  8964. // Fwd decls
  8965. struct SummaryColumn;
  8966. class TablePrinter;
  8967. class ConsoleReporter final : public StreamingReporterBase {
  8968. Detail::unique_ptr<TablePrinter> m_tablePrinter;
  8969. public:
  8970. ConsoleReporter(ReporterConfig&& config);
  8971. ~ConsoleReporter() override;
  8972. static std::string getDescription();
  8973. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  8974. void reportInvalidTestSpec( StringRef arg ) override;
  8975. void assertionStarting(AssertionInfo const&) override;
  8976. void assertionEnded(AssertionStats const& _assertionStats) override;
  8977. void sectionStarting(SectionInfo const& _sectionInfo) override;
  8978. void sectionEnded(SectionStats const& _sectionStats) override;
  8979. void benchmarkPreparing( StringRef name ) override;
  8980. void benchmarkStarting(BenchmarkInfo const& info) override;
  8981. void benchmarkEnded(BenchmarkStats<> const& stats) override;
  8982. void benchmarkFailed( StringRef error ) override;
  8983. void testCaseEnded(TestCaseStats const& _testCaseStats) override;
  8984. void testRunEnded(TestRunStats const& _testRunStats) override;
  8985. void testRunStarting(TestRunInfo const& _testRunInfo) override;
  8986. private:
  8987. void lazyPrint();
  8988. void lazyPrintWithoutClosingBenchmarkTable();
  8989. void lazyPrintRunInfo();
  8990. void printTestCaseAndSectionHeader();
  8991. void printClosedHeader(std::string const& _name);
  8992. void printOpenHeader(std::string const& _name);
  8993. // if string has a : in first line will set indent to follow it on
  8994. // subsequent lines
  8995. void printHeaderString(std::string const& _string, std::size_t indent = 0);
  8996. void printTotals(Totals const& totals);
  8997. void printSummaryRow(StringRef label, std::vector<SummaryColumn> const& cols, std::size_t row);
  8998. void printTotalsDivider(Totals const& totals);
  8999. void printSummaryDivider();
  9000. bool m_headerPrinted = false;
  9001. bool m_testRunInfoPrinted = false;
  9002. };
  9003. } // end namespace Catch
  9004. #endif // CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  9005. #ifndef CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  9006. #define CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  9007. #include <string>
  9008. #include <vector>
  9009. namespace Catch {
  9010. namespace Detail {
  9011. //! Represents either an assertion or a benchmark result to be handled by cumulative reporter later
  9012. class AssertionOrBenchmarkResult {
  9013. // This should really be a variant, but this is much faster
  9014. // to write and the data layout here is already terrible
  9015. // enough that we do not have to care about the object size.
  9016. Optional<AssertionStats> m_assertion;
  9017. Optional<BenchmarkStats<>> m_benchmark;
  9018. public:
  9019. AssertionOrBenchmarkResult(AssertionStats const& assertion);
  9020. AssertionOrBenchmarkResult(BenchmarkStats<> const& benchmark);
  9021. bool isAssertion() const;
  9022. bool isBenchmark() const;
  9023. AssertionStats const& asAssertion() const;
  9024. BenchmarkStats<> const& asBenchmark() const;
  9025. };
  9026. }
  9027. /**
  9028. * Utility base for reporters that need to handle all results at once
  9029. *
  9030. * It stores tree of all test cases, sections and assertions, and after the
  9031. * test run is finished, calls into `testRunEndedCumulative` to pass the
  9032. * control to the deriving class.
  9033. *
  9034. * If you are deriving from this class and override any testing related
  9035. * member functions, you should first call into the base's implementation to
  9036. * avoid breaking the tree construction.
  9037. *
  9038. * Due to the way this base functions, it has to expand assertions up-front,
  9039. * even if they are later unused (e.g. because the deriving reporter does
  9040. * not report successful assertions, or because the deriving reporter does
  9041. * not use assertion expansion at all). Derived classes can use two
  9042. * customization points, `m_shouldStoreSuccesfulAssertions` and
  9043. * `m_shouldStoreFailedAssertions`, to disable the expansion and gain extra
  9044. * performance. **Accessing the assertion expansions if it wasn't stored is
  9045. * UB.**
  9046. */
  9047. class CumulativeReporterBase : public ReporterBase {
  9048. public:
  9049. template<typename T, typename ChildNodeT>
  9050. struct Node {
  9051. explicit Node( T const& _value ) : value( _value ) {}
  9052. using ChildNodes = std::vector<Detail::unique_ptr<ChildNodeT>>;
  9053. T value;
  9054. ChildNodes children;
  9055. };
  9056. struct SectionNode {
  9057. explicit SectionNode(SectionStats const& _stats) : stats(_stats) {}
  9058. bool operator == (SectionNode const& other) const {
  9059. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  9060. }
  9061. bool hasAnyAssertions() const;
  9062. SectionStats stats;
  9063. std::vector<Detail::unique_ptr<SectionNode>> childSections;
  9064. std::vector<Detail::AssertionOrBenchmarkResult> assertionsAndBenchmarks;
  9065. std::string stdOut;
  9066. std::string stdErr;
  9067. };
  9068. using TestCaseNode = Node<TestCaseStats, SectionNode>;
  9069. using TestRunNode = Node<TestRunStats, TestCaseNode>;
  9070. // GCC5 compat: we cannot use inherited constructor, because it
  9071. // doesn't implement backport of P0136
  9072. CumulativeReporterBase(ReporterConfig&& _config):
  9073. ReporterBase(CATCH_MOVE(_config))
  9074. {}
  9075. ~CumulativeReporterBase() override;
  9076. void benchmarkPreparing( StringRef ) override {}
  9077. void benchmarkStarting( BenchmarkInfo const& ) override {}
  9078. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  9079. void benchmarkFailed( StringRef ) override {}
  9080. void noMatchingTestCases( StringRef ) override {}
  9081. void reportInvalidTestSpec( StringRef ) override {}
  9082. void fatalErrorEncountered( StringRef /*error*/ ) override {}
  9083. void testRunStarting( TestRunInfo const& ) override {}
  9084. void testCaseStarting( TestCaseInfo const& ) override {}
  9085. void testCasePartialStarting( TestCaseInfo const&, uint64_t ) override {}
  9086. void sectionStarting( SectionInfo const& sectionInfo ) override;
  9087. void assertionStarting( AssertionInfo const& ) override {}
  9088. void assertionEnded( AssertionStats const& assertionStats ) override;
  9089. void sectionEnded( SectionStats const& sectionStats ) override;
  9090. void testCasePartialEnded( TestCaseStats const&, uint64_t ) override {}
  9091. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  9092. void testRunEnded( TestRunStats const& testRunStats ) override;
  9093. //! Customization point: called after last test finishes (testRunEnded has been handled)
  9094. virtual void testRunEndedCumulative() = 0;
  9095. void skipTest(TestCaseInfo const&) override {}
  9096. protected:
  9097. //! Should the cumulative base store the assertion expansion for succesful assertions?
  9098. bool m_shouldStoreSuccesfulAssertions = true;
  9099. //! Should the cumulative base store the assertion expansion for failed assertions?
  9100. bool m_shouldStoreFailedAssertions = true;
  9101. // We need lazy construction here. We should probably refactor it
  9102. // later, after the events are redone.
  9103. //! The root node of the test run tree.
  9104. Detail::unique_ptr<TestRunNode> m_testRun;
  9105. private:
  9106. // Note: We rely on pointer identity being stable, which is why
  9107. // we store pointers to the nodes rather than the values.
  9108. std::vector<Detail::unique_ptr<TestCaseNode>> m_testCases;
  9109. // Root section of the _current_ test case
  9110. Detail::unique_ptr<SectionNode> m_rootSection;
  9111. // Deepest section of the _current_ test case
  9112. SectionNode* m_deepestSection = nullptr;
  9113. // Stack of _active_ sections in the _current_ test case
  9114. std::vector<SectionNode*> m_sectionStack;
  9115. };
  9116. } // end namespace Catch
  9117. #endif // CATCH_REPORTER_CUMULATIVE_BASE_HPP_INCLUDED
  9118. #ifndef CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  9119. #define CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  9120. namespace Catch {
  9121. /**
  9122. * Base class to simplify implementing listeners.
  9123. *
  9124. * Provides empty default implementation for all IEventListener member
  9125. * functions, so that a listener implementation can pick which
  9126. * member functions it actually cares about.
  9127. */
  9128. class EventListenerBase : public IEventListener {
  9129. public:
  9130. using IEventListener::IEventListener;
  9131. void reportInvalidTestSpec( StringRef unmatchedSpec ) override;
  9132. void fatalErrorEncountered( StringRef error ) override;
  9133. void benchmarkPreparing( StringRef name ) override;
  9134. void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
  9135. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  9136. void benchmarkFailed( StringRef error ) override;
  9137. void assertionStarting( AssertionInfo const& assertionInfo ) override;
  9138. void assertionEnded( AssertionStats const& assertionStats ) override;
  9139. void listReporters(
  9140. std::vector<ReporterDescription> const& descriptions ) override;
  9141. void listListeners(
  9142. std::vector<ListenerDescription> const& descriptions ) override;
  9143. void listTests( std::vector<TestCaseHandle> const& tests ) override;
  9144. void listTags( std::vector<TagInfo> const& tagInfos ) override;
  9145. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  9146. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  9147. void testCaseStarting( TestCaseInfo const& testInfo ) override;
  9148. void testCasePartialStarting( TestCaseInfo const& testInfo,
  9149. uint64_t partNumber ) override;
  9150. void sectionStarting( SectionInfo const& sectionInfo ) override;
  9151. void sectionEnded( SectionStats const& sectionStats ) override;
  9152. void testCasePartialEnded( TestCaseStats const& testCaseStats,
  9153. uint64_t partNumber ) override;
  9154. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  9155. void testRunEnded( TestRunStats const& testRunStats ) override;
  9156. void skipTest( TestCaseInfo const& testInfo ) override;
  9157. };
  9158. } // end namespace Catch
  9159. #endif // CATCH_REPORTER_EVENT_LISTENER_HPP_INCLUDED
  9160. #ifndef CATCH_REPORTER_HELPERS_HPP_INCLUDED
  9161. #define CATCH_REPORTER_HELPERS_HPP_INCLUDED
  9162. #include <iosfwd>
  9163. #include <string>
  9164. #include <vector>
  9165. namespace Catch {
  9166. class IConfig;
  9167. class TestCaseHandle;
  9168. class ColourImpl;
  9169. // Returns double formatted as %.3f (format expected on output)
  9170. std::string getFormattedDuration( double duration );
  9171. //! Should the reporter show duration of test given current configuration?
  9172. bool shouldShowDuration( IConfig const& config, double duration );
  9173. std::string serializeFilters( std::vector<std::string> const& filters );
  9174. struct lineOfChars {
  9175. char c;
  9176. constexpr lineOfChars( char c_ ): c( c_ ) {}
  9177. friend std::ostream& operator<<( std::ostream& out, lineOfChars value );
  9178. };
  9179. /**
  9180. * Lists reporter descriptions to the provided stream in user-friendly
  9181. * format
  9182. *
  9183. * Used as the default listing implementation by the first party reporter
  9184. * bases. The output should be backwards compatible with the output of
  9185. * Catch2 v2 binaries.
  9186. */
  9187. void
  9188. defaultListReporters( std::ostream& out,
  9189. std::vector<ReporterDescription> const& descriptions,
  9190. Verbosity verbosity );
  9191. /**
  9192. * Lists listeners descriptions to the provided stream in user-friendly
  9193. * format
  9194. */
  9195. void defaultListListeners( std::ostream& out,
  9196. std::vector<ListenerDescription> const& descriptions );
  9197. /**
  9198. * Lists tag information to the provided stream in user-friendly format
  9199. *
  9200. * Used as the default listing implementation by the first party reporter
  9201. * bases. The output should be backwards compatible with the output of
  9202. * Catch2 v2 binaries.
  9203. */
  9204. void defaultListTags( std::ostream& out, std::vector<TagInfo> const& tags, bool isFiltered );
  9205. /**
  9206. * Lists test case information to the provided stream in user-friendly
  9207. * format
  9208. *
  9209. * Used as the default listing implementation by the first party reporter
  9210. * bases. The output is backwards compatible with the output of Catch2
  9211. * v2 binaries, and also supports the format specific to the old
  9212. * `--list-test-names-only` option, for people who used it in integrations.
  9213. */
  9214. void defaultListTests( std::ostream& out,
  9215. ColourImpl* streamColour,
  9216. std::vector<TestCaseHandle> const& tests,
  9217. bool isFiltered,
  9218. Verbosity verbosity );
  9219. } // end namespace Catch
  9220. #endif // CATCH_REPORTER_HELPERS_HPP_INCLUDED
  9221. #ifndef CATCH_REPORTER_JUNIT_HPP_INCLUDED
  9222. #define CATCH_REPORTER_JUNIT_HPP_INCLUDED
  9223. namespace Catch {
  9224. class JunitReporter final : public CumulativeReporterBase {
  9225. public:
  9226. JunitReporter(ReporterConfig&& _config);
  9227. ~JunitReporter() override = default;
  9228. static std::string getDescription();
  9229. void testRunStarting(TestRunInfo const& runInfo) override;
  9230. void testCaseStarting(TestCaseInfo const& testCaseInfo) override;
  9231. void assertionEnded(AssertionStats const& assertionStats) override;
  9232. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  9233. void testRunEndedCumulative() override;
  9234. private:
  9235. void writeRun(TestRunNode const& testRunNode, double suiteTime);
  9236. void writeTestCase(TestCaseNode const& testCaseNode);
  9237. void writeSection( std::string const& className,
  9238. std::string const& rootName,
  9239. SectionNode const& sectionNode,
  9240. bool testOkToFail );
  9241. void writeAssertions(SectionNode const& sectionNode);
  9242. void writeAssertion(AssertionStats const& stats);
  9243. XmlWriter xml;
  9244. Timer suiteTimer;
  9245. std::string stdOutForSuite;
  9246. std::string stdErrForSuite;
  9247. unsigned int unexpectedExceptions = 0;
  9248. bool m_okToFail = false;
  9249. };
  9250. } // end namespace Catch
  9251. #endif // CATCH_REPORTER_JUNIT_HPP_INCLUDED
  9252. #ifndef CATCH_REPORTER_MULTI_HPP_INCLUDED
  9253. #define CATCH_REPORTER_MULTI_HPP_INCLUDED
  9254. namespace Catch {
  9255. class MultiReporter final : public IEventListener {
  9256. /*
  9257. * Stores all added reporters and listeners
  9258. *
  9259. * All Listeners are stored before all reporters, and individual
  9260. * listeners/reporters are stored in order of insertion.
  9261. */
  9262. std::vector<IEventListenerPtr> m_reporterLikes;
  9263. bool m_haveNoncapturingReporters = false;
  9264. // Keep track of how many listeners we have already inserted,
  9265. // so that we can insert them into the main vector at the right place
  9266. size_t m_insertedListeners = 0;
  9267. void updatePreferences(IEventListener const& reporterish);
  9268. public:
  9269. using IEventListener::IEventListener;
  9270. void addListener( IEventListenerPtr&& listener );
  9271. void addReporter( IEventListenerPtr&& reporter );
  9272. public: // IEventListener
  9273. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  9274. void fatalErrorEncountered( StringRef error ) override;
  9275. void reportInvalidTestSpec( StringRef arg ) override;
  9276. void benchmarkPreparing( StringRef name ) override;
  9277. void benchmarkStarting( BenchmarkInfo const& benchmarkInfo ) override;
  9278. void benchmarkEnded( BenchmarkStats<> const& benchmarkStats ) override;
  9279. void benchmarkFailed( StringRef error ) override;
  9280. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  9281. void testCaseStarting( TestCaseInfo const& testInfo ) override;
  9282. void testCasePartialStarting(TestCaseInfo const& testInfo, uint64_t partNumber) override;
  9283. void sectionStarting( SectionInfo const& sectionInfo ) override;
  9284. void assertionStarting( AssertionInfo const& assertionInfo ) override;
  9285. void assertionEnded( AssertionStats const& assertionStats ) override;
  9286. void sectionEnded( SectionStats const& sectionStats ) override;
  9287. void testCasePartialEnded(TestCaseStats const& testInfo, uint64_t partNumber) override;
  9288. void testCaseEnded( TestCaseStats const& testCaseStats ) override;
  9289. void testRunEnded( TestRunStats const& testRunStats ) override;
  9290. void skipTest( TestCaseInfo const& testInfo ) override;
  9291. void listReporters(std::vector<ReporterDescription> const& descriptions) override;
  9292. void listListeners(std::vector<ListenerDescription> const& descriptions) override;
  9293. void listTests(std::vector<TestCaseHandle> const& tests) override;
  9294. void listTags(std::vector<TagInfo> const& tags) override;
  9295. };
  9296. } // end namespace Catch
  9297. #endif // CATCH_REPORTER_MULTI_HPP_INCLUDED
  9298. #ifndef CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  9299. #define CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  9300. #include <type_traits>
  9301. namespace Catch {
  9302. namespace Detail {
  9303. template <typename T, typename = void>
  9304. struct has_description : std::false_type {};
  9305. template <typename T>
  9306. struct has_description<
  9307. T,
  9308. void_t<decltype( T::getDescription() )>>
  9309. : std::true_type {};
  9310. //! Indirection for reporter registration, so that the error handling is
  9311. //! independent on the reporter's concrete type
  9312. void registerReporterImpl( std::string const& name,
  9313. IReporterFactoryPtr reporterPtr );
  9314. } // namespace Detail
  9315. class IEventListener;
  9316. using IEventListenerPtr = Detail::unique_ptr<IEventListener>;
  9317. template <typename T>
  9318. class ReporterFactory : public IReporterFactory {
  9319. IEventListenerPtr create( ReporterConfig&& config ) const override {
  9320. return Detail::make_unique<T>( CATCH_MOVE(config) );
  9321. }
  9322. std::string getDescription() const override {
  9323. return T::getDescription();
  9324. }
  9325. };
  9326. template<typename T>
  9327. class ReporterRegistrar {
  9328. public:
  9329. explicit ReporterRegistrar( std::string const& name ) {
  9330. registerReporterImpl( name,
  9331. Detail::make_unique<ReporterFactory<T>>() );
  9332. }
  9333. };
  9334. template<typename T>
  9335. class ListenerRegistrar {
  9336. class TypedListenerFactory : public EventListenerFactory {
  9337. StringRef m_listenerName;
  9338. std::string getDescriptionImpl( std::true_type ) const {
  9339. return T::getDescription();
  9340. }
  9341. std::string getDescriptionImpl( std::false_type ) const {
  9342. return "(No description provided)";
  9343. }
  9344. public:
  9345. TypedListenerFactory( StringRef listenerName ):
  9346. m_listenerName( listenerName ) {}
  9347. IEventListenerPtr create( IConfig const* config ) const override {
  9348. return Detail::make_unique<T>( config );
  9349. }
  9350. StringRef getName() const override {
  9351. return m_listenerName;
  9352. }
  9353. std::string getDescription() const override {
  9354. return getDescriptionImpl( Detail::has_description<T>{} );
  9355. }
  9356. };
  9357. public:
  9358. ListenerRegistrar(StringRef listenerName) {
  9359. getMutableRegistryHub().registerListener( Detail::make_unique<TypedListenerFactory>(listenerName) );
  9360. }
  9361. };
  9362. }
  9363. #if !defined(CATCH_CONFIG_DISABLE)
  9364. # define CATCH_REGISTER_REPORTER( name, reporterType ) \
  9365. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  9366. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  9367. namespace { \
  9368. Catch::ReporterRegistrar<reporterType> INTERNAL_CATCH_UNIQUE_NAME( \
  9369. catch_internal_RegistrarFor )( name ); \
  9370. } \
  9371. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  9372. # define CATCH_REGISTER_LISTENER( listenerType ) \
  9373. CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
  9374. CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
  9375. namespace { \
  9376. Catch::ListenerRegistrar<listenerType> INTERNAL_CATCH_UNIQUE_NAME( \
  9377. catch_internal_RegistrarFor )( #listenerType ); \
  9378. } \
  9379. CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
  9380. #else // CATCH_CONFIG_DISABLE
  9381. #define CATCH_REGISTER_REPORTER(name, reporterType)
  9382. #define CATCH_REGISTER_LISTENER(listenerType)
  9383. #endif // CATCH_CONFIG_DISABLE
  9384. #endif // CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  9385. #ifndef CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  9386. #define CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  9387. namespace Catch {
  9388. class SonarQubeReporter final : public CumulativeReporterBase {
  9389. public:
  9390. SonarQubeReporter(ReporterConfig&& config)
  9391. : CumulativeReporterBase(CATCH_MOVE(config))
  9392. , xml(m_stream) {
  9393. m_preferences.shouldRedirectStdOut = true;
  9394. m_preferences.shouldReportAllAssertions = true;
  9395. m_shouldStoreSuccesfulAssertions = false;
  9396. }
  9397. ~SonarQubeReporter() override = default;
  9398. static std::string getDescription() {
  9399. using namespace std::string_literals;
  9400. return "Reports test results in the Generic Test Data SonarQube XML format"s;
  9401. }
  9402. void testRunStarting( TestRunInfo const& testRunInfo ) override;
  9403. void testRunEndedCumulative() override {
  9404. writeRun( *m_testRun );
  9405. xml.endElement();
  9406. }
  9407. void writeRun( TestRunNode const& groupNode );
  9408. void writeTestFile(std::string const& filename, std::vector<TestCaseNode const*> const& testCaseNodes);
  9409. void writeTestCase(TestCaseNode const& testCaseNode);
  9410. void writeSection(std::string const& rootName, SectionNode const& sectionNode, bool okToFail);
  9411. void writeAssertions(SectionNode const& sectionNode, bool okToFail);
  9412. void writeAssertion(AssertionStats const& stats, bool okToFail);
  9413. private:
  9414. XmlWriter xml;
  9415. };
  9416. } // end namespace Catch
  9417. #endif // CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
  9418. #ifndef CATCH_REPORTER_TAP_HPP_INCLUDED
  9419. #define CATCH_REPORTER_TAP_HPP_INCLUDED
  9420. namespace Catch {
  9421. class TAPReporter final : public StreamingReporterBase {
  9422. public:
  9423. TAPReporter( ReporterConfig&& config ):
  9424. StreamingReporterBase( CATCH_MOVE(config) ) {
  9425. m_preferences.shouldReportAllAssertions = true;
  9426. }
  9427. ~TAPReporter() override = default;
  9428. static std::string getDescription() {
  9429. using namespace std::string_literals;
  9430. return "Reports test results in TAP format, suitable for test harnesses"s;
  9431. }
  9432. void testRunStarting( TestRunInfo const& testInfo ) override;
  9433. void noMatchingTestCases( StringRef unmatchedSpec ) override;
  9434. void assertionEnded(AssertionStats const& _assertionStats) override;
  9435. void testRunEnded(TestRunStats const& _testRunStats) override;
  9436. private:
  9437. std::size_t counter = 0;
  9438. };
  9439. } // end namespace Catch
  9440. #endif // CATCH_REPORTER_TAP_HPP_INCLUDED
  9441. #ifndef CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  9442. #define CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  9443. #include <cstring>
  9444. #ifdef __clang__
  9445. # pragma clang diagnostic push
  9446. # pragma clang diagnostic ignored "-Wpadded"
  9447. #endif
  9448. namespace Catch {
  9449. class TeamCityReporter final : public StreamingReporterBase {
  9450. public:
  9451. TeamCityReporter( ReporterConfig&& _config )
  9452. : StreamingReporterBase( CATCH_MOVE(_config) )
  9453. {
  9454. m_preferences.shouldRedirectStdOut = true;
  9455. }
  9456. ~TeamCityReporter() override;
  9457. static std::string getDescription() {
  9458. using namespace std::string_literals;
  9459. return "Reports test results as TeamCity service messages"s;
  9460. }
  9461. void testRunStarting( TestRunInfo const& groupInfo ) override;
  9462. void testRunEnded( TestRunStats const& testGroupStats ) override;
  9463. void assertionEnded(AssertionStats const& assertionStats) override;
  9464. void sectionStarting(SectionInfo const& sectionInfo) override {
  9465. m_headerPrintedForThisSection = false;
  9466. StreamingReporterBase::sectionStarting( sectionInfo );
  9467. }
  9468. void testCaseStarting(TestCaseInfo const& testInfo) override;
  9469. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  9470. private:
  9471. void printSectionHeader(std::ostream& os);
  9472. bool m_headerPrintedForThisSection = false;
  9473. Timer m_testTimer;
  9474. };
  9475. } // end namespace Catch
  9476. #ifdef __clang__
  9477. # pragma clang diagnostic pop
  9478. #endif
  9479. #endif // CATCH_REPORTER_TEAMCITY_HPP_INCLUDED
  9480. #ifndef CATCH_REPORTER_XML_HPP_INCLUDED
  9481. #define CATCH_REPORTER_XML_HPP_INCLUDED
  9482. namespace Catch {
  9483. class XmlReporter : public StreamingReporterBase {
  9484. public:
  9485. XmlReporter(ReporterConfig&& _config);
  9486. ~XmlReporter() override;
  9487. static std::string getDescription();
  9488. virtual std::string getStylesheetRef() const;
  9489. void writeSourceInfo(SourceLineInfo const& sourceInfo);
  9490. public: // StreamingReporterBase
  9491. void testRunStarting(TestRunInfo const& testInfo) override;
  9492. void testCaseStarting(TestCaseInfo const& testInfo) override;
  9493. void sectionStarting(SectionInfo const& sectionInfo) override;
  9494. void assertionStarting(AssertionInfo const&) override;
  9495. void assertionEnded(AssertionStats const& assertionStats) override;
  9496. void sectionEnded(SectionStats const& sectionStats) override;
  9497. void testCaseEnded(TestCaseStats const& testCaseStats) override;
  9498. void testRunEnded(TestRunStats const& testRunStats) override;
  9499. void benchmarkPreparing( StringRef name ) override;
  9500. void benchmarkStarting(BenchmarkInfo const&) override;
  9501. void benchmarkEnded(BenchmarkStats<> const&) override;
  9502. void benchmarkFailed( StringRef error ) override;
  9503. void listReporters(std::vector<ReporterDescription> const& descriptions) override;
  9504. void listListeners(std::vector<ListenerDescription> const& descriptions) override;
  9505. void listTests(std::vector<TestCaseHandle> const& tests) override;
  9506. void listTags(std::vector<TagInfo> const& tags) override;
  9507. private:
  9508. Timer m_testCaseTimer;
  9509. XmlWriter m_xml;
  9510. int m_sectionDepth = 0;
  9511. };
  9512. } // end namespace Catch
  9513. #endif // CATCH_REPORTER_XML_HPP_INCLUDED
  9514. #endif // CATCH_REPORTERS_ALL_HPP_INCLUDED
  9515. #endif // CATCH_ALL_HPP_INCLUDED
  9516. #endif // CATCH_AMALGAMATED_HPP_INCLUDED