catch.hpp 419 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826
  1. /*
  2. * Catch v1.12.2
  3. * Generated: 2023-01-17 08:45:40.979381
  4. * ----------------------------------------------------------
  5. * This file has been merged from multiple headers. Please don't edit it directly
  6. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
  7. *
  8. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. */
  11. #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  12. #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  13. #define TWOBLUECUBES_CATCH_HPP_INCLUDED
  14. #ifdef __clang__
  15. # pragma clang system_header
  16. #elif defined __GNUC__
  17. # pragma GCC system_header
  18. #endif
  19. // #included from: internal/catch_suppress_warnings.h
  20. #ifdef __clang__
  21. # ifdef __ICC // icpc defines the __clang__ macro
  22. # pragma warning(push)
  23. # pragma warning(disable: 161 1682)
  24. # else // __ICC
  25. # pragma clang diagnostic ignored "-Wglobal-constructors"
  26. # pragma clang diagnostic ignored "-Wvariadic-macros"
  27. # pragma clang diagnostic ignored "-Wc99-extensions"
  28. # pragma clang diagnostic ignored "-Wunused-variable"
  29. # pragma clang diagnostic push
  30. # pragma clang diagnostic ignored "-Wpadded"
  31. # pragma clang diagnostic ignored "-Wc++98-compat"
  32. # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
  33. # pragma clang diagnostic ignored "-Wswitch-enum"
  34. # pragma clang diagnostic ignored "-Wcovered-switch-default"
  35. # endif
  36. #elif defined __GNUC__
  37. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  38. # pragma GCC diagnostic ignored "-Wunused-variable"
  39. # pragma GCC diagnostic ignored "-Wparentheses"
  40. # pragma GCC diagnostic push
  41. # pragma GCC diagnostic ignored "-Wpadded"
  42. #endif
  43. #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
  44. # define CATCH_IMPL
  45. #endif
  46. #ifdef CATCH_IMPL
  47. # ifndef CLARA_CONFIG_MAIN
  48. # define CLARA_CONFIG_MAIN_NOT_DEFINED
  49. # define CLARA_CONFIG_MAIN
  50. # endif
  51. #endif
  52. // #included from: internal/catch_notimplemented_exception.h
  53. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
  54. // #included from: catch_common.h
  55. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  56. // #included from: catch_compiler_capabilities.h
  57. #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  58. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  59. // The following features are defined:
  60. //
  61. // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
  62. // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  63. // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  64. // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
  65. // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
  66. // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
  67. // CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
  68. // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  69. // CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
  70. // CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
  71. // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  72. // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  73. // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
  74. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  75. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  76. // ****************
  77. // Note to maintainers: if new toggles are added please document them
  78. // in configuration.md, too
  79. // ****************
  80. // In general each macro has a _NO_<feature name> form
  81. // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  82. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  83. // can be combined, en-mass, with the _NO_ forms later.
  84. // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
  85. #ifdef __cplusplus
  86. # if __cplusplus >= 201103L
  87. # define CATCH_CPP11_OR_GREATER
  88. # endif
  89. # if __cplusplus >= 201402L
  90. # define CATCH_CPP14_OR_GREATER
  91. # endif
  92. #endif
  93. #ifdef __clang__
  94. # if __has_feature(cxx_nullptr)
  95. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  96. # endif
  97. # if __has_feature(cxx_noexcept)
  98. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  99. # endif
  100. # if defined(CATCH_CPP11_OR_GREATER)
  101. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  102. _Pragma( "clang diagnostic push" ) \
  103. _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" )
  104. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  105. _Pragma( "clang diagnostic pop" )
  106. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  107. _Pragma( "clang diagnostic push" ) \
  108. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  109. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  110. _Pragma( "clang diagnostic pop" )
  111. # endif
  112. #endif // __clang__
  113. ////////////////////////////////////////////////////////////////////////////////
  114. // We know some environments not to support full POSIX signals
  115. #if defined(__CYGWIN__) || defined(__QNX__)
  116. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  117. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  118. # endif
  119. #endif
  120. #ifdef __OS400__
  121. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  122. # define CATCH_CONFIG_COLOUR_NONE
  123. #endif
  124. ////////////////////////////////////////////////////////////////////////////////
  125. // Cygwin
  126. #ifdef __CYGWIN__
  127. // Required for some versions of Cygwin to declare gettimeofday
  128. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  129. # define _BSD_SOURCE
  130. #endif // __CYGWIN__
  131. ////////////////////////////////////////////////////////////////////////////////
  132. // Borland
  133. #ifdef __BORLANDC__
  134. #endif // __BORLANDC__
  135. ////////////////////////////////////////////////////////////////////////////////
  136. // EDG
  137. #ifdef __EDG_VERSION__
  138. #endif // __EDG_VERSION__
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // Digital Mars
  141. #ifdef __DMC__
  142. #endif // __DMC__
  143. ////////////////////////////////////////////////////////////////////////////////
  144. // GCC
  145. #ifdef __GNUC__
  146. # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  147. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  148. # endif
  149. // - otherwise more recent versions define __cplusplus >= 201103L
  150. // and will get picked up below
  151. #endif // __GNUC__
  152. ////////////////////////////////////////////////////////////////////////////////
  153. // Visual C++
  154. #ifdef _MSC_VER
  155. #define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  156. #if (_MSC_VER >= 1600)
  157. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  158. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  159. #endif
  160. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  161. #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  162. #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  163. #define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  164. #define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  165. #endif
  166. #endif // _MSC_VER
  167. ////////////////////////////////////////////////////////////////////////////////
  168. // Use variadic macros if the compiler supports them
  169. #if ( defined _MSC_VER && _MSC_VER >= 1400 && !defined __EDGE__) || \
  170. ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
  171. ( defined __GNUC__ && __GNUC__ >= 3 ) || \
  172. ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
  173. #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  174. #endif
  175. // Use __COUNTER__ if the compiler supports it
  176. #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
  177. ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \
  178. ( defined __clang__ && __clang_major__ >= 3 )
  179. // Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former,
  180. // because __COUNTER__ is not properly handled by it.
  181. // This does not affect compilation
  182. #if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L )
  183. #define CATCH_INTERNAL_CONFIG_COUNTER
  184. #endif
  185. #endif
  186. ////////////////////////////////////////////////////////////////////////////////
  187. // C++ language feature support
  188. // catch all support for C++11
  189. #if defined(CATCH_CPP11_OR_GREATER)
  190. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
  191. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  192. # endif
  193. # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  194. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  195. # endif
  196. # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  197. # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  198. # endif
  199. # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  200. # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  201. # endif
  202. # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  203. # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  204. # endif
  205. # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  206. # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  207. # endif
  208. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
  209. # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
  210. # endif
  211. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
  212. # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
  213. # endif
  214. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  215. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  216. # endif
  217. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
  218. # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  219. # endif
  220. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
  221. # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  222. # endif
  223. #endif // __cplusplus >= 201103L
  224. // Now set the actual defines based on the above + anything the user has configured
  225. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
  226. # define CATCH_CONFIG_CPP11_NULLPTR
  227. #endif
  228. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
  229. # define CATCH_CONFIG_CPP11_NOEXCEPT
  230. #endif
  231. #if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11)
  232. # define CATCH_CONFIG_CPP11_GENERATED_METHODS
  233. #endif
  234. #if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11)
  235. # define CATCH_CONFIG_CPP11_IS_ENUM
  236. #endif
  237. #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
  238. # define CATCH_CONFIG_CPP11_TUPLE
  239. #endif
  240. #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
  241. # define CATCH_CONFIG_VARIADIC_MACROS
  242. #endif
  243. #if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11)
  244. # define CATCH_CONFIG_CPP11_LONG_LONG
  245. #endif
  246. #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
  247. # define CATCH_CONFIG_CPP11_OVERRIDE
  248. #endif
  249. #if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11)
  250. # define CATCH_CONFIG_CPP11_UNIQUE_PTR
  251. #endif
  252. #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
  253. # define CATCH_CONFIG_COUNTER
  254. #endif
  255. #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
  256. # define CATCH_CONFIG_CPP11_SHUFFLE
  257. #endif
  258. # if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11)
  259. # define CATCH_CONFIG_CPP11_TYPE_TRAITS
  260. # endif
  261. #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
  262. # define CATCH_CONFIG_WINDOWS_SEH
  263. #endif
  264. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  265. #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
  266. # define CATCH_CONFIG_POSIX_SIGNALS
  267. #endif
  268. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  269. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  270. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
  271. #endif
  272. #if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
  273. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  274. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  275. #endif
  276. // noexcept support:
  277. #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
  278. # define CATCH_NOEXCEPT noexcept
  279. # define CATCH_NOEXCEPT_IS(x) noexcept(x)
  280. #else
  281. # define CATCH_NOEXCEPT throw()
  282. # define CATCH_NOEXCEPT_IS(x)
  283. #endif
  284. // nullptr support
  285. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  286. # define CATCH_NULL nullptr
  287. #else
  288. # define CATCH_NULL NULL
  289. #endif
  290. // override support
  291. #ifdef CATCH_CONFIG_CPP11_OVERRIDE
  292. # define CATCH_OVERRIDE override
  293. #else
  294. # define CATCH_OVERRIDE
  295. #endif
  296. // unique_ptr support
  297. #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
  298. # define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
  299. #else
  300. # define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
  301. #endif
  302. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  303. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  304. #ifdef CATCH_CONFIG_COUNTER
  305. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  306. #else
  307. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  308. #endif
  309. #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
  310. #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
  311. #include <sstream>
  312. #include <algorithm>
  313. namespace Catch {
  314. struct IConfig;
  315. struct CaseSensitive { enum Choice {
  316. Yes,
  317. No
  318. }; };
  319. class NonCopyable {
  320. #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  321. NonCopyable( NonCopyable const& ) = delete;
  322. NonCopyable( NonCopyable && ) = delete;
  323. NonCopyable& operator = ( NonCopyable const& ) = delete;
  324. NonCopyable& operator = ( NonCopyable && ) = delete;
  325. #else
  326. NonCopyable( NonCopyable const& info );
  327. NonCopyable& operator = ( NonCopyable const& );
  328. #endif
  329. protected:
  330. NonCopyable() {}
  331. virtual ~NonCopyable();
  332. };
  333. class SafeBool {
  334. public:
  335. typedef void (SafeBool::*type)() const;
  336. static type makeSafe( bool value ) {
  337. return value ? &SafeBool::trueValue : 0;
  338. }
  339. private:
  340. void trueValue() const {}
  341. };
  342. template<typename ContainerT>
  343. void deleteAll( ContainerT& container ) {
  344. typename ContainerT::const_iterator it = container.begin();
  345. typename ContainerT::const_iterator itEnd = container.end();
  346. for(; it != itEnd; ++it )
  347. delete *it;
  348. }
  349. template<typename AssociativeContainerT>
  350. void deleteAllValues( AssociativeContainerT& container ) {
  351. typename AssociativeContainerT::const_iterator it = container.begin();
  352. typename AssociativeContainerT::const_iterator itEnd = container.end();
  353. for(; it != itEnd; ++it )
  354. delete it->second;
  355. }
  356. bool startsWith( std::string const& s, std::string const& prefix );
  357. bool startsWith( std::string const& s, char prefix );
  358. bool endsWith( std::string const& s, std::string const& suffix );
  359. bool endsWith( std::string const& s, char suffix );
  360. bool contains( std::string const& s, std::string const& infix );
  361. void toLowerInPlace( std::string& s );
  362. std::string toLower( std::string const& s );
  363. std::string trim( std::string const& str );
  364. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  365. struct pluralise {
  366. pluralise( std::size_t count, std::string const& label );
  367. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  368. std::size_t m_count;
  369. std::string m_label;
  370. };
  371. struct SourceLineInfo {
  372. SourceLineInfo();
  373. SourceLineInfo( char const* _file, std::size_t _line );
  374. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  375. SourceLineInfo(SourceLineInfo const& other) = default;
  376. SourceLineInfo( SourceLineInfo && ) = default;
  377. SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
  378. SourceLineInfo& operator = ( SourceLineInfo && ) = default;
  379. # endif
  380. bool empty() const;
  381. bool operator == ( SourceLineInfo const& other ) const;
  382. bool operator < ( SourceLineInfo const& other ) const;
  383. char const* file;
  384. std::size_t line;
  385. };
  386. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
  387. // This is just here to avoid compiler warnings with macro constants and boolean literals
  388. inline bool isTrue( bool value ){ return value; }
  389. inline bool alwaysTrue() { return true; }
  390. inline bool alwaysFalse() { return false; }
  391. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
  392. void seedRng( IConfig const& config );
  393. unsigned int rngSeed();
  394. // Use this in variadic streaming macros to allow
  395. // >> +StreamEndStop
  396. // as well as
  397. // >> stuff +StreamEndStop
  398. struct StreamEndStop {
  399. std::string operator+() {
  400. return std::string();
  401. }
  402. };
  403. template<typename T>
  404. T const& operator + ( T const& value, StreamEndStop ) {
  405. return value;
  406. }
  407. }
  408. #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  409. #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
  410. namespace Catch {
  411. class NotImplementedException : public std::exception
  412. {
  413. public:
  414. NotImplementedException( SourceLineInfo const& lineInfo );
  415. virtual ~NotImplementedException() CATCH_NOEXCEPT {}
  416. virtual const char* what() const CATCH_NOEXCEPT;
  417. private:
  418. std::string m_what;
  419. SourceLineInfo m_lineInfo;
  420. };
  421. } // end namespace Catch
  422. ///////////////////////////////////////////////////////////////////////////////
  423. #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
  424. // #included from: internal/catch_context.h
  425. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  426. // #included from: catch_interfaces_generators.h
  427. #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
  428. #include <string>
  429. namespace Catch {
  430. struct IGeneratorInfo {
  431. virtual ~IGeneratorInfo();
  432. virtual bool moveNext() = 0;
  433. virtual std::size_t getCurrentIndex() const = 0;
  434. };
  435. struct IGeneratorsForTest {
  436. virtual ~IGeneratorsForTest();
  437. virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
  438. virtual bool moveNext() = 0;
  439. };
  440. IGeneratorsForTest* createGeneratorsForTest();
  441. } // end namespace Catch
  442. // #included from: catch_ptr.hpp
  443. #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
  444. #ifdef __clang__
  445. #pragma clang diagnostic push
  446. #pragma clang diagnostic ignored "-Wpadded"
  447. #endif
  448. namespace Catch {
  449. // An intrusive reference counting smart pointer.
  450. // T must implement addRef() and release() methods
  451. // typically implementing the IShared interface
  452. template<typename T>
  453. class Ptr {
  454. public:
  455. Ptr() : m_p( CATCH_NULL ){}
  456. Ptr( T* p ) : m_p( p ){
  457. if( m_p )
  458. m_p->addRef();
  459. }
  460. Ptr( Ptr const& other ) : m_p( other.m_p ){
  461. if( m_p )
  462. m_p->addRef();
  463. }
  464. ~Ptr(){
  465. if( m_p )
  466. m_p->release();
  467. }
  468. void reset() {
  469. if( m_p )
  470. m_p->release();
  471. m_p = CATCH_NULL;
  472. }
  473. Ptr& operator = ( T* p ){
  474. Ptr temp( p );
  475. swap( temp );
  476. return *this;
  477. }
  478. Ptr& operator = ( Ptr const& other ){
  479. Ptr temp( other );
  480. swap( temp );
  481. return *this;
  482. }
  483. void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
  484. T* get() const{ return m_p; }
  485. T& operator*() const { return *m_p; }
  486. T* operator->() const { return m_p; }
  487. bool operator !() const { return m_p == CATCH_NULL; }
  488. operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
  489. private:
  490. T* m_p;
  491. };
  492. struct IShared : NonCopyable {
  493. virtual ~IShared();
  494. virtual void addRef() const = 0;
  495. virtual void release() const = 0;
  496. };
  497. template<typename T = IShared>
  498. struct SharedImpl : T {
  499. SharedImpl() : m_rc( 0 ){}
  500. virtual void addRef() const {
  501. ++m_rc;
  502. }
  503. virtual void release() const {
  504. if( --m_rc == 0 )
  505. delete this;
  506. }
  507. mutable unsigned int m_rc;
  508. };
  509. } // end namespace Catch
  510. #ifdef __clang__
  511. #pragma clang diagnostic pop
  512. #endif
  513. namespace Catch {
  514. class TestCase;
  515. class Stream;
  516. struct IResultCapture;
  517. struct IRunner;
  518. struct IGeneratorsForTest;
  519. struct IConfig;
  520. struct IContext
  521. {
  522. virtual ~IContext();
  523. virtual IResultCapture* getResultCapture() = 0;
  524. virtual IRunner* getRunner() = 0;
  525. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
  526. virtual bool advanceGeneratorsForCurrentTest() = 0;
  527. virtual Ptr<IConfig const> getConfig() const = 0;
  528. };
  529. struct IMutableContext : IContext
  530. {
  531. virtual ~IMutableContext();
  532. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  533. virtual void setRunner( IRunner* runner ) = 0;
  534. virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
  535. };
  536. IContext& getCurrentContext();
  537. IMutableContext& getCurrentMutableContext();
  538. void cleanUpContext();
  539. Stream createStream( std::string const& streamName );
  540. }
  541. // #included from: internal/catch_test_registry.hpp
  542. #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
  543. // #included from: catch_interfaces_testcase.h
  544. #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
  545. #include <vector>
  546. namespace Catch {
  547. class TestSpec;
  548. struct ITestCase : IShared {
  549. virtual void invoke () const = 0;
  550. protected:
  551. virtual ~ITestCase();
  552. };
  553. class TestCase;
  554. struct IConfig;
  555. struct ITestCaseRegistry {
  556. virtual ~ITestCaseRegistry();
  557. virtual std::vector<TestCase> const& getAllTests() const = 0;
  558. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
  559. };
  560. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
  561. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
  562. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
  563. }
  564. namespace Catch {
  565. template<typename C>
  566. class MethodTestCase : public SharedImpl<ITestCase> {
  567. public:
  568. MethodTestCase( void (C::*method)() ) : m_method( method ) {}
  569. virtual void invoke() const {
  570. C obj;
  571. (obj.*m_method)();
  572. }
  573. private:
  574. virtual ~MethodTestCase() {}
  575. void (C::*m_method)();
  576. };
  577. typedef void(*TestFunction)();
  578. struct NameAndDesc {
  579. NameAndDesc( const char* _name = "", const char* _description= "" )
  580. : name( _name ), description( _description )
  581. {}
  582. const char* name;
  583. const char* description;
  584. };
  585. void registerTestCase
  586. ( ITestCase* testCase,
  587. char const* className,
  588. NameAndDesc const& nameAndDesc,
  589. SourceLineInfo const& lineInfo );
  590. struct AutoReg {
  591. AutoReg
  592. ( TestFunction function,
  593. SourceLineInfo const& lineInfo,
  594. NameAndDesc const& nameAndDesc );
  595. template<typename C>
  596. AutoReg
  597. ( void (C::*method)(),
  598. char const* className,
  599. NameAndDesc const& nameAndDesc,
  600. SourceLineInfo const& lineInfo ) {
  601. registerTestCase
  602. ( new MethodTestCase<C>( method ),
  603. className,
  604. nameAndDesc,
  605. lineInfo );
  606. }
  607. ~AutoReg();
  608. private:
  609. AutoReg( AutoReg const& );
  610. void operator= ( AutoReg const& );
  611. };
  612. void registerTestCaseFunction
  613. ( TestFunction function,
  614. SourceLineInfo const& lineInfo,
  615. NameAndDesc const& nameAndDesc );
  616. } // end namespace Catch
  617. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  618. ///////////////////////////////////////////////////////////////////////////////
  619. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  620. static void TestName(); \
  621. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  622. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); } /* NOLINT */ \
  623. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  624. static void TestName()
  625. #define INTERNAL_CATCH_TESTCASE( ... ) \
  626. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
  627. ///////////////////////////////////////////////////////////////////////////////
  628. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  629. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  630. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  631. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  632. ///////////////////////////////////////////////////////////////////////////////
  633. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  634. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  635. namespace{ \
  636. struct TestName : ClassName{ \
  637. void test(); \
  638. }; \
  639. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  640. } \
  641. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  642. void TestName::test()
  643. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  644. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
  645. ///////////////////////////////////////////////////////////////////////////////
  646. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  647. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  648. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); /* NOLINT */ \
  649. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  650. #else
  651. ///////////////////////////////////////////////////////////////////////////////
  652. #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
  653. static void TestName(); \
  654. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  655. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); } /* NOLINT */ \
  656. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  657. static void TestName()
  658. #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
  659. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
  660. ///////////////////////////////////////////////////////////////////////////////
  661. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
  662. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  663. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  664. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  665. ///////////////////////////////////////////////////////////////////////////////
  666. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
  667. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  668. namespace{ \
  669. struct TestCaseName : ClassName{ \
  670. void test(); \
  671. }; \
  672. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  673. } \
  674. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  675. void TestCaseName::test()
  676. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
  677. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
  678. ///////////////////////////////////////////////////////////////////////////////
  679. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
  680. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  681. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); /* NOLINT */ \
  682. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  683. #endif
  684. // #included from: internal/catch_capture.hpp
  685. #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
  686. // #included from: catch_result_builder.h
  687. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
  688. // #included from: catch_result_type.h
  689. #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
  690. namespace Catch {
  691. // ResultWas::OfType enum
  692. struct ResultWas { enum OfType {
  693. Unknown = -1,
  694. Ok = 0,
  695. Info = 1,
  696. Warning = 2,
  697. FailureBit = 0x10,
  698. ExpressionFailed = FailureBit | 1,
  699. ExplicitFailure = FailureBit | 2,
  700. Exception = 0x100 | FailureBit,
  701. ThrewException = Exception | 1,
  702. DidntThrowException = Exception | 2,
  703. FatalErrorCondition = 0x200 | FailureBit
  704. }; };
  705. inline bool isOk( ResultWas::OfType resultType ) {
  706. return ( resultType & ResultWas::FailureBit ) == 0;
  707. }
  708. inline bool isJustInfo( int flags ) {
  709. return flags == ResultWas::Info;
  710. }
  711. // ResultDisposition::Flags enum
  712. struct ResultDisposition { enum Flags {
  713. Normal = 0x01,
  714. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  715. FalseTest = 0x04, // Prefix expression with !
  716. SuppressFail = 0x08 // Failures are reported but do not fail the test
  717. }; };
  718. inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
  719. return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
  720. }
  721. inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
  722. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  723. inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
  724. } // end namespace Catch
  725. // #included from: catch_assertionresult.h
  726. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
  727. #include <string>
  728. namespace Catch {
  729. struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
  730. struct DecomposedExpression
  731. {
  732. virtual ~DecomposedExpression() {}
  733. virtual bool isBinaryExpression() const {
  734. return false;
  735. }
  736. virtual void reconstructExpression( std::string& dest ) const = 0;
  737. // Only simple binary comparisons can be decomposed.
  738. // If more complex check is required then wrap sub-expressions in parentheses.
  739. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& );
  740. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& );
  741. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& );
  742. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& );
  743. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& );
  744. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& );
  745. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& );
  746. private:
  747. DecomposedExpression& operator = (DecomposedExpression const&);
  748. };
  749. struct AssertionInfo
  750. {
  751. AssertionInfo();
  752. AssertionInfo( char const * _macroName,
  753. SourceLineInfo const& _lineInfo,
  754. char const * _capturedExpression,
  755. ResultDisposition::Flags _resultDisposition,
  756. char const * _secondArg = "");
  757. char const * macroName;
  758. SourceLineInfo lineInfo;
  759. char const * capturedExpression;
  760. ResultDisposition::Flags resultDisposition;
  761. char const * secondArg;
  762. };
  763. struct AssertionResultData
  764. {
  765. AssertionResultData() : decomposedExpression( CATCH_NULL )
  766. , resultType( ResultWas::Unknown )
  767. , negated( false )
  768. , parenthesized( false ) {}
  769. void negate( bool parenthesize ) {
  770. negated = !negated;
  771. parenthesized = parenthesize;
  772. if( resultType == ResultWas::Ok )
  773. resultType = ResultWas::ExpressionFailed;
  774. else if( resultType == ResultWas::ExpressionFailed )
  775. resultType = ResultWas::Ok;
  776. }
  777. std::string const& reconstructExpression() const {
  778. if( decomposedExpression != CATCH_NULL ) {
  779. decomposedExpression->reconstructExpression( reconstructedExpression );
  780. if( parenthesized ) {
  781. reconstructedExpression.insert( 0, 1, '(' );
  782. reconstructedExpression.append( 1, ')' );
  783. }
  784. if( negated ) {
  785. reconstructedExpression.insert( 0, 1, '!' );
  786. }
  787. decomposedExpression = CATCH_NULL;
  788. }
  789. return reconstructedExpression;
  790. }
  791. mutable DecomposedExpression const* decomposedExpression;
  792. mutable std::string reconstructedExpression;
  793. std::string message;
  794. ResultWas::OfType resultType;
  795. bool negated;
  796. bool parenthesized;
  797. };
  798. class AssertionResult {
  799. public:
  800. AssertionResult();
  801. AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
  802. ~AssertionResult();
  803. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  804. AssertionResult( AssertionResult const& ) = default;
  805. AssertionResult( AssertionResult && ) = default;
  806. AssertionResult& operator = ( AssertionResult const& ) = default;
  807. AssertionResult& operator = ( AssertionResult && ) = default;
  808. # endif
  809. bool isOk() const;
  810. bool succeeded() const;
  811. ResultWas::OfType getResultType() const;
  812. bool hasExpression() const;
  813. bool hasMessage() const;
  814. std::string getExpression() const;
  815. std::string getExpressionInMacro() const;
  816. bool hasExpandedExpression() const;
  817. std::string getExpandedExpression() const;
  818. std::string getMessage() const;
  819. SourceLineInfo getSourceInfo() const;
  820. std::string getTestMacroName() const;
  821. void discardDecomposedExpression() const;
  822. void expandDecomposedExpression() const;
  823. protected:
  824. AssertionInfo m_info;
  825. AssertionResultData m_resultData;
  826. };
  827. } // end namespace Catch
  828. // #included from: catch_matchers.hpp
  829. #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
  830. namespace Catch {
  831. namespace Matchers {
  832. namespace Impl {
  833. template<typename ArgT> struct MatchAllOf;
  834. template<typename ArgT> struct MatchAnyOf;
  835. template<typename ArgT> struct MatchNotOf;
  836. class MatcherUntypedBase {
  837. public:
  838. std::string toString() const {
  839. if( m_cachedToString.empty() )
  840. m_cachedToString = describe();
  841. return m_cachedToString;
  842. }
  843. protected:
  844. virtual ~MatcherUntypedBase();
  845. virtual std::string describe() const = 0;
  846. mutable std::string m_cachedToString;
  847. private:
  848. MatcherUntypedBase& operator = ( MatcherUntypedBase const& );
  849. };
  850. template<typename ObjectT>
  851. struct MatcherMethod {
  852. virtual bool match( ObjectT const& arg ) const = 0;
  853. };
  854. template<typename PtrT>
  855. struct MatcherMethod<PtrT*> {
  856. virtual bool match( PtrT* arg ) const = 0;
  857. };
  858. template<typename ObjectT, typename ComparatorT = ObjectT>
  859. struct MatcherBase : MatcherUntypedBase, MatcherMethod<ObjectT> {
  860. MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
  861. MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
  862. MatchNotOf<ComparatorT> operator ! () const;
  863. };
  864. template<typename ArgT>
  865. struct MatchAllOf : MatcherBase<ArgT> {
  866. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  867. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  868. if (!m_matchers[i]->match(arg))
  869. return false;
  870. }
  871. return true;
  872. }
  873. virtual std::string describe() const CATCH_OVERRIDE {
  874. std::string description;
  875. description.reserve( 4 + m_matchers.size()*32 );
  876. description += "( ";
  877. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  878. if( i != 0 )
  879. description += " and ";
  880. description += m_matchers[i]->toString();
  881. }
  882. description += " )";
  883. return description;
  884. }
  885. MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
  886. m_matchers.push_back( &other );
  887. return *this;
  888. }
  889. std::vector<MatcherBase<ArgT> const*> m_matchers;
  890. };
  891. template<typename ArgT>
  892. struct MatchAnyOf : MatcherBase<ArgT> {
  893. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  894. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  895. if (m_matchers[i]->match(arg))
  896. return true;
  897. }
  898. return false;
  899. }
  900. virtual std::string describe() const CATCH_OVERRIDE {
  901. std::string description;
  902. description.reserve( 4 + m_matchers.size()*32 );
  903. description += "( ";
  904. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  905. if( i != 0 )
  906. description += " or ";
  907. description += m_matchers[i]->toString();
  908. }
  909. description += " )";
  910. return description;
  911. }
  912. MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
  913. m_matchers.push_back( &other );
  914. return *this;
  915. }
  916. std::vector<MatcherBase<ArgT> const*> m_matchers;
  917. };
  918. template<typename ArgT>
  919. struct MatchNotOf : MatcherBase<ArgT> {
  920. MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
  921. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  922. return !m_underlyingMatcher.match( arg );
  923. }
  924. virtual std::string describe() const CATCH_OVERRIDE {
  925. return "not " + m_underlyingMatcher.toString();
  926. }
  927. MatcherBase<ArgT> const& m_underlyingMatcher;
  928. };
  929. template<typename ObjectT, typename ComparatorT>
  930. MatchAllOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator && ( MatcherBase const& other ) const {
  931. return MatchAllOf<ComparatorT>() && *this && other;
  932. }
  933. template<typename ObjectT, typename ComparatorT>
  934. MatchAnyOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator || ( MatcherBase const& other ) const {
  935. return MatchAnyOf<ComparatorT>() || *this || other;
  936. }
  937. template<typename ObjectT, typename ComparatorT>
  938. MatchNotOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator ! () const {
  939. return MatchNotOf<ComparatorT>( *this );
  940. }
  941. } // namespace Impl
  942. // The following functions create the actual matcher objects.
  943. // This allows the types to be inferred
  944. // - deprecated: prefer ||, && and !
  945. template<typename T>
  946. Impl::MatchNotOf<T> Not( Impl::MatcherBase<T> const& underlyingMatcher ) {
  947. return Impl::MatchNotOf<T>( underlyingMatcher );
  948. }
  949. template<typename T>
  950. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  951. return Impl::MatchAllOf<T>() && m1 && m2;
  952. }
  953. template<typename T>
  954. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  955. return Impl::MatchAllOf<T>() && m1 && m2 && m3;
  956. }
  957. template<typename T>
  958. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  959. return Impl::MatchAnyOf<T>() || m1 || m2;
  960. }
  961. template<typename T>
  962. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  963. return Impl::MatchAnyOf<T>() || m1 || m2 || m3;
  964. }
  965. } // namespace Matchers
  966. using namespace Matchers;
  967. using Matchers::Impl::MatcherBase;
  968. } // namespace Catch
  969. namespace Catch {
  970. struct TestFailureException{};
  971. template<typename T> class ExpressionLhs;
  972. struct CopyableStream {
  973. CopyableStream() {}
  974. CopyableStream( CopyableStream const& other ) {
  975. oss << other.oss.str();
  976. }
  977. CopyableStream& operator=( CopyableStream const& other ) {
  978. oss.str(std::string());
  979. oss << other.oss.str();
  980. return *this;
  981. }
  982. std::ostringstream oss;
  983. };
  984. class ResultBuilder : public DecomposedExpression {
  985. public:
  986. ResultBuilder( char const* macroName,
  987. SourceLineInfo const& lineInfo,
  988. char const* capturedExpression,
  989. ResultDisposition::Flags resultDisposition,
  990. char const* secondArg = "" );
  991. ~ResultBuilder();
  992. template<typename T>
  993. ExpressionLhs<T const&> operator <= ( T const& operand );
  994. ExpressionLhs<bool> operator <= ( bool value );
  995. template<typename T>
  996. ResultBuilder& operator << ( T const& value ) {
  997. stream().oss << value;
  998. return *this;
  999. }
  1000. ResultBuilder& setResultType( ResultWas::OfType result );
  1001. ResultBuilder& setResultType( bool result );
  1002. void endExpression( DecomposedExpression const& expr );
  1003. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE;
  1004. AssertionResult build() const;
  1005. AssertionResult build( DecomposedExpression const& expr ) const;
  1006. void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
  1007. void captureResult( ResultWas::OfType resultType );
  1008. void captureExpression();
  1009. void captureExpectedException( std::string const& expectedMessage );
  1010. void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher );
  1011. void handleResult( AssertionResult const& result );
  1012. void react();
  1013. bool shouldDebugBreak() const;
  1014. bool allowThrows() const;
  1015. template<typename ArgT, typename MatcherT>
  1016. void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
  1017. void setExceptionGuard();
  1018. void unsetExceptionGuard();
  1019. private:
  1020. AssertionInfo m_assertionInfo;
  1021. AssertionResultData m_data;
  1022. CopyableStream &stream()
  1023. {
  1024. if(!m_usedStream)
  1025. {
  1026. m_usedStream = true;
  1027. m_stream().oss.str("");
  1028. }
  1029. return m_stream();
  1030. }
  1031. static CopyableStream &m_stream()
  1032. {
  1033. static CopyableStream s;
  1034. return s;
  1035. }
  1036. bool m_shouldDebugBreak;
  1037. bool m_shouldThrow;
  1038. bool m_guardException;
  1039. bool m_usedStream;
  1040. };
  1041. } // namespace Catch
  1042. // Include after due to circular dependency:
  1043. // #included from: catch_expression_lhs.hpp
  1044. #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
  1045. // #included from: catch_evaluate.hpp
  1046. #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
  1047. #ifdef _MSC_VER
  1048. #pragma warning(push)
  1049. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  1050. #pragma warning(disable:4018) // more "signed/unsigned mismatch"
  1051. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  1052. #endif
  1053. #include <cstddef>
  1054. namespace Catch {
  1055. namespace Internal {
  1056. enum Operator {
  1057. IsEqualTo,
  1058. IsNotEqualTo,
  1059. IsLessThan,
  1060. IsGreaterThan,
  1061. IsLessThanOrEqualTo,
  1062. IsGreaterThanOrEqualTo
  1063. };
  1064. template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
  1065. template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
  1066. template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
  1067. template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
  1068. template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
  1069. template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
  1070. template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
  1071. template<typename T>
  1072. T& opCast(T const& t) { return const_cast<T&>(t); }
  1073. // nullptr_t support based on pull request #154 from Konstantin Baumann
  1074. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1075. inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
  1076. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1077. // So the compare overloads can be operator agnostic we convey the operator as a template
  1078. // enum, which is used to specialise an Evaluator for doing the comparison.
  1079. template<typename T1, typename T2, Operator Op>
  1080. struct Evaluator{};
  1081. template<typename T1, typename T2>
  1082. struct Evaluator<T1, T2, IsEqualTo> {
  1083. static bool evaluate( T1 const& lhs, T2 const& rhs) {
  1084. return bool( opCast( lhs ) == opCast( rhs ) );
  1085. }
  1086. };
  1087. template<typename T1, typename T2>
  1088. struct Evaluator<T1, T2, IsNotEqualTo> {
  1089. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1090. return bool( opCast( lhs ) != opCast( rhs ) );
  1091. }
  1092. };
  1093. template<typename T1, typename T2>
  1094. struct Evaluator<T1, T2, IsLessThan> {
  1095. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1096. return bool( opCast( lhs ) < opCast( rhs ) );
  1097. }
  1098. };
  1099. template<typename T1, typename T2>
  1100. struct Evaluator<T1, T2, IsGreaterThan> {
  1101. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1102. return bool( opCast( lhs ) > opCast( rhs ) );
  1103. }
  1104. };
  1105. template<typename T1, typename T2>
  1106. struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
  1107. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1108. return bool( opCast( lhs ) >= opCast( rhs ) );
  1109. }
  1110. };
  1111. template<typename T1, typename T2>
  1112. struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
  1113. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1114. return bool( opCast( lhs ) <= opCast( rhs ) );
  1115. }
  1116. };
  1117. template<Operator Op, typename T1, typename T2>
  1118. bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
  1119. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1120. }
  1121. // This level of indirection allows us to specialise for integer types
  1122. // to avoid signed/ unsigned warnings
  1123. // "base" overload
  1124. template<Operator Op, typename T1, typename T2>
  1125. bool compare( T1 const& lhs, T2 const& rhs ) {
  1126. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1127. }
  1128. // unsigned X to int
  1129. template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
  1130. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1131. }
  1132. template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
  1133. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1134. }
  1135. template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
  1136. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1137. }
  1138. // unsigned X to long
  1139. template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
  1140. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1141. }
  1142. template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
  1143. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1144. }
  1145. template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
  1146. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1147. }
  1148. // int to unsigned X
  1149. template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
  1150. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1151. }
  1152. template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
  1153. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1154. }
  1155. template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
  1156. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1157. }
  1158. // long to unsigned X
  1159. template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
  1160. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1161. }
  1162. template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
  1163. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1164. }
  1165. template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
  1166. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1167. }
  1168. // pointer to long (when comparing against NULL)
  1169. template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
  1170. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1171. }
  1172. template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
  1173. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1174. }
  1175. // pointer to int (when comparing against NULL)
  1176. template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
  1177. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1178. }
  1179. template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
  1180. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1181. }
  1182. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1183. // long long to unsigned X
  1184. template<Operator Op> bool compare( long long lhs, unsigned int rhs ) {
  1185. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1186. }
  1187. template<Operator Op> bool compare( long long lhs, unsigned long rhs ) {
  1188. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1189. }
  1190. template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) {
  1191. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1192. }
  1193. template<Operator Op> bool compare( long long lhs, unsigned char rhs ) {
  1194. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1195. }
  1196. // unsigned long long to X
  1197. template<Operator Op> bool compare( unsigned long long lhs, int rhs ) {
  1198. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1199. }
  1200. template<Operator Op> bool compare( unsigned long long lhs, long rhs ) {
  1201. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1202. }
  1203. template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) {
  1204. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1205. }
  1206. template<Operator Op> bool compare( unsigned long long lhs, char rhs ) {
  1207. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1208. }
  1209. // pointer to long long (when comparing against NULL)
  1210. template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) {
  1211. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1212. }
  1213. template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) {
  1214. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1215. }
  1216. #endif // CATCH_CONFIG_CPP11_LONG_LONG
  1217. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1218. // pointer to nullptr_t (when comparing against nullptr)
  1219. template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
  1220. return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs );
  1221. }
  1222. template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
  1223. return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr );
  1224. }
  1225. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1226. } // end of namespace Internal
  1227. } // end of namespace Catch
  1228. #ifdef _MSC_VER
  1229. #pragma warning(pop)
  1230. #endif
  1231. // #included from: catch_tostring.h
  1232. #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
  1233. #include <sstream>
  1234. #include <iomanip>
  1235. #include <limits>
  1236. #include <vector>
  1237. #include <cstddef>
  1238. #ifdef __OBJC__
  1239. // #included from: catch_objc_arc.hpp
  1240. #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
  1241. #import <Foundation/Foundation.h>
  1242. #ifdef __has_feature
  1243. #define CATCH_ARC_ENABLED __has_feature(objc_arc)
  1244. #else
  1245. #define CATCH_ARC_ENABLED 0
  1246. #endif
  1247. void arcSafeRelease( NSObject* obj );
  1248. id performOptionalSelector( id obj, SEL sel );
  1249. #if !CATCH_ARC_ENABLED
  1250. inline void arcSafeRelease( NSObject* obj ) {
  1251. [obj release];
  1252. }
  1253. inline id performOptionalSelector( id obj, SEL sel ) {
  1254. if( [obj respondsToSelector: sel] )
  1255. return [obj performSelector: sel];
  1256. return nil;
  1257. }
  1258. #define CATCH_UNSAFE_UNRETAINED
  1259. #define CATCH_ARC_STRONG
  1260. #else
  1261. inline void arcSafeRelease( NSObject* ){}
  1262. inline id performOptionalSelector( id obj, SEL sel ) {
  1263. #ifdef __clang__
  1264. #pragma clang diagnostic push
  1265. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  1266. #endif
  1267. if( [obj respondsToSelector: sel] )
  1268. return [obj performSelector: sel];
  1269. #ifdef __clang__
  1270. #pragma clang diagnostic pop
  1271. #endif
  1272. return nil;
  1273. }
  1274. #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
  1275. #define CATCH_ARC_STRONG __strong
  1276. #endif
  1277. #endif
  1278. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1279. #include <tuple>
  1280. #endif
  1281. #ifdef CATCH_CONFIG_CPP11_IS_ENUM
  1282. #include <type_traits>
  1283. #endif
  1284. namespace Catch {
  1285. // Why we're here.
  1286. template<typename T>
  1287. std::string toString( T const& value );
  1288. // Built in overloads
  1289. std::string toString( std::string const& value );
  1290. std::string toString( std::wstring const& value );
  1291. std::string toString( const char* const value );
  1292. std::string toString( char* const value );
  1293. std::string toString( const wchar_t* const value );
  1294. std::string toString( wchar_t* const value );
  1295. std::string toString( int value );
  1296. std::string toString( unsigned long value );
  1297. std::string toString( unsigned int value );
  1298. std::string toString( const double value );
  1299. std::string toString( const float value );
  1300. std::string toString( bool value );
  1301. std::string toString( char value );
  1302. std::string toString( signed char value );
  1303. std::string toString( unsigned char value );
  1304. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1305. std::string toString( long long value );
  1306. std::string toString( unsigned long long value );
  1307. #endif
  1308. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1309. std::string toString( std::nullptr_t );
  1310. #endif
  1311. #ifdef __OBJC__
  1312. std::string toString( NSString const * const& nsstring );
  1313. std::string toString( NSString * CATCH_ARC_STRONG & nsstring );
  1314. std::string toString( NSObject* const& nsObject );
  1315. #endif
  1316. namespace Detail {
  1317. extern const std::string unprintableString;
  1318. #if !defined(CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK)
  1319. struct BorgType {
  1320. template<typename T> BorgType( T const& );
  1321. };
  1322. struct TrueType { char sizer[1]; };
  1323. struct FalseType { char sizer[2]; };
  1324. TrueType& testStreamable( std::ostream& );
  1325. FalseType testStreamable( FalseType );
  1326. FalseType operator<<( std::ostream const&, BorgType const& );
  1327. template<typename T>
  1328. struct IsStreamInsertable {
  1329. static std::ostream &s;
  1330. static T const&t;
  1331. enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
  1332. };
  1333. #else
  1334. template<typename T>
  1335. class IsStreamInsertable {
  1336. template<typename SS, typename TT>
  1337. static auto test(int)
  1338. -> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() );
  1339. template<typename, typename>
  1340. static auto test(...) -> std::false_type;
  1341. public:
  1342. static const bool value = decltype(test<std::ostream,const T&>(0))::value;
  1343. };
  1344. #endif
  1345. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1346. template<typename T,
  1347. bool IsEnum = std::is_enum<T>::value
  1348. >
  1349. struct EnumStringMaker
  1350. {
  1351. static std::string convert( T const& ) { return unprintableString; }
  1352. };
  1353. template<typename T>
  1354. struct EnumStringMaker<T,true>
  1355. {
  1356. static std::string convert( T const& v )
  1357. {
  1358. return ::Catch::toString(
  1359. static_cast<typename std::underlying_type<T>::type>(v)
  1360. );
  1361. }
  1362. };
  1363. #endif
  1364. template<bool C>
  1365. struct StringMakerBase {
  1366. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1367. template<typename T>
  1368. static std::string convert( T const& v )
  1369. {
  1370. return EnumStringMaker<T>::convert( v );
  1371. }
  1372. #else
  1373. template<typename T>
  1374. static std::string convert( T const& ) { return unprintableString; }
  1375. #endif
  1376. };
  1377. template<>
  1378. struct StringMakerBase<true> {
  1379. template<typename T>
  1380. static std::string convert( T const& _value ) {
  1381. std::ostringstream oss;
  1382. oss << _value;
  1383. return oss.str();
  1384. }
  1385. };
  1386. std::string rawMemoryToString( const void *object, std::size_t size );
  1387. template<typename T>
  1388. std::string rawMemoryToString( const T& object ) {
  1389. return rawMemoryToString( &object, sizeof(object) );
  1390. }
  1391. } // end namespace Detail
  1392. template<typename T>
  1393. struct StringMaker :
  1394. Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
  1395. template<typename T>
  1396. struct StringMaker<T*> {
  1397. template<typename U>
  1398. static std::string convert( U* p ) {
  1399. if( !p )
  1400. return "NULL";
  1401. else
  1402. return Detail::rawMemoryToString( p );
  1403. }
  1404. };
  1405. template<typename R, typename C>
  1406. struct StringMaker<R C::*> {
  1407. static std::string convert( R C::* p ) {
  1408. if( !p )
  1409. return "NULL";
  1410. else
  1411. return Detail::rawMemoryToString( p );
  1412. }
  1413. };
  1414. namespace Detail {
  1415. template<typename InputIterator>
  1416. std::string rangeToString( InputIterator first, InputIterator last );
  1417. }
  1418. //template<typename T, typename Allocator>
  1419. //struct StringMaker<std::vector<T, Allocator> > {
  1420. // static std::string convert( std::vector<T,Allocator> const& v ) {
  1421. // return Detail::rangeToString( v.begin(), v.end() );
  1422. // }
  1423. //};
  1424. template<typename T, typename Allocator>
  1425. std::string toString( std::vector<T,Allocator> const& v ) {
  1426. return Detail::rangeToString( v.begin(), v.end() );
  1427. }
  1428. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1429. // toString for tuples
  1430. namespace TupleDetail {
  1431. template<
  1432. typename Tuple,
  1433. std::size_t N = 0,
  1434. bool = (N < std::tuple_size<Tuple>::value)
  1435. >
  1436. struct ElementPrinter {
  1437. static void print( const Tuple& tuple, std::ostream& os )
  1438. {
  1439. os << ( N ? ", " : " " )
  1440. << Catch::toString(std::get<N>(tuple));
  1441. ElementPrinter<Tuple,N+1>::print(tuple,os);
  1442. }
  1443. };
  1444. template<
  1445. typename Tuple,
  1446. std::size_t N
  1447. >
  1448. struct ElementPrinter<Tuple,N,false> {
  1449. static void print( const Tuple&, std::ostream& ) {}
  1450. };
  1451. }
  1452. template<typename ...Types>
  1453. struct StringMaker<std::tuple<Types...>> {
  1454. static std::string convert( const std::tuple<Types...>& tuple )
  1455. {
  1456. std::ostringstream os;
  1457. os << '{';
  1458. TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
  1459. os << " }";
  1460. return os.str();
  1461. }
  1462. };
  1463. #endif // CATCH_CONFIG_CPP11_TUPLE
  1464. namespace Detail {
  1465. template<typename T>
  1466. std::string makeString( T const& value ) {
  1467. return StringMaker<T>::convert( value );
  1468. }
  1469. } // end namespace Detail
  1470. /// \brief converts any type to a string
  1471. ///
  1472. /// The default template forwards on to ostringstream - except when an
  1473. /// ostringstream overload does not exist - in which case it attempts to detect
  1474. /// that and writes {?}.
  1475. /// Overload (not specialise) this template for custom typs that you don't want
  1476. /// to provide an ostream overload for.
  1477. template<typename T>
  1478. std::string toString( T const& value ) {
  1479. return StringMaker<T>::convert( value );
  1480. }
  1481. namespace Detail {
  1482. template<typename InputIterator>
  1483. std::string rangeToString( InputIterator first, InputIterator last ) {
  1484. std::ostringstream oss;
  1485. oss << "{ ";
  1486. if( first != last ) {
  1487. oss << Catch::toString( *first );
  1488. for( ++first ; first != last ; ++first )
  1489. oss << ", " << Catch::toString( *first );
  1490. }
  1491. oss << " }";
  1492. return oss.str();
  1493. }
  1494. }
  1495. } // end namespace Catch
  1496. namespace Catch {
  1497. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1498. class BinaryExpression;
  1499. template<typename ArgT, typename MatcherT>
  1500. class MatchExpression;
  1501. // Wraps the LHS of an expression and overloads comparison operators
  1502. // for also capturing those and RHS (if any)
  1503. template<typename T>
  1504. class ExpressionLhs : public DecomposedExpression {
  1505. public:
  1506. ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {}
  1507. ExpressionLhs& operator = ( const ExpressionLhs& );
  1508. template<typename RhsT>
  1509. BinaryExpression<T, Internal::IsEqualTo, RhsT const&>
  1510. operator == ( RhsT const& rhs ) {
  1511. return captureExpression<Internal::IsEqualTo>( rhs );
  1512. }
  1513. template<typename RhsT>
  1514. BinaryExpression<T, Internal::IsNotEqualTo, RhsT const&>
  1515. operator != ( RhsT const& rhs ) {
  1516. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1517. }
  1518. template<typename RhsT>
  1519. BinaryExpression<T, Internal::IsLessThan, RhsT const&>
  1520. operator < ( RhsT const& rhs ) {
  1521. return captureExpression<Internal::IsLessThan>( rhs );
  1522. }
  1523. template<typename RhsT>
  1524. BinaryExpression<T, Internal::IsGreaterThan, RhsT const&>
  1525. operator > ( RhsT const& rhs ) {
  1526. return captureExpression<Internal::IsGreaterThan>( rhs );
  1527. }
  1528. template<typename RhsT>
  1529. BinaryExpression<T, Internal::IsLessThanOrEqualTo, RhsT const&>
  1530. operator <= ( RhsT const& rhs ) {
  1531. return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
  1532. }
  1533. template<typename RhsT>
  1534. BinaryExpression<T, Internal::IsGreaterThanOrEqualTo, RhsT const&>
  1535. operator >= ( RhsT const& rhs ) {
  1536. return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
  1537. }
  1538. BinaryExpression<T, Internal::IsEqualTo, bool> operator == ( bool rhs ) {
  1539. return captureExpression<Internal::IsEqualTo>( rhs );
  1540. }
  1541. BinaryExpression<T, Internal::IsNotEqualTo, bool> operator != ( bool rhs ) {
  1542. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1543. }
  1544. void endExpression() {
  1545. m_truthy = m_lhs ? true : false;
  1546. m_rb
  1547. .setResultType( m_truthy )
  1548. .endExpression( *this );
  1549. }
  1550. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1551. dest = Catch::toString( m_lhs );
  1552. }
  1553. private:
  1554. template<Internal::Operator Op, typename RhsT>
  1555. BinaryExpression<T, Op, RhsT&> captureExpression( RhsT& rhs ) const {
  1556. return BinaryExpression<T, Op, RhsT&>( m_rb, m_lhs, rhs );
  1557. }
  1558. template<Internal::Operator Op>
  1559. BinaryExpression<T, Op, bool> captureExpression( bool rhs ) const {
  1560. return BinaryExpression<T, Op, bool>( m_rb, m_lhs, rhs );
  1561. }
  1562. private:
  1563. ResultBuilder& m_rb;
  1564. T m_lhs;
  1565. bool m_truthy;
  1566. };
  1567. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1568. class BinaryExpression : public DecomposedExpression {
  1569. public:
  1570. BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs )
  1571. : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {}
  1572. BinaryExpression& operator = ( BinaryExpression& );
  1573. void endExpression() const {
  1574. m_rb
  1575. .setResultType( Internal::compare<Op>( m_lhs, m_rhs ) )
  1576. .endExpression( *this );
  1577. }
  1578. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1579. return true;
  1580. }
  1581. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1582. std::string lhs = Catch::toString( m_lhs );
  1583. std::string rhs = Catch::toString( m_rhs );
  1584. char delim = lhs.size() + rhs.size() < 40 &&
  1585. lhs.find('\n') == std::string::npos &&
  1586. rhs.find('\n') == std::string::npos ? ' ' : '\n';
  1587. dest.reserve( 7 + lhs.size() + rhs.size() );
  1588. // 2 for spaces around operator
  1589. // 2 for operator
  1590. // 2 for parentheses (conditionally added later)
  1591. // 1 for negation (conditionally added later)
  1592. dest = lhs;
  1593. dest += delim;
  1594. dest += Internal::OperatorTraits<Op>::getName();
  1595. dest += delim;
  1596. dest += rhs;
  1597. }
  1598. private:
  1599. ResultBuilder& m_rb;
  1600. LhsT m_lhs;
  1601. RhsT m_rhs;
  1602. };
  1603. template<typename ArgT, typename MatcherT>
  1604. class MatchExpression : public DecomposedExpression {
  1605. public:
  1606. MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString )
  1607. : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {}
  1608. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1609. return true;
  1610. }
  1611. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1612. std::string matcherAsString = m_matcher.toString();
  1613. dest = Catch::toString( m_arg );
  1614. dest += ' ';
  1615. if( matcherAsString == Detail::unprintableString )
  1616. dest += m_matcherString;
  1617. else
  1618. dest += matcherAsString;
  1619. }
  1620. private:
  1621. ArgT m_arg;
  1622. MatcherT m_matcher;
  1623. char const* m_matcherString;
  1624. };
  1625. } // end namespace Catch
  1626. namespace Catch {
  1627. template<typename T>
  1628. ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
  1629. return ExpressionLhs<T const&>( *this, operand );
  1630. }
  1631. inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
  1632. return ExpressionLhs<bool>( *this, value );
  1633. }
  1634. template<typename ArgT, typename MatcherT>
  1635. void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
  1636. char const* matcherString ) {
  1637. MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString );
  1638. setResultType( matcher.match( arg ) );
  1639. endExpression( expr );
  1640. }
  1641. } // namespace Catch
  1642. // #included from: catch_message.h
  1643. #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
  1644. #include <string>
  1645. namespace Catch {
  1646. struct MessageInfo {
  1647. MessageInfo( std::string const& _macroName,
  1648. SourceLineInfo const& _lineInfo,
  1649. ResultWas::OfType _type );
  1650. std::string macroName;
  1651. SourceLineInfo lineInfo;
  1652. ResultWas::OfType type;
  1653. std::string message;
  1654. unsigned int sequence;
  1655. bool operator == ( MessageInfo const& other ) const {
  1656. return sequence == other.sequence;
  1657. }
  1658. bool operator < ( MessageInfo const& other ) const {
  1659. return sequence < other.sequence;
  1660. }
  1661. private:
  1662. static unsigned int globalCount;
  1663. };
  1664. struct MessageBuilder {
  1665. MessageBuilder( std::string const& macroName,
  1666. SourceLineInfo const& lineInfo,
  1667. ResultWas::OfType type )
  1668. : m_info( macroName, lineInfo, type )
  1669. {}
  1670. template<typename T>
  1671. MessageBuilder& operator << ( T const& value ) {
  1672. m_stream << value;
  1673. return *this;
  1674. }
  1675. MessageInfo m_info;
  1676. std::ostringstream m_stream;
  1677. };
  1678. class ScopedMessage {
  1679. public:
  1680. ScopedMessage( MessageBuilder const& builder );
  1681. ScopedMessage( ScopedMessage const& other );
  1682. ~ScopedMessage();
  1683. MessageInfo m_info;
  1684. };
  1685. } // end namespace Catch
  1686. // #included from: catch_interfaces_capture.h
  1687. #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
  1688. #include <string>
  1689. namespace Catch {
  1690. class TestCase;
  1691. class AssertionResult;
  1692. struct AssertionInfo;
  1693. struct SectionInfo;
  1694. struct SectionEndInfo;
  1695. struct MessageInfo;
  1696. class ScopedMessageBuilder;
  1697. struct Counts;
  1698. struct IResultCapture {
  1699. virtual ~IResultCapture();
  1700. virtual void assertionEnded( AssertionResult const& result ) = 0;
  1701. virtual bool sectionStarted( SectionInfo const& sectionInfo,
  1702. Counts& assertions ) = 0;
  1703. virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
  1704. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
  1705. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  1706. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  1707. virtual std::string getCurrentTestName() const = 0;
  1708. virtual const AssertionResult* getLastResult() const = 0;
  1709. virtual void exceptionEarlyReported() = 0;
  1710. virtual void handleFatalErrorCondition( std::string const& message ) = 0;
  1711. virtual bool lastAssertionPassed() = 0;
  1712. virtual void assertionPassed() = 0;
  1713. virtual void assertionRun() = 0;
  1714. };
  1715. IResultCapture& getResultCapture();
  1716. }
  1717. // #included from: catch_debugger.h
  1718. #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
  1719. // #included from: catch_platform.h
  1720. #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED
  1721. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  1722. # define CATCH_PLATFORM_MAC
  1723. #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  1724. # define CATCH_PLATFORM_IPHONE
  1725. #elif defined(linux) || defined(__linux) || defined(__linux__)
  1726. # define CATCH_PLATFORM_LINUX
  1727. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  1728. # define CATCH_PLATFORM_WINDOWS
  1729. # if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
  1730. # define CATCH_DEFINES_NOMINMAX
  1731. # endif
  1732. # if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
  1733. # define CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  1734. # endif
  1735. #endif
  1736. #include <string>
  1737. namespace Catch{
  1738. bool isDebuggerActive();
  1739. void writeToDebugConsole( std::string const& text );
  1740. }
  1741. #ifdef CATCH_PLATFORM_MAC
  1742. // The following code snippet based on:
  1743. // http://cocoawithlove.com/2008/03/break-into-debugger.html
  1744. #if defined(__ppc64__) || defined(__ppc__)
  1745. #define CATCH_TRAP() \
  1746. __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  1747. : : : "memory","r0","r3","r4" ) /* NOLINT */
  1748. #elif defined(__aarch64__)
  1749. // Backport of https://github.com/catchorg/Catch2/commit/a25c1a24af8bffd35727a888a307ff0280cf9387
  1750. #define CATCH_TRAP() __asm__(".inst 0xd4200000")
  1751. #else
  1752. #define CATCH_TRAP() __asm__("int $3\n" : : /* NOLINT */ )
  1753. #endif
  1754. #elif defined(CATCH_PLATFORM_LINUX)
  1755. // If we can use inline assembler, do it because this allows us to break
  1756. // directly at the location of the failing check instead of breaking inside
  1757. // raise() called from it, i.e. one stack frame below.
  1758. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  1759. #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
  1760. #else // Fall back to the generic way.
  1761. #include <signal.h>
  1762. #define CATCH_TRAP() raise(SIGTRAP)
  1763. #endif
  1764. #elif defined(_MSC_VER)
  1765. #define CATCH_TRAP() __debugbreak()
  1766. #elif defined(__MINGW32__)
  1767. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  1768. #define CATCH_TRAP() DebugBreak()
  1769. #endif
  1770. #ifdef CATCH_TRAP
  1771. #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
  1772. #else
  1773. #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
  1774. #endif
  1775. // #included from: catch_interfaces_runner.h
  1776. #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
  1777. namespace Catch {
  1778. class TestCase;
  1779. struct IRunner {
  1780. virtual ~IRunner();
  1781. virtual bool aborting() const = 0;
  1782. };
  1783. }
  1784. #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
  1785. # define CATCH_INTERNAL_STRINGIFY(expr) #expr
  1786. #else
  1787. # define CATCH_INTERNAL_STRINGIFY(expr) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  1788. #endif
  1789. #if defined(CATCH_CONFIG_FAST_COMPILE)
  1790. ///////////////////////////////////////////////////////////////////////////////
  1791. // We can speedup compilation significantly by breaking into debugger lower in
  1792. // the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
  1793. // macro in each assertion
  1794. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1795. resultBuilder.react();
  1796. ///////////////////////////////////////////////////////////////////////////////
  1797. // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
  1798. // macros.
  1799. // This can potentially cause false negative, if the test code catches
  1800. // the exception before it propagates back up to the runner.
  1801. #define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \
  1802. do { \
  1803. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1804. __catchResult.setExceptionGuard(); \
  1805. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1806. ( __catchResult <= expr ).endExpression(); \
  1807. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1808. __catchResult.unsetExceptionGuard(); \
  1809. INTERNAL_CATCH_REACT( __catchResult ) \
  1810. } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
  1811. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1812. #define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \
  1813. do { \
  1814. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1815. __catchResult.setExceptionGuard(); \
  1816. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1817. __catchResult.unsetExceptionGuard(); \
  1818. INTERNAL_CATCH_REACT( __catchResult ) \
  1819. } while( Catch::alwaysFalse() )
  1820. #else
  1821. ///////////////////////////////////////////////////////////////////////////////
  1822. // In the event of a failure works out if the debugger needs to be invoked
  1823. // and/or an exception thrown and takes appropriate action.
  1824. // This needs to be done as a macro so the debugger will stop in the user
  1825. // source code rather than in Catch library code
  1826. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1827. if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
  1828. resultBuilder.react();
  1829. #endif
  1830. ///////////////////////////////////////////////////////////////////////////////
  1831. #define INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ) \
  1832. do { \
  1833. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1834. try { \
  1835. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1836. ( __catchResult <= expr ).endExpression(); \
  1837. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1838. } \
  1839. catch( ... ) { \
  1840. __catchResult.useActiveException( resultDisposition ); \
  1841. } \
  1842. INTERNAL_CATCH_REACT( __catchResult ) \
  1843. } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
  1844. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1845. ///////////////////////////////////////////////////////////////////////////////
  1846. #define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \
  1847. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1848. if( Catch::getResultCapture().lastAssertionPassed() )
  1849. ///////////////////////////////////////////////////////////////////////////////
  1850. #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \
  1851. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1852. if( !Catch::getResultCapture().lastAssertionPassed() )
  1853. ///////////////////////////////////////////////////////////////////////////////
  1854. #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \
  1855. do { \
  1856. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1857. try { \
  1858. static_cast<void>(expr); \
  1859. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1860. } \
  1861. catch( ... ) { \
  1862. __catchResult.useActiveException( resultDisposition ); \
  1863. } \
  1864. INTERNAL_CATCH_REACT( __catchResult ) \
  1865. } while( Catch::alwaysFalse() )
  1866. ///////////////////////////////////////////////////////////////////////////////
  1867. #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \
  1868. do { \
  1869. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1870. if( __catchResult.allowThrows() ) \
  1871. try { \
  1872. static_cast<void>(expr); \
  1873. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1874. } \
  1875. catch( ... ) { \
  1876. __catchResult.captureExpectedException( matcher ); \
  1877. } \
  1878. else \
  1879. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1880. INTERNAL_CATCH_REACT( __catchResult ) \
  1881. } while( Catch::alwaysFalse() )
  1882. ///////////////////////////////////////////////////////////////////////////////
  1883. #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
  1884. do { \
  1885. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
  1886. if( __catchResult.allowThrows() ) \
  1887. try { \
  1888. static_cast<void>(expr); \
  1889. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1890. } \
  1891. catch( exceptionType ) { \
  1892. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1893. } \
  1894. catch( ... ) { \
  1895. __catchResult.useActiveException( resultDisposition ); \
  1896. } \
  1897. else \
  1898. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1899. INTERNAL_CATCH_REACT( __catchResult ) \
  1900. } while( Catch::alwaysFalse() )
  1901. ///////////////////////////////////////////////////////////////////////////////
  1902. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  1903. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
  1904. do { \
  1905. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1906. __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
  1907. __catchResult.captureResult( messageType ); \
  1908. INTERNAL_CATCH_REACT( __catchResult ) \
  1909. } while( Catch::alwaysFalse() )
  1910. #else
  1911. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, log ) \
  1912. do { \
  1913. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1914. __catchResult << log + ::Catch::StreamEndStop(); \
  1915. __catchResult.captureResult( messageType ); \
  1916. INTERNAL_CATCH_REACT( __catchResult ) \
  1917. } while( Catch::alwaysFalse() )
  1918. #endif
  1919. ///////////////////////////////////////////////////////////////////////////////
  1920. #define INTERNAL_CATCH_INFO( macroName, log ) \
  1921. Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
  1922. ///////////////////////////////////////////////////////////////////////////////
  1923. #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
  1924. do { \
  1925. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1926. try { \
  1927. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1928. } catch( ... ) { \
  1929. __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
  1930. } \
  1931. INTERNAL_CATCH_REACT( __catchResult ) \
  1932. } while( Catch::alwaysFalse() )
  1933. // #included from: internal/catch_section.h
  1934. #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
  1935. // #included from: catch_section_info.h
  1936. #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
  1937. // #included from: catch_totals.hpp
  1938. #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
  1939. #include <cstddef>
  1940. namespace Catch {
  1941. struct Counts {
  1942. Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
  1943. Counts operator - ( Counts const& other ) const {
  1944. Counts diff;
  1945. diff.passed = passed - other.passed;
  1946. diff.failed = failed - other.failed;
  1947. diff.failedButOk = failedButOk - other.failedButOk;
  1948. return diff;
  1949. }
  1950. Counts& operator += ( Counts const& other ) {
  1951. passed += other.passed;
  1952. failed += other.failed;
  1953. failedButOk += other.failedButOk;
  1954. return *this;
  1955. }
  1956. std::size_t total() const {
  1957. return passed + failed + failedButOk;
  1958. }
  1959. bool allPassed() const {
  1960. return failed == 0 && failedButOk == 0;
  1961. }
  1962. bool allOk() const {
  1963. return failed == 0;
  1964. }
  1965. std::size_t passed;
  1966. std::size_t failed;
  1967. std::size_t failedButOk;
  1968. };
  1969. struct Totals {
  1970. Totals operator - ( Totals const& other ) const {
  1971. Totals diff;
  1972. diff.assertions = assertions - other.assertions;
  1973. diff.testCases = testCases - other.testCases;
  1974. return diff;
  1975. }
  1976. Totals delta( Totals const& prevTotals ) const {
  1977. Totals diff = *this - prevTotals;
  1978. if( diff.assertions.failed > 0 )
  1979. ++diff.testCases.failed;
  1980. else if( diff.assertions.failedButOk > 0 )
  1981. ++diff.testCases.failedButOk;
  1982. else
  1983. ++diff.testCases.passed;
  1984. return diff;
  1985. }
  1986. Totals& operator += ( Totals const& other ) {
  1987. assertions += other.assertions;
  1988. testCases += other.testCases;
  1989. return *this;
  1990. }
  1991. Counts assertions;
  1992. Counts testCases;
  1993. };
  1994. }
  1995. #include <string>
  1996. namespace Catch {
  1997. struct SectionInfo {
  1998. SectionInfo
  1999. ( SourceLineInfo const& _lineInfo,
  2000. std::string const& _name,
  2001. std::string const& _description = std::string() );
  2002. std::string name;
  2003. std::string description;
  2004. SourceLineInfo lineInfo;
  2005. };
  2006. struct SectionEndInfo {
  2007. SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
  2008. : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
  2009. {}
  2010. SectionInfo sectionInfo;
  2011. Counts prevAssertions;
  2012. double durationInSeconds;
  2013. };
  2014. } // end namespace Catch
  2015. // #included from: catch_timer.h
  2016. #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED
  2017. #ifdef _MSC_VER
  2018. namespace Catch {
  2019. typedef unsigned long long UInt64;
  2020. }
  2021. #else
  2022. #include <stdint.h>
  2023. namespace Catch {
  2024. typedef uint64_t UInt64;
  2025. }
  2026. #endif
  2027. namespace Catch {
  2028. class Timer {
  2029. public:
  2030. Timer() : m_ticks( 0 ) {}
  2031. void start();
  2032. unsigned int getElapsedMicroseconds() const;
  2033. unsigned int getElapsedMilliseconds() const;
  2034. double getElapsedSeconds() const;
  2035. private:
  2036. UInt64 m_ticks;
  2037. };
  2038. } // namespace Catch
  2039. #include <string>
  2040. namespace Catch {
  2041. class Section : NonCopyable {
  2042. public:
  2043. Section( SectionInfo const& info );
  2044. ~Section();
  2045. // This indicates whether the section should be executed or not
  2046. operator bool() const;
  2047. private:
  2048. SectionInfo m_info;
  2049. std::string m_name;
  2050. Counts m_assertions;
  2051. bool m_sectionIncluded;
  2052. Timer m_timer;
  2053. };
  2054. } // end namespace Catch
  2055. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  2056. #define INTERNAL_CATCH_SECTION( ... ) \
  2057. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
  2058. #else
  2059. #define INTERNAL_CATCH_SECTION( name, desc ) \
  2060. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
  2061. #endif
  2062. // #included from: internal/catch_generators.hpp
  2063. #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
  2064. #include <vector>
  2065. #include <string>
  2066. #include <stdlib.h>
  2067. namespace Catch {
  2068. template<typename T>
  2069. struct IGenerator {
  2070. virtual ~IGenerator() {}
  2071. virtual T getValue( std::size_t index ) const = 0;
  2072. virtual std::size_t size () const = 0;
  2073. };
  2074. template<typename T>
  2075. class BetweenGenerator : public IGenerator<T> {
  2076. public:
  2077. BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
  2078. virtual T getValue( std::size_t index ) const {
  2079. return m_from+static_cast<int>( index );
  2080. }
  2081. virtual std::size_t size() const {
  2082. return static_cast<std::size_t>( 1+m_to-m_from );
  2083. }
  2084. private:
  2085. T m_from;
  2086. T m_to;
  2087. };
  2088. template<typename T>
  2089. class ValuesGenerator : public IGenerator<T> {
  2090. public:
  2091. ValuesGenerator(){}
  2092. void add( T value ) {
  2093. m_values.push_back( value );
  2094. }
  2095. virtual T getValue( std::size_t index ) const {
  2096. return m_values[index];
  2097. }
  2098. virtual std::size_t size() const {
  2099. return m_values.size();
  2100. }
  2101. private:
  2102. std::vector<T> m_values;
  2103. };
  2104. template<typename T>
  2105. class CompositeGenerator {
  2106. public:
  2107. CompositeGenerator() : m_totalSize( 0 ) {}
  2108. // *** Move semantics, similar to auto_ptr ***
  2109. CompositeGenerator( CompositeGenerator& other )
  2110. : m_fileInfo( other.m_fileInfo ),
  2111. m_totalSize( 0 )
  2112. {
  2113. move( other );
  2114. }
  2115. CompositeGenerator& setFileInfo( const char* fileInfo ) {
  2116. m_fileInfo = fileInfo;
  2117. return *this;
  2118. }
  2119. ~CompositeGenerator() {
  2120. deleteAll( m_composed );
  2121. }
  2122. operator T () const {
  2123. size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
  2124. typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
  2125. typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
  2126. for( size_t index = 0; it != itEnd; ++it )
  2127. {
  2128. const IGenerator<T>* generator = *it;
  2129. if( overallIndex >= index && overallIndex < index + generator->size() )
  2130. {
  2131. return generator->getValue( overallIndex-index );
  2132. }
  2133. index += generator->size();
  2134. }
  2135. CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
  2136. return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
  2137. }
  2138. void add( const IGenerator<T>* generator ) {
  2139. m_totalSize += generator->size();
  2140. m_composed.push_back( generator );
  2141. }
  2142. CompositeGenerator& then( CompositeGenerator& other ) {
  2143. move( other );
  2144. return *this;
  2145. }
  2146. CompositeGenerator& then( T value ) {
  2147. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2148. valuesGen->add( value );
  2149. add( valuesGen );
  2150. return *this;
  2151. }
  2152. private:
  2153. void move( CompositeGenerator& other ) {
  2154. m_composed.insert( m_composed.end(), other.m_composed.begin(), other.m_composed.end() );
  2155. m_totalSize += other.m_totalSize;
  2156. other.m_composed.clear();
  2157. }
  2158. std::vector<const IGenerator<T>*> m_composed;
  2159. std::string m_fileInfo;
  2160. size_t m_totalSize;
  2161. };
  2162. namespace Generators
  2163. {
  2164. template<typename T>
  2165. CompositeGenerator<T> between( T from, T to ) {
  2166. CompositeGenerator<T> generators;
  2167. generators.add( new BetweenGenerator<T>( from, to ) );
  2168. return generators;
  2169. }
  2170. template<typename T>
  2171. CompositeGenerator<T> values( T val1, T val2 ) {
  2172. CompositeGenerator<T> generators;
  2173. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2174. valuesGen->add( val1 );
  2175. valuesGen->add( val2 );
  2176. generators.add( valuesGen );
  2177. return generators;
  2178. }
  2179. template<typename T>
  2180. CompositeGenerator<T> values( T val1, T val2, T val3 ){
  2181. CompositeGenerator<T> generators;
  2182. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2183. valuesGen->add( val1 );
  2184. valuesGen->add( val2 );
  2185. valuesGen->add( val3 );
  2186. generators.add( valuesGen );
  2187. return generators;
  2188. }
  2189. template<typename T>
  2190. CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
  2191. CompositeGenerator<T> generators;
  2192. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2193. valuesGen->add( val1 );
  2194. valuesGen->add( val2 );
  2195. valuesGen->add( val3 );
  2196. valuesGen->add( val4 );
  2197. generators.add( valuesGen );
  2198. return generators;
  2199. }
  2200. } // end namespace Generators
  2201. using namespace Generators;
  2202. } // end namespace Catch
  2203. #define INTERNAL_CATCH_LINESTR2( line ) #line
  2204. #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
  2205. #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
  2206. // #included from: internal/catch_interfaces_exception.h
  2207. #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
  2208. #include <string>
  2209. #include <vector>
  2210. // #included from: catch_interfaces_registry_hub.h
  2211. #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
  2212. #include <string>
  2213. namespace Catch {
  2214. class TestCase;
  2215. struct ITestCaseRegistry;
  2216. struct IExceptionTranslatorRegistry;
  2217. struct IExceptionTranslator;
  2218. struct IReporterRegistry;
  2219. struct IReporterFactory;
  2220. struct ITagAliasRegistry;
  2221. struct IRegistryHub {
  2222. virtual ~IRegistryHub();
  2223. virtual IReporterRegistry const& getReporterRegistry() const = 0;
  2224. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  2225. virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
  2226. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
  2227. };
  2228. struct IMutableRegistryHub {
  2229. virtual ~IMutableRegistryHub();
  2230. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
  2231. virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
  2232. virtual void registerTest( TestCase const& testInfo ) = 0;
  2233. virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
  2234. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
  2235. };
  2236. IRegistryHub& getRegistryHub();
  2237. IMutableRegistryHub& getMutableRegistryHub();
  2238. void cleanUp();
  2239. std::string translateActiveException();
  2240. }
  2241. namespace Catch {
  2242. typedef std::string(*exceptionTranslateFunction)();
  2243. struct IExceptionTranslator;
  2244. typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
  2245. struct IExceptionTranslator {
  2246. virtual ~IExceptionTranslator();
  2247. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  2248. };
  2249. struct IExceptionTranslatorRegistry {
  2250. virtual ~IExceptionTranslatorRegistry();
  2251. virtual std::string translateActiveException() const = 0;
  2252. };
  2253. class ExceptionTranslatorRegistrar {
  2254. template<typename T>
  2255. class ExceptionTranslator : public IExceptionTranslator {
  2256. public:
  2257. ExceptionTranslator( std::string(*translateFunction)( T& ) )
  2258. : m_translateFunction( translateFunction )
  2259. {}
  2260. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
  2261. try {
  2262. if( it == itEnd )
  2263. throw;
  2264. else
  2265. return (*it)->translate( it+1, itEnd );
  2266. }
  2267. catch( T& ex ) {
  2268. return m_translateFunction( ex );
  2269. }
  2270. }
  2271. protected:
  2272. std::string(*m_translateFunction)( T& );
  2273. };
  2274. public:
  2275. template<typename T>
  2276. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
  2277. getMutableRegistryHub().registerTranslator
  2278. ( new ExceptionTranslator<T>( translateFunction ) );
  2279. }
  2280. };
  2281. }
  2282. ///////////////////////////////////////////////////////////////////////////////
  2283. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  2284. static std::string translatorName( signature ); \
  2285. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\
  2286. static std::string translatorName( signature )
  2287. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  2288. // #included from: internal/catch_approx.hpp
  2289. #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
  2290. #include <cmath>
  2291. #include <limits>
  2292. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2293. #include <type_traits>
  2294. #endif
  2295. namespace Catch {
  2296. namespace Detail {
  2297. class Approx {
  2298. public:
  2299. explicit Approx ( double value )
  2300. : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
  2301. m_margin( 0.0 ),
  2302. m_scale( 1.0 ),
  2303. m_value( value )
  2304. {}
  2305. static Approx custom() {
  2306. return Approx( 0 );
  2307. }
  2308. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2309. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2310. Approx operator()( T value ) {
  2311. Approx approx( static_cast<double>(value) );
  2312. approx.epsilon( m_epsilon );
  2313. approx.margin( m_margin );
  2314. approx.scale( m_scale );
  2315. return approx;
  2316. }
  2317. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2318. explicit Approx( T value ): Approx(static_cast<double>(value))
  2319. {}
  2320. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2321. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2322. // Thanks to Richard Harris for his help refining this formula
  2323. auto lhs_v = double(lhs);
  2324. bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale + (std::max)(std::fabs(lhs_v), std::fabs(rhs.m_value)));
  2325. if (relativeOK) {
  2326. return true;
  2327. }
  2328. return std::fabs(lhs_v - rhs.m_value) <= rhs.m_margin;
  2329. }
  2330. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2331. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2332. return operator==( rhs, lhs );
  2333. }
  2334. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2335. friend bool operator != ( T lhs, Approx const& rhs ) {
  2336. return !operator==( lhs, rhs );
  2337. }
  2338. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2339. friend bool operator != ( Approx const& lhs, T rhs ) {
  2340. return !operator==( rhs, lhs );
  2341. }
  2342. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2343. friend bool operator <= ( T lhs, Approx const& rhs ) {
  2344. return double(lhs) < rhs.m_value || lhs == rhs;
  2345. }
  2346. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2347. friend bool operator <= ( Approx const& lhs, T rhs ) {
  2348. return lhs.m_value < double(rhs) || lhs == rhs;
  2349. }
  2350. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2351. friend bool operator >= ( T lhs, Approx const& rhs ) {
  2352. return double(lhs) > rhs.m_value || lhs == rhs;
  2353. }
  2354. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2355. friend bool operator >= ( Approx const& lhs, T rhs ) {
  2356. return lhs.m_value > double(rhs) || lhs == rhs;
  2357. }
  2358. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2359. Approx& epsilon( T newEpsilon ) {
  2360. m_epsilon = double(newEpsilon);
  2361. return *this;
  2362. }
  2363. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2364. Approx& margin( T newMargin ) {
  2365. m_margin = double(newMargin);
  2366. return *this;
  2367. }
  2368. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2369. Approx& scale( T newScale ) {
  2370. m_scale = double(newScale);
  2371. return *this;
  2372. }
  2373. #else
  2374. Approx operator()( double value ) {
  2375. Approx approx( value );
  2376. approx.epsilon( m_epsilon );
  2377. approx.margin( m_margin );
  2378. approx.scale( m_scale );
  2379. return approx;
  2380. }
  2381. friend bool operator == ( double lhs, Approx const& rhs ) {
  2382. // Thanks to Richard Harris for his help refining this formula
  2383. bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) );
  2384. if (relativeOK) {
  2385. return true;
  2386. }
  2387. return std::fabs(lhs - rhs.m_value) <= rhs.m_margin;
  2388. }
  2389. friend bool operator == ( Approx const& lhs, double rhs ) {
  2390. return operator==( rhs, lhs );
  2391. }
  2392. friend bool operator != ( double lhs, Approx const& rhs ) {
  2393. return !operator==( lhs, rhs );
  2394. }
  2395. friend bool operator != ( Approx const& lhs, double rhs ) {
  2396. return !operator==( rhs, lhs );
  2397. }
  2398. friend bool operator <= ( double lhs, Approx const& rhs ) {
  2399. return lhs < rhs.m_value || lhs == rhs;
  2400. }
  2401. friend bool operator <= ( Approx const& lhs, double rhs ) {
  2402. return lhs.m_value < rhs || lhs == rhs;
  2403. }
  2404. friend bool operator >= ( double lhs, Approx const& rhs ) {
  2405. return lhs > rhs.m_value || lhs == rhs;
  2406. }
  2407. friend bool operator >= ( Approx const& lhs, double rhs ) {
  2408. return lhs.m_value > rhs || lhs == rhs;
  2409. }
  2410. Approx& epsilon( double newEpsilon ) {
  2411. m_epsilon = newEpsilon;
  2412. return *this;
  2413. }
  2414. Approx& margin( double newMargin ) {
  2415. m_margin = newMargin;
  2416. return *this;
  2417. }
  2418. Approx& scale( double newScale ) {
  2419. m_scale = newScale;
  2420. return *this;
  2421. }
  2422. #endif
  2423. std::string toString() const {
  2424. std::ostringstream oss;
  2425. oss << "Approx( " << Catch::toString( m_value ) << " )";
  2426. return oss.str();
  2427. }
  2428. private:
  2429. double m_epsilon;
  2430. double m_margin;
  2431. double m_scale;
  2432. double m_value;
  2433. };
  2434. }
  2435. template<>
  2436. inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
  2437. return value.toString();
  2438. }
  2439. } // end namespace Catch
  2440. // #included from: internal/catch_matchers_string.h
  2441. #define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
  2442. namespace Catch {
  2443. namespace Matchers {
  2444. namespace StdString {
  2445. struct CasedString
  2446. {
  2447. CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
  2448. std::string adjustString( std::string const& str ) const;
  2449. std::string caseSensitivitySuffix() const;
  2450. CaseSensitive::Choice m_caseSensitivity;
  2451. std::string m_str;
  2452. };
  2453. struct StringMatcherBase : MatcherBase<std::string> {
  2454. StringMatcherBase( std::string const& operation, CasedString const& comparator );
  2455. virtual std::string describe() const CATCH_OVERRIDE;
  2456. CasedString m_comparator;
  2457. std::string m_operation;
  2458. };
  2459. struct EqualsMatcher : StringMatcherBase {
  2460. EqualsMatcher( CasedString const& comparator );
  2461. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2462. };
  2463. struct ContainsMatcher : StringMatcherBase {
  2464. ContainsMatcher( CasedString const& comparator );
  2465. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2466. };
  2467. struct StartsWithMatcher : StringMatcherBase {
  2468. StartsWithMatcher( CasedString const& comparator );
  2469. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2470. };
  2471. struct EndsWithMatcher : StringMatcherBase {
  2472. EndsWithMatcher( CasedString const& comparator );
  2473. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2474. };
  2475. } // namespace StdString
  2476. // The following functions create the actual matcher objects.
  2477. // This allows the types to be inferred
  2478. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2479. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2480. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2481. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2482. } // namespace Matchers
  2483. } // namespace Catch
  2484. // #included from: internal/catch_matchers_vector.h
  2485. #define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED
  2486. namespace Catch {
  2487. namespace Matchers {
  2488. namespace Vector {
  2489. template<typename T>
  2490. struct ContainsElementMatcher : MatcherBase<std::vector<T>, T> {
  2491. ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
  2492. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2493. return std::find(v.begin(), v.end(), m_comparator) != v.end();
  2494. }
  2495. virtual std::string describe() const CATCH_OVERRIDE {
  2496. return "Contains: " + Catch::toString( m_comparator );
  2497. }
  2498. T const& m_comparator;
  2499. };
  2500. template<typename T>
  2501. struct ContainsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2502. ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2503. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2504. // !TBD: see note in EqualsMatcher
  2505. if (m_comparator.size() > v.size())
  2506. return false;
  2507. for (size_t i = 0; i < m_comparator.size(); ++i)
  2508. if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end())
  2509. return false;
  2510. return true;
  2511. }
  2512. virtual std::string describe() const CATCH_OVERRIDE {
  2513. return "Contains: " + Catch::toString( m_comparator );
  2514. }
  2515. std::vector<T> const& m_comparator;
  2516. };
  2517. template<typename T>
  2518. struct EqualsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2519. EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2520. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2521. // !TBD: This currently works if all elements can be compared using !=
  2522. // - a more general approach would be via a compare template that defaults
  2523. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  2524. // - then just call that directly
  2525. if (m_comparator.size() != v.size())
  2526. return false;
  2527. for (size_t i = 0; i < v.size(); ++i)
  2528. if (m_comparator[i] != v[i])
  2529. return false;
  2530. return true;
  2531. }
  2532. virtual std::string describe() const CATCH_OVERRIDE {
  2533. return "Equals: " + Catch::toString( m_comparator );
  2534. }
  2535. std::vector<T> const& m_comparator;
  2536. };
  2537. } // namespace Vector
  2538. // The following functions create the actual matcher objects.
  2539. // This allows the types to be inferred
  2540. template<typename T>
  2541. Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
  2542. return Vector::ContainsMatcher<T>( comparator );
  2543. }
  2544. template<typename T>
  2545. Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) {
  2546. return Vector::ContainsElementMatcher<T>( comparator );
  2547. }
  2548. template<typename T>
  2549. Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
  2550. return Vector::EqualsMatcher<T>( comparator );
  2551. }
  2552. } // namespace Matchers
  2553. } // namespace Catch
  2554. // #included from: internal/catch_interfaces_tag_alias_registry.h
  2555. #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
  2556. // #included from: catch_tag_alias.h
  2557. #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED
  2558. #include <string>
  2559. namespace Catch {
  2560. struct TagAlias {
  2561. TagAlias( std::string const& _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
  2562. std::string tag;
  2563. SourceLineInfo lineInfo;
  2564. };
  2565. struct RegistrarForTagAliases {
  2566. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  2567. };
  2568. } // end namespace Catch
  2569. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); }
  2570. // #included from: catch_option.hpp
  2571. #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
  2572. namespace Catch {
  2573. // An optional type
  2574. template<typename T>
  2575. class Option {
  2576. public:
  2577. Option() : nullableValue( CATCH_NULL ) {}
  2578. Option( T const& _value )
  2579. : nullableValue( new( storage ) T( _value ) )
  2580. {}
  2581. Option( Option const& _other )
  2582. : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
  2583. {}
  2584. ~Option() {
  2585. reset();
  2586. }
  2587. Option& operator= ( Option const& _other ) {
  2588. if( &_other != this ) {
  2589. reset();
  2590. if( _other )
  2591. nullableValue = new( storage ) T( *_other );
  2592. }
  2593. return *this;
  2594. }
  2595. Option& operator = ( T const& _value ) {
  2596. reset();
  2597. nullableValue = new( storage ) T( _value );
  2598. return *this;
  2599. }
  2600. void reset() {
  2601. if( nullableValue )
  2602. nullableValue->~T();
  2603. nullableValue = CATCH_NULL;
  2604. }
  2605. T& operator*() { return *nullableValue; }
  2606. T const& operator*() const { return *nullableValue; }
  2607. T* operator->() { return nullableValue; }
  2608. const T* operator->() const { return nullableValue; }
  2609. T valueOr( T const& defaultValue ) const {
  2610. return nullableValue ? *nullableValue : defaultValue;
  2611. }
  2612. bool some() const { return nullableValue != CATCH_NULL; }
  2613. bool none() const { return nullableValue == CATCH_NULL; }
  2614. bool operator !() const { return nullableValue == CATCH_NULL; }
  2615. operator SafeBool::type() const {
  2616. return SafeBool::makeSafe( some() );
  2617. }
  2618. private:
  2619. T *nullableValue;
  2620. union {
  2621. char storage[sizeof(T)];
  2622. // These are here to force alignment for the storage
  2623. long double dummy1;
  2624. void (*dummy2)();
  2625. long double dummy3;
  2626. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  2627. long long dummy4;
  2628. #endif
  2629. };
  2630. };
  2631. } // end namespace Catch
  2632. namespace Catch {
  2633. struct ITagAliasRegistry {
  2634. virtual ~ITagAliasRegistry();
  2635. virtual Option<TagAlias> find( std::string const& alias ) const = 0;
  2636. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  2637. static ITagAliasRegistry const& get();
  2638. };
  2639. } // end namespace Catch
  2640. // These files are included here so the single_include script doesn't put them
  2641. // in the conditionally compiled sections
  2642. // #included from: internal/catch_test_case_info.h
  2643. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
  2644. #include <string>
  2645. #include <set>
  2646. #ifdef __clang__
  2647. #pragma clang diagnostic push
  2648. #pragma clang diagnostic ignored "-Wpadded"
  2649. #endif
  2650. namespace Catch {
  2651. struct ITestCase;
  2652. struct TestCaseInfo {
  2653. enum SpecialProperties{
  2654. None = 0,
  2655. IsHidden = 1 << 1,
  2656. ShouldFail = 1 << 2,
  2657. MayFail = 1 << 3,
  2658. Throws = 1 << 4,
  2659. NonPortable = 1 << 5
  2660. };
  2661. TestCaseInfo( std::string const& _name,
  2662. std::string const& _className,
  2663. std::string const& _description,
  2664. std::set<std::string> const& _tags,
  2665. SourceLineInfo const& _lineInfo );
  2666. TestCaseInfo( TestCaseInfo const& other );
  2667. friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
  2668. bool isHidden() const;
  2669. bool throws() const;
  2670. bool okToFail() const;
  2671. bool expectedToFail() const;
  2672. std::string name;
  2673. std::string className;
  2674. std::string description;
  2675. std::set<std::string> tags;
  2676. std::set<std::string> lcaseTags;
  2677. std::string tagsAsString;
  2678. SourceLineInfo lineInfo;
  2679. SpecialProperties properties;
  2680. };
  2681. class TestCase : public TestCaseInfo {
  2682. public:
  2683. TestCase( ITestCase* testCase, TestCaseInfo const& info );
  2684. TestCase( TestCase const& other );
  2685. TestCase withName( std::string const& _newName ) const;
  2686. void invoke() const;
  2687. TestCaseInfo const& getTestCaseInfo() const;
  2688. void swap( TestCase& other );
  2689. bool operator == ( TestCase const& other ) const;
  2690. bool operator < ( TestCase const& other ) const;
  2691. TestCase& operator = ( TestCase const& other );
  2692. private:
  2693. Ptr<ITestCase> test;
  2694. };
  2695. TestCase makeTestCase( ITestCase* testCase,
  2696. std::string const& className,
  2697. std::string const& name,
  2698. std::string const& description,
  2699. SourceLineInfo const& lineInfo );
  2700. }
  2701. #ifdef __clang__
  2702. #pragma clang diagnostic pop
  2703. #endif
  2704. #ifdef __OBJC__
  2705. // #included from: internal/catch_objc.hpp
  2706. #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
  2707. #import <objc/runtime.h>
  2708. #include <string>
  2709. // NB. Any general catch headers included here must be included
  2710. // in catch.hpp first to make sure they are included by the single
  2711. // header for non obj-usage
  2712. ///////////////////////////////////////////////////////////////////////////////
  2713. // This protocol is really only here for (self) documenting purposes, since
  2714. // all its methods are optional.
  2715. @protocol OcFixture
  2716. @optional
  2717. -(void) setUp;
  2718. -(void) tearDown;
  2719. @end
  2720. namespace Catch {
  2721. class OcMethod : public SharedImpl<ITestCase> {
  2722. public:
  2723. OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
  2724. virtual void invoke() const {
  2725. id obj = [[m_cls alloc] init];
  2726. performOptionalSelector( obj, @selector(setUp) );
  2727. performOptionalSelector( obj, m_sel );
  2728. performOptionalSelector( obj, @selector(tearDown) );
  2729. arcSafeRelease( obj );
  2730. }
  2731. private:
  2732. virtual ~OcMethod() {}
  2733. Class m_cls;
  2734. SEL m_sel;
  2735. };
  2736. namespace Detail{
  2737. inline std::string getAnnotation( Class cls,
  2738. std::string const& annotationName,
  2739. std::string const& testCaseName ) {
  2740. NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
  2741. SEL sel = NSSelectorFromString( selStr );
  2742. arcSafeRelease( selStr );
  2743. id value = performOptionalSelector( cls, sel );
  2744. if( value )
  2745. return [(NSString*)value UTF8String];
  2746. return "";
  2747. }
  2748. }
  2749. inline size_t registerTestMethods() {
  2750. size_t noTestMethods = 0;
  2751. int noClasses = objc_getClassList( CATCH_NULL, 0 );
  2752. Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
  2753. objc_getClassList( classes, noClasses );
  2754. for( int c = 0; c < noClasses; c++ ) {
  2755. Class cls = classes[c];
  2756. {
  2757. u_int count;
  2758. Method* methods = class_copyMethodList( cls, &count );
  2759. for( u_int m = 0; m < count ; m++ ) {
  2760. SEL selector = method_getName(methods[m]);
  2761. std::string methodName = sel_getName(selector);
  2762. if( startsWith( methodName, "Catch_TestCase_" ) ) {
  2763. std::string testCaseName = methodName.substr( 15 );
  2764. std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
  2765. std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
  2766. const char* className = class_getName( cls );
  2767. getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
  2768. noTestMethods++;
  2769. }
  2770. }
  2771. free(methods);
  2772. }
  2773. }
  2774. return noTestMethods;
  2775. }
  2776. namespace Matchers {
  2777. namespace Impl {
  2778. namespace NSStringMatchers {
  2779. struct StringHolder : MatcherBase<NSString*>{
  2780. StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
  2781. StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
  2782. StringHolder() {
  2783. arcSafeRelease( m_substr );
  2784. }
  2785. virtual bool match( NSString* arg ) const CATCH_OVERRIDE {
  2786. return false;
  2787. }
  2788. NSString* m_substr;
  2789. };
  2790. struct Equals : StringHolder {
  2791. Equals( NSString* substr ) : StringHolder( substr ){}
  2792. virtual bool match( NSString* str ) const CATCH_OVERRIDE {
  2793. return (str != nil || m_substr == nil ) &&
  2794. [str isEqualToString:m_substr];
  2795. }
  2796. virtual std::string describe() const CATCH_OVERRIDE {
  2797. return "equals string: " + Catch::toString( m_substr );
  2798. }
  2799. };
  2800. struct Contains : StringHolder {
  2801. Contains( NSString* substr ) : StringHolder( substr ){}
  2802. virtual bool match( NSString* str ) const {
  2803. return (str != nil || m_substr == nil ) &&
  2804. [str rangeOfString:m_substr].location != NSNotFound;
  2805. }
  2806. virtual std::string describe() const CATCH_OVERRIDE {
  2807. return "contains string: " + Catch::toString( m_substr );
  2808. }
  2809. };
  2810. struct StartsWith : StringHolder {
  2811. StartsWith( NSString* substr ) : StringHolder( substr ){}
  2812. virtual bool match( NSString* str ) const {
  2813. return (str != nil || m_substr == nil ) &&
  2814. [str rangeOfString:m_substr].location == 0;
  2815. }
  2816. virtual std::string describe() const CATCH_OVERRIDE {
  2817. return "starts with: " + Catch::toString( m_substr );
  2818. }
  2819. };
  2820. struct EndsWith : StringHolder {
  2821. EndsWith( NSString* substr ) : StringHolder( substr ){}
  2822. virtual bool match( NSString* str ) const {
  2823. return (str != nil || m_substr == nil ) &&
  2824. [str rangeOfString:m_substr].location == [str length] - [m_substr length];
  2825. }
  2826. virtual std::string describe() const CATCH_OVERRIDE {
  2827. return "ends with: " + Catch::toString( m_substr );
  2828. }
  2829. };
  2830. } // namespace NSStringMatchers
  2831. } // namespace Impl
  2832. inline Impl::NSStringMatchers::Equals
  2833. Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
  2834. inline Impl::NSStringMatchers::Contains
  2835. Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
  2836. inline Impl::NSStringMatchers::StartsWith
  2837. StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
  2838. inline Impl::NSStringMatchers::EndsWith
  2839. EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
  2840. } // namespace Matchers
  2841. using namespace Matchers;
  2842. } // namespace Catch
  2843. ///////////////////////////////////////////////////////////////////////////////
  2844. #define OC_TEST_CASE( name, desc )\
  2845. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
  2846. {\
  2847. return @ name; \
  2848. }\
  2849. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
  2850. { \
  2851. return @ desc; \
  2852. } \
  2853. -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
  2854. #endif
  2855. #ifdef CATCH_IMPL
  2856. // !TBD: Move the leak detector code into a separate header
  2857. #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
  2858. #include <crtdbg.h>
  2859. class LeakDetector {
  2860. public:
  2861. LeakDetector() {
  2862. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  2863. flag |= _CRTDBG_LEAK_CHECK_DF;
  2864. flag |= _CRTDBG_ALLOC_MEM_DF;
  2865. _CrtSetDbgFlag(flag);
  2866. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  2867. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  2868. // Change this to leaking allocation's number to break there
  2869. _CrtSetBreakAlloc(-1);
  2870. }
  2871. };
  2872. #else
  2873. class LeakDetector {};
  2874. #endif
  2875. LeakDetector leakDetector;
  2876. // #included from: internal/catch_impl.hpp
  2877. #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
  2878. // Collect all the implementation files together here
  2879. // These are the equivalent of what would usually be cpp files
  2880. #ifdef __clang__
  2881. #pragma clang diagnostic push
  2882. #pragma clang diagnostic ignored "-Wweak-vtables"
  2883. #endif
  2884. // #included from: ../catch_session.hpp
  2885. #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
  2886. // #included from: internal/catch_commandline.hpp
  2887. #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
  2888. // #included from: catch_config.hpp
  2889. #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
  2890. // #included from: catch_test_spec_parser.hpp
  2891. #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  2892. #ifdef __clang__
  2893. #pragma clang diagnostic push
  2894. #pragma clang diagnostic ignored "-Wpadded"
  2895. #endif
  2896. // #included from: catch_test_spec.hpp
  2897. #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  2898. #ifdef __clang__
  2899. #pragma clang diagnostic push
  2900. #pragma clang diagnostic ignored "-Wpadded"
  2901. #endif
  2902. // #included from: catch_wildcard_pattern.hpp
  2903. #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2904. #include <stdexcept>
  2905. namespace Catch
  2906. {
  2907. class WildcardPattern {
  2908. enum WildcardPosition {
  2909. NoWildcard = 0,
  2910. WildcardAtStart = 1,
  2911. WildcardAtEnd = 2,
  2912. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2913. };
  2914. public:
  2915. WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
  2916. : m_caseSensitivity( caseSensitivity ),
  2917. m_wildcard( NoWildcard ),
  2918. m_pattern( adjustCase( pattern ) )
  2919. {
  2920. if( startsWith( m_pattern, '*' ) ) {
  2921. m_pattern = m_pattern.substr( 1 );
  2922. m_wildcard = WildcardAtStart;
  2923. }
  2924. if( endsWith( m_pattern, '*' ) ) {
  2925. m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
  2926. m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
  2927. }
  2928. }
  2929. virtual ~WildcardPattern();
  2930. virtual bool matches( std::string const& str ) const {
  2931. switch( m_wildcard ) {
  2932. case NoWildcard:
  2933. return m_pattern == adjustCase( str );
  2934. case WildcardAtStart:
  2935. return endsWith( adjustCase( str ), m_pattern );
  2936. case WildcardAtEnd:
  2937. return startsWith( adjustCase( str ), m_pattern );
  2938. case WildcardAtBothEnds:
  2939. return contains( adjustCase( str ), m_pattern );
  2940. }
  2941. #ifdef __clang__
  2942. #pragma clang diagnostic push
  2943. #pragma clang diagnostic ignored "-Wunreachable-code"
  2944. #endif
  2945. throw std::logic_error( "Unknown enum" );
  2946. #ifdef __clang__
  2947. #pragma clang diagnostic pop
  2948. #endif
  2949. }
  2950. private:
  2951. std::string adjustCase( std::string const& str ) const {
  2952. return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
  2953. }
  2954. CaseSensitive::Choice m_caseSensitivity;
  2955. WildcardPosition m_wildcard;
  2956. std::string m_pattern;
  2957. };
  2958. }
  2959. #include <string>
  2960. #include <vector>
  2961. namespace Catch {
  2962. class TestSpec {
  2963. struct Pattern : SharedImpl<> {
  2964. virtual ~Pattern();
  2965. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2966. };
  2967. class NamePattern : public Pattern {
  2968. public:
  2969. NamePattern( std::string const& name )
  2970. : m_wildcardPattern( toLower( name ), CaseSensitive::No )
  2971. {}
  2972. virtual ~NamePattern();
  2973. virtual bool matches( TestCaseInfo const& testCase ) const {
  2974. return m_wildcardPattern.matches( toLower( testCase.name ) );
  2975. }
  2976. private:
  2977. WildcardPattern m_wildcardPattern;
  2978. };
  2979. class TagPattern : public Pattern {
  2980. public:
  2981. TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
  2982. virtual ~TagPattern();
  2983. virtual bool matches( TestCaseInfo const& testCase ) const {
  2984. return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
  2985. }
  2986. private:
  2987. std::string m_tag;
  2988. };
  2989. class ExcludedPattern : public Pattern {
  2990. public:
  2991. ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
  2992. virtual ~ExcludedPattern();
  2993. virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
  2994. private:
  2995. Ptr<Pattern> m_underlyingPattern;
  2996. };
  2997. struct Filter {
  2998. std::vector<Ptr<Pattern> > m_patterns;
  2999. bool matches( TestCaseInfo const& testCase ) const {
  3000. // All patterns in a filter must match for the filter to be a match
  3001. for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
  3002. if( !(*it)->matches( testCase ) )
  3003. return false;
  3004. }
  3005. return true;
  3006. }
  3007. };
  3008. public:
  3009. bool hasFilters() const {
  3010. return !m_filters.empty();
  3011. }
  3012. bool matches( TestCaseInfo const& testCase ) const {
  3013. // A TestSpec matches if any filter matches
  3014. for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
  3015. if( it->matches( testCase ) )
  3016. return true;
  3017. return false;
  3018. }
  3019. private:
  3020. std::vector<Filter> m_filters;
  3021. friend class TestSpecParser;
  3022. };
  3023. }
  3024. #ifdef __clang__
  3025. #pragma clang diagnostic pop
  3026. #endif
  3027. namespace Catch {
  3028. class TestSpecParser {
  3029. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  3030. Mode m_mode;
  3031. bool m_exclusion;
  3032. std::size_t m_start, m_pos;
  3033. std::string m_arg;
  3034. std::vector<std::size_t> m_escapeChars;
  3035. TestSpec::Filter m_currentFilter;
  3036. TestSpec m_testSpec;
  3037. ITagAliasRegistry const* m_tagAliases;
  3038. public:
  3039. TestSpecParser( ITagAliasRegistry const& tagAliases ) :m_mode(None), m_exclusion(false), m_start(0), m_pos(0), m_tagAliases( &tagAliases ) {}
  3040. TestSpecParser& parse( std::string const& arg ) {
  3041. m_mode = None;
  3042. m_exclusion = false;
  3043. m_start = std::string::npos;
  3044. m_arg = m_tagAliases->expandAliases( arg );
  3045. m_escapeChars.clear();
  3046. for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
  3047. visitChar( m_arg[m_pos] );
  3048. if( m_mode == Name )
  3049. addPattern<TestSpec::NamePattern>();
  3050. return *this;
  3051. }
  3052. TestSpec testSpec() {
  3053. addFilter();
  3054. return m_testSpec;
  3055. }
  3056. private:
  3057. void visitChar( char c ) {
  3058. if( m_mode == None ) {
  3059. switch( c ) {
  3060. case ' ': return;
  3061. case '~': m_exclusion = true; return;
  3062. case '[': return startNewMode( Tag, ++m_pos );
  3063. case '"': return startNewMode( QuotedName, ++m_pos );
  3064. case '\\': return escape();
  3065. default: startNewMode( Name, m_pos ); break;
  3066. }
  3067. }
  3068. if( m_mode == Name ) {
  3069. if( c == ',' ) {
  3070. addPattern<TestSpec::NamePattern>();
  3071. addFilter();
  3072. }
  3073. else if( c == '[' ) {
  3074. if( subString() == "exclude:" )
  3075. m_exclusion = true;
  3076. else
  3077. addPattern<TestSpec::NamePattern>();
  3078. startNewMode( Tag, ++m_pos );
  3079. }
  3080. else if( c == '\\' )
  3081. escape();
  3082. }
  3083. else if( m_mode == EscapedName )
  3084. m_mode = Name;
  3085. else if( m_mode == QuotedName && c == '"' )
  3086. addPattern<TestSpec::NamePattern>();
  3087. else if( m_mode == Tag && c == ']' )
  3088. addPattern<TestSpec::TagPattern>();
  3089. }
  3090. void startNewMode( Mode mode, std::size_t start ) {
  3091. m_mode = mode;
  3092. m_start = start;
  3093. }
  3094. void escape() {
  3095. if( m_mode == None )
  3096. m_start = m_pos;
  3097. m_mode = EscapedName;
  3098. m_escapeChars.push_back( m_pos );
  3099. }
  3100. std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
  3101. template<typename T>
  3102. void addPattern() {
  3103. std::string token = subString();
  3104. for( size_t i = 0; i < m_escapeChars.size(); ++i )
  3105. token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
  3106. m_escapeChars.clear();
  3107. if( startsWith( token, "exclude:" ) ) {
  3108. m_exclusion = true;
  3109. token = token.substr( 8 );
  3110. }
  3111. if( !token.empty() ) {
  3112. Ptr<TestSpec::Pattern> pattern = new T( token );
  3113. if( m_exclusion )
  3114. pattern = new TestSpec::ExcludedPattern( pattern );
  3115. m_currentFilter.m_patterns.push_back( pattern );
  3116. }
  3117. m_exclusion = false;
  3118. m_mode = None;
  3119. }
  3120. void addFilter() {
  3121. if( !m_currentFilter.m_patterns.empty() ) {
  3122. m_testSpec.m_filters.push_back( m_currentFilter );
  3123. m_currentFilter = TestSpec::Filter();
  3124. }
  3125. }
  3126. };
  3127. inline TestSpec parseTestSpec( std::string const& arg ) {
  3128. return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
  3129. }
  3130. } // namespace Catch
  3131. #ifdef __clang__
  3132. #pragma clang diagnostic pop
  3133. #endif
  3134. // #included from: catch_interfaces_config.h
  3135. #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
  3136. #include <iosfwd>
  3137. #include <string>
  3138. #include <vector>
  3139. namespace Catch {
  3140. struct Verbosity { enum Level {
  3141. NoOutput = 0,
  3142. Quiet,
  3143. Normal
  3144. }; };
  3145. struct WarnAbout { enum What {
  3146. Nothing = 0x00,
  3147. NoAssertions = 0x01
  3148. }; };
  3149. struct ShowDurations { enum OrNot {
  3150. DefaultForReporter,
  3151. Always,
  3152. Never
  3153. }; };
  3154. struct RunTests { enum InWhatOrder {
  3155. InDeclarationOrder,
  3156. InLexicographicalOrder,
  3157. InRandomOrder
  3158. }; };
  3159. struct UseColour { enum YesOrNo {
  3160. Auto,
  3161. Yes,
  3162. No
  3163. }; };
  3164. struct WaitForKeypress { enum When {
  3165. Never,
  3166. BeforeStart = 1,
  3167. BeforeExit = 2,
  3168. BeforeStartAndExit = BeforeStart | BeforeExit
  3169. }; };
  3170. class TestSpec;
  3171. struct IConfig : IShared {
  3172. virtual ~IConfig();
  3173. virtual bool allowThrows() const = 0;
  3174. virtual std::ostream& stream() const = 0;
  3175. virtual std::string name() const = 0;
  3176. virtual bool includeSuccessfulResults() const = 0;
  3177. virtual bool shouldDebugBreak() const = 0;
  3178. virtual bool warnAboutMissingAssertions() const = 0;
  3179. virtual int abortAfter() const = 0;
  3180. virtual bool showInvisibles() const = 0;
  3181. virtual ShowDurations::OrNot showDurations() const = 0;
  3182. virtual TestSpec const& testSpec() const = 0;
  3183. virtual RunTests::InWhatOrder runOrder() const = 0;
  3184. virtual unsigned int rngSeed() const = 0;
  3185. virtual UseColour::YesOrNo useColour() const = 0;
  3186. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  3187. };
  3188. }
  3189. // #included from: catch_stream.h
  3190. #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
  3191. // #included from: catch_streambuf.h
  3192. #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
  3193. #include <streambuf>
  3194. namespace Catch {
  3195. class StreamBufBase : public std::streambuf {
  3196. public:
  3197. virtual ~StreamBufBase() CATCH_NOEXCEPT;
  3198. };
  3199. }
  3200. #include <streambuf>
  3201. #include <ostream>
  3202. #include <fstream>
  3203. #include <memory>
  3204. namespace Catch {
  3205. std::ostream& cout();
  3206. std::ostream& cerr();
  3207. std::ostream& clog();
  3208. struct IStream {
  3209. virtual ~IStream() CATCH_NOEXCEPT;
  3210. virtual std::ostream& stream() const = 0;
  3211. };
  3212. class FileStream : public IStream {
  3213. mutable std::ofstream m_ofs;
  3214. public:
  3215. FileStream( std::string const& filename );
  3216. virtual ~FileStream() CATCH_NOEXCEPT;
  3217. public: // IStream
  3218. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3219. };
  3220. class CoutStream : public IStream {
  3221. mutable std::ostream m_os;
  3222. public:
  3223. CoutStream();
  3224. virtual ~CoutStream() CATCH_NOEXCEPT;
  3225. public: // IStream
  3226. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3227. };
  3228. class DebugOutStream : public IStream {
  3229. CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
  3230. mutable std::ostream m_os;
  3231. public:
  3232. DebugOutStream();
  3233. virtual ~DebugOutStream() CATCH_NOEXCEPT;
  3234. public: // IStream
  3235. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3236. };
  3237. }
  3238. #include <memory>
  3239. #include <vector>
  3240. #include <string>
  3241. #include <stdexcept>
  3242. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  3243. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  3244. #endif
  3245. namespace Catch {
  3246. struct ConfigData {
  3247. ConfigData()
  3248. : listTests( false ),
  3249. listTags( false ),
  3250. listReporters( false ),
  3251. listTestNamesOnly( false ),
  3252. listExtraInfo( false ),
  3253. showSuccessfulTests( false ),
  3254. shouldDebugBreak( false ),
  3255. noThrow( false ),
  3256. showHelp( false ),
  3257. showInvisibles( false ),
  3258. filenamesAsTags( false ),
  3259. libIdentify( false ),
  3260. abortAfter( -1 ),
  3261. rngSeed( 0 ),
  3262. verbosity( Verbosity::Normal ),
  3263. warnings( WarnAbout::Nothing ),
  3264. showDurations( ShowDurations::DefaultForReporter ),
  3265. runOrder( RunTests::InDeclarationOrder ),
  3266. useColour( UseColour::Auto ),
  3267. waitForKeypress( WaitForKeypress::Never )
  3268. {}
  3269. bool listTests;
  3270. bool listTags;
  3271. bool listReporters;
  3272. bool listTestNamesOnly;
  3273. bool listExtraInfo;
  3274. bool showSuccessfulTests;
  3275. bool shouldDebugBreak;
  3276. bool noThrow;
  3277. bool showHelp;
  3278. bool showInvisibles;
  3279. bool filenamesAsTags;
  3280. bool libIdentify;
  3281. int abortAfter;
  3282. unsigned int rngSeed;
  3283. Verbosity::Level verbosity;
  3284. WarnAbout::What warnings;
  3285. ShowDurations::OrNot showDurations;
  3286. RunTests::InWhatOrder runOrder;
  3287. UseColour::YesOrNo useColour;
  3288. WaitForKeypress::When waitForKeypress;
  3289. std::string outputFilename;
  3290. std::string name;
  3291. std::string processName;
  3292. std::vector<std::string> reporterNames;
  3293. std::vector<std::string> testsOrTags;
  3294. std::vector<std::string> sectionsToRun;
  3295. };
  3296. class Config : public SharedImpl<IConfig> {
  3297. private:
  3298. Config( Config const& other );
  3299. Config& operator = ( Config const& other );
  3300. virtual void dummy();
  3301. public:
  3302. Config()
  3303. {}
  3304. Config( ConfigData const& data )
  3305. : m_data( data ),
  3306. m_stream( openStream() )
  3307. {
  3308. if( !data.testsOrTags.empty() ) {
  3309. TestSpecParser parser( ITagAliasRegistry::get() );
  3310. for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
  3311. parser.parse( data.testsOrTags[i] );
  3312. m_testSpec = parser.testSpec();
  3313. }
  3314. }
  3315. virtual ~Config() {}
  3316. std::string const& getFilename() const {
  3317. return m_data.outputFilename ;
  3318. }
  3319. bool listTests() const { return m_data.listTests; }
  3320. bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
  3321. bool listTags() const { return m_data.listTags; }
  3322. bool listReporters() const { return m_data.listReporters; }
  3323. bool listExtraInfo() const { return m_data.listExtraInfo; }
  3324. std::string getProcessName() const { return m_data.processName; }
  3325. std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
  3326. std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; }
  3327. virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; }
  3328. bool showHelp() const { return m_data.showHelp; }
  3329. // IConfig interface
  3330. virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; }
  3331. virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); }
  3332. virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; }
  3333. virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; }
  3334. virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; }
  3335. virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; }
  3336. virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; }
  3337. virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; }
  3338. virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; }
  3339. virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; }
  3340. virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; }
  3341. virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; }
  3342. private:
  3343. IStream const* openStream() {
  3344. if( m_data.outputFilename.empty() )
  3345. return new CoutStream();
  3346. else if( m_data.outputFilename[0] == '%' ) {
  3347. if( m_data.outputFilename == "%debug" )
  3348. return new DebugOutStream();
  3349. else
  3350. throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
  3351. }
  3352. else
  3353. return new FileStream( m_data.outputFilename );
  3354. }
  3355. ConfigData m_data;
  3356. CATCH_AUTO_PTR( IStream const ) m_stream;
  3357. TestSpec m_testSpec;
  3358. };
  3359. } // end namespace Catch
  3360. // #included from: catch_clara.h
  3361. #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
  3362. // Use Catch's value for console width (store Clara's off to the side, if present)
  3363. #ifdef CLARA_CONFIG_CONSOLE_WIDTH
  3364. #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
  3365. #undef CLARA_CONFIG_CONSOLE_WIDTH
  3366. #endif
  3367. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  3368. // Declare Clara inside the Catch namespace
  3369. #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
  3370. // #included from: ../external/clara.h
  3371. // Version 0.0.2.4
  3372. // Only use header guard if we are not using an outer namespace
  3373. #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
  3374. #ifndef STITCH_CLARA_OPEN_NAMESPACE
  3375. #define TWOBLUECUBES_CLARA_H_INCLUDED
  3376. #define STITCH_CLARA_OPEN_NAMESPACE
  3377. #define STITCH_CLARA_CLOSE_NAMESPACE
  3378. #else
  3379. #define STITCH_CLARA_CLOSE_NAMESPACE }
  3380. #endif
  3381. #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
  3382. // ----------- #included from tbc_text_format.h -----------
  3383. // Only use header guard if we are not using an outer namespace
  3384. #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
  3385. #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3386. #define TBC_TEXT_FORMAT_H_INCLUDED
  3387. #endif
  3388. #include <string>
  3389. #include <vector>
  3390. #include <sstream>
  3391. #include <algorithm>
  3392. #include <cctype>
  3393. // Use optional outer namespace
  3394. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3395. namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  3396. #endif
  3397. namespace Tbc {
  3398. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  3399. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  3400. #else
  3401. const unsigned int consoleWidth = 80;
  3402. #endif
  3403. struct TextAttributes {
  3404. TextAttributes()
  3405. : initialIndent( std::string::npos ),
  3406. indent( 0 ),
  3407. width( consoleWidth-1 ),
  3408. tabChar( '\t' )
  3409. {}
  3410. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  3411. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  3412. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  3413. TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
  3414. std::size_t initialIndent; // indent of first line, or npos
  3415. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  3416. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  3417. char tabChar; // If this char is seen the indent is changed to current pos
  3418. };
  3419. class Text {
  3420. public:
  3421. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  3422. : attr( _attr )
  3423. {
  3424. std::string wrappableChars = " [({.,/|\\-";
  3425. std::size_t indent = _attr.initialIndent != std::string::npos
  3426. ? _attr.initialIndent
  3427. : _attr.indent;
  3428. std::string remainder = _str;
  3429. while( !remainder.empty() ) {
  3430. if( lines.size() >= 1000 ) {
  3431. lines.push_back( "... message truncated due to excessive size" );
  3432. return;
  3433. }
  3434. std::size_t tabPos = std::string::npos;
  3435. std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
  3436. std::size_t pos = remainder.find_first_of( '\n' );
  3437. if( pos <= width ) {
  3438. width = pos;
  3439. }
  3440. pos = remainder.find_last_of( _attr.tabChar, width );
  3441. if( pos != std::string::npos ) {
  3442. tabPos = pos;
  3443. if( remainder[width] == '\n' )
  3444. width--;
  3445. remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
  3446. }
  3447. if( width == remainder.size() ) {
  3448. spliceLine( indent, remainder, width );
  3449. }
  3450. else if( remainder[width] == '\n' ) {
  3451. spliceLine( indent, remainder, width );
  3452. if( width <= 1 || remainder.size() != 1 )
  3453. remainder = remainder.substr( 1 );
  3454. indent = _attr.indent;
  3455. }
  3456. else {
  3457. pos = remainder.find_last_of( wrappableChars, width );
  3458. if( pos != std::string::npos && pos > 0 ) {
  3459. spliceLine( indent, remainder, pos );
  3460. if( remainder[0] == ' ' )
  3461. remainder = remainder.substr( 1 );
  3462. }
  3463. else {
  3464. spliceLine( indent, remainder, width-1 );
  3465. lines.back() += "-";
  3466. }
  3467. if( lines.size() == 1 )
  3468. indent = _attr.indent;
  3469. if( tabPos != std::string::npos )
  3470. indent += tabPos;
  3471. }
  3472. }
  3473. }
  3474. void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
  3475. lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
  3476. _remainder = _remainder.substr( _pos );
  3477. }
  3478. typedef std::vector<std::string>::const_iterator const_iterator;
  3479. const_iterator begin() const { return lines.begin(); }
  3480. const_iterator end() const { return lines.end(); }
  3481. std::string const& last() const { return lines.back(); }
  3482. std::size_t size() const { return lines.size(); }
  3483. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  3484. std::string toString() const {
  3485. std::ostringstream oss;
  3486. oss << *this;
  3487. return oss.str();
  3488. }
  3489. friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  3490. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  3491. it != itEnd; ++it ) {
  3492. if( it != _text.begin() )
  3493. _stream << "\n";
  3494. _stream << *it;
  3495. }
  3496. return _stream;
  3497. }
  3498. private:
  3499. std::string str;
  3500. TextAttributes attr;
  3501. std::vector<std::string> lines;
  3502. };
  3503. } // end namespace Tbc
  3504. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3505. } // end outer namespace
  3506. #endif
  3507. #endif // TBC_TEXT_FORMAT_H_INCLUDED
  3508. // ----------- end of #include from tbc_text_format.h -----------
  3509. // ........... back in clara.h
  3510. #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
  3511. // ----------- #included from clara_compilers.h -----------
  3512. #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3513. #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3514. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  3515. // The following features are defined:
  3516. //
  3517. // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
  3518. // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  3519. // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  3520. // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
  3521. // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  3522. // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  3523. // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  3524. // In general each macro has a _NO_<feature name> form
  3525. // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  3526. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  3527. // can be combined, en-mass, with the _NO_ forms later.
  3528. // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
  3529. #ifdef __clang__
  3530. #if __has_feature(cxx_nullptr)
  3531. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3532. #endif
  3533. #if __has_feature(cxx_noexcept)
  3534. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3535. #endif
  3536. #endif // __clang__
  3537. ////////////////////////////////////////////////////////////////////////////////
  3538. // GCC
  3539. #ifdef __GNUC__
  3540. #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  3541. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3542. #endif
  3543. // - otherwise more recent versions define __cplusplus >= 201103L
  3544. // and will get picked up below
  3545. #endif // __GNUC__
  3546. ////////////////////////////////////////////////////////////////////////////////
  3547. // Visual C++
  3548. #ifdef _MSC_VER
  3549. #if (_MSC_VER >= 1600)
  3550. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3551. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3552. #endif
  3553. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  3554. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3555. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3556. #endif
  3557. #endif // _MSC_VER
  3558. ////////////////////////////////////////////////////////////////////////////////
  3559. // C++ language feature support
  3560. // catch all support for C++11
  3561. #if defined(__cplusplus) && __cplusplus >= 201103L
  3562. #define CLARA_CPP11_OR_GREATER
  3563. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
  3564. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3565. #endif
  3566. #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3567. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3568. #endif
  3569. #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3570. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3571. #endif
  3572. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
  3573. #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
  3574. #endif
  3575. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  3576. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3577. #endif
  3578. #endif // __cplusplus >= 201103L
  3579. // Now set the actual defines based on the above + anything the user has configured
  3580. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3581. #define CLARA_CONFIG_CPP11_NULLPTR
  3582. #endif
  3583. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
  3584. #define CLARA_CONFIG_CPP11_NOEXCEPT
  3585. #endif
  3586. #if defined(CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_NO_CPP11)
  3587. #define CLARA_CONFIG_CPP11_GENERATED_METHODS
  3588. #endif
  3589. #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
  3590. #define CLARA_CONFIG_CPP11_OVERRIDE
  3591. #endif
  3592. #if defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_UNIQUE_PTR) && !defined(CLARA_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3593. #define CLARA_CONFIG_CPP11_UNIQUE_PTR
  3594. #endif
  3595. // noexcept support:
  3596. #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
  3597. #define CLARA_NOEXCEPT noexcept
  3598. # define CLARA_NOEXCEPT_IS(x) noexcept(x)
  3599. #else
  3600. #define CLARA_NOEXCEPT throw()
  3601. # define CLARA_NOEXCEPT_IS(x)
  3602. #endif
  3603. // nullptr support
  3604. #ifdef CLARA_CONFIG_CPP11_NULLPTR
  3605. #define CLARA_NULL nullptr
  3606. #else
  3607. #define CLARA_NULL NULL
  3608. #endif
  3609. // override support
  3610. #ifdef CLARA_CONFIG_CPP11_OVERRIDE
  3611. #define CLARA_OVERRIDE override
  3612. #else
  3613. #define CLARA_OVERRIDE
  3614. #endif
  3615. // unique_ptr support
  3616. #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
  3617. # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
  3618. #else
  3619. # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
  3620. #endif
  3621. #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3622. // ----------- end of #include from clara_compilers.h -----------
  3623. // ........... back in clara.h
  3624. #include <map>
  3625. #include <stdexcept>
  3626. #include <memory>
  3627. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  3628. #define CLARA_PLATFORM_WINDOWS
  3629. #endif
  3630. // Use optional outer namespace
  3631. #ifdef STITCH_CLARA_OPEN_NAMESPACE
  3632. STITCH_CLARA_OPEN_NAMESPACE
  3633. #endif
  3634. namespace Clara {
  3635. struct UnpositionalTag {};
  3636. extern UnpositionalTag _;
  3637. #ifdef CLARA_CONFIG_MAIN
  3638. UnpositionalTag _;
  3639. #endif
  3640. namespace Detail {
  3641. #ifdef CLARA_CONSOLE_WIDTH
  3642. const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
  3643. #else
  3644. const unsigned int consoleWidth = 80;
  3645. #endif
  3646. using namespace Tbc;
  3647. inline bool startsWith( std::string const& str, std::string const& prefix ) {
  3648. return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
  3649. }
  3650. template<typename T> struct RemoveConstRef{ typedef T type; };
  3651. template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
  3652. template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
  3653. template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
  3654. template<typename T> struct IsBool { static const bool value = false; };
  3655. template<> struct IsBool<bool> { static const bool value = true; };
  3656. template<typename T>
  3657. void convertInto( std::string const& _source, T& _dest ) {
  3658. std::stringstream ss;
  3659. ss << _source;
  3660. ss >> _dest;
  3661. if( ss.fail() )
  3662. throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
  3663. }
  3664. inline void convertInto( std::string const& _source, std::string& _dest ) {
  3665. _dest = _source;
  3666. }
  3667. char toLowerCh(char c) {
  3668. return static_cast<char>( std::tolower( c ) );
  3669. }
  3670. inline void convertInto( std::string const& _source, bool& _dest ) {
  3671. std::string sourceLC = _source;
  3672. std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
  3673. if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
  3674. _dest = true;
  3675. else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
  3676. _dest = false;
  3677. else
  3678. throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
  3679. }
  3680. template<typename ConfigT>
  3681. struct IArgFunction {
  3682. virtual ~IArgFunction() {}
  3683. #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
  3684. IArgFunction() = default;
  3685. IArgFunction( IArgFunction const& ) = default;
  3686. #endif
  3687. virtual void set( ConfigT& config, std::string const& value ) const = 0;
  3688. virtual bool takesArg() const = 0;
  3689. virtual IArgFunction* clone() const = 0;
  3690. };
  3691. template<typename ConfigT>
  3692. class BoundArgFunction {
  3693. public:
  3694. BoundArgFunction() : functionObj( CLARA_NULL ) {}
  3695. BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
  3696. BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
  3697. BoundArgFunction& operator = ( BoundArgFunction const& other ) {
  3698. IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
  3699. delete functionObj;
  3700. functionObj = newFunctionObj;
  3701. return *this;
  3702. }
  3703. ~BoundArgFunction() { delete functionObj; }
  3704. void set( ConfigT& config, std::string const& value ) const {
  3705. functionObj->set( config, value );
  3706. }
  3707. bool takesArg() const { return functionObj->takesArg(); }
  3708. bool isSet() const {
  3709. return functionObj != CLARA_NULL;
  3710. }
  3711. private:
  3712. IArgFunction<ConfigT>* functionObj;
  3713. };
  3714. template<typename C>
  3715. struct NullBinder : IArgFunction<C>{
  3716. virtual void set( C&, std::string const& ) const {}
  3717. virtual bool takesArg() const { return true; }
  3718. virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
  3719. };
  3720. template<typename C, typename M>
  3721. struct BoundDataMember : IArgFunction<C>{
  3722. BoundDataMember( M C::* _member ) : member( _member ) {}
  3723. virtual void set( C& p, std::string const& stringValue ) const {
  3724. convertInto( stringValue, p.*member );
  3725. }
  3726. virtual bool takesArg() const { return !IsBool<M>::value; }
  3727. virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
  3728. M C::* member;
  3729. };
  3730. template<typename C, typename M>
  3731. struct BoundUnaryMethod : IArgFunction<C>{
  3732. BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
  3733. virtual void set( C& p, std::string const& stringValue ) const {
  3734. typename RemoveConstRef<M>::type value;
  3735. convertInto( stringValue, value );
  3736. (p.*member)( value );
  3737. }
  3738. virtual bool takesArg() const { return !IsBool<M>::value; }
  3739. virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
  3740. void (C::*member)( M );
  3741. };
  3742. template<typename C>
  3743. struct BoundNullaryMethod : IArgFunction<C>{
  3744. BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
  3745. virtual void set( C& p, std::string const& stringValue ) const {
  3746. bool value;
  3747. convertInto( stringValue, value );
  3748. if( value )
  3749. (p.*member)();
  3750. }
  3751. virtual bool takesArg() const { return false; }
  3752. virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
  3753. void (C::*member)();
  3754. };
  3755. template<typename C>
  3756. struct BoundUnaryFunction : IArgFunction<C>{
  3757. BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
  3758. virtual void set( C& obj, std::string const& stringValue ) const {
  3759. bool value;
  3760. convertInto( stringValue, value );
  3761. if( value )
  3762. function( obj );
  3763. }
  3764. virtual bool takesArg() const { return false; }
  3765. virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
  3766. void (*function)( C& );
  3767. };
  3768. template<typename C, typename T>
  3769. struct BoundBinaryFunction : IArgFunction<C>{
  3770. BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
  3771. virtual void set( C& obj, std::string const& stringValue ) const {
  3772. typename RemoveConstRef<T>::type value;
  3773. convertInto( stringValue, value );
  3774. function( obj, value );
  3775. }
  3776. virtual bool takesArg() const { return !IsBool<T>::value; }
  3777. virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
  3778. void (*function)( C&, T );
  3779. };
  3780. } // namespace Detail
  3781. inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
  3782. std::vector<std::string> args( static_cast<std::size_t>( argc ) );
  3783. for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
  3784. args[i] = argv[i];
  3785. return args;
  3786. }
  3787. class Parser {
  3788. enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
  3789. Mode mode;
  3790. std::size_t from;
  3791. bool inQuotes;
  3792. public:
  3793. struct Token {
  3794. enum Type { Positional, ShortOpt, LongOpt };
  3795. Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
  3796. Type type;
  3797. std::string data;
  3798. };
  3799. Parser() : mode( None ), from( 0 ), inQuotes( false ){}
  3800. void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
  3801. const std::string doubleDash = "--";
  3802. for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
  3803. parseIntoTokens( args[i], tokens);
  3804. }
  3805. void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
  3806. for( std::size_t i = 0; i < arg.size(); ++i ) {
  3807. char c = arg[i];
  3808. if( c == '"' )
  3809. inQuotes = !inQuotes;
  3810. mode = handleMode( i, c, arg, tokens );
  3811. }
  3812. mode = handleMode( arg.size(), '\0', arg, tokens );
  3813. }
  3814. Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3815. switch( mode ) {
  3816. case None: return handleNone( i, c );
  3817. case MaybeShortOpt: return handleMaybeShortOpt( i, c );
  3818. case ShortOpt:
  3819. case LongOpt:
  3820. case SlashOpt: return handleOpt( i, c, arg, tokens );
  3821. case Positional: return handlePositional( i, c, arg, tokens );
  3822. default: throw std::logic_error( "Unknown mode" );
  3823. }
  3824. }
  3825. Mode handleNone( std::size_t i, char c ) {
  3826. if( inQuotes ) {
  3827. from = i;
  3828. return Positional;
  3829. }
  3830. switch( c ) {
  3831. case '-': return MaybeShortOpt;
  3832. #ifdef CLARA_PLATFORM_WINDOWS
  3833. case '/': from = i+1; return SlashOpt;
  3834. #endif
  3835. default: from = i; return Positional;
  3836. }
  3837. }
  3838. Mode handleMaybeShortOpt( std::size_t i, char c ) {
  3839. switch( c ) {
  3840. case '-': from = i+1; return LongOpt;
  3841. default: from = i; return ShortOpt;
  3842. }
  3843. }
  3844. Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3845. if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
  3846. return mode;
  3847. std::string optName = arg.substr( from, i-from );
  3848. if( mode == ShortOpt )
  3849. for( std::size_t j = 0; j < optName.size(); ++j )
  3850. tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
  3851. else if( mode == SlashOpt && optName.size() == 1 )
  3852. tokens.push_back( Token( Token::ShortOpt, optName ) );
  3853. else
  3854. tokens.push_back( Token( Token::LongOpt, optName ) );
  3855. return None;
  3856. }
  3857. Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3858. if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
  3859. return mode;
  3860. std::string data = arg.substr( from, i-from );
  3861. tokens.push_back( Token( Token::Positional, data ) );
  3862. return None;
  3863. }
  3864. };
  3865. template<typename ConfigT>
  3866. struct CommonArgProperties {
  3867. CommonArgProperties() {}
  3868. CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
  3869. Detail::BoundArgFunction<ConfigT> boundField;
  3870. std::string description;
  3871. std::string detail;
  3872. std::string placeholder; // Only value if boundField takes an arg
  3873. bool takesArg() const {
  3874. return !placeholder.empty();
  3875. }
  3876. void validate() const {
  3877. if( !boundField.isSet() )
  3878. throw std::logic_error( "option not bound" );
  3879. }
  3880. };
  3881. struct OptionArgProperties {
  3882. std::vector<std::string> shortNames;
  3883. std::string longName;
  3884. bool hasShortName( std::string const& shortName ) const {
  3885. return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
  3886. }
  3887. bool hasLongName( std::string const& _longName ) const {
  3888. return _longName == longName;
  3889. }
  3890. };
  3891. struct PositionalArgProperties {
  3892. PositionalArgProperties() : position( -1 ) {}
  3893. int position; // -1 means non-positional (floating)
  3894. bool isFixedPositional() const {
  3895. return position != -1;
  3896. }
  3897. };
  3898. template<typename ConfigT>
  3899. class CommandLine {
  3900. struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
  3901. Arg() {}
  3902. Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
  3903. using CommonArgProperties<ConfigT>::placeholder; // !TBD
  3904. std::string dbgName() const {
  3905. if( !longName.empty() )
  3906. return "--" + longName;
  3907. if( !shortNames.empty() )
  3908. return "-" + shortNames[0];
  3909. return "positional args";
  3910. }
  3911. std::string commands() const {
  3912. std::ostringstream oss;
  3913. bool first = true;
  3914. std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
  3915. for(; it != itEnd; ++it ) {
  3916. if( first )
  3917. first = false;
  3918. else
  3919. oss << ", ";
  3920. oss << "-" << *it;
  3921. }
  3922. if( !longName.empty() ) {
  3923. if( !first )
  3924. oss << ", ";
  3925. oss << "--" << longName;
  3926. }
  3927. if( !placeholder.empty() )
  3928. oss << " <" << placeholder << ">";
  3929. return oss.str();
  3930. }
  3931. };
  3932. typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
  3933. friend void addOptName( Arg& arg, std::string const& optName )
  3934. {
  3935. if( optName.empty() )
  3936. return;
  3937. if( Detail::startsWith( optName, "--" ) ) {
  3938. if( !arg.longName.empty() )
  3939. throw std::logic_error( "Only one long opt may be specified. '"
  3940. + arg.longName
  3941. + "' already specified, now attempting to add '"
  3942. + optName + "'" );
  3943. arg.longName = optName.substr( 2 );
  3944. }
  3945. else if( Detail::startsWith( optName, "-" ) )
  3946. arg.shortNames.push_back( optName.substr( 1 ) );
  3947. else
  3948. throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
  3949. }
  3950. friend void setPositionalArg( Arg& arg, int position )
  3951. {
  3952. arg.position = position;
  3953. }
  3954. class ArgBuilder {
  3955. public:
  3956. ArgBuilder( Arg* arg ) : m_arg( arg ) {}
  3957. // Bind a non-boolean data member (requires placeholder string)
  3958. template<typename C, typename M>
  3959. void bind( M C::* field, std::string const& placeholder ) {
  3960. m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
  3961. m_arg->placeholder = placeholder;
  3962. }
  3963. // Bind a boolean data member (no placeholder required)
  3964. template<typename C>
  3965. void bind( bool C::* field ) {
  3966. m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
  3967. }
  3968. // Bind a method taking a single, non-boolean argument (requires a placeholder string)
  3969. template<typename C, typename M>
  3970. void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
  3971. m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
  3972. m_arg->placeholder = placeholder;
  3973. }
  3974. // Bind a method taking a single, boolean argument (no placeholder string required)
  3975. template<typename C>
  3976. void bind( void (C::* unaryMethod)( bool ) ) {
  3977. m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
  3978. }
  3979. // Bind a method that takes no arguments (will be called if opt is present)
  3980. template<typename C>
  3981. void bind( void (C::* nullaryMethod)() ) {
  3982. m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
  3983. }
  3984. // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
  3985. template<typename C>
  3986. void bind( void (* unaryFunction)( C& ) ) {
  3987. m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
  3988. }
  3989. // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
  3990. template<typename C, typename T>
  3991. void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
  3992. m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
  3993. m_arg->placeholder = placeholder;
  3994. }
  3995. ArgBuilder& describe( std::string const& description ) {
  3996. m_arg->description = description;
  3997. return *this;
  3998. }
  3999. ArgBuilder& detail( std::string const& detail ) {
  4000. m_arg->detail = detail;
  4001. return *this;
  4002. }
  4003. protected:
  4004. Arg* m_arg;
  4005. };
  4006. class OptBuilder : public ArgBuilder {
  4007. public:
  4008. OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
  4009. OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
  4010. OptBuilder& operator[]( std::string const& optName ) {
  4011. addOptName( *ArgBuilder::m_arg, optName );
  4012. return *this;
  4013. }
  4014. };
  4015. public:
  4016. CommandLine()
  4017. : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
  4018. m_highestSpecifiedArgPosition( 0 ),
  4019. m_throwOnUnrecognisedTokens( false )
  4020. {}
  4021. CommandLine( CommandLine const& other )
  4022. : m_boundProcessName( other.m_boundProcessName ),
  4023. m_options ( other.m_options ),
  4024. m_positionalArgs( other.m_positionalArgs ),
  4025. m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
  4026. m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
  4027. {
  4028. if( other.m_floatingArg.get() )
  4029. m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
  4030. }
  4031. CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
  4032. m_throwOnUnrecognisedTokens = shouldThrow;
  4033. return *this;
  4034. }
  4035. OptBuilder operator[]( std::string const& optName ) {
  4036. m_options.push_back( Arg() );
  4037. addOptName( m_options.back(), optName );
  4038. OptBuilder builder( &m_options.back() );
  4039. return builder;
  4040. }
  4041. ArgBuilder operator[]( int position ) {
  4042. m_positionalArgs.insert( std::make_pair( position, Arg() ) );
  4043. if( position > m_highestSpecifiedArgPosition )
  4044. m_highestSpecifiedArgPosition = position;
  4045. setPositionalArg( m_positionalArgs[position], position );
  4046. ArgBuilder builder( &m_positionalArgs[position] );
  4047. return builder;
  4048. }
  4049. // Invoke this with the _ instance
  4050. ArgBuilder operator[]( UnpositionalTag ) {
  4051. if( m_floatingArg.get() )
  4052. throw std::logic_error( "Only one unpositional argument can be added" );
  4053. m_floatingArg.reset( new Arg() );
  4054. ArgBuilder builder( m_floatingArg.get() );
  4055. return builder;
  4056. }
  4057. template<typename C, typename M>
  4058. void bindProcessName( M C::* field ) {
  4059. m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
  4060. }
  4061. template<typename C, typename M>
  4062. void bindProcessName( void (C::*_unaryMethod)( M ) ) {
  4063. m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
  4064. }
  4065. void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
  4066. typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
  4067. std::size_t maxWidth = 0;
  4068. for( it = itBegin; it != itEnd; ++it )
  4069. maxWidth = (std::max)( maxWidth, it->commands().size() );
  4070. for( it = itBegin; it != itEnd; ++it ) {
  4071. Detail::Text usage( it->commands(), Detail::TextAttributes()
  4072. .setWidth( maxWidth+indent )
  4073. .setIndent( indent ) );
  4074. Detail::Text desc( it->description, Detail::TextAttributes()
  4075. .setWidth( width - maxWidth - 3 ) );
  4076. for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
  4077. std::string usageCol = i < usage.size() ? usage[i] : "";
  4078. os << usageCol;
  4079. if( i < desc.size() && !desc[i].empty() )
  4080. os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
  4081. << desc[i];
  4082. os << "\n";
  4083. }
  4084. }
  4085. }
  4086. std::string optUsage() const {
  4087. std::ostringstream oss;
  4088. optUsage( oss );
  4089. return oss.str();
  4090. }
  4091. void argSynopsis( std::ostream& os ) const {
  4092. for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
  4093. if( i > 1 )
  4094. os << " ";
  4095. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
  4096. if( it != m_positionalArgs.end() )
  4097. os << "<" << it->second.placeholder << ">";
  4098. else if( m_floatingArg.get() )
  4099. os << "<" << m_floatingArg->placeholder << ">";
  4100. else
  4101. throw std::logic_error( "non consecutive positional arguments with no floating args" );
  4102. }
  4103. // !TBD No indication of mandatory args
  4104. if( m_floatingArg.get() ) {
  4105. if( m_highestSpecifiedArgPosition > 1 )
  4106. os << " ";
  4107. os << "[<" << m_floatingArg->placeholder << "> ...]";
  4108. }
  4109. }
  4110. std::string argSynopsis() const {
  4111. std::ostringstream oss;
  4112. argSynopsis( oss );
  4113. return oss.str();
  4114. }
  4115. void usage( std::ostream& os, std::string const& procName ) const {
  4116. validate();
  4117. os << "usage:\n " << procName << " ";
  4118. argSynopsis( os );
  4119. if( !m_options.empty() ) {
  4120. os << " [options]\n\nwhere options are: \n";
  4121. optUsage( os, 2 );
  4122. }
  4123. os << "\n";
  4124. }
  4125. std::string usage( std::string const& procName ) const {
  4126. std::ostringstream oss;
  4127. usage( oss, procName );
  4128. return oss.str();
  4129. }
  4130. ConfigT parse( std::vector<std::string> const& args ) const {
  4131. ConfigT config;
  4132. parseInto( args, config );
  4133. return config;
  4134. }
  4135. std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
  4136. std::string processName = args.empty() ? std::string() : args[0];
  4137. std::size_t lastSlash = processName.find_last_of( "/\\" );
  4138. if( lastSlash != std::string::npos )
  4139. processName = processName.substr( lastSlash+1 );
  4140. m_boundProcessName.set( config, processName );
  4141. std::vector<Parser::Token> tokens;
  4142. Parser parser;
  4143. parser.parseIntoTokens( args, tokens );
  4144. return populate( tokens, config );
  4145. }
  4146. std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4147. validate();
  4148. std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
  4149. unusedTokens = populateFixedArgs( unusedTokens, config );
  4150. unusedTokens = populateFloatingArgs( unusedTokens, config );
  4151. return unusedTokens;
  4152. }
  4153. std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4154. std::vector<Parser::Token> unusedTokens;
  4155. std::vector<std::string> errors;
  4156. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4157. Parser::Token const& token = tokens[i];
  4158. typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
  4159. for(; it != itEnd; ++it ) {
  4160. Arg const& arg = *it;
  4161. try {
  4162. if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
  4163. ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
  4164. if( arg.takesArg() ) {
  4165. if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
  4166. errors.push_back( "Expected argument to option: " + token.data );
  4167. else
  4168. arg.boundField.set( config, tokens[++i].data );
  4169. }
  4170. else {
  4171. arg.boundField.set( config, "true" );
  4172. }
  4173. break;
  4174. }
  4175. }
  4176. catch( std::exception& ex ) {
  4177. errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
  4178. }
  4179. }
  4180. if( it == itEnd ) {
  4181. if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
  4182. unusedTokens.push_back( token );
  4183. else if( errors.empty() && m_throwOnUnrecognisedTokens )
  4184. errors.push_back( "unrecognised option: " + token.data );
  4185. }
  4186. }
  4187. if( !errors.empty() ) {
  4188. std::ostringstream oss;
  4189. for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
  4190. it != itEnd;
  4191. ++it ) {
  4192. if( it != errors.begin() )
  4193. oss << "\n";
  4194. oss << *it;
  4195. }
  4196. throw std::runtime_error( oss.str() );
  4197. }
  4198. return unusedTokens;
  4199. }
  4200. std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4201. std::vector<Parser::Token> unusedTokens;
  4202. int position = 1;
  4203. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4204. Parser::Token const& token = tokens[i];
  4205. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
  4206. if( it != m_positionalArgs.end() )
  4207. it->second.boundField.set( config, token.data );
  4208. else
  4209. unusedTokens.push_back( token );
  4210. if( token.type == Parser::Token::Positional )
  4211. position++;
  4212. }
  4213. return unusedTokens;
  4214. }
  4215. std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4216. if( !m_floatingArg.get() )
  4217. return tokens;
  4218. std::vector<Parser::Token> unusedTokens;
  4219. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4220. Parser::Token const& token = tokens[i];
  4221. if( token.type == Parser::Token::Positional )
  4222. m_floatingArg->boundField.set( config, token.data );
  4223. else
  4224. unusedTokens.push_back( token );
  4225. }
  4226. return unusedTokens;
  4227. }
  4228. void validate() const
  4229. {
  4230. if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
  4231. throw std::logic_error( "No options or arguments specified" );
  4232. for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
  4233. itEnd = m_options.end();
  4234. it != itEnd; ++it )
  4235. it->validate();
  4236. }
  4237. private:
  4238. Detail::BoundArgFunction<ConfigT> m_boundProcessName;
  4239. std::vector<Arg> m_options;
  4240. std::map<int, Arg> m_positionalArgs;
  4241. ArgAutoPtr m_floatingArg;
  4242. int m_highestSpecifiedArgPosition;
  4243. bool m_throwOnUnrecognisedTokens;
  4244. };
  4245. } // end namespace Clara
  4246. STITCH_CLARA_CLOSE_NAMESPACE
  4247. #undef STITCH_CLARA_OPEN_NAMESPACE
  4248. #undef STITCH_CLARA_CLOSE_NAMESPACE
  4249. #endif // TWOBLUECUBES_CLARA_H_INCLUDED
  4250. #undef STITCH_CLARA_OPEN_NAMESPACE
  4251. // Restore Clara's value for console width, if present
  4252. #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4253. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4254. #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4255. #endif
  4256. #include <fstream>
  4257. #include <ctime>
  4258. namespace Catch {
  4259. inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
  4260. inline void abortAfterX( ConfigData& config, int x ) {
  4261. if( x < 1 )
  4262. throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
  4263. config.abortAfter = x;
  4264. }
  4265. inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
  4266. inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); }
  4267. inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
  4268. inline void addWarning( ConfigData& config, std::string const& _warning ) {
  4269. if( _warning == "NoAssertions" )
  4270. config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
  4271. else
  4272. throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' );
  4273. }
  4274. inline void setOrder( ConfigData& config, std::string const& order ) {
  4275. if( startsWith( "declared", order ) )
  4276. config.runOrder = RunTests::InDeclarationOrder;
  4277. else if( startsWith( "lexical", order ) )
  4278. config.runOrder = RunTests::InLexicographicalOrder;
  4279. else if( startsWith( "random", order ) )
  4280. config.runOrder = RunTests::InRandomOrder;
  4281. else
  4282. throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' );
  4283. }
  4284. inline void setRngSeed( ConfigData& config, std::string const& seed ) {
  4285. if( seed == "time" ) {
  4286. config.rngSeed = static_cast<unsigned int>( std::time(0) );
  4287. }
  4288. else {
  4289. std::stringstream ss;
  4290. ss << seed;
  4291. ss >> config.rngSeed;
  4292. if( ss.fail() )
  4293. throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" );
  4294. }
  4295. }
  4296. inline void setVerbosity( ConfigData& config, int level ) {
  4297. // !TBD: accept strings?
  4298. config.verbosity = static_cast<Verbosity::Level>( level );
  4299. }
  4300. inline void setShowDurations( ConfigData& config, bool _showDurations ) {
  4301. config.showDurations = _showDurations
  4302. ? ShowDurations::Always
  4303. : ShowDurations::Never;
  4304. }
  4305. inline void setUseColour( ConfigData& config, std::string const& value ) {
  4306. std::string mode = toLower( value );
  4307. if( mode == "yes" )
  4308. config.useColour = UseColour::Yes;
  4309. else if( mode == "no" )
  4310. config.useColour = UseColour::No;
  4311. else if( mode == "auto" )
  4312. config.useColour = UseColour::Auto;
  4313. else
  4314. throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
  4315. }
  4316. inline void setWaitForKeypress( ConfigData& config, std::string const& keypress ) {
  4317. std::string keypressLc = toLower( keypress );
  4318. if( keypressLc == "start" )
  4319. config.waitForKeypress = WaitForKeypress::BeforeStart;
  4320. else if( keypressLc == "exit" )
  4321. config.waitForKeypress = WaitForKeypress::BeforeExit;
  4322. else if( keypressLc == "both" )
  4323. config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
  4324. else
  4325. throw std::runtime_error( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
  4326. };
  4327. inline void forceColour( ConfigData& config ) {
  4328. config.useColour = UseColour::Yes;
  4329. }
  4330. inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
  4331. std::ifstream f( _filename.c_str() );
  4332. if( !f.is_open() )
  4333. throw std::domain_error( "Unable to load input file: " + _filename );
  4334. std::string line;
  4335. while( std::getline( f, line ) ) {
  4336. line = trim(line);
  4337. if( !line.empty() && !startsWith( line, '#' ) ) {
  4338. if( !startsWith( line, '"' ) )
  4339. line = '"' + line + '"';
  4340. addTestOrTags( config, line + ',' );
  4341. }
  4342. }
  4343. }
  4344. inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
  4345. using namespace Clara;
  4346. CommandLine<ConfigData> cli;
  4347. cli.bindProcessName( &ConfigData::processName );
  4348. cli["-?"]["-h"]["--help"]
  4349. .describe( "display usage information" )
  4350. .bind( &ConfigData::showHelp );
  4351. cli["-l"]["--list-tests"]
  4352. .describe( "list all/matching test cases" )
  4353. .bind( &ConfigData::listTests );
  4354. cli["-t"]["--list-tags"]
  4355. .describe( "list all/matching tags" )
  4356. .bind( &ConfigData::listTags );
  4357. cli["-s"]["--success"]
  4358. .describe( "include successful tests in output" )
  4359. .bind( &ConfigData::showSuccessfulTests );
  4360. cli["-b"]["--break"]
  4361. .describe( "break into debugger on failure" )
  4362. .bind( &ConfigData::shouldDebugBreak );
  4363. cli["-e"]["--nothrow"]
  4364. .describe( "skip exception tests" )
  4365. .bind( &ConfigData::noThrow );
  4366. cli["-i"]["--invisibles"]
  4367. .describe( "show invisibles (tabs, newlines)" )
  4368. .bind( &ConfigData::showInvisibles );
  4369. cli["-o"]["--out"]
  4370. .describe( "output filename" )
  4371. .bind( &ConfigData::outputFilename, "filename" );
  4372. cli["-r"]["--reporter"]
  4373. // .placeholder( "name[:filename]" )
  4374. .describe( "reporter to use (defaults to console)" )
  4375. .bind( &addReporterName, "name" );
  4376. cli["-n"]["--name"]
  4377. .describe( "suite name" )
  4378. .bind( &ConfigData::name, "name" );
  4379. cli["-a"]["--abort"]
  4380. .describe( "abort at first failure" )
  4381. .bind( &abortAfterFirst );
  4382. cli["-x"]["--abortx"]
  4383. .describe( "abort after x failures" )
  4384. .bind( &abortAfterX, "no. failures" );
  4385. cli["-w"]["--warn"]
  4386. .describe( "enable warnings" )
  4387. .bind( &addWarning, "warning name" );
  4388. // - needs updating if reinstated
  4389. // cli.into( &setVerbosity )
  4390. // .describe( "level of verbosity (0=no output)" )
  4391. // .shortOpt( "v")
  4392. // .longOpt( "verbosity" )
  4393. // .placeholder( "level" );
  4394. cli[_]
  4395. .describe( "which test or tests to use" )
  4396. .bind( &addTestOrTags, "test name, pattern or tags" );
  4397. cli["-d"]["--durations"]
  4398. .describe( "show test durations" )
  4399. .bind( &setShowDurations, "yes|no" );
  4400. cli["-f"]["--input-file"]
  4401. .describe( "load test names to run from a file" )
  4402. .bind( &loadTestNamesFromFile, "filename" );
  4403. cli["-#"]["--filenames-as-tags"]
  4404. .describe( "adds a tag for the filename" )
  4405. .bind( &ConfigData::filenamesAsTags );
  4406. cli["-c"]["--section"]
  4407. .describe( "specify section to run" )
  4408. .bind( &addSectionToRun, "section name" );
  4409. // Less common commands which don't have a short form
  4410. cli["--list-test-names-only"]
  4411. .describe( "list all/matching test cases names only" )
  4412. .bind( &ConfigData::listTestNamesOnly );
  4413. cli["--list-extra-info"]
  4414. .describe( "list all/matching test cases with more info" )
  4415. .bind( &ConfigData::listExtraInfo );
  4416. cli["--list-reporters"]
  4417. .describe( "list all reporters" )
  4418. .bind( &ConfigData::listReporters );
  4419. cli["--order"]
  4420. .describe( "test case order (defaults to decl)" )
  4421. .bind( &setOrder, "decl|lex|rand" );
  4422. cli["--rng-seed"]
  4423. .describe( "set a specific seed for random numbers" )
  4424. .bind( &setRngSeed, "'time'|number" );
  4425. cli["--force-colour"]
  4426. .describe( "force colourised output (deprecated)" )
  4427. .bind( &forceColour );
  4428. cli["--use-colour"]
  4429. .describe( "should output be colourised" )
  4430. .bind( &setUseColour, "yes|no" );
  4431. cli["--libidentify"]
  4432. .describe( "report name and version according to libidentify standard" )
  4433. .bind( &ConfigData::libIdentify );
  4434. cli["--wait-for-keypress"]
  4435. .describe( "waits for a keypress before exiting" )
  4436. .bind( &setWaitForKeypress, "start|exit|both" );
  4437. return cli;
  4438. }
  4439. } // end namespace Catch
  4440. // #included from: internal/catch_list.hpp
  4441. #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
  4442. // #included from: catch_text.h
  4443. #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
  4444. #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  4445. #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
  4446. // #included from: ../external/tbc_text_format.h
  4447. // Only use header guard if we are not using an outer namespace
  4448. #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4449. # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4450. # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4451. # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4452. # endif
  4453. # else
  4454. # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4455. # endif
  4456. #endif
  4457. #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4458. #include <string>
  4459. #include <vector>
  4460. #include <sstream>
  4461. // Use optional outer namespace
  4462. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4463. namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  4464. #endif
  4465. namespace Tbc {
  4466. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  4467. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  4468. #else
  4469. const unsigned int consoleWidth = 80;
  4470. #endif
  4471. struct TextAttributes {
  4472. TextAttributes()
  4473. : initialIndent( std::string::npos ),
  4474. indent( 0 ),
  4475. width( consoleWidth-1 )
  4476. {}
  4477. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  4478. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  4479. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  4480. std::size_t initialIndent; // indent of first line, or npos
  4481. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  4482. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  4483. };
  4484. class Text {
  4485. public:
  4486. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  4487. : attr( _attr )
  4488. {
  4489. const std::string wrappableBeforeChars = "[({<\t";
  4490. const std::string wrappableAfterChars = "])}>-,./|\\";
  4491. const std::string wrappableInsteadOfChars = " \n\r";
  4492. std::string indent = _attr.initialIndent != std::string::npos
  4493. ? std::string( _attr.initialIndent, ' ' )
  4494. : std::string( _attr.indent, ' ' );
  4495. typedef std::string::const_iterator iterator;
  4496. iterator it = _str.begin();
  4497. const iterator strEnd = _str.end();
  4498. while( it != strEnd ) {
  4499. if( lines.size() >= 1000 ) {
  4500. lines.push_back( "... message truncated due to excessive size" );
  4501. return;
  4502. }
  4503. std::string suffix;
  4504. std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
  4505. iterator itEnd = it+width;
  4506. iterator itNext = _str.end();
  4507. iterator itNewLine = std::find( it, itEnd, '\n' );
  4508. if( itNewLine != itEnd )
  4509. itEnd = itNewLine;
  4510. if( itEnd != strEnd ) {
  4511. bool foundWrapPoint = false;
  4512. iterator findIt = itEnd;
  4513. do {
  4514. if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
  4515. itEnd = findIt+1;
  4516. itNext = findIt+1;
  4517. foundWrapPoint = true;
  4518. }
  4519. else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
  4520. itEnd = findIt;
  4521. itNext = findIt;
  4522. foundWrapPoint = true;
  4523. }
  4524. else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
  4525. itNext = findIt+1;
  4526. itEnd = findIt;
  4527. foundWrapPoint = true;
  4528. }
  4529. if( findIt == it )
  4530. break;
  4531. else
  4532. --findIt;
  4533. }
  4534. while( !foundWrapPoint );
  4535. if( !foundWrapPoint ) {
  4536. // No good wrap char, so we'll break mid word and add a hyphen
  4537. --itEnd;
  4538. itNext = itEnd;
  4539. suffix = "-";
  4540. }
  4541. else {
  4542. while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
  4543. --itEnd;
  4544. }
  4545. }
  4546. lines.push_back( indent + std::string( it, itEnd ) + suffix );
  4547. if( indent.size() != _attr.indent )
  4548. indent = std::string( _attr.indent, ' ' );
  4549. it = itNext;
  4550. }
  4551. }
  4552. typedef std::vector<std::string>::const_iterator const_iterator;
  4553. const_iterator begin() const { return lines.begin(); }
  4554. const_iterator end() const { return lines.end(); }
  4555. std::string const& last() const { return lines.back(); }
  4556. std::size_t size() const { return lines.size(); }
  4557. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  4558. std::string toString() const {
  4559. std::ostringstream oss;
  4560. oss << *this;
  4561. return oss.str();
  4562. }
  4563. inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  4564. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  4565. it != itEnd; ++it ) {
  4566. if( it != _text.begin() )
  4567. _stream << "\n";
  4568. _stream << *it;
  4569. }
  4570. return _stream;
  4571. }
  4572. private:
  4573. std::string str;
  4574. TextAttributes attr;
  4575. std::vector<std::string> lines;
  4576. };
  4577. } // end namespace Tbc
  4578. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4579. } // end outer namespace
  4580. #endif
  4581. #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4582. #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4583. namespace Catch {
  4584. using Tbc::Text;
  4585. using Tbc::TextAttributes;
  4586. }
  4587. // #included from: catch_console_colour.hpp
  4588. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  4589. namespace Catch {
  4590. struct Colour {
  4591. enum Code {
  4592. None = 0,
  4593. White,
  4594. Red,
  4595. Green,
  4596. Blue,
  4597. Cyan,
  4598. Yellow,
  4599. Grey,
  4600. Bright = 0x10,
  4601. BrightRed = Bright | Red,
  4602. BrightGreen = Bright | Green,
  4603. LightGrey = Bright | Grey,
  4604. BrightWhite = Bright | White,
  4605. // By intention
  4606. FileName = LightGrey,
  4607. Warning = Yellow,
  4608. ResultError = BrightRed,
  4609. ResultSuccess = BrightGreen,
  4610. ResultExpectedFailure = Warning,
  4611. Error = BrightRed,
  4612. Success = Green,
  4613. OriginalExpression = Cyan,
  4614. ReconstructedExpression = Yellow,
  4615. SecondaryText = LightGrey,
  4616. Headers = White
  4617. };
  4618. // Use constructed object for RAII guard
  4619. Colour( Code _colourCode );
  4620. Colour( Colour const& other );
  4621. ~Colour();
  4622. // Use static method for one-shot changes
  4623. static void use( Code _colourCode );
  4624. private:
  4625. bool m_moved;
  4626. };
  4627. inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
  4628. } // end namespace Catch
  4629. // #included from: catch_interfaces_reporter.h
  4630. #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
  4631. #include <string>
  4632. #include <ostream>
  4633. #include <map>
  4634. namespace Catch
  4635. {
  4636. struct ReporterConfig {
  4637. explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
  4638. : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
  4639. ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
  4640. : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
  4641. std::ostream& stream() const { return *m_stream; }
  4642. Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
  4643. private:
  4644. std::ostream* m_stream;
  4645. Ptr<IConfig const> m_fullConfig;
  4646. };
  4647. struct ReporterPreferences {
  4648. ReporterPreferences()
  4649. : shouldRedirectStdOut( false )
  4650. {}
  4651. bool shouldRedirectStdOut;
  4652. };
  4653. template<typename T>
  4654. struct LazyStat : Option<T> {
  4655. LazyStat() : used( false ) {}
  4656. LazyStat& operator=( T const& _value ) {
  4657. Option<T>::operator=( _value );
  4658. used = false;
  4659. return *this;
  4660. }
  4661. void reset() {
  4662. Option<T>::reset();
  4663. used = false;
  4664. }
  4665. bool used;
  4666. };
  4667. struct TestRunInfo {
  4668. TestRunInfo( std::string const& _name ) : name( _name ) {}
  4669. std::string name;
  4670. };
  4671. struct GroupInfo {
  4672. GroupInfo( std::string const& _name,
  4673. std::size_t _groupIndex,
  4674. std::size_t _groupsCount )
  4675. : name( _name ),
  4676. groupIndex( _groupIndex ),
  4677. groupsCounts( _groupsCount )
  4678. {}
  4679. std::string name;
  4680. std::size_t groupIndex;
  4681. std::size_t groupsCounts;
  4682. };
  4683. struct AssertionStats {
  4684. AssertionStats( AssertionResult const& _assertionResult,
  4685. std::vector<MessageInfo> const& _infoMessages,
  4686. Totals const& _totals )
  4687. : assertionResult( _assertionResult ),
  4688. infoMessages( _infoMessages ),
  4689. totals( _totals )
  4690. {
  4691. if( assertionResult.hasMessage() ) {
  4692. // Copy message into messages list.
  4693. // !TBD This should have been done earlier, somewhere
  4694. MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
  4695. builder << assertionResult.getMessage();
  4696. builder.m_info.message = builder.m_stream.str();
  4697. infoMessages.push_back( builder.m_info );
  4698. }
  4699. }
  4700. virtual ~AssertionStats();
  4701. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4702. AssertionStats( AssertionStats const& ) = default;
  4703. AssertionStats( AssertionStats && ) = default;
  4704. AssertionStats& operator = ( AssertionStats const& ) = default;
  4705. AssertionStats& operator = ( AssertionStats && ) = default;
  4706. # endif
  4707. AssertionResult assertionResult;
  4708. std::vector<MessageInfo> infoMessages;
  4709. Totals totals;
  4710. };
  4711. struct SectionStats {
  4712. SectionStats( SectionInfo const& _sectionInfo,
  4713. Counts const& _assertions,
  4714. double _durationInSeconds,
  4715. bool _missingAssertions )
  4716. : sectionInfo( _sectionInfo ),
  4717. assertions( _assertions ),
  4718. durationInSeconds( _durationInSeconds ),
  4719. missingAssertions( _missingAssertions )
  4720. {}
  4721. virtual ~SectionStats();
  4722. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4723. SectionStats( SectionStats const& ) = default;
  4724. SectionStats( SectionStats && ) = default;
  4725. SectionStats& operator = ( SectionStats const& ) = default;
  4726. SectionStats& operator = ( SectionStats && ) = default;
  4727. # endif
  4728. SectionInfo sectionInfo;
  4729. Counts assertions;
  4730. double durationInSeconds;
  4731. bool missingAssertions;
  4732. };
  4733. struct TestCaseStats {
  4734. TestCaseStats( TestCaseInfo const& _testInfo,
  4735. Totals const& _totals,
  4736. std::string const& _stdOut,
  4737. std::string const& _stdErr,
  4738. bool _aborting )
  4739. : testInfo( _testInfo ),
  4740. totals( _totals ),
  4741. stdOut( _stdOut ),
  4742. stdErr( _stdErr ),
  4743. aborting( _aborting )
  4744. {}
  4745. virtual ~TestCaseStats();
  4746. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4747. TestCaseStats( TestCaseStats const& ) = default;
  4748. TestCaseStats( TestCaseStats && ) = default;
  4749. TestCaseStats& operator = ( TestCaseStats const& ) = default;
  4750. TestCaseStats& operator = ( TestCaseStats && ) = default;
  4751. # endif
  4752. TestCaseInfo testInfo;
  4753. Totals totals;
  4754. std::string stdOut;
  4755. std::string stdErr;
  4756. bool aborting;
  4757. };
  4758. struct TestGroupStats {
  4759. TestGroupStats( GroupInfo const& _groupInfo,
  4760. Totals const& _totals,
  4761. bool _aborting )
  4762. : groupInfo( _groupInfo ),
  4763. totals( _totals ),
  4764. aborting( _aborting )
  4765. {}
  4766. TestGroupStats( GroupInfo const& _groupInfo )
  4767. : groupInfo( _groupInfo ),
  4768. aborting( false )
  4769. {}
  4770. virtual ~TestGroupStats();
  4771. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4772. TestGroupStats( TestGroupStats const& ) = default;
  4773. TestGroupStats( TestGroupStats && ) = default;
  4774. TestGroupStats& operator = ( TestGroupStats const& ) = default;
  4775. TestGroupStats& operator = ( TestGroupStats && ) = default;
  4776. # endif
  4777. GroupInfo groupInfo;
  4778. Totals totals;
  4779. bool aborting;
  4780. };
  4781. struct TestRunStats {
  4782. TestRunStats( TestRunInfo const& _runInfo,
  4783. Totals const& _totals,
  4784. bool _aborting )
  4785. : runInfo( _runInfo ),
  4786. totals( _totals ),
  4787. aborting( _aborting )
  4788. {}
  4789. virtual ~TestRunStats();
  4790. # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4791. TestRunStats( TestRunStats const& _other )
  4792. : runInfo( _other.runInfo ),
  4793. totals( _other.totals ),
  4794. aborting( _other.aborting )
  4795. {}
  4796. # else
  4797. TestRunStats( TestRunStats const& ) = default;
  4798. TestRunStats( TestRunStats && ) = default;
  4799. TestRunStats& operator = ( TestRunStats const& ) = default;
  4800. TestRunStats& operator = ( TestRunStats && ) = default;
  4801. # endif
  4802. TestRunInfo runInfo;
  4803. Totals totals;
  4804. bool aborting;
  4805. };
  4806. class MultipleReporters;
  4807. struct IStreamingReporter : IShared {
  4808. virtual ~IStreamingReporter();
  4809. // Implementing class must also provide the following static method:
  4810. // static std::string getDescription();
  4811. virtual ReporterPreferences getPreferences() const = 0;
  4812. virtual void noMatchingTestCases( std::string const& spec ) = 0;
  4813. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  4814. virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
  4815. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  4816. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  4817. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  4818. // The return value indicates if the messages buffer should be cleared:
  4819. virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
  4820. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  4821. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  4822. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
  4823. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  4824. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  4825. virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
  4826. };
  4827. struct IReporterFactory : IShared {
  4828. virtual ~IReporterFactory();
  4829. virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
  4830. virtual std::string getDescription() const = 0;
  4831. };
  4832. struct IReporterRegistry {
  4833. typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
  4834. typedef std::vector<Ptr<IReporterFactory> > Listeners;
  4835. virtual ~IReporterRegistry();
  4836. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
  4837. virtual FactoryMap const& getFactories() const = 0;
  4838. virtual Listeners const& getListeners() const = 0;
  4839. };
  4840. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
  4841. }
  4842. #include <limits>
  4843. #include <algorithm>
  4844. namespace Catch {
  4845. inline std::size_t listTests( Config const& config ) {
  4846. TestSpec testSpec = config.testSpec();
  4847. if( config.testSpec().hasFilters() )
  4848. Catch::cout() << "Matching test cases:\n";
  4849. else {
  4850. Catch::cout() << "All available test cases:\n";
  4851. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4852. }
  4853. std::size_t matchedTests = 0;
  4854. TextAttributes nameAttr, descAttr, tagsAttr;
  4855. nameAttr.setInitialIndent( 2 ).setIndent( 4 );
  4856. descAttr.setIndent( 4 );
  4857. tagsAttr.setIndent( 6 );
  4858. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4859. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4860. it != itEnd;
  4861. ++it ) {
  4862. matchedTests++;
  4863. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4864. Colour::Code colour = testCaseInfo.isHidden()
  4865. ? Colour::SecondaryText
  4866. : Colour::None;
  4867. Colour colourGuard( colour );
  4868. Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
  4869. if( config.listExtraInfo() ) {
  4870. Catch::cout() << " " << testCaseInfo.lineInfo << std::endl;
  4871. std::string description = testCaseInfo.description;
  4872. if( description.empty() )
  4873. description = "(NO DESCRIPTION)";
  4874. Catch::cout() << Text( description, descAttr ) << std::endl;
  4875. }
  4876. if( !testCaseInfo.tags.empty() )
  4877. Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
  4878. }
  4879. if( !config.testSpec().hasFilters() )
  4880. Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
  4881. else
  4882. Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
  4883. return matchedTests;
  4884. }
  4885. inline std::size_t listTestsNamesOnly( Config const& config ) {
  4886. TestSpec testSpec = config.testSpec();
  4887. if( !config.testSpec().hasFilters() )
  4888. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4889. std::size_t matchedTests = 0;
  4890. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4891. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4892. it != itEnd;
  4893. ++it ) {
  4894. matchedTests++;
  4895. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4896. if( startsWith( testCaseInfo.name, '#' ) )
  4897. Catch::cout() << '"' << testCaseInfo.name << '"';
  4898. else
  4899. Catch::cout() << testCaseInfo.name;
  4900. if ( config.listExtraInfo() )
  4901. Catch::cout() << "\t@" << testCaseInfo.lineInfo;
  4902. Catch::cout() << std::endl;
  4903. }
  4904. return matchedTests;
  4905. }
  4906. struct TagInfo {
  4907. TagInfo() : count ( 0 ) {}
  4908. void add( std::string const& spelling ) {
  4909. ++count;
  4910. spellings.insert( spelling );
  4911. }
  4912. std::string all() const {
  4913. std::string out;
  4914. for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
  4915. it != itEnd;
  4916. ++it )
  4917. out += "[" + *it + "]";
  4918. return out;
  4919. }
  4920. std::set<std::string> spellings;
  4921. std::size_t count;
  4922. };
  4923. inline std::size_t listTags( Config const& config ) {
  4924. TestSpec testSpec = config.testSpec();
  4925. if( config.testSpec().hasFilters() )
  4926. Catch::cout() << "Tags for matching test cases:\n";
  4927. else {
  4928. Catch::cout() << "All available tags:\n";
  4929. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4930. }
  4931. std::map<std::string, TagInfo> tagCounts;
  4932. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4933. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4934. it != itEnd;
  4935. ++it ) {
  4936. for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
  4937. tagItEnd = it->getTestCaseInfo().tags.end();
  4938. tagIt != tagItEnd;
  4939. ++tagIt ) {
  4940. std::string tagName = *tagIt;
  4941. std::string lcaseTagName = toLower( tagName );
  4942. std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
  4943. if( countIt == tagCounts.end() )
  4944. countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
  4945. countIt->second.add( tagName );
  4946. }
  4947. }
  4948. for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
  4949. countItEnd = tagCounts.end();
  4950. countIt != countItEnd;
  4951. ++countIt ) {
  4952. std::ostringstream oss;
  4953. oss << " " << std::setw(2) << countIt->second.count << " ";
  4954. Text wrapper( countIt->second.all(), TextAttributes()
  4955. .setInitialIndent( 0 )
  4956. .setIndent( oss.str().size() )
  4957. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
  4958. Catch::cout() << oss.str() << wrapper << '\n';
  4959. }
  4960. Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
  4961. return tagCounts.size();
  4962. }
  4963. inline std::size_t listReporters( Config const& /*config*/ ) {
  4964. Catch::cout() << "Available reporters:\n";
  4965. IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
  4966. IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
  4967. std::size_t maxNameLen = 0;
  4968. for(it = itBegin; it != itEnd; ++it )
  4969. maxNameLen = (std::max)( maxNameLen, it->first.size() );
  4970. for(it = itBegin; it != itEnd; ++it ) {
  4971. Text wrapper( it->second->getDescription(), TextAttributes()
  4972. .setInitialIndent( 0 )
  4973. .setIndent( 7+maxNameLen )
  4974. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
  4975. Catch::cout() << " "
  4976. << it->first
  4977. << ':'
  4978. << std::string( maxNameLen - it->first.size() + 2, ' ' )
  4979. << wrapper << '\n';
  4980. }
  4981. Catch::cout() << std::endl;
  4982. return factories.size();
  4983. }
  4984. inline Option<std::size_t> list( Config const& config ) {
  4985. Option<std::size_t> listedCount;
  4986. if( config.listTests() || ( config.listExtraInfo() && !config.listTestNamesOnly() ) )
  4987. listedCount = listedCount.valueOr(0) + listTests( config );
  4988. if( config.listTestNamesOnly() )
  4989. listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
  4990. if( config.listTags() )
  4991. listedCount = listedCount.valueOr(0) + listTags( config );
  4992. if( config.listReporters() )
  4993. listedCount = listedCount.valueOr(0) + listReporters( config );
  4994. return listedCount;
  4995. }
  4996. } // end namespace Catch
  4997. // #included from: internal/catch_run_context.hpp
  4998. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  4999. // #included from: catch_test_case_tracker.hpp
  5000. #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  5001. #include <algorithm>
  5002. #include <string>
  5003. #include <assert.h>
  5004. #include <vector>
  5005. #include <stdexcept>
  5006. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  5007. namespace Catch {
  5008. namespace TestCaseTracking {
  5009. struct NameAndLocation {
  5010. std::string name;
  5011. SourceLineInfo location;
  5012. NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
  5013. : name( _name ),
  5014. location( _location )
  5015. {}
  5016. };
  5017. struct ITracker : SharedImpl<> {
  5018. virtual ~ITracker();
  5019. // static queries
  5020. virtual NameAndLocation const& nameAndLocation() const = 0;
  5021. // dynamic queries
  5022. virtual bool isComplete() const = 0; // Successfully completed or failed
  5023. virtual bool isSuccessfullyCompleted() const = 0;
  5024. virtual bool isOpen() const = 0; // Started but not complete
  5025. virtual bool hasChildren() const = 0;
  5026. virtual ITracker& parent() = 0;
  5027. // actions
  5028. virtual void close() = 0; // Successfully complete
  5029. virtual void fail() = 0;
  5030. virtual void markAsNeedingAnotherRun() = 0;
  5031. virtual void addChild( Ptr<ITracker> const& child ) = 0;
  5032. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0;
  5033. virtual void openChild() = 0;
  5034. // Debug/ checking
  5035. virtual bool isSectionTracker() const = 0;
  5036. virtual bool isIndexTracker() const = 0;
  5037. };
  5038. class TrackerContext {
  5039. enum RunState {
  5040. NotStarted,
  5041. Executing,
  5042. CompletedCycle
  5043. };
  5044. Ptr<ITracker> m_rootTracker;
  5045. ITracker* m_currentTracker;
  5046. RunState m_runState;
  5047. public:
  5048. static TrackerContext& instance() {
  5049. static TrackerContext s_instance;
  5050. return s_instance;
  5051. }
  5052. TrackerContext()
  5053. : m_currentTracker( CATCH_NULL ),
  5054. m_runState( NotStarted )
  5055. {}
  5056. ITracker& startRun();
  5057. void endRun() {
  5058. m_rootTracker.reset();
  5059. m_currentTracker = CATCH_NULL;
  5060. m_runState = NotStarted;
  5061. }
  5062. void startCycle() {
  5063. m_currentTracker = m_rootTracker.get();
  5064. m_runState = Executing;
  5065. }
  5066. void completeCycle() {
  5067. m_runState = CompletedCycle;
  5068. }
  5069. bool completedCycle() const {
  5070. return m_runState == CompletedCycle;
  5071. }
  5072. ITracker& currentTracker() {
  5073. return *m_currentTracker;
  5074. }
  5075. void setCurrentTracker( ITracker* tracker ) {
  5076. m_currentTracker = tracker;
  5077. }
  5078. };
  5079. class TrackerBase : public ITracker {
  5080. protected:
  5081. enum CycleState {
  5082. NotStarted,
  5083. Executing,
  5084. ExecutingChildren,
  5085. NeedsAnotherRun,
  5086. CompletedSuccessfully,
  5087. Failed
  5088. };
  5089. class TrackerHasName {
  5090. NameAndLocation m_nameAndLocation;
  5091. public:
  5092. TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {}
  5093. bool operator ()( Ptr<ITracker> const& tracker ) {
  5094. return
  5095. tracker->nameAndLocation().name == m_nameAndLocation.name &&
  5096. tracker->nameAndLocation().location == m_nameAndLocation.location;
  5097. }
  5098. };
  5099. typedef std::vector<Ptr<ITracker> > Children;
  5100. NameAndLocation m_nameAndLocation;
  5101. TrackerContext& m_ctx;
  5102. ITracker* m_parent;
  5103. Children m_children;
  5104. CycleState m_runState;
  5105. public:
  5106. TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5107. : m_nameAndLocation( nameAndLocation ),
  5108. m_ctx( ctx ),
  5109. m_parent( parent ),
  5110. m_runState( NotStarted )
  5111. {}
  5112. virtual ~TrackerBase();
  5113. virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE {
  5114. return m_nameAndLocation;
  5115. }
  5116. virtual bool isComplete() const CATCH_OVERRIDE {
  5117. return m_runState == CompletedSuccessfully || m_runState == Failed;
  5118. }
  5119. virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
  5120. return m_runState == CompletedSuccessfully;
  5121. }
  5122. virtual bool isOpen() const CATCH_OVERRIDE {
  5123. return m_runState != NotStarted && !isComplete();
  5124. }
  5125. virtual bool hasChildren() const CATCH_OVERRIDE {
  5126. return !m_children.empty();
  5127. }
  5128. virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
  5129. m_children.push_back( child );
  5130. }
  5131. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE {
  5132. Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
  5133. return( it != m_children.end() )
  5134. ? it->get()
  5135. : CATCH_NULL;
  5136. }
  5137. virtual ITracker& parent() CATCH_OVERRIDE {
  5138. assert( m_parent ); // Should always be non-null except for root
  5139. return *m_parent;
  5140. }
  5141. virtual void openChild() CATCH_OVERRIDE {
  5142. if( m_runState != ExecutingChildren ) {
  5143. m_runState = ExecutingChildren;
  5144. if( m_parent )
  5145. m_parent->openChild();
  5146. }
  5147. }
  5148. virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
  5149. virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
  5150. void open() {
  5151. m_runState = Executing;
  5152. moveToThis();
  5153. if( m_parent )
  5154. m_parent->openChild();
  5155. }
  5156. virtual void close() CATCH_OVERRIDE {
  5157. // Close any still open children (e.g. generators)
  5158. while( &m_ctx.currentTracker() != this )
  5159. m_ctx.currentTracker().close();
  5160. switch( m_runState ) {
  5161. case NotStarted:
  5162. case CompletedSuccessfully:
  5163. case Failed:
  5164. throw std::logic_error( "Illogical state" );
  5165. case NeedsAnotherRun:
  5166. break;;
  5167. case Executing:
  5168. m_runState = CompletedSuccessfully;
  5169. break;
  5170. case ExecutingChildren:
  5171. if( m_children.empty() || m_children.back()->isComplete() )
  5172. m_runState = CompletedSuccessfully;
  5173. break;
  5174. default:
  5175. throw std::logic_error( "Unexpected state" );
  5176. }
  5177. moveToParent();
  5178. m_ctx.completeCycle();
  5179. }
  5180. virtual void fail() CATCH_OVERRIDE {
  5181. m_runState = Failed;
  5182. if( m_parent )
  5183. m_parent->markAsNeedingAnotherRun();
  5184. moveToParent();
  5185. m_ctx.completeCycle();
  5186. }
  5187. virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
  5188. m_runState = NeedsAnotherRun;
  5189. }
  5190. private:
  5191. void moveToParent() {
  5192. assert( m_parent );
  5193. m_ctx.setCurrentTracker( m_parent );
  5194. }
  5195. void moveToThis() {
  5196. m_ctx.setCurrentTracker( this );
  5197. }
  5198. };
  5199. class SectionTracker : public TrackerBase {
  5200. std::vector<std::string> m_filters;
  5201. public:
  5202. SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5203. : TrackerBase( nameAndLocation, ctx, parent )
  5204. {
  5205. if( parent ) {
  5206. while( !parent->isSectionTracker() )
  5207. parent = &parent->parent();
  5208. SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
  5209. addNextFilters( parentSection.m_filters );
  5210. }
  5211. }
  5212. virtual ~SectionTracker();
  5213. virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
  5214. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
  5215. SectionTracker* section = CATCH_NULL;
  5216. ITracker& currentTracker = ctx.currentTracker();
  5217. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5218. assert( childTracker );
  5219. assert( childTracker->isSectionTracker() );
  5220. section = static_cast<SectionTracker*>( childTracker );
  5221. }
  5222. else {
  5223. section = new SectionTracker( nameAndLocation, ctx, &currentTracker );
  5224. currentTracker.addChild( section );
  5225. }
  5226. if( !ctx.completedCycle() )
  5227. section->tryOpen();
  5228. return *section;
  5229. }
  5230. void tryOpen() {
  5231. if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) )
  5232. open();
  5233. }
  5234. void addInitialFilters( std::vector<std::string> const& filters ) {
  5235. if( !filters.empty() ) {
  5236. m_filters.push_back(""); // Root - should never be consulted
  5237. m_filters.push_back(""); // Test Case - not a section filter
  5238. m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
  5239. }
  5240. }
  5241. void addNextFilters( std::vector<std::string> const& filters ) {
  5242. if( filters.size() > 1 )
  5243. m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() );
  5244. }
  5245. };
  5246. class IndexTracker : public TrackerBase {
  5247. int m_size;
  5248. int m_index;
  5249. public:
  5250. IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size )
  5251. : TrackerBase( nameAndLocation, ctx, parent ),
  5252. m_size( size ),
  5253. m_index( -1 )
  5254. {}
  5255. virtual ~IndexTracker();
  5256. virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
  5257. static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) {
  5258. IndexTracker* tracker = CATCH_NULL;
  5259. ITracker& currentTracker = ctx.currentTracker();
  5260. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5261. assert( childTracker );
  5262. assert( childTracker->isIndexTracker() );
  5263. tracker = static_cast<IndexTracker*>( childTracker );
  5264. }
  5265. else {
  5266. tracker = new IndexTracker( nameAndLocation, ctx, &currentTracker, size );
  5267. currentTracker.addChild( tracker );
  5268. }
  5269. if( !ctx.completedCycle() && !tracker->isComplete() ) {
  5270. if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
  5271. tracker->moveNext();
  5272. tracker->open();
  5273. }
  5274. return *tracker;
  5275. }
  5276. int index() const { return m_index; }
  5277. void moveNext() {
  5278. m_index++;
  5279. m_children.clear();
  5280. }
  5281. virtual void close() CATCH_OVERRIDE {
  5282. TrackerBase::close();
  5283. if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
  5284. m_runState = Executing;
  5285. }
  5286. };
  5287. inline ITracker& TrackerContext::startRun() {
  5288. m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL );
  5289. m_currentTracker = CATCH_NULL;
  5290. m_runState = Executing;
  5291. return *m_rootTracker;
  5292. }
  5293. } // namespace TestCaseTracking
  5294. using TestCaseTracking::ITracker;
  5295. using TestCaseTracking::TrackerContext;
  5296. using TestCaseTracking::SectionTracker;
  5297. using TestCaseTracking::IndexTracker;
  5298. } // namespace Catch
  5299. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  5300. // #included from: catch_fatal_condition.hpp
  5301. #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
  5302. #include <cassert>
  5303. #include <stdexcept>
  5304. namespace Catch {
  5305. //! Signals fatal error message to the run context
  5306. inline void reportFatal(std::string const &message) {
  5307. IContext &context = Catch::getCurrentContext();
  5308. IResultCapture *resultCapture = context.getResultCapture();
  5309. resultCapture->handleFatalErrorCondition(message);
  5310. }
  5311. } // namespace Catch
  5312. #if defined(CATCH_PLATFORM_WINDOWS) /////////////////////////////////////////
  5313. // #included from: catch_windows_h_proxy.h
  5314. #define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED
  5315. #ifdef CATCH_DEFINES_NOMINMAX
  5316. # define NOMINMAX
  5317. #endif
  5318. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5319. # define WIN32_LEAN_AND_MEAN
  5320. #endif
  5321. #ifdef __AFXDLL
  5322. #include <AfxWin.h>
  5323. #else
  5324. #include <windows.h>
  5325. #endif
  5326. #ifdef CATCH_DEFINES_NOMINMAX
  5327. # undef NOMINMAX
  5328. #endif
  5329. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5330. # undef WIN32_LEAN_AND_MEAN
  5331. #endif
  5332. #if !defined(CATCH_CONFIG_WINDOWS_SEH)
  5333. namespace Catch {
  5334. class FatalConditionHandler {
  5335. bool m_started;
  5336. // Install/disengage implementation for specific platform.
  5337. // Should be if-defed to work on current platform, can assume
  5338. // engage-disengage 1:1 pairing.
  5339. void engage_platform() {}
  5340. void disengage_platform() {}
  5341. public:
  5342. // Should also have platform-specific implementations as needed
  5343. FatalConditionHandler() : m_started(false) {}
  5344. ~FatalConditionHandler() {}
  5345. void engage() {
  5346. assert(!m_started && "Handler cannot be installed twice.");
  5347. m_started = true;
  5348. engage_platform();
  5349. }
  5350. void disengage() {
  5351. assert(m_started &&
  5352. "Handler cannot be uninstalled without being installed first");
  5353. m_started = false;
  5354. disengage_platform();
  5355. }
  5356. };
  5357. } // namespace Catch
  5358. #else // CATCH_CONFIG_WINDOWS_SEH is defined
  5359. namespace Catch {
  5360. struct SignalDefs {
  5361. DWORD id;
  5362. const char *name;
  5363. };
  5364. extern SignalDefs signalDefs[];
  5365. // There is no 1-1 mapping between signals and windows exceptions.
  5366. // Windows can easily distinguish between SO and SigSegV,
  5367. // but SigInt, SigTerm, etc are handled differently.
  5368. SignalDefs signalDefs[] = {
  5369. {EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal"},
  5370. {EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow"},
  5371. {EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal"},
  5372. {EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error"},
  5373. };
  5374. static LONG CALLBACK
  5375. handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
  5376. for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5377. if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
  5378. reportFatal(signalDefs[i].name);
  5379. }
  5380. }
  5381. // If its not an exception we care about, pass it along.
  5382. // This stops us from eating debugger breaks etc.
  5383. return EXCEPTION_CONTINUE_SEARCH;
  5384. }
  5385. // Since we do not support multiple instantiations, we put these
  5386. // into global variables and rely on cleaning them up in outlined
  5387. // constructors/destructors
  5388. static PVOID exceptionHandlerHandle = CATCH_NULL;
  5389. class FatalConditionHandler {
  5390. bool m_started;
  5391. // Install/disengage implementation for specific platform.
  5392. // Should be if-defed to work on current platform, can assume
  5393. // engage-disengage 1:1 pairing.
  5394. void engage_platform() {
  5395. // Register as first handler in current chain
  5396. exceptionHandlerHandle =
  5397. AddVectoredExceptionHandler(1, handleVectoredException);
  5398. if (!exceptionHandlerHandle) {
  5399. throw std::runtime_error("Could not register vectored exception handler");
  5400. }
  5401. }
  5402. void disengage_platform() {
  5403. if (!RemoveVectoredExceptionHandler(exceptionHandlerHandle)) {
  5404. throw std::runtime_error(
  5405. "Could not unregister vectored exception handler");
  5406. }
  5407. exceptionHandlerHandle = CATCH_NULL;
  5408. }
  5409. public:
  5410. FatalConditionHandler() : m_started(false) {
  5411. ULONG guaranteeSize = static_cast<ULONG>(32 * 1024);
  5412. if (!SetThreadStackGuarantee(&guaranteeSize)) {
  5413. // We do not want to fully error out, because needing
  5414. // the stack reserve should be rare enough anyway.
  5415. Catch::cerr() << "Failed to reserve piece of stack."
  5416. << " Stack overflows will not be reported successfully.";
  5417. }
  5418. }
  5419. // We do not attempt to unset the stack guarantee, because
  5420. // Windows does not support lowering the stack size guarantee.
  5421. ~FatalConditionHandler() {}
  5422. void engage() {
  5423. assert(!m_started && "Handler cannot be installed twice.");
  5424. m_started = true;
  5425. engage_platform();
  5426. }
  5427. void disengage() {
  5428. assert(m_started &&
  5429. "Handler cannot be uninstalled without being installed first");
  5430. m_started = false;
  5431. disengage_platform();
  5432. }
  5433. };
  5434. } // namespace Catch
  5435. #endif // CATCH_CONFIG_WINDOWS_SEH
  5436. #else // Not Windows - assumed to be POSIX compatible //////////////////////////
  5437. #if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  5438. namespace Catch {
  5439. class FatalConditionHandler {
  5440. bool m_started;
  5441. // Install/disengage implementation for specific platform.
  5442. // Should be if-defed to work on current platform, can assume
  5443. // engage-disengage 1:1 pairing.
  5444. void engage_platform() {}
  5445. void disengage_platform() {}
  5446. public:
  5447. // Should also have platform-specific implementations as needed
  5448. FatalConditionHandler() : m_started(false) {}
  5449. ~FatalConditionHandler() {}
  5450. void engage() {
  5451. assert(!m_started && "Handler cannot be installed twice.");
  5452. m_started = true;
  5453. engage_platform();
  5454. }
  5455. void disengage() {
  5456. assert(m_started &&
  5457. "Handler cannot be uninstalled without being installed first");
  5458. m_started = false;
  5459. disengage_platform();
  5460. }
  5461. };
  5462. } // namespace Catch
  5463. #else // CATCH_CONFIG_POSIX_SIGNALS is defined
  5464. #include <signal.h>
  5465. namespace Catch {
  5466. struct SignalDefs {
  5467. int id;
  5468. const char *name;
  5469. };
  5470. extern SignalDefs signalDefs[];
  5471. SignalDefs signalDefs[] = {
  5472. {SIGINT, "SIGINT - Terminal interrupt signal"},
  5473. {SIGILL, "SIGILL - Illegal instruction signal"},
  5474. {SIGFPE, "SIGFPE - Floating point error signal"},
  5475. {SIGSEGV, "SIGSEGV - Segmentation violation signal"},
  5476. {SIGTERM, "SIGTERM - Termination request signal"},
  5477. {SIGABRT, "SIGABRT - Abort (abnormal termination) signal"}};
  5478. // Older GCCs trigger -Wmissing-field-initializers for T foo = {}
  5479. // which is zero initialization, but not explicit. We want to avoid
  5480. // that.
  5481. #if defined(__GNUC__)
  5482. #pragma GCC diagnostic push
  5483. #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
  5484. #endif
  5485. static char *altStackMem = CATCH_NULL;
  5486. static std::size_t altStackSize = 0;
  5487. static stack_t oldSigStack;
  5488. static struct sigaction oldSigActions[sizeof(signalDefs) / sizeof(SignalDefs)];
  5489. static void restorePreviousSignalHandlers() {
  5490. // We set signal handlers back to the previous ones. Hopefully
  5491. // nobody overwrote them in the meantime, and doesn't expect
  5492. // their signal handlers to live past ours given that they
  5493. // installed them after ours..
  5494. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5495. sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL);
  5496. }
  5497. // Return the old stack
  5498. sigaltstack(&oldSigStack, CATCH_NULL);
  5499. }
  5500. static void handleSignal(int sig) {
  5501. char const *name = "<unknown signal>";
  5502. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5503. SignalDefs &def = signalDefs[i];
  5504. if (sig == def.id) {
  5505. name = def.name;
  5506. break;
  5507. }
  5508. }
  5509. // We need to restore previous signal handlers and let them do
  5510. // their thing, so that the users can have the debugger break
  5511. // when a signal is raised, and so on.
  5512. restorePreviousSignalHandlers();
  5513. reportFatal(name);
  5514. raise(sig);
  5515. }
  5516. class FatalConditionHandler {
  5517. bool m_started;
  5518. // Install/disengage implementation for specific platform.
  5519. // Should be if-defed to work on current platform, can assume
  5520. // engage-disengage 1:1 pairing.
  5521. void engage_platform() {
  5522. stack_t sigStack;
  5523. sigStack.ss_sp = altStackMem;
  5524. sigStack.ss_size = SIGSTKSZ;
  5525. sigStack.ss_flags = 0;
  5526. sigaltstack(&sigStack, &oldSigStack);
  5527. struct sigaction sa = {0};
  5528. sa.sa_handler = handleSignal;
  5529. sa.sa_flags = SA_ONSTACK;
  5530. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5531. sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
  5532. }
  5533. }
  5534. void disengage_platform() { restorePreviousSignalHandlers(); }
  5535. public:
  5536. FatalConditionHandler() : m_started(false) {
  5537. assert(!altStackMem &&
  5538. "Cannot initialize POSIX signal handler when one already exists");
  5539. if (altStackSize == 0) {
  5540. altStackSize = SIGSTKSZ;
  5541. }
  5542. altStackMem = new char[altStackSize]();
  5543. }
  5544. ~FatalConditionHandler() {
  5545. delete[] altStackMem;
  5546. // We signal that another instance can be constructed by zeroing
  5547. // out the pointer.
  5548. altStackMem = CATCH_NULL;
  5549. }
  5550. void engage() {
  5551. assert(!m_started && "Handler cannot be installed twice.");
  5552. m_started = true;
  5553. engage_platform();
  5554. }
  5555. void disengage() {
  5556. assert(m_started &&
  5557. "Handler cannot be uninstalled without being installed first");
  5558. m_started = false;
  5559. disengage_platform();
  5560. }
  5561. };
  5562. #if defined(__GNUC__)
  5563. #pragma GCC diagnostic pop
  5564. #endif
  5565. } // namespace Catch
  5566. #endif // CATCH_CONFIG_POSIX_SIGNALS
  5567. #endif // not Windows
  5568. namespace Catch {
  5569. //! Simple RAII guard for (dis)engaging the FatalConditionHandler
  5570. class FatalConditionHandlerGuard {
  5571. FatalConditionHandler *m_handler;
  5572. public:
  5573. FatalConditionHandlerGuard(FatalConditionHandler *handler)
  5574. : m_handler(handler) {
  5575. m_handler->engage();
  5576. }
  5577. ~FatalConditionHandlerGuard() { m_handler->disengage(); }
  5578. };
  5579. } // end namespace Catch
  5580. #include <cassert>
  5581. #include <set>
  5582. #include <string>
  5583. namespace Catch {
  5584. class StreamRedirect {
  5585. public:
  5586. StreamRedirect( std::ostream& stream, std::string& targetString )
  5587. : m_stream( stream ),
  5588. m_prevBuf( stream.rdbuf() ),
  5589. m_targetString( targetString )
  5590. {
  5591. stream.rdbuf( m_oss.rdbuf() );
  5592. }
  5593. ~StreamRedirect() {
  5594. m_targetString += m_oss.str();
  5595. m_stream.rdbuf( m_prevBuf );
  5596. }
  5597. private:
  5598. std::ostream& m_stream;
  5599. std::streambuf* m_prevBuf;
  5600. std::ostringstream m_oss;
  5601. std::string& m_targetString;
  5602. };
  5603. // StdErr has two constituent streams in C++, std::cerr and std::clog
  5604. // This means that we need to redirect 2 streams into 1 to keep proper
  5605. // order of writes and cannot use StreamRedirect on its own
  5606. class StdErrRedirect {
  5607. public:
  5608. StdErrRedirect(std::string& targetString)
  5609. :m_cerrBuf( cerr().rdbuf() ), m_clogBuf(clog().rdbuf()),
  5610. m_targetString(targetString){
  5611. cerr().rdbuf(m_oss.rdbuf());
  5612. clog().rdbuf(m_oss.rdbuf());
  5613. }
  5614. ~StdErrRedirect() {
  5615. m_targetString += m_oss.str();
  5616. cerr().rdbuf(m_cerrBuf);
  5617. clog().rdbuf(m_clogBuf);
  5618. }
  5619. private:
  5620. std::streambuf* m_cerrBuf;
  5621. std::streambuf* m_clogBuf;
  5622. std::ostringstream m_oss;
  5623. std::string& m_targetString;
  5624. };
  5625. ///////////////////////////////////////////////////////////////////////////
  5626. class RunContext : public IResultCapture, public IRunner {
  5627. RunContext( RunContext const& );
  5628. void operator =( RunContext const& );
  5629. public:
  5630. explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
  5631. : m_runInfo( _config->name() ),
  5632. m_context( getCurrentMutableContext() ),
  5633. m_activeTestCase( CATCH_NULL ),
  5634. m_config( _config ),
  5635. m_reporter( reporter ),
  5636. m_shouldReportUnexpected ( true )
  5637. {
  5638. m_context.setRunner( this );
  5639. m_context.setConfig( m_config );
  5640. m_context.setResultCapture( this );
  5641. m_reporter->testRunStarting( m_runInfo );
  5642. }
  5643. virtual ~RunContext() {
  5644. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
  5645. }
  5646. void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
  5647. m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
  5648. }
  5649. void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
  5650. m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
  5651. }
  5652. Totals runTest( TestCase const& testCase ) {
  5653. Totals prevTotals = m_totals;
  5654. std::string redirectedCout;
  5655. std::string redirectedCerr;
  5656. TestCaseInfo testInfo = testCase.getTestCaseInfo();
  5657. m_reporter->testCaseStarting( testInfo );
  5658. m_activeTestCase = &testCase;
  5659. do {
  5660. ITracker& rootTracker = m_trackerContext.startRun();
  5661. assert( rootTracker.isSectionTracker() );
  5662. static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() );
  5663. do {
  5664. m_trackerContext.startCycle();
  5665. m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) );
  5666. runCurrentTest( redirectedCout, redirectedCerr );
  5667. }
  5668. while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
  5669. }
  5670. // !TBD: deprecated - this will be replaced by indexed trackers
  5671. while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
  5672. Totals deltaTotals = m_totals.delta( prevTotals );
  5673. if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
  5674. deltaTotals.assertions.failed++;
  5675. deltaTotals.testCases.passed--;
  5676. deltaTotals.testCases.failed++;
  5677. }
  5678. m_totals.testCases += deltaTotals.testCases;
  5679. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5680. deltaTotals,
  5681. redirectedCout,
  5682. redirectedCerr,
  5683. aborting() ) );
  5684. m_activeTestCase = CATCH_NULL;
  5685. m_testCaseTracker = CATCH_NULL;
  5686. return deltaTotals;
  5687. }
  5688. Ptr<IConfig const> config() const {
  5689. return m_config;
  5690. }
  5691. private: // IResultCapture
  5692. virtual void assertionEnded( AssertionResult const& result ) {
  5693. if( result.getResultType() == ResultWas::Ok ) {
  5694. m_totals.assertions.passed++;
  5695. }
  5696. else if( !result.isOk() ) {
  5697. if( m_activeTestCase->getTestCaseInfo().okToFail() )
  5698. m_totals.assertions.failedButOk++;
  5699. else
  5700. m_totals.assertions.failed++;
  5701. }
  5702. // We have no use for the return value (whether messages should be cleared), because messages were made scoped
  5703. // and should be let to clear themselves out.
  5704. static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
  5705. // Reset working state
  5706. m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
  5707. m_lastResult = result;
  5708. }
  5709. virtual bool lastAssertionPassed()
  5710. {
  5711. return m_totals.assertions.passed == (m_prevPassed + 1);
  5712. }
  5713. virtual void assertionPassed()
  5714. {
  5715. m_totals.assertions.passed++;
  5716. m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}";
  5717. m_lastAssertionInfo.macroName = "";
  5718. }
  5719. virtual void assertionRun()
  5720. {
  5721. m_prevPassed = m_totals.assertions.passed;
  5722. }
  5723. virtual bool sectionStarted (
  5724. SectionInfo const& sectionInfo,
  5725. Counts& assertions
  5726. )
  5727. {
  5728. ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) );
  5729. if( !sectionTracker.isOpen() )
  5730. return false;
  5731. m_activeSections.push_back( &sectionTracker );
  5732. m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
  5733. m_reporter->sectionStarting( sectionInfo );
  5734. assertions = m_totals.assertions;
  5735. return true;
  5736. }
  5737. bool testForMissingAssertions( Counts& assertions ) {
  5738. if( assertions.total() != 0 )
  5739. return false;
  5740. if( !m_config->warnAboutMissingAssertions() )
  5741. return false;
  5742. if( m_trackerContext.currentTracker().hasChildren() )
  5743. return false;
  5744. m_totals.assertions.failed++;
  5745. assertions.failed++;
  5746. return true;
  5747. }
  5748. virtual void sectionEnded( SectionEndInfo const& endInfo ) {
  5749. Counts assertions = m_totals.assertions - endInfo.prevAssertions;
  5750. bool missingAssertions = testForMissingAssertions( assertions );
  5751. if( !m_activeSections.empty() ) {
  5752. m_activeSections.back()->close();
  5753. m_activeSections.pop_back();
  5754. }
  5755. m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
  5756. m_messages.clear();
  5757. }
  5758. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
  5759. if( m_unfinishedSections.empty() )
  5760. m_activeSections.back()->fail();
  5761. else
  5762. m_activeSections.back()->close();
  5763. m_activeSections.pop_back();
  5764. m_unfinishedSections.push_back( endInfo );
  5765. }
  5766. virtual void pushScopedMessage( MessageInfo const& message ) {
  5767. m_messages.push_back( message );
  5768. }
  5769. virtual void popScopedMessage( MessageInfo const& message ) {
  5770. m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
  5771. }
  5772. virtual std::string getCurrentTestName() const {
  5773. return m_activeTestCase
  5774. ? m_activeTestCase->getTestCaseInfo().name
  5775. : std::string();
  5776. }
  5777. virtual const AssertionResult* getLastResult() const {
  5778. return &m_lastResult;
  5779. }
  5780. virtual void exceptionEarlyReported() {
  5781. m_shouldReportUnexpected = false;
  5782. }
  5783. virtual void handleFatalErrorCondition( std::string const& message ) {
  5784. // Don't rebuild the result -- the stringification itself can cause more fatal errors
  5785. // Instead, fake a result data.
  5786. AssertionResultData tempResult;
  5787. tempResult.resultType = ResultWas::FatalErrorCondition;
  5788. tempResult.message = message;
  5789. AssertionResult result(m_lastAssertionInfo, tempResult);
  5790. getResultCapture().assertionEnded(result);
  5791. handleUnfinishedSections();
  5792. // Recreate section for test case (as we will lose the one that was in scope)
  5793. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5794. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5795. Counts assertions;
  5796. assertions.failed = 1;
  5797. SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
  5798. m_reporter->sectionEnded( testCaseSectionStats );
  5799. TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
  5800. Totals deltaTotals;
  5801. deltaTotals.testCases.failed = 1;
  5802. deltaTotals.assertions.failed = 1;
  5803. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5804. deltaTotals,
  5805. std::string(),
  5806. std::string(),
  5807. false ) );
  5808. m_totals.testCases.failed++;
  5809. testGroupEnded( std::string(), m_totals, 1, 1 );
  5810. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
  5811. }
  5812. public:
  5813. // !TBD We need to do this another way!
  5814. bool aborting() const {
  5815. return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
  5816. }
  5817. private:
  5818. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
  5819. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5820. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5821. m_reporter->sectionStarting( testCaseSection );
  5822. Counts prevAssertions = m_totals.assertions;
  5823. double duration = 0;
  5824. m_shouldReportUnexpected = true;
  5825. try {
  5826. m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
  5827. seedRng( *m_config );
  5828. Timer timer;
  5829. timer.start();
  5830. if( m_reporter->getPreferences().shouldRedirectStdOut ) {
  5831. StreamRedirect coutRedir( Catch::cout(), redirectedCout );
  5832. StdErrRedirect errRedir( redirectedCerr );
  5833. invokeActiveTestCase();
  5834. }
  5835. else {
  5836. invokeActiveTestCase();
  5837. }
  5838. duration = timer.getElapsedSeconds();
  5839. }
  5840. catch( TestFailureException& ) {
  5841. // This just means the test was aborted due to failure
  5842. }
  5843. catch(...) {
  5844. // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
  5845. // are reported without translation at the point of origin.
  5846. if (m_shouldReportUnexpected) {
  5847. makeUnexpectedResultBuilder().useActiveException();
  5848. }
  5849. }
  5850. m_testCaseTracker->close();
  5851. handleUnfinishedSections();
  5852. m_messages.clear();
  5853. Counts assertions = m_totals.assertions - prevAssertions;
  5854. bool missingAssertions = testForMissingAssertions( assertions );
  5855. SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
  5856. m_reporter->sectionEnded( testCaseSectionStats );
  5857. }
  5858. void invokeActiveTestCase() {
  5859. FatalConditionHandlerGuard _(&m_fatalConditionhandler);
  5860. m_activeTestCase->invoke();
  5861. }
  5862. private:
  5863. ResultBuilder makeUnexpectedResultBuilder() const {
  5864. return ResultBuilder( m_lastAssertionInfo.macroName,
  5865. m_lastAssertionInfo.lineInfo,
  5866. m_lastAssertionInfo.capturedExpression,
  5867. m_lastAssertionInfo.resultDisposition );
  5868. }
  5869. void handleUnfinishedSections() {
  5870. // If sections ended prematurely due to an exception we stored their
  5871. // infos here so we can tear them down outside the unwind process.
  5872. for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
  5873. itEnd = m_unfinishedSections.rend();
  5874. it != itEnd;
  5875. ++it )
  5876. sectionEnded( *it );
  5877. m_unfinishedSections.clear();
  5878. }
  5879. TestRunInfo m_runInfo;
  5880. IMutableContext& m_context;
  5881. TestCase const* m_activeTestCase;
  5882. ITracker* m_testCaseTracker;
  5883. ITracker* m_currentSectionTracker;
  5884. AssertionResult m_lastResult;
  5885. Ptr<IConfig const> m_config;
  5886. Totals m_totals;
  5887. Ptr<IStreamingReporter> m_reporter;
  5888. std::vector<MessageInfo> m_messages;
  5889. AssertionInfo m_lastAssertionInfo;
  5890. std::vector<SectionEndInfo> m_unfinishedSections;
  5891. std::vector<ITracker*> m_activeSections;
  5892. TrackerContext m_trackerContext;
  5893. FatalConditionHandler m_fatalConditionhandler;
  5894. size_t m_prevPassed;
  5895. bool m_shouldReportUnexpected;
  5896. };
  5897. IResultCapture& getResultCapture() {
  5898. if( IResultCapture* capture = getCurrentContext().getResultCapture() )
  5899. return *capture;
  5900. else
  5901. throw std::logic_error( "No result capture instance" );
  5902. }
  5903. } // end namespace Catch
  5904. // #included from: internal/catch_version.h
  5905. #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
  5906. namespace Catch {
  5907. // Versioning information
  5908. struct Version {
  5909. Version( unsigned int _majorVersion,
  5910. unsigned int _minorVersion,
  5911. unsigned int _patchNumber,
  5912. char const * const _branchName,
  5913. unsigned int _buildNumber );
  5914. unsigned int const majorVersion;
  5915. unsigned int const minorVersion;
  5916. unsigned int const patchNumber;
  5917. // buildNumber is only used if branchName is not null
  5918. char const * const branchName;
  5919. unsigned int const buildNumber;
  5920. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5921. private:
  5922. void operator=( Version const& );
  5923. };
  5924. inline Version libraryVersion();
  5925. }
  5926. #include <fstream>
  5927. #include <stdlib.h>
  5928. #include <limits>
  5929. namespace Catch {
  5930. Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
  5931. Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
  5932. if( !reporter ) {
  5933. std::ostringstream oss;
  5934. oss << "No reporter registered with name: '" << reporterName << "'";
  5935. throw std::domain_error( oss.str() );
  5936. }
  5937. return reporter;
  5938. }
  5939. #if !defined(CATCH_CONFIG_DEFAULT_REPORTER)
  5940. #define CATCH_CONFIG_DEFAULT_REPORTER "console"
  5941. #endif
  5942. Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
  5943. std::vector<std::string> reporters = config->getReporterNames();
  5944. if( reporters.empty() )
  5945. reporters.push_back( CATCH_CONFIG_DEFAULT_REPORTER );
  5946. Ptr<IStreamingReporter> reporter;
  5947. for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
  5948. it != itEnd;
  5949. ++it )
  5950. reporter = addReporter( reporter, createReporter( *it, config ) );
  5951. return reporter;
  5952. }
  5953. Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
  5954. IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
  5955. for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
  5956. it != itEnd;
  5957. ++it )
  5958. reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
  5959. return reporters;
  5960. }
  5961. Totals runTests( Ptr<Config> const& config ) {
  5962. Ptr<IConfig const> iconfig = config.get();
  5963. Ptr<IStreamingReporter> reporter = makeReporter( config );
  5964. reporter = addListeners( iconfig, reporter );
  5965. RunContext context( iconfig, reporter );
  5966. Totals totals;
  5967. context.testGroupStarting( config->name(), 1, 1 );
  5968. TestSpec testSpec = config->testSpec();
  5969. if( !testSpec.hasFilters() )
  5970. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
  5971. std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
  5972. for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
  5973. it != itEnd;
  5974. ++it ) {
  5975. if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
  5976. totals += context.runTest( *it );
  5977. else
  5978. reporter->skipTest( *it );
  5979. }
  5980. context.testGroupEnded( iconfig->name(), totals, 1, 1 );
  5981. return totals;
  5982. }
  5983. void applyFilenamesAsTags( IConfig const& config ) {
  5984. std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
  5985. for(std::size_t i = 0; i < tests.size(); ++i ) {
  5986. TestCase& test = const_cast<TestCase&>( tests[i] );
  5987. std::set<std::string> tags = test.tags;
  5988. std::string filename = test.lineInfo.file;
  5989. std::string::size_type lastSlash = filename.find_last_of( "\\/" );
  5990. if( lastSlash != std::string::npos )
  5991. filename = filename.substr( lastSlash+1 );
  5992. std::string::size_type lastDot = filename.find_last_of( '.' );
  5993. if( lastDot != std::string::npos )
  5994. filename = filename.substr( 0, lastDot );
  5995. tags.insert( '#' + filename );
  5996. setTags( test, tags );
  5997. }
  5998. }
  5999. class Session : NonCopyable {
  6000. static bool alreadyInstantiated;
  6001. public:
  6002. struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
  6003. Session()
  6004. : m_cli( makeCommandLineParser() ) {
  6005. if( alreadyInstantiated ) {
  6006. std::string msg = "Only one instance of Catch::Session can ever be used";
  6007. Catch::cerr() << msg << std::endl;
  6008. throw std::logic_error( msg );
  6009. }
  6010. alreadyInstantiated = true;
  6011. }
  6012. ~Session() {
  6013. Catch::cleanUp();
  6014. }
  6015. void showHelp( std::string const& processName ) {
  6016. Catch::cout() << "\nCatch v" << libraryVersion() << "\n";
  6017. m_cli.usage( Catch::cout(), processName );
  6018. Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
  6019. }
  6020. void libIdentify() {
  6021. Catch::cout()
  6022. << std::left << std::setw(16) << "description: " << "A Catch test executable\n"
  6023. << std::left << std::setw(16) << "category: " << "testframework\n"
  6024. << std::left << std::setw(16) << "framework: " << "Catch Test\n"
  6025. << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
  6026. }
  6027. int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
  6028. try {
  6029. m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
  6030. m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
  6031. if( m_configData.showHelp )
  6032. showHelp( m_configData.processName );
  6033. if( m_configData.libIdentify )
  6034. libIdentify();
  6035. m_config.reset();
  6036. }
  6037. catch( std::exception& ex ) {
  6038. {
  6039. Colour colourGuard( Colour::Red );
  6040. Catch::cerr()
  6041. << "\nError(s) in input:\n"
  6042. << Text( ex.what(), TextAttributes().setIndent(2) )
  6043. << "\n\n";
  6044. }
  6045. m_cli.usage( Catch::cout(), m_configData.processName );
  6046. return (std::numeric_limits<int>::max)();
  6047. }
  6048. return 0;
  6049. }
  6050. void useConfigData( ConfigData const& _configData ) {
  6051. m_configData = _configData;
  6052. m_config.reset();
  6053. }
  6054. int run( int argc, char const* const* const argv ) {
  6055. int returnCode = applyCommandLine( argc, argv );
  6056. if( returnCode == 0 )
  6057. returnCode = run();
  6058. return returnCode;
  6059. }
  6060. #if defined(WIN32) && defined(UNICODE)
  6061. int run( int argc, wchar_t const* const* const argv ) {
  6062. char **utf8Argv = new char *[ argc ];
  6063. for ( int i = 0; i < argc; ++i ) {
  6064. int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL );
  6065. utf8Argv[ i ] = new char[ bufSize ];
  6066. WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
  6067. }
  6068. int returnCode = applyCommandLine( argc, utf8Argv );
  6069. if( returnCode == 0 )
  6070. returnCode = run();
  6071. for ( int i = 0; i < argc; ++i )
  6072. delete [] utf8Argv[ i ];
  6073. delete [] utf8Argv;
  6074. return returnCode;
  6075. }
  6076. #endif
  6077. int run() {
  6078. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
  6079. Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
  6080. static_cast<void>(std::getchar());
  6081. }
  6082. int exitCode = runInternal();
  6083. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
  6084. Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
  6085. static_cast<void>(std::getchar());
  6086. }
  6087. return exitCode;
  6088. }
  6089. Clara::CommandLine<ConfigData> const& cli() const {
  6090. return m_cli;
  6091. }
  6092. std::vector<Clara::Parser::Token> const& unusedTokens() const {
  6093. return m_unusedTokens;
  6094. }
  6095. ConfigData& configData() {
  6096. return m_configData;
  6097. }
  6098. Config& config() {
  6099. if( !m_config )
  6100. m_config = new Config( m_configData );
  6101. return *m_config;
  6102. }
  6103. private:
  6104. int runInternal() {
  6105. if( m_configData.showHelp || m_configData.libIdentify )
  6106. return 0;
  6107. try
  6108. {
  6109. config(); // Force config to be constructed
  6110. seedRng( *m_config );
  6111. if( m_configData.filenamesAsTags )
  6112. applyFilenamesAsTags( *m_config );
  6113. // Handle list request
  6114. if( Option<std::size_t> listed = list( config() ) )
  6115. return static_cast<int>( *listed );
  6116. return static_cast<int>( runTests( m_config ).assertions.failed );
  6117. }
  6118. catch( std::exception& ex ) {
  6119. Catch::cerr() << ex.what() << std::endl;
  6120. return (std::numeric_limits<int>::max)();
  6121. }
  6122. }
  6123. Clara::CommandLine<ConfigData> m_cli;
  6124. std::vector<Clara::Parser::Token> m_unusedTokens;
  6125. ConfigData m_configData;
  6126. Ptr<Config> m_config;
  6127. };
  6128. bool Session::alreadyInstantiated = false;
  6129. } // end namespace Catch
  6130. // #included from: catch_registry_hub.hpp
  6131. #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
  6132. // #included from: catch_test_case_registry_impl.hpp
  6133. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  6134. #include <vector>
  6135. #include <set>
  6136. #include <sstream>
  6137. #include <algorithm>
  6138. namespace Catch {
  6139. struct RandomNumberGenerator {
  6140. typedef unsigned int result_type;
  6141. result_type operator()( result_type n ) const { return std::rand() % n; }
  6142. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6143. static constexpr result_type (min)() { return 0; }
  6144. static constexpr result_type (max)() { return 1000000; }
  6145. result_type operator()() const { return std::rand() % (max)(); }
  6146. #endif
  6147. template<typename V>
  6148. static void shuffle( V& vector ) {
  6149. RandomNumberGenerator rng;
  6150. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6151. std::shuffle( vector.begin(), vector.end(), rng );
  6152. #else
  6153. std::random_shuffle( vector.begin(), vector.end(), rng );
  6154. #endif
  6155. }
  6156. };
  6157. inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
  6158. std::vector<TestCase> sorted = unsortedTestCases;
  6159. switch( config.runOrder() ) {
  6160. case RunTests::InLexicographicalOrder:
  6161. std::sort( sorted.begin(), sorted.end() );
  6162. break;
  6163. case RunTests::InRandomOrder:
  6164. {
  6165. seedRng( config );
  6166. RandomNumberGenerator::shuffle( sorted );
  6167. }
  6168. break;
  6169. case RunTests::InDeclarationOrder:
  6170. // already in declaration order
  6171. break;
  6172. }
  6173. return sorted;
  6174. }
  6175. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
  6176. return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
  6177. }
  6178. void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
  6179. std::set<TestCase> seenFunctions;
  6180. for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
  6181. it != itEnd;
  6182. ++it ) {
  6183. std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
  6184. if( !prev.second ) {
  6185. std::ostringstream ss;
  6186. ss << Colour( Colour::Red )
  6187. << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
  6188. << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n'
  6189. << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
  6190. throw std::runtime_error(ss.str());
  6191. }
  6192. }
  6193. }
  6194. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
  6195. std::vector<TestCase> filtered;
  6196. filtered.reserve( testCases.size() );
  6197. for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
  6198. it != itEnd;
  6199. ++it )
  6200. if( matchTest( *it, testSpec, config ) )
  6201. filtered.push_back( *it );
  6202. return filtered;
  6203. }
  6204. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
  6205. return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
  6206. }
  6207. class TestRegistry : public ITestCaseRegistry {
  6208. public:
  6209. TestRegistry()
  6210. : m_currentSortOrder( RunTests::InDeclarationOrder ),
  6211. m_unnamedCount( 0 )
  6212. {}
  6213. virtual ~TestRegistry();
  6214. virtual void registerTest( TestCase const& testCase ) {
  6215. std::string name = testCase.getTestCaseInfo().name;
  6216. if( name.empty() ) {
  6217. std::ostringstream oss;
  6218. oss << "Anonymous test case " << ++m_unnamedCount;
  6219. return registerTest( testCase.withName( oss.str() ) );
  6220. }
  6221. m_functions.push_back( testCase );
  6222. }
  6223. virtual std::vector<TestCase> const& getAllTests() const {
  6224. return m_functions;
  6225. }
  6226. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
  6227. if( m_sortedFunctions.empty() )
  6228. enforceNoDuplicateTestCases( m_functions );
  6229. if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
  6230. m_sortedFunctions = sortTests( config, m_functions );
  6231. m_currentSortOrder = config.runOrder();
  6232. }
  6233. return m_sortedFunctions;
  6234. }
  6235. private:
  6236. std::vector<TestCase> m_functions;
  6237. mutable RunTests::InWhatOrder m_currentSortOrder;
  6238. mutable std::vector<TestCase> m_sortedFunctions;
  6239. size_t m_unnamedCount;
  6240. std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
  6241. };
  6242. ///////////////////////////////////////////////////////////////////////////
  6243. class FreeFunctionTestCase : public SharedImpl<ITestCase> {
  6244. public:
  6245. FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
  6246. virtual void invoke() const {
  6247. m_fun();
  6248. }
  6249. private:
  6250. virtual ~FreeFunctionTestCase();
  6251. TestFunction m_fun;
  6252. };
  6253. inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
  6254. std::string className = classOrQualifiedMethodName;
  6255. if( startsWith( className, '&' ) )
  6256. {
  6257. std::size_t lastColons = className.rfind( "::" );
  6258. std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
  6259. if( penultimateColons == std::string::npos )
  6260. penultimateColons = 1;
  6261. className = className.substr( penultimateColons, lastColons-penultimateColons );
  6262. }
  6263. return className;
  6264. }
  6265. void registerTestCase
  6266. ( ITestCase* testCase,
  6267. char const* classOrQualifiedMethodName,
  6268. NameAndDesc const& nameAndDesc,
  6269. SourceLineInfo const& lineInfo ) {
  6270. getMutableRegistryHub().registerTest
  6271. ( makeTestCase
  6272. ( testCase,
  6273. extractClassName( classOrQualifiedMethodName ),
  6274. nameAndDesc.name,
  6275. nameAndDesc.description,
  6276. lineInfo ) );
  6277. }
  6278. void registerTestCaseFunction
  6279. ( TestFunction function,
  6280. SourceLineInfo const& lineInfo,
  6281. NameAndDesc const& nameAndDesc ) {
  6282. registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
  6283. }
  6284. ///////////////////////////////////////////////////////////////////////////
  6285. AutoReg::AutoReg
  6286. ( TestFunction function,
  6287. SourceLineInfo const& lineInfo,
  6288. NameAndDesc const& nameAndDesc ) {
  6289. registerTestCaseFunction( function, lineInfo, nameAndDesc );
  6290. }
  6291. AutoReg::~AutoReg() {}
  6292. } // end namespace Catch
  6293. // #included from: catch_reporter_registry.hpp
  6294. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6295. #include <map>
  6296. namespace Catch {
  6297. class ReporterRegistry : public IReporterRegistry {
  6298. public:
  6299. virtual ~ReporterRegistry() CATCH_OVERRIDE {}
  6300. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
  6301. FactoryMap::const_iterator it = m_factories.find( name );
  6302. if( it == m_factories.end() )
  6303. return CATCH_NULL;
  6304. return it->second->create( ReporterConfig( config ) );
  6305. }
  6306. void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
  6307. m_factories.insert( std::make_pair( name, factory ) );
  6308. }
  6309. void registerListener( Ptr<IReporterFactory> const& factory ) {
  6310. m_listeners.push_back( factory );
  6311. }
  6312. virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
  6313. return m_factories;
  6314. }
  6315. virtual Listeners const& getListeners() const CATCH_OVERRIDE {
  6316. return m_listeners;
  6317. }
  6318. private:
  6319. FactoryMap m_factories;
  6320. Listeners m_listeners;
  6321. };
  6322. }
  6323. // #included from: catch_exception_translator_registry.hpp
  6324. #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6325. #ifdef __OBJC__
  6326. #import "Foundation/Foundation.h"
  6327. #endif
  6328. namespace Catch {
  6329. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  6330. public:
  6331. ~ExceptionTranslatorRegistry() {
  6332. deleteAll( m_translators );
  6333. }
  6334. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  6335. m_translators.push_back( translator );
  6336. }
  6337. virtual std::string translateActiveException() const {
  6338. try {
  6339. #ifdef __OBJC__
  6340. // In Objective-C try objective-c exceptions first
  6341. @try {
  6342. return tryTranslators();
  6343. }
  6344. @catch (NSException *exception) {
  6345. return Catch::toString( [exception description] );
  6346. }
  6347. #else
  6348. return tryTranslators();
  6349. #endif
  6350. }
  6351. catch( TestFailureException& ) {
  6352. throw;
  6353. }
  6354. catch( std::exception& ex ) {
  6355. return ex.what();
  6356. }
  6357. catch( std::string& msg ) {
  6358. return msg;
  6359. }
  6360. catch( const char* msg ) {
  6361. return msg;
  6362. }
  6363. catch(...) {
  6364. return "Unknown exception";
  6365. }
  6366. }
  6367. std::string tryTranslators() const {
  6368. if( m_translators.empty() )
  6369. throw;
  6370. else
  6371. return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
  6372. }
  6373. private:
  6374. std::vector<const IExceptionTranslator*> m_translators;
  6375. };
  6376. }
  6377. // #included from: catch_tag_alias_registry.h
  6378. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
  6379. #include <map>
  6380. namespace Catch {
  6381. class TagAliasRegistry : public ITagAliasRegistry {
  6382. public:
  6383. virtual ~TagAliasRegistry();
  6384. virtual Option<TagAlias> find( std::string const& alias ) const;
  6385. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
  6386. void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
  6387. private:
  6388. std::map<std::string, TagAlias> m_registry;
  6389. };
  6390. } // end namespace Catch
  6391. namespace Catch {
  6392. namespace {
  6393. class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
  6394. RegistryHub( RegistryHub const& );
  6395. void operator=( RegistryHub const& );
  6396. public: // IRegistryHub
  6397. RegistryHub() {
  6398. }
  6399. virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
  6400. return m_reporterRegistry;
  6401. }
  6402. virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
  6403. return m_testCaseRegistry;
  6404. }
  6405. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
  6406. return m_exceptionTranslatorRegistry;
  6407. }
  6408. virtual ITagAliasRegistry const& getTagAliasRegistry() const CATCH_OVERRIDE {
  6409. return m_tagAliasRegistry;
  6410. }
  6411. public: // IMutableRegistryHub
  6412. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6413. m_reporterRegistry.registerReporter( name, factory );
  6414. }
  6415. virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6416. m_reporterRegistry.registerListener( factory );
  6417. }
  6418. virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
  6419. m_testCaseRegistry.registerTest( testInfo );
  6420. }
  6421. virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
  6422. m_exceptionTranslatorRegistry.registerTranslator( translator );
  6423. }
  6424. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) CATCH_OVERRIDE {
  6425. m_tagAliasRegistry.add( alias, tag, lineInfo );
  6426. }
  6427. private:
  6428. TestRegistry m_testCaseRegistry;
  6429. ReporterRegistry m_reporterRegistry;
  6430. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  6431. TagAliasRegistry m_tagAliasRegistry;
  6432. };
  6433. // Single, global, instance
  6434. inline RegistryHub*& getTheRegistryHub() {
  6435. static RegistryHub* theRegistryHub = CATCH_NULL;
  6436. if( !theRegistryHub )
  6437. theRegistryHub = new RegistryHub();
  6438. return theRegistryHub;
  6439. }
  6440. }
  6441. IRegistryHub& getRegistryHub() {
  6442. return *getTheRegistryHub();
  6443. }
  6444. IMutableRegistryHub& getMutableRegistryHub() {
  6445. return *getTheRegistryHub();
  6446. }
  6447. void cleanUp() {
  6448. delete getTheRegistryHub();
  6449. getTheRegistryHub() = CATCH_NULL;
  6450. cleanUpContext();
  6451. }
  6452. std::string translateActiveException() {
  6453. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  6454. }
  6455. } // end namespace Catch
  6456. // #included from: catch_notimplemented_exception.hpp
  6457. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
  6458. #include <sstream>
  6459. namespace Catch {
  6460. NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
  6461. : m_lineInfo( lineInfo ) {
  6462. std::ostringstream oss;
  6463. oss << lineInfo << ": function ";
  6464. oss << "not implemented";
  6465. m_what = oss.str();
  6466. }
  6467. const char* NotImplementedException::what() const CATCH_NOEXCEPT {
  6468. return m_what.c_str();
  6469. }
  6470. } // end namespace Catch
  6471. // #included from: catch_context_impl.hpp
  6472. #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
  6473. // #included from: catch_stream.hpp
  6474. #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
  6475. #include <stdexcept>
  6476. #include <cstdio>
  6477. #include <iostream>
  6478. namespace Catch {
  6479. template<typename WriterF, size_t bufferSize=256>
  6480. class StreamBufImpl : public StreamBufBase {
  6481. char data[bufferSize];
  6482. WriterF m_writer;
  6483. public:
  6484. StreamBufImpl() {
  6485. setp( data, data + sizeof(data) );
  6486. }
  6487. ~StreamBufImpl() CATCH_NOEXCEPT {
  6488. sync();
  6489. }
  6490. private:
  6491. int overflow( int c ) {
  6492. sync();
  6493. if( c != EOF ) {
  6494. if( pbase() == epptr() )
  6495. m_writer( std::string( 1, static_cast<char>( c ) ) );
  6496. else
  6497. sputc( static_cast<char>( c ) );
  6498. }
  6499. return 0;
  6500. }
  6501. int sync() {
  6502. if( pbase() != pptr() ) {
  6503. m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
  6504. setp( pbase(), epptr() );
  6505. }
  6506. return 0;
  6507. }
  6508. };
  6509. ///////////////////////////////////////////////////////////////////////////
  6510. FileStream::FileStream( std::string const& filename ) {
  6511. m_ofs.open( filename.c_str() );
  6512. if( m_ofs.fail() ) {
  6513. std::ostringstream oss;
  6514. oss << "Unable to open file: '" << filename << '\'';
  6515. throw std::domain_error( oss.str() );
  6516. }
  6517. }
  6518. std::ostream& FileStream::stream() const {
  6519. return m_ofs;
  6520. }
  6521. struct OutputDebugWriter {
  6522. void operator()( std::string const&str ) {
  6523. writeToDebugConsole( str );
  6524. }
  6525. };
  6526. DebugOutStream::DebugOutStream()
  6527. : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
  6528. m_os( m_streamBuf.get() )
  6529. {}
  6530. std::ostream& DebugOutStream::stream() const {
  6531. return m_os;
  6532. }
  6533. // Store the streambuf from cout up-front because
  6534. // cout may get redirected when running tests
  6535. CoutStream::CoutStream()
  6536. : m_os( Catch::cout().rdbuf() )
  6537. {}
  6538. std::ostream& CoutStream::stream() const {
  6539. return m_os;
  6540. }
  6541. #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
  6542. std::ostream& cout() {
  6543. return std::cout;
  6544. }
  6545. std::ostream& cerr() {
  6546. return std::cerr;
  6547. }
  6548. std::ostream& clog() {
  6549. return std::clog;
  6550. }
  6551. #endif
  6552. }
  6553. namespace Catch {
  6554. class Context : public IMutableContext {
  6555. Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
  6556. Context( Context const& );
  6557. void operator=( Context const& );
  6558. public:
  6559. virtual ~Context() {
  6560. deleteAllValues( m_generatorsByTestName );
  6561. }
  6562. public: // IContext
  6563. virtual IResultCapture* getResultCapture() {
  6564. return m_resultCapture;
  6565. }
  6566. virtual IRunner* getRunner() {
  6567. return m_runner;
  6568. }
  6569. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
  6570. return getGeneratorsForCurrentTest()
  6571. .getGeneratorInfo( fileInfo, totalSize )
  6572. .getCurrentIndex();
  6573. }
  6574. virtual bool advanceGeneratorsForCurrentTest() {
  6575. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6576. return generators && generators->moveNext();
  6577. }
  6578. virtual Ptr<IConfig const> getConfig() const {
  6579. return m_config;
  6580. }
  6581. public: // IMutableContext
  6582. virtual void setResultCapture( IResultCapture* resultCapture ) {
  6583. m_resultCapture = resultCapture;
  6584. }
  6585. virtual void setRunner( IRunner* runner ) {
  6586. m_runner = runner;
  6587. }
  6588. virtual void setConfig( Ptr<IConfig const> const& config ) {
  6589. m_config = config;
  6590. }
  6591. friend IMutableContext& getCurrentMutableContext();
  6592. private:
  6593. IGeneratorsForTest* findGeneratorsForCurrentTest() {
  6594. std::string testName = getResultCapture()->getCurrentTestName();
  6595. std::map<std::string, IGeneratorsForTest*>::const_iterator it =
  6596. m_generatorsByTestName.find( testName );
  6597. return it != m_generatorsByTestName.end()
  6598. ? it->second
  6599. : CATCH_NULL;
  6600. }
  6601. IGeneratorsForTest& getGeneratorsForCurrentTest() {
  6602. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6603. if( !generators ) {
  6604. std::string testName = getResultCapture()->getCurrentTestName();
  6605. generators = createGeneratorsForTest();
  6606. m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
  6607. }
  6608. return *generators;
  6609. }
  6610. private:
  6611. Ptr<IConfig const> m_config;
  6612. IRunner* m_runner;
  6613. IResultCapture* m_resultCapture;
  6614. std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
  6615. };
  6616. namespace {
  6617. Context* currentContext = CATCH_NULL;
  6618. }
  6619. IMutableContext& getCurrentMutableContext() {
  6620. if( !currentContext )
  6621. currentContext = new Context();
  6622. return *currentContext;
  6623. }
  6624. IContext& getCurrentContext() {
  6625. return getCurrentMutableContext();
  6626. }
  6627. void cleanUpContext() {
  6628. delete currentContext;
  6629. currentContext = CATCH_NULL;
  6630. }
  6631. }
  6632. // #included from: catch_console_colour_impl.hpp
  6633. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
  6634. // #included from: catch_errno_guard.hpp
  6635. #define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
  6636. #include <cerrno>
  6637. namespace Catch {
  6638. class ErrnoGuard {
  6639. public:
  6640. ErrnoGuard():m_oldErrno(errno){}
  6641. ~ErrnoGuard() { errno = m_oldErrno; }
  6642. private:
  6643. int m_oldErrno;
  6644. };
  6645. }
  6646. namespace Catch {
  6647. namespace {
  6648. struct IColourImpl {
  6649. virtual ~IColourImpl() {}
  6650. virtual void use( Colour::Code _colourCode ) = 0;
  6651. };
  6652. struct NoColourImpl : IColourImpl {
  6653. void use( Colour::Code ) {}
  6654. static IColourImpl* instance() {
  6655. static NoColourImpl s_instance;
  6656. return &s_instance;
  6657. }
  6658. };
  6659. } // anon namespace
  6660. } // namespace Catch
  6661. #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
  6662. # ifdef CATCH_PLATFORM_WINDOWS
  6663. # define CATCH_CONFIG_COLOUR_WINDOWS
  6664. # else
  6665. # define CATCH_CONFIG_COLOUR_ANSI
  6666. # endif
  6667. #endif
  6668. #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
  6669. namespace Catch {
  6670. namespace {
  6671. class Win32ColourImpl : public IColourImpl {
  6672. public:
  6673. Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
  6674. {
  6675. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  6676. GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
  6677. originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
  6678. originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
  6679. }
  6680. virtual void use( Colour::Code _colourCode ) {
  6681. switch( _colourCode ) {
  6682. case Colour::None: return setTextAttribute( originalForegroundAttributes );
  6683. case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6684. case Colour::Red: return setTextAttribute( FOREGROUND_RED );
  6685. case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
  6686. case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
  6687. case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
  6688. case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
  6689. case Colour::Grey: return setTextAttribute( 0 );
  6690. case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
  6691. case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
  6692. case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
  6693. case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6694. case Colour::Bright: throw std::logic_error( "not a colour" );
  6695. }
  6696. }
  6697. private:
  6698. void setTextAttribute( WORD _textAttribute ) {
  6699. SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
  6700. }
  6701. HANDLE stdoutHandle;
  6702. WORD originalForegroundAttributes;
  6703. WORD originalBackgroundAttributes;
  6704. };
  6705. IColourImpl* platformColourInstance() {
  6706. static Win32ColourImpl s_instance;
  6707. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6708. UseColour::YesOrNo colourMode = config
  6709. ? config->useColour()
  6710. : UseColour::Auto;
  6711. if( colourMode == UseColour::Auto )
  6712. colourMode = !isDebuggerActive()
  6713. ? UseColour::Yes
  6714. : UseColour::No;
  6715. return colourMode == UseColour::Yes
  6716. ? &s_instance
  6717. : NoColourImpl::instance();
  6718. }
  6719. } // end anon namespace
  6720. } // end namespace Catch
  6721. #elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
  6722. #include <unistd.h>
  6723. namespace Catch {
  6724. namespace {
  6725. // use POSIX/ ANSI console terminal codes
  6726. // Thanks to Adam Strzelecki for original contribution
  6727. // (http://github.com/nanoant)
  6728. // https://github.com/philsquared/Catch/pull/131
  6729. class PosixColourImpl : public IColourImpl {
  6730. public:
  6731. virtual void use( Colour::Code _colourCode ) {
  6732. switch( _colourCode ) {
  6733. case Colour::None:
  6734. case Colour::White: return setColour( "[0m" );
  6735. case Colour::Red: return setColour( "[0;31m" );
  6736. case Colour::Green: return setColour( "[0;32m" );
  6737. case Colour::Blue: return setColour( "[0;34m" );
  6738. case Colour::Cyan: return setColour( "[0;36m" );
  6739. case Colour::Yellow: return setColour( "[0;33m" );
  6740. case Colour::Grey: return setColour( "[1;30m" );
  6741. case Colour::LightGrey: return setColour( "[0;37m" );
  6742. case Colour::BrightRed: return setColour( "[1;31m" );
  6743. case Colour::BrightGreen: return setColour( "[1;32m" );
  6744. case Colour::BrightWhite: return setColour( "[1;37m" );
  6745. case Colour::Bright: throw std::logic_error( "not a colour" );
  6746. }
  6747. }
  6748. static IColourImpl* instance() {
  6749. static PosixColourImpl s_instance;
  6750. return &s_instance;
  6751. }
  6752. private:
  6753. void setColour( const char* _escapeCode ) {
  6754. Catch::cout() << '\033' << _escapeCode;
  6755. }
  6756. };
  6757. IColourImpl* platformColourInstance() {
  6758. ErrnoGuard guard;
  6759. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6760. UseColour::YesOrNo colourMode = config
  6761. ? config->useColour()
  6762. : UseColour::Auto;
  6763. if( colourMode == UseColour::Auto )
  6764. colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
  6765. ? UseColour::Yes
  6766. : UseColour::No;
  6767. return colourMode == UseColour::Yes
  6768. ? PosixColourImpl::instance()
  6769. : NoColourImpl::instance();
  6770. }
  6771. } // end anon namespace
  6772. } // end namespace Catch
  6773. #else // not Windows or ANSI ///////////////////////////////////////////////
  6774. namespace Catch {
  6775. static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
  6776. } // end namespace Catch
  6777. #endif // Windows/ ANSI/ None
  6778. namespace Catch {
  6779. Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
  6780. Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
  6781. Colour::~Colour(){ if( !m_moved ) use( None ); }
  6782. void Colour::use( Code _colourCode ) {
  6783. static IColourImpl* impl = platformColourInstance();
  6784. impl->use( _colourCode );
  6785. }
  6786. } // end namespace Catch
  6787. // #included from: catch_generators_impl.hpp
  6788. #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
  6789. #include <vector>
  6790. #include <string>
  6791. #include <map>
  6792. namespace Catch {
  6793. struct GeneratorInfo : IGeneratorInfo {
  6794. GeneratorInfo( std::size_t size )
  6795. : m_size( size ),
  6796. m_currentIndex( 0 )
  6797. {}
  6798. bool moveNext() {
  6799. if( ++m_currentIndex == m_size ) {
  6800. m_currentIndex = 0;
  6801. return false;
  6802. }
  6803. return true;
  6804. }
  6805. std::size_t getCurrentIndex() const {
  6806. return m_currentIndex;
  6807. }
  6808. std::size_t m_size;
  6809. std::size_t m_currentIndex;
  6810. };
  6811. ///////////////////////////////////////////////////////////////////////////
  6812. class GeneratorsForTest : public IGeneratorsForTest {
  6813. public:
  6814. ~GeneratorsForTest() {
  6815. deleteAll( m_generatorsInOrder );
  6816. }
  6817. IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
  6818. std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
  6819. if( it == m_generatorsByName.end() ) {
  6820. IGeneratorInfo* info = new GeneratorInfo( size );
  6821. m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
  6822. m_generatorsInOrder.push_back( info );
  6823. return *info;
  6824. }
  6825. return *it->second;
  6826. }
  6827. bool moveNext() {
  6828. std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
  6829. std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
  6830. for(; it != itEnd; ++it ) {
  6831. if( (*it)->moveNext() )
  6832. return true;
  6833. }
  6834. return false;
  6835. }
  6836. private:
  6837. std::map<std::string, IGeneratorInfo*> m_generatorsByName;
  6838. std::vector<IGeneratorInfo*> m_generatorsInOrder;
  6839. };
  6840. IGeneratorsForTest* createGeneratorsForTest()
  6841. {
  6842. return new GeneratorsForTest();
  6843. }
  6844. } // end namespace Catch
  6845. // #included from: catch_assertionresult.hpp
  6846. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
  6847. namespace Catch {
  6848. AssertionInfo::AssertionInfo():macroName(""), capturedExpression(""), resultDisposition(ResultDisposition::Normal), secondArg(""){}
  6849. AssertionInfo::AssertionInfo( char const * _macroName,
  6850. SourceLineInfo const& _lineInfo,
  6851. char const * _capturedExpression,
  6852. ResultDisposition::Flags _resultDisposition,
  6853. char const * _secondArg)
  6854. : macroName( _macroName ),
  6855. lineInfo( _lineInfo ),
  6856. capturedExpression( _capturedExpression ),
  6857. resultDisposition( _resultDisposition ),
  6858. secondArg( _secondArg )
  6859. {}
  6860. AssertionResult::AssertionResult() {}
  6861. AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
  6862. : m_info( info ),
  6863. m_resultData( data )
  6864. {}
  6865. AssertionResult::~AssertionResult() {}
  6866. // Result was a success
  6867. bool AssertionResult::succeeded() const {
  6868. return Catch::isOk( m_resultData.resultType );
  6869. }
  6870. // Result was a success, or failure is suppressed
  6871. bool AssertionResult::isOk() const {
  6872. return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
  6873. }
  6874. ResultWas::OfType AssertionResult::getResultType() const {
  6875. return m_resultData.resultType;
  6876. }
  6877. bool AssertionResult::hasExpression() const {
  6878. return m_info.capturedExpression[0] != 0;
  6879. }
  6880. bool AssertionResult::hasMessage() const {
  6881. return !m_resultData.message.empty();
  6882. }
  6883. std::string capturedExpressionWithSecondArgument( char const * capturedExpression, char const * secondArg ) {
  6884. return (secondArg[0] == 0 || secondArg[0] == '"' && secondArg[1] == '"')
  6885. ? capturedExpression
  6886. : std::string(capturedExpression) + ", " + secondArg;
  6887. }
  6888. std::string AssertionResult::getExpression() const {
  6889. if( isFalseTest( m_info.resultDisposition ) )
  6890. return "!(" + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + ")";
  6891. else
  6892. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6893. }
  6894. std::string AssertionResult::getExpressionInMacro() const {
  6895. if( m_info.macroName[0] == 0 )
  6896. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6897. else
  6898. return std::string(m_info.macroName) + "( " + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + " )";
  6899. }
  6900. bool AssertionResult::hasExpandedExpression() const {
  6901. return hasExpression() && getExpandedExpression() != getExpression();
  6902. }
  6903. std::string AssertionResult::getExpandedExpression() const {
  6904. return m_resultData.reconstructExpression();
  6905. }
  6906. std::string AssertionResult::getMessage() const {
  6907. return m_resultData.message;
  6908. }
  6909. SourceLineInfo AssertionResult::getSourceInfo() const {
  6910. return m_info.lineInfo;
  6911. }
  6912. std::string AssertionResult::getTestMacroName() const {
  6913. return m_info.macroName;
  6914. }
  6915. void AssertionResult::discardDecomposedExpression() const {
  6916. m_resultData.decomposedExpression = CATCH_NULL;
  6917. }
  6918. void AssertionResult::expandDecomposedExpression() const {
  6919. m_resultData.reconstructExpression();
  6920. }
  6921. } // end namespace Catch
  6922. // #included from: catch_test_case_info.hpp
  6923. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
  6924. #include <cctype>
  6925. namespace Catch {
  6926. inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
  6927. if( startsWith( tag, '.' ) ||
  6928. tag == "hide" ||
  6929. tag == "!hide" )
  6930. return TestCaseInfo::IsHidden;
  6931. else if( tag == "!throws" )
  6932. return TestCaseInfo::Throws;
  6933. else if( tag == "!shouldfail" )
  6934. return TestCaseInfo::ShouldFail;
  6935. else if( tag == "!mayfail" )
  6936. return TestCaseInfo::MayFail;
  6937. else if( tag == "!nonportable" )
  6938. return TestCaseInfo::NonPortable;
  6939. else
  6940. return TestCaseInfo::None;
  6941. }
  6942. inline bool isReservedTag( std::string const& tag ) {
  6943. return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] );
  6944. }
  6945. inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
  6946. if( isReservedTag( tag ) ) {
  6947. std::ostringstream ss;
  6948. ss << Colour(Colour::Red)
  6949. << "Tag name [" << tag << "] not allowed.\n"
  6950. << "Tag names starting with non alpha-numeric characters are reserved\n"
  6951. << Colour(Colour::FileName)
  6952. << _lineInfo << '\n';
  6953. throw std::runtime_error(ss.str());
  6954. }
  6955. }
  6956. TestCase makeTestCase( ITestCase* _testCase,
  6957. std::string const& _className,
  6958. std::string const& _name,
  6959. std::string const& _descOrTags,
  6960. SourceLineInfo const& _lineInfo )
  6961. {
  6962. bool isHidden( startsWith( _name, "./" ) ); // Legacy support
  6963. // Parse out tags
  6964. std::set<std::string> tags;
  6965. std::string desc, tag;
  6966. bool inTag = false;
  6967. for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
  6968. char c = _descOrTags[i];
  6969. if( !inTag ) {
  6970. if( c == '[' )
  6971. inTag = true;
  6972. else
  6973. desc += c;
  6974. }
  6975. else {
  6976. if( c == ']' ) {
  6977. TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
  6978. if( prop == TestCaseInfo::IsHidden )
  6979. isHidden = true;
  6980. else if( prop == TestCaseInfo::None )
  6981. enforceNotReservedTag( tag, _lineInfo );
  6982. tags.insert( tag );
  6983. tag.clear();
  6984. inTag = false;
  6985. }
  6986. else
  6987. tag += c;
  6988. }
  6989. }
  6990. if( isHidden ) {
  6991. tags.insert( "hide" );
  6992. tags.insert( "." );
  6993. }
  6994. TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
  6995. return TestCase( _testCase, info );
  6996. }
  6997. void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
  6998. {
  6999. testCaseInfo.tags = tags;
  7000. testCaseInfo.lcaseTags.clear();
  7001. std::ostringstream oss;
  7002. for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
  7003. oss << '[' << *it << ']';
  7004. std::string lcaseTag = toLower( *it );
  7005. testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
  7006. testCaseInfo.lcaseTags.insert( lcaseTag );
  7007. }
  7008. testCaseInfo.tagsAsString = oss.str();
  7009. }
  7010. TestCaseInfo::TestCaseInfo( std::string const& _name,
  7011. std::string const& _className,
  7012. std::string const& _description,
  7013. std::set<std::string> const& _tags,
  7014. SourceLineInfo const& _lineInfo )
  7015. : name( _name ),
  7016. className( _className ),
  7017. description( _description ),
  7018. lineInfo( _lineInfo ),
  7019. properties( None )
  7020. {
  7021. setTags( *this, _tags );
  7022. }
  7023. TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
  7024. : name( other.name ),
  7025. className( other.className ),
  7026. description( other.description ),
  7027. tags( other.tags ),
  7028. lcaseTags( other.lcaseTags ),
  7029. tagsAsString( other.tagsAsString ),
  7030. lineInfo( other.lineInfo ),
  7031. properties( other.properties )
  7032. {}
  7033. bool TestCaseInfo::isHidden() const {
  7034. return ( properties & IsHidden ) != 0;
  7035. }
  7036. bool TestCaseInfo::throws() const {
  7037. return ( properties & Throws ) != 0;
  7038. }
  7039. bool TestCaseInfo::okToFail() const {
  7040. return ( properties & (ShouldFail | MayFail ) ) != 0;
  7041. }
  7042. bool TestCaseInfo::expectedToFail() const {
  7043. return ( properties & (ShouldFail ) ) != 0;
  7044. }
  7045. TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
  7046. TestCase::TestCase( TestCase const& other )
  7047. : TestCaseInfo( other ),
  7048. test( other.test )
  7049. {}
  7050. TestCase TestCase::withName( std::string const& _newName ) const {
  7051. TestCase other( *this );
  7052. other.name = _newName;
  7053. return other;
  7054. }
  7055. void TestCase::swap( TestCase& other ) {
  7056. test.swap( other.test );
  7057. name.swap( other.name );
  7058. className.swap( other.className );
  7059. description.swap( other.description );
  7060. tags.swap( other.tags );
  7061. lcaseTags.swap( other.lcaseTags );
  7062. tagsAsString.swap( other.tagsAsString );
  7063. std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
  7064. std::swap( lineInfo, other.lineInfo );
  7065. }
  7066. void TestCase::invoke() const {
  7067. test->invoke();
  7068. }
  7069. bool TestCase::operator == ( TestCase const& other ) const {
  7070. return test.get() == other.test.get() &&
  7071. name == other.name &&
  7072. className == other.className;
  7073. }
  7074. bool TestCase::operator < ( TestCase const& other ) const {
  7075. return name < other.name;
  7076. }
  7077. TestCase& TestCase::operator = ( TestCase const& other ) {
  7078. TestCase temp( other );
  7079. swap( temp );
  7080. return *this;
  7081. }
  7082. TestCaseInfo const& TestCase::getTestCaseInfo() const
  7083. {
  7084. return *this;
  7085. }
  7086. } // end namespace Catch
  7087. // #included from: catch_version.hpp
  7088. #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
  7089. namespace Catch {
  7090. Version::Version
  7091. ( unsigned int _majorVersion,
  7092. unsigned int _minorVersion,
  7093. unsigned int _patchNumber,
  7094. char const * const _branchName,
  7095. unsigned int _buildNumber )
  7096. : majorVersion( _majorVersion ),
  7097. minorVersion( _minorVersion ),
  7098. patchNumber( _patchNumber ),
  7099. branchName( _branchName ),
  7100. buildNumber( _buildNumber )
  7101. {}
  7102. std::ostream& operator << ( std::ostream& os, Version const& version ) {
  7103. os << version.majorVersion << '.'
  7104. << version.minorVersion << '.'
  7105. << version.patchNumber;
  7106. // branchName is never null -> 0th char is \0 if it is empty
  7107. if (version.branchName[0]) {
  7108. os << '-' << version.branchName
  7109. << '.' << version.buildNumber;
  7110. }
  7111. return os;
  7112. }
  7113. inline Version libraryVersion() {
  7114. static Version version( 1, 12, 2, "", 0 );
  7115. return version;
  7116. }
  7117. }
  7118. // #included from: catch_message.hpp
  7119. #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
  7120. namespace Catch {
  7121. MessageInfo::MessageInfo( std::string const& _macroName,
  7122. SourceLineInfo const& _lineInfo,
  7123. ResultWas::OfType _type )
  7124. : macroName( _macroName ),
  7125. lineInfo( _lineInfo ),
  7126. type( _type ),
  7127. sequence( ++globalCount )
  7128. {}
  7129. // This may need protecting if threading support is added
  7130. unsigned int MessageInfo::globalCount = 0;
  7131. ////////////////////////////////////////////////////////////////////////////
  7132. ScopedMessage::ScopedMessage( MessageBuilder const& builder )
  7133. : m_info( builder.m_info )
  7134. {
  7135. m_info.message = builder.m_stream.str();
  7136. getResultCapture().pushScopedMessage( m_info );
  7137. }
  7138. ScopedMessage::ScopedMessage( ScopedMessage const& other )
  7139. : m_info( other.m_info )
  7140. {}
  7141. #if defined(_MSC_VER)
  7142. #pragma warning(push)
  7143. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7144. #endif
  7145. ScopedMessage::~ScopedMessage() {
  7146. if ( !std::uncaught_exception() ){
  7147. getResultCapture().popScopedMessage(m_info);
  7148. }
  7149. }
  7150. #if defined(_MSC_VER)
  7151. #pragma warning(pop)
  7152. #endif
  7153. } // end namespace Catch
  7154. // #included from: catch_legacy_reporter_adapter.hpp
  7155. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
  7156. // #included from: catch_legacy_reporter_adapter.h
  7157. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
  7158. namespace Catch
  7159. {
  7160. // Deprecated
  7161. struct IReporter : IShared {
  7162. virtual ~IReporter();
  7163. virtual bool shouldRedirectStdout() const = 0;
  7164. virtual void StartTesting() = 0;
  7165. virtual void EndTesting( Totals const& totals ) = 0;
  7166. virtual void StartGroup( std::string const& groupName ) = 0;
  7167. virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
  7168. virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
  7169. virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
  7170. virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
  7171. virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
  7172. virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
  7173. virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
  7174. virtual void Aborted() = 0;
  7175. virtual void Result( AssertionResult const& result ) = 0;
  7176. };
  7177. class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
  7178. {
  7179. public:
  7180. LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
  7181. virtual ~LegacyReporterAdapter();
  7182. virtual ReporterPreferences getPreferences() const;
  7183. virtual void noMatchingTestCases( std::string const& );
  7184. virtual void testRunStarting( TestRunInfo const& );
  7185. virtual void testGroupStarting( GroupInfo const& groupInfo );
  7186. virtual void testCaseStarting( TestCaseInfo const& testInfo );
  7187. virtual void sectionStarting( SectionInfo const& sectionInfo );
  7188. virtual void assertionStarting( AssertionInfo const& );
  7189. virtual bool assertionEnded( AssertionStats const& assertionStats );
  7190. virtual void sectionEnded( SectionStats const& sectionStats );
  7191. virtual void testCaseEnded( TestCaseStats const& testCaseStats );
  7192. virtual void testGroupEnded( TestGroupStats const& testGroupStats );
  7193. virtual void testRunEnded( TestRunStats const& testRunStats );
  7194. virtual void skipTest( TestCaseInfo const& );
  7195. private:
  7196. Ptr<IReporter> m_legacyReporter;
  7197. };
  7198. }
  7199. namespace Catch
  7200. {
  7201. LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
  7202. : m_legacyReporter( legacyReporter )
  7203. {}
  7204. LegacyReporterAdapter::~LegacyReporterAdapter() {}
  7205. ReporterPreferences LegacyReporterAdapter::getPreferences() const {
  7206. ReporterPreferences prefs;
  7207. prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
  7208. return prefs;
  7209. }
  7210. void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
  7211. void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
  7212. m_legacyReporter->StartTesting();
  7213. }
  7214. void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
  7215. m_legacyReporter->StartGroup( groupInfo.name );
  7216. }
  7217. void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
  7218. m_legacyReporter->StartTestCase( testInfo );
  7219. }
  7220. void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
  7221. m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
  7222. }
  7223. void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
  7224. // Not on legacy interface
  7225. }
  7226. bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
  7227. if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
  7228. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  7229. it != itEnd;
  7230. ++it ) {
  7231. if( it->type == ResultWas::Info ) {
  7232. ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
  7233. rb << it->message;
  7234. rb.setResultType( ResultWas::Info );
  7235. AssertionResult result = rb.build();
  7236. m_legacyReporter->Result( result );
  7237. }
  7238. }
  7239. }
  7240. m_legacyReporter->Result( assertionStats.assertionResult );
  7241. return true;
  7242. }
  7243. void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
  7244. if( sectionStats.missingAssertions )
  7245. m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
  7246. m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
  7247. }
  7248. void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
  7249. m_legacyReporter->EndTestCase
  7250. ( testCaseStats.testInfo,
  7251. testCaseStats.totals,
  7252. testCaseStats.stdOut,
  7253. testCaseStats.stdErr );
  7254. }
  7255. void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
  7256. if( testGroupStats.aborting )
  7257. m_legacyReporter->Aborted();
  7258. m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
  7259. }
  7260. void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
  7261. m_legacyReporter->EndTesting( testRunStats.totals );
  7262. }
  7263. void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
  7264. }
  7265. }
  7266. // #included from: catch_timer.hpp
  7267. #ifdef __clang__
  7268. #pragma clang diagnostic push
  7269. #pragma clang diagnostic ignored "-Wc++11-long-long"
  7270. #endif
  7271. #ifdef CATCH_PLATFORM_WINDOWS
  7272. #else
  7273. #include <sys/time.h>
  7274. #endif
  7275. namespace Catch {
  7276. namespace {
  7277. #ifdef CATCH_PLATFORM_WINDOWS
  7278. UInt64 getCurrentTicks() {
  7279. static UInt64 hz=0, hzo=0;
  7280. if (!hz) {
  7281. QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
  7282. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
  7283. }
  7284. UInt64 t;
  7285. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
  7286. return ((t-hzo)*1000000)/hz;
  7287. }
  7288. #else
  7289. UInt64 getCurrentTicks() {
  7290. timeval t;
  7291. gettimeofday(&t,CATCH_NULL);
  7292. return static_cast<UInt64>( t.tv_sec ) * 1000000ull + static_cast<UInt64>( t.tv_usec );
  7293. }
  7294. #endif
  7295. }
  7296. void Timer::start() {
  7297. m_ticks = getCurrentTicks();
  7298. }
  7299. unsigned int Timer::getElapsedMicroseconds() const {
  7300. return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
  7301. }
  7302. unsigned int Timer::getElapsedMilliseconds() const {
  7303. return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
  7304. }
  7305. double Timer::getElapsedSeconds() const {
  7306. return getElapsedMicroseconds()/1000000.0;
  7307. }
  7308. } // namespace Catch
  7309. #ifdef __clang__
  7310. #pragma clang diagnostic pop
  7311. #endif
  7312. // #included from: catch_common.hpp
  7313. #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
  7314. #include <cstring>
  7315. #include <cctype>
  7316. namespace Catch {
  7317. bool startsWith( std::string const& s, std::string const& prefix ) {
  7318. return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
  7319. }
  7320. bool startsWith( std::string const& s, char prefix ) {
  7321. return !s.empty() && s[0] == prefix;
  7322. }
  7323. bool endsWith( std::string const& s, std::string const& suffix ) {
  7324. return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
  7325. }
  7326. bool endsWith( std::string const& s, char suffix ) {
  7327. return !s.empty() && s[s.size()-1] == suffix;
  7328. }
  7329. bool contains( std::string const& s, std::string const& infix ) {
  7330. return s.find( infix ) != std::string::npos;
  7331. }
  7332. char toLowerCh(char c) {
  7333. return static_cast<char>( std::tolower( c ) );
  7334. }
  7335. void toLowerInPlace( std::string& s ) {
  7336. std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
  7337. }
  7338. std::string toLower( std::string const& s ) {
  7339. std::string lc = s;
  7340. toLowerInPlace( lc );
  7341. return lc;
  7342. }
  7343. std::string trim( std::string const& str ) {
  7344. static char const* whitespaceChars = "\n\r\t ";
  7345. std::string::size_type start = str.find_first_not_of( whitespaceChars );
  7346. std::string::size_type end = str.find_last_not_of( whitespaceChars );
  7347. return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
  7348. }
  7349. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
  7350. bool replaced = false;
  7351. std::size_t i = str.find( replaceThis );
  7352. while( i != std::string::npos ) {
  7353. replaced = true;
  7354. str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
  7355. if( i < str.size()-withThis.size() )
  7356. i = str.find( replaceThis, i+withThis.size() );
  7357. else
  7358. i = std::string::npos;
  7359. }
  7360. return replaced;
  7361. }
  7362. pluralise::pluralise( std::size_t count, std::string const& label )
  7363. : m_count( count ),
  7364. m_label( label )
  7365. {}
  7366. std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
  7367. os << pluraliser.m_count << ' ' << pluraliser.m_label;
  7368. if( pluraliser.m_count != 1 )
  7369. os << 's';
  7370. return os;
  7371. }
  7372. SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
  7373. SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
  7374. : file( _file ),
  7375. line( _line )
  7376. {}
  7377. bool SourceLineInfo::empty() const {
  7378. return file[0] == '\0';
  7379. }
  7380. bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
  7381. return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
  7382. }
  7383. bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
  7384. return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
  7385. }
  7386. void seedRng( IConfig const& config ) {
  7387. if( config.rngSeed() != 0 )
  7388. std::srand( config.rngSeed() );
  7389. }
  7390. unsigned int rngSeed() {
  7391. return getCurrentContext().getConfig()->rngSeed();
  7392. }
  7393. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
  7394. #ifndef __GNUG__
  7395. os << info.file << '(' << info.line << ')';
  7396. #else
  7397. os << info.file << ':' << info.line;
  7398. #endif
  7399. return os;
  7400. }
  7401. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
  7402. std::ostringstream oss;
  7403. oss << locationInfo << ": Internal Catch error: '" << message << '\'';
  7404. if( alwaysTrue() )
  7405. throw std::logic_error( oss.str() );
  7406. }
  7407. }
  7408. // #included from: catch_section.hpp
  7409. #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
  7410. namespace Catch {
  7411. SectionInfo::SectionInfo
  7412. ( SourceLineInfo const& _lineInfo,
  7413. std::string const& _name,
  7414. std::string const& _description )
  7415. : name( _name ),
  7416. description( _description ),
  7417. lineInfo( _lineInfo )
  7418. {}
  7419. Section::Section( SectionInfo const& info )
  7420. : m_info( info ),
  7421. m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
  7422. {
  7423. m_timer.start();
  7424. }
  7425. #if defined(_MSC_VER)
  7426. #pragma warning(push)
  7427. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7428. #endif
  7429. Section::~Section() {
  7430. if( m_sectionIncluded ) {
  7431. SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
  7432. if( std::uncaught_exception() )
  7433. getResultCapture().sectionEndedEarly( endInfo );
  7434. else
  7435. getResultCapture().sectionEnded( endInfo );
  7436. }
  7437. }
  7438. #if defined(_MSC_VER)
  7439. #pragma warning(pop)
  7440. #endif
  7441. // This indicates whether the section should be executed or not
  7442. Section::operator bool() const {
  7443. return m_sectionIncluded;
  7444. }
  7445. } // end namespace Catch
  7446. // #included from: catch_debugger.hpp
  7447. #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
  7448. #ifdef CATCH_PLATFORM_MAC
  7449. #include <assert.h>
  7450. #include <stdbool.h>
  7451. #include <sys/types.h>
  7452. #include <unistd.h>
  7453. #include <sys/sysctl.h>
  7454. namespace Catch{
  7455. // The following function is taken directly from the following technical note:
  7456. // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
  7457. // Returns true if the current process is being debugged (either
  7458. // running under the debugger or has a debugger attached post facto).
  7459. bool isDebuggerActive(){
  7460. int mib[4];
  7461. struct kinfo_proc info;
  7462. size_t size;
  7463. // Initialize the flags so that, if sysctl fails for some bizarre
  7464. // reason, we get a predictable result.
  7465. info.kp_proc.p_flag = 0;
  7466. // Initialize mib, which tells sysctl the info we want, in this case
  7467. // we're looking for information about a specific process ID.
  7468. mib[0] = CTL_KERN;
  7469. mib[1] = KERN_PROC;
  7470. mib[2] = KERN_PROC_PID;
  7471. mib[3] = getpid();
  7472. // Call sysctl.
  7473. size = sizeof(info);
  7474. if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
  7475. Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
  7476. return false;
  7477. }
  7478. // We're being debugged if the P_TRACED flag is set.
  7479. return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
  7480. }
  7481. } // namespace Catch
  7482. #elif defined(CATCH_PLATFORM_LINUX)
  7483. #include <fstream>
  7484. #include <string>
  7485. namespace Catch{
  7486. // The standard POSIX way of detecting a debugger is to attempt to
  7487. // ptrace() the process, but this needs to be done from a child and not
  7488. // this process itself to still allow attaching to this process later
  7489. // if wanted, so is rather heavy. Under Linux we have the PID of the
  7490. // "debugger" (which doesn't need to be gdb, of course, it could also
  7491. // be strace, for example) in /proc/$PID/status, so just get it from
  7492. // there instead.
  7493. bool isDebuggerActive(){
  7494. // Libstdc++ has a bug, where std::ifstream sets errno to 0
  7495. // This way our users can properly assert over errno values
  7496. ErrnoGuard guard;
  7497. std::ifstream in("/proc/self/status");
  7498. for( std::string line; std::getline(in, line); ) {
  7499. static const int PREFIX_LEN = 11;
  7500. if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) {
  7501. // We're traced if the PID is not 0 and no other PID starts
  7502. // with 0 digit, so it's enough to check for just a single
  7503. // character.
  7504. return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0';
  7505. }
  7506. }
  7507. return false;
  7508. }
  7509. } // namespace Catch
  7510. #elif defined(_MSC_VER)
  7511. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7512. namespace Catch {
  7513. bool isDebuggerActive() {
  7514. return IsDebuggerPresent() != 0;
  7515. }
  7516. }
  7517. #elif defined(__MINGW32__)
  7518. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7519. namespace Catch {
  7520. bool isDebuggerActive() {
  7521. return IsDebuggerPresent() != 0;
  7522. }
  7523. }
  7524. #else
  7525. namespace Catch {
  7526. inline bool isDebuggerActive() { return false; }
  7527. }
  7528. #endif // Platform
  7529. #ifdef CATCH_PLATFORM_WINDOWS
  7530. namespace Catch {
  7531. void writeToDebugConsole( std::string const& text ) {
  7532. ::OutputDebugStringA( text.c_str() );
  7533. }
  7534. }
  7535. #else
  7536. namespace Catch {
  7537. void writeToDebugConsole( std::string const& text ) {
  7538. // !TBD: Need a version for Mac/ XCode and other IDEs
  7539. Catch::cout() << text;
  7540. }
  7541. }
  7542. #endif // Platform
  7543. // #included from: catch_tostring.hpp
  7544. #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
  7545. namespace Catch {
  7546. namespace Detail {
  7547. const std::string unprintableString = "{?}";
  7548. namespace {
  7549. const int hexThreshold = 255;
  7550. struct Endianness {
  7551. enum Arch { Big, Little };
  7552. static Arch which() {
  7553. union _{
  7554. int asInt;
  7555. char asChar[sizeof (int)];
  7556. } u;
  7557. u.asInt = 1;
  7558. return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
  7559. }
  7560. };
  7561. }
  7562. std::string rawMemoryToString( const void *object, std::size_t size )
  7563. {
  7564. // Reverse order for little endian architectures
  7565. int i = 0, end = static_cast<int>( size ), inc = 1;
  7566. if( Endianness::which() == Endianness::Little ) {
  7567. i = end-1;
  7568. end = inc = -1;
  7569. }
  7570. unsigned char const *bytes = static_cast<unsigned char const *>(object);
  7571. std::ostringstream os;
  7572. os << "0x" << std::setfill('0') << std::hex;
  7573. for( ; i != end; i += inc )
  7574. os << std::setw(2) << static_cast<unsigned>(bytes[i]);
  7575. return os.str();
  7576. }
  7577. }
  7578. std::string toString( std::string const& value ) {
  7579. std::string s = value;
  7580. if( getCurrentContext().getConfig()->showInvisibles() ) {
  7581. for(size_t i = 0; i < s.size(); ++i ) {
  7582. std::string subs;
  7583. switch( s[i] ) {
  7584. case '\n': subs = "\\n"; break;
  7585. case '\t': subs = "\\t"; break;
  7586. default: break;
  7587. }
  7588. if( !subs.empty() ) {
  7589. s = s.substr( 0, i ) + subs + s.substr( i+1 );
  7590. ++i;
  7591. }
  7592. }
  7593. }
  7594. return '"' + s + '"';
  7595. }
  7596. std::string toString( std::wstring const& value ) {
  7597. std::string s;
  7598. s.reserve( value.size() );
  7599. for(size_t i = 0; i < value.size(); ++i )
  7600. s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
  7601. return Catch::toString( s );
  7602. }
  7603. std::string toString( const char* const value ) {
  7604. return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
  7605. }
  7606. std::string toString( char* const value ) {
  7607. return Catch::toString( static_cast<const char*>( value ) );
  7608. }
  7609. std::string toString( const wchar_t* const value )
  7610. {
  7611. return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
  7612. }
  7613. std::string toString( wchar_t* const value )
  7614. {
  7615. return Catch::toString( static_cast<const wchar_t*>( value ) );
  7616. }
  7617. std::string toString( int value ) {
  7618. std::ostringstream oss;
  7619. oss << value;
  7620. if( value > Detail::hexThreshold )
  7621. oss << " (0x" << std::hex << value << ')';
  7622. return oss.str();
  7623. }
  7624. std::string toString( unsigned long value ) {
  7625. std::ostringstream oss;
  7626. oss << value;
  7627. if( value > Detail::hexThreshold )
  7628. oss << " (0x" << std::hex << value << ')';
  7629. return oss.str();
  7630. }
  7631. std::string toString( unsigned int value ) {
  7632. return Catch::toString( static_cast<unsigned long>( value ) );
  7633. }
  7634. template<typename T>
  7635. std::string fpToString( T value, int precision ) {
  7636. std::ostringstream oss;
  7637. oss << std::setprecision( precision )
  7638. << std::fixed
  7639. << value;
  7640. std::string d = oss.str();
  7641. std::size_t i = d.find_last_not_of( '0' );
  7642. if( i != std::string::npos && i != d.size()-1 ) {
  7643. if( d[i] == '.' )
  7644. i++;
  7645. d = d.substr( 0, i+1 );
  7646. }
  7647. return d;
  7648. }
  7649. std::string toString( const double value ) {
  7650. return fpToString( value, 10 );
  7651. }
  7652. std::string toString( const float value ) {
  7653. return fpToString( value, 5 ) + 'f';
  7654. }
  7655. std::string toString( bool value ) {
  7656. return value ? "true" : "false";
  7657. }
  7658. std::string toString( char value ) {
  7659. if ( value == '\r' )
  7660. return "'\\r'";
  7661. if ( value == '\f' )
  7662. return "'\\f'";
  7663. if ( value == '\n' )
  7664. return "'\\n'";
  7665. if ( value == '\t' )
  7666. return "'\\t'";
  7667. if ( '\0' <= value && value < ' ' )
  7668. return toString( static_cast<unsigned int>( value ) );
  7669. char chstr[] = "' '";
  7670. chstr[1] = value;
  7671. return chstr;
  7672. }
  7673. std::string toString( signed char value ) {
  7674. return toString( static_cast<char>( value ) );
  7675. }
  7676. std::string toString( unsigned char value ) {
  7677. return toString( static_cast<char>( value ) );
  7678. }
  7679. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  7680. std::string toString( long long value ) {
  7681. std::ostringstream oss;
  7682. oss << value;
  7683. if( value > Detail::hexThreshold )
  7684. oss << " (0x" << std::hex << value << ')';
  7685. return oss.str();
  7686. }
  7687. std::string toString( unsigned long long value ) {
  7688. std::ostringstream oss;
  7689. oss << value;
  7690. if( value > Detail::hexThreshold )
  7691. oss << " (0x" << std::hex << value << ')';
  7692. return oss.str();
  7693. }
  7694. #endif
  7695. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  7696. std::string toString( std::nullptr_t ) {
  7697. return "nullptr";
  7698. }
  7699. #endif
  7700. #ifdef __OBJC__
  7701. std::string toString( NSString const * const& nsstring ) {
  7702. if( !nsstring )
  7703. return "nil";
  7704. return "@" + toString([nsstring UTF8String]);
  7705. }
  7706. std::string toString( NSString * CATCH_ARC_STRONG & nsstring ) {
  7707. if( !nsstring )
  7708. return "nil";
  7709. return "@" + toString([nsstring UTF8String]);
  7710. }
  7711. std::string toString( NSObject* const& nsObject ) {
  7712. return toString( [nsObject description] );
  7713. }
  7714. #endif
  7715. } // end namespace Catch
  7716. // #included from: catch_result_builder.hpp
  7717. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
  7718. #include <cassert>
  7719. namespace Catch {
  7720. ResultBuilder::ResultBuilder( char const* macroName,
  7721. SourceLineInfo const& lineInfo,
  7722. char const* capturedExpression,
  7723. ResultDisposition::Flags resultDisposition,
  7724. char const* secondArg )
  7725. : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition, secondArg ),
  7726. m_shouldDebugBreak( false ),
  7727. m_shouldThrow( false ),
  7728. m_guardException( false ),
  7729. m_usedStream( false )
  7730. {}
  7731. ResultBuilder::~ResultBuilder() {
  7732. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7733. if ( m_guardException ) {
  7734. stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
  7735. captureResult( ResultWas::ThrewException );
  7736. getCurrentContext().getResultCapture()->exceptionEarlyReported();
  7737. }
  7738. #endif
  7739. }
  7740. ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
  7741. m_data.resultType = result;
  7742. return *this;
  7743. }
  7744. ResultBuilder& ResultBuilder::setResultType( bool result ) {
  7745. m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
  7746. return *this;
  7747. }
  7748. void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
  7749. // Flip bool results if FalseTest flag is set
  7750. if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
  7751. m_data.negate( expr.isBinaryExpression() );
  7752. }
  7753. getResultCapture().assertionRun();
  7754. if(getCurrentContext().getConfig()->includeSuccessfulResults() || m_data.resultType != ResultWas::Ok)
  7755. {
  7756. AssertionResult result = build( expr );
  7757. handleResult( result );
  7758. }
  7759. else
  7760. getResultCapture().assertionPassed();
  7761. }
  7762. void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
  7763. m_assertionInfo.resultDisposition = resultDisposition;
  7764. stream().oss << Catch::translateActiveException();
  7765. captureResult( ResultWas::ThrewException );
  7766. }
  7767. void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
  7768. setResultType( resultType );
  7769. captureExpression();
  7770. }
  7771. void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
  7772. if( expectedMessage.empty() )
  7773. captureExpectedException( Matchers::Impl::MatchAllOf<std::string>() );
  7774. else
  7775. captureExpectedException( Matchers::Equals( expectedMessage ) );
  7776. }
  7777. void ResultBuilder::captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher ) {
  7778. assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
  7779. AssertionResultData data = m_data;
  7780. data.resultType = ResultWas::Ok;
  7781. data.reconstructedExpression = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7782. std::string actualMessage = Catch::translateActiveException();
  7783. if( !matcher.match( actualMessage ) ) {
  7784. data.resultType = ResultWas::ExpressionFailed;
  7785. data.reconstructedExpression = actualMessage;
  7786. }
  7787. AssertionResult result( m_assertionInfo, data );
  7788. handleResult( result );
  7789. }
  7790. void ResultBuilder::captureExpression() {
  7791. AssertionResult result = build();
  7792. handleResult( result );
  7793. }
  7794. void ResultBuilder::handleResult( AssertionResult const& result )
  7795. {
  7796. getResultCapture().assertionEnded( result );
  7797. if( !result.isOk() ) {
  7798. if( getCurrentContext().getConfig()->shouldDebugBreak() )
  7799. m_shouldDebugBreak = true;
  7800. if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
  7801. m_shouldThrow = true;
  7802. }
  7803. }
  7804. void ResultBuilder::react() {
  7805. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7806. if (m_shouldDebugBreak) {
  7807. ///////////////////////////////////////////////////////////////////
  7808. // To inspect the state during test, you need to go one level up the callstack
  7809. // To go back to the test and change execution, jump over the throw statement
  7810. ///////////////////////////////////////////////////////////////////
  7811. CATCH_BREAK_INTO_DEBUGGER();
  7812. }
  7813. #endif
  7814. if( m_shouldThrow )
  7815. throw Catch::TestFailureException();
  7816. }
  7817. bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
  7818. bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
  7819. AssertionResult ResultBuilder::build() const
  7820. {
  7821. return build( *this );
  7822. }
  7823. // CAVEAT: The returned AssertionResult stores a pointer to the argument expr,
  7824. // a temporary DecomposedExpression, which in turn holds references to
  7825. // operands, possibly temporary as well.
  7826. // It should immediately be passed to handleResult; if the expression
  7827. // needs to be reported, its string expansion must be composed before
  7828. // the temporaries are destroyed.
  7829. AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
  7830. {
  7831. assert( m_data.resultType != ResultWas::Unknown );
  7832. AssertionResultData data = m_data;
  7833. if(m_usedStream)
  7834. data.message = m_stream().oss.str();
  7835. data.decomposedExpression = &expr; // for lazy reconstruction
  7836. return AssertionResult( m_assertionInfo, data );
  7837. }
  7838. void ResultBuilder::reconstructExpression( std::string& dest ) const {
  7839. dest = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7840. }
  7841. void ResultBuilder::setExceptionGuard() {
  7842. m_guardException = true;
  7843. }
  7844. void ResultBuilder::unsetExceptionGuard() {
  7845. m_guardException = false;
  7846. }
  7847. } // end namespace Catch
  7848. // #included from: catch_tag_alias_registry.hpp
  7849. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7850. namespace Catch {
  7851. TagAliasRegistry::~TagAliasRegistry() {}
  7852. Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
  7853. std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
  7854. if( it != m_registry.end() )
  7855. return it->second;
  7856. else
  7857. return Option<TagAlias>();
  7858. }
  7859. std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
  7860. std::string expandedTestSpec = unexpandedTestSpec;
  7861. for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
  7862. it != itEnd;
  7863. ++it ) {
  7864. std::size_t pos = expandedTestSpec.find( it->first );
  7865. if( pos != std::string::npos ) {
  7866. expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
  7867. it->second.tag +
  7868. expandedTestSpec.substr( pos + it->first.size() );
  7869. }
  7870. }
  7871. return expandedTestSpec;
  7872. }
  7873. void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
  7874. if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) {
  7875. std::ostringstream oss;
  7876. oss << Colour( Colour::Red )
  7877. << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n"
  7878. << Colour( Colour::FileName )
  7879. << lineInfo << '\n';
  7880. throw std::domain_error( oss.str().c_str() );
  7881. }
  7882. if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
  7883. std::ostringstream oss;
  7884. oss << Colour( Colour::Red )
  7885. << "error: tag alias, \"" << alias << "\" already registered.\n"
  7886. << "\tFirst seen at "
  7887. << Colour( Colour::Red ) << find(alias)->lineInfo << '\n'
  7888. << Colour( Colour::Red ) << "\tRedefined at "
  7889. << Colour( Colour::FileName) << lineInfo << '\n';
  7890. throw std::domain_error( oss.str().c_str() );
  7891. }
  7892. }
  7893. ITagAliasRegistry::~ITagAliasRegistry() {}
  7894. ITagAliasRegistry const& ITagAliasRegistry::get() {
  7895. return getRegistryHub().getTagAliasRegistry();
  7896. }
  7897. RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
  7898. getMutableRegistryHub().registerTagAlias( alias, tag, lineInfo );
  7899. }
  7900. } // end namespace Catch
  7901. // #included from: catch_matchers_string.hpp
  7902. namespace Catch {
  7903. namespace Matchers {
  7904. namespace StdString {
  7905. CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
  7906. : m_caseSensitivity( caseSensitivity ),
  7907. m_str( adjustString( str ) )
  7908. {}
  7909. std::string CasedString::adjustString( std::string const& str ) const {
  7910. return m_caseSensitivity == CaseSensitive::No
  7911. ? toLower( str )
  7912. : str;
  7913. }
  7914. std::string CasedString::caseSensitivitySuffix() const {
  7915. return m_caseSensitivity == CaseSensitive::No
  7916. ? " (case insensitive)"
  7917. : std::string();
  7918. }
  7919. StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
  7920. : m_comparator( comparator ),
  7921. m_operation( operation ) {
  7922. }
  7923. std::string StringMatcherBase::describe() const {
  7924. std::string description;
  7925. description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
  7926. m_comparator.caseSensitivitySuffix().size());
  7927. description += m_operation;
  7928. description += ": \"";
  7929. description += m_comparator.m_str;
  7930. description += "\"";
  7931. description += m_comparator.caseSensitivitySuffix();
  7932. return description;
  7933. }
  7934. EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {}
  7935. bool EqualsMatcher::match( std::string const& source ) const {
  7936. return m_comparator.adjustString( source ) == m_comparator.m_str;
  7937. }
  7938. ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {}
  7939. bool ContainsMatcher::match( std::string const& source ) const {
  7940. return contains( m_comparator.adjustString( source ), m_comparator.m_str );
  7941. }
  7942. StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {}
  7943. bool StartsWithMatcher::match( std::string const& source ) const {
  7944. return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7945. }
  7946. EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {}
  7947. bool EndsWithMatcher::match( std::string const& source ) const {
  7948. return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7949. }
  7950. } // namespace StdString
  7951. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7952. return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
  7953. }
  7954. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7955. return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
  7956. }
  7957. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7958. return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7959. }
  7960. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7961. return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7962. }
  7963. } // namespace Matchers
  7964. } // namespace Catch
  7965. // #included from: ../reporters/catch_reporter_multi.hpp
  7966. #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
  7967. namespace Catch {
  7968. class MultipleReporters : public SharedImpl<IStreamingReporter> {
  7969. typedef std::vector<Ptr<IStreamingReporter> > Reporters;
  7970. Reporters m_reporters;
  7971. public:
  7972. void add( Ptr<IStreamingReporter> const& reporter ) {
  7973. m_reporters.push_back( reporter );
  7974. }
  7975. public: // IStreamingReporter
  7976. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7977. return m_reporters[0]->getPreferences();
  7978. }
  7979. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  7980. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7981. it != itEnd;
  7982. ++it )
  7983. (*it)->noMatchingTestCases( spec );
  7984. }
  7985. virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
  7986. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7987. it != itEnd;
  7988. ++it )
  7989. (*it)->testRunStarting( testRunInfo );
  7990. }
  7991. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  7992. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7993. it != itEnd;
  7994. ++it )
  7995. (*it)->testGroupStarting( groupInfo );
  7996. }
  7997. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7998. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7999. it != itEnd;
  8000. ++it )
  8001. (*it)->testCaseStarting( testInfo );
  8002. }
  8003. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8004. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8005. it != itEnd;
  8006. ++it )
  8007. (*it)->sectionStarting( sectionInfo );
  8008. }
  8009. virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
  8010. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8011. it != itEnd;
  8012. ++it )
  8013. (*it)->assertionStarting( assertionInfo );
  8014. }
  8015. // The return value indicates if the messages buffer should be cleared:
  8016. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8017. bool clearBuffer = false;
  8018. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8019. it != itEnd;
  8020. ++it )
  8021. clearBuffer |= (*it)->assertionEnded( assertionStats );
  8022. return clearBuffer;
  8023. }
  8024. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8025. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8026. it != itEnd;
  8027. ++it )
  8028. (*it)->sectionEnded( sectionStats );
  8029. }
  8030. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8031. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8032. it != itEnd;
  8033. ++it )
  8034. (*it)->testCaseEnded( testCaseStats );
  8035. }
  8036. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8037. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8038. it != itEnd;
  8039. ++it )
  8040. (*it)->testGroupEnded( testGroupStats );
  8041. }
  8042. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8043. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8044. it != itEnd;
  8045. ++it )
  8046. (*it)->testRunEnded( testRunStats );
  8047. }
  8048. virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  8049. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  8050. it != itEnd;
  8051. ++it )
  8052. (*it)->skipTest( testInfo );
  8053. }
  8054. virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
  8055. return this;
  8056. }
  8057. };
  8058. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
  8059. Ptr<IStreamingReporter> resultingReporter;
  8060. if( existingReporter ) {
  8061. MultipleReporters* multi = existingReporter->tryAsMulti();
  8062. if( !multi ) {
  8063. multi = new MultipleReporters;
  8064. resultingReporter = Ptr<IStreamingReporter>( multi );
  8065. if( existingReporter )
  8066. multi->add( existingReporter );
  8067. }
  8068. else
  8069. resultingReporter = existingReporter;
  8070. multi->add( additionalReporter );
  8071. }
  8072. else
  8073. resultingReporter = additionalReporter;
  8074. return resultingReporter;
  8075. }
  8076. } // end namespace Catch
  8077. // #included from: ../reporters/catch_reporter_xml.hpp
  8078. #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
  8079. // #included from: catch_reporter_bases.hpp
  8080. #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
  8081. #include <cstring>
  8082. #include <cfloat>
  8083. #include <cstdio>
  8084. #include <assert.h>
  8085. namespace Catch {
  8086. namespace {
  8087. // Because formatting using c++ streams is stateful, drop down to C is required
  8088. // Alternatively we could use stringstream, but its performance is... not good.
  8089. std::string getFormattedDuration( double duration ) {
  8090. // Max exponent + 1 is required to represent the whole part
  8091. // + 1 for decimal point
  8092. // + 3 for the 3 decimal places
  8093. // + 1 for null terminator
  8094. const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
  8095. char buffer[maxDoubleSize];
  8096. // Save previous errno, to prevent sprintf from overwriting it
  8097. ErrnoGuard guard;
  8098. #ifdef _MSC_VER
  8099. sprintf_s(buffer, "%.3f", duration);
  8100. #else
  8101. sprintf(buffer, "%.3f", duration);
  8102. #endif
  8103. return std::string(buffer);
  8104. }
  8105. }
  8106. struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
  8107. StreamingReporterBase( ReporterConfig const& _config )
  8108. : m_config( _config.fullConfig() ),
  8109. stream( _config.stream() )
  8110. {
  8111. m_reporterPrefs.shouldRedirectStdOut = false;
  8112. }
  8113. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8114. return m_reporterPrefs;
  8115. }
  8116. virtual ~StreamingReporterBase() CATCH_OVERRIDE;
  8117. virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
  8118. virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
  8119. currentTestRunInfo = _testRunInfo;
  8120. }
  8121. virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
  8122. currentGroupInfo = _groupInfo;
  8123. }
  8124. virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
  8125. currentTestCaseInfo = _testInfo;
  8126. }
  8127. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8128. m_sectionStack.push_back( _sectionInfo );
  8129. }
  8130. virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
  8131. m_sectionStack.pop_back();
  8132. }
  8133. virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
  8134. currentTestCaseInfo.reset();
  8135. }
  8136. virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
  8137. currentGroupInfo.reset();
  8138. }
  8139. virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
  8140. currentTestCaseInfo.reset();
  8141. currentGroupInfo.reset();
  8142. currentTestRunInfo.reset();
  8143. }
  8144. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
  8145. // Don't do anything with this by default.
  8146. // It can optionally be overridden in the derived class.
  8147. }
  8148. Ptr<IConfig const> m_config;
  8149. std::ostream& stream;
  8150. LazyStat<TestRunInfo> currentTestRunInfo;
  8151. LazyStat<GroupInfo> currentGroupInfo;
  8152. LazyStat<TestCaseInfo> currentTestCaseInfo;
  8153. std::vector<SectionInfo> m_sectionStack;
  8154. ReporterPreferences m_reporterPrefs;
  8155. };
  8156. struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
  8157. template<typename T, typename ChildNodeT>
  8158. struct Node : SharedImpl<> {
  8159. explicit Node( T const& _value ) : value( _value ) {}
  8160. virtual ~Node() {}
  8161. typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
  8162. T value;
  8163. ChildNodes children;
  8164. };
  8165. struct SectionNode : SharedImpl<> {
  8166. explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
  8167. virtual ~SectionNode();
  8168. bool operator == ( SectionNode const& other ) const {
  8169. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  8170. }
  8171. bool operator == ( Ptr<SectionNode> const& other ) const {
  8172. return operator==( *other );
  8173. }
  8174. SectionStats stats;
  8175. typedef std::vector<Ptr<SectionNode> > ChildSections;
  8176. typedef std::vector<AssertionStats> Assertions;
  8177. ChildSections childSections;
  8178. Assertions assertions;
  8179. std::string stdOut;
  8180. std::string stdErr;
  8181. };
  8182. struct BySectionInfo {
  8183. BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
  8184. BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
  8185. bool operator() ( Ptr<SectionNode> const& node ) const {
  8186. return ((node->stats.sectionInfo.name == m_other.name) &&
  8187. (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
  8188. }
  8189. private:
  8190. void operator=( BySectionInfo const& );
  8191. SectionInfo const& m_other;
  8192. };
  8193. typedef Node<TestCaseStats, SectionNode> TestCaseNode;
  8194. typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
  8195. typedef Node<TestRunStats, TestGroupNode> TestRunNode;
  8196. CumulativeReporterBase( ReporterConfig const& _config )
  8197. : m_config( _config.fullConfig() ),
  8198. stream( _config.stream() )
  8199. {
  8200. m_reporterPrefs.shouldRedirectStdOut = false;
  8201. }
  8202. ~CumulativeReporterBase();
  8203. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8204. return m_reporterPrefs;
  8205. }
  8206. virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
  8207. virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
  8208. virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8209. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8210. SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
  8211. Ptr<SectionNode> node;
  8212. if( m_sectionStack.empty() ) {
  8213. if( !m_rootSection )
  8214. m_rootSection = new SectionNode( incompleteStats );
  8215. node = m_rootSection;
  8216. }
  8217. else {
  8218. SectionNode& parentNode = *m_sectionStack.back();
  8219. SectionNode::ChildSections::const_iterator it =
  8220. std::find_if( parentNode.childSections.begin(),
  8221. parentNode.childSections.end(),
  8222. BySectionInfo( sectionInfo ) );
  8223. if( it == parentNode.childSections.end() ) {
  8224. node = new SectionNode( incompleteStats );
  8225. parentNode.childSections.push_back( node );
  8226. }
  8227. else
  8228. node = *it;
  8229. }
  8230. m_sectionStack.push_back( node );
  8231. m_deepestSection = node;
  8232. }
  8233. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8234. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8235. assert( !m_sectionStack.empty() );
  8236. SectionNode& sectionNode = *m_sectionStack.back();
  8237. sectionNode.assertions.push_back( assertionStats );
  8238. // AssertionResult holds a pointer to a temporary DecomposedExpression,
  8239. // which getExpandedExpression() calls to build the expression string.
  8240. // Our section stack copy of the assertionResult will likely outlive the
  8241. // temporary, so it must be expanded or discarded now to avoid calling
  8242. // a destroyed object later.
  8243. prepareExpandedExpression( sectionNode.assertions.back().assertionResult );
  8244. return true;
  8245. }
  8246. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8247. assert( !m_sectionStack.empty() );
  8248. SectionNode& node = *m_sectionStack.back();
  8249. node.stats = sectionStats;
  8250. m_sectionStack.pop_back();
  8251. }
  8252. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8253. Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
  8254. assert( m_sectionStack.size() == 0 );
  8255. node->children.push_back( m_rootSection );
  8256. m_testCases.push_back( node );
  8257. m_rootSection.reset();
  8258. assert( m_deepestSection );
  8259. m_deepestSection->stdOut = testCaseStats.stdOut;
  8260. m_deepestSection->stdErr = testCaseStats.stdErr;
  8261. }
  8262. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8263. Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
  8264. node->children.swap( m_testCases );
  8265. m_testGroups.push_back( node );
  8266. }
  8267. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8268. Ptr<TestRunNode> node = new TestRunNode( testRunStats );
  8269. node->children.swap( m_testGroups );
  8270. m_testRuns.push_back( node );
  8271. testRunEndedCumulative();
  8272. }
  8273. virtual void testRunEndedCumulative() = 0;
  8274. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8275. virtual void prepareExpandedExpression( AssertionResult& result ) const {
  8276. if( result.isOk() )
  8277. result.discardDecomposedExpression();
  8278. else
  8279. result.expandDecomposedExpression();
  8280. }
  8281. Ptr<IConfig const> m_config;
  8282. std::ostream& stream;
  8283. std::vector<AssertionStats> m_assertions;
  8284. std::vector<std::vector<Ptr<SectionNode> > > m_sections;
  8285. std::vector<Ptr<TestCaseNode> > m_testCases;
  8286. std::vector<Ptr<TestGroupNode> > m_testGroups;
  8287. std::vector<Ptr<TestRunNode> > m_testRuns;
  8288. Ptr<SectionNode> m_rootSection;
  8289. Ptr<SectionNode> m_deepestSection;
  8290. std::vector<Ptr<SectionNode> > m_sectionStack;
  8291. ReporterPreferences m_reporterPrefs;
  8292. };
  8293. template<char C>
  8294. char const* getLineOfChars() {
  8295. static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
  8296. if( !*line ) {
  8297. std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
  8298. line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
  8299. }
  8300. return line;
  8301. }
  8302. struct TestEventListenerBase : StreamingReporterBase {
  8303. TestEventListenerBase( ReporterConfig const& _config )
  8304. : StreamingReporterBase( _config )
  8305. {}
  8306. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8307. virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
  8308. return false;
  8309. }
  8310. };
  8311. } // end namespace Catch
  8312. // #included from: ../internal/catch_reporter_registrars.hpp
  8313. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  8314. namespace Catch {
  8315. template<typename T>
  8316. class LegacyReporterRegistrar {
  8317. class ReporterFactory : public IReporterFactory {
  8318. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8319. return new LegacyReporterAdapter( new T( config ) );
  8320. }
  8321. virtual std::string getDescription() const {
  8322. return T::getDescription();
  8323. }
  8324. };
  8325. public:
  8326. LegacyReporterRegistrar( std::string const& name ) {
  8327. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8328. }
  8329. };
  8330. template<typename T>
  8331. class ReporterRegistrar {
  8332. class ReporterFactory : public SharedImpl<IReporterFactory> {
  8333. // *** Please Note ***:
  8334. // - If you end up here looking at a compiler error because it's trying to register
  8335. // your custom reporter class be aware that the native reporter interface has changed
  8336. // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
  8337. // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
  8338. // However please consider updating to the new interface as the old one is now
  8339. // deprecated and will probably be removed quite soon!
  8340. // Please contact me via github if you have any questions at all about this.
  8341. // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
  8342. // no idea who is actually using custom reporters at all (possibly no-one!).
  8343. // The new interface is designed to minimise exposure to interface changes in the future.
  8344. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8345. return new T( config );
  8346. }
  8347. virtual std::string getDescription() const {
  8348. return T::getDescription();
  8349. }
  8350. };
  8351. public:
  8352. ReporterRegistrar( std::string const& name ) {
  8353. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8354. }
  8355. };
  8356. template<typename T>
  8357. class ListenerRegistrar {
  8358. class ListenerFactory : public SharedImpl<IReporterFactory> {
  8359. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8360. return new T( config );
  8361. }
  8362. virtual std::string getDescription() const {
  8363. return std::string();
  8364. }
  8365. };
  8366. public:
  8367. ListenerRegistrar() {
  8368. getMutableRegistryHub().registerListener( new ListenerFactory() );
  8369. }
  8370. };
  8371. }
  8372. #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
  8373. namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8374. #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
  8375. namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8376. // Deprecated - use the form without INTERNAL_
  8377. #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
  8378. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8379. #define CATCH_REGISTER_LISTENER( listenerType ) \
  8380. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8381. // #included from: ../internal/catch_xmlwriter.hpp
  8382. #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
  8383. #include <sstream>
  8384. #include <string>
  8385. #include <vector>
  8386. #include <iomanip>
  8387. namespace Catch {
  8388. class XmlEncode {
  8389. public:
  8390. enum ForWhat { ForTextNodes, ForAttributes };
  8391. XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
  8392. : m_str( str ),
  8393. m_forWhat( forWhat )
  8394. {}
  8395. void encodeTo( std::ostream& os ) const {
  8396. // Apostrophe escaping not necessary if we always use " to write attributes
  8397. // (see: http://www.w3.org/TR/xml/#syntax)
  8398. for( std::size_t i = 0; i < m_str.size(); ++ i ) {
  8399. char c = m_str[i];
  8400. switch( c ) {
  8401. case '<': os << "&lt;"; break;
  8402. case '&': os << "&amp;"; break;
  8403. case '>':
  8404. // See: http://www.w3.org/TR/xml/#syntax
  8405. if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
  8406. os << "&gt;";
  8407. else
  8408. os << c;
  8409. break;
  8410. case '\"':
  8411. if( m_forWhat == ForAttributes )
  8412. os << "&quot;";
  8413. else
  8414. os << c;
  8415. break;
  8416. default:
  8417. // Escape control chars - based on contribution by @espenalb in PR #465 and
  8418. // by @mrpi PR #588
  8419. if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) {
  8420. // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
  8421. os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
  8422. << static_cast<int>( c );
  8423. }
  8424. else
  8425. os << c;
  8426. }
  8427. }
  8428. }
  8429. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
  8430. xmlEncode.encodeTo( os );
  8431. return os;
  8432. }
  8433. private:
  8434. std::string m_str;
  8435. ForWhat m_forWhat;
  8436. };
  8437. class XmlWriter {
  8438. public:
  8439. class ScopedElement {
  8440. public:
  8441. ScopedElement( XmlWriter* writer )
  8442. : m_writer( writer )
  8443. {}
  8444. ScopedElement( ScopedElement const& other )
  8445. : m_writer( other.m_writer ){
  8446. other.m_writer = CATCH_NULL;
  8447. }
  8448. ~ScopedElement() {
  8449. if( m_writer )
  8450. m_writer->endElement();
  8451. }
  8452. ScopedElement& writeText( std::string const& text, bool indent = true ) {
  8453. m_writer->writeText( text, indent );
  8454. return *this;
  8455. }
  8456. template<typename T>
  8457. ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
  8458. m_writer->writeAttribute( name, attribute );
  8459. return *this;
  8460. }
  8461. private:
  8462. mutable XmlWriter* m_writer;
  8463. };
  8464. XmlWriter()
  8465. : m_tagIsOpen( false ),
  8466. m_needsNewline( false ),
  8467. m_os( Catch::cout() )
  8468. {
  8469. writeDeclaration();
  8470. }
  8471. XmlWriter( std::ostream& os )
  8472. : m_tagIsOpen( false ),
  8473. m_needsNewline( false ),
  8474. m_os( os )
  8475. {
  8476. writeDeclaration();
  8477. }
  8478. ~XmlWriter() {
  8479. while( !m_tags.empty() )
  8480. endElement();
  8481. }
  8482. XmlWriter& startElement( std::string const& name ) {
  8483. ensureTagClosed();
  8484. newlineIfNecessary();
  8485. m_os << m_indent << '<' << name;
  8486. m_tags.push_back( name );
  8487. m_indent += " ";
  8488. m_tagIsOpen = true;
  8489. return *this;
  8490. }
  8491. ScopedElement scopedElement( std::string const& name ) {
  8492. ScopedElement scoped( this );
  8493. startElement( name );
  8494. return scoped;
  8495. }
  8496. XmlWriter& endElement() {
  8497. newlineIfNecessary();
  8498. m_indent = m_indent.substr( 0, m_indent.size()-2 );
  8499. if( m_tagIsOpen ) {
  8500. m_os << "/>";
  8501. m_tagIsOpen = false;
  8502. }
  8503. else {
  8504. m_os << m_indent << "</" << m_tags.back() << ">";
  8505. }
  8506. m_os << std::endl;
  8507. m_tags.pop_back();
  8508. return *this;
  8509. }
  8510. XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
  8511. if( !name.empty() && !attribute.empty() )
  8512. m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
  8513. return *this;
  8514. }
  8515. XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
  8516. m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
  8517. return *this;
  8518. }
  8519. template<typename T>
  8520. XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
  8521. std::ostringstream oss;
  8522. oss << attribute;
  8523. return writeAttribute( name, oss.str() );
  8524. }
  8525. XmlWriter& writeText( std::string const& text, bool indent = true ) {
  8526. if( !text.empty() ){
  8527. bool tagWasOpen = m_tagIsOpen;
  8528. ensureTagClosed();
  8529. if( tagWasOpen && indent )
  8530. m_os << m_indent;
  8531. m_os << XmlEncode( text );
  8532. m_needsNewline = true;
  8533. }
  8534. return *this;
  8535. }
  8536. XmlWriter& writeComment( std::string const& text ) {
  8537. ensureTagClosed();
  8538. m_os << m_indent << "<!--" << text << "-->";
  8539. m_needsNewline = true;
  8540. return *this;
  8541. }
  8542. void writeStylesheetRef( std::string const& url ) {
  8543. m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
  8544. }
  8545. XmlWriter& writeBlankLine() {
  8546. ensureTagClosed();
  8547. m_os << '\n';
  8548. return *this;
  8549. }
  8550. void ensureTagClosed() {
  8551. if( m_tagIsOpen ) {
  8552. m_os << ">" << std::endl;
  8553. m_tagIsOpen = false;
  8554. }
  8555. }
  8556. private:
  8557. XmlWriter( XmlWriter const& );
  8558. void operator=( XmlWriter const& );
  8559. void writeDeclaration() {
  8560. m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  8561. }
  8562. void newlineIfNecessary() {
  8563. if( m_needsNewline ) {
  8564. m_os << std::endl;
  8565. m_needsNewline = false;
  8566. }
  8567. }
  8568. bool m_tagIsOpen;
  8569. bool m_needsNewline;
  8570. std::vector<std::string> m_tags;
  8571. std::string m_indent;
  8572. std::ostream& m_os;
  8573. };
  8574. }
  8575. namespace Catch {
  8576. class XmlReporter : public StreamingReporterBase {
  8577. public:
  8578. XmlReporter( ReporterConfig const& _config )
  8579. : StreamingReporterBase( _config ),
  8580. m_xml(_config.stream()),
  8581. m_sectionDepth( 0 )
  8582. {
  8583. m_reporterPrefs.shouldRedirectStdOut = true;
  8584. }
  8585. virtual ~XmlReporter() CATCH_OVERRIDE;
  8586. static std::string getDescription() {
  8587. return "Reports test results as an XML document";
  8588. }
  8589. virtual std::string getStylesheetRef() const {
  8590. return std::string();
  8591. }
  8592. void writeSourceInfo( SourceLineInfo const& sourceInfo ) {
  8593. m_xml
  8594. .writeAttribute( "filename", sourceInfo.file )
  8595. .writeAttribute( "line", sourceInfo.line );
  8596. }
  8597. public: // StreamingReporterBase
  8598. virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
  8599. StreamingReporterBase::noMatchingTestCases( s );
  8600. }
  8601. virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
  8602. StreamingReporterBase::testRunStarting( testInfo );
  8603. std::string stylesheetRef = getStylesheetRef();
  8604. if( !stylesheetRef.empty() )
  8605. m_xml.writeStylesheetRef( stylesheetRef );
  8606. m_xml.startElement( "Catch" );
  8607. if( !m_config->name().empty() )
  8608. m_xml.writeAttribute( "name", m_config->name() );
  8609. }
  8610. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8611. StreamingReporterBase::testGroupStarting( groupInfo );
  8612. m_xml.startElement( "Group" )
  8613. .writeAttribute( "name", groupInfo.name );
  8614. }
  8615. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  8616. StreamingReporterBase::testCaseStarting(testInfo);
  8617. m_xml.startElement( "TestCase" )
  8618. .writeAttribute( "name", trim( testInfo.name ) )
  8619. .writeAttribute( "description", testInfo.description )
  8620. .writeAttribute( "tags", testInfo.tagsAsString );
  8621. writeSourceInfo( testInfo.lineInfo );
  8622. if ( m_config->showDurations() == ShowDurations::Always )
  8623. m_testCaseTimer.start();
  8624. m_xml.ensureTagClosed();
  8625. }
  8626. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8627. StreamingReporterBase::sectionStarting( sectionInfo );
  8628. if( m_sectionDepth++ > 0 ) {
  8629. m_xml.startElement( "Section" )
  8630. .writeAttribute( "name", trim( sectionInfo.name ) )
  8631. .writeAttribute( "description", sectionInfo.description );
  8632. writeSourceInfo( sectionInfo.lineInfo );
  8633. m_xml.ensureTagClosed();
  8634. }
  8635. }
  8636. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
  8637. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8638. AssertionResult const& result = assertionStats.assertionResult;
  8639. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8640. if( includeResults || result.getResultType() == ResultWas::Warning ) {
  8641. // Print any info messages in <Info> tags.
  8642. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  8643. it != itEnd;
  8644. ++it ) {
  8645. if( it->type == ResultWas::Info && includeResults ) {
  8646. m_xml.scopedElement( "Info" )
  8647. .writeText( it->message );
  8648. } else if ( it->type == ResultWas::Warning ) {
  8649. m_xml.scopedElement( "Warning" )
  8650. .writeText( it->message );
  8651. }
  8652. }
  8653. }
  8654. // Drop out if result was successful but we're not printing them.
  8655. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8656. return true;
  8657. // Print the expression if there is one.
  8658. if( result.hasExpression() ) {
  8659. m_xml.startElement( "Expression" )
  8660. .writeAttribute( "success", result.succeeded() )
  8661. .writeAttribute( "type", result.getTestMacroName() );
  8662. writeSourceInfo( result.getSourceInfo() );
  8663. m_xml.scopedElement( "Original" )
  8664. .writeText( result.getExpression() );
  8665. m_xml.scopedElement( "Expanded" )
  8666. .writeText( result.getExpandedExpression() );
  8667. }
  8668. // And... Print a result applicable to each result type.
  8669. switch( result.getResultType() ) {
  8670. case ResultWas::ThrewException:
  8671. m_xml.startElement( "Exception" );
  8672. writeSourceInfo( result.getSourceInfo() );
  8673. m_xml.writeText( result.getMessage() );
  8674. m_xml.endElement();
  8675. break;
  8676. case ResultWas::FatalErrorCondition:
  8677. m_xml.startElement( "FatalErrorCondition" );
  8678. writeSourceInfo( result.getSourceInfo() );
  8679. m_xml.writeText( result.getMessage() );
  8680. m_xml.endElement();
  8681. break;
  8682. case ResultWas::Info:
  8683. m_xml.scopedElement( "Info" )
  8684. .writeText( result.getMessage() );
  8685. break;
  8686. case ResultWas::Warning:
  8687. // Warning will already have been written
  8688. break;
  8689. case ResultWas::ExplicitFailure:
  8690. m_xml.startElement( "Failure" );
  8691. writeSourceInfo( result.getSourceInfo() );
  8692. m_xml.writeText( result.getMessage() );
  8693. m_xml.endElement();
  8694. break;
  8695. default:
  8696. break;
  8697. }
  8698. if( result.hasExpression() )
  8699. m_xml.endElement();
  8700. return true;
  8701. }
  8702. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8703. StreamingReporterBase::sectionEnded( sectionStats );
  8704. if( --m_sectionDepth > 0 ) {
  8705. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
  8706. e.writeAttribute( "successes", sectionStats.assertions.passed );
  8707. e.writeAttribute( "failures", sectionStats.assertions.failed );
  8708. e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
  8709. if ( m_config->showDurations() == ShowDurations::Always )
  8710. e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
  8711. m_xml.endElement();
  8712. }
  8713. }
  8714. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8715. StreamingReporterBase::testCaseEnded( testCaseStats );
  8716. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
  8717. e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
  8718. if ( m_config->showDurations() == ShowDurations::Always )
  8719. e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
  8720. if( !testCaseStats.stdOut.empty() )
  8721. m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false );
  8722. if( !testCaseStats.stdErr.empty() )
  8723. m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false );
  8724. m_xml.endElement();
  8725. }
  8726. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8727. StreamingReporterBase::testGroupEnded( testGroupStats );
  8728. // TODO: Check testGroupStats.aborting and act accordingly.
  8729. m_xml.scopedElement( "OverallResults" )
  8730. .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
  8731. .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
  8732. .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
  8733. m_xml.endElement();
  8734. }
  8735. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8736. StreamingReporterBase::testRunEnded( testRunStats );
  8737. m_xml.scopedElement( "OverallResults" )
  8738. .writeAttribute( "successes", testRunStats.totals.assertions.passed )
  8739. .writeAttribute( "failures", testRunStats.totals.assertions.failed )
  8740. .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
  8741. m_xml.endElement();
  8742. }
  8743. private:
  8744. Timer m_testCaseTimer;
  8745. XmlWriter m_xml;
  8746. int m_sectionDepth;
  8747. };
  8748. INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
  8749. } // end namespace Catch
  8750. // #included from: ../reporters/catch_reporter_junit.hpp
  8751. #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
  8752. #include <assert.h>
  8753. namespace Catch {
  8754. namespace {
  8755. std::string getCurrentTimestamp() {
  8756. // Beware, this is not reentrant because of backward compatibility issues
  8757. // Also, UTC only, again because of backward compatibility (%z is C++11)
  8758. time_t rawtime;
  8759. std::time(&rawtime);
  8760. const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z");
  8761. #ifdef _MSC_VER
  8762. std::tm timeInfo = {};
  8763. gmtime_s(&timeInfo, &rawtime);
  8764. #else
  8765. std::tm* timeInfo;
  8766. timeInfo = std::gmtime(&rawtime);
  8767. #endif
  8768. char timeStamp[timeStampSize];
  8769. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  8770. #ifdef _MSC_VER
  8771. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  8772. #else
  8773. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  8774. #endif
  8775. return std::string(timeStamp);
  8776. }
  8777. }
  8778. class JunitReporter : public CumulativeReporterBase {
  8779. public:
  8780. JunitReporter( ReporterConfig const& _config )
  8781. : CumulativeReporterBase( _config ),
  8782. xml( _config.stream() ),
  8783. unexpectedExceptions( 0 ),
  8784. m_okToFail( false )
  8785. {
  8786. m_reporterPrefs.shouldRedirectStdOut = true;
  8787. }
  8788. virtual ~JunitReporter() CATCH_OVERRIDE;
  8789. static std::string getDescription() {
  8790. return "Reports test results in an XML format that looks like Ant's junitreport target";
  8791. }
  8792. virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
  8793. virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
  8794. CumulativeReporterBase::testRunStarting( runInfo );
  8795. xml.startElement( "testsuites" );
  8796. }
  8797. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8798. suiteTimer.start();
  8799. stdOutForSuite.str("");
  8800. stdErrForSuite.str("");
  8801. unexpectedExceptions = 0;
  8802. CumulativeReporterBase::testGroupStarting( groupInfo );
  8803. }
  8804. virtual void testCaseStarting( TestCaseInfo const& testCaseInfo ) CATCH_OVERRIDE {
  8805. m_okToFail = testCaseInfo.okToFail();
  8806. }
  8807. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8808. if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail )
  8809. unexpectedExceptions++;
  8810. return CumulativeReporterBase::assertionEnded( assertionStats );
  8811. }
  8812. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8813. stdOutForSuite << testCaseStats.stdOut;
  8814. stdErrForSuite << testCaseStats.stdErr;
  8815. CumulativeReporterBase::testCaseEnded( testCaseStats );
  8816. }
  8817. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8818. double suiteTime = suiteTimer.getElapsedSeconds();
  8819. CumulativeReporterBase::testGroupEnded( testGroupStats );
  8820. writeGroup( *m_testGroups.back(), suiteTime );
  8821. }
  8822. virtual void testRunEndedCumulative() CATCH_OVERRIDE {
  8823. xml.endElement();
  8824. }
  8825. void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
  8826. XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
  8827. TestGroupStats const& stats = groupNode.value;
  8828. xml.writeAttribute( "name", stats.groupInfo.name );
  8829. xml.writeAttribute( "errors", unexpectedExceptions );
  8830. xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
  8831. xml.writeAttribute( "tests", stats.totals.assertions.total() );
  8832. xml.writeAttribute( "hostname", "tbd" ); // !TBD
  8833. if( m_config->showDurations() == ShowDurations::Never )
  8834. xml.writeAttribute( "time", "" );
  8835. else
  8836. xml.writeAttribute( "time", suiteTime );
  8837. xml.writeAttribute( "timestamp", getCurrentTimestamp() );
  8838. // Write test cases
  8839. for( TestGroupNode::ChildNodes::const_iterator
  8840. it = groupNode.children.begin(), itEnd = groupNode.children.end();
  8841. it != itEnd;
  8842. ++it )
  8843. writeTestCase( **it );
  8844. xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
  8845. xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
  8846. }
  8847. void writeTestCase( TestCaseNode const& testCaseNode ) {
  8848. TestCaseStats const& stats = testCaseNode.value;
  8849. // All test cases have exactly one section - which represents the
  8850. // test case itself. That section may have 0-n nested sections
  8851. assert( testCaseNode.children.size() == 1 );
  8852. SectionNode const& rootSection = *testCaseNode.children.front();
  8853. std::string className = stats.testInfo.className;
  8854. if( className.empty() ) {
  8855. if( rootSection.childSections.empty() )
  8856. className = "global";
  8857. }
  8858. writeSection( className, "", rootSection );
  8859. }
  8860. void writeSection( std::string const& className,
  8861. std::string const& rootName,
  8862. SectionNode const& sectionNode ) {
  8863. std::string name = trim( sectionNode.stats.sectionInfo.name );
  8864. if( !rootName.empty() )
  8865. name = rootName + '/' + name;
  8866. if( !sectionNode.assertions.empty() ||
  8867. !sectionNode.stdOut.empty() ||
  8868. !sectionNode.stdErr.empty() ) {
  8869. XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
  8870. if( className.empty() ) {
  8871. xml.writeAttribute( "classname", name );
  8872. xml.writeAttribute( "name", "root" );
  8873. }
  8874. else {
  8875. xml.writeAttribute( "classname", className );
  8876. xml.writeAttribute( "name", name );
  8877. }
  8878. xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
  8879. writeAssertions( sectionNode );
  8880. if( !sectionNode.stdOut.empty() )
  8881. xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
  8882. if( !sectionNode.stdErr.empty() )
  8883. xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
  8884. }
  8885. for( SectionNode::ChildSections::const_iterator
  8886. it = sectionNode.childSections.begin(),
  8887. itEnd = sectionNode.childSections.end();
  8888. it != itEnd;
  8889. ++it )
  8890. if( className.empty() )
  8891. writeSection( name, "", **it );
  8892. else
  8893. writeSection( className, name, **it );
  8894. }
  8895. void writeAssertions( SectionNode const& sectionNode ) {
  8896. for( SectionNode::Assertions::const_iterator
  8897. it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
  8898. it != itEnd;
  8899. ++it )
  8900. writeAssertion( *it );
  8901. }
  8902. void writeAssertion( AssertionStats const& stats ) {
  8903. AssertionResult const& result = stats.assertionResult;
  8904. if( !result.isOk() ) {
  8905. std::string elementName;
  8906. switch( result.getResultType() ) {
  8907. case ResultWas::ThrewException:
  8908. case ResultWas::FatalErrorCondition:
  8909. elementName = "error";
  8910. break;
  8911. case ResultWas::ExplicitFailure:
  8912. elementName = "failure";
  8913. break;
  8914. case ResultWas::ExpressionFailed:
  8915. elementName = "failure";
  8916. break;
  8917. case ResultWas::DidntThrowException:
  8918. elementName = "failure";
  8919. break;
  8920. // We should never see these here:
  8921. case ResultWas::Info:
  8922. case ResultWas::Warning:
  8923. case ResultWas::Ok:
  8924. case ResultWas::Unknown:
  8925. case ResultWas::FailureBit:
  8926. case ResultWas::Exception:
  8927. elementName = "internalError";
  8928. break;
  8929. }
  8930. XmlWriter::ScopedElement e = xml.scopedElement( elementName );
  8931. xml.writeAttribute( "message", result.getExpandedExpression() );
  8932. xml.writeAttribute( "type", result.getTestMacroName() );
  8933. std::ostringstream oss;
  8934. if( !result.getMessage().empty() )
  8935. oss << result.getMessage() << '\n';
  8936. for( std::vector<MessageInfo>::const_iterator
  8937. it = stats.infoMessages.begin(),
  8938. itEnd = stats.infoMessages.end();
  8939. it != itEnd;
  8940. ++it )
  8941. if( it->type == ResultWas::Info )
  8942. oss << it->message << '\n';
  8943. oss << "at " << result.getSourceInfo();
  8944. xml.writeText( oss.str(), false );
  8945. }
  8946. }
  8947. XmlWriter xml;
  8948. Timer suiteTimer;
  8949. std::ostringstream stdOutForSuite;
  8950. std::ostringstream stdErrForSuite;
  8951. unsigned int unexpectedExceptions;
  8952. bool m_okToFail;
  8953. };
  8954. INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
  8955. } // end namespace Catch
  8956. // #included from: ../reporters/catch_reporter_console.hpp
  8957. #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8958. #include <cassert>
  8959. #include <cfloat>
  8960. #include <cstdio>
  8961. namespace Catch {
  8962. struct ConsoleReporter : StreamingReporterBase {
  8963. ConsoleReporter( ReporterConfig const& _config )
  8964. : StreamingReporterBase( _config ),
  8965. m_headerPrinted( false )
  8966. {}
  8967. virtual ~ConsoleReporter() CATCH_OVERRIDE;
  8968. static std::string getDescription() {
  8969. return "Reports test results as plain lines of text";
  8970. }
  8971. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  8972. stream << "No test cases matched '" << spec << '\'' << std::endl;
  8973. }
  8974. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
  8975. }
  8976. virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
  8977. AssertionResult const& result = _assertionStats.assertionResult;
  8978. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8979. // Drop out if result was successful but we're not printing them.
  8980. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8981. return false;
  8982. lazyPrint();
  8983. AssertionPrinter printer( stream, _assertionStats, includeResults );
  8984. printer.print();
  8985. stream << std::endl;
  8986. return true;
  8987. }
  8988. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8989. m_headerPrinted = false;
  8990. StreamingReporterBase::sectionStarting( _sectionInfo );
  8991. }
  8992. virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
  8993. if( _sectionStats.missingAssertions ) {
  8994. lazyPrint();
  8995. Colour colour( Colour::ResultError );
  8996. if( m_sectionStack.size() > 1 )
  8997. stream << "\nNo assertions in section";
  8998. else
  8999. stream << "\nNo assertions in test case";
  9000. stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
  9001. }
  9002. if( m_config->showDurations() == ShowDurations::Always ) {
  9003. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  9004. }
  9005. if( m_headerPrinted ) {
  9006. m_headerPrinted = false;
  9007. }
  9008. StreamingReporterBase::sectionEnded( _sectionStats );
  9009. }
  9010. virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
  9011. StreamingReporterBase::testCaseEnded( _testCaseStats );
  9012. m_headerPrinted = false;
  9013. }
  9014. virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
  9015. if( currentGroupInfo.used ) {
  9016. printSummaryDivider();
  9017. stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
  9018. printTotals( _testGroupStats.totals );
  9019. stream << '\n' << std::endl;
  9020. }
  9021. StreamingReporterBase::testGroupEnded( _testGroupStats );
  9022. }
  9023. virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
  9024. printTotalsDivider( _testRunStats.totals );
  9025. printTotals( _testRunStats.totals );
  9026. stream << std::endl;
  9027. StreamingReporterBase::testRunEnded( _testRunStats );
  9028. }
  9029. private:
  9030. class AssertionPrinter {
  9031. void operator= ( AssertionPrinter const& );
  9032. public:
  9033. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  9034. : stream( _stream ),
  9035. stats( _stats ),
  9036. result( _stats.assertionResult ),
  9037. colour( Colour::None ),
  9038. message( result.getMessage() ),
  9039. messages( _stats.infoMessages ),
  9040. printInfoMessages( _printInfoMessages )
  9041. {
  9042. switch( result.getResultType() ) {
  9043. case ResultWas::Ok:
  9044. colour = Colour::Success;
  9045. passOrFail = "PASSED";
  9046. //if( result.hasMessage() )
  9047. if( _stats.infoMessages.size() == 1 )
  9048. messageLabel = "with message";
  9049. if( _stats.infoMessages.size() > 1 )
  9050. messageLabel = "with messages";
  9051. break;
  9052. case ResultWas::ExpressionFailed:
  9053. if( result.isOk() ) {
  9054. colour = Colour::Success;
  9055. passOrFail = "FAILED - but was ok";
  9056. }
  9057. else {
  9058. colour = Colour::Error;
  9059. passOrFail = "FAILED";
  9060. }
  9061. if( _stats.infoMessages.size() == 1 )
  9062. messageLabel = "with message";
  9063. if( _stats.infoMessages.size() > 1 )
  9064. messageLabel = "with messages";
  9065. break;
  9066. case ResultWas::ThrewException:
  9067. colour = Colour::Error;
  9068. passOrFail = "FAILED";
  9069. messageLabel = "due to unexpected exception with ";
  9070. if (_stats.infoMessages.size() == 1)
  9071. messageLabel += "message";
  9072. if (_stats.infoMessages.size() > 1)
  9073. messageLabel += "messages";
  9074. break;
  9075. case ResultWas::FatalErrorCondition:
  9076. colour = Colour::Error;
  9077. passOrFail = "FAILED";
  9078. messageLabel = "due to a fatal error condition";
  9079. break;
  9080. case ResultWas::DidntThrowException:
  9081. colour = Colour::Error;
  9082. passOrFail = "FAILED";
  9083. messageLabel = "because no exception was thrown where one was expected";
  9084. break;
  9085. case ResultWas::Info:
  9086. messageLabel = "info";
  9087. break;
  9088. case ResultWas::Warning:
  9089. messageLabel = "warning";
  9090. break;
  9091. case ResultWas::ExplicitFailure:
  9092. passOrFail = "FAILED";
  9093. colour = Colour::Error;
  9094. if( _stats.infoMessages.size() == 1 )
  9095. messageLabel = "explicitly with message";
  9096. if( _stats.infoMessages.size() > 1 )
  9097. messageLabel = "explicitly with messages";
  9098. break;
  9099. // These cases are here to prevent compiler warnings
  9100. case ResultWas::Unknown:
  9101. case ResultWas::FailureBit:
  9102. case ResultWas::Exception:
  9103. passOrFail = "** internal error **";
  9104. colour = Colour::Error;
  9105. break;
  9106. }
  9107. }
  9108. void print() const {
  9109. printSourceInfo();
  9110. if( stats.totals.assertions.total() > 0 ) {
  9111. if( result.isOk() )
  9112. stream << '\n';
  9113. printResultType();
  9114. printOriginalExpression();
  9115. printReconstructedExpression();
  9116. }
  9117. else {
  9118. stream << '\n';
  9119. }
  9120. printMessage();
  9121. }
  9122. private:
  9123. void printResultType() const {
  9124. if( !passOrFail.empty() ) {
  9125. Colour colourGuard( colour );
  9126. stream << passOrFail << ":\n";
  9127. }
  9128. }
  9129. void printOriginalExpression() const {
  9130. if( result.hasExpression() ) {
  9131. Colour colourGuard( Colour::OriginalExpression );
  9132. stream << " ";
  9133. stream << result.getExpressionInMacro();
  9134. stream << '\n';
  9135. }
  9136. }
  9137. void printReconstructedExpression() const {
  9138. if( result.hasExpandedExpression() ) {
  9139. stream << "with expansion:\n";
  9140. Colour colourGuard( Colour::ReconstructedExpression );
  9141. stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n';
  9142. }
  9143. }
  9144. void printMessage() const {
  9145. if( !messageLabel.empty() )
  9146. stream << messageLabel << ':' << '\n';
  9147. for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
  9148. it != itEnd;
  9149. ++it ) {
  9150. // If this assertion is a warning ignore any INFO messages
  9151. if( printInfoMessages || it->type != ResultWas::Info )
  9152. stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
  9153. }
  9154. }
  9155. void printSourceInfo() const {
  9156. Colour colourGuard( Colour::FileName );
  9157. stream << result.getSourceInfo() << ": ";
  9158. }
  9159. std::ostream& stream;
  9160. AssertionStats const& stats;
  9161. AssertionResult const& result;
  9162. Colour::Code colour;
  9163. std::string passOrFail;
  9164. std::string messageLabel;
  9165. std::string message;
  9166. std::vector<MessageInfo> messages;
  9167. bool printInfoMessages;
  9168. };
  9169. void lazyPrint() {
  9170. if( !currentTestRunInfo.used )
  9171. lazyPrintRunInfo();
  9172. if( !currentGroupInfo.used )
  9173. lazyPrintGroupInfo();
  9174. if( !m_headerPrinted ) {
  9175. printTestCaseAndSectionHeader();
  9176. m_headerPrinted = true;
  9177. }
  9178. }
  9179. void lazyPrintRunInfo() {
  9180. stream << '\n' << getLineOfChars<'~'>() << '\n';
  9181. Colour colour( Colour::SecondaryText );
  9182. stream << currentTestRunInfo->name
  9183. << " is a Catch v" << libraryVersion() << " host application.\n"
  9184. << "Run with -? for options\n\n";
  9185. if( m_config->rngSeed() != 0 )
  9186. stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
  9187. currentTestRunInfo.used = true;
  9188. }
  9189. void lazyPrintGroupInfo() {
  9190. if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
  9191. printClosedHeader( "Group: " + currentGroupInfo->name );
  9192. currentGroupInfo.used = true;
  9193. }
  9194. }
  9195. void printTestCaseAndSectionHeader() {
  9196. assert( !m_sectionStack.empty() );
  9197. printOpenHeader( currentTestCaseInfo->name );
  9198. if( m_sectionStack.size() > 1 ) {
  9199. Colour colourGuard( Colour::Headers );
  9200. std::vector<SectionInfo>::const_iterator
  9201. it = m_sectionStack.begin()+1, // Skip first section (test case)
  9202. itEnd = m_sectionStack.end();
  9203. for( ; it != itEnd; ++it )
  9204. printHeaderString( it->name, 2 );
  9205. }
  9206. SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
  9207. if( !lineInfo.empty() ){
  9208. stream << getLineOfChars<'-'>() << '\n';
  9209. Colour colourGuard( Colour::FileName );
  9210. stream << lineInfo << '\n';
  9211. }
  9212. stream << getLineOfChars<'.'>() << '\n' << std::endl;
  9213. }
  9214. void printClosedHeader( std::string const& _name ) {
  9215. printOpenHeader( _name );
  9216. stream << getLineOfChars<'.'>() << '\n';
  9217. }
  9218. void printOpenHeader( std::string const& _name ) {
  9219. stream << getLineOfChars<'-'>() << '\n';
  9220. {
  9221. Colour colourGuard( Colour::Headers );
  9222. printHeaderString( _name );
  9223. }
  9224. }
  9225. // if string has a : in first line will set indent to follow it on
  9226. // subsequent lines
  9227. void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
  9228. std::size_t i = _string.find( ": " );
  9229. if( i != std::string::npos )
  9230. i+=2;
  9231. else
  9232. i = 0;
  9233. stream << Text( _string, TextAttributes()
  9234. .setIndent( indent+i)
  9235. .setInitialIndent( indent ) ) << '\n';
  9236. }
  9237. struct SummaryColumn {
  9238. SummaryColumn( std::string const& _label, Colour::Code _colour )
  9239. : label( _label ),
  9240. colour( _colour )
  9241. {}
  9242. SummaryColumn addRow( std::size_t count ) {
  9243. std::ostringstream oss;
  9244. oss << count;
  9245. std::string row = oss.str();
  9246. for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
  9247. while( it->size() < row.size() )
  9248. *it = ' ' + *it;
  9249. while( it->size() > row.size() )
  9250. row = ' ' + row;
  9251. }
  9252. rows.push_back( row );
  9253. return *this;
  9254. }
  9255. std::string label;
  9256. Colour::Code colour;
  9257. std::vector<std::string> rows;
  9258. };
  9259. void printTotals( Totals const& totals ) {
  9260. if( totals.testCases.total() == 0 ) {
  9261. stream << Colour( Colour::Warning ) << "No tests ran\n";
  9262. }
  9263. else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
  9264. stream << Colour( Colour::ResultSuccess ) << "All tests passed";
  9265. stream << " ("
  9266. << pluralise( totals.assertions.passed, "assertion" ) << " in "
  9267. << pluralise( totals.testCases.passed, "test case" ) << ')'
  9268. << '\n';
  9269. }
  9270. else {
  9271. std::vector<SummaryColumn> columns;
  9272. columns.push_back( SummaryColumn( "", Colour::None )
  9273. .addRow( totals.testCases.total() )
  9274. .addRow( totals.assertions.total() ) );
  9275. columns.push_back( SummaryColumn( "passed", Colour::Success )
  9276. .addRow( totals.testCases.passed )
  9277. .addRow( totals.assertions.passed ) );
  9278. columns.push_back( SummaryColumn( "failed", Colour::ResultError )
  9279. .addRow( totals.testCases.failed )
  9280. .addRow( totals.assertions.failed ) );
  9281. columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
  9282. .addRow( totals.testCases.failedButOk )
  9283. .addRow( totals.assertions.failedButOk ) );
  9284. printSummaryRow( "test cases", columns, 0 );
  9285. printSummaryRow( "assertions", columns, 1 );
  9286. }
  9287. }
  9288. void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
  9289. for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
  9290. std::string value = it->rows[row];
  9291. if( it->label.empty() ) {
  9292. stream << label << ": ";
  9293. if( value != "0" )
  9294. stream << value;
  9295. else
  9296. stream << Colour( Colour::Warning ) << "- none -";
  9297. }
  9298. else if( value != "0" ) {
  9299. stream << Colour( Colour::LightGrey ) << " | ";
  9300. stream << Colour( it->colour )
  9301. << value << ' ' << it->label;
  9302. }
  9303. }
  9304. stream << '\n';
  9305. }
  9306. static std::size_t makeRatio( std::size_t number, std::size_t total ) {
  9307. std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
  9308. return ( ratio == 0 && number > 0 ) ? 1 : ratio;
  9309. }
  9310. static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
  9311. if( i > j && i > k )
  9312. return i;
  9313. else if( j > k )
  9314. return j;
  9315. else
  9316. return k;
  9317. }
  9318. void printTotalsDivider( Totals const& totals ) {
  9319. if( totals.testCases.total() > 0 ) {
  9320. std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
  9321. std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
  9322. std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
  9323. while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9324. findMax( failedRatio, failedButOkRatio, passedRatio )++;
  9325. while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9326. findMax( failedRatio, failedButOkRatio, passedRatio )--;
  9327. stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
  9328. stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
  9329. if( totals.testCases.allPassed() )
  9330. stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
  9331. else
  9332. stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
  9333. }
  9334. else {
  9335. stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
  9336. }
  9337. stream << '\n';
  9338. }
  9339. void printSummaryDivider() {
  9340. stream << getLineOfChars<'-'>() << '\n';
  9341. }
  9342. private:
  9343. bool m_headerPrinted;
  9344. };
  9345. INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
  9346. } // end namespace Catch
  9347. // #included from: ../reporters/catch_reporter_compact.hpp
  9348. #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
  9349. namespace Catch {
  9350. struct CompactReporter : StreamingReporterBase {
  9351. CompactReporter( ReporterConfig const& _config )
  9352. : StreamingReporterBase( _config )
  9353. {}
  9354. virtual ~CompactReporter();
  9355. static std::string getDescription() {
  9356. return "Reports test results on a single line, suitable for IDEs";
  9357. }
  9358. virtual ReporterPreferences getPreferences() const {
  9359. ReporterPreferences prefs;
  9360. prefs.shouldRedirectStdOut = false;
  9361. return prefs;
  9362. }
  9363. virtual void noMatchingTestCases( std::string const& spec ) {
  9364. stream << "No test cases matched '" << spec << '\'' << std::endl;
  9365. }
  9366. virtual void assertionStarting( AssertionInfo const& ) {}
  9367. virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
  9368. AssertionResult const& result = _assertionStats.assertionResult;
  9369. bool printInfoMessages = true;
  9370. // Drop out if result was successful and we're not printing those
  9371. if( !m_config->includeSuccessfulResults() && result.isOk() ) {
  9372. if( result.getResultType() != ResultWas::Warning )
  9373. return false;
  9374. printInfoMessages = false;
  9375. }
  9376. AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
  9377. printer.print();
  9378. stream << std::endl;
  9379. return true;
  9380. }
  9381. virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE {
  9382. if (m_config->showDurations() == ShowDurations::Always) {
  9383. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  9384. }
  9385. }
  9386. virtual void testRunEnded( TestRunStats const& _testRunStats ) {
  9387. printTotals( _testRunStats.totals );
  9388. stream << '\n' << std::endl;
  9389. StreamingReporterBase::testRunEnded( _testRunStats );
  9390. }
  9391. private:
  9392. class AssertionPrinter {
  9393. void operator= ( AssertionPrinter const& );
  9394. public:
  9395. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  9396. : stream( _stream )
  9397. , stats( _stats )
  9398. , result( _stats.assertionResult )
  9399. , messages( _stats.infoMessages )
  9400. , itMessage( _stats.infoMessages.begin() )
  9401. , printInfoMessages( _printInfoMessages )
  9402. {}
  9403. void print() {
  9404. printSourceInfo();
  9405. itMessage = messages.begin();
  9406. switch( result.getResultType() ) {
  9407. case ResultWas::Ok:
  9408. printResultType( Colour::ResultSuccess, passedString() );
  9409. printOriginalExpression();
  9410. printReconstructedExpression();
  9411. if ( ! result.hasExpression() )
  9412. printRemainingMessages( Colour::None );
  9413. else
  9414. printRemainingMessages();
  9415. break;
  9416. case ResultWas::ExpressionFailed:
  9417. if( result.isOk() )
  9418. printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
  9419. else
  9420. printResultType( Colour::Error, failedString() );
  9421. printOriginalExpression();
  9422. printReconstructedExpression();
  9423. printRemainingMessages();
  9424. break;
  9425. case ResultWas::ThrewException:
  9426. printResultType( Colour::Error, failedString() );
  9427. printIssue( "unexpected exception with message:" );
  9428. printMessage();
  9429. printExpressionWas();
  9430. printRemainingMessages();
  9431. break;
  9432. case ResultWas::FatalErrorCondition:
  9433. printResultType( Colour::Error, failedString() );
  9434. printIssue( "fatal error condition with message:" );
  9435. printMessage();
  9436. printExpressionWas();
  9437. printRemainingMessages();
  9438. break;
  9439. case ResultWas::DidntThrowException:
  9440. printResultType( Colour::Error, failedString() );
  9441. printIssue( "expected exception, got none" );
  9442. printExpressionWas();
  9443. printRemainingMessages();
  9444. break;
  9445. case ResultWas::Info:
  9446. printResultType( Colour::None, "info" );
  9447. printMessage();
  9448. printRemainingMessages();
  9449. break;
  9450. case ResultWas::Warning:
  9451. printResultType( Colour::None, "warning" );
  9452. printMessage();
  9453. printRemainingMessages();
  9454. break;
  9455. case ResultWas::ExplicitFailure:
  9456. printResultType( Colour::Error, failedString() );
  9457. printIssue( "explicitly" );
  9458. printRemainingMessages( Colour::None );
  9459. break;
  9460. // These cases are here to prevent compiler warnings
  9461. case ResultWas::Unknown:
  9462. case ResultWas::FailureBit:
  9463. case ResultWas::Exception:
  9464. printResultType( Colour::Error, "** internal error **" );
  9465. break;
  9466. }
  9467. }
  9468. private:
  9469. // Colour::LightGrey
  9470. static Colour::Code dimColour() { return Colour::FileName; }
  9471. #ifdef CATCH_PLATFORM_MAC
  9472. static const char* failedString() { return "FAILED"; }
  9473. static const char* passedString() { return "PASSED"; }
  9474. #else
  9475. static const char* failedString() { return "failed"; }
  9476. static const char* passedString() { return "passed"; }
  9477. #endif
  9478. void printSourceInfo() const {
  9479. Colour colourGuard( Colour::FileName );
  9480. stream << result.getSourceInfo() << ':';
  9481. }
  9482. void printResultType( Colour::Code colour, std::string const& passOrFail ) const {
  9483. if( !passOrFail.empty() ) {
  9484. {
  9485. Colour colourGuard( colour );
  9486. stream << ' ' << passOrFail;
  9487. }
  9488. stream << ':';
  9489. }
  9490. }
  9491. void printIssue( std::string const& issue ) const {
  9492. stream << ' ' << issue;
  9493. }
  9494. void printExpressionWas() {
  9495. if( result.hasExpression() ) {
  9496. stream << ';';
  9497. {
  9498. Colour colour( dimColour() );
  9499. stream << " expression was:";
  9500. }
  9501. printOriginalExpression();
  9502. }
  9503. }
  9504. void printOriginalExpression() const {
  9505. if( result.hasExpression() ) {
  9506. stream << ' ' << result.getExpression();
  9507. }
  9508. }
  9509. void printReconstructedExpression() const {
  9510. if( result.hasExpandedExpression() ) {
  9511. {
  9512. Colour colour( dimColour() );
  9513. stream << " for: ";
  9514. }
  9515. stream << result.getExpandedExpression();
  9516. }
  9517. }
  9518. void printMessage() {
  9519. if ( itMessage != messages.end() ) {
  9520. stream << " '" << itMessage->message << '\'';
  9521. ++itMessage;
  9522. }
  9523. }
  9524. void printRemainingMessages( Colour::Code colour = dimColour() ) {
  9525. if ( itMessage == messages.end() )
  9526. return;
  9527. // using messages.end() directly yields compilation error:
  9528. std::vector<MessageInfo>::const_iterator itEnd = messages.end();
  9529. const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
  9530. {
  9531. Colour colourGuard( colour );
  9532. stream << " with " << pluralise( N, "message" ) << ':';
  9533. }
  9534. for(; itMessage != itEnd; ) {
  9535. // If this assertion is a warning ignore any INFO messages
  9536. if( printInfoMessages || itMessage->type != ResultWas::Info ) {
  9537. stream << " '" << itMessage->message << '\'';
  9538. if ( ++itMessage != itEnd ) {
  9539. Colour colourGuard( dimColour() );
  9540. stream << " and";
  9541. }
  9542. }
  9543. }
  9544. }
  9545. private:
  9546. std::ostream& stream;
  9547. AssertionStats const& stats;
  9548. AssertionResult const& result;
  9549. std::vector<MessageInfo> messages;
  9550. std::vector<MessageInfo>::const_iterator itMessage;
  9551. bool printInfoMessages;
  9552. };
  9553. // Colour, message variants:
  9554. // - white: No tests ran.
  9555. // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
  9556. // - white: Passed [both/all] N test cases (no assertions).
  9557. // - red: Failed N tests cases, failed M assertions.
  9558. // - green: Passed [both/all] N tests cases with M assertions.
  9559. std::string bothOrAll( std::size_t count ) const {
  9560. return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
  9561. }
  9562. void printTotals( const Totals& totals ) const {
  9563. if( totals.testCases.total() == 0 ) {
  9564. stream << "No tests ran.";
  9565. }
  9566. else if( totals.testCases.failed == totals.testCases.total() ) {
  9567. Colour colour( Colour::ResultError );
  9568. const std::string qualify_assertions_failed =
  9569. totals.assertions.failed == totals.assertions.total() ?
  9570. bothOrAll( totals.assertions.failed ) : std::string();
  9571. stream <<
  9572. "Failed " << bothOrAll( totals.testCases.failed )
  9573. << pluralise( totals.testCases.failed, "test case" ) << ", "
  9574. "failed " << qualify_assertions_failed <<
  9575. pluralise( totals.assertions.failed, "assertion" ) << '.';
  9576. }
  9577. else if( totals.assertions.total() == 0 ) {
  9578. stream <<
  9579. "Passed " << bothOrAll( totals.testCases.total() )
  9580. << pluralise( totals.testCases.total(), "test case" )
  9581. << " (no assertions).";
  9582. }
  9583. else if( totals.assertions.failed ) {
  9584. Colour colour( Colour::ResultError );
  9585. stream <<
  9586. "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
  9587. "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
  9588. }
  9589. else {
  9590. Colour colour( Colour::ResultSuccess );
  9591. stream <<
  9592. "Passed " << bothOrAll( totals.testCases.passed )
  9593. << pluralise( totals.testCases.passed, "test case" ) <<
  9594. " with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
  9595. }
  9596. }
  9597. };
  9598. INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
  9599. } // end namespace Catch
  9600. namespace Catch {
  9601. // These are all here to avoid warnings about not having any out of line
  9602. // virtual methods
  9603. NonCopyable::~NonCopyable() {}
  9604. IShared::~IShared() {}
  9605. IStream::~IStream() CATCH_NOEXCEPT {}
  9606. FileStream::~FileStream() CATCH_NOEXCEPT {}
  9607. CoutStream::~CoutStream() CATCH_NOEXCEPT {}
  9608. DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
  9609. StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
  9610. IContext::~IContext() {}
  9611. IResultCapture::~IResultCapture() {}
  9612. ITestCase::~ITestCase() {}
  9613. ITestCaseRegistry::~ITestCaseRegistry() {}
  9614. IRegistryHub::~IRegistryHub() {}
  9615. IMutableRegistryHub::~IMutableRegistryHub() {}
  9616. IExceptionTranslator::~IExceptionTranslator() {}
  9617. IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
  9618. IReporter::~IReporter() {}
  9619. IReporterFactory::~IReporterFactory() {}
  9620. IReporterRegistry::~IReporterRegistry() {}
  9621. IStreamingReporter::~IStreamingReporter() {}
  9622. AssertionStats::~AssertionStats() {}
  9623. SectionStats::~SectionStats() {}
  9624. TestCaseStats::~TestCaseStats() {}
  9625. TestGroupStats::~TestGroupStats() {}
  9626. TestRunStats::~TestRunStats() {}
  9627. CumulativeReporterBase::SectionNode::~SectionNode() {}
  9628. CumulativeReporterBase::~CumulativeReporterBase() {}
  9629. StreamingReporterBase::~StreamingReporterBase() {}
  9630. ConsoleReporter::~ConsoleReporter() {}
  9631. CompactReporter::~CompactReporter() {}
  9632. IRunner::~IRunner() {}
  9633. IMutableContext::~IMutableContext() {}
  9634. IConfig::~IConfig() {}
  9635. XmlReporter::~XmlReporter() {}
  9636. JunitReporter::~JunitReporter() {}
  9637. TestRegistry::~TestRegistry() {}
  9638. FreeFunctionTestCase::~FreeFunctionTestCase() {}
  9639. IGeneratorInfo::~IGeneratorInfo() {}
  9640. IGeneratorsForTest::~IGeneratorsForTest() {}
  9641. WildcardPattern::~WildcardPattern() {}
  9642. TestSpec::Pattern::~Pattern() {}
  9643. TestSpec::NamePattern::~NamePattern() {}
  9644. TestSpec::TagPattern::~TagPattern() {}
  9645. TestSpec::ExcludedPattern::~ExcludedPattern() {}
  9646. Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {}
  9647. void Config::dummy() {}
  9648. namespace TestCaseTracking {
  9649. ITracker::~ITracker() {}
  9650. TrackerBase::~TrackerBase() {}
  9651. SectionTracker::~SectionTracker() {}
  9652. IndexTracker::~IndexTracker() {}
  9653. }
  9654. }
  9655. #ifdef __clang__
  9656. #pragma clang diagnostic pop
  9657. #endif
  9658. #endif
  9659. #ifdef CATCH_CONFIG_MAIN
  9660. // #included from: internal/catch_default_main.hpp
  9661. #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
  9662. #ifndef __OBJC__
  9663. #if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
  9664. // Standard C/C++ Win32 Unicode wmain entry point
  9665. extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
  9666. #else
  9667. // Standard C/C++ main entry point
  9668. int main (int argc, char * argv[]) {
  9669. #endif
  9670. int result = Catch::Session().run( argc, argv );
  9671. return ( result < 0xff ? result : 0xff );
  9672. }
  9673. #else // __OBJC__
  9674. // Objective-C entry point
  9675. int main (int argc, char * const argv[]) {
  9676. #if !CATCH_ARC_ENABLED
  9677. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9678. #endif
  9679. Catch::registerTestMethods();
  9680. int result = Catch::Session().run( argc, (char* const*)argv );
  9681. #if !CATCH_ARC_ENABLED
  9682. [pool drain];
  9683. #endif
  9684. return ( result < 0xff ? result : 0xff );
  9685. }
  9686. #endif // __OBJC__
  9687. #endif
  9688. #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
  9689. # undef CLARA_CONFIG_MAIN
  9690. #endif
  9691. //////
  9692. // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
  9693. #ifdef CATCH_CONFIG_PREFIX_ALL
  9694. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9695. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9696. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9697. #else
  9698. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9699. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9700. #endif
  9701. #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9702. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9703. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9704. #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9705. #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9706. #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9707. #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9708. #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9709. #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9710. #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9711. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9712. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9713. #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9714. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9715. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9716. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9717. #else
  9718. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9719. #endif
  9720. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9721. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9722. #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9723. #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9724. #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9725. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9726. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9727. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9728. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9729. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9730. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9731. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9732. #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9733. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9734. #else
  9735. #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9736. #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9737. #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9738. #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
  9739. #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9740. #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9741. #define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9742. #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9743. #endif
  9744. #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9745. #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9746. #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9747. #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9748. // "BDD-style" convenience wrappers
  9749. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9750. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  9751. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9752. #else
  9753. #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
  9754. #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9755. #endif
  9756. #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
  9757. #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
  9758. #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9759. #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
  9760. #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9761. // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
  9762. #else
  9763. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9764. #define REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9765. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9766. #else
  9767. #define REQUIRE( expr ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9768. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9769. #endif
  9770. #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9771. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9772. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9773. #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9774. #define CHECK( expr ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9775. #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9776. #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9777. #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9778. #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9779. #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9780. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9781. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9782. #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9783. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9784. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9785. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9786. #else
  9787. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9788. #endif
  9789. #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9790. #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9791. #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9792. #define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9793. #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9794. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9795. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9796. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9797. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9798. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9799. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9800. #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9801. #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9802. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9803. #else
  9804. #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9805. #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9806. #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9807. #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
  9808. #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9809. #define FAIL( msg ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9810. #define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9811. #define SUCCEED( msg ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9812. #endif
  9813. #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9814. #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9815. #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9816. #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9817. #endif
  9818. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  9819. // "BDD-style" convenience wrappers
  9820. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9821. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  9822. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9823. #else
  9824. #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
  9825. #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9826. #endif
  9827. #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
  9828. #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
  9829. #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
  9830. #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
  9831. #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
  9832. using Catch::Detail::Approx;
  9833. // #included from: internal/catch_reenable_warnings.h
  9834. #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
  9835. #ifdef __clang__
  9836. # ifdef __ICC // icpc defines the __clang__ macro
  9837. # pragma warning(pop)
  9838. # else
  9839. # pragma clang diagnostic pop
  9840. # endif
  9841. #elif defined __GNUC__
  9842. # pragma GCC diagnostic pop
  9843. #endif
  9844. #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED