catch.hpp 417 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697
  1. /*
  2. * Catch v1.12.2
  3. * Generated: 2018-05-14 15:10:01.112442
  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. // NOTE: added backport of fix for macOS on ARM, as per https://github.com/catchorg/Catch2/commit/bb6d08323f23a39eb65dd86671e68f4f5d3f2d6c
  12. // NOTE: SIGSTKSZ is no longer a constant in glibc 2.34; see https://github.com/catchorg/Catch2/issues/2178
  13. #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  14. #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  15. #define TWOBLUECUBES_CATCH_HPP_INCLUDED
  16. #ifdef __clang__
  17. # pragma clang system_header
  18. #elif defined __GNUC__
  19. # pragma GCC system_header
  20. #endif
  21. // #included from: internal/catch_suppress_warnings.h
  22. #ifdef __clang__
  23. # ifdef __ICC // icpc defines the __clang__ macro
  24. # pragma warning(push)
  25. # pragma warning(disable: 161 1682)
  26. # else // __ICC
  27. # pragma clang diagnostic ignored "-Wglobal-constructors"
  28. # pragma clang diagnostic ignored "-Wvariadic-macros"
  29. # pragma clang diagnostic ignored "-Wc99-extensions"
  30. # pragma clang diagnostic ignored "-Wunused-variable"
  31. # pragma clang diagnostic push
  32. # pragma clang diagnostic ignored "-Wpadded"
  33. # pragma clang diagnostic ignored "-Wc++98-compat"
  34. # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
  35. # pragma clang diagnostic ignored "-Wswitch-enum"
  36. # pragma clang diagnostic ignored "-Wcovered-switch-default"
  37. # endif
  38. #elif defined __GNUC__
  39. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  40. # pragma GCC diagnostic ignored "-Wunused-variable"
  41. # pragma GCC diagnostic ignored "-Wparentheses"
  42. # pragma GCC diagnostic push
  43. # pragma GCC diagnostic ignored "-Wpadded"
  44. #endif
  45. #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
  46. # define CATCH_IMPL
  47. #endif
  48. #ifdef CATCH_IMPL
  49. # ifndef CLARA_CONFIG_MAIN
  50. # define CLARA_CONFIG_MAIN_NOT_DEFINED
  51. # define CLARA_CONFIG_MAIN
  52. # endif
  53. #endif
  54. // #included from: internal/catch_notimplemented_exception.h
  55. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
  56. // #included from: catch_common.h
  57. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  58. // #included from: catch_compiler_capabilities.h
  59. #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  60. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  61. // The following features are defined:
  62. //
  63. // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
  64. // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  65. // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  66. // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
  67. // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
  68. // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
  69. // CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
  70. // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  71. // CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
  72. // CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
  73. // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  74. // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  75. // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
  76. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  77. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  78. // ****************
  79. // Note to maintainers: if new toggles are added please document them
  80. // in configuration.md, too
  81. // ****************
  82. // In general each macro has a _NO_<feature name> form
  83. // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  84. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  85. // can be combined, en-mass, with the _NO_ forms later.
  86. // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
  87. #ifdef __cplusplus
  88. # if __cplusplus >= 201103L
  89. # define CATCH_CPP11_OR_GREATER
  90. # endif
  91. # if __cplusplus >= 201402L
  92. # define CATCH_CPP14_OR_GREATER
  93. # endif
  94. #endif
  95. #ifdef __clang__
  96. # if __has_feature(cxx_nullptr)
  97. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  98. # endif
  99. # if __has_feature(cxx_noexcept)
  100. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  101. # endif
  102. # if defined(CATCH_CPP11_OR_GREATER)
  103. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  104. _Pragma( "clang diagnostic push" ) \
  105. _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" )
  106. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  107. _Pragma( "clang diagnostic pop" )
  108. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  109. _Pragma( "clang diagnostic push" ) \
  110. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  111. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  112. _Pragma( "clang diagnostic pop" )
  113. # endif
  114. #endif // __clang__
  115. ////////////////////////////////////////////////////////////////////////////////
  116. // We know some environments not to support full POSIX signals
  117. #if defined(__CYGWIN__) || defined(__QNX__)
  118. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  119. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  120. # endif
  121. #endif
  122. #ifdef __OS400__
  123. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  124. # define CATCH_CONFIG_COLOUR_NONE
  125. #endif
  126. ////////////////////////////////////////////////////////////////////////////////
  127. // Cygwin
  128. #ifdef __CYGWIN__
  129. // Required for some versions of Cygwin to declare gettimeofday
  130. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  131. # define _BSD_SOURCE
  132. #endif // __CYGWIN__
  133. ////////////////////////////////////////////////////////////////////////////////
  134. // Borland
  135. #ifdef __BORLANDC__
  136. #endif // __BORLANDC__
  137. ////////////////////////////////////////////////////////////////////////////////
  138. // EDG
  139. #ifdef __EDG_VERSION__
  140. #endif // __EDG_VERSION__
  141. ////////////////////////////////////////////////////////////////////////////////
  142. // Digital Mars
  143. #ifdef __DMC__
  144. #endif // __DMC__
  145. ////////////////////////////////////////////////////////////////////////////////
  146. // GCC
  147. #ifdef __GNUC__
  148. # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  149. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  150. # endif
  151. // - otherwise more recent versions define __cplusplus >= 201103L
  152. // and will get picked up below
  153. #endif // __GNUC__
  154. ////////////////////////////////////////////////////////////////////////////////
  155. // Visual C++
  156. #ifdef _MSC_VER
  157. #define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  158. #if (_MSC_VER >= 1600)
  159. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  160. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  161. #endif
  162. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  163. #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  164. #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  165. #define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  166. #define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  167. #endif
  168. #endif // _MSC_VER
  169. ////////////////////////////////////////////////////////////////////////////////
  170. // Use variadic macros if the compiler supports them
  171. #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
  172. ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
  173. ( defined __GNUC__ && __GNUC__ >= 3 ) || \
  174. ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
  175. #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  176. #endif
  177. // Use __COUNTER__ if the compiler supports it
  178. #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
  179. ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \
  180. ( defined __clang__ && __clang_major__ >= 3 )
  181. // Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former,
  182. // because __COUNTER__ is not properly handled by it.
  183. // This does not affect compilation
  184. #if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L )
  185. #define CATCH_INTERNAL_CONFIG_COUNTER
  186. #endif
  187. #endif
  188. ////////////////////////////////////////////////////////////////////////////////
  189. // C++ language feature support
  190. // catch all support for C++11
  191. #if defined(CATCH_CPP11_OR_GREATER)
  192. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
  193. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  194. # endif
  195. # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  196. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  197. # endif
  198. # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  199. # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  200. # endif
  201. # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  202. # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  203. # endif
  204. # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  205. # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  206. # endif
  207. # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  208. # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  209. # endif
  210. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
  211. # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
  212. # endif
  213. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
  214. # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
  215. # endif
  216. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  217. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  218. # endif
  219. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
  220. # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  221. # endif
  222. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
  223. # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  224. # endif
  225. #endif // __cplusplus >= 201103L
  226. // Now set the actual defines based on the above + anything the user has configured
  227. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
  228. # define CATCH_CONFIG_CPP11_NULLPTR
  229. #endif
  230. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
  231. # define CATCH_CONFIG_CPP11_NOEXCEPT
  232. #endif
  233. #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)
  234. # define CATCH_CONFIG_CPP11_GENERATED_METHODS
  235. #endif
  236. #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)
  237. # define CATCH_CONFIG_CPP11_IS_ENUM
  238. #endif
  239. #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
  240. # define CATCH_CONFIG_CPP11_TUPLE
  241. #endif
  242. #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
  243. # define CATCH_CONFIG_VARIADIC_MACROS
  244. #endif
  245. #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)
  246. # define CATCH_CONFIG_CPP11_LONG_LONG
  247. #endif
  248. #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
  249. # define CATCH_CONFIG_CPP11_OVERRIDE
  250. #endif
  251. #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)
  252. # define CATCH_CONFIG_CPP11_UNIQUE_PTR
  253. #endif
  254. #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
  255. # define CATCH_CONFIG_COUNTER
  256. #endif
  257. #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
  258. # define CATCH_CONFIG_CPP11_SHUFFLE
  259. #endif
  260. # 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)
  261. # define CATCH_CONFIG_CPP11_TYPE_TRAITS
  262. # endif
  263. #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
  264. # define CATCH_CONFIG_WINDOWS_SEH
  265. #endif
  266. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  267. #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
  268. # define CATCH_CONFIG_POSIX_SIGNALS
  269. #endif
  270. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  271. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  272. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
  273. #endif
  274. #if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
  275. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  276. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  277. #endif
  278. // noexcept support:
  279. #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
  280. # define CATCH_NOEXCEPT noexcept
  281. # define CATCH_NOEXCEPT_IS(x) noexcept(x)
  282. #else
  283. # define CATCH_NOEXCEPT throw()
  284. # define CATCH_NOEXCEPT_IS(x)
  285. #endif
  286. // nullptr support
  287. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  288. # define CATCH_NULL nullptr
  289. #else
  290. # define CATCH_NULL NULL
  291. #endif
  292. // override support
  293. #ifdef CATCH_CONFIG_CPP11_OVERRIDE
  294. # define CATCH_OVERRIDE override
  295. #else
  296. # define CATCH_OVERRIDE
  297. #endif
  298. // unique_ptr support
  299. #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
  300. # define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
  301. #else
  302. # define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
  303. #endif
  304. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  305. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  306. #ifdef CATCH_CONFIG_COUNTER
  307. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  308. #else
  309. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  310. #endif
  311. #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
  312. #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
  313. #include <sstream>
  314. #include <algorithm>
  315. namespace Catch {
  316. struct IConfig;
  317. struct CaseSensitive { enum Choice {
  318. Yes,
  319. No
  320. }; };
  321. class NonCopyable {
  322. #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  323. NonCopyable( NonCopyable const& ) = delete;
  324. NonCopyable( NonCopyable && ) = delete;
  325. NonCopyable& operator = ( NonCopyable const& ) = delete;
  326. NonCopyable& operator = ( NonCopyable && ) = delete;
  327. #else
  328. NonCopyable( NonCopyable const& info );
  329. NonCopyable& operator = ( NonCopyable const& );
  330. #endif
  331. protected:
  332. NonCopyable() {}
  333. virtual ~NonCopyable();
  334. };
  335. class SafeBool {
  336. public:
  337. typedef void (SafeBool::*type)() const;
  338. static type makeSafe( bool value ) {
  339. return value ? &SafeBool::trueValue : 0;
  340. }
  341. private:
  342. void trueValue() const {}
  343. };
  344. template<typename ContainerT>
  345. void deleteAll( ContainerT& container ) {
  346. typename ContainerT::const_iterator it = container.begin();
  347. typename ContainerT::const_iterator itEnd = container.end();
  348. for(; it != itEnd; ++it )
  349. delete *it;
  350. }
  351. template<typename AssociativeContainerT>
  352. void deleteAllValues( AssociativeContainerT& container ) {
  353. typename AssociativeContainerT::const_iterator it = container.begin();
  354. typename AssociativeContainerT::const_iterator itEnd = container.end();
  355. for(; it != itEnd; ++it )
  356. delete it->second;
  357. }
  358. bool startsWith( std::string const& s, std::string const& prefix );
  359. bool startsWith( std::string const& s, char prefix );
  360. bool endsWith( std::string const& s, std::string const& suffix );
  361. bool endsWith( std::string const& s, char suffix );
  362. bool contains( std::string const& s, std::string const& infix );
  363. void toLowerInPlace( std::string& s );
  364. std::string toLower( std::string const& s );
  365. std::string trim( std::string const& str );
  366. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  367. struct pluralise {
  368. pluralise( std::size_t count, std::string const& label );
  369. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  370. std::size_t m_count;
  371. std::string m_label;
  372. };
  373. struct SourceLineInfo {
  374. SourceLineInfo();
  375. SourceLineInfo( char const* _file, std::size_t _line );
  376. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  377. SourceLineInfo(SourceLineInfo const& other) = default;
  378. SourceLineInfo( SourceLineInfo && ) = default;
  379. SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
  380. SourceLineInfo& operator = ( SourceLineInfo && ) = default;
  381. # endif
  382. bool empty() const;
  383. bool operator == ( SourceLineInfo const& other ) const;
  384. bool operator < ( SourceLineInfo const& other ) const;
  385. char const* file;
  386. std::size_t line;
  387. };
  388. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
  389. // This is just here to avoid compiler warnings with macro constants and boolean literals
  390. inline bool isTrue( bool value ){ return value; }
  391. inline bool alwaysTrue() { return true; }
  392. inline bool alwaysFalse() { return false; }
  393. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
  394. void seedRng( IConfig const& config );
  395. unsigned int rngSeed();
  396. // Use this in variadic streaming macros to allow
  397. // >> +StreamEndStop
  398. // as well as
  399. // >> stuff +StreamEndStop
  400. struct StreamEndStop {
  401. std::string operator+() {
  402. return std::string();
  403. }
  404. };
  405. template<typename T>
  406. T const& operator + ( T const& value, StreamEndStop ) {
  407. return value;
  408. }
  409. }
  410. #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  411. #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
  412. namespace Catch {
  413. class NotImplementedException : public std::exception
  414. {
  415. public:
  416. NotImplementedException( SourceLineInfo const& lineInfo );
  417. virtual ~NotImplementedException() CATCH_NOEXCEPT {}
  418. virtual const char* what() const CATCH_NOEXCEPT;
  419. private:
  420. std::string m_what;
  421. SourceLineInfo m_lineInfo;
  422. };
  423. } // end namespace Catch
  424. ///////////////////////////////////////////////////////////////////////////////
  425. #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
  426. // #included from: internal/catch_context.h
  427. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  428. // #included from: catch_interfaces_generators.h
  429. #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
  430. #include <string>
  431. namespace Catch {
  432. struct IGeneratorInfo {
  433. virtual ~IGeneratorInfo();
  434. virtual bool moveNext() = 0;
  435. virtual std::size_t getCurrentIndex() const = 0;
  436. };
  437. struct IGeneratorsForTest {
  438. virtual ~IGeneratorsForTest();
  439. virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
  440. virtual bool moveNext() = 0;
  441. };
  442. IGeneratorsForTest* createGeneratorsForTest();
  443. } // end namespace Catch
  444. // #included from: catch_ptr.hpp
  445. #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
  446. #ifdef __clang__
  447. #pragma clang diagnostic push
  448. #pragma clang diagnostic ignored "-Wpadded"
  449. #endif
  450. namespace Catch {
  451. // An intrusive reference counting smart pointer.
  452. // T must implement addRef() and release() methods
  453. // typically implementing the IShared interface
  454. template<typename T>
  455. class Ptr {
  456. public:
  457. Ptr() : m_p( CATCH_NULL ){}
  458. Ptr( T* p ) : m_p( p ){
  459. if( m_p )
  460. m_p->addRef();
  461. }
  462. Ptr( Ptr const& other ) : m_p( other.m_p ){
  463. if( m_p )
  464. m_p->addRef();
  465. }
  466. ~Ptr(){
  467. if( m_p )
  468. m_p->release();
  469. }
  470. void reset() {
  471. if( m_p )
  472. m_p->release();
  473. m_p = CATCH_NULL;
  474. }
  475. Ptr& operator = ( T* p ){
  476. Ptr temp( p );
  477. swap( temp );
  478. return *this;
  479. }
  480. Ptr& operator = ( Ptr const& other ){
  481. Ptr temp( other );
  482. swap( temp );
  483. return *this;
  484. }
  485. void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
  486. T* get() const{ return m_p; }
  487. T& operator*() const { return *m_p; }
  488. T* operator->() const { return m_p; }
  489. bool operator !() const { return m_p == CATCH_NULL; }
  490. operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
  491. private:
  492. T* m_p;
  493. };
  494. struct IShared : NonCopyable {
  495. virtual ~IShared();
  496. virtual void addRef() const = 0;
  497. virtual void release() const = 0;
  498. };
  499. template<typename T = IShared>
  500. struct SharedImpl : T {
  501. SharedImpl() : m_rc( 0 ){}
  502. virtual void addRef() const {
  503. ++m_rc;
  504. }
  505. virtual void release() const {
  506. if( --m_rc == 0 )
  507. delete this;
  508. }
  509. mutable unsigned int m_rc;
  510. };
  511. } // end namespace Catch
  512. #ifdef __clang__
  513. #pragma clang diagnostic pop
  514. #endif
  515. namespace Catch {
  516. class TestCase;
  517. class Stream;
  518. struct IResultCapture;
  519. struct IRunner;
  520. struct IGeneratorsForTest;
  521. struct IConfig;
  522. struct IContext
  523. {
  524. virtual ~IContext();
  525. virtual IResultCapture* getResultCapture() = 0;
  526. virtual IRunner* getRunner() = 0;
  527. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
  528. virtual bool advanceGeneratorsForCurrentTest() = 0;
  529. virtual Ptr<IConfig const> getConfig() const = 0;
  530. };
  531. struct IMutableContext : IContext
  532. {
  533. virtual ~IMutableContext();
  534. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  535. virtual void setRunner( IRunner* runner ) = 0;
  536. virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
  537. };
  538. IContext& getCurrentContext();
  539. IMutableContext& getCurrentMutableContext();
  540. void cleanUpContext();
  541. Stream createStream( std::string const& streamName );
  542. }
  543. // #included from: internal/catch_test_registry.hpp
  544. #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
  545. // #included from: catch_interfaces_testcase.h
  546. #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
  547. #include <vector>
  548. namespace Catch {
  549. class TestSpec;
  550. struct ITestCase : IShared {
  551. virtual void invoke () const = 0;
  552. protected:
  553. virtual ~ITestCase();
  554. };
  555. class TestCase;
  556. struct IConfig;
  557. struct ITestCaseRegistry {
  558. virtual ~ITestCaseRegistry();
  559. virtual std::vector<TestCase> const& getAllTests() const = 0;
  560. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
  561. };
  562. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
  563. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
  564. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
  565. }
  566. namespace Catch {
  567. template<typename C>
  568. class MethodTestCase : public SharedImpl<ITestCase> {
  569. public:
  570. MethodTestCase( void (C::*method)() ) : m_method( method ) {}
  571. virtual void invoke() const {
  572. C obj;
  573. (obj.*m_method)();
  574. }
  575. private:
  576. virtual ~MethodTestCase() {}
  577. void (C::*m_method)();
  578. };
  579. typedef void(*TestFunction)();
  580. struct NameAndDesc {
  581. NameAndDesc( const char* _name = "", const char* _description= "" )
  582. : name( _name ), description( _description )
  583. {}
  584. const char* name;
  585. const char* description;
  586. };
  587. void registerTestCase
  588. ( ITestCase* testCase,
  589. char const* className,
  590. NameAndDesc const& nameAndDesc,
  591. SourceLineInfo const& lineInfo );
  592. struct AutoReg {
  593. AutoReg
  594. ( TestFunction function,
  595. SourceLineInfo const& lineInfo,
  596. NameAndDesc const& nameAndDesc );
  597. template<typename C>
  598. AutoReg
  599. ( void (C::*method)(),
  600. char const* className,
  601. NameAndDesc const& nameAndDesc,
  602. SourceLineInfo const& lineInfo ) {
  603. registerTestCase
  604. ( new MethodTestCase<C>( method ),
  605. className,
  606. nameAndDesc,
  607. lineInfo );
  608. }
  609. ~AutoReg();
  610. private:
  611. AutoReg( AutoReg const& );
  612. void operator= ( AutoReg const& );
  613. };
  614. void registerTestCaseFunction
  615. ( TestFunction function,
  616. SourceLineInfo const& lineInfo,
  617. NameAndDesc const& nameAndDesc );
  618. } // end namespace Catch
  619. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  620. ///////////////////////////////////////////////////////////////////////////////
  621. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  622. static void TestName(); \
  623. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  624. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); } /* NOLINT */ \
  625. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  626. static void TestName()
  627. #define INTERNAL_CATCH_TESTCASE( ... ) \
  628. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
  629. ///////////////////////////////////////////////////////////////////////////////
  630. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  631. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  632. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  633. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  634. ///////////////////////////////////////////////////////////////////////////////
  635. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  636. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  637. namespace{ \
  638. struct TestName : ClassName{ \
  639. void test(); \
  640. }; \
  641. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  642. } \
  643. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  644. void TestName::test()
  645. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  646. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
  647. ///////////////////////////////////////////////////////////////////////////////
  648. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  649. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  650. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); /* NOLINT */ \
  651. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  652. #else
  653. ///////////////////////////////////////////////////////////////////////////////
  654. #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
  655. static void TestName(); \
  656. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  657. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); } /* NOLINT */ \
  658. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  659. static void TestName()
  660. #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
  661. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
  662. ///////////////////////////////////////////////////////////////////////////////
  663. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
  664. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  665. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  666. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  667. ///////////////////////////////////////////////////////////////////////////////
  668. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
  669. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  670. namespace{ \
  671. struct TestCaseName : ClassName{ \
  672. void test(); \
  673. }; \
  674. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  675. } \
  676. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  677. void TestCaseName::test()
  678. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
  679. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
  680. ///////////////////////////////////////////////////////////////////////////////
  681. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
  682. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  683. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); /* NOLINT */ \
  684. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  685. #endif
  686. // #included from: internal/catch_capture.hpp
  687. #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
  688. // #included from: catch_result_builder.h
  689. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
  690. // #included from: catch_result_type.h
  691. #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
  692. namespace Catch {
  693. // ResultWas::OfType enum
  694. struct ResultWas { enum OfType {
  695. Unknown = -1,
  696. Ok = 0,
  697. Info = 1,
  698. Warning = 2,
  699. FailureBit = 0x10,
  700. ExpressionFailed = FailureBit | 1,
  701. ExplicitFailure = FailureBit | 2,
  702. Exception = 0x100 | FailureBit,
  703. ThrewException = Exception | 1,
  704. DidntThrowException = Exception | 2,
  705. FatalErrorCondition = 0x200 | FailureBit
  706. }; };
  707. inline bool isOk( ResultWas::OfType resultType ) {
  708. return ( resultType & ResultWas::FailureBit ) == 0;
  709. }
  710. inline bool isJustInfo( int flags ) {
  711. return flags == ResultWas::Info;
  712. }
  713. // ResultDisposition::Flags enum
  714. struct ResultDisposition { enum Flags {
  715. Normal = 0x01,
  716. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  717. FalseTest = 0x04, // Prefix expression with !
  718. SuppressFail = 0x08 // Failures are reported but do not fail the test
  719. }; };
  720. inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
  721. return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
  722. }
  723. inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
  724. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  725. inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
  726. } // end namespace Catch
  727. // #included from: catch_assertionresult.h
  728. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
  729. #include <string>
  730. namespace Catch {
  731. struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
  732. struct DecomposedExpression
  733. {
  734. virtual ~DecomposedExpression() {}
  735. virtual bool isBinaryExpression() const {
  736. return false;
  737. }
  738. virtual void reconstructExpression( std::string& dest ) const = 0;
  739. // Only simple binary comparisons can be decomposed.
  740. // If more complex check is required then wrap sub-expressions in parentheses.
  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. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& );
  747. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& );
  748. private:
  749. DecomposedExpression& operator = (DecomposedExpression const&);
  750. };
  751. struct AssertionInfo
  752. {
  753. AssertionInfo();
  754. AssertionInfo( char const * _macroName,
  755. SourceLineInfo const& _lineInfo,
  756. char const * _capturedExpression,
  757. ResultDisposition::Flags _resultDisposition,
  758. char const * _secondArg = "");
  759. char const * macroName;
  760. SourceLineInfo lineInfo;
  761. char const * capturedExpression;
  762. ResultDisposition::Flags resultDisposition;
  763. char const * secondArg;
  764. };
  765. struct AssertionResultData
  766. {
  767. AssertionResultData() : decomposedExpression( CATCH_NULL )
  768. , resultType( ResultWas::Unknown )
  769. , negated( false )
  770. , parenthesized( false ) {}
  771. void negate( bool parenthesize ) {
  772. negated = !negated;
  773. parenthesized = parenthesize;
  774. if( resultType == ResultWas::Ok )
  775. resultType = ResultWas::ExpressionFailed;
  776. else if( resultType == ResultWas::ExpressionFailed )
  777. resultType = ResultWas::Ok;
  778. }
  779. std::string const& reconstructExpression() const {
  780. if( decomposedExpression != CATCH_NULL ) {
  781. decomposedExpression->reconstructExpression( reconstructedExpression );
  782. if( parenthesized ) {
  783. reconstructedExpression.insert( 0, 1, '(' );
  784. reconstructedExpression.append( 1, ')' );
  785. }
  786. if( negated ) {
  787. reconstructedExpression.insert( 0, 1, '!' );
  788. }
  789. decomposedExpression = CATCH_NULL;
  790. }
  791. return reconstructedExpression;
  792. }
  793. mutable DecomposedExpression const* decomposedExpression;
  794. mutable std::string reconstructedExpression;
  795. std::string message;
  796. ResultWas::OfType resultType;
  797. bool negated;
  798. bool parenthesized;
  799. };
  800. class AssertionResult {
  801. public:
  802. AssertionResult();
  803. AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
  804. ~AssertionResult();
  805. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  806. AssertionResult( AssertionResult const& ) = default;
  807. AssertionResult( AssertionResult && ) = default;
  808. AssertionResult& operator = ( AssertionResult const& ) = default;
  809. AssertionResult& operator = ( AssertionResult && ) = default;
  810. # endif
  811. bool isOk() const;
  812. bool succeeded() const;
  813. ResultWas::OfType getResultType() const;
  814. bool hasExpression() const;
  815. bool hasMessage() const;
  816. std::string getExpression() const;
  817. std::string getExpressionInMacro() const;
  818. bool hasExpandedExpression() const;
  819. std::string getExpandedExpression() const;
  820. std::string getMessage() const;
  821. SourceLineInfo getSourceInfo() const;
  822. std::string getTestMacroName() const;
  823. void discardDecomposedExpression() const;
  824. void expandDecomposedExpression() const;
  825. protected:
  826. AssertionInfo m_info;
  827. AssertionResultData m_resultData;
  828. };
  829. } // end namespace Catch
  830. // #included from: catch_matchers.hpp
  831. #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
  832. namespace Catch {
  833. namespace Matchers {
  834. namespace Impl {
  835. template<typename ArgT> struct MatchAllOf;
  836. template<typename ArgT> struct MatchAnyOf;
  837. template<typename ArgT> struct MatchNotOf;
  838. class MatcherUntypedBase {
  839. public:
  840. std::string toString() const {
  841. if( m_cachedToString.empty() )
  842. m_cachedToString = describe();
  843. return m_cachedToString;
  844. }
  845. protected:
  846. virtual ~MatcherUntypedBase();
  847. virtual std::string describe() const = 0;
  848. mutable std::string m_cachedToString;
  849. private:
  850. MatcherUntypedBase& operator = ( MatcherUntypedBase const& );
  851. };
  852. template<typename ObjectT>
  853. struct MatcherMethod {
  854. virtual bool match( ObjectT const& arg ) const = 0;
  855. };
  856. template<typename PtrT>
  857. struct MatcherMethod<PtrT*> {
  858. virtual bool match( PtrT* arg ) const = 0;
  859. };
  860. template<typename ObjectT, typename ComparatorT = ObjectT>
  861. struct MatcherBase : MatcherUntypedBase, MatcherMethod<ObjectT> {
  862. MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
  863. MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
  864. MatchNotOf<ComparatorT> operator ! () const;
  865. };
  866. template<typename ArgT>
  867. struct MatchAllOf : MatcherBase<ArgT> {
  868. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  869. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  870. if (!m_matchers[i]->match(arg))
  871. return false;
  872. }
  873. return true;
  874. }
  875. virtual std::string describe() const CATCH_OVERRIDE {
  876. std::string description;
  877. description.reserve( 4 + m_matchers.size()*32 );
  878. description += "( ";
  879. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  880. if( i != 0 )
  881. description += " and ";
  882. description += m_matchers[i]->toString();
  883. }
  884. description += " )";
  885. return description;
  886. }
  887. MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
  888. m_matchers.push_back( &other );
  889. return *this;
  890. }
  891. std::vector<MatcherBase<ArgT> const*> m_matchers;
  892. };
  893. template<typename ArgT>
  894. struct MatchAnyOf : MatcherBase<ArgT> {
  895. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  896. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  897. if (m_matchers[i]->match(arg))
  898. return true;
  899. }
  900. return false;
  901. }
  902. virtual std::string describe() const CATCH_OVERRIDE {
  903. std::string description;
  904. description.reserve( 4 + m_matchers.size()*32 );
  905. description += "( ";
  906. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  907. if( i != 0 )
  908. description += " or ";
  909. description += m_matchers[i]->toString();
  910. }
  911. description += " )";
  912. return description;
  913. }
  914. MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
  915. m_matchers.push_back( &other );
  916. return *this;
  917. }
  918. std::vector<MatcherBase<ArgT> const*> m_matchers;
  919. };
  920. template<typename ArgT>
  921. struct MatchNotOf : MatcherBase<ArgT> {
  922. MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
  923. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  924. return !m_underlyingMatcher.match( arg );
  925. }
  926. virtual std::string describe() const CATCH_OVERRIDE {
  927. return "not " + m_underlyingMatcher.toString();
  928. }
  929. MatcherBase<ArgT> const& m_underlyingMatcher;
  930. };
  931. template<typename ObjectT, typename ComparatorT>
  932. MatchAllOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator && ( MatcherBase const& other ) const {
  933. return MatchAllOf<ComparatorT>() && *this && other;
  934. }
  935. template<typename ObjectT, typename ComparatorT>
  936. MatchAnyOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator || ( MatcherBase const& other ) const {
  937. return MatchAnyOf<ComparatorT>() || *this || other;
  938. }
  939. template<typename ObjectT, typename ComparatorT>
  940. MatchNotOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator ! () const {
  941. return MatchNotOf<ComparatorT>( *this );
  942. }
  943. } // namespace Impl
  944. // The following functions create the actual matcher objects.
  945. // This allows the types to be inferred
  946. // - deprecated: prefer ||, && and !
  947. template<typename T>
  948. Impl::MatchNotOf<T> Not( Impl::MatcherBase<T> const& underlyingMatcher ) {
  949. return Impl::MatchNotOf<T>( underlyingMatcher );
  950. }
  951. template<typename T>
  952. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  953. return Impl::MatchAllOf<T>() && m1 && m2;
  954. }
  955. template<typename T>
  956. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  957. return Impl::MatchAllOf<T>() && m1 && m2 && m3;
  958. }
  959. template<typename T>
  960. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  961. return Impl::MatchAnyOf<T>() || m1 || m2;
  962. }
  963. template<typename T>
  964. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  965. return Impl::MatchAnyOf<T>() || m1 || m2 || m3;
  966. }
  967. } // namespace Matchers
  968. using namespace Matchers;
  969. using Matchers::Impl::MatcherBase;
  970. } // namespace Catch
  971. namespace Catch {
  972. struct TestFailureException{};
  973. template<typename T> class ExpressionLhs;
  974. struct CopyableStream {
  975. CopyableStream() {}
  976. CopyableStream( CopyableStream const& other ) {
  977. oss << other.oss.str();
  978. }
  979. CopyableStream& operator=( CopyableStream const& other ) {
  980. oss.str(std::string());
  981. oss << other.oss.str();
  982. return *this;
  983. }
  984. std::ostringstream oss;
  985. };
  986. class ResultBuilder : public DecomposedExpression {
  987. public:
  988. ResultBuilder( char const* macroName,
  989. SourceLineInfo const& lineInfo,
  990. char const* capturedExpression,
  991. ResultDisposition::Flags resultDisposition,
  992. char const* secondArg = "" );
  993. ~ResultBuilder();
  994. template<typename T>
  995. ExpressionLhs<T const&> operator <= ( T const& operand );
  996. ExpressionLhs<bool> operator <= ( bool value );
  997. template<typename T>
  998. ResultBuilder& operator << ( T const& value ) {
  999. stream().oss << value;
  1000. return *this;
  1001. }
  1002. ResultBuilder& setResultType( ResultWas::OfType result );
  1003. ResultBuilder& setResultType( bool result );
  1004. void endExpression( DecomposedExpression const& expr );
  1005. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE;
  1006. AssertionResult build() const;
  1007. AssertionResult build( DecomposedExpression const& expr ) const;
  1008. void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
  1009. void captureResult( ResultWas::OfType resultType );
  1010. void captureExpression();
  1011. void captureExpectedException( std::string const& expectedMessage );
  1012. void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher );
  1013. void handleResult( AssertionResult const& result );
  1014. void react();
  1015. bool shouldDebugBreak() const;
  1016. bool allowThrows() const;
  1017. template<typename ArgT, typename MatcherT>
  1018. void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
  1019. void setExceptionGuard();
  1020. void unsetExceptionGuard();
  1021. private:
  1022. AssertionInfo m_assertionInfo;
  1023. AssertionResultData m_data;
  1024. CopyableStream &stream()
  1025. {
  1026. if(!m_usedStream)
  1027. {
  1028. m_usedStream = true;
  1029. m_stream().oss.str("");
  1030. }
  1031. return m_stream();
  1032. }
  1033. static CopyableStream &m_stream()
  1034. {
  1035. static CopyableStream s;
  1036. return s;
  1037. }
  1038. bool m_shouldDebugBreak;
  1039. bool m_shouldThrow;
  1040. bool m_guardException;
  1041. bool m_usedStream;
  1042. };
  1043. } // namespace Catch
  1044. // Include after due to circular dependency:
  1045. // #included from: catch_expression_lhs.hpp
  1046. #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
  1047. // #included from: catch_evaluate.hpp
  1048. #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
  1049. #ifdef _MSC_VER
  1050. #pragma warning(push)
  1051. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  1052. #pragma warning(disable:4018) // more "signed/unsigned mismatch"
  1053. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  1054. #endif
  1055. #include <cstddef>
  1056. namespace Catch {
  1057. namespace Internal {
  1058. enum Operator {
  1059. IsEqualTo,
  1060. IsNotEqualTo,
  1061. IsLessThan,
  1062. IsGreaterThan,
  1063. IsLessThanOrEqualTo,
  1064. IsGreaterThanOrEqualTo
  1065. };
  1066. template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
  1067. template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
  1068. template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
  1069. template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
  1070. template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
  1071. template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
  1072. template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
  1073. template<typename T>
  1074. T& opCast(T const& t) { return const_cast<T&>(t); }
  1075. // nullptr_t support based on pull request #154 from Konstantin Baumann
  1076. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1077. inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
  1078. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1079. // So the compare overloads can be operator agnostic we convey the operator as a template
  1080. // enum, which is used to specialise an Evaluator for doing the comparison.
  1081. template<typename T1, typename T2, Operator Op>
  1082. struct Evaluator{};
  1083. template<typename T1, typename T2>
  1084. struct Evaluator<T1, T2, IsEqualTo> {
  1085. static bool evaluate( T1 const& lhs, T2 const& rhs) {
  1086. return bool( opCast( lhs ) == opCast( rhs ) );
  1087. }
  1088. };
  1089. template<typename T1, typename T2>
  1090. struct Evaluator<T1, T2, IsNotEqualTo> {
  1091. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1092. return bool( opCast( lhs ) != opCast( rhs ) );
  1093. }
  1094. };
  1095. template<typename T1, typename T2>
  1096. struct Evaluator<T1, T2, IsLessThan> {
  1097. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1098. return bool( opCast( lhs ) < opCast( rhs ) );
  1099. }
  1100. };
  1101. template<typename T1, typename T2>
  1102. struct Evaluator<T1, T2, IsGreaterThan> {
  1103. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1104. return bool( opCast( lhs ) > opCast( rhs ) );
  1105. }
  1106. };
  1107. template<typename T1, typename T2>
  1108. struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
  1109. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1110. return bool( opCast( lhs ) >= opCast( rhs ) );
  1111. }
  1112. };
  1113. template<typename T1, typename T2>
  1114. struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
  1115. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1116. return bool( opCast( lhs ) <= opCast( rhs ) );
  1117. }
  1118. };
  1119. template<Operator Op, typename T1, typename T2>
  1120. bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
  1121. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1122. }
  1123. // This level of indirection allows us to specialise for integer types
  1124. // to avoid signed/ unsigned warnings
  1125. // "base" overload
  1126. template<Operator Op, typename T1, typename T2>
  1127. bool compare( T1 const& lhs, T2 const& rhs ) {
  1128. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1129. }
  1130. // unsigned X to int
  1131. template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
  1132. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1133. }
  1134. template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
  1135. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1136. }
  1137. template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
  1138. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1139. }
  1140. // unsigned X to long
  1141. template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
  1142. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1143. }
  1144. template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
  1145. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1146. }
  1147. template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
  1148. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1149. }
  1150. // int to unsigned X
  1151. template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
  1152. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1153. }
  1154. template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
  1155. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1156. }
  1157. template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
  1158. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1159. }
  1160. // long to unsigned X
  1161. template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
  1162. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1163. }
  1164. template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
  1165. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1166. }
  1167. template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
  1168. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1169. }
  1170. // pointer to long (when comparing against NULL)
  1171. template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
  1172. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1173. }
  1174. template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
  1175. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1176. }
  1177. // pointer to int (when comparing against NULL)
  1178. template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
  1179. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1180. }
  1181. template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
  1182. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1183. }
  1184. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1185. // long long to unsigned X
  1186. template<Operator Op> bool compare( long long lhs, unsigned int rhs ) {
  1187. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1188. }
  1189. template<Operator Op> bool compare( long long lhs, unsigned long rhs ) {
  1190. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1191. }
  1192. template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) {
  1193. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1194. }
  1195. template<Operator Op> bool compare( long long lhs, unsigned char rhs ) {
  1196. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1197. }
  1198. // unsigned long long to X
  1199. template<Operator Op> bool compare( unsigned long long lhs, int rhs ) {
  1200. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1201. }
  1202. template<Operator Op> bool compare( unsigned long long lhs, long rhs ) {
  1203. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1204. }
  1205. template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) {
  1206. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1207. }
  1208. template<Operator Op> bool compare( unsigned long long lhs, char rhs ) {
  1209. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1210. }
  1211. // pointer to long long (when comparing against NULL)
  1212. template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) {
  1213. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1214. }
  1215. template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) {
  1216. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1217. }
  1218. #endif // CATCH_CONFIG_CPP11_LONG_LONG
  1219. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1220. // pointer to nullptr_t (when comparing against nullptr)
  1221. template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
  1222. return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs );
  1223. }
  1224. template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
  1225. return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr );
  1226. }
  1227. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1228. } // end of namespace Internal
  1229. } // end of namespace Catch
  1230. #ifdef _MSC_VER
  1231. #pragma warning(pop)
  1232. #endif
  1233. // #included from: catch_tostring.h
  1234. #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
  1235. #include <sstream>
  1236. #include <iomanip>
  1237. #include <limits>
  1238. #include <vector>
  1239. #include <cstddef>
  1240. #ifdef __OBJC__
  1241. // #included from: catch_objc_arc.hpp
  1242. #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
  1243. #import <Foundation/Foundation.h>
  1244. #ifdef __has_feature
  1245. #define CATCH_ARC_ENABLED __has_feature(objc_arc)
  1246. #else
  1247. #define CATCH_ARC_ENABLED 0
  1248. #endif
  1249. void arcSafeRelease( NSObject* obj );
  1250. id performOptionalSelector( id obj, SEL sel );
  1251. #if !CATCH_ARC_ENABLED
  1252. inline void arcSafeRelease( NSObject* obj ) {
  1253. [obj release];
  1254. }
  1255. inline id performOptionalSelector( id obj, SEL sel ) {
  1256. if( [obj respondsToSelector: sel] )
  1257. return [obj performSelector: sel];
  1258. return nil;
  1259. }
  1260. #define CATCH_UNSAFE_UNRETAINED
  1261. #define CATCH_ARC_STRONG
  1262. #else
  1263. inline void arcSafeRelease( NSObject* ){}
  1264. inline id performOptionalSelector( id obj, SEL sel ) {
  1265. #ifdef __clang__
  1266. #pragma clang diagnostic push
  1267. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  1268. #endif
  1269. if( [obj respondsToSelector: sel] )
  1270. return [obj performSelector: sel];
  1271. #ifdef __clang__
  1272. #pragma clang diagnostic pop
  1273. #endif
  1274. return nil;
  1275. }
  1276. #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
  1277. #define CATCH_ARC_STRONG __strong
  1278. #endif
  1279. #endif
  1280. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1281. #include <tuple>
  1282. #endif
  1283. #ifdef CATCH_CONFIG_CPP11_IS_ENUM
  1284. #include <type_traits>
  1285. #endif
  1286. namespace Catch {
  1287. // Why we're here.
  1288. template<typename T>
  1289. std::string toString( T const& value );
  1290. // Built in overloads
  1291. std::string toString( std::string const& value );
  1292. std::string toString( std::wstring const& value );
  1293. std::string toString( const char* const value );
  1294. std::string toString( char* const value );
  1295. std::string toString( const wchar_t* const value );
  1296. std::string toString( wchar_t* const value );
  1297. std::string toString( int value );
  1298. std::string toString( unsigned long value );
  1299. std::string toString( unsigned int value );
  1300. std::string toString( const double value );
  1301. std::string toString( const float value );
  1302. std::string toString( bool value );
  1303. std::string toString( char value );
  1304. std::string toString( signed char value );
  1305. std::string toString( unsigned char value );
  1306. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1307. std::string toString( long long value );
  1308. std::string toString( unsigned long long value );
  1309. #endif
  1310. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1311. std::string toString( std::nullptr_t );
  1312. #endif
  1313. #ifdef __OBJC__
  1314. std::string toString( NSString const * const& nsstring );
  1315. std::string toString( NSString * CATCH_ARC_STRONG & nsstring );
  1316. std::string toString( NSObject* const& nsObject );
  1317. #endif
  1318. namespace Detail {
  1319. extern const std::string unprintableString;
  1320. #if !defined(CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK)
  1321. struct BorgType {
  1322. template<typename T> BorgType( T const& );
  1323. };
  1324. struct TrueType { char sizer[1]; };
  1325. struct FalseType { char sizer[2]; };
  1326. TrueType& testStreamable( std::ostream& );
  1327. FalseType testStreamable( FalseType );
  1328. FalseType operator<<( std::ostream const&, BorgType const& );
  1329. template<typename T>
  1330. struct IsStreamInsertable {
  1331. static std::ostream &s;
  1332. static T const&t;
  1333. enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
  1334. };
  1335. #else
  1336. template<typename T>
  1337. class IsStreamInsertable {
  1338. template<typename SS, typename TT>
  1339. static auto test(int)
  1340. -> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() );
  1341. template<typename, typename>
  1342. static auto test(...) -> std::false_type;
  1343. public:
  1344. static const bool value = decltype(test<std::ostream,const T&>(0))::value;
  1345. };
  1346. #endif
  1347. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1348. template<typename T,
  1349. bool IsEnum = std::is_enum<T>::value
  1350. >
  1351. struct EnumStringMaker
  1352. {
  1353. static std::string convert( T const& ) { return unprintableString; }
  1354. };
  1355. template<typename T>
  1356. struct EnumStringMaker<T,true>
  1357. {
  1358. static std::string convert( T const& v )
  1359. {
  1360. return ::Catch::toString(
  1361. static_cast<typename std::underlying_type<T>::type>(v)
  1362. );
  1363. }
  1364. };
  1365. #endif
  1366. template<bool C>
  1367. struct StringMakerBase {
  1368. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1369. template<typename T>
  1370. static std::string convert( T const& v )
  1371. {
  1372. return EnumStringMaker<T>::convert( v );
  1373. }
  1374. #else
  1375. template<typename T>
  1376. static std::string convert( T const& ) { return unprintableString; }
  1377. #endif
  1378. };
  1379. template<>
  1380. struct StringMakerBase<true> {
  1381. template<typename T>
  1382. static std::string convert( T const& _value ) {
  1383. std::ostringstream oss;
  1384. oss << _value;
  1385. return oss.str();
  1386. }
  1387. };
  1388. std::string rawMemoryToString( const void *object, std::size_t size );
  1389. template<typename T>
  1390. std::string rawMemoryToString( const T& object ) {
  1391. return rawMemoryToString( &object, sizeof(object) );
  1392. }
  1393. } // end namespace Detail
  1394. template<typename T>
  1395. struct StringMaker :
  1396. Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
  1397. template<typename T>
  1398. struct StringMaker<T*> {
  1399. template<typename U>
  1400. static std::string convert( U* p ) {
  1401. if( !p )
  1402. return "NULL";
  1403. else
  1404. return Detail::rawMemoryToString( p );
  1405. }
  1406. };
  1407. template<typename R, typename C>
  1408. struct StringMaker<R C::*> {
  1409. static std::string convert( R C::* p ) {
  1410. if( !p )
  1411. return "NULL";
  1412. else
  1413. return Detail::rawMemoryToString( p );
  1414. }
  1415. };
  1416. namespace Detail {
  1417. template<typename InputIterator>
  1418. std::string rangeToString( InputIterator first, InputIterator last );
  1419. }
  1420. //template<typename T, typename Allocator>
  1421. //struct StringMaker<std::vector<T, Allocator> > {
  1422. // static std::string convert( std::vector<T,Allocator> const& v ) {
  1423. // return Detail::rangeToString( v.begin(), v.end() );
  1424. // }
  1425. //};
  1426. template<typename T, typename Allocator>
  1427. std::string toString( std::vector<T,Allocator> const& v ) {
  1428. return Detail::rangeToString( v.begin(), v.end() );
  1429. }
  1430. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1431. // toString for tuples
  1432. namespace TupleDetail {
  1433. template<
  1434. typename Tuple,
  1435. std::size_t N = 0,
  1436. bool = (N < std::tuple_size<Tuple>::value)
  1437. >
  1438. struct ElementPrinter {
  1439. static void print( const Tuple& tuple, std::ostream& os )
  1440. {
  1441. os << ( N ? ", " : " " )
  1442. << Catch::toString(std::get<N>(tuple));
  1443. ElementPrinter<Tuple,N+1>::print(tuple,os);
  1444. }
  1445. };
  1446. template<
  1447. typename Tuple,
  1448. std::size_t N
  1449. >
  1450. struct ElementPrinter<Tuple,N,false> {
  1451. static void print( const Tuple&, std::ostream& ) {}
  1452. };
  1453. }
  1454. template<typename ...Types>
  1455. struct StringMaker<std::tuple<Types...>> {
  1456. static std::string convert( const std::tuple<Types...>& tuple )
  1457. {
  1458. std::ostringstream os;
  1459. os << '{';
  1460. TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
  1461. os << " }";
  1462. return os.str();
  1463. }
  1464. };
  1465. #endif // CATCH_CONFIG_CPP11_TUPLE
  1466. namespace Detail {
  1467. template<typename T>
  1468. std::string makeString( T const& value ) {
  1469. return StringMaker<T>::convert( value );
  1470. }
  1471. } // end namespace Detail
  1472. /// \brief converts any type to a string
  1473. ///
  1474. /// The default template forwards on to ostringstream - except when an
  1475. /// ostringstream overload does not exist - in which case it attempts to detect
  1476. /// that and writes {?}.
  1477. /// Overload (not specialise) this template for custom typs that you don't want
  1478. /// to provide an ostream overload for.
  1479. template<typename T>
  1480. std::string toString( T const& value ) {
  1481. return StringMaker<T>::convert( value );
  1482. }
  1483. namespace Detail {
  1484. template<typename InputIterator>
  1485. std::string rangeToString( InputIterator first, InputIterator last ) {
  1486. std::ostringstream oss;
  1487. oss << "{ ";
  1488. if( first != last ) {
  1489. oss << Catch::toString( *first );
  1490. for( ++first ; first != last ; ++first )
  1491. oss << ", " << Catch::toString( *first );
  1492. }
  1493. oss << " }";
  1494. return oss.str();
  1495. }
  1496. }
  1497. } // end namespace Catch
  1498. namespace Catch {
  1499. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1500. class BinaryExpression;
  1501. template<typename ArgT, typename MatcherT>
  1502. class MatchExpression;
  1503. // Wraps the LHS of an expression and overloads comparison operators
  1504. // for also capturing those and RHS (if any)
  1505. template<typename T>
  1506. class ExpressionLhs : public DecomposedExpression {
  1507. public:
  1508. ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {}
  1509. ExpressionLhs& operator = ( const ExpressionLhs& );
  1510. template<typename RhsT>
  1511. BinaryExpression<T, Internal::IsEqualTo, RhsT const&>
  1512. operator == ( RhsT const& rhs ) {
  1513. return captureExpression<Internal::IsEqualTo>( rhs );
  1514. }
  1515. template<typename RhsT>
  1516. BinaryExpression<T, Internal::IsNotEqualTo, RhsT const&>
  1517. operator != ( RhsT const& rhs ) {
  1518. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1519. }
  1520. template<typename RhsT>
  1521. BinaryExpression<T, Internal::IsLessThan, RhsT const&>
  1522. operator < ( RhsT const& rhs ) {
  1523. return captureExpression<Internal::IsLessThan>( rhs );
  1524. }
  1525. template<typename RhsT>
  1526. BinaryExpression<T, Internal::IsGreaterThan, RhsT const&>
  1527. operator > ( RhsT const& rhs ) {
  1528. return captureExpression<Internal::IsGreaterThan>( rhs );
  1529. }
  1530. template<typename RhsT>
  1531. BinaryExpression<T, Internal::IsLessThanOrEqualTo, RhsT const&>
  1532. operator <= ( RhsT const& rhs ) {
  1533. return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
  1534. }
  1535. template<typename RhsT>
  1536. BinaryExpression<T, Internal::IsGreaterThanOrEqualTo, RhsT const&>
  1537. operator >= ( RhsT const& rhs ) {
  1538. return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
  1539. }
  1540. BinaryExpression<T, Internal::IsEqualTo, bool> operator == ( bool rhs ) {
  1541. return captureExpression<Internal::IsEqualTo>( rhs );
  1542. }
  1543. BinaryExpression<T, Internal::IsNotEqualTo, bool> operator != ( bool rhs ) {
  1544. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1545. }
  1546. void endExpression() {
  1547. m_truthy = m_lhs ? true : false;
  1548. m_rb
  1549. .setResultType( m_truthy )
  1550. .endExpression( *this );
  1551. }
  1552. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1553. dest = Catch::toString( m_lhs );
  1554. }
  1555. private:
  1556. template<Internal::Operator Op, typename RhsT>
  1557. BinaryExpression<T, Op, RhsT&> captureExpression( RhsT& rhs ) const {
  1558. return BinaryExpression<T, Op, RhsT&>( m_rb, m_lhs, rhs );
  1559. }
  1560. template<Internal::Operator Op>
  1561. BinaryExpression<T, Op, bool> captureExpression( bool rhs ) const {
  1562. return BinaryExpression<T, Op, bool>( m_rb, m_lhs, rhs );
  1563. }
  1564. private:
  1565. ResultBuilder& m_rb;
  1566. T m_lhs;
  1567. bool m_truthy;
  1568. };
  1569. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1570. class BinaryExpression : public DecomposedExpression {
  1571. public:
  1572. BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs )
  1573. : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {}
  1574. BinaryExpression& operator = ( BinaryExpression& );
  1575. void endExpression() const {
  1576. m_rb
  1577. .setResultType( Internal::compare<Op>( m_lhs, m_rhs ) )
  1578. .endExpression( *this );
  1579. }
  1580. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1581. return true;
  1582. }
  1583. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1584. std::string lhs = Catch::toString( m_lhs );
  1585. std::string rhs = Catch::toString( m_rhs );
  1586. char delim = lhs.size() + rhs.size() < 40 &&
  1587. lhs.find('\n') == std::string::npos &&
  1588. rhs.find('\n') == std::string::npos ? ' ' : '\n';
  1589. dest.reserve( 7 + lhs.size() + rhs.size() );
  1590. // 2 for spaces around operator
  1591. // 2 for operator
  1592. // 2 for parentheses (conditionally added later)
  1593. // 1 for negation (conditionally added later)
  1594. dest = lhs;
  1595. dest += delim;
  1596. dest += Internal::OperatorTraits<Op>::getName();
  1597. dest += delim;
  1598. dest += rhs;
  1599. }
  1600. private:
  1601. ResultBuilder& m_rb;
  1602. LhsT m_lhs;
  1603. RhsT m_rhs;
  1604. };
  1605. template<typename ArgT, typename MatcherT>
  1606. class MatchExpression : public DecomposedExpression {
  1607. public:
  1608. MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString )
  1609. : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {}
  1610. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1611. return true;
  1612. }
  1613. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1614. std::string matcherAsString = m_matcher.toString();
  1615. dest = Catch::toString( m_arg );
  1616. dest += ' ';
  1617. if( matcherAsString == Detail::unprintableString )
  1618. dest += m_matcherString;
  1619. else
  1620. dest += matcherAsString;
  1621. }
  1622. private:
  1623. ArgT m_arg;
  1624. MatcherT m_matcher;
  1625. char const* m_matcherString;
  1626. };
  1627. } // end namespace Catch
  1628. namespace Catch {
  1629. template<typename T>
  1630. ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
  1631. return ExpressionLhs<T const&>( *this, operand );
  1632. }
  1633. inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
  1634. return ExpressionLhs<bool>( *this, value );
  1635. }
  1636. template<typename ArgT, typename MatcherT>
  1637. void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
  1638. char const* matcherString ) {
  1639. MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString );
  1640. setResultType( matcher.match( arg ) );
  1641. endExpression( expr );
  1642. }
  1643. } // namespace Catch
  1644. // #included from: catch_message.h
  1645. #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
  1646. #include <string>
  1647. namespace Catch {
  1648. struct MessageInfo {
  1649. MessageInfo( std::string const& _macroName,
  1650. SourceLineInfo const& _lineInfo,
  1651. ResultWas::OfType _type );
  1652. std::string macroName;
  1653. SourceLineInfo lineInfo;
  1654. ResultWas::OfType type;
  1655. std::string message;
  1656. unsigned int sequence;
  1657. bool operator == ( MessageInfo const& other ) const {
  1658. return sequence == other.sequence;
  1659. }
  1660. bool operator < ( MessageInfo const& other ) const {
  1661. return sequence < other.sequence;
  1662. }
  1663. private:
  1664. static unsigned int globalCount;
  1665. };
  1666. struct MessageBuilder {
  1667. MessageBuilder( std::string const& macroName,
  1668. SourceLineInfo const& lineInfo,
  1669. ResultWas::OfType type )
  1670. : m_info( macroName, lineInfo, type )
  1671. {}
  1672. template<typename T>
  1673. MessageBuilder& operator << ( T const& value ) {
  1674. m_stream << value;
  1675. return *this;
  1676. }
  1677. MessageInfo m_info;
  1678. std::ostringstream m_stream;
  1679. };
  1680. class ScopedMessage {
  1681. public:
  1682. ScopedMessage( MessageBuilder const& builder );
  1683. ScopedMessage( ScopedMessage const& other );
  1684. ~ScopedMessage();
  1685. MessageInfo m_info;
  1686. };
  1687. } // end namespace Catch
  1688. // #included from: catch_interfaces_capture.h
  1689. #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
  1690. #include <string>
  1691. namespace Catch {
  1692. class TestCase;
  1693. class AssertionResult;
  1694. struct AssertionInfo;
  1695. struct SectionInfo;
  1696. struct SectionEndInfo;
  1697. struct MessageInfo;
  1698. class ScopedMessageBuilder;
  1699. struct Counts;
  1700. struct IResultCapture {
  1701. virtual ~IResultCapture();
  1702. virtual void assertionEnded( AssertionResult const& result ) = 0;
  1703. virtual bool sectionStarted( SectionInfo const& sectionInfo,
  1704. Counts& assertions ) = 0;
  1705. virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
  1706. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
  1707. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  1708. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  1709. virtual std::string getCurrentTestName() const = 0;
  1710. virtual const AssertionResult* getLastResult() const = 0;
  1711. virtual void exceptionEarlyReported() = 0;
  1712. virtual void handleFatalErrorCondition( std::string const& message ) = 0;
  1713. virtual bool lastAssertionPassed() = 0;
  1714. virtual void assertionPassed() = 0;
  1715. virtual void assertionRun() = 0;
  1716. };
  1717. IResultCapture& getResultCapture();
  1718. }
  1719. // #included from: catch_debugger.h
  1720. #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
  1721. // #included from: catch_platform.h
  1722. #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED
  1723. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  1724. # define CATCH_PLATFORM_MAC
  1725. #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  1726. # define CATCH_PLATFORM_IPHONE
  1727. #elif defined(linux) || defined(__linux) || defined(__linux__)
  1728. # define CATCH_PLATFORM_LINUX
  1729. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  1730. # define CATCH_PLATFORM_WINDOWS
  1731. # if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
  1732. # define CATCH_DEFINES_NOMINMAX
  1733. # endif
  1734. # if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
  1735. # define CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  1736. # endif
  1737. #endif
  1738. #include <string>
  1739. namespace Catch{
  1740. bool isDebuggerActive();
  1741. void writeToDebugConsole( std::string const& text );
  1742. }
  1743. #ifdef CATCH_PLATFORM_MAC
  1744. // The following code snippet based on:
  1745. // http://cocoawithlove.com/2008/03/break-into-debugger.html
  1746. #if defined(__ppc64__) || defined(__ppc__)
  1747. #define CATCH_TRAP() \
  1748. __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  1749. : : : "memory","r0","r3","r4" ) /* NOLINT */
  1750. #elif defined(__aarch64__)
  1751. // Backport of https://github.com/catchorg/Catch2/commit/a25c1a24af8bffd35727a888a307ff0280cf9387
  1752. #define CATCH_TRAP() __asm__(".inst 0xd4200000")
  1753. #else
  1754. #define CATCH_TRAP() __asm__("int $3\n" : : /* NOLINT */ )
  1755. #endif
  1756. #elif defined(CATCH_PLATFORM_LINUX)
  1757. // If we can use inline assembler, do it because this allows us to break
  1758. // directly at the location of the failing check instead of breaking inside
  1759. // raise() called from it, i.e. one stack frame below.
  1760. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  1761. #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
  1762. #else // Fall back to the generic way.
  1763. #include <signal.h>
  1764. #define CATCH_TRAP() raise(SIGTRAP)
  1765. #endif
  1766. #elif defined(_MSC_VER)
  1767. #define CATCH_TRAP() __debugbreak()
  1768. #elif defined(__MINGW32__)
  1769. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  1770. #define CATCH_TRAP() DebugBreak()
  1771. #endif
  1772. #ifdef CATCH_TRAP
  1773. #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
  1774. #else
  1775. #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
  1776. #endif
  1777. // #included from: catch_interfaces_runner.h
  1778. #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
  1779. namespace Catch {
  1780. class TestCase;
  1781. struct IRunner {
  1782. virtual ~IRunner();
  1783. virtual bool aborting() const = 0;
  1784. };
  1785. }
  1786. #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
  1787. # define CATCH_INTERNAL_STRINGIFY(expr) #expr
  1788. #else
  1789. # define CATCH_INTERNAL_STRINGIFY(expr) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  1790. #endif
  1791. #if defined(CATCH_CONFIG_FAST_COMPILE)
  1792. ///////////////////////////////////////////////////////////////////////////////
  1793. // We can speedup compilation significantly by breaking into debugger lower in
  1794. // the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
  1795. // macro in each assertion
  1796. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1797. resultBuilder.react();
  1798. ///////////////////////////////////////////////////////////////////////////////
  1799. // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
  1800. // macros.
  1801. // This can potentially cause false negative, if the test code catches
  1802. // the exception before it propagates back up to the runner.
  1803. #define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \
  1804. do { \
  1805. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1806. __catchResult.setExceptionGuard(); \
  1807. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1808. ( __catchResult <= expr ).endExpression(); \
  1809. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1810. __catchResult.unsetExceptionGuard(); \
  1811. INTERNAL_CATCH_REACT( __catchResult ) \
  1812. } 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
  1813. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1814. #define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \
  1815. do { \
  1816. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1817. __catchResult.setExceptionGuard(); \
  1818. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1819. __catchResult.unsetExceptionGuard(); \
  1820. INTERNAL_CATCH_REACT( __catchResult ) \
  1821. } while( Catch::alwaysFalse() )
  1822. #else
  1823. ///////////////////////////////////////////////////////////////////////////////
  1824. // In the event of a failure works out if the debugger needs to be invoked
  1825. // and/or an exception thrown and takes appropriate action.
  1826. // This needs to be done as a macro so the debugger will stop in the user
  1827. // source code rather than in Catch library code
  1828. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1829. if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
  1830. resultBuilder.react();
  1831. #endif
  1832. ///////////////////////////////////////////////////////////////////////////////
  1833. #define INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ) \
  1834. do { \
  1835. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1836. try { \
  1837. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1838. ( __catchResult <= expr ).endExpression(); \
  1839. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1840. } \
  1841. catch( ... ) { \
  1842. __catchResult.useActiveException( resultDisposition ); \
  1843. } \
  1844. INTERNAL_CATCH_REACT( __catchResult ) \
  1845. } 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
  1846. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1847. ///////////////////////////////////////////////////////////////////////////////
  1848. #define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \
  1849. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1850. if( Catch::getResultCapture().lastAssertionPassed() )
  1851. ///////////////////////////////////////////////////////////////////////////////
  1852. #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \
  1853. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1854. if( !Catch::getResultCapture().lastAssertionPassed() )
  1855. ///////////////////////////////////////////////////////////////////////////////
  1856. #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \
  1857. do { \
  1858. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1859. try { \
  1860. static_cast<void>(expr); \
  1861. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1862. } \
  1863. catch( ... ) { \
  1864. __catchResult.useActiveException( resultDisposition ); \
  1865. } \
  1866. INTERNAL_CATCH_REACT( __catchResult ) \
  1867. } while( Catch::alwaysFalse() )
  1868. ///////////////////////////////////////////////////////////////////////////////
  1869. #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \
  1870. do { \
  1871. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1872. if( __catchResult.allowThrows() ) \
  1873. try { \
  1874. static_cast<void>(expr); \
  1875. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1876. } \
  1877. catch( ... ) { \
  1878. __catchResult.captureExpectedException( matcher ); \
  1879. } \
  1880. else \
  1881. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1882. INTERNAL_CATCH_REACT( __catchResult ) \
  1883. } while( Catch::alwaysFalse() )
  1884. ///////////////////////////////////////////////////////////////////////////////
  1885. #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
  1886. do { \
  1887. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
  1888. if( __catchResult.allowThrows() ) \
  1889. try { \
  1890. static_cast<void>(expr); \
  1891. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1892. } \
  1893. catch( exceptionType ) { \
  1894. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1895. } \
  1896. catch( ... ) { \
  1897. __catchResult.useActiveException( resultDisposition ); \
  1898. } \
  1899. else \
  1900. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1901. INTERNAL_CATCH_REACT( __catchResult ) \
  1902. } while( Catch::alwaysFalse() )
  1903. ///////////////////////////////////////////////////////////////////////////////
  1904. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  1905. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
  1906. do { \
  1907. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1908. __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
  1909. __catchResult.captureResult( messageType ); \
  1910. INTERNAL_CATCH_REACT( __catchResult ) \
  1911. } while( Catch::alwaysFalse() )
  1912. #else
  1913. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, log ) \
  1914. do { \
  1915. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1916. __catchResult << log + ::Catch::StreamEndStop(); \
  1917. __catchResult.captureResult( messageType ); \
  1918. INTERNAL_CATCH_REACT( __catchResult ) \
  1919. } while( Catch::alwaysFalse() )
  1920. #endif
  1921. ///////////////////////////////////////////////////////////////////////////////
  1922. #define INTERNAL_CATCH_INFO( macroName, log ) \
  1923. Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
  1924. ///////////////////////////////////////////////////////////////////////////////
  1925. #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
  1926. do { \
  1927. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1928. try { \
  1929. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1930. } catch( ... ) { \
  1931. __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
  1932. } \
  1933. INTERNAL_CATCH_REACT( __catchResult ) \
  1934. } while( Catch::alwaysFalse() )
  1935. // #included from: internal/catch_section.h
  1936. #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
  1937. // #included from: catch_section_info.h
  1938. #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
  1939. // #included from: catch_totals.hpp
  1940. #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
  1941. #include <cstddef>
  1942. namespace Catch {
  1943. struct Counts {
  1944. Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
  1945. Counts operator - ( Counts const& other ) const {
  1946. Counts diff;
  1947. diff.passed = passed - other.passed;
  1948. diff.failed = failed - other.failed;
  1949. diff.failedButOk = failedButOk - other.failedButOk;
  1950. return diff;
  1951. }
  1952. Counts& operator += ( Counts const& other ) {
  1953. passed += other.passed;
  1954. failed += other.failed;
  1955. failedButOk += other.failedButOk;
  1956. return *this;
  1957. }
  1958. std::size_t total() const {
  1959. return passed + failed + failedButOk;
  1960. }
  1961. bool allPassed() const {
  1962. return failed == 0 && failedButOk == 0;
  1963. }
  1964. bool allOk() const {
  1965. return failed == 0;
  1966. }
  1967. std::size_t passed;
  1968. std::size_t failed;
  1969. std::size_t failedButOk;
  1970. };
  1971. struct Totals {
  1972. Totals operator - ( Totals const& other ) const {
  1973. Totals diff;
  1974. diff.assertions = assertions - other.assertions;
  1975. diff.testCases = testCases - other.testCases;
  1976. return diff;
  1977. }
  1978. Totals delta( Totals const& prevTotals ) const {
  1979. Totals diff = *this - prevTotals;
  1980. if( diff.assertions.failed > 0 )
  1981. ++diff.testCases.failed;
  1982. else if( diff.assertions.failedButOk > 0 )
  1983. ++diff.testCases.failedButOk;
  1984. else
  1985. ++diff.testCases.passed;
  1986. return diff;
  1987. }
  1988. Totals& operator += ( Totals const& other ) {
  1989. assertions += other.assertions;
  1990. testCases += other.testCases;
  1991. return *this;
  1992. }
  1993. Counts assertions;
  1994. Counts testCases;
  1995. };
  1996. }
  1997. #include <string>
  1998. namespace Catch {
  1999. struct SectionInfo {
  2000. SectionInfo
  2001. ( SourceLineInfo const& _lineInfo,
  2002. std::string const& _name,
  2003. std::string const& _description = std::string() );
  2004. std::string name;
  2005. std::string description;
  2006. SourceLineInfo lineInfo;
  2007. };
  2008. struct SectionEndInfo {
  2009. SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
  2010. : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
  2011. {}
  2012. SectionInfo sectionInfo;
  2013. Counts prevAssertions;
  2014. double durationInSeconds;
  2015. };
  2016. } // end namespace Catch
  2017. // #included from: catch_timer.h
  2018. #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED
  2019. #ifdef _MSC_VER
  2020. namespace Catch {
  2021. typedef unsigned long long UInt64;
  2022. }
  2023. #else
  2024. #include <stdint.h>
  2025. namespace Catch {
  2026. typedef uint64_t UInt64;
  2027. }
  2028. #endif
  2029. namespace Catch {
  2030. class Timer {
  2031. public:
  2032. Timer() : m_ticks( 0 ) {}
  2033. void start();
  2034. unsigned int getElapsedMicroseconds() const;
  2035. unsigned int getElapsedMilliseconds() const;
  2036. double getElapsedSeconds() const;
  2037. private:
  2038. UInt64 m_ticks;
  2039. };
  2040. } // namespace Catch
  2041. #include <string>
  2042. namespace Catch {
  2043. class Section : NonCopyable {
  2044. public:
  2045. Section( SectionInfo const& info );
  2046. ~Section();
  2047. // This indicates whether the section should be executed or not
  2048. operator bool() const;
  2049. private:
  2050. SectionInfo m_info;
  2051. std::string m_name;
  2052. Counts m_assertions;
  2053. bool m_sectionIncluded;
  2054. Timer m_timer;
  2055. };
  2056. } // end namespace Catch
  2057. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  2058. #define INTERNAL_CATCH_SECTION( ... ) \
  2059. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
  2060. #else
  2061. #define INTERNAL_CATCH_SECTION( name, desc ) \
  2062. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
  2063. #endif
  2064. // #included from: internal/catch_generators.hpp
  2065. #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
  2066. #include <vector>
  2067. #include <string>
  2068. #include <stdlib.h>
  2069. namespace Catch {
  2070. template<typename T>
  2071. struct IGenerator {
  2072. virtual ~IGenerator() {}
  2073. virtual T getValue( std::size_t index ) const = 0;
  2074. virtual std::size_t size () const = 0;
  2075. };
  2076. template<typename T>
  2077. class BetweenGenerator : public IGenerator<T> {
  2078. public:
  2079. BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
  2080. virtual T getValue( std::size_t index ) const {
  2081. return m_from+static_cast<int>( index );
  2082. }
  2083. virtual std::size_t size() const {
  2084. return static_cast<std::size_t>( 1+m_to-m_from );
  2085. }
  2086. private:
  2087. T m_from;
  2088. T m_to;
  2089. };
  2090. template<typename T>
  2091. class ValuesGenerator : public IGenerator<T> {
  2092. public:
  2093. ValuesGenerator(){}
  2094. void add( T value ) {
  2095. m_values.push_back( value );
  2096. }
  2097. virtual T getValue( std::size_t index ) const {
  2098. return m_values[index];
  2099. }
  2100. virtual std::size_t size() const {
  2101. return m_values.size();
  2102. }
  2103. private:
  2104. std::vector<T> m_values;
  2105. };
  2106. template<typename T>
  2107. class CompositeGenerator {
  2108. public:
  2109. CompositeGenerator() : m_totalSize( 0 ) {}
  2110. // *** Move semantics, similar to auto_ptr ***
  2111. CompositeGenerator( CompositeGenerator& other )
  2112. : m_fileInfo( other.m_fileInfo ),
  2113. m_totalSize( 0 )
  2114. {
  2115. move( other );
  2116. }
  2117. CompositeGenerator& setFileInfo( const char* fileInfo ) {
  2118. m_fileInfo = fileInfo;
  2119. return *this;
  2120. }
  2121. ~CompositeGenerator() {
  2122. deleteAll( m_composed );
  2123. }
  2124. operator T () const {
  2125. size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
  2126. typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
  2127. typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
  2128. for( size_t index = 0; it != itEnd; ++it )
  2129. {
  2130. const IGenerator<T>* generator = *it;
  2131. if( overallIndex >= index && overallIndex < index + generator->size() )
  2132. {
  2133. return generator->getValue( overallIndex-index );
  2134. }
  2135. index += generator->size();
  2136. }
  2137. CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
  2138. 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
  2139. }
  2140. void add( const IGenerator<T>* generator ) {
  2141. m_totalSize += generator->size();
  2142. m_composed.push_back( generator );
  2143. }
  2144. CompositeGenerator& then( CompositeGenerator& other ) {
  2145. move( other );
  2146. return *this;
  2147. }
  2148. CompositeGenerator& then( T value ) {
  2149. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2150. valuesGen->add( value );
  2151. add( valuesGen );
  2152. return *this;
  2153. }
  2154. private:
  2155. void move( CompositeGenerator& other ) {
  2156. m_composed.insert( m_composed.end(), other.m_composed.begin(), other.m_composed.end() );
  2157. m_totalSize += other.m_totalSize;
  2158. other.m_composed.clear();
  2159. }
  2160. std::vector<const IGenerator<T>*> m_composed;
  2161. std::string m_fileInfo;
  2162. size_t m_totalSize;
  2163. };
  2164. namespace Generators
  2165. {
  2166. template<typename T>
  2167. CompositeGenerator<T> between( T from, T to ) {
  2168. CompositeGenerator<T> generators;
  2169. generators.add( new BetweenGenerator<T>( from, to ) );
  2170. return generators;
  2171. }
  2172. template<typename T>
  2173. CompositeGenerator<T> values( T val1, T val2 ) {
  2174. CompositeGenerator<T> generators;
  2175. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2176. valuesGen->add( val1 );
  2177. valuesGen->add( val2 );
  2178. generators.add( valuesGen );
  2179. return generators;
  2180. }
  2181. template<typename T>
  2182. CompositeGenerator<T> values( T val1, T val2, T val3 ){
  2183. CompositeGenerator<T> generators;
  2184. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2185. valuesGen->add( val1 );
  2186. valuesGen->add( val2 );
  2187. valuesGen->add( val3 );
  2188. generators.add( valuesGen );
  2189. return generators;
  2190. }
  2191. template<typename T>
  2192. CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
  2193. CompositeGenerator<T> generators;
  2194. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2195. valuesGen->add( val1 );
  2196. valuesGen->add( val2 );
  2197. valuesGen->add( val3 );
  2198. valuesGen->add( val4 );
  2199. generators.add( valuesGen );
  2200. return generators;
  2201. }
  2202. } // end namespace Generators
  2203. using namespace Generators;
  2204. } // end namespace Catch
  2205. #define INTERNAL_CATCH_LINESTR2( line ) #line
  2206. #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
  2207. #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
  2208. // #included from: internal/catch_interfaces_exception.h
  2209. #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
  2210. #include <string>
  2211. #include <vector>
  2212. // #included from: catch_interfaces_registry_hub.h
  2213. #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
  2214. #include <string>
  2215. namespace Catch {
  2216. class TestCase;
  2217. struct ITestCaseRegistry;
  2218. struct IExceptionTranslatorRegistry;
  2219. struct IExceptionTranslator;
  2220. struct IReporterRegistry;
  2221. struct IReporterFactory;
  2222. struct ITagAliasRegistry;
  2223. struct IRegistryHub {
  2224. virtual ~IRegistryHub();
  2225. virtual IReporterRegistry const& getReporterRegistry() const = 0;
  2226. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  2227. virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
  2228. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
  2229. };
  2230. struct IMutableRegistryHub {
  2231. virtual ~IMutableRegistryHub();
  2232. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
  2233. virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
  2234. virtual void registerTest( TestCase const& testInfo ) = 0;
  2235. virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
  2236. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
  2237. };
  2238. IRegistryHub& getRegistryHub();
  2239. IMutableRegistryHub& getMutableRegistryHub();
  2240. void cleanUp();
  2241. std::string translateActiveException();
  2242. }
  2243. namespace Catch {
  2244. typedef std::string(*exceptionTranslateFunction)();
  2245. struct IExceptionTranslator;
  2246. typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
  2247. struct IExceptionTranslator {
  2248. virtual ~IExceptionTranslator();
  2249. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  2250. };
  2251. struct IExceptionTranslatorRegistry {
  2252. virtual ~IExceptionTranslatorRegistry();
  2253. virtual std::string translateActiveException() const = 0;
  2254. };
  2255. class ExceptionTranslatorRegistrar {
  2256. template<typename T>
  2257. class ExceptionTranslator : public IExceptionTranslator {
  2258. public:
  2259. ExceptionTranslator( std::string(*translateFunction)( T& ) )
  2260. : m_translateFunction( translateFunction )
  2261. {}
  2262. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
  2263. try {
  2264. if( it == itEnd )
  2265. throw;
  2266. else
  2267. return (*it)->translate( it+1, itEnd );
  2268. }
  2269. catch( T& ex ) {
  2270. return m_translateFunction( ex );
  2271. }
  2272. }
  2273. protected:
  2274. std::string(*m_translateFunction)( T& );
  2275. };
  2276. public:
  2277. template<typename T>
  2278. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
  2279. getMutableRegistryHub().registerTranslator
  2280. ( new ExceptionTranslator<T>( translateFunction ) );
  2281. }
  2282. };
  2283. }
  2284. ///////////////////////////////////////////////////////////////////////////////
  2285. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  2286. static std::string translatorName( signature ); \
  2287. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\
  2288. static std::string translatorName( signature )
  2289. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  2290. // #included from: internal/catch_approx.hpp
  2291. #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
  2292. #include <cmath>
  2293. #include <limits>
  2294. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2295. #include <type_traits>
  2296. #endif
  2297. namespace Catch {
  2298. namespace Detail {
  2299. class Approx {
  2300. public:
  2301. explicit Approx ( double value )
  2302. : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
  2303. m_margin( 0.0 ),
  2304. m_scale( 1.0 ),
  2305. m_value( value )
  2306. {}
  2307. static Approx custom() {
  2308. return Approx( 0 );
  2309. }
  2310. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2311. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2312. Approx operator()( T value ) {
  2313. Approx approx( static_cast<double>(value) );
  2314. approx.epsilon( m_epsilon );
  2315. approx.margin( m_margin );
  2316. approx.scale( m_scale );
  2317. return approx;
  2318. }
  2319. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2320. explicit Approx( T value ): Approx(static_cast<double>(value))
  2321. {}
  2322. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2323. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2324. // Thanks to Richard Harris for his help refining this formula
  2325. auto lhs_v = double(lhs);
  2326. 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)));
  2327. if (relativeOK) {
  2328. return true;
  2329. }
  2330. return std::fabs(lhs_v - rhs.m_value) <= rhs.m_margin;
  2331. }
  2332. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2333. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2334. return operator==( rhs, lhs );
  2335. }
  2336. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2337. friend bool operator != ( T lhs, Approx const& rhs ) {
  2338. return !operator==( lhs, rhs );
  2339. }
  2340. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2341. friend bool operator != ( Approx const& lhs, T rhs ) {
  2342. return !operator==( rhs, lhs );
  2343. }
  2344. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2345. friend bool operator <= ( T lhs, Approx const& rhs ) {
  2346. return double(lhs) < rhs.m_value || lhs == rhs;
  2347. }
  2348. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2349. friend bool operator <= ( Approx const& lhs, T rhs ) {
  2350. return lhs.m_value < double(rhs) || lhs == rhs;
  2351. }
  2352. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2353. friend bool operator >= ( T lhs, Approx const& rhs ) {
  2354. return double(lhs) > rhs.m_value || lhs == rhs;
  2355. }
  2356. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2357. friend bool operator >= ( Approx const& lhs, T rhs ) {
  2358. return lhs.m_value > double(rhs) || lhs == rhs;
  2359. }
  2360. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2361. Approx& epsilon( T newEpsilon ) {
  2362. m_epsilon = double(newEpsilon);
  2363. return *this;
  2364. }
  2365. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2366. Approx& margin( T newMargin ) {
  2367. m_margin = double(newMargin);
  2368. return *this;
  2369. }
  2370. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2371. Approx& scale( T newScale ) {
  2372. m_scale = double(newScale);
  2373. return *this;
  2374. }
  2375. #else
  2376. Approx operator()( double value ) {
  2377. Approx approx( value );
  2378. approx.epsilon( m_epsilon );
  2379. approx.margin( m_margin );
  2380. approx.scale( m_scale );
  2381. return approx;
  2382. }
  2383. friend bool operator == ( double lhs, Approx const& rhs ) {
  2384. // Thanks to Richard Harris for his help refining this formula
  2385. bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) );
  2386. if (relativeOK) {
  2387. return true;
  2388. }
  2389. return std::fabs(lhs - rhs.m_value) <= rhs.m_margin;
  2390. }
  2391. friend bool operator == ( Approx const& lhs, double rhs ) {
  2392. return operator==( rhs, lhs );
  2393. }
  2394. friend bool operator != ( double lhs, Approx const& rhs ) {
  2395. return !operator==( lhs, rhs );
  2396. }
  2397. friend bool operator != ( Approx const& lhs, double rhs ) {
  2398. return !operator==( rhs, lhs );
  2399. }
  2400. friend bool operator <= ( double lhs, Approx const& rhs ) {
  2401. return lhs < rhs.m_value || lhs == rhs;
  2402. }
  2403. friend bool operator <= ( Approx const& lhs, double rhs ) {
  2404. return lhs.m_value < rhs || lhs == rhs;
  2405. }
  2406. friend bool operator >= ( double lhs, Approx const& rhs ) {
  2407. return lhs > rhs.m_value || lhs == rhs;
  2408. }
  2409. friend bool operator >= ( Approx const& lhs, double rhs ) {
  2410. return lhs.m_value > rhs || lhs == rhs;
  2411. }
  2412. Approx& epsilon( double newEpsilon ) {
  2413. m_epsilon = newEpsilon;
  2414. return *this;
  2415. }
  2416. Approx& margin( double newMargin ) {
  2417. m_margin = newMargin;
  2418. return *this;
  2419. }
  2420. Approx& scale( double newScale ) {
  2421. m_scale = newScale;
  2422. return *this;
  2423. }
  2424. #endif
  2425. std::string toString() const {
  2426. std::ostringstream oss;
  2427. oss << "Approx( " << Catch::toString( m_value ) << " )";
  2428. return oss.str();
  2429. }
  2430. private:
  2431. double m_epsilon;
  2432. double m_margin;
  2433. double m_scale;
  2434. double m_value;
  2435. };
  2436. }
  2437. template<>
  2438. inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
  2439. return value.toString();
  2440. }
  2441. } // end namespace Catch
  2442. // #included from: internal/catch_matchers_string.h
  2443. #define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
  2444. namespace Catch {
  2445. namespace Matchers {
  2446. namespace StdString {
  2447. struct CasedString
  2448. {
  2449. CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
  2450. std::string adjustString( std::string const& str ) const;
  2451. std::string caseSensitivitySuffix() const;
  2452. CaseSensitive::Choice m_caseSensitivity;
  2453. std::string m_str;
  2454. };
  2455. struct StringMatcherBase : MatcherBase<std::string> {
  2456. StringMatcherBase( std::string const& operation, CasedString const& comparator );
  2457. virtual std::string describe() const CATCH_OVERRIDE;
  2458. CasedString m_comparator;
  2459. std::string m_operation;
  2460. };
  2461. struct EqualsMatcher : StringMatcherBase {
  2462. EqualsMatcher( CasedString const& comparator );
  2463. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2464. };
  2465. struct ContainsMatcher : StringMatcherBase {
  2466. ContainsMatcher( CasedString const& comparator );
  2467. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2468. };
  2469. struct StartsWithMatcher : StringMatcherBase {
  2470. StartsWithMatcher( CasedString const& comparator );
  2471. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2472. };
  2473. struct EndsWithMatcher : StringMatcherBase {
  2474. EndsWithMatcher( CasedString const& comparator );
  2475. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2476. };
  2477. } // namespace StdString
  2478. // The following functions create the actual matcher objects.
  2479. // This allows the types to be inferred
  2480. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2481. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2482. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2483. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2484. } // namespace Matchers
  2485. } // namespace Catch
  2486. // #included from: internal/catch_matchers_vector.h
  2487. #define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED
  2488. namespace Catch {
  2489. namespace Matchers {
  2490. namespace Vector {
  2491. template<typename T>
  2492. struct ContainsElementMatcher : MatcherBase<std::vector<T>, T> {
  2493. ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
  2494. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2495. return std::find(v.begin(), v.end(), m_comparator) != v.end();
  2496. }
  2497. virtual std::string describe() const CATCH_OVERRIDE {
  2498. return "Contains: " + Catch::toString( m_comparator );
  2499. }
  2500. T const& m_comparator;
  2501. };
  2502. template<typename T>
  2503. struct ContainsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2504. ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2505. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2506. // !TBD: see note in EqualsMatcher
  2507. if (m_comparator.size() > v.size())
  2508. return false;
  2509. for (size_t i = 0; i < m_comparator.size(); ++i)
  2510. if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end())
  2511. return false;
  2512. return true;
  2513. }
  2514. virtual std::string describe() const CATCH_OVERRIDE {
  2515. return "Contains: " + Catch::toString( m_comparator );
  2516. }
  2517. std::vector<T> const& m_comparator;
  2518. };
  2519. template<typename T>
  2520. struct EqualsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2521. EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2522. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2523. // !TBD: This currently works if all elements can be compared using !=
  2524. // - a more general approach would be via a compare template that defaults
  2525. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  2526. // - then just call that directly
  2527. if (m_comparator.size() != v.size())
  2528. return false;
  2529. for (size_t i = 0; i < v.size(); ++i)
  2530. if (m_comparator[i] != v[i])
  2531. return false;
  2532. return true;
  2533. }
  2534. virtual std::string describe() const CATCH_OVERRIDE {
  2535. return "Equals: " + Catch::toString( m_comparator );
  2536. }
  2537. std::vector<T> const& m_comparator;
  2538. };
  2539. } // namespace Vector
  2540. // The following functions create the actual matcher objects.
  2541. // This allows the types to be inferred
  2542. template<typename T>
  2543. Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
  2544. return Vector::ContainsMatcher<T>( comparator );
  2545. }
  2546. template<typename T>
  2547. Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) {
  2548. return Vector::ContainsElementMatcher<T>( comparator );
  2549. }
  2550. template<typename T>
  2551. Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
  2552. return Vector::EqualsMatcher<T>( comparator );
  2553. }
  2554. } // namespace Matchers
  2555. } // namespace Catch
  2556. // #included from: internal/catch_interfaces_tag_alias_registry.h
  2557. #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
  2558. // #included from: catch_tag_alias.h
  2559. #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED
  2560. #include <string>
  2561. namespace Catch {
  2562. struct TagAlias {
  2563. TagAlias( std::string const& _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
  2564. std::string tag;
  2565. SourceLineInfo lineInfo;
  2566. };
  2567. struct RegistrarForTagAliases {
  2568. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  2569. };
  2570. } // end namespace Catch
  2571. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); }
  2572. // #included from: catch_option.hpp
  2573. #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
  2574. namespace Catch {
  2575. // An optional type
  2576. template<typename T>
  2577. class Option {
  2578. public:
  2579. Option() : nullableValue( CATCH_NULL ) {}
  2580. Option( T const& _value )
  2581. : nullableValue( new( storage ) T( _value ) )
  2582. {}
  2583. Option( Option const& _other )
  2584. : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
  2585. {}
  2586. ~Option() {
  2587. reset();
  2588. }
  2589. Option& operator= ( Option const& _other ) {
  2590. if( &_other != this ) {
  2591. reset();
  2592. if( _other )
  2593. nullableValue = new( storage ) T( *_other );
  2594. }
  2595. return *this;
  2596. }
  2597. Option& operator = ( T const& _value ) {
  2598. reset();
  2599. nullableValue = new( storage ) T( _value );
  2600. return *this;
  2601. }
  2602. void reset() {
  2603. if( nullableValue )
  2604. nullableValue->~T();
  2605. nullableValue = CATCH_NULL;
  2606. }
  2607. T& operator*() { return *nullableValue; }
  2608. T const& operator*() const { return *nullableValue; }
  2609. T* operator->() { return nullableValue; }
  2610. const T* operator->() const { return nullableValue; }
  2611. T valueOr( T const& defaultValue ) const {
  2612. return nullableValue ? *nullableValue : defaultValue;
  2613. }
  2614. bool some() const { return nullableValue != CATCH_NULL; }
  2615. bool none() const { return nullableValue == CATCH_NULL; }
  2616. bool operator !() const { return nullableValue == CATCH_NULL; }
  2617. operator SafeBool::type() const {
  2618. return SafeBool::makeSafe( some() );
  2619. }
  2620. private:
  2621. T *nullableValue;
  2622. union {
  2623. char storage[sizeof(T)];
  2624. // These are here to force alignment for the storage
  2625. long double dummy1;
  2626. void (*dummy2)();
  2627. long double dummy3;
  2628. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  2629. long long dummy4;
  2630. #endif
  2631. };
  2632. };
  2633. } // end namespace Catch
  2634. namespace Catch {
  2635. struct ITagAliasRegistry {
  2636. virtual ~ITagAliasRegistry();
  2637. virtual Option<TagAlias> find( std::string const& alias ) const = 0;
  2638. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  2639. static ITagAliasRegistry const& get();
  2640. };
  2641. } // end namespace Catch
  2642. // These files are included here so the single_include script doesn't put them
  2643. // in the conditionally compiled sections
  2644. // #included from: internal/catch_test_case_info.h
  2645. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
  2646. #include <string>
  2647. #include <set>
  2648. #ifdef __clang__
  2649. #pragma clang diagnostic push
  2650. #pragma clang diagnostic ignored "-Wpadded"
  2651. #endif
  2652. namespace Catch {
  2653. struct ITestCase;
  2654. struct TestCaseInfo {
  2655. enum SpecialProperties{
  2656. None = 0,
  2657. IsHidden = 1 << 1,
  2658. ShouldFail = 1 << 2,
  2659. MayFail = 1 << 3,
  2660. Throws = 1 << 4,
  2661. NonPortable = 1 << 5
  2662. };
  2663. TestCaseInfo( std::string const& _name,
  2664. std::string const& _className,
  2665. std::string const& _description,
  2666. std::set<std::string> const& _tags,
  2667. SourceLineInfo const& _lineInfo );
  2668. TestCaseInfo( TestCaseInfo const& other );
  2669. friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
  2670. bool isHidden() const;
  2671. bool throws() const;
  2672. bool okToFail() const;
  2673. bool expectedToFail() const;
  2674. std::string name;
  2675. std::string className;
  2676. std::string description;
  2677. std::set<std::string> tags;
  2678. std::set<std::string> lcaseTags;
  2679. std::string tagsAsString;
  2680. SourceLineInfo lineInfo;
  2681. SpecialProperties properties;
  2682. };
  2683. class TestCase : public TestCaseInfo {
  2684. public:
  2685. TestCase( ITestCase* testCase, TestCaseInfo const& info );
  2686. TestCase( TestCase const& other );
  2687. TestCase withName( std::string const& _newName ) const;
  2688. void invoke() const;
  2689. TestCaseInfo const& getTestCaseInfo() const;
  2690. void swap( TestCase& other );
  2691. bool operator == ( TestCase const& other ) const;
  2692. bool operator < ( TestCase const& other ) const;
  2693. TestCase& operator = ( TestCase const& other );
  2694. private:
  2695. Ptr<ITestCase> test;
  2696. };
  2697. TestCase makeTestCase( ITestCase* testCase,
  2698. std::string const& className,
  2699. std::string const& name,
  2700. std::string const& description,
  2701. SourceLineInfo const& lineInfo );
  2702. }
  2703. #ifdef __clang__
  2704. #pragma clang diagnostic pop
  2705. #endif
  2706. #ifdef __OBJC__
  2707. // #included from: internal/catch_objc.hpp
  2708. #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
  2709. #import <objc/runtime.h>
  2710. #include <string>
  2711. // NB. Any general catch headers included here must be included
  2712. // in catch.hpp first to make sure they are included by the single
  2713. // header for non obj-usage
  2714. ///////////////////////////////////////////////////////////////////////////////
  2715. // This protocol is really only here for (self) documenting purposes, since
  2716. // all its methods are optional.
  2717. @protocol OcFixture
  2718. @optional
  2719. -(void) setUp;
  2720. -(void) tearDown;
  2721. @end
  2722. namespace Catch {
  2723. class OcMethod : public SharedImpl<ITestCase> {
  2724. public:
  2725. OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
  2726. virtual void invoke() const {
  2727. id obj = [[m_cls alloc] init];
  2728. performOptionalSelector( obj, @selector(setUp) );
  2729. performOptionalSelector( obj, m_sel );
  2730. performOptionalSelector( obj, @selector(tearDown) );
  2731. arcSafeRelease( obj );
  2732. }
  2733. private:
  2734. virtual ~OcMethod() {}
  2735. Class m_cls;
  2736. SEL m_sel;
  2737. };
  2738. namespace Detail{
  2739. inline std::string getAnnotation( Class cls,
  2740. std::string const& annotationName,
  2741. std::string const& testCaseName ) {
  2742. NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
  2743. SEL sel = NSSelectorFromString( selStr );
  2744. arcSafeRelease( selStr );
  2745. id value = performOptionalSelector( cls, sel );
  2746. if( value )
  2747. return [(NSString*)value UTF8String];
  2748. return "";
  2749. }
  2750. }
  2751. inline size_t registerTestMethods() {
  2752. size_t noTestMethods = 0;
  2753. int noClasses = objc_getClassList( CATCH_NULL, 0 );
  2754. Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
  2755. objc_getClassList( classes, noClasses );
  2756. for( int c = 0; c < noClasses; c++ ) {
  2757. Class cls = classes[c];
  2758. {
  2759. u_int count;
  2760. Method* methods = class_copyMethodList( cls, &count );
  2761. for( u_int m = 0; m < count ; m++ ) {
  2762. SEL selector = method_getName(methods[m]);
  2763. std::string methodName = sel_getName(selector);
  2764. if( startsWith( methodName, "Catch_TestCase_" ) ) {
  2765. std::string testCaseName = methodName.substr( 15 );
  2766. std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
  2767. std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
  2768. const char* className = class_getName( cls );
  2769. getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
  2770. noTestMethods++;
  2771. }
  2772. }
  2773. free(methods);
  2774. }
  2775. }
  2776. return noTestMethods;
  2777. }
  2778. namespace Matchers {
  2779. namespace Impl {
  2780. namespace NSStringMatchers {
  2781. struct StringHolder : MatcherBase<NSString*>{
  2782. StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
  2783. StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
  2784. StringHolder() {
  2785. arcSafeRelease( m_substr );
  2786. }
  2787. virtual bool match( NSString* arg ) const CATCH_OVERRIDE {
  2788. return false;
  2789. }
  2790. NSString* m_substr;
  2791. };
  2792. struct Equals : StringHolder {
  2793. Equals( NSString* substr ) : StringHolder( substr ){}
  2794. virtual bool match( NSString* str ) const CATCH_OVERRIDE {
  2795. return (str != nil || m_substr == nil ) &&
  2796. [str isEqualToString:m_substr];
  2797. }
  2798. virtual std::string describe() const CATCH_OVERRIDE {
  2799. return "equals string: " + Catch::toString( m_substr );
  2800. }
  2801. };
  2802. struct Contains : StringHolder {
  2803. Contains( NSString* substr ) : StringHolder( substr ){}
  2804. virtual bool match( NSString* str ) const {
  2805. return (str != nil || m_substr == nil ) &&
  2806. [str rangeOfString:m_substr].location != NSNotFound;
  2807. }
  2808. virtual std::string describe() const CATCH_OVERRIDE {
  2809. return "contains string: " + Catch::toString( m_substr );
  2810. }
  2811. };
  2812. struct StartsWith : StringHolder {
  2813. StartsWith( NSString* substr ) : StringHolder( substr ){}
  2814. virtual bool match( NSString* str ) const {
  2815. return (str != nil || m_substr == nil ) &&
  2816. [str rangeOfString:m_substr].location == 0;
  2817. }
  2818. virtual std::string describe() const CATCH_OVERRIDE {
  2819. return "starts with: " + Catch::toString( m_substr );
  2820. }
  2821. };
  2822. struct EndsWith : StringHolder {
  2823. EndsWith( NSString* substr ) : StringHolder( substr ){}
  2824. virtual bool match( NSString* str ) const {
  2825. return (str != nil || m_substr == nil ) &&
  2826. [str rangeOfString:m_substr].location == [str length] - [m_substr length];
  2827. }
  2828. virtual std::string describe() const CATCH_OVERRIDE {
  2829. return "ends with: " + Catch::toString( m_substr );
  2830. }
  2831. };
  2832. } // namespace NSStringMatchers
  2833. } // namespace Impl
  2834. inline Impl::NSStringMatchers::Equals
  2835. Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
  2836. inline Impl::NSStringMatchers::Contains
  2837. Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
  2838. inline Impl::NSStringMatchers::StartsWith
  2839. StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
  2840. inline Impl::NSStringMatchers::EndsWith
  2841. EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
  2842. } // namespace Matchers
  2843. using namespace Matchers;
  2844. } // namespace Catch
  2845. ///////////////////////////////////////////////////////////////////////////////
  2846. #define OC_TEST_CASE( name, desc )\
  2847. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
  2848. {\
  2849. return @ name; \
  2850. }\
  2851. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
  2852. { \
  2853. return @ desc; \
  2854. } \
  2855. -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
  2856. #endif
  2857. #ifdef CATCH_IMPL
  2858. // !TBD: Move the leak detector code into a separate header
  2859. #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
  2860. #include <crtdbg.h>
  2861. class LeakDetector {
  2862. public:
  2863. LeakDetector() {
  2864. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  2865. flag |= _CRTDBG_LEAK_CHECK_DF;
  2866. flag |= _CRTDBG_ALLOC_MEM_DF;
  2867. _CrtSetDbgFlag(flag);
  2868. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  2869. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  2870. // Change this to leaking allocation's number to break there
  2871. _CrtSetBreakAlloc(-1);
  2872. }
  2873. };
  2874. #else
  2875. class LeakDetector {};
  2876. #endif
  2877. LeakDetector leakDetector;
  2878. // #included from: internal/catch_impl.hpp
  2879. #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
  2880. // Collect all the implementation files together here
  2881. // These are the equivalent of what would usually be cpp files
  2882. #ifdef __clang__
  2883. #pragma clang diagnostic push
  2884. #pragma clang diagnostic ignored "-Wweak-vtables"
  2885. #endif
  2886. // #included from: ../catch_session.hpp
  2887. #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
  2888. // #included from: internal/catch_commandline.hpp
  2889. #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
  2890. // #included from: catch_config.hpp
  2891. #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
  2892. // #included from: catch_test_spec_parser.hpp
  2893. #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  2894. #ifdef __clang__
  2895. #pragma clang diagnostic push
  2896. #pragma clang diagnostic ignored "-Wpadded"
  2897. #endif
  2898. // #included from: catch_test_spec.hpp
  2899. #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  2900. #ifdef __clang__
  2901. #pragma clang diagnostic push
  2902. #pragma clang diagnostic ignored "-Wpadded"
  2903. #endif
  2904. // #included from: catch_wildcard_pattern.hpp
  2905. #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2906. #include <stdexcept>
  2907. namespace Catch
  2908. {
  2909. class WildcardPattern {
  2910. enum WildcardPosition {
  2911. NoWildcard = 0,
  2912. WildcardAtStart = 1,
  2913. WildcardAtEnd = 2,
  2914. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2915. };
  2916. public:
  2917. WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
  2918. : m_caseSensitivity( caseSensitivity ),
  2919. m_wildcard( NoWildcard ),
  2920. m_pattern( adjustCase( pattern ) )
  2921. {
  2922. if( startsWith( m_pattern, '*' ) ) {
  2923. m_pattern = m_pattern.substr( 1 );
  2924. m_wildcard = WildcardAtStart;
  2925. }
  2926. if( endsWith( m_pattern, '*' ) ) {
  2927. m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
  2928. m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
  2929. }
  2930. }
  2931. virtual ~WildcardPattern();
  2932. virtual bool matches( std::string const& str ) const {
  2933. switch( m_wildcard ) {
  2934. case NoWildcard:
  2935. return m_pattern == adjustCase( str );
  2936. case WildcardAtStart:
  2937. return endsWith( adjustCase( str ), m_pattern );
  2938. case WildcardAtEnd:
  2939. return startsWith( adjustCase( str ), m_pattern );
  2940. case WildcardAtBothEnds:
  2941. return contains( adjustCase( str ), m_pattern );
  2942. }
  2943. #ifdef __clang__
  2944. #pragma clang diagnostic push
  2945. #pragma clang diagnostic ignored "-Wunreachable-code"
  2946. #endif
  2947. throw std::logic_error( "Unknown enum" );
  2948. #ifdef __clang__
  2949. #pragma clang diagnostic pop
  2950. #endif
  2951. }
  2952. private:
  2953. std::string adjustCase( std::string const& str ) const {
  2954. return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
  2955. }
  2956. CaseSensitive::Choice m_caseSensitivity;
  2957. WildcardPosition m_wildcard;
  2958. std::string m_pattern;
  2959. };
  2960. }
  2961. #include <string>
  2962. #include <vector>
  2963. namespace Catch {
  2964. class TestSpec {
  2965. struct Pattern : SharedImpl<> {
  2966. virtual ~Pattern();
  2967. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2968. };
  2969. class NamePattern : public Pattern {
  2970. public:
  2971. NamePattern( std::string const& name )
  2972. : m_wildcardPattern( toLower( name ), CaseSensitive::No )
  2973. {}
  2974. virtual ~NamePattern();
  2975. virtual bool matches( TestCaseInfo const& testCase ) const {
  2976. return m_wildcardPattern.matches( toLower( testCase.name ) );
  2977. }
  2978. private:
  2979. WildcardPattern m_wildcardPattern;
  2980. };
  2981. class TagPattern : public Pattern {
  2982. public:
  2983. TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
  2984. virtual ~TagPattern();
  2985. virtual bool matches( TestCaseInfo const& testCase ) const {
  2986. return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
  2987. }
  2988. private:
  2989. std::string m_tag;
  2990. };
  2991. class ExcludedPattern : public Pattern {
  2992. public:
  2993. ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
  2994. virtual ~ExcludedPattern();
  2995. virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
  2996. private:
  2997. Ptr<Pattern> m_underlyingPattern;
  2998. };
  2999. struct Filter {
  3000. std::vector<Ptr<Pattern> > m_patterns;
  3001. bool matches( TestCaseInfo const& testCase ) const {
  3002. // All patterns in a filter must match for the filter to be a match
  3003. for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
  3004. if( !(*it)->matches( testCase ) )
  3005. return false;
  3006. }
  3007. return true;
  3008. }
  3009. };
  3010. public:
  3011. bool hasFilters() const {
  3012. return !m_filters.empty();
  3013. }
  3014. bool matches( TestCaseInfo const& testCase ) const {
  3015. // A TestSpec matches if any filter matches
  3016. for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
  3017. if( it->matches( testCase ) )
  3018. return true;
  3019. return false;
  3020. }
  3021. private:
  3022. std::vector<Filter> m_filters;
  3023. friend class TestSpecParser;
  3024. };
  3025. }
  3026. #ifdef __clang__
  3027. #pragma clang diagnostic pop
  3028. #endif
  3029. namespace Catch {
  3030. class TestSpecParser {
  3031. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  3032. Mode m_mode;
  3033. bool m_exclusion;
  3034. std::size_t m_start, m_pos;
  3035. std::string m_arg;
  3036. std::vector<std::size_t> m_escapeChars;
  3037. TestSpec::Filter m_currentFilter;
  3038. TestSpec m_testSpec;
  3039. ITagAliasRegistry const* m_tagAliases;
  3040. public:
  3041. TestSpecParser( ITagAliasRegistry const& tagAliases ) :m_mode(None), m_exclusion(false), m_start(0), m_pos(0), m_tagAliases( &tagAliases ) {}
  3042. TestSpecParser& parse( std::string const& arg ) {
  3043. m_mode = None;
  3044. m_exclusion = false;
  3045. m_start = std::string::npos;
  3046. m_arg = m_tagAliases->expandAliases( arg );
  3047. m_escapeChars.clear();
  3048. for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
  3049. visitChar( m_arg[m_pos] );
  3050. if( m_mode == Name )
  3051. addPattern<TestSpec::NamePattern>();
  3052. return *this;
  3053. }
  3054. TestSpec testSpec() {
  3055. addFilter();
  3056. return m_testSpec;
  3057. }
  3058. private:
  3059. void visitChar( char c ) {
  3060. if( m_mode == None ) {
  3061. switch( c ) {
  3062. case ' ': return;
  3063. case '~': m_exclusion = true; return;
  3064. case '[': return startNewMode( Tag, ++m_pos );
  3065. case '"': return startNewMode( QuotedName, ++m_pos );
  3066. case '\\': return escape();
  3067. default: startNewMode( Name, m_pos ); break;
  3068. }
  3069. }
  3070. if( m_mode == Name ) {
  3071. if( c == ',' ) {
  3072. addPattern<TestSpec::NamePattern>();
  3073. addFilter();
  3074. }
  3075. else if( c == '[' ) {
  3076. if( subString() == "exclude:" )
  3077. m_exclusion = true;
  3078. else
  3079. addPattern<TestSpec::NamePattern>();
  3080. startNewMode( Tag, ++m_pos );
  3081. }
  3082. else if( c == '\\' )
  3083. escape();
  3084. }
  3085. else if( m_mode == EscapedName )
  3086. m_mode = Name;
  3087. else if( m_mode == QuotedName && c == '"' )
  3088. addPattern<TestSpec::NamePattern>();
  3089. else if( m_mode == Tag && c == ']' )
  3090. addPattern<TestSpec::TagPattern>();
  3091. }
  3092. void startNewMode( Mode mode, std::size_t start ) {
  3093. m_mode = mode;
  3094. m_start = start;
  3095. }
  3096. void escape() {
  3097. if( m_mode == None )
  3098. m_start = m_pos;
  3099. m_mode = EscapedName;
  3100. m_escapeChars.push_back( m_pos );
  3101. }
  3102. std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
  3103. template<typename T>
  3104. void addPattern() {
  3105. std::string token = subString();
  3106. for( size_t i = 0; i < m_escapeChars.size(); ++i )
  3107. token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
  3108. m_escapeChars.clear();
  3109. if( startsWith( token, "exclude:" ) ) {
  3110. m_exclusion = true;
  3111. token = token.substr( 8 );
  3112. }
  3113. if( !token.empty() ) {
  3114. Ptr<TestSpec::Pattern> pattern = new T( token );
  3115. if( m_exclusion )
  3116. pattern = new TestSpec::ExcludedPattern( pattern );
  3117. m_currentFilter.m_patterns.push_back( pattern );
  3118. }
  3119. m_exclusion = false;
  3120. m_mode = None;
  3121. }
  3122. void addFilter() {
  3123. if( !m_currentFilter.m_patterns.empty() ) {
  3124. m_testSpec.m_filters.push_back( m_currentFilter );
  3125. m_currentFilter = TestSpec::Filter();
  3126. }
  3127. }
  3128. };
  3129. inline TestSpec parseTestSpec( std::string const& arg ) {
  3130. return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
  3131. }
  3132. } // namespace Catch
  3133. #ifdef __clang__
  3134. #pragma clang diagnostic pop
  3135. #endif
  3136. // #included from: catch_interfaces_config.h
  3137. #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
  3138. #include <iosfwd>
  3139. #include <string>
  3140. #include <vector>
  3141. namespace Catch {
  3142. struct Verbosity { enum Level {
  3143. NoOutput = 0,
  3144. Quiet,
  3145. Normal
  3146. }; };
  3147. struct WarnAbout { enum What {
  3148. Nothing = 0x00,
  3149. NoAssertions = 0x01
  3150. }; };
  3151. struct ShowDurations { enum OrNot {
  3152. DefaultForReporter,
  3153. Always,
  3154. Never
  3155. }; };
  3156. struct RunTests { enum InWhatOrder {
  3157. InDeclarationOrder,
  3158. InLexicographicalOrder,
  3159. InRandomOrder
  3160. }; };
  3161. struct UseColour { enum YesOrNo {
  3162. Auto,
  3163. Yes,
  3164. No
  3165. }; };
  3166. struct WaitForKeypress { enum When {
  3167. Never,
  3168. BeforeStart = 1,
  3169. BeforeExit = 2,
  3170. BeforeStartAndExit = BeforeStart | BeforeExit
  3171. }; };
  3172. class TestSpec;
  3173. struct IConfig : IShared {
  3174. virtual ~IConfig();
  3175. virtual bool allowThrows() const = 0;
  3176. virtual std::ostream& stream() const = 0;
  3177. virtual std::string name() const = 0;
  3178. virtual bool includeSuccessfulResults() const = 0;
  3179. virtual bool shouldDebugBreak() const = 0;
  3180. virtual bool warnAboutMissingAssertions() const = 0;
  3181. virtual int abortAfter() const = 0;
  3182. virtual bool showInvisibles() const = 0;
  3183. virtual ShowDurations::OrNot showDurations() const = 0;
  3184. virtual TestSpec const& testSpec() const = 0;
  3185. virtual RunTests::InWhatOrder runOrder() const = 0;
  3186. virtual unsigned int rngSeed() const = 0;
  3187. virtual UseColour::YesOrNo useColour() const = 0;
  3188. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  3189. };
  3190. }
  3191. // #included from: catch_stream.h
  3192. #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
  3193. // #included from: catch_streambuf.h
  3194. #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
  3195. #include <streambuf>
  3196. namespace Catch {
  3197. class StreamBufBase : public std::streambuf {
  3198. public:
  3199. virtual ~StreamBufBase() CATCH_NOEXCEPT;
  3200. };
  3201. }
  3202. #include <streambuf>
  3203. #include <ostream>
  3204. #include <fstream>
  3205. #include <memory>
  3206. namespace Catch {
  3207. std::ostream& cout();
  3208. std::ostream& cerr();
  3209. std::ostream& clog();
  3210. struct IStream {
  3211. virtual ~IStream() CATCH_NOEXCEPT;
  3212. virtual std::ostream& stream() const = 0;
  3213. };
  3214. class FileStream : public IStream {
  3215. mutable std::ofstream m_ofs;
  3216. public:
  3217. FileStream( std::string const& filename );
  3218. virtual ~FileStream() CATCH_NOEXCEPT;
  3219. public: // IStream
  3220. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3221. };
  3222. class CoutStream : public IStream {
  3223. mutable std::ostream m_os;
  3224. public:
  3225. CoutStream();
  3226. virtual ~CoutStream() CATCH_NOEXCEPT;
  3227. public: // IStream
  3228. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3229. };
  3230. class DebugOutStream : public IStream {
  3231. CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
  3232. mutable std::ostream m_os;
  3233. public:
  3234. DebugOutStream();
  3235. virtual ~DebugOutStream() CATCH_NOEXCEPT;
  3236. public: // IStream
  3237. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3238. };
  3239. }
  3240. #include <memory>
  3241. #include <vector>
  3242. #include <string>
  3243. #include <stdexcept>
  3244. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  3245. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  3246. #endif
  3247. namespace Catch {
  3248. struct ConfigData {
  3249. ConfigData()
  3250. : listTests( false ),
  3251. listTags( false ),
  3252. listReporters( false ),
  3253. listTestNamesOnly( false ),
  3254. listExtraInfo( false ),
  3255. showSuccessfulTests( false ),
  3256. shouldDebugBreak( false ),
  3257. noThrow( false ),
  3258. showHelp( false ),
  3259. showInvisibles( false ),
  3260. filenamesAsTags( false ),
  3261. libIdentify( false ),
  3262. abortAfter( -1 ),
  3263. rngSeed( 0 ),
  3264. verbosity( Verbosity::Normal ),
  3265. warnings( WarnAbout::Nothing ),
  3266. showDurations( ShowDurations::DefaultForReporter ),
  3267. runOrder( RunTests::InDeclarationOrder ),
  3268. useColour( UseColour::Auto ),
  3269. waitForKeypress( WaitForKeypress::Never )
  3270. {}
  3271. bool listTests;
  3272. bool listTags;
  3273. bool listReporters;
  3274. bool listTestNamesOnly;
  3275. bool listExtraInfo;
  3276. bool showSuccessfulTests;
  3277. bool shouldDebugBreak;
  3278. bool noThrow;
  3279. bool showHelp;
  3280. bool showInvisibles;
  3281. bool filenamesAsTags;
  3282. bool libIdentify;
  3283. int abortAfter;
  3284. unsigned int rngSeed;
  3285. Verbosity::Level verbosity;
  3286. WarnAbout::What warnings;
  3287. ShowDurations::OrNot showDurations;
  3288. RunTests::InWhatOrder runOrder;
  3289. UseColour::YesOrNo useColour;
  3290. WaitForKeypress::When waitForKeypress;
  3291. std::string outputFilename;
  3292. std::string name;
  3293. std::string processName;
  3294. std::vector<std::string> reporterNames;
  3295. std::vector<std::string> testsOrTags;
  3296. std::vector<std::string> sectionsToRun;
  3297. };
  3298. class Config : public SharedImpl<IConfig> {
  3299. private:
  3300. Config( Config const& other );
  3301. Config& operator = ( Config const& other );
  3302. virtual void dummy();
  3303. public:
  3304. Config()
  3305. {}
  3306. Config( ConfigData const& data )
  3307. : m_data( data ),
  3308. m_stream( openStream() )
  3309. {
  3310. if( !data.testsOrTags.empty() ) {
  3311. TestSpecParser parser( ITagAliasRegistry::get() );
  3312. for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
  3313. parser.parse( data.testsOrTags[i] );
  3314. m_testSpec = parser.testSpec();
  3315. }
  3316. }
  3317. virtual ~Config() {}
  3318. std::string const& getFilename() const {
  3319. return m_data.outputFilename ;
  3320. }
  3321. bool listTests() const { return m_data.listTests; }
  3322. bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
  3323. bool listTags() const { return m_data.listTags; }
  3324. bool listReporters() const { return m_data.listReporters; }
  3325. bool listExtraInfo() const { return m_data.listExtraInfo; }
  3326. std::string getProcessName() const { return m_data.processName; }
  3327. std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
  3328. std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; }
  3329. virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; }
  3330. bool showHelp() const { return m_data.showHelp; }
  3331. // IConfig interface
  3332. virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; }
  3333. virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); }
  3334. virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; }
  3335. virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; }
  3336. virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; }
  3337. virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; }
  3338. virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; }
  3339. virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; }
  3340. virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; }
  3341. virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; }
  3342. virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; }
  3343. virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; }
  3344. private:
  3345. IStream const* openStream() {
  3346. if( m_data.outputFilename.empty() )
  3347. return new CoutStream();
  3348. else if( m_data.outputFilename[0] == '%' ) {
  3349. if( m_data.outputFilename == "%debug" )
  3350. return new DebugOutStream();
  3351. else
  3352. throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
  3353. }
  3354. else
  3355. return new FileStream( m_data.outputFilename );
  3356. }
  3357. ConfigData m_data;
  3358. CATCH_AUTO_PTR( IStream const ) m_stream;
  3359. TestSpec m_testSpec;
  3360. };
  3361. } // end namespace Catch
  3362. // #included from: catch_clara.h
  3363. #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
  3364. // Use Catch's value for console width (store Clara's off to the side, if present)
  3365. #ifdef CLARA_CONFIG_CONSOLE_WIDTH
  3366. #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
  3367. #undef CLARA_CONFIG_CONSOLE_WIDTH
  3368. #endif
  3369. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  3370. // Declare Clara inside the Catch namespace
  3371. #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
  3372. // #included from: ../external/clara.h
  3373. // Version 0.0.2.4
  3374. // Only use header guard if we are not using an outer namespace
  3375. #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
  3376. #ifndef STITCH_CLARA_OPEN_NAMESPACE
  3377. #define TWOBLUECUBES_CLARA_H_INCLUDED
  3378. #define STITCH_CLARA_OPEN_NAMESPACE
  3379. #define STITCH_CLARA_CLOSE_NAMESPACE
  3380. #else
  3381. #define STITCH_CLARA_CLOSE_NAMESPACE }
  3382. #endif
  3383. #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
  3384. // ----------- #included from tbc_text_format.h -----------
  3385. // Only use header guard if we are not using an outer namespace
  3386. #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
  3387. #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3388. #define TBC_TEXT_FORMAT_H_INCLUDED
  3389. #endif
  3390. #include <string>
  3391. #include <vector>
  3392. #include <sstream>
  3393. #include <algorithm>
  3394. #include <cctype>
  3395. // Use optional outer namespace
  3396. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3397. namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  3398. #endif
  3399. namespace Tbc {
  3400. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  3401. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  3402. #else
  3403. const unsigned int consoleWidth = 80;
  3404. #endif
  3405. struct TextAttributes {
  3406. TextAttributes()
  3407. : initialIndent( std::string::npos ),
  3408. indent( 0 ),
  3409. width( consoleWidth-1 ),
  3410. tabChar( '\t' )
  3411. {}
  3412. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  3413. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  3414. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  3415. TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
  3416. std::size_t initialIndent; // indent of first line, or npos
  3417. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  3418. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  3419. char tabChar; // If this char is seen the indent is changed to current pos
  3420. };
  3421. class Text {
  3422. public:
  3423. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  3424. : attr( _attr )
  3425. {
  3426. std::string wrappableChars = " [({.,/|\\-";
  3427. std::size_t indent = _attr.initialIndent != std::string::npos
  3428. ? _attr.initialIndent
  3429. : _attr.indent;
  3430. std::string remainder = _str;
  3431. while( !remainder.empty() ) {
  3432. if( lines.size() >= 1000 ) {
  3433. lines.push_back( "... message truncated due to excessive size" );
  3434. return;
  3435. }
  3436. std::size_t tabPos = std::string::npos;
  3437. std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
  3438. std::size_t pos = remainder.find_first_of( '\n' );
  3439. if( pos <= width ) {
  3440. width = pos;
  3441. }
  3442. pos = remainder.find_last_of( _attr.tabChar, width );
  3443. if( pos != std::string::npos ) {
  3444. tabPos = pos;
  3445. if( remainder[width] == '\n' )
  3446. width--;
  3447. remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
  3448. }
  3449. if( width == remainder.size() ) {
  3450. spliceLine( indent, remainder, width );
  3451. }
  3452. else if( remainder[width] == '\n' ) {
  3453. spliceLine( indent, remainder, width );
  3454. if( width <= 1 || remainder.size() != 1 )
  3455. remainder = remainder.substr( 1 );
  3456. indent = _attr.indent;
  3457. }
  3458. else {
  3459. pos = remainder.find_last_of( wrappableChars, width );
  3460. if( pos != std::string::npos && pos > 0 ) {
  3461. spliceLine( indent, remainder, pos );
  3462. if( remainder[0] == ' ' )
  3463. remainder = remainder.substr( 1 );
  3464. }
  3465. else {
  3466. spliceLine( indent, remainder, width-1 );
  3467. lines.back() += "-";
  3468. }
  3469. if( lines.size() == 1 )
  3470. indent = _attr.indent;
  3471. if( tabPos != std::string::npos )
  3472. indent += tabPos;
  3473. }
  3474. }
  3475. }
  3476. void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
  3477. lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
  3478. _remainder = _remainder.substr( _pos );
  3479. }
  3480. typedef std::vector<std::string>::const_iterator const_iterator;
  3481. const_iterator begin() const { return lines.begin(); }
  3482. const_iterator end() const { return lines.end(); }
  3483. std::string const& last() const { return lines.back(); }
  3484. std::size_t size() const { return lines.size(); }
  3485. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  3486. std::string toString() const {
  3487. std::ostringstream oss;
  3488. oss << *this;
  3489. return oss.str();
  3490. }
  3491. friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  3492. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  3493. it != itEnd; ++it ) {
  3494. if( it != _text.begin() )
  3495. _stream << "\n";
  3496. _stream << *it;
  3497. }
  3498. return _stream;
  3499. }
  3500. private:
  3501. std::string str;
  3502. TextAttributes attr;
  3503. std::vector<std::string> lines;
  3504. };
  3505. } // end namespace Tbc
  3506. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3507. } // end outer namespace
  3508. #endif
  3509. #endif // TBC_TEXT_FORMAT_H_INCLUDED
  3510. // ----------- end of #include from tbc_text_format.h -----------
  3511. // ........... back in clara.h
  3512. #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
  3513. // ----------- #included from clara_compilers.h -----------
  3514. #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3515. #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3516. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  3517. // The following features are defined:
  3518. //
  3519. // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
  3520. // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  3521. // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  3522. // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
  3523. // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  3524. // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  3525. // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  3526. // In general each macro has a _NO_<feature name> form
  3527. // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  3528. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  3529. // can be combined, en-mass, with the _NO_ forms later.
  3530. // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
  3531. #ifdef __clang__
  3532. #if __has_feature(cxx_nullptr)
  3533. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3534. #endif
  3535. #if __has_feature(cxx_noexcept)
  3536. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3537. #endif
  3538. #endif // __clang__
  3539. ////////////////////////////////////////////////////////////////////////////////
  3540. // GCC
  3541. #ifdef __GNUC__
  3542. #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  3543. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3544. #endif
  3545. // - otherwise more recent versions define __cplusplus >= 201103L
  3546. // and will get picked up below
  3547. #endif // __GNUC__
  3548. ////////////////////////////////////////////////////////////////////////////////
  3549. // Visual C++
  3550. #ifdef _MSC_VER
  3551. #if (_MSC_VER >= 1600)
  3552. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3553. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3554. #endif
  3555. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  3556. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3557. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3558. #endif
  3559. #endif // _MSC_VER
  3560. ////////////////////////////////////////////////////////////////////////////////
  3561. // C++ language feature support
  3562. // catch all support for C++11
  3563. #if defined(__cplusplus) && __cplusplus >= 201103L
  3564. #define CLARA_CPP11_OR_GREATER
  3565. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
  3566. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3567. #endif
  3568. #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3569. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3570. #endif
  3571. #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3572. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3573. #endif
  3574. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
  3575. #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
  3576. #endif
  3577. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  3578. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3579. #endif
  3580. #endif // __cplusplus >= 201103L
  3581. // Now set the actual defines based on the above + anything the user has configured
  3582. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3583. #define CLARA_CONFIG_CPP11_NULLPTR
  3584. #endif
  3585. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
  3586. #define CLARA_CONFIG_CPP11_NOEXCEPT
  3587. #endif
  3588. #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)
  3589. #define CLARA_CONFIG_CPP11_GENERATED_METHODS
  3590. #endif
  3591. #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
  3592. #define CLARA_CONFIG_CPP11_OVERRIDE
  3593. #endif
  3594. #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)
  3595. #define CLARA_CONFIG_CPP11_UNIQUE_PTR
  3596. #endif
  3597. // noexcept support:
  3598. #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
  3599. #define CLARA_NOEXCEPT noexcept
  3600. # define CLARA_NOEXCEPT_IS(x) noexcept(x)
  3601. #else
  3602. #define CLARA_NOEXCEPT throw()
  3603. # define CLARA_NOEXCEPT_IS(x)
  3604. #endif
  3605. // nullptr support
  3606. #ifdef CLARA_CONFIG_CPP11_NULLPTR
  3607. #define CLARA_NULL nullptr
  3608. #else
  3609. #define CLARA_NULL NULL
  3610. #endif
  3611. // override support
  3612. #ifdef CLARA_CONFIG_CPP11_OVERRIDE
  3613. #define CLARA_OVERRIDE override
  3614. #else
  3615. #define CLARA_OVERRIDE
  3616. #endif
  3617. // unique_ptr support
  3618. #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
  3619. # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
  3620. #else
  3621. # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
  3622. #endif
  3623. #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3624. // ----------- end of #include from clara_compilers.h -----------
  3625. // ........... back in clara.h
  3626. #include <map>
  3627. #include <stdexcept>
  3628. #include <memory>
  3629. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  3630. #define CLARA_PLATFORM_WINDOWS
  3631. #endif
  3632. // Use optional outer namespace
  3633. #ifdef STITCH_CLARA_OPEN_NAMESPACE
  3634. STITCH_CLARA_OPEN_NAMESPACE
  3635. #endif
  3636. namespace Clara {
  3637. struct UnpositionalTag {};
  3638. extern UnpositionalTag _;
  3639. #ifdef CLARA_CONFIG_MAIN
  3640. UnpositionalTag _;
  3641. #endif
  3642. namespace Detail {
  3643. #ifdef CLARA_CONSOLE_WIDTH
  3644. const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
  3645. #else
  3646. const unsigned int consoleWidth = 80;
  3647. #endif
  3648. using namespace Tbc;
  3649. inline bool startsWith( std::string const& str, std::string const& prefix ) {
  3650. return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
  3651. }
  3652. template<typename T> struct RemoveConstRef{ typedef T type; };
  3653. template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
  3654. template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
  3655. template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
  3656. template<typename T> struct IsBool { static const bool value = false; };
  3657. template<> struct IsBool<bool> { static const bool value = true; };
  3658. template<typename T>
  3659. void convertInto( std::string const& _source, T& _dest ) {
  3660. std::stringstream ss;
  3661. ss << _source;
  3662. ss >> _dest;
  3663. if( ss.fail() )
  3664. throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
  3665. }
  3666. inline void convertInto( std::string const& _source, std::string& _dest ) {
  3667. _dest = _source;
  3668. }
  3669. char toLowerCh(char c) {
  3670. return static_cast<char>( std::tolower( c ) );
  3671. }
  3672. inline void convertInto( std::string const& _source, bool& _dest ) {
  3673. std::string sourceLC = _source;
  3674. std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
  3675. if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
  3676. _dest = true;
  3677. else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
  3678. _dest = false;
  3679. else
  3680. throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
  3681. }
  3682. template<typename ConfigT>
  3683. struct IArgFunction {
  3684. virtual ~IArgFunction() {}
  3685. #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
  3686. IArgFunction() = default;
  3687. IArgFunction( IArgFunction const& ) = default;
  3688. #endif
  3689. virtual void set( ConfigT& config, std::string const& value ) const = 0;
  3690. virtual bool takesArg() const = 0;
  3691. virtual IArgFunction* clone() const = 0;
  3692. };
  3693. template<typename ConfigT>
  3694. class BoundArgFunction {
  3695. public:
  3696. BoundArgFunction() : functionObj( CLARA_NULL ) {}
  3697. BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
  3698. BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
  3699. BoundArgFunction& operator = ( BoundArgFunction const& other ) {
  3700. IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
  3701. delete functionObj;
  3702. functionObj = newFunctionObj;
  3703. return *this;
  3704. }
  3705. ~BoundArgFunction() { delete functionObj; }
  3706. void set( ConfigT& config, std::string const& value ) const {
  3707. functionObj->set( config, value );
  3708. }
  3709. bool takesArg() const { return functionObj->takesArg(); }
  3710. bool isSet() const {
  3711. return functionObj != CLARA_NULL;
  3712. }
  3713. private:
  3714. IArgFunction<ConfigT>* functionObj;
  3715. };
  3716. template<typename C>
  3717. struct NullBinder : IArgFunction<C>{
  3718. virtual void set( C&, std::string const& ) const {}
  3719. virtual bool takesArg() const { return true; }
  3720. virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
  3721. };
  3722. template<typename C, typename M>
  3723. struct BoundDataMember : IArgFunction<C>{
  3724. BoundDataMember( M C::* _member ) : member( _member ) {}
  3725. virtual void set( C& p, std::string const& stringValue ) const {
  3726. convertInto( stringValue, p.*member );
  3727. }
  3728. virtual bool takesArg() const { return !IsBool<M>::value; }
  3729. virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
  3730. M C::* member;
  3731. };
  3732. template<typename C, typename M>
  3733. struct BoundUnaryMethod : IArgFunction<C>{
  3734. BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
  3735. virtual void set( C& p, std::string const& stringValue ) const {
  3736. typename RemoveConstRef<M>::type value;
  3737. convertInto( stringValue, value );
  3738. (p.*member)( value );
  3739. }
  3740. virtual bool takesArg() const { return !IsBool<M>::value; }
  3741. virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
  3742. void (C::*member)( M );
  3743. };
  3744. template<typename C>
  3745. struct BoundNullaryMethod : IArgFunction<C>{
  3746. BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
  3747. virtual void set( C& p, std::string const& stringValue ) const {
  3748. bool value;
  3749. convertInto( stringValue, value );
  3750. if( value )
  3751. (p.*member)();
  3752. }
  3753. virtual bool takesArg() const { return false; }
  3754. virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
  3755. void (C::*member)();
  3756. };
  3757. template<typename C>
  3758. struct BoundUnaryFunction : IArgFunction<C>{
  3759. BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
  3760. virtual void set( C& obj, std::string const& stringValue ) const {
  3761. bool value;
  3762. convertInto( stringValue, value );
  3763. if( value )
  3764. function( obj );
  3765. }
  3766. virtual bool takesArg() const { return false; }
  3767. virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
  3768. void (*function)( C& );
  3769. };
  3770. template<typename C, typename T>
  3771. struct BoundBinaryFunction : IArgFunction<C>{
  3772. BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
  3773. virtual void set( C& obj, std::string const& stringValue ) const {
  3774. typename RemoveConstRef<T>::type value;
  3775. convertInto( stringValue, value );
  3776. function( obj, value );
  3777. }
  3778. virtual bool takesArg() const { return !IsBool<T>::value; }
  3779. virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
  3780. void (*function)( C&, T );
  3781. };
  3782. } // namespace Detail
  3783. inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
  3784. std::vector<std::string> args( static_cast<std::size_t>( argc ) );
  3785. for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
  3786. args[i] = argv[i];
  3787. return args;
  3788. }
  3789. class Parser {
  3790. enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
  3791. Mode mode;
  3792. std::size_t from;
  3793. bool inQuotes;
  3794. public:
  3795. struct Token {
  3796. enum Type { Positional, ShortOpt, LongOpt };
  3797. Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
  3798. Type type;
  3799. std::string data;
  3800. };
  3801. Parser() : mode( None ), from( 0 ), inQuotes( false ){}
  3802. void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
  3803. const std::string doubleDash = "--";
  3804. for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
  3805. parseIntoTokens( args[i], tokens);
  3806. }
  3807. void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
  3808. for( std::size_t i = 0; i < arg.size(); ++i ) {
  3809. char c = arg[i];
  3810. if( c == '"' )
  3811. inQuotes = !inQuotes;
  3812. mode = handleMode( i, c, arg, tokens );
  3813. }
  3814. mode = handleMode( arg.size(), '\0', arg, tokens );
  3815. }
  3816. Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3817. switch( mode ) {
  3818. case None: return handleNone( i, c );
  3819. case MaybeShortOpt: return handleMaybeShortOpt( i, c );
  3820. case ShortOpt:
  3821. case LongOpt:
  3822. case SlashOpt: return handleOpt( i, c, arg, tokens );
  3823. case Positional: return handlePositional( i, c, arg, tokens );
  3824. default: throw std::logic_error( "Unknown mode" );
  3825. }
  3826. }
  3827. Mode handleNone( std::size_t i, char c ) {
  3828. if( inQuotes ) {
  3829. from = i;
  3830. return Positional;
  3831. }
  3832. switch( c ) {
  3833. case '-': return MaybeShortOpt;
  3834. #ifdef CLARA_PLATFORM_WINDOWS
  3835. case '/': from = i+1; return SlashOpt;
  3836. #endif
  3837. default: from = i; return Positional;
  3838. }
  3839. }
  3840. Mode handleMaybeShortOpt( std::size_t i, char c ) {
  3841. switch( c ) {
  3842. case '-': from = i+1; return LongOpt;
  3843. default: from = i; return ShortOpt;
  3844. }
  3845. }
  3846. Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3847. if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
  3848. return mode;
  3849. std::string optName = arg.substr( from, i-from );
  3850. if( mode == ShortOpt )
  3851. for( std::size_t j = 0; j < optName.size(); ++j )
  3852. tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
  3853. else if( mode == SlashOpt && optName.size() == 1 )
  3854. tokens.push_back( Token( Token::ShortOpt, optName ) );
  3855. else
  3856. tokens.push_back( Token( Token::LongOpt, optName ) );
  3857. return None;
  3858. }
  3859. Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3860. if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
  3861. return mode;
  3862. std::string data = arg.substr( from, i-from );
  3863. tokens.push_back( Token( Token::Positional, data ) );
  3864. return None;
  3865. }
  3866. };
  3867. template<typename ConfigT>
  3868. struct CommonArgProperties {
  3869. CommonArgProperties() {}
  3870. CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
  3871. Detail::BoundArgFunction<ConfigT> boundField;
  3872. std::string description;
  3873. std::string detail;
  3874. std::string placeholder; // Only value if boundField takes an arg
  3875. bool takesArg() const {
  3876. return !placeholder.empty();
  3877. }
  3878. void validate() const {
  3879. if( !boundField.isSet() )
  3880. throw std::logic_error( "option not bound" );
  3881. }
  3882. };
  3883. struct OptionArgProperties {
  3884. std::vector<std::string> shortNames;
  3885. std::string longName;
  3886. bool hasShortName( std::string const& shortName ) const {
  3887. return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
  3888. }
  3889. bool hasLongName( std::string const& _longName ) const {
  3890. return _longName == longName;
  3891. }
  3892. };
  3893. struct PositionalArgProperties {
  3894. PositionalArgProperties() : position( -1 ) {}
  3895. int position; // -1 means non-positional (floating)
  3896. bool isFixedPositional() const {
  3897. return position != -1;
  3898. }
  3899. };
  3900. template<typename ConfigT>
  3901. class CommandLine {
  3902. struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
  3903. Arg() {}
  3904. Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
  3905. using CommonArgProperties<ConfigT>::placeholder; // !TBD
  3906. std::string dbgName() const {
  3907. if( !longName.empty() )
  3908. return "--" + longName;
  3909. if( !shortNames.empty() )
  3910. return "-" + shortNames[0];
  3911. return "positional args";
  3912. }
  3913. std::string commands() const {
  3914. std::ostringstream oss;
  3915. bool first = true;
  3916. std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
  3917. for(; it != itEnd; ++it ) {
  3918. if( first )
  3919. first = false;
  3920. else
  3921. oss << ", ";
  3922. oss << "-" << *it;
  3923. }
  3924. if( !longName.empty() ) {
  3925. if( !first )
  3926. oss << ", ";
  3927. oss << "--" << longName;
  3928. }
  3929. if( !placeholder.empty() )
  3930. oss << " <" << placeholder << ">";
  3931. return oss.str();
  3932. }
  3933. };
  3934. typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
  3935. friend void addOptName( Arg& arg, std::string const& optName )
  3936. {
  3937. if( optName.empty() )
  3938. return;
  3939. if( Detail::startsWith( optName, "--" ) ) {
  3940. if( !arg.longName.empty() )
  3941. throw std::logic_error( "Only one long opt may be specified. '"
  3942. + arg.longName
  3943. + "' already specified, now attempting to add '"
  3944. + optName + "'" );
  3945. arg.longName = optName.substr( 2 );
  3946. }
  3947. else if( Detail::startsWith( optName, "-" ) )
  3948. arg.shortNames.push_back( optName.substr( 1 ) );
  3949. else
  3950. throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
  3951. }
  3952. friend void setPositionalArg( Arg& arg, int position )
  3953. {
  3954. arg.position = position;
  3955. }
  3956. class ArgBuilder {
  3957. public:
  3958. ArgBuilder( Arg* arg ) : m_arg( arg ) {}
  3959. // Bind a non-boolean data member (requires placeholder string)
  3960. template<typename C, typename M>
  3961. void bind( M C::* field, std::string const& placeholder ) {
  3962. m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
  3963. m_arg->placeholder = placeholder;
  3964. }
  3965. // Bind a boolean data member (no placeholder required)
  3966. template<typename C>
  3967. void bind( bool C::* field ) {
  3968. m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
  3969. }
  3970. // Bind a method taking a single, non-boolean argument (requires a placeholder string)
  3971. template<typename C, typename M>
  3972. void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
  3973. m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
  3974. m_arg->placeholder = placeholder;
  3975. }
  3976. // Bind a method taking a single, boolean argument (no placeholder string required)
  3977. template<typename C>
  3978. void bind( void (C::* unaryMethod)( bool ) ) {
  3979. m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
  3980. }
  3981. // Bind a method that takes no arguments (will be called if opt is present)
  3982. template<typename C>
  3983. void bind( void (C::* nullaryMethod)() ) {
  3984. m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
  3985. }
  3986. // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
  3987. template<typename C>
  3988. void bind( void (* unaryFunction)( C& ) ) {
  3989. m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
  3990. }
  3991. // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
  3992. template<typename C, typename T>
  3993. void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
  3994. m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
  3995. m_arg->placeholder = placeholder;
  3996. }
  3997. ArgBuilder& describe( std::string const& description ) {
  3998. m_arg->description = description;
  3999. return *this;
  4000. }
  4001. ArgBuilder& detail( std::string const& detail ) {
  4002. m_arg->detail = detail;
  4003. return *this;
  4004. }
  4005. protected:
  4006. Arg* m_arg;
  4007. };
  4008. class OptBuilder : public ArgBuilder {
  4009. public:
  4010. OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
  4011. OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
  4012. OptBuilder& operator[]( std::string const& optName ) {
  4013. addOptName( *ArgBuilder::m_arg, optName );
  4014. return *this;
  4015. }
  4016. };
  4017. public:
  4018. CommandLine()
  4019. : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
  4020. m_highestSpecifiedArgPosition( 0 ),
  4021. m_throwOnUnrecognisedTokens( false )
  4022. {}
  4023. CommandLine( CommandLine const& other )
  4024. : m_boundProcessName( other.m_boundProcessName ),
  4025. m_options ( other.m_options ),
  4026. m_positionalArgs( other.m_positionalArgs ),
  4027. m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
  4028. m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
  4029. {
  4030. if( other.m_floatingArg.get() )
  4031. m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
  4032. }
  4033. CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
  4034. m_throwOnUnrecognisedTokens = shouldThrow;
  4035. return *this;
  4036. }
  4037. OptBuilder operator[]( std::string const& optName ) {
  4038. m_options.push_back( Arg() );
  4039. addOptName( m_options.back(), optName );
  4040. OptBuilder builder( &m_options.back() );
  4041. return builder;
  4042. }
  4043. ArgBuilder operator[]( int position ) {
  4044. m_positionalArgs.insert( std::make_pair( position, Arg() ) );
  4045. if( position > m_highestSpecifiedArgPosition )
  4046. m_highestSpecifiedArgPosition = position;
  4047. setPositionalArg( m_positionalArgs[position], position );
  4048. ArgBuilder builder( &m_positionalArgs[position] );
  4049. return builder;
  4050. }
  4051. // Invoke this with the _ instance
  4052. ArgBuilder operator[]( UnpositionalTag ) {
  4053. if( m_floatingArg.get() )
  4054. throw std::logic_error( "Only one unpositional argument can be added" );
  4055. m_floatingArg.reset( new Arg() );
  4056. ArgBuilder builder( m_floatingArg.get() );
  4057. return builder;
  4058. }
  4059. template<typename C, typename M>
  4060. void bindProcessName( M C::* field ) {
  4061. m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
  4062. }
  4063. template<typename C, typename M>
  4064. void bindProcessName( void (C::*_unaryMethod)( M ) ) {
  4065. m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
  4066. }
  4067. void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
  4068. typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
  4069. std::size_t maxWidth = 0;
  4070. for( it = itBegin; it != itEnd; ++it )
  4071. maxWidth = (std::max)( maxWidth, it->commands().size() );
  4072. for( it = itBegin; it != itEnd; ++it ) {
  4073. Detail::Text usage( it->commands(), Detail::TextAttributes()
  4074. .setWidth( maxWidth+indent )
  4075. .setIndent( indent ) );
  4076. Detail::Text desc( it->description, Detail::TextAttributes()
  4077. .setWidth( width - maxWidth - 3 ) );
  4078. for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
  4079. std::string usageCol = i < usage.size() ? usage[i] : "";
  4080. os << usageCol;
  4081. if( i < desc.size() && !desc[i].empty() )
  4082. os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
  4083. << desc[i];
  4084. os << "\n";
  4085. }
  4086. }
  4087. }
  4088. std::string optUsage() const {
  4089. std::ostringstream oss;
  4090. optUsage( oss );
  4091. return oss.str();
  4092. }
  4093. void argSynopsis( std::ostream& os ) const {
  4094. for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
  4095. if( i > 1 )
  4096. os << " ";
  4097. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
  4098. if( it != m_positionalArgs.end() )
  4099. os << "<" << it->second.placeholder << ">";
  4100. else if( m_floatingArg.get() )
  4101. os << "<" << m_floatingArg->placeholder << ">";
  4102. else
  4103. throw std::logic_error( "non consecutive positional arguments with no floating args" );
  4104. }
  4105. // !TBD No indication of mandatory args
  4106. if( m_floatingArg.get() ) {
  4107. if( m_highestSpecifiedArgPosition > 1 )
  4108. os << " ";
  4109. os << "[<" << m_floatingArg->placeholder << "> ...]";
  4110. }
  4111. }
  4112. std::string argSynopsis() const {
  4113. std::ostringstream oss;
  4114. argSynopsis( oss );
  4115. return oss.str();
  4116. }
  4117. void usage( std::ostream& os, std::string const& procName ) const {
  4118. validate();
  4119. os << "usage:\n " << procName << " ";
  4120. argSynopsis( os );
  4121. if( !m_options.empty() ) {
  4122. os << " [options]\n\nwhere options are: \n";
  4123. optUsage( os, 2 );
  4124. }
  4125. os << "\n";
  4126. }
  4127. std::string usage( std::string const& procName ) const {
  4128. std::ostringstream oss;
  4129. usage( oss, procName );
  4130. return oss.str();
  4131. }
  4132. ConfigT parse( std::vector<std::string> const& args ) const {
  4133. ConfigT config;
  4134. parseInto( args, config );
  4135. return config;
  4136. }
  4137. std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
  4138. std::string processName = args.empty() ? std::string() : args[0];
  4139. std::size_t lastSlash = processName.find_last_of( "/\\" );
  4140. if( lastSlash != std::string::npos )
  4141. processName = processName.substr( lastSlash+1 );
  4142. m_boundProcessName.set( config, processName );
  4143. std::vector<Parser::Token> tokens;
  4144. Parser parser;
  4145. parser.parseIntoTokens( args, tokens );
  4146. return populate( tokens, config );
  4147. }
  4148. std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4149. validate();
  4150. std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
  4151. unusedTokens = populateFixedArgs( unusedTokens, config );
  4152. unusedTokens = populateFloatingArgs( unusedTokens, config );
  4153. return unusedTokens;
  4154. }
  4155. std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4156. std::vector<Parser::Token> unusedTokens;
  4157. std::vector<std::string> errors;
  4158. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4159. Parser::Token const& token = tokens[i];
  4160. typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
  4161. for(; it != itEnd; ++it ) {
  4162. Arg const& arg = *it;
  4163. try {
  4164. if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
  4165. ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
  4166. if( arg.takesArg() ) {
  4167. if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
  4168. errors.push_back( "Expected argument to option: " + token.data );
  4169. else
  4170. arg.boundField.set( config, tokens[++i].data );
  4171. }
  4172. else {
  4173. arg.boundField.set( config, "true" );
  4174. }
  4175. break;
  4176. }
  4177. }
  4178. catch( std::exception& ex ) {
  4179. errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
  4180. }
  4181. }
  4182. if( it == itEnd ) {
  4183. if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
  4184. unusedTokens.push_back( token );
  4185. else if( errors.empty() && m_throwOnUnrecognisedTokens )
  4186. errors.push_back( "unrecognised option: " + token.data );
  4187. }
  4188. }
  4189. if( !errors.empty() ) {
  4190. std::ostringstream oss;
  4191. for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
  4192. it != itEnd;
  4193. ++it ) {
  4194. if( it != errors.begin() )
  4195. oss << "\n";
  4196. oss << *it;
  4197. }
  4198. throw std::runtime_error( oss.str() );
  4199. }
  4200. return unusedTokens;
  4201. }
  4202. std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4203. std::vector<Parser::Token> unusedTokens;
  4204. int position = 1;
  4205. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4206. Parser::Token const& token = tokens[i];
  4207. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
  4208. if( it != m_positionalArgs.end() )
  4209. it->second.boundField.set( config, token.data );
  4210. else
  4211. unusedTokens.push_back( token );
  4212. if( token.type == Parser::Token::Positional )
  4213. position++;
  4214. }
  4215. return unusedTokens;
  4216. }
  4217. std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4218. if( !m_floatingArg.get() )
  4219. return tokens;
  4220. std::vector<Parser::Token> unusedTokens;
  4221. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4222. Parser::Token const& token = tokens[i];
  4223. if( token.type == Parser::Token::Positional )
  4224. m_floatingArg->boundField.set( config, token.data );
  4225. else
  4226. unusedTokens.push_back( token );
  4227. }
  4228. return unusedTokens;
  4229. }
  4230. void validate() const
  4231. {
  4232. if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
  4233. throw std::logic_error( "No options or arguments specified" );
  4234. for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
  4235. itEnd = m_options.end();
  4236. it != itEnd; ++it )
  4237. it->validate();
  4238. }
  4239. private:
  4240. Detail::BoundArgFunction<ConfigT> m_boundProcessName;
  4241. std::vector<Arg> m_options;
  4242. std::map<int, Arg> m_positionalArgs;
  4243. ArgAutoPtr m_floatingArg;
  4244. int m_highestSpecifiedArgPosition;
  4245. bool m_throwOnUnrecognisedTokens;
  4246. };
  4247. } // end namespace Clara
  4248. STITCH_CLARA_CLOSE_NAMESPACE
  4249. #undef STITCH_CLARA_OPEN_NAMESPACE
  4250. #undef STITCH_CLARA_CLOSE_NAMESPACE
  4251. #endif // TWOBLUECUBES_CLARA_H_INCLUDED
  4252. #undef STITCH_CLARA_OPEN_NAMESPACE
  4253. // Restore Clara's value for console width, if present
  4254. #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4255. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4256. #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4257. #endif
  4258. #include <fstream>
  4259. #include <ctime>
  4260. namespace Catch {
  4261. inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
  4262. inline void abortAfterX( ConfigData& config, int x ) {
  4263. if( x < 1 )
  4264. throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
  4265. config.abortAfter = x;
  4266. }
  4267. inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
  4268. inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); }
  4269. inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
  4270. inline void addWarning( ConfigData& config, std::string const& _warning ) {
  4271. if( _warning == "NoAssertions" )
  4272. config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
  4273. else
  4274. throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' );
  4275. }
  4276. inline void setOrder( ConfigData& config, std::string const& order ) {
  4277. if( startsWith( "declared", order ) )
  4278. config.runOrder = RunTests::InDeclarationOrder;
  4279. else if( startsWith( "lexical", order ) )
  4280. config.runOrder = RunTests::InLexicographicalOrder;
  4281. else if( startsWith( "random", order ) )
  4282. config.runOrder = RunTests::InRandomOrder;
  4283. else
  4284. throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' );
  4285. }
  4286. inline void setRngSeed( ConfigData& config, std::string const& seed ) {
  4287. if( seed == "time" ) {
  4288. config.rngSeed = static_cast<unsigned int>( std::time(0) );
  4289. }
  4290. else {
  4291. std::stringstream ss;
  4292. ss << seed;
  4293. ss >> config.rngSeed;
  4294. if( ss.fail() )
  4295. throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" );
  4296. }
  4297. }
  4298. inline void setVerbosity( ConfigData& config, int level ) {
  4299. // !TBD: accept strings?
  4300. config.verbosity = static_cast<Verbosity::Level>( level );
  4301. }
  4302. inline void setShowDurations( ConfigData& config, bool _showDurations ) {
  4303. config.showDurations = _showDurations
  4304. ? ShowDurations::Always
  4305. : ShowDurations::Never;
  4306. }
  4307. inline void setUseColour( ConfigData& config, std::string const& value ) {
  4308. std::string mode = toLower( value );
  4309. if( mode == "yes" )
  4310. config.useColour = UseColour::Yes;
  4311. else if( mode == "no" )
  4312. config.useColour = UseColour::No;
  4313. else if( mode == "auto" )
  4314. config.useColour = UseColour::Auto;
  4315. else
  4316. throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
  4317. }
  4318. inline void setWaitForKeypress( ConfigData& config, std::string const& keypress ) {
  4319. std::string keypressLc = toLower( keypress );
  4320. if( keypressLc == "start" )
  4321. config.waitForKeypress = WaitForKeypress::BeforeStart;
  4322. else if( keypressLc == "exit" )
  4323. config.waitForKeypress = WaitForKeypress::BeforeExit;
  4324. else if( keypressLc == "both" )
  4325. config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
  4326. else
  4327. throw std::runtime_error( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
  4328. };
  4329. inline void forceColour( ConfigData& config ) {
  4330. config.useColour = UseColour::Yes;
  4331. }
  4332. inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
  4333. std::ifstream f( _filename.c_str() );
  4334. if( !f.is_open() )
  4335. throw std::domain_error( "Unable to load input file: " + _filename );
  4336. std::string line;
  4337. while( std::getline( f, line ) ) {
  4338. line = trim(line);
  4339. if( !line.empty() && !startsWith( line, '#' ) ) {
  4340. if( !startsWith( line, '"' ) )
  4341. line = '"' + line + '"';
  4342. addTestOrTags( config, line + ',' );
  4343. }
  4344. }
  4345. }
  4346. inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
  4347. using namespace Clara;
  4348. CommandLine<ConfigData> cli;
  4349. cli.bindProcessName( &ConfigData::processName );
  4350. cli["-?"]["-h"]["--help"]
  4351. .describe( "display usage information" )
  4352. .bind( &ConfigData::showHelp );
  4353. cli["-l"]["--list-tests"]
  4354. .describe( "list all/matching test cases" )
  4355. .bind( &ConfigData::listTests );
  4356. cli["-t"]["--list-tags"]
  4357. .describe( "list all/matching tags" )
  4358. .bind( &ConfigData::listTags );
  4359. cli["-s"]["--success"]
  4360. .describe( "include successful tests in output" )
  4361. .bind( &ConfigData::showSuccessfulTests );
  4362. cli["-b"]["--break"]
  4363. .describe( "break into debugger on failure" )
  4364. .bind( &ConfigData::shouldDebugBreak );
  4365. cli["-e"]["--nothrow"]
  4366. .describe( "skip exception tests" )
  4367. .bind( &ConfigData::noThrow );
  4368. cli["-i"]["--invisibles"]
  4369. .describe( "show invisibles (tabs, newlines)" )
  4370. .bind( &ConfigData::showInvisibles );
  4371. cli["-o"]["--out"]
  4372. .describe( "output filename" )
  4373. .bind( &ConfigData::outputFilename, "filename" );
  4374. cli["-r"]["--reporter"]
  4375. // .placeholder( "name[:filename]" )
  4376. .describe( "reporter to use (defaults to console)" )
  4377. .bind( &addReporterName, "name" );
  4378. cli["-n"]["--name"]
  4379. .describe( "suite name" )
  4380. .bind( &ConfigData::name, "name" );
  4381. cli["-a"]["--abort"]
  4382. .describe( "abort at first failure" )
  4383. .bind( &abortAfterFirst );
  4384. cli["-x"]["--abortx"]
  4385. .describe( "abort after x failures" )
  4386. .bind( &abortAfterX, "no. failures" );
  4387. cli["-w"]["--warn"]
  4388. .describe( "enable warnings" )
  4389. .bind( &addWarning, "warning name" );
  4390. // - needs updating if reinstated
  4391. // cli.into( &setVerbosity )
  4392. // .describe( "level of verbosity (0=no output)" )
  4393. // .shortOpt( "v")
  4394. // .longOpt( "verbosity" )
  4395. // .placeholder( "level" );
  4396. cli[_]
  4397. .describe( "which test or tests to use" )
  4398. .bind( &addTestOrTags, "test name, pattern or tags" );
  4399. cli["-d"]["--durations"]
  4400. .describe( "show test durations" )
  4401. .bind( &setShowDurations, "yes|no" );
  4402. cli["-f"]["--input-file"]
  4403. .describe( "load test names to run from a file" )
  4404. .bind( &loadTestNamesFromFile, "filename" );
  4405. cli["-#"]["--filenames-as-tags"]
  4406. .describe( "adds a tag for the filename" )
  4407. .bind( &ConfigData::filenamesAsTags );
  4408. cli["-c"]["--section"]
  4409. .describe( "specify section to run" )
  4410. .bind( &addSectionToRun, "section name" );
  4411. // Less common commands which don't have a short form
  4412. cli["--list-test-names-only"]
  4413. .describe( "list all/matching test cases names only" )
  4414. .bind( &ConfigData::listTestNamesOnly );
  4415. cli["--list-extra-info"]
  4416. .describe( "list all/matching test cases with more info" )
  4417. .bind( &ConfigData::listExtraInfo );
  4418. cli["--list-reporters"]
  4419. .describe( "list all reporters" )
  4420. .bind( &ConfigData::listReporters );
  4421. cli["--order"]
  4422. .describe( "test case order (defaults to decl)" )
  4423. .bind( &setOrder, "decl|lex|rand" );
  4424. cli["--rng-seed"]
  4425. .describe( "set a specific seed for random numbers" )
  4426. .bind( &setRngSeed, "'time'|number" );
  4427. cli["--force-colour"]
  4428. .describe( "force colourised output (deprecated)" )
  4429. .bind( &forceColour );
  4430. cli["--use-colour"]
  4431. .describe( "should output be colourised" )
  4432. .bind( &setUseColour, "yes|no" );
  4433. cli["--libidentify"]
  4434. .describe( "report name and version according to libidentify standard" )
  4435. .bind( &ConfigData::libIdentify );
  4436. cli["--wait-for-keypress"]
  4437. .describe( "waits for a keypress before exiting" )
  4438. .bind( &setWaitForKeypress, "start|exit|both" );
  4439. return cli;
  4440. }
  4441. } // end namespace Catch
  4442. // #included from: internal/catch_list.hpp
  4443. #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
  4444. // #included from: catch_text.h
  4445. #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
  4446. #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  4447. #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
  4448. // #included from: ../external/tbc_text_format.h
  4449. // Only use header guard if we are not using an outer namespace
  4450. #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4451. # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4452. # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4453. # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4454. # endif
  4455. # else
  4456. # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4457. # endif
  4458. #endif
  4459. #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4460. #include <string>
  4461. #include <vector>
  4462. #include <sstream>
  4463. // Use optional outer namespace
  4464. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4465. namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  4466. #endif
  4467. namespace Tbc {
  4468. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  4469. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  4470. #else
  4471. const unsigned int consoleWidth = 80;
  4472. #endif
  4473. struct TextAttributes {
  4474. TextAttributes()
  4475. : initialIndent( std::string::npos ),
  4476. indent( 0 ),
  4477. width( consoleWidth-1 )
  4478. {}
  4479. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  4480. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  4481. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  4482. std::size_t initialIndent; // indent of first line, or npos
  4483. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  4484. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  4485. };
  4486. class Text {
  4487. public:
  4488. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  4489. : attr( _attr )
  4490. {
  4491. const std::string wrappableBeforeChars = "[({<\t";
  4492. const std::string wrappableAfterChars = "])}>-,./|\\";
  4493. const std::string wrappableInsteadOfChars = " \n\r";
  4494. std::string indent = _attr.initialIndent != std::string::npos
  4495. ? std::string( _attr.initialIndent, ' ' )
  4496. : std::string( _attr.indent, ' ' );
  4497. typedef std::string::const_iterator iterator;
  4498. iterator it = _str.begin();
  4499. const iterator strEnd = _str.end();
  4500. while( it != strEnd ) {
  4501. if( lines.size() >= 1000 ) {
  4502. lines.push_back( "... message truncated due to excessive size" );
  4503. return;
  4504. }
  4505. std::string suffix;
  4506. std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
  4507. iterator itEnd = it+width;
  4508. iterator itNext = _str.end();
  4509. iterator itNewLine = std::find( it, itEnd, '\n' );
  4510. if( itNewLine != itEnd )
  4511. itEnd = itNewLine;
  4512. if( itEnd != strEnd ) {
  4513. bool foundWrapPoint = false;
  4514. iterator findIt = itEnd;
  4515. do {
  4516. if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
  4517. itEnd = findIt+1;
  4518. itNext = findIt+1;
  4519. foundWrapPoint = true;
  4520. }
  4521. else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
  4522. itEnd = findIt;
  4523. itNext = findIt;
  4524. foundWrapPoint = true;
  4525. }
  4526. else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
  4527. itNext = findIt+1;
  4528. itEnd = findIt;
  4529. foundWrapPoint = true;
  4530. }
  4531. if( findIt == it )
  4532. break;
  4533. else
  4534. --findIt;
  4535. }
  4536. while( !foundWrapPoint );
  4537. if( !foundWrapPoint ) {
  4538. // No good wrap char, so we'll break mid word and add a hyphen
  4539. --itEnd;
  4540. itNext = itEnd;
  4541. suffix = "-";
  4542. }
  4543. else {
  4544. while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
  4545. --itEnd;
  4546. }
  4547. }
  4548. lines.push_back( indent + std::string( it, itEnd ) + suffix );
  4549. if( indent.size() != _attr.indent )
  4550. indent = std::string( _attr.indent, ' ' );
  4551. it = itNext;
  4552. }
  4553. }
  4554. typedef std::vector<std::string>::const_iterator const_iterator;
  4555. const_iterator begin() const { return lines.begin(); }
  4556. const_iterator end() const { return lines.end(); }
  4557. std::string const& last() const { return lines.back(); }
  4558. std::size_t size() const { return lines.size(); }
  4559. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  4560. std::string toString() const {
  4561. std::ostringstream oss;
  4562. oss << *this;
  4563. return oss.str();
  4564. }
  4565. inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  4566. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  4567. it != itEnd; ++it ) {
  4568. if( it != _text.begin() )
  4569. _stream << "\n";
  4570. _stream << *it;
  4571. }
  4572. return _stream;
  4573. }
  4574. private:
  4575. std::string str;
  4576. TextAttributes attr;
  4577. std::vector<std::string> lines;
  4578. };
  4579. } // end namespace Tbc
  4580. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4581. } // end outer namespace
  4582. #endif
  4583. #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4584. #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4585. namespace Catch {
  4586. using Tbc::Text;
  4587. using Tbc::TextAttributes;
  4588. }
  4589. // #included from: catch_console_colour.hpp
  4590. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  4591. namespace Catch {
  4592. struct Colour {
  4593. enum Code {
  4594. None = 0,
  4595. White,
  4596. Red,
  4597. Green,
  4598. Blue,
  4599. Cyan,
  4600. Yellow,
  4601. Grey,
  4602. Bright = 0x10,
  4603. BrightRed = Bright | Red,
  4604. BrightGreen = Bright | Green,
  4605. LightGrey = Bright | Grey,
  4606. BrightWhite = Bright | White,
  4607. // By intention
  4608. FileName = LightGrey,
  4609. Warning = Yellow,
  4610. ResultError = BrightRed,
  4611. ResultSuccess = BrightGreen,
  4612. ResultExpectedFailure = Warning,
  4613. Error = BrightRed,
  4614. Success = Green,
  4615. OriginalExpression = Cyan,
  4616. ReconstructedExpression = Yellow,
  4617. SecondaryText = LightGrey,
  4618. Headers = White
  4619. };
  4620. // Use constructed object for RAII guard
  4621. Colour( Code _colourCode );
  4622. Colour( Colour const& other );
  4623. ~Colour();
  4624. // Use static method for one-shot changes
  4625. static void use( Code _colourCode );
  4626. private:
  4627. bool m_moved;
  4628. };
  4629. inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
  4630. } // end namespace Catch
  4631. // #included from: catch_interfaces_reporter.h
  4632. #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
  4633. #include <string>
  4634. #include <ostream>
  4635. #include <map>
  4636. namespace Catch
  4637. {
  4638. struct ReporterConfig {
  4639. explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
  4640. : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
  4641. ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
  4642. : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
  4643. std::ostream& stream() const { return *m_stream; }
  4644. Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
  4645. private:
  4646. std::ostream* m_stream;
  4647. Ptr<IConfig const> m_fullConfig;
  4648. };
  4649. struct ReporterPreferences {
  4650. ReporterPreferences()
  4651. : shouldRedirectStdOut( false )
  4652. {}
  4653. bool shouldRedirectStdOut;
  4654. };
  4655. template<typename T>
  4656. struct LazyStat : Option<T> {
  4657. LazyStat() : used( false ) {}
  4658. LazyStat& operator=( T const& _value ) {
  4659. Option<T>::operator=( _value );
  4660. used = false;
  4661. return *this;
  4662. }
  4663. void reset() {
  4664. Option<T>::reset();
  4665. used = false;
  4666. }
  4667. bool used;
  4668. };
  4669. struct TestRunInfo {
  4670. TestRunInfo( std::string const& _name ) : name( _name ) {}
  4671. std::string name;
  4672. };
  4673. struct GroupInfo {
  4674. GroupInfo( std::string const& _name,
  4675. std::size_t _groupIndex,
  4676. std::size_t _groupsCount )
  4677. : name( _name ),
  4678. groupIndex( _groupIndex ),
  4679. groupsCounts( _groupsCount )
  4680. {}
  4681. std::string name;
  4682. std::size_t groupIndex;
  4683. std::size_t groupsCounts;
  4684. };
  4685. struct AssertionStats {
  4686. AssertionStats( AssertionResult const& _assertionResult,
  4687. std::vector<MessageInfo> const& _infoMessages,
  4688. Totals const& _totals )
  4689. : assertionResult( _assertionResult ),
  4690. infoMessages( _infoMessages ),
  4691. totals( _totals )
  4692. {
  4693. if( assertionResult.hasMessage() ) {
  4694. // Copy message into messages list.
  4695. // !TBD This should have been done earlier, somewhere
  4696. MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
  4697. builder << assertionResult.getMessage();
  4698. builder.m_info.message = builder.m_stream.str();
  4699. infoMessages.push_back( builder.m_info );
  4700. }
  4701. }
  4702. virtual ~AssertionStats();
  4703. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4704. AssertionStats( AssertionStats const& ) = default;
  4705. AssertionStats( AssertionStats && ) = default;
  4706. AssertionStats& operator = ( AssertionStats const& ) = default;
  4707. AssertionStats& operator = ( AssertionStats && ) = default;
  4708. # endif
  4709. AssertionResult assertionResult;
  4710. std::vector<MessageInfo> infoMessages;
  4711. Totals totals;
  4712. };
  4713. struct SectionStats {
  4714. SectionStats( SectionInfo const& _sectionInfo,
  4715. Counts const& _assertions,
  4716. double _durationInSeconds,
  4717. bool _missingAssertions )
  4718. : sectionInfo( _sectionInfo ),
  4719. assertions( _assertions ),
  4720. durationInSeconds( _durationInSeconds ),
  4721. missingAssertions( _missingAssertions )
  4722. {}
  4723. virtual ~SectionStats();
  4724. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4725. SectionStats( SectionStats const& ) = default;
  4726. SectionStats( SectionStats && ) = default;
  4727. SectionStats& operator = ( SectionStats const& ) = default;
  4728. SectionStats& operator = ( SectionStats && ) = default;
  4729. # endif
  4730. SectionInfo sectionInfo;
  4731. Counts assertions;
  4732. double durationInSeconds;
  4733. bool missingAssertions;
  4734. };
  4735. struct TestCaseStats {
  4736. TestCaseStats( TestCaseInfo const& _testInfo,
  4737. Totals const& _totals,
  4738. std::string const& _stdOut,
  4739. std::string const& _stdErr,
  4740. bool _aborting )
  4741. : testInfo( _testInfo ),
  4742. totals( _totals ),
  4743. stdOut( _stdOut ),
  4744. stdErr( _stdErr ),
  4745. aborting( _aborting )
  4746. {}
  4747. virtual ~TestCaseStats();
  4748. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4749. TestCaseStats( TestCaseStats const& ) = default;
  4750. TestCaseStats( TestCaseStats && ) = default;
  4751. TestCaseStats& operator = ( TestCaseStats const& ) = default;
  4752. TestCaseStats& operator = ( TestCaseStats && ) = default;
  4753. # endif
  4754. TestCaseInfo testInfo;
  4755. Totals totals;
  4756. std::string stdOut;
  4757. std::string stdErr;
  4758. bool aborting;
  4759. };
  4760. struct TestGroupStats {
  4761. TestGroupStats( GroupInfo const& _groupInfo,
  4762. Totals const& _totals,
  4763. bool _aborting )
  4764. : groupInfo( _groupInfo ),
  4765. totals( _totals ),
  4766. aborting( _aborting )
  4767. {}
  4768. TestGroupStats( GroupInfo const& _groupInfo )
  4769. : groupInfo( _groupInfo ),
  4770. aborting( false )
  4771. {}
  4772. virtual ~TestGroupStats();
  4773. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4774. TestGroupStats( TestGroupStats const& ) = default;
  4775. TestGroupStats( TestGroupStats && ) = default;
  4776. TestGroupStats& operator = ( TestGroupStats const& ) = default;
  4777. TestGroupStats& operator = ( TestGroupStats && ) = default;
  4778. # endif
  4779. GroupInfo groupInfo;
  4780. Totals totals;
  4781. bool aborting;
  4782. };
  4783. struct TestRunStats {
  4784. TestRunStats( TestRunInfo const& _runInfo,
  4785. Totals const& _totals,
  4786. bool _aborting )
  4787. : runInfo( _runInfo ),
  4788. totals( _totals ),
  4789. aborting( _aborting )
  4790. {}
  4791. virtual ~TestRunStats();
  4792. # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4793. TestRunStats( TestRunStats const& _other )
  4794. : runInfo( _other.runInfo ),
  4795. totals( _other.totals ),
  4796. aborting( _other.aborting )
  4797. {}
  4798. # else
  4799. TestRunStats( TestRunStats const& ) = default;
  4800. TestRunStats( TestRunStats && ) = default;
  4801. TestRunStats& operator = ( TestRunStats const& ) = default;
  4802. TestRunStats& operator = ( TestRunStats && ) = default;
  4803. # endif
  4804. TestRunInfo runInfo;
  4805. Totals totals;
  4806. bool aborting;
  4807. };
  4808. class MultipleReporters;
  4809. struct IStreamingReporter : IShared {
  4810. virtual ~IStreamingReporter();
  4811. // Implementing class must also provide the following static method:
  4812. // static std::string getDescription();
  4813. virtual ReporterPreferences getPreferences() const = 0;
  4814. virtual void noMatchingTestCases( std::string const& spec ) = 0;
  4815. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  4816. virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
  4817. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  4818. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  4819. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  4820. // The return value indicates if the messages buffer should be cleared:
  4821. virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
  4822. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  4823. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  4824. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
  4825. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  4826. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  4827. virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
  4828. };
  4829. struct IReporterFactory : IShared {
  4830. virtual ~IReporterFactory();
  4831. virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
  4832. virtual std::string getDescription() const = 0;
  4833. };
  4834. struct IReporterRegistry {
  4835. typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
  4836. typedef std::vector<Ptr<IReporterFactory> > Listeners;
  4837. virtual ~IReporterRegistry();
  4838. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
  4839. virtual FactoryMap const& getFactories() const = 0;
  4840. virtual Listeners const& getListeners() const = 0;
  4841. };
  4842. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
  4843. }
  4844. #include <limits>
  4845. #include <algorithm>
  4846. namespace Catch {
  4847. inline std::size_t listTests( Config const& config ) {
  4848. TestSpec testSpec = config.testSpec();
  4849. if( config.testSpec().hasFilters() )
  4850. Catch::cout() << "Matching test cases:\n";
  4851. else {
  4852. Catch::cout() << "All available test cases:\n";
  4853. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4854. }
  4855. std::size_t matchedTests = 0;
  4856. TextAttributes nameAttr, descAttr, tagsAttr;
  4857. nameAttr.setInitialIndent( 2 ).setIndent( 4 );
  4858. descAttr.setIndent( 4 );
  4859. tagsAttr.setIndent( 6 );
  4860. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4861. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4862. it != itEnd;
  4863. ++it ) {
  4864. matchedTests++;
  4865. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4866. Colour::Code colour = testCaseInfo.isHidden()
  4867. ? Colour::SecondaryText
  4868. : Colour::None;
  4869. Colour colourGuard( colour );
  4870. Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
  4871. if( config.listExtraInfo() ) {
  4872. Catch::cout() << " " << testCaseInfo.lineInfo << std::endl;
  4873. std::string description = testCaseInfo.description;
  4874. if( description.empty() )
  4875. description = "(NO DESCRIPTION)";
  4876. Catch::cout() << Text( description, descAttr ) << std::endl;
  4877. }
  4878. if( !testCaseInfo.tags.empty() )
  4879. Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
  4880. }
  4881. if( !config.testSpec().hasFilters() )
  4882. Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
  4883. else
  4884. Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
  4885. return matchedTests;
  4886. }
  4887. inline std::size_t listTestsNamesOnly( Config const& config ) {
  4888. TestSpec testSpec = config.testSpec();
  4889. if( !config.testSpec().hasFilters() )
  4890. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4891. std::size_t matchedTests = 0;
  4892. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4893. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4894. it != itEnd;
  4895. ++it ) {
  4896. matchedTests++;
  4897. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4898. if( startsWith( testCaseInfo.name, '#' ) )
  4899. Catch::cout() << '"' << testCaseInfo.name << '"';
  4900. else
  4901. Catch::cout() << testCaseInfo.name;
  4902. if ( config.listExtraInfo() )
  4903. Catch::cout() << "\t@" << testCaseInfo.lineInfo;
  4904. Catch::cout() << std::endl;
  4905. }
  4906. return matchedTests;
  4907. }
  4908. struct TagInfo {
  4909. TagInfo() : count ( 0 ) {}
  4910. void add( std::string const& spelling ) {
  4911. ++count;
  4912. spellings.insert( spelling );
  4913. }
  4914. std::string all() const {
  4915. std::string out;
  4916. for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
  4917. it != itEnd;
  4918. ++it )
  4919. out += "[" + *it + "]";
  4920. return out;
  4921. }
  4922. std::set<std::string> spellings;
  4923. std::size_t count;
  4924. };
  4925. inline std::size_t listTags( Config const& config ) {
  4926. TestSpec testSpec = config.testSpec();
  4927. if( config.testSpec().hasFilters() )
  4928. Catch::cout() << "Tags for matching test cases:\n";
  4929. else {
  4930. Catch::cout() << "All available tags:\n";
  4931. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4932. }
  4933. std::map<std::string, TagInfo> tagCounts;
  4934. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4935. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4936. it != itEnd;
  4937. ++it ) {
  4938. for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
  4939. tagItEnd = it->getTestCaseInfo().tags.end();
  4940. tagIt != tagItEnd;
  4941. ++tagIt ) {
  4942. std::string tagName = *tagIt;
  4943. std::string lcaseTagName = toLower( tagName );
  4944. std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
  4945. if( countIt == tagCounts.end() )
  4946. countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
  4947. countIt->second.add( tagName );
  4948. }
  4949. }
  4950. for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
  4951. countItEnd = tagCounts.end();
  4952. countIt != countItEnd;
  4953. ++countIt ) {
  4954. std::ostringstream oss;
  4955. oss << " " << std::setw(2) << countIt->second.count << " ";
  4956. Text wrapper( countIt->second.all(), TextAttributes()
  4957. .setInitialIndent( 0 )
  4958. .setIndent( oss.str().size() )
  4959. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
  4960. Catch::cout() << oss.str() << wrapper << '\n';
  4961. }
  4962. Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
  4963. return tagCounts.size();
  4964. }
  4965. inline std::size_t listReporters( Config const& /*config*/ ) {
  4966. Catch::cout() << "Available reporters:\n";
  4967. IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
  4968. IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
  4969. std::size_t maxNameLen = 0;
  4970. for(it = itBegin; it != itEnd; ++it )
  4971. maxNameLen = (std::max)( maxNameLen, it->first.size() );
  4972. for(it = itBegin; it != itEnd; ++it ) {
  4973. Text wrapper( it->second->getDescription(), TextAttributes()
  4974. .setInitialIndent( 0 )
  4975. .setIndent( 7+maxNameLen )
  4976. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
  4977. Catch::cout() << " "
  4978. << it->first
  4979. << ':'
  4980. << std::string( maxNameLen - it->first.size() + 2, ' ' )
  4981. << wrapper << '\n';
  4982. }
  4983. Catch::cout() << std::endl;
  4984. return factories.size();
  4985. }
  4986. inline Option<std::size_t> list( Config const& config ) {
  4987. Option<std::size_t> listedCount;
  4988. if( config.listTests() || ( config.listExtraInfo() && !config.listTestNamesOnly() ) )
  4989. listedCount = listedCount.valueOr(0) + listTests( config );
  4990. if( config.listTestNamesOnly() )
  4991. listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
  4992. if( config.listTags() )
  4993. listedCount = listedCount.valueOr(0) + listTags( config );
  4994. if( config.listReporters() )
  4995. listedCount = listedCount.valueOr(0) + listReporters( config );
  4996. return listedCount;
  4997. }
  4998. } // end namespace Catch
  4999. // #included from: internal/catch_run_context.hpp
  5000. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  5001. // #included from: catch_test_case_tracker.hpp
  5002. #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  5003. #include <algorithm>
  5004. #include <string>
  5005. #include <assert.h>
  5006. #include <vector>
  5007. #include <stdexcept>
  5008. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  5009. namespace Catch {
  5010. namespace TestCaseTracking {
  5011. struct NameAndLocation {
  5012. std::string name;
  5013. SourceLineInfo location;
  5014. NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
  5015. : name( _name ),
  5016. location( _location )
  5017. {}
  5018. };
  5019. struct ITracker : SharedImpl<> {
  5020. virtual ~ITracker();
  5021. // static queries
  5022. virtual NameAndLocation const& nameAndLocation() const = 0;
  5023. // dynamic queries
  5024. virtual bool isComplete() const = 0; // Successfully completed or failed
  5025. virtual bool isSuccessfullyCompleted() const = 0;
  5026. virtual bool isOpen() const = 0; // Started but not complete
  5027. virtual bool hasChildren() const = 0;
  5028. virtual ITracker& parent() = 0;
  5029. // actions
  5030. virtual void close() = 0; // Successfully complete
  5031. virtual void fail() = 0;
  5032. virtual void markAsNeedingAnotherRun() = 0;
  5033. virtual void addChild( Ptr<ITracker> const& child ) = 0;
  5034. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0;
  5035. virtual void openChild() = 0;
  5036. // Debug/ checking
  5037. virtual bool isSectionTracker() const = 0;
  5038. virtual bool isIndexTracker() const = 0;
  5039. };
  5040. class TrackerContext {
  5041. enum RunState {
  5042. NotStarted,
  5043. Executing,
  5044. CompletedCycle
  5045. };
  5046. Ptr<ITracker> m_rootTracker;
  5047. ITracker* m_currentTracker;
  5048. RunState m_runState;
  5049. public:
  5050. static TrackerContext& instance() {
  5051. static TrackerContext s_instance;
  5052. return s_instance;
  5053. }
  5054. TrackerContext()
  5055. : m_currentTracker( CATCH_NULL ),
  5056. m_runState( NotStarted )
  5057. {}
  5058. ITracker& startRun();
  5059. void endRun() {
  5060. m_rootTracker.reset();
  5061. m_currentTracker = CATCH_NULL;
  5062. m_runState = NotStarted;
  5063. }
  5064. void startCycle() {
  5065. m_currentTracker = m_rootTracker.get();
  5066. m_runState = Executing;
  5067. }
  5068. void completeCycle() {
  5069. m_runState = CompletedCycle;
  5070. }
  5071. bool completedCycle() const {
  5072. return m_runState == CompletedCycle;
  5073. }
  5074. ITracker& currentTracker() {
  5075. return *m_currentTracker;
  5076. }
  5077. void setCurrentTracker( ITracker* tracker ) {
  5078. m_currentTracker = tracker;
  5079. }
  5080. };
  5081. class TrackerBase : public ITracker {
  5082. protected:
  5083. enum CycleState {
  5084. NotStarted,
  5085. Executing,
  5086. ExecutingChildren,
  5087. NeedsAnotherRun,
  5088. CompletedSuccessfully,
  5089. Failed
  5090. };
  5091. class TrackerHasName {
  5092. NameAndLocation m_nameAndLocation;
  5093. public:
  5094. TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {}
  5095. bool operator ()( Ptr<ITracker> const& tracker ) {
  5096. return
  5097. tracker->nameAndLocation().name == m_nameAndLocation.name &&
  5098. tracker->nameAndLocation().location == m_nameAndLocation.location;
  5099. }
  5100. };
  5101. typedef std::vector<Ptr<ITracker> > Children;
  5102. NameAndLocation m_nameAndLocation;
  5103. TrackerContext& m_ctx;
  5104. ITracker* m_parent;
  5105. Children m_children;
  5106. CycleState m_runState;
  5107. public:
  5108. TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5109. : m_nameAndLocation( nameAndLocation ),
  5110. m_ctx( ctx ),
  5111. m_parent( parent ),
  5112. m_runState( NotStarted )
  5113. {}
  5114. virtual ~TrackerBase();
  5115. virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE {
  5116. return m_nameAndLocation;
  5117. }
  5118. virtual bool isComplete() const CATCH_OVERRIDE {
  5119. return m_runState == CompletedSuccessfully || m_runState == Failed;
  5120. }
  5121. virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
  5122. return m_runState == CompletedSuccessfully;
  5123. }
  5124. virtual bool isOpen() const CATCH_OVERRIDE {
  5125. return m_runState != NotStarted && !isComplete();
  5126. }
  5127. virtual bool hasChildren() const CATCH_OVERRIDE {
  5128. return !m_children.empty();
  5129. }
  5130. virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
  5131. m_children.push_back( child );
  5132. }
  5133. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE {
  5134. Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
  5135. return( it != m_children.end() )
  5136. ? it->get()
  5137. : CATCH_NULL;
  5138. }
  5139. virtual ITracker& parent() CATCH_OVERRIDE {
  5140. assert( m_parent ); // Should always be non-null except for root
  5141. return *m_parent;
  5142. }
  5143. virtual void openChild() CATCH_OVERRIDE {
  5144. if( m_runState != ExecutingChildren ) {
  5145. m_runState = ExecutingChildren;
  5146. if( m_parent )
  5147. m_parent->openChild();
  5148. }
  5149. }
  5150. virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
  5151. virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
  5152. void open() {
  5153. m_runState = Executing;
  5154. moveToThis();
  5155. if( m_parent )
  5156. m_parent->openChild();
  5157. }
  5158. virtual void close() CATCH_OVERRIDE {
  5159. // Close any still open children (e.g. generators)
  5160. while( &m_ctx.currentTracker() != this )
  5161. m_ctx.currentTracker().close();
  5162. switch( m_runState ) {
  5163. case NotStarted:
  5164. case CompletedSuccessfully:
  5165. case Failed:
  5166. throw std::logic_error( "Illogical state" );
  5167. case NeedsAnotherRun:
  5168. break;;
  5169. case Executing:
  5170. m_runState = CompletedSuccessfully;
  5171. break;
  5172. case ExecutingChildren:
  5173. if( m_children.empty() || m_children.back()->isComplete() )
  5174. m_runState = CompletedSuccessfully;
  5175. break;
  5176. default:
  5177. throw std::logic_error( "Unexpected state" );
  5178. }
  5179. moveToParent();
  5180. m_ctx.completeCycle();
  5181. }
  5182. virtual void fail() CATCH_OVERRIDE {
  5183. m_runState = Failed;
  5184. if( m_parent )
  5185. m_parent->markAsNeedingAnotherRun();
  5186. moveToParent();
  5187. m_ctx.completeCycle();
  5188. }
  5189. virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
  5190. m_runState = NeedsAnotherRun;
  5191. }
  5192. private:
  5193. void moveToParent() {
  5194. assert( m_parent );
  5195. m_ctx.setCurrentTracker( m_parent );
  5196. }
  5197. void moveToThis() {
  5198. m_ctx.setCurrentTracker( this );
  5199. }
  5200. };
  5201. class SectionTracker : public TrackerBase {
  5202. std::vector<std::string> m_filters;
  5203. public:
  5204. SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5205. : TrackerBase( nameAndLocation, ctx, parent )
  5206. {
  5207. if( parent ) {
  5208. while( !parent->isSectionTracker() )
  5209. parent = &parent->parent();
  5210. SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
  5211. addNextFilters( parentSection.m_filters );
  5212. }
  5213. }
  5214. virtual ~SectionTracker();
  5215. virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
  5216. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
  5217. SectionTracker* section = CATCH_NULL;
  5218. ITracker& currentTracker = ctx.currentTracker();
  5219. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5220. assert( childTracker );
  5221. assert( childTracker->isSectionTracker() );
  5222. section = static_cast<SectionTracker*>( childTracker );
  5223. }
  5224. else {
  5225. section = new SectionTracker( nameAndLocation, ctx, &currentTracker );
  5226. currentTracker.addChild( section );
  5227. }
  5228. if( !ctx.completedCycle() )
  5229. section->tryOpen();
  5230. return *section;
  5231. }
  5232. void tryOpen() {
  5233. if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) )
  5234. open();
  5235. }
  5236. void addInitialFilters( std::vector<std::string> const& filters ) {
  5237. if( !filters.empty() ) {
  5238. m_filters.push_back(""); // Root - should never be consulted
  5239. m_filters.push_back(""); // Test Case - not a section filter
  5240. m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
  5241. }
  5242. }
  5243. void addNextFilters( std::vector<std::string> const& filters ) {
  5244. if( filters.size() > 1 )
  5245. m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() );
  5246. }
  5247. };
  5248. class IndexTracker : public TrackerBase {
  5249. int m_size;
  5250. int m_index;
  5251. public:
  5252. IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size )
  5253. : TrackerBase( nameAndLocation, ctx, parent ),
  5254. m_size( size ),
  5255. m_index( -1 )
  5256. {}
  5257. virtual ~IndexTracker();
  5258. virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
  5259. static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) {
  5260. IndexTracker* tracker = CATCH_NULL;
  5261. ITracker& currentTracker = ctx.currentTracker();
  5262. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5263. assert( childTracker );
  5264. assert( childTracker->isIndexTracker() );
  5265. tracker = static_cast<IndexTracker*>( childTracker );
  5266. }
  5267. else {
  5268. tracker = new IndexTracker( nameAndLocation, ctx, &currentTracker, size );
  5269. currentTracker.addChild( tracker );
  5270. }
  5271. if( !ctx.completedCycle() && !tracker->isComplete() ) {
  5272. if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
  5273. tracker->moveNext();
  5274. tracker->open();
  5275. }
  5276. return *tracker;
  5277. }
  5278. int index() const { return m_index; }
  5279. void moveNext() {
  5280. m_index++;
  5281. m_children.clear();
  5282. }
  5283. virtual void close() CATCH_OVERRIDE {
  5284. TrackerBase::close();
  5285. if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
  5286. m_runState = Executing;
  5287. }
  5288. };
  5289. inline ITracker& TrackerContext::startRun() {
  5290. m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL );
  5291. m_currentTracker = CATCH_NULL;
  5292. m_runState = Executing;
  5293. return *m_rootTracker;
  5294. }
  5295. } // namespace TestCaseTracking
  5296. using TestCaseTracking::ITracker;
  5297. using TestCaseTracking::TrackerContext;
  5298. using TestCaseTracking::SectionTracker;
  5299. using TestCaseTracking::IndexTracker;
  5300. } // namespace Catch
  5301. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  5302. // #included from: catch_fatal_condition.hpp
  5303. #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
  5304. namespace Catch {
  5305. // Report the error condition
  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. struct FatalConditionHandler {
  5335. void reset() {}
  5336. };
  5337. }
  5338. # else // CATCH_CONFIG_WINDOWS_SEH is defined
  5339. namespace Catch {
  5340. struct SignalDefs { DWORD id; const char* name; };
  5341. extern SignalDefs signalDefs[];
  5342. // There is no 1-1 mapping between signals and windows exceptions.
  5343. // Windows can easily distinguish between SO and SigSegV,
  5344. // but SigInt, SigTerm, etc are handled differently.
  5345. SignalDefs signalDefs[] = {
  5346. { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
  5347. { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
  5348. { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
  5349. { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" },
  5350. };
  5351. struct FatalConditionHandler {
  5352. static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
  5353. for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5354. if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
  5355. reportFatal(signalDefs[i].name);
  5356. }
  5357. }
  5358. // If its not an exception we care about, pass it along.
  5359. // This stops us from eating debugger breaks etc.
  5360. return EXCEPTION_CONTINUE_SEARCH;
  5361. }
  5362. FatalConditionHandler() {
  5363. isSet = true;
  5364. // 32k seems enough for Catch to handle stack overflow,
  5365. // but the value was found experimentally, so there is no strong guarantee
  5366. guaranteeSize = 32 * 1024;
  5367. exceptionHandlerHandle = CATCH_NULL;
  5368. // Register as first handler in current chain
  5369. exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
  5370. // Pass in guarantee size to be filled
  5371. SetThreadStackGuarantee(&guaranteeSize);
  5372. }
  5373. static void reset() {
  5374. if (isSet) {
  5375. // Unregister handler and restore the old guarantee
  5376. RemoveVectoredExceptionHandler(exceptionHandlerHandle);
  5377. SetThreadStackGuarantee(&guaranteeSize);
  5378. exceptionHandlerHandle = CATCH_NULL;
  5379. isSet = false;
  5380. }
  5381. }
  5382. ~FatalConditionHandler() {
  5383. reset();
  5384. }
  5385. private:
  5386. static bool isSet;
  5387. static ULONG guaranteeSize;
  5388. static PVOID exceptionHandlerHandle;
  5389. };
  5390. bool FatalConditionHandler::isSet = false;
  5391. ULONG FatalConditionHandler::guaranteeSize = 0;
  5392. PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL;
  5393. } // namespace Catch
  5394. # endif // CATCH_CONFIG_WINDOWS_SEH
  5395. #else // Not Windows - assumed to be POSIX compatible //////////////////////////
  5396. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  5397. namespace Catch {
  5398. struct FatalConditionHandler {
  5399. void reset() {}
  5400. };
  5401. }
  5402. # else // CATCH_CONFIG_POSIX_SIGNALS is defined
  5403. #include <signal.h>
  5404. namespace Catch {
  5405. struct SignalDefs {
  5406. int id;
  5407. const char* name;
  5408. };
  5409. extern SignalDefs signalDefs[];
  5410. SignalDefs signalDefs[] = {
  5411. { SIGINT, "SIGINT - Terminal interrupt signal" },
  5412. { SIGILL, "SIGILL - Illegal instruction signal" },
  5413. { SIGFPE, "SIGFPE - Floating point error signal" },
  5414. { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
  5415. { SIGTERM, "SIGTERM - Termination request signal" },
  5416. { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
  5417. };
  5418. struct FatalConditionHandler {
  5419. static bool isSet;
  5420. static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)];
  5421. static stack_t oldSigStack;
  5422. static char altStackMem[SIGSTKSZ];
  5423. static void handleSignal( int sig ) {
  5424. std::string name = "<unknown signal>";
  5425. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5426. SignalDefs &def = signalDefs[i];
  5427. if (sig == def.id) {
  5428. name = def.name;
  5429. break;
  5430. }
  5431. }
  5432. reset();
  5433. reportFatal(name);
  5434. raise( sig );
  5435. }
  5436. FatalConditionHandler() {
  5437. isSet = true;
  5438. stack_t sigStack;
  5439. sigStack.ss_sp = altStackMem;
  5440. sigStack.ss_size = SIGSTKSZ;
  5441. sigStack.ss_flags = 0;
  5442. sigaltstack(&sigStack, &oldSigStack);
  5443. struct sigaction sa = { 0 };
  5444. sa.sa_handler = handleSignal;
  5445. sa.sa_flags = SA_ONSTACK;
  5446. for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
  5447. sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
  5448. }
  5449. }
  5450. ~FatalConditionHandler() {
  5451. reset();
  5452. }
  5453. static void reset() {
  5454. if( isSet ) {
  5455. // Set signals back to previous values -- hopefully nobody overwrote them in the meantime
  5456. for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
  5457. sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL);
  5458. }
  5459. // Return the old stack
  5460. sigaltstack(&oldSigStack, CATCH_NULL);
  5461. isSet = false;
  5462. }
  5463. }
  5464. };
  5465. bool FatalConditionHandler::isSet = false;
  5466. struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
  5467. stack_t FatalConditionHandler::oldSigStack = {};
  5468. char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
  5469. } // namespace Catch
  5470. # endif // CATCH_CONFIG_POSIX_SIGNALS
  5471. #endif // not Windows
  5472. #include <cassert>
  5473. #include <set>
  5474. #include <string>
  5475. namespace Catch {
  5476. class StreamRedirect {
  5477. public:
  5478. StreamRedirect( std::ostream& stream, std::string& targetString )
  5479. : m_stream( stream ),
  5480. m_prevBuf( stream.rdbuf() ),
  5481. m_targetString( targetString )
  5482. {
  5483. stream.rdbuf( m_oss.rdbuf() );
  5484. }
  5485. ~StreamRedirect() {
  5486. m_targetString += m_oss.str();
  5487. m_stream.rdbuf( m_prevBuf );
  5488. }
  5489. private:
  5490. std::ostream& m_stream;
  5491. std::streambuf* m_prevBuf;
  5492. std::ostringstream m_oss;
  5493. std::string& m_targetString;
  5494. };
  5495. // StdErr has two constituent streams in C++, std::cerr and std::clog
  5496. // This means that we need to redirect 2 streams into 1 to keep proper
  5497. // order of writes and cannot use StreamRedirect on its own
  5498. class StdErrRedirect {
  5499. public:
  5500. StdErrRedirect(std::string& targetString)
  5501. :m_cerrBuf( cerr().rdbuf() ), m_clogBuf(clog().rdbuf()),
  5502. m_targetString(targetString){
  5503. cerr().rdbuf(m_oss.rdbuf());
  5504. clog().rdbuf(m_oss.rdbuf());
  5505. }
  5506. ~StdErrRedirect() {
  5507. m_targetString += m_oss.str();
  5508. cerr().rdbuf(m_cerrBuf);
  5509. clog().rdbuf(m_clogBuf);
  5510. }
  5511. private:
  5512. std::streambuf* m_cerrBuf;
  5513. std::streambuf* m_clogBuf;
  5514. std::ostringstream m_oss;
  5515. std::string& m_targetString;
  5516. };
  5517. ///////////////////////////////////////////////////////////////////////////
  5518. class RunContext : public IResultCapture, public IRunner {
  5519. RunContext( RunContext const& );
  5520. void operator =( RunContext const& );
  5521. public:
  5522. explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
  5523. : m_runInfo( _config->name() ),
  5524. m_context( getCurrentMutableContext() ),
  5525. m_activeTestCase( CATCH_NULL ),
  5526. m_config( _config ),
  5527. m_reporter( reporter ),
  5528. m_shouldReportUnexpected ( true )
  5529. {
  5530. m_context.setRunner( this );
  5531. m_context.setConfig( m_config );
  5532. m_context.setResultCapture( this );
  5533. m_reporter->testRunStarting( m_runInfo );
  5534. }
  5535. virtual ~RunContext() {
  5536. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
  5537. }
  5538. void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
  5539. m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
  5540. }
  5541. void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
  5542. m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
  5543. }
  5544. Totals runTest( TestCase const& testCase ) {
  5545. Totals prevTotals = m_totals;
  5546. std::string redirectedCout;
  5547. std::string redirectedCerr;
  5548. TestCaseInfo testInfo = testCase.getTestCaseInfo();
  5549. m_reporter->testCaseStarting( testInfo );
  5550. m_activeTestCase = &testCase;
  5551. do {
  5552. ITracker& rootTracker = m_trackerContext.startRun();
  5553. assert( rootTracker.isSectionTracker() );
  5554. static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() );
  5555. do {
  5556. m_trackerContext.startCycle();
  5557. m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) );
  5558. runCurrentTest( redirectedCout, redirectedCerr );
  5559. }
  5560. while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
  5561. }
  5562. // !TBD: deprecated - this will be replaced by indexed trackers
  5563. while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
  5564. Totals deltaTotals = m_totals.delta( prevTotals );
  5565. if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
  5566. deltaTotals.assertions.failed++;
  5567. deltaTotals.testCases.passed--;
  5568. deltaTotals.testCases.failed++;
  5569. }
  5570. m_totals.testCases += deltaTotals.testCases;
  5571. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5572. deltaTotals,
  5573. redirectedCout,
  5574. redirectedCerr,
  5575. aborting() ) );
  5576. m_activeTestCase = CATCH_NULL;
  5577. m_testCaseTracker = CATCH_NULL;
  5578. return deltaTotals;
  5579. }
  5580. Ptr<IConfig const> config() const {
  5581. return m_config;
  5582. }
  5583. private: // IResultCapture
  5584. virtual void assertionEnded( AssertionResult const& result ) {
  5585. if( result.getResultType() == ResultWas::Ok ) {
  5586. m_totals.assertions.passed++;
  5587. }
  5588. else if( !result.isOk() ) {
  5589. if( m_activeTestCase->getTestCaseInfo().okToFail() )
  5590. m_totals.assertions.failedButOk++;
  5591. else
  5592. m_totals.assertions.failed++;
  5593. }
  5594. // We have no use for the return value (whether messages should be cleared), because messages were made scoped
  5595. // and should be let to clear themselves out.
  5596. static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
  5597. // Reset working state
  5598. m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
  5599. m_lastResult = result;
  5600. }
  5601. virtual bool lastAssertionPassed()
  5602. {
  5603. return m_totals.assertions.passed == (m_prevPassed + 1);
  5604. }
  5605. virtual void assertionPassed()
  5606. {
  5607. m_totals.assertions.passed++;
  5608. m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}";
  5609. m_lastAssertionInfo.macroName = "";
  5610. }
  5611. virtual void assertionRun()
  5612. {
  5613. m_prevPassed = m_totals.assertions.passed;
  5614. }
  5615. virtual bool sectionStarted (
  5616. SectionInfo const& sectionInfo,
  5617. Counts& assertions
  5618. )
  5619. {
  5620. ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) );
  5621. if( !sectionTracker.isOpen() )
  5622. return false;
  5623. m_activeSections.push_back( &sectionTracker );
  5624. m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
  5625. m_reporter->sectionStarting( sectionInfo );
  5626. assertions = m_totals.assertions;
  5627. return true;
  5628. }
  5629. bool testForMissingAssertions( Counts& assertions ) {
  5630. if( assertions.total() != 0 )
  5631. return false;
  5632. if( !m_config->warnAboutMissingAssertions() )
  5633. return false;
  5634. if( m_trackerContext.currentTracker().hasChildren() )
  5635. return false;
  5636. m_totals.assertions.failed++;
  5637. assertions.failed++;
  5638. return true;
  5639. }
  5640. virtual void sectionEnded( SectionEndInfo const& endInfo ) {
  5641. Counts assertions = m_totals.assertions - endInfo.prevAssertions;
  5642. bool missingAssertions = testForMissingAssertions( assertions );
  5643. if( !m_activeSections.empty() ) {
  5644. m_activeSections.back()->close();
  5645. m_activeSections.pop_back();
  5646. }
  5647. m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
  5648. m_messages.clear();
  5649. }
  5650. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
  5651. if( m_unfinishedSections.empty() )
  5652. m_activeSections.back()->fail();
  5653. else
  5654. m_activeSections.back()->close();
  5655. m_activeSections.pop_back();
  5656. m_unfinishedSections.push_back( endInfo );
  5657. }
  5658. virtual void pushScopedMessage( MessageInfo const& message ) {
  5659. m_messages.push_back( message );
  5660. }
  5661. virtual void popScopedMessage( MessageInfo const& message ) {
  5662. m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
  5663. }
  5664. virtual std::string getCurrentTestName() const {
  5665. return m_activeTestCase
  5666. ? m_activeTestCase->getTestCaseInfo().name
  5667. : std::string();
  5668. }
  5669. virtual const AssertionResult* getLastResult() const {
  5670. return &m_lastResult;
  5671. }
  5672. virtual void exceptionEarlyReported() {
  5673. m_shouldReportUnexpected = false;
  5674. }
  5675. virtual void handleFatalErrorCondition( std::string const& message ) {
  5676. // Don't rebuild the result -- the stringification itself can cause more fatal errors
  5677. // Instead, fake a result data.
  5678. AssertionResultData tempResult;
  5679. tempResult.resultType = ResultWas::FatalErrorCondition;
  5680. tempResult.message = message;
  5681. AssertionResult result(m_lastAssertionInfo, tempResult);
  5682. getResultCapture().assertionEnded(result);
  5683. handleUnfinishedSections();
  5684. // Recreate section for test case (as we will lose the one that was in scope)
  5685. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5686. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5687. Counts assertions;
  5688. assertions.failed = 1;
  5689. SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
  5690. m_reporter->sectionEnded( testCaseSectionStats );
  5691. TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
  5692. Totals deltaTotals;
  5693. deltaTotals.testCases.failed = 1;
  5694. deltaTotals.assertions.failed = 1;
  5695. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5696. deltaTotals,
  5697. std::string(),
  5698. std::string(),
  5699. false ) );
  5700. m_totals.testCases.failed++;
  5701. testGroupEnded( std::string(), m_totals, 1, 1 );
  5702. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
  5703. }
  5704. public:
  5705. // !TBD We need to do this another way!
  5706. bool aborting() const {
  5707. return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
  5708. }
  5709. private:
  5710. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
  5711. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5712. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5713. m_reporter->sectionStarting( testCaseSection );
  5714. Counts prevAssertions = m_totals.assertions;
  5715. double duration = 0;
  5716. m_shouldReportUnexpected = true;
  5717. try {
  5718. m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
  5719. seedRng( *m_config );
  5720. Timer timer;
  5721. timer.start();
  5722. if( m_reporter->getPreferences().shouldRedirectStdOut ) {
  5723. StreamRedirect coutRedir( Catch::cout(), redirectedCout );
  5724. StdErrRedirect errRedir( redirectedCerr );
  5725. invokeActiveTestCase();
  5726. }
  5727. else {
  5728. invokeActiveTestCase();
  5729. }
  5730. duration = timer.getElapsedSeconds();
  5731. }
  5732. catch( TestFailureException& ) {
  5733. // This just means the test was aborted due to failure
  5734. }
  5735. catch(...) {
  5736. // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
  5737. // are reported without translation at the point of origin.
  5738. if (m_shouldReportUnexpected) {
  5739. makeUnexpectedResultBuilder().useActiveException();
  5740. }
  5741. }
  5742. m_testCaseTracker->close();
  5743. handleUnfinishedSections();
  5744. m_messages.clear();
  5745. Counts assertions = m_totals.assertions - prevAssertions;
  5746. bool missingAssertions = testForMissingAssertions( assertions );
  5747. SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
  5748. m_reporter->sectionEnded( testCaseSectionStats );
  5749. }
  5750. void invokeActiveTestCase() {
  5751. FatalConditionHandler fatalConditionHandler; // Handle signals
  5752. m_activeTestCase->invoke();
  5753. fatalConditionHandler.reset();
  5754. }
  5755. private:
  5756. ResultBuilder makeUnexpectedResultBuilder() const {
  5757. return ResultBuilder( m_lastAssertionInfo.macroName,
  5758. m_lastAssertionInfo.lineInfo,
  5759. m_lastAssertionInfo.capturedExpression,
  5760. m_lastAssertionInfo.resultDisposition );
  5761. }
  5762. void handleUnfinishedSections() {
  5763. // If sections ended prematurely due to an exception we stored their
  5764. // infos here so we can tear them down outside the unwind process.
  5765. for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
  5766. itEnd = m_unfinishedSections.rend();
  5767. it != itEnd;
  5768. ++it )
  5769. sectionEnded( *it );
  5770. m_unfinishedSections.clear();
  5771. }
  5772. TestRunInfo m_runInfo;
  5773. IMutableContext& m_context;
  5774. TestCase const* m_activeTestCase;
  5775. ITracker* m_testCaseTracker;
  5776. ITracker* m_currentSectionTracker;
  5777. AssertionResult m_lastResult;
  5778. Ptr<IConfig const> m_config;
  5779. Totals m_totals;
  5780. Ptr<IStreamingReporter> m_reporter;
  5781. std::vector<MessageInfo> m_messages;
  5782. AssertionInfo m_lastAssertionInfo;
  5783. std::vector<SectionEndInfo> m_unfinishedSections;
  5784. std::vector<ITracker*> m_activeSections;
  5785. TrackerContext m_trackerContext;
  5786. size_t m_prevPassed;
  5787. bool m_shouldReportUnexpected;
  5788. };
  5789. IResultCapture& getResultCapture() {
  5790. if( IResultCapture* capture = getCurrentContext().getResultCapture() )
  5791. return *capture;
  5792. else
  5793. throw std::logic_error( "No result capture instance" );
  5794. }
  5795. } // end namespace Catch
  5796. // #included from: internal/catch_version.h
  5797. #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
  5798. namespace Catch {
  5799. // Versioning information
  5800. struct Version {
  5801. Version( unsigned int _majorVersion,
  5802. unsigned int _minorVersion,
  5803. unsigned int _patchNumber,
  5804. char const * const _branchName,
  5805. unsigned int _buildNumber );
  5806. unsigned int const majorVersion;
  5807. unsigned int const minorVersion;
  5808. unsigned int const patchNumber;
  5809. // buildNumber is only used if branchName is not null
  5810. char const * const branchName;
  5811. unsigned int const buildNumber;
  5812. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5813. private:
  5814. void operator=( Version const& );
  5815. };
  5816. inline Version libraryVersion();
  5817. }
  5818. #include <fstream>
  5819. #include <stdlib.h>
  5820. #include <limits>
  5821. namespace Catch {
  5822. Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
  5823. Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
  5824. if( !reporter ) {
  5825. std::ostringstream oss;
  5826. oss << "No reporter registered with name: '" << reporterName << "'";
  5827. throw std::domain_error( oss.str() );
  5828. }
  5829. return reporter;
  5830. }
  5831. #if !defined(CATCH_CONFIG_DEFAULT_REPORTER)
  5832. #define CATCH_CONFIG_DEFAULT_REPORTER "console"
  5833. #endif
  5834. Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
  5835. std::vector<std::string> reporters = config->getReporterNames();
  5836. if( reporters.empty() )
  5837. reporters.push_back( CATCH_CONFIG_DEFAULT_REPORTER );
  5838. Ptr<IStreamingReporter> reporter;
  5839. for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
  5840. it != itEnd;
  5841. ++it )
  5842. reporter = addReporter( reporter, createReporter( *it, config ) );
  5843. return reporter;
  5844. }
  5845. Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
  5846. IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
  5847. for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
  5848. it != itEnd;
  5849. ++it )
  5850. reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
  5851. return reporters;
  5852. }
  5853. Totals runTests( Ptr<Config> const& config ) {
  5854. Ptr<IConfig const> iconfig = config.get();
  5855. Ptr<IStreamingReporter> reporter = makeReporter( config );
  5856. reporter = addListeners( iconfig, reporter );
  5857. RunContext context( iconfig, reporter );
  5858. Totals totals;
  5859. context.testGroupStarting( config->name(), 1, 1 );
  5860. TestSpec testSpec = config->testSpec();
  5861. if( !testSpec.hasFilters() )
  5862. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
  5863. std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
  5864. for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
  5865. it != itEnd;
  5866. ++it ) {
  5867. if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
  5868. totals += context.runTest( *it );
  5869. else
  5870. reporter->skipTest( *it );
  5871. }
  5872. context.testGroupEnded( iconfig->name(), totals, 1, 1 );
  5873. return totals;
  5874. }
  5875. void applyFilenamesAsTags( IConfig const& config ) {
  5876. std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
  5877. for(std::size_t i = 0; i < tests.size(); ++i ) {
  5878. TestCase& test = const_cast<TestCase&>( tests[i] );
  5879. std::set<std::string> tags = test.tags;
  5880. std::string filename = test.lineInfo.file;
  5881. std::string::size_type lastSlash = filename.find_last_of( "\\/" );
  5882. if( lastSlash != std::string::npos )
  5883. filename = filename.substr( lastSlash+1 );
  5884. std::string::size_type lastDot = filename.find_last_of( '.' );
  5885. if( lastDot != std::string::npos )
  5886. filename = filename.substr( 0, lastDot );
  5887. tags.insert( '#' + filename );
  5888. setTags( test, tags );
  5889. }
  5890. }
  5891. class Session : NonCopyable {
  5892. static bool alreadyInstantiated;
  5893. public:
  5894. struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
  5895. Session()
  5896. : m_cli( makeCommandLineParser() ) {
  5897. if( alreadyInstantiated ) {
  5898. std::string msg = "Only one instance of Catch::Session can ever be used";
  5899. Catch::cerr() << msg << std::endl;
  5900. throw std::logic_error( msg );
  5901. }
  5902. alreadyInstantiated = true;
  5903. }
  5904. ~Session() {
  5905. Catch::cleanUp();
  5906. }
  5907. void showHelp( std::string const& processName ) {
  5908. Catch::cout() << "\nCatch v" << libraryVersion() << "\n";
  5909. m_cli.usage( Catch::cout(), processName );
  5910. Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
  5911. }
  5912. void libIdentify() {
  5913. Catch::cout()
  5914. << std::left << std::setw(16) << "description: " << "A Catch test executable\n"
  5915. << std::left << std::setw(16) << "category: " << "testframework\n"
  5916. << std::left << std::setw(16) << "framework: " << "Catch Test\n"
  5917. << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
  5918. }
  5919. int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
  5920. try {
  5921. m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
  5922. m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
  5923. if( m_configData.showHelp )
  5924. showHelp( m_configData.processName );
  5925. if( m_configData.libIdentify )
  5926. libIdentify();
  5927. m_config.reset();
  5928. }
  5929. catch( std::exception& ex ) {
  5930. {
  5931. Colour colourGuard( Colour::Red );
  5932. Catch::cerr()
  5933. << "\nError(s) in input:\n"
  5934. << Text( ex.what(), TextAttributes().setIndent(2) )
  5935. << "\n\n";
  5936. }
  5937. m_cli.usage( Catch::cout(), m_configData.processName );
  5938. return (std::numeric_limits<int>::max)();
  5939. }
  5940. return 0;
  5941. }
  5942. void useConfigData( ConfigData const& _configData ) {
  5943. m_configData = _configData;
  5944. m_config.reset();
  5945. }
  5946. int run( int argc, char const* const* const argv ) {
  5947. int returnCode = applyCommandLine( argc, argv );
  5948. if( returnCode == 0 )
  5949. returnCode = run();
  5950. return returnCode;
  5951. }
  5952. #if defined(WIN32) && defined(UNICODE)
  5953. int run( int argc, wchar_t const* const* const argv ) {
  5954. char **utf8Argv = new char *[ argc ];
  5955. for ( int i = 0; i < argc; ++i ) {
  5956. int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL );
  5957. utf8Argv[ i ] = new char[ bufSize ];
  5958. WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
  5959. }
  5960. int returnCode = applyCommandLine( argc, utf8Argv );
  5961. if( returnCode == 0 )
  5962. returnCode = run();
  5963. for ( int i = 0; i < argc; ++i )
  5964. delete [] utf8Argv[ i ];
  5965. delete [] utf8Argv;
  5966. return returnCode;
  5967. }
  5968. #endif
  5969. int run() {
  5970. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
  5971. Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
  5972. static_cast<void>(std::getchar());
  5973. }
  5974. int exitCode = runInternal();
  5975. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
  5976. Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
  5977. static_cast<void>(std::getchar());
  5978. }
  5979. return exitCode;
  5980. }
  5981. Clara::CommandLine<ConfigData> const& cli() const {
  5982. return m_cli;
  5983. }
  5984. std::vector<Clara::Parser::Token> const& unusedTokens() const {
  5985. return m_unusedTokens;
  5986. }
  5987. ConfigData& configData() {
  5988. return m_configData;
  5989. }
  5990. Config& config() {
  5991. if( !m_config )
  5992. m_config = new Config( m_configData );
  5993. return *m_config;
  5994. }
  5995. private:
  5996. int runInternal() {
  5997. if( m_configData.showHelp || m_configData.libIdentify )
  5998. return 0;
  5999. try
  6000. {
  6001. config(); // Force config to be constructed
  6002. seedRng( *m_config );
  6003. if( m_configData.filenamesAsTags )
  6004. applyFilenamesAsTags( *m_config );
  6005. // Handle list request
  6006. if( Option<std::size_t> listed = list( config() ) )
  6007. return static_cast<int>( *listed );
  6008. return static_cast<int>( runTests( m_config ).assertions.failed );
  6009. }
  6010. catch( std::exception& ex ) {
  6011. Catch::cerr() << ex.what() << std::endl;
  6012. return (std::numeric_limits<int>::max)();
  6013. }
  6014. }
  6015. Clara::CommandLine<ConfigData> m_cli;
  6016. std::vector<Clara::Parser::Token> m_unusedTokens;
  6017. ConfigData m_configData;
  6018. Ptr<Config> m_config;
  6019. };
  6020. bool Session::alreadyInstantiated = false;
  6021. } // end namespace Catch
  6022. // #included from: catch_registry_hub.hpp
  6023. #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
  6024. // #included from: catch_test_case_registry_impl.hpp
  6025. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  6026. #include <vector>
  6027. #include <set>
  6028. #include <sstream>
  6029. #include <algorithm>
  6030. namespace Catch {
  6031. struct RandomNumberGenerator {
  6032. typedef unsigned int result_type;
  6033. result_type operator()( result_type n ) const { return std::rand() % n; }
  6034. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6035. static constexpr result_type (min)() { return 0; }
  6036. static constexpr result_type (max)() { return 1000000; }
  6037. result_type operator()() const { return std::rand() % (max)(); }
  6038. #endif
  6039. template<typename V>
  6040. static void shuffle( V& vector ) {
  6041. RandomNumberGenerator rng;
  6042. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6043. std::shuffle( vector.begin(), vector.end(), rng );
  6044. #else
  6045. std::random_shuffle( vector.begin(), vector.end(), rng );
  6046. #endif
  6047. }
  6048. };
  6049. inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
  6050. std::vector<TestCase> sorted = unsortedTestCases;
  6051. switch( config.runOrder() ) {
  6052. case RunTests::InLexicographicalOrder:
  6053. std::sort( sorted.begin(), sorted.end() );
  6054. break;
  6055. case RunTests::InRandomOrder:
  6056. {
  6057. seedRng( config );
  6058. RandomNumberGenerator::shuffle( sorted );
  6059. }
  6060. break;
  6061. case RunTests::InDeclarationOrder:
  6062. // already in declaration order
  6063. break;
  6064. }
  6065. return sorted;
  6066. }
  6067. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
  6068. return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
  6069. }
  6070. void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
  6071. std::set<TestCase> seenFunctions;
  6072. for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
  6073. it != itEnd;
  6074. ++it ) {
  6075. std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
  6076. if( !prev.second ) {
  6077. std::ostringstream ss;
  6078. ss << Colour( Colour::Red )
  6079. << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
  6080. << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n'
  6081. << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
  6082. throw std::runtime_error(ss.str());
  6083. }
  6084. }
  6085. }
  6086. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
  6087. std::vector<TestCase> filtered;
  6088. filtered.reserve( testCases.size() );
  6089. for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
  6090. it != itEnd;
  6091. ++it )
  6092. if( matchTest( *it, testSpec, config ) )
  6093. filtered.push_back( *it );
  6094. return filtered;
  6095. }
  6096. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
  6097. return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
  6098. }
  6099. class TestRegistry : public ITestCaseRegistry {
  6100. public:
  6101. TestRegistry()
  6102. : m_currentSortOrder( RunTests::InDeclarationOrder ),
  6103. m_unnamedCount( 0 )
  6104. {}
  6105. virtual ~TestRegistry();
  6106. virtual void registerTest( TestCase const& testCase ) {
  6107. std::string name = testCase.getTestCaseInfo().name;
  6108. if( name.empty() ) {
  6109. std::ostringstream oss;
  6110. oss << "Anonymous test case " << ++m_unnamedCount;
  6111. return registerTest( testCase.withName( oss.str() ) );
  6112. }
  6113. m_functions.push_back( testCase );
  6114. }
  6115. virtual std::vector<TestCase> const& getAllTests() const {
  6116. return m_functions;
  6117. }
  6118. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
  6119. if( m_sortedFunctions.empty() )
  6120. enforceNoDuplicateTestCases( m_functions );
  6121. if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
  6122. m_sortedFunctions = sortTests( config, m_functions );
  6123. m_currentSortOrder = config.runOrder();
  6124. }
  6125. return m_sortedFunctions;
  6126. }
  6127. private:
  6128. std::vector<TestCase> m_functions;
  6129. mutable RunTests::InWhatOrder m_currentSortOrder;
  6130. mutable std::vector<TestCase> m_sortedFunctions;
  6131. size_t m_unnamedCount;
  6132. std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
  6133. };
  6134. ///////////////////////////////////////////////////////////////////////////
  6135. class FreeFunctionTestCase : public SharedImpl<ITestCase> {
  6136. public:
  6137. FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
  6138. virtual void invoke() const {
  6139. m_fun();
  6140. }
  6141. private:
  6142. virtual ~FreeFunctionTestCase();
  6143. TestFunction m_fun;
  6144. };
  6145. inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
  6146. std::string className = classOrQualifiedMethodName;
  6147. if( startsWith( className, '&' ) )
  6148. {
  6149. std::size_t lastColons = className.rfind( "::" );
  6150. std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
  6151. if( penultimateColons == std::string::npos )
  6152. penultimateColons = 1;
  6153. className = className.substr( penultimateColons, lastColons-penultimateColons );
  6154. }
  6155. return className;
  6156. }
  6157. void registerTestCase
  6158. ( ITestCase* testCase,
  6159. char const* classOrQualifiedMethodName,
  6160. NameAndDesc const& nameAndDesc,
  6161. SourceLineInfo const& lineInfo ) {
  6162. getMutableRegistryHub().registerTest
  6163. ( makeTestCase
  6164. ( testCase,
  6165. extractClassName( classOrQualifiedMethodName ),
  6166. nameAndDesc.name,
  6167. nameAndDesc.description,
  6168. lineInfo ) );
  6169. }
  6170. void registerTestCaseFunction
  6171. ( TestFunction function,
  6172. SourceLineInfo const& lineInfo,
  6173. NameAndDesc const& nameAndDesc ) {
  6174. registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
  6175. }
  6176. ///////////////////////////////////////////////////////////////////////////
  6177. AutoReg::AutoReg
  6178. ( TestFunction function,
  6179. SourceLineInfo const& lineInfo,
  6180. NameAndDesc const& nameAndDesc ) {
  6181. registerTestCaseFunction( function, lineInfo, nameAndDesc );
  6182. }
  6183. AutoReg::~AutoReg() {}
  6184. } // end namespace Catch
  6185. // #included from: catch_reporter_registry.hpp
  6186. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6187. #include <map>
  6188. namespace Catch {
  6189. class ReporterRegistry : public IReporterRegistry {
  6190. public:
  6191. virtual ~ReporterRegistry() CATCH_OVERRIDE {}
  6192. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
  6193. FactoryMap::const_iterator it = m_factories.find( name );
  6194. if( it == m_factories.end() )
  6195. return CATCH_NULL;
  6196. return it->second->create( ReporterConfig( config ) );
  6197. }
  6198. void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
  6199. m_factories.insert( std::make_pair( name, factory ) );
  6200. }
  6201. void registerListener( Ptr<IReporterFactory> const& factory ) {
  6202. m_listeners.push_back( factory );
  6203. }
  6204. virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
  6205. return m_factories;
  6206. }
  6207. virtual Listeners const& getListeners() const CATCH_OVERRIDE {
  6208. return m_listeners;
  6209. }
  6210. private:
  6211. FactoryMap m_factories;
  6212. Listeners m_listeners;
  6213. };
  6214. }
  6215. // #included from: catch_exception_translator_registry.hpp
  6216. #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6217. #ifdef __OBJC__
  6218. #import "Foundation/Foundation.h"
  6219. #endif
  6220. namespace Catch {
  6221. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  6222. public:
  6223. ~ExceptionTranslatorRegistry() {
  6224. deleteAll( m_translators );
  6225. }
  6226. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  6227. m_translators.push_back( translator );
  6228. }
  6229. virtual std::string translateActiveException() const {
  6230. try {
  6231. #ifdef __OBJC__
  6232. // In Objective-C try objective-c exceptions first
  6233. @try {
  6234. return tryTranslators();
  6235. }
  6236. @catch (NSException *exception) {
  6237. return Catch::toString( [exception description] );
  6238. }
  6239. #else
  6240. return tryTranslators();
  6241. #endif
  6242. }
  6243. catch( TestFailureException& ) {
  6244. throw;
  6245. }
  6246. catch( std::exception& ex ) {
  6247. return ex.what();
  6248. }
  6249. catch( std::string& msg ) {
  6250. return msg;
  6251. }
  6252. catch( const char* msg ) {
  6253. return msg;
  6254. }
  6255. catch(...) {
  6256. return "Unknown exception";
  6257. }
  6258. }
  6259. std::string tryTranslators() const {
  6260. if( m_translators.empty() )
  6261. throw;
  6262. else
  6263. return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
  6264. }
  6265. private:
  6266. std::vector<const IExceptionTranslator*> m_translators;
  6267. };
  6268. }
  6269. // #included from: catch_tag_alias_registry.h
  6270. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
  6271. #include <map>
  6272. namespace Catch {
  6273. class TagAliasRegistry : public ITagAliasRegistry {
  6274. public:
  6275. virtual ~TagAliasRegistry();
  6276. virtual Option<TagAlias> find( std::string const& alias ) const;
  6277. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
  6278. void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
  6279. private:
  6280. std::map<std::string, TagAlias> m_registry;
  6281. };
  6282. } // end namespace Catch
  6283. namespace Catch {
  6284. namespace {
  6285. class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
  6286. RegistryHub( RegistryHub const& );
  6287. void operator=( RegistryHub const& );
  6288. public: // IRegistryHub
  6289. RegistryHub() {
  6290. }
  6291. virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
  6292. return m_reporterRegistry;
  6293. }
  6294. virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
  6295. return m_testCaseRegistry;
  6296. }
  6297. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
  6298. return m_exceptionTranslatorRegistry;
  6299. }
  6300. virtual ITagAliasRegistry const& getTagAliasRegistry() const CATCH_OVERRIDE {
  6301. return m_tagAliasRegistry;
  6302. }
  6303. public: // IMutableRegistryHub
  6304. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6305. m_reporterRegistry.registerReporter( name, factory );
  6306. }
  6307. virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6308. m_reporterRegistry.registerListener( factory );
  6309. }
  6310. virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
  6311. m_testCaseRegistry.registerTest( testInfo );
  6312. }
  6313. virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
  6314. m_exceptionTranslatorRegistry.registerTranslator( translator );
  6315. }
  6316. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) CATCH_OVERRIDE {
  6317. m_tagAliasRegistry.add( alias, tag, lineInfo );
  6318. }
  6319. private:
  6320. TestRegistry m_testCaseRegistry;
  6321. ReporterRegistry m_reporterRegistry;
  6322. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  6323. TagAliasRegistry m_tagAliasRegistry;
  6324. };
  6325. // Single, global, instance
  6326. inline RegistryHub*& getTheRegistryHub() {
  6327. static RegistryHub* theRegistryHub = CATCH_NULL;
  6328. if( !theRegistryHub )
  6329. theRegistryHub = new RegistryHub();
  6330. return theRegistryHub;
  6331. }
  6332. }
  6333. IRegistryHub& getRegistryHub() {
  6334. return *getTheRegistryHub();
  6335. }
  6336. IMutableRegistryHub& getMutableRegistryHub() {
  6337. return *getTheRegistryHub();
  6338. }
  6339. void cleanUp() {
  6340. delete getTheRegistryHub();
  6341. getTheRegistryHub() = CATCH_NULL;
  6342. cleanUpContext();
  6343. }
  6344. std::string translateActiveException() {
  6345. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  6346. }
  6347. } // end namespace Catch
  6348. // #included from: catch_notimplemented_exception.hpp
  6349. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
  6350. #include <sstream>
  6351. namespace Catch {
  6352. NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
  6353. : m_lineInfo( lineInfo ) {
  6354. std::ostringstream oss;
  6355. oss << lineInfo << ": function ";
  6356. oss << "not implemented";
  6357. m_what = oss.str();
  6358. }
  6359. const char* NotImplementedException::what() const CATCH_NOEXCEPT {
  6360. return m_what.c_str();
  6361. }
  6362. } // end namespace Catch
  6363. // #included from: catch_context_impl.hpp
  6364. #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
  6365. // #included from: catch_stream.hpp
  6366. #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
  6367. #include <stdexcept>
  6368. #include <cstdio>
  6369. #include <iostream>
  6370. namespace Catch {
  6371. template<typename WriterF, size_t bufferSize=256>
  6372. class StreamBufImpl : public StreamBufBase {
  6373. char data[bufferSize];
  6374. WriterF m_writer;
  6375. public:
  6376. StreamBufImpl() {
  6377. setp( data, data + sizeof(data) );
  6378. }
  6379. ~StreamBufImpl() CATCH_NOEXCEPT {
  6380. sync();
  6381. }
  6382. private:
  6383. int overflow( int c ) {
  6384. sync();
  6385. if( c != EOF ) {
  6386. if( pbase() == epptr() )
  6387. m_writer( std::string( 1, static_cast<char>( c ) ) );
  6388. else
  6389. sputc( static_cast<char>( c ) );
  6390. }
  6391. return 0;
  6392. }
  6393. int sync() {
  6394. if( pbase() != pptr() ) {
  6395. m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
  6396. setp( pbase(), epptr() );
  6397. }
  6398. return 0;
  6399. }
  6400. };
  6401. ///////////////////////////////////////////////////////////////////////////
  6402. FileStream::FileStream( std::string const& filename ) {
  6403. m_ofs.open( filename.c_str() );
  6404. if( m_ofs.fail() ) {
  6405. std::ostringstream oss;
  6406. oss << "Unable to open file: '" << filename << '\'';
  6407. throw std::domain_error( oss.str() );
  6408. }
  6409. }
  6410. std::ostream& FileStream::stream() const {
  6411. return m_ofs;
  6412. }
  6413. struct OutputDebugWriter {
  6414. void operator()( std::string const&str ) {
  6415. writeToDebugConsole( str );
  6416. }
  6417. };
  6418. DebugOutStream::DebugOutStream()
  6419. : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
  6420. m_os( m_streamBuf.get() )
  6421. {}
  6422. std::ostream& DebugOutStream::stream() const {
  6423. return m_os;
  6424. }
  6425. // Store the streambuf from cout up-front because
  6426. // cout may get redirected when running tests
  6427. CoutStream::CoutStream()
  6428. : m_os( Catch::cout().rdbuf() )
  6429. {}
  6430. std::ostream& CoutStream::stream() const {
  6431. return m_os;
  6432. }
  6433. #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
  6434. std::ostream& cout() {
  6435. return std::cout;
  6436. }
  6437. std::ostream& cerr() {
  6438. return std::cerr;
  6439. }
  6440. std::ostream& clog() {
  6441. return std::clog;
  6442. }
  6443. #endif
  6444. }
  6445. namespace Catch {
  6446. class Context : public IMutableContext {
  6447. Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
  6448. Context( Context const& );
  6449. void operator=( Context const& );
  6450. public:
  6451. virtual ~Context() {
  6452. deleteAllValues( m_generatorsByTestName );
  6453. }
  6454. public: // IContext
  6455. virtual IResultCapture* getResultCapture() {
  6456. return m_resultCapture;
  6457. }
  6458. virtual IRunner* getRunner() {
  6459. return m_runner;
  6460. }
  6461. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
  6462. return getGeneratorsForCurrentTest()
  6463. .getGeneratorInfo( fileInfo, totalSize )
  6464. .getCurrentIndex();
  6465. }
  6466. virtual bool advanceGeneratorsForCurrentTest() {
  6467. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6468. return generators && generators->moveNext();
  6469. }
  6470. virtual Ptr<IConfig const> getConfig() const {
  6471. return m_config;
  6472. }
  6473. public: // IMutableContext
  6474. virtual void setResultCapture( IResultCapture* resultCapture ) {
  6475. m_resultCapture = resultCapture;
  6476. }
  6477. virtual void setRunner( IRunner* runner ) {
  6478. m_runner = runner;
  6479. }
  6480. virtual void setConfig( Ptr<IConfig const> const& config ) {
  6481. m_config = config;
  6482. }
  6483. friend IMutableContext& getCurrentMutableContext();
  6484. private:
  6485. IGeneratorsForTest* findGeneratorsForCurrentTest() {
  6486. std::string testName = getResultCapture()->getCurrentTestName();
  6487. std::map<std::string, IGeneratorsForTest*>::const_iterator it =
  6488. m_generatorsByTestName.find( testName );
  6489. return it != m_generatorsByTestName.end()
  6490. ? it->second
  6491. : CATCH_NULL;
  6492. }
  6493. IGeneratorsForTest& getGeneratorsForCurrentTest() {
  6494. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6495. if( !generators ) {
  6496. std::string testName = getResultCapture()->getCurrentTestName();
  6497. generators = createGeneratorsForTest();
  6498. m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
  6499. }
  6500. return *generators;
  6501. }
  6502. private:
  6503. Ptr<IConfig const> m_config;
  6504. IRunner* m_runner;
  6505. IResultCapture* m_resultCapture;
  6506. std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
  6507. };
  6508. namespace {
  6509. Context* currentContext = CATCH_NULL;
  6510. }
  6511. IMutableContext& getCurrentMutableContext() {
  6512. if( !currentContext )
  6513. currentContext = new Context();
  6514. return *currentContext;
  6515. }
  6516. IContext& getCurrentContext() {
  6517. return getCurrentMutableContext();
  6518. }
  6519. void cleanUpContext() {
  6520. delete currentContext;
  6521. currentContext = CATCH_NULL;
  6522. }
  6523. }
  6524. // #included from: catch_console_colour_impl.hpp
  6525. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
  6526. // #included from: catch_errno_guard.hpp
  6527. #define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
  6528. #include <cerrno>
  6529. namespace Catch {
  6530. class ErrnoGuard {
  6531. public:
  6532. ErrnoGuard():m_oldErrno(errno){}
  6533. ~ErrnoGuard() { errno = m_oldErrno; }
  6534. private:
  6535. int m_oldErrno;
  6536. };
  6537. }
  6538. namespace Catch {
  6539. namespace {
  6540. struct IColourImpl {
  6541. virtual ~IColourImpl() {}
  6542. virtual void use( Colour::Code _colourCode ) = 0;
  6543. };
  6544. struct NoColourImpl : IColourImpl {
  6545. void use( Colour::Code ) {}
  6546. static IColourImpl* instance() {
  6547. static NoColourImpl s_instance;
  6548. return &s_instance;
  6549. }
  6550. };
  6551. } // anon namespace
  6552. } // namespace Catch
  6553. #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
  6554. # ifdef CATCH_PLATFORM_WINDOWS
  6555. # define CATCH_CONFIG_COLOUR_WINDOWS
  6556. # else
  6557. # define CATCH_CONFIG_COLOUR_ANSI
  6558. # endif
  6559. #endif
  6560. #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
  6561. namespace Catch {
  6562. namespace {
  6563. class Win32ColourImpl : public IColourImpl {
  6564. public:
  6565. Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
  6566. {
  6567. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  6568. GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
  6569. originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
  6570. originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
  6571. }
  6572. virtual void use( Colour::Code _colourCode ) {
  6573. switch( _colourCode ) {
  6574. case Colour::None: return setTextAttribute( originalForegroundAttributes );
  6575. case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6576. case Colour::Red: return setTextAttribute( FOREGROUND_RED );
  6577. case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
  6578. case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
  6579. case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
  6580. case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
  6581. case Colour::Grey: return setTextAttribute( 0 );
  6582. case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
  6583. case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
  6584. case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
  6585. case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6586. case Colour::Bright: throw std::logic_error( "not a colour" );
  6587. }
  6588. }
  6589. private:
  6590. void setTextAttribute( WORD _textAttribute ) {
  6591. SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
  6592. }
  6593. HANDLE stdoutHandle;
  6594. WORD originalForegroundAttributes;
  6595. WORD originalBackgroundAttributes;
  6596. };
  6597. IColourImpl* platformColourInstance() {
  6598. static Win32ColourImpl s_instance;
  6599. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6600. UseColour::YesOrNo colourMode = config
  6601. ? config->useColour()
  6602. : UseColour::Auto;
  6603. if( colourMode == UseColour::Auto )
  6604. colourMode = !isDebuggerActive()
  6605. ? UseColour::Yes
  6606. : UseColour::No;
  6607. return colourMode == UseColour::Yes
  6608. ? &s_instance
  6609. : NoColourImpl::instance();
  6610. }
  6611. } // end anon namespace
  6612. } // end namespace Catch
  6613. #elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
  6614. #include <unistd.h>
  6615. namespace Catch {
  6616. namespace {
  6617. // use POSIX/ ANSI console terminal codes
  6618. // Thanks to Adam Strzelecki for original contribution
  6619. // (http://github.com/nanoant)
  6620. // https://github.com/philsquared/Catch/pull/131
  6621. class PosixColourImpl : public IColourImpl {
  6622. public:
  6623. virtual void use( Colour::Code _colourCode ) {
  6624. switch( _colourCode ) {
  6625. case Colour::None:
  6626. case Colour::White: return setColour( "[0m" );
  6627. case Colour::Red: return setColour( "[0;31m" );
  6628. case Colour::Green: return setColour( "[0;32m" );
  6629. case Colour::Blue: return setColour( "[0;34m" );
  6630. case Colour::Cyan: return setColour( "[0;36m" );
  6631. case Colour::Yellow: return setColour( "[0;33m" );
  6632. case Colour::Grey: return setColour( "[1;30m" );
  6633. case Colour::LightGrey: return setColour( "[0;37m" );
  6634. case Colour::BrightRed: return setColour( "[1;31m" );
  6635. case Colour::BrightGreen: return setColour( "[1;32m" );
  6636. case Colour::BrightWhite: return setColour( "[1;37m" );
  6637. case Colour::Bright: throw std::logic_error( "not a colour" );
  6638. }
  6639. }
  6640. static IColourImpl* instance() {
  6641. static PosixColourImpl s_instance;
  6642. return &s_instance;
  6643. }
  6644. private:
  6645. void setColour( const char* _escapeCode ) {
  6646. Catch::cout() << '\033' << _escapeCode;
  6647. }
  6648. };
  6649. IColourImpl* platformColourInstance() {
  6650. ErrnoGuard guard;
  6651. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6652. UseColour::YesOrNo colourMode = config
  6653. ? config->useColour()
  6654. : UseColour::Auto;
  6655. if( colourMode == UseColour::Auto )
  6656. colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
  6657. ? UseColour::Yes
  6658. : UseColour::No;
  6659. return colourMode == UseColour::Yes
  6660. ? PosixColourImpl::instance()
  6661. : NoColourImpl::instance();
  6662. }
  6663. } // end anon namespace
  6664. } // end namespace Catch
  6665. #else // not Windows or ANSI ///////////////////////////////////////////////
  6666. namespace Catch {
  6667. static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
  6668. } // end namespace Catch
  6669. #endif // Windows/ ANSI/ None
  6670. namespace Catch {
  6671. Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
  6672. Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
  6673. Colour::~Colour(){ if( !m_moved ) use( None ); }
  6674. void Colour::use( Code _colourCode ) {
  6675. static IColourImpl* impl = platformColourInstance();
  6676. impl->use( _colourCode );
  6677. }
  6678. } // end namespace Catch
  6679. // #included from: catch_generators_impl.hpp
  6680. #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
  6681. #include <vector>
  6682. #include <string>
  6683. #include <map>
  6684. namespace Catch {
  6685. struct GeneratorInfo : IGeneratorInfo {
  6686. GeneratorInfo( std::size_t size )
  6687. : m_size( size ),
  6688. m_currentIndex( 0 )
  6689. {}
  6690. bool moveNext() {
  6691. if( ++m_currentIndex == m_size ) {
  6692. m_currentIndex = 0;
  6693. return false;
  6694. }
  6695. return true;
  6696. }
  6697. std::size_t getCurrentIndex() const {
  6698. return m_currentIndex;
  6699. }
  6700. std::size_t m_size;
  6701. std::size_t m_currentIndex;
  6702. };
  6703. ///////////////////////////////////////////////////////////////////////////
  6704. class GeneratorsForTest : public IGeneratorsForTest {
  6705. public:
  6706. ~GeneratorsForTest() {
  6707. deleteAll( m_generatorsInOrder );
  6708. }
  6709. IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
  6710. std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
  6711. if( it == m_generatorsByName.end() ) {
  6712. IGeneratorInfo* info = new GeneratorInfo( size );
  6713. m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
  6714. m_generatorsInOrder.push_back( info );
  6715. return *info;
  6716. }
  6717. return *it->second;
  6718. }
  6719. bool moveNext() {
  6720. std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
  6721. std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
  6722. for(; it != itEnd; ++it ) {
  6723. if( (*it)->moveNext() )
  6724. return true;
  6725. }
  6726. return false;
  6727. }
  6728. private:
  6729. std::map<std::string, IGeneratorInfo*> m_generatorsByName;
  6730. std::vector<IGeneratorInfo*> m_generatorsInOrder;
  6731. };
  6732. IGeneratorsForTest* createGeneratorsForTest()
  6733. {
  6734. return new GeneratorsForTest();
  6735. }
  6736. } // end namespace Catch
  6737. // #included from: catch_assertionresult.hpp
  6738. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
  6739. namespace Catch {
  6740. AssertionInfo::AssertionInfo():macroName(""), capturedExpression(""), resultDisposition(ResultDisposition::Normal), secondArg(""){}
  6741. AssertionInfo::AssertionInfo( char const * _macroName,
  6742. SourceLineInfo const& _lineInfo,
  6743. char const * _capturedExpression,
  6744. ResultDisposition::Flags _resultDisposition,
  6745. char const * _secondArg)
  6746. : macroName( _macroName ),
  6747. lineInfo( _lineInfo ),
  6748. capturedExpression( _capturedExpression ),
  6749. resultDisposition( _resultDisposition ),
  6750. secondArg( _secondArg )
  6751. {}
  6752. AssertionResult::AssertionResult() {}
  6753. AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
  6754. : m_info( info ),
  6755. m_resultData( data )
  6756. {}
  6757. AssertionResult::~AssertionResult() {}
  6758. // Result was a success
  6759. bool AssertionResult::succeeded() const {
  6760. return Catch::isOk( m_resultData.resultType );
  6761. }
  6762. // Result was a success, or failure is suppressed
  6763. bool AssertionResult::isOk() const {
  6764. return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
  6765. }
  6766. ResultWas::OfType AssertionResult::getResultType() const {
  6767. return m_resultData.resultType;
  6768. }
  6769. bool AssertionResult::hasExpression() const {
  6770. return m_info.capturedExpression[0] != 0;
  6771. }
  6772. bool AssertionResult::hasMessage() const {
  6773. return !m_resultData.message.empty();
  6774. }
  6775. std::string capturedExpressionWithSecondArgument( char const * capturedExpression, char const * secondArg ) {
  6776. return (secondArg[0] == 0 || secondArg[0] == '"' && secondArg[1] == '"')
  6777. ? capturedExpression
  6778. : std::string(capturedExpression) + ", " + secondArg;
  6779. }
  6780. std::string AssertionResult::getExpression() const {
  6781. if( isFalseTest( m_info.resultDisposition ) )
  6782. return "!(" + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + ")";
  6783. else
  6784. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6785. }
  6786. std::string AssertionResult::getExpressionInMacro() const {
  6787. if( m_info.macroName[0] == 0 )
  6788. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6789. else
  6790. return std::string(m_info.macroName) + "( " + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + " )";
  6791. }
  6792. bool AssertionResult::hasExpandedExpression() const {
  6793. return hasExpression() && getExpandedExpression() != getExpression();
  6794. }
  6795. std::string AssertionResult::getExpandedExpression() const {
  6796. return m_resultData.reconstructExpression();
  6797. }
  6798. std::string AssertionResult::getMessage() const {
  6799. return m_resultData.message;
  6800. }
  6801. SourceLineInfo AssertionResult::getSourceInfo() const {
  6802. return m_info.lineInfo;
  6803. }
  6804. std::string AssertionResult::getTestMacroName() const {
  6805. return m_info.macroName;
  6806. }
  6807. void AssertionResult::discardDecomposedExpression() const {
  6808. m_resultData.decomposedExpression = CATCH_NULL;
  6809. }
  6810. void AssertionResult::expandDecomposedExpression() const {
  6811. m_resultData.reconstructExpression();
  6812. }
  6813. } // end namespace Catch
  6814. // #included from: catch_test_case_info.hpp
  6815. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
  6816. #include <cctype>
  6817. namespace Catch {
  6818. inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
  6819. if( startsWith( tag, '.' ) ||
  6820. tag == "hide" ||
  6821. tag == "!hide" )
  6822. return TestCaseInfo::IsHidden;
  6823. else if( tag == "!throws" )
  6824. return TestCaseInfo::Throws;
  6825. else if( tag == "!shouldfail" )
  6826. return TestCaseInfo::ShouldFail;
  6827. else if( tag == "!mayfail" )
  6828. return TestCaseInfo::MayFail;
  6829. else if( tag == "!nonportable" )
  6830. return TestCaseInfo::NonPortable;
  6831. else
  6832. return TestCaseInfo::None;
  6833. }
  6834. inline bool isReservedTag( std::string const& tag ) {
  6835. return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] );
  6836. }
  6837. inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
  6838. if( isReservedTag( tag ) ) {
  6839. std::ostringstream ss;
  6840. ss << Colour(Colour::Red)
  6841. << "Tag name [" << tag << "] not allowed.\n"
  6842. << "Tag names starting with non alpha-numeric characters are reserved\n"
  6843. << Colour(Colour::FileName)
  6844. << _lineInfo << '\n';
  6845. throw std::runtime_error(ss.str());
  6846. }
  6847. }
  6848. TestCase makeTestCase( ITestCase* _testCase,
  6849. std::string const& _className,
  6850. std::string const& _name,
  6851. std::string const& _descOrTags,
  6852. SourceLineInfo const& _lineInfo )
  6853. {
  6854. bool isHidden( startsWith( _name, "./" ) ); // Legacy support
  6855. // Parse out tags
  6856. std::set<std::string> tags;
  6857. std::string desc, tag;
  6858. bool inTag = false;
  6859. for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
  6860. char c = _descOrTags[i];
  6861. if( !inTag ) {
  6862. if( c == '[' )
  6863. inTag = true;
  6864. else
  6865. desc += c;
  6866. }
  6867. else {
  6868. if( c == ']' ) {
  6869. TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
  6870. if( prop == TestCaseInfo::IsHidden )
  6871. isHidden = true;
  6872. else if( prop == TestCaseInfo::None )
  6873. enforceNotReservedTag( tag, _lineInfo );
  6874. tags.insert( tag );
  6875. tag.clear();
  6876. inTag = false;
  6877. }
  6878. else
  6879. tag += c;
  6880. }
  6881. }
  6882. if( isHidden ) {
  6883. tags.insert( "hide" );
  6884. tags.insert( "." );
  6885. }
  6886. TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
  6887. return TestCase( _testCase, info );
  6888. }
  6889. void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
  6890. {
  6891. testCaseInfo.tags = tags;
  6892. testCaseInfo.lcaseTags.clear();
  6893. std::ostringstream oss;
  6894. for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
  6895. oss << '[' << *it << ']';
  6896. std::string lcaseTag = toLower( *it );
  6897. testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
  6898. testCaseInfo.lcaseTags.insert( lcaseTag );
  6899. }
  6900. testCaseInfo.tagsAsString = oss.str();
  6901. }
  6902. TestCaseInfo::TestCaseInfo( std::string const& _name,
  6903. std::string const& _className,
  6904. std::string const& _description,
  6905. std::set<std::string> const& _tags,
  6906. SourceLineInfo const& _lineInfo )
  6907. : name( _name ),
  6908. className( _className ),
  6909. description( _description ),
  6910. lineInfo( _lineInfo ),
  6911. properties( None )
  6912. {
  6913. setTags( *this, _tags );
  6914. }
  6915. TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
  6916. : name( other.name ),
  6917. className( other.className ),
  6918. description( other.description ),
  6919. tags( other.tags ),
  6920. lcaseTags( other.lcaseTags ),
  6921. tagsAsString( other.tagsAsString ),
  6922. lineInfo( other.lineInfo ),
  6923. properties( other.properties )
  6924. {}
  6925. bool TestCaseInfo::isHidden() const {
  6926. return ( properties & IsHidden ) != 0;
  6927. }
  6928. bool TestCaseInfo::throws() const {
  6929. return ( properties & Throws ) != 0;
  6930. }
  6931. bool TestCaseInfo::okToFail() const {
  6932. return ( properties & (ShouldFail | MayFail ) ) != 0;
  6933. }
  6934. bool TestCaseInfo::expectedToFail() const {
  6935. return ( properties & (ShouldFail ) ) != 0;
  6936. }
  6937. TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
  6938. TestCase::TestCase( TestCase const& other )
  6939. : TestCaseInfo( other ),
  6940. test( other.test )
  6941. {}
  6942. TestCase TestCase::withName( std::string const& _newName ) const {
  6943. TestCase other( *this );
  6944. other.name = _newName;
  6945. return other;
  6946. }
  6947. void TestCase::swap( TestCase& other ) {
  6948. test.swap( other.test );
  6949. name.swap( other.name );
  6950. className.swap( other.className );
  6951. description.swap( other.description );
  6952. tags.swap( other.tags );
  6953. lcaseTags.swap( other.lcaseTags );
  6954. tagsAsString.swap( other.tagsAsString );
  6955. std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
  6956. std::swap( lineInfo, other.lineInfo );
  6957. }
  6958. void TestCase::invoke() const {
  6959. test->invoke();
  6960. }
  6961. bool TestCase::operator == ( TestCase const& other ) const {
  6962. return test.get() == other.test.get() &&
  6963. name == other.name &&
  6964. className == other.className;
  6965. }
  6966. bool TestCase::operator < ( TestCase const& other ) const {
  6967. return name < other.name;
  6968. }
  6969. TestCase& TestCase::operator = ( TestCase const& other ) {
  6970. TestCase temp( other );
  6971. swap( temp );
  6972. return *this;
  6973. }
  6974. TestCaseInfo const& TestCase::getTestCaseInfo() const
  6975. {
  6976. return *this;
  6977. }
  6978. } // end namespace Catch
  6979. // #included from: catch_version.hpp
  6980. #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
  6981. namespace Catch {
  6982. Version::Version
  6983. ( unsigned int _majorVersion,
  6984. unsigned int _minorVersion,
  6985. unsigned int _patchNumber,
  6986. char const * const _branchName,
  6987. unsigned int _buildNumber )
  6988. : majorVersion( _majorVersion ),
  6989. minorVersion( _minorVersion ),
  6990. patchNumber( _patchNumber ),
  6991. branchName( _branchName ),
  6992. buildNumber( _buildNumber )
  6993. {}
  6994. std::ostream& operator << ( std::ostream& os, Version const& version ) {
  6995. os << version.majorVersion << '.'
  6996. << version.minorVersion << '.'
  6997. << version.patchNumber;
  6998. // branchName is never null -> 0th char is \0 if it is empty
  6999. if (version.branchName[0]) {
  7000. os << '-' << version.branchName
  7001. << '.' << version.buildNumber;
  7002. }
  7003. return os;
  7004. }
  7005. inline Version libraryVersion() {
  7006. static Version version( 1, 12, 2, "", 0 );
  7007. return version;
  7008. }
  7009. }
  7010. // #included from: catch_message.hpp
  7011. #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
  7012. namespace Catch {
  7013. MessageInfo::MessageInfo( std::string const& _macroName,
  7014. SourceLineInfo const& _lineInfo,
  7015. ResultWas::OfType _type )
  7016. : macroName( _macroName ),
  7017. lineInfo( _lineInfo ),
  7018. type( _type ),
  7019. sequence( ++globalCount )
  7020. {}
  7021. // This may need protecting if threading support is added
  7022. unsigned int MessageInfo::globalCount = 0;
  7023. ////////////////////////////////////////////////////////////////////////////
  7024. ScopedMessage::ScopedMessage( MessageBuilder const& builder )
  7025. : m_info( builder.m_info )
  7026. {
  7027. m_info.message = builder.m_stream.str();
  7028. getResultCapture().pushScopedMessage( m_info );
  7029. }
  7030. ScopedMessage::ScopedMessage( ScopedMessage const& other )
  7031. : m_info( other.m_info )
  7032. {}
  7033. #if defined(_MSC_VER)
  7034. #pragma warning(push)
  7035. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7036. #endif
  7037. ScopedMessage::~ScopedMessage() {
  7038. if ( !std::uncaught_exception() ){
  7039. getResultCapture().popScopedMessage(m_info);
  7040. }
  7041. }
  7042. #if defined(_MSC_VER)
  7043. #pragma warning(pop)
  7044. #endif
  7045. } // end namespace Catch
  7046. // #included from: catch_legacy_reporter_adapter.hpp
  7047. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
  7048. // #included from: catch_legacy_reporter_adapter.h
  7049. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
  7050. namespace Catch
  7051. {
  7052. // Deprecated
  7053. struct IReporter : IShared {
  7054. virtual ~IReporter();
  7055. virtual bool shouldRedirectStdout() const = 0;
  7056. virtual void StartTesting() = 0;
  7057. virtual void EndTesting( Totals const& totals ) = 0;
  7058. virtual void StartGroup( std::string const& groupName ) = 0;
  7059. virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
  7060. virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
  7061. virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
  7062. virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
  7063. virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
  7064. virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
  7065. virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
  7066. virtual void Aborted() = 0;
  7067. virtual void Result( AssertionResult const& result ) = 0;
  7068. };
  7069. class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
  7070. {
  7071. public:
  7072. LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
  7073. virtual ~LegacyReporterAdapter();
  7074. virtual ReporterPreferences getPreferences() const;
  7075. virtual void noMatchingTestCases( std::string const& );
  7076. virtual void testRunStarting( TestRunInfo const& );
  7077. virtual void testGroupStarting( GroupInfo const& groupInfo );
  7078. virtual void testCaseStarting( TestCaseInfo const& testInfo );
  7079. virtual void sectionStarting( SectionInfo const& sectionInfo );
  7080. virtual void assertionStarting( AssertionInfo const& );
  7081. virtual bool assertionEnded( AssertionStats const& assertionStats );
  7082. virtual void sectionEnded( SectionStats const& sectionStats );
  7083. virtual void testCaseEnded( TestCaseStats const& testCaseStats );
  7084. virtual void testGroupEnded( TestGroupStats const& testGroupStats );
  7085. virtual void testRunEnded( TestRunStats const& testRunStats );
  7086. virtual void skipTest( TestCaseInfo const& );
  7087. private:
  7088. Ptr<IReporter> m_legacyReporter;
  7089. };
  7090. }
  7091. namespace Catch
  7092. {
  7093. LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
  7094. : m_legacyReporter( legacyReporter )
  7095. {}
  7096. LegacyReporterAdapter::~LegacyReporterAdapter() {}
  7097. ReporterPreferences LegacyReporterAdapter::getPreferences() const {
  7098. ReporterPreferences prefs;
  7099. prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
  7100. return prefs;
  7101. }
  7102. void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
  7103. void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
  7104. m_legacyReporter->StartTesting();
  7105. }
  7106. void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
  7107. m_legacyReporter->StartGroup( groupInfo.name );
  7108. }
  7109. void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
  7110. m_legacyReporter->StartTestCase( testInfo );
  7111. }
  7112. void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
  7113. m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
  7114. }
  7115. void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
  7116. // Not on legacy interface
  7117. }
  7118. bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
  7119. if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
  7120. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  7121. it != itEnd;
  7122. ++it ) {
  7123. if( it->type == ResultWas::Info ) {
  7124. ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
  7125. rb << it->message;
  7126. rb.setResultType( ResultWas::Info );
  7127. AssertionResult result = rb.build();
  7128. m_legacyReporter->Result( result );
  7129. }
  7130. }
  7131. }
  7132. m_legacyReporter->Result( assertionStats.assertionResult );
  7133. return true;
  7134. }
  7135. void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
  7136. if( sectionStats.missingAssertions )
  7137. m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
  7138. m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
  7139. }
  7140. void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
  7141. m_legacyReporter->EndTestCase
  7142. ( testCaseStats.testInfo,
  7143. testCaseStats.totals,
  7144. testCaseStats.stdOut,
  7145. testCaseStats.stdErr );
  7146. }
  7147. void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
  7148. if( testGroupStats.aborting )
  7149. m_legacyReporter->Aborted();
  7150. m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
  7151. }
  7152. void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
  7153. m_legacyReporter->EndTesting( testRunStats.totals );
  7154. }
  7155. void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
  7156. }
  7157. }
  7158. // #included from: catch_timer.hpp
  7159. #ifdef __clang__
  7160. #pragma clang diagnostic push
  7161. #pragma clang diagnostic ignored "-Wc++11-long-long"
  7162. #endif
  7163. #ifdef CATCH_PLATFORM_WINDOWS
  7164. #else
  7165. #include <sys/time.h>
  7166. #endif
  7167. namespace Catch {
  7168. namespace {
  7169. #ifdef CATCH_PLATFORM_WINDOWS
  7170. UInt64 getCurrentTicks() {
  7171. static UInt64 hz=0, hzo=0;
  7172. if (!hz) {
  7173. QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
  7174. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
  7175. }
  7176. UInt64 t;
  7177. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
  7178. return ((t-hzo)*1000000)/hz;
  7179. }
  7180. #else
  7181. UInt64 getCurrentTicks() {
  7182. timeval t;
  7183. gettimeofday(&t,CATCH_NULL);
  7184. return static_cast<UInt64>( t.tv_sec ) * 1000000ull + static_cast<UInt64>( t.tv_usec );
  7185. }
  7186. #endif
  7187. }
  7188. void Timer::start() {
  7189. m_ticks = getCurrentTicks();
  7190. }
  7191. unsigned int Timer::getElapsedMicroseconds() const {
  7192. return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
  7193. }
  7194. unsigned int Timer::getElapsedMilliseconds() const {
  7195. return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
  7196. }
  7197. double Timer::getElapsedSeconds() const {
  7198. return getElapsedMicroseconds()/1000000.0;
  7199. }
  7200. } // namespace Catch
  7201. #ifdef __clang__
  7202. #pragma clang diagnostic pop
  7203. #endif
  7204. // #included from: catch_common.hpp
  7205. #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
  7206. #include <cstring>
  7207. #include <cctype>
  7208. namespace Catch {
  7209. bool startsWith( std::string const& s, std::string const& prefix ) {
  7210. return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
  7211. }
  7212. bool startsWith( std::string const& s, char prefix ) {
  7213. return !s.empty() && s[0] == prefix;
  7214. }
  7215. bool endsWith( std::string const& s, std::string const& suffix ) {
  7216. return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
  7217. }
  7218. bool endsWith( std::string const& s, char suffix ) {
  7219. return !s.empty() && s[s.size()-1] == suffix;
  7220. }
  7221. bool contains( std::string const& s, std::string const& infix ) {
  7222. return s.find( infix ) != std::string::npos;
  7223. }
  7224. char toLowerCh(char c) {
  7225. return static_cast<char>( std::tolower( c ) );
  7226. }
  7227. void toLowerInPlace( std::string& s ) {
  7228. std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
  7229. }
  7230. std::string toLower( std::string const& s ) {
  7231. std::string lc = s;
  7232. toLowerInPlace( lc );
  7233. return lc;
  7234. }
  7235. std::string trim( std::string const& str ) {
  7236. static char const* whitespaceChars = "\n\r\t ";
  7237. std::string::size_type start = str.find_first_not_of( whitespaceChars );
  7238. std::string::size_type end = str.find_last_not_of( whitespaceChars );
  7239. return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
  7240. }
  7241. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
  7242. bool replaced = false;
  7243. std::size_t i = str.find( replaceThis );
  7244. while( i != std::string::npos ) {
  7245. replaced = true;
  7246. str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
  7247. if( i < str.size()-withThis.size() )
  7248. i = str.find( replaceThis, i+withThis.size() );
  7249. else
  7250. i = std::string::npos;
  7251. }
  7252. return replaced;
  7253. }
  7254. pluralise::pluralise( std::size_t count, std::string const& label )
  7255. : m_count( count ),
  7256. m_label( label )
  7257. {}
  7258. std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
  7259. os << pluraliser.m_count << ' ' << pluraliser.m_label;
  7260. if( pluraliser.m_count != 1 )
  7261. os << 's';
  7262. return os;
  7263. }
  7264. SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
  7265. SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
  7266. : file( _file ),
  7267. line( _line )
  7268. {}
  7269. bool SourceLineInfo::empty() const {
  7270. return file[0] == '\0';
  7271. }
  7272. bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
  7273. return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
  7274. }
  7275. bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
  7276. return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
  7277. }
  7278. void seedRng( IConfig const& config ) {
  7279. if( config.rngSeed() != 0 )
  7280. std::srand( config.rngSeed() );
  7281. }
  7282. unsigned int rngSeed() {
  7283. return getCurrentContext().getConfig()->rngSeed();
  7284. }
  7285. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
  7286. #ifndef __GNUG__
  7287. os << info.file << '(' << info.line << ')';
  7288. #else
  7289. os << info.file << ':' << info.line;
  7290. #endif
  7291. return os;
  7292. }
  7293. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
  7294. std::ostringstream oss;
  7295. oss << locationInfo << ": Internal Catch error: '" << message << '\'';
  7296. if( alwaysTrue() )
  7297. throw std::logic_error( oss.str() );
  7298. }
  7299. }
  7300. // #included from: catch_section.hpp
  7301. #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
  7302. namespace Catch {
  7303. SectionInfo::SectionInfo
  7304. ( SourceLineInfo const& _lineInfo,
  7305. std::string const& _name,
  7306. std::string const& _description )
  7307. : name( _name ),
  7308. description( _description ),
  7309. lineInfo( _lineInfo )
  7310. {}
  7311. Section::Section( SectionInfo const& info )
  7312. : m_info( info ),
  7313. m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
  7314. {
  7315. m_timer.start();
  7316. }
  7317. #if defined(_MSC_VER)
  7318. #pragma warning(push)
  7319. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7320. #endif
  7321. Section::~Section() {
  7322. if( m_sectionIncluded ) {
  7323. SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
  7324. if( std::uncaught_exception() )
  7325. getResultCapture().sectionEndedEarly( endInfo );
  7326. else
  7327. getResultCapture().sectionEnded( endInfo );
  7328. }
  7329. }
  7330. #if defined(_MSC_VER)
  7331. #pragma warning(pop)
  7332. #endif
  7333. // This indicates whether the section should be executed or not
  7334. Section::operator bool() const {
  7335. return m_sectionIncluded;
  7336. }
  7337. } // end namespace Catch
  7338. // #included from: catch_debugger.hpp
  7339. #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
  7340. #ifdef CATCH_PLATFORM_MAC
  7341. #include <assert.h>
  7342. #include <stdbool.h>
  7343. #include <sys/types.h>
  7344. #include <unistd.h>
  7345. #include <sys/sysctl.h>
  7346. namespace Catch{
  7347. // The following function is taken directly from the following technical note:
  7348. // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
  7349. // Returns true if the current process is being debugged (either
  7350. // running under the debugger or has a debugger attached post facto).
  7351. bool isDebuggerActive(){
  7352. int mib[4];
  7353. struct kinfo_proc info;
  7354. size_t size;
  7355. // Initialize the flags so that, if sysctl fails for some bizarre
  7356. // reason, we get a predictable result.
  7357. info.kp_proc.p_flag = 0;
  7358. // Initialize mib, which tells sysctl the info we want, in this case
  7359. // we're looking for information about a specific process ID.
  7360. mib[0] = CTL_KERN;
  7361. mib[1] = KERN_PROC;
  7362. mib[2] = KERN_PROC_PID;
  7363. mib[3] = getpid();
  7364. // Call sysctl.
  7365. size = sizeof(info);
  7366. if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
  7367. Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
  7368. return false;
  7369. }
  7370. // We're being debugged if the P_TRACED flag is set.
  7371. return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
  7372. }
  7373. } // namespace Catch
  7374. #elif defined(CATCH_PLATFORM_LINUX)
  7375. #include <fstream>
  7376. #include <string>
  7377. namespace Catch{
  7378. // The standard POSIX way of detecting a debugger is to attempt to
  7379. // ptrace() the process, but this needs to be done from a child and not
  7380. // this process itself to still allow attaching to this process later
  7381. // if wanted, so is rather heavy. Under Linux we have the PID of the
  7382. // "debugger" (which doesn't need to be gdb, of course, it could also
  7383. // be strace, for example) in /proc/$PID/status, so just get it from
  7384. // there instead.
  7385. bool isDebuggerActive(){
  7386. // Libstdc++ has a bug, where std::ifstream sets errno to 0
  7387. // This way our users can properly assert over errno values
  7388. ErrnoGuard guard;
  7389. std::ifstream in("/proc/self/status");
  7390. for( std::string line; std::getline(in, line); ) {
  7391. static const int PREFIX_LEN = 11;
  7392. if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) {
  7393. // We're traced if the PID is not 0 and no other PID starts
  7394. // with 0 digit, so it's enough to check for just a single
  7395. // character.
  7396. return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0';
  7397. }
  7398. }
  7399. return false;
  7400. }
  7401. } // namespace Catch
  7402. #elif defined(_MSC_VER)
  7403. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7404. namespace Catch {
  7405. bool isDebuggerActive() {
  7406. return IsDebuggerPresent() != 0;
  7407. }
  7408. }
  7409. #elif defined(__MINGW32__)
  7410. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7411. namespace Catch {
  7412. bool isDebuggerActive() {
  7413. return IsDebuggerPresent() != 0;
  7414. }
  7415. }
  7416. #else
  7417. namespace Catch {
  7418. inline bool isDebuggerActive() { return false; }
  7419. }
  7420. #endif // Platform
  7421. #ifdef CATCH_PLATFORM_WINDOWS
  7422. namespace Catch {
  7423. void writeToDebugConsole( std::string const& text ) {
  7424. ::OutputDebugStringA( text.c_str() );
  7425. }
  7426. }
  7427. #else
  7428. namespace Catch {
  7429. void writeToDebugConsole( std::string const& text ) {
  7430. // !TBD: Need a version for Mac/ XCode and other IDEs
  7431. Catch::cout() << text;
  7432. }
  7433. }
  7434. #endif // Platform
  7435. // #included from: catch_tostring.hpp
  7436. #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
  7437. namespace Catch {
  7438. namespace Detail {
  7439. const std::string unprintableString = "{?}";
  7440. namespace {
  7441. const int hexThreshold = 255;
  7442. struct Endianness {
  7443. enum Arch { Big, Little };
  7444. static Arch which() {
  7445. union _{
  7446. int asInt;
  7447. char asChar[sizeof (int)];
  7448. } u;
  7449. u.asInt = 1;
  7450. return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
  7451. }
  7452. };
  7453. }
  7454. std::string rawMemoryToString( const void *object, std::size_t size )
  7455. {
  7456. // Reverse order for little endian architectures
  7457. int i = 0, end = static_cast<int>( size ), inc = 1;
  7458. if( Endianness::which() == Endianness::Little ) {
  7459. i = end-1;
  7460. end = inc = -1;
  7461. }
  7462. unsigned char const *bytes = static_cast<unsigned char const *>(object);
  7463. std::ostringstream os;
  7464. os << "0x" << std::setfill('0') << std::hex;
  7465. for( ; i != end; i += inc )
  7466. os << std::setw(2) << static_cast<unsigned>(bytes[i]);
  7467. return os.str();
  7468. }
  7469. }
  7470. std::string toString( std::string const& value ) {
  7471. std::string s = value;
  7472. if( getCurrentContext().getConfig()->showInvisibles() ) {
  7473. for(size_t i = 0; i < s.size(); ++i ) {
  7474. std::string subs;
  7475. switch( s[i] ) {
  7476. case '\n': subs = "\\n"; break;
  7477. case '\t': subs = "\\t"; break;
  7478. default: break;
  7479. }
  7480. if( !subs.empty() ) {
  7481. s = s.substr( 0, i ) + subs + s.substr( i+1 );
  7482. ++i;
  7483. }
  7484. }
  7485. }
  7486. return '"' + s + '"';
  7487. }
  7488. std::string toString( std::wstring const& value ) {
  7489. std::string s;
  7490. s.reserve( value.size() );
  7491. for(size_t i = 0; i < value.size(); ++i )
  7492. s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
  7493. return Catch::toString( s );
  7494. }
  7495. std::string toString( const char* const value ) {
  7496. return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
  7497. }
  7498. std::string toString( char* const value ) {
  7499. return Catch::toString( static_cast<const char*>( value ) );
  7500. }
  7501. std::string toString( const wchar_t* const value )
  7502. {
  7503. return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
  7504. }
  7505. std::string toString( wchar_t* const value )
  7506. {
  7507. return Catch::toString( static_cast<const wchar_t*>( value ) );
  7508. }
  7509. std::string toString( int value ) {
  7510. std::ostringstream oss;
  7511. oss << value;
  7512. if( value > Detail::hexThreshold )
  7513. oss << " (0x" << std::hex << value << ')';
  7514. return oss.str();
  7515. }
  7516. std::string toString( unsigned long value ) {
  7517. std::ostringstream oss;
  7518. oss << value;
  7519. if( value > Detail::hexThreshold )
  7520. oss << " (0x" << std::hex << value << ')';
  7521. return oss.str();
  7522. }
  7523. std::string toString( unsigned int value ) {
  7524. return Catch::toString( static_cast<unsigned long>( value ) );
  7525. }
  7526. template<typename T>
  7527. std::string fpToString( T value, int precision ) {
  7528. std::ostringstream oss;
  7529. oss << std::setprecision( precision )
  7530. << std::fixed
  7531. << value;
  7532. std::string d = oss.str();
  7533. std::size_t i = d.find_last_not_of( '0' );
  7534. if( i != std::string::npos && i != d.size()-1 ) {
  7535. if( d[i] == '.' )
  7536. i++;
  7537. d = d.substr( 0, i+1 );
  7538. }
  7539. return d;
  7540. }
  7541. std::string toString( const double value ) {
  7542. return fpToString( value, 10 );
  7543. }
  7544. std::string toString( const float value ) {
  7545. return fpToString( value, 5 ) + 'f';
  7546. }
  7547. std::string toString( bool value ) {
  7548. return value ? "true" : "false";
  7549. }
  7550. std::string toString( char value ) {
  7551. if ( value == '\r' )
  7552. return "'\\r'";
  7553. if ( value == '\f' )
  7554. return "'\\f'";
  7555. if ( value == '\n' )
  7556. return "'\\n'";
  7557. if ( value == '\t' )
  7558. return "'\\t'";
  7559. if ( '\0' <= value && value < ' ' )
  7560. return toString( static_cast<unsigned int>( value ) );
  7561. char chstr[] = "' '";
  7562. chstr[1] = value;
  7563. return chstr;
  7564. }
  7565. std::string toString( signed char value ) {
  7566. return toString( static_cast<char>( value ) );
  7567. }
  7568. std::string toString( unsigned char value ) {
  7569. return toString( static_cast<char>( value ) );
  7570. }
  7571. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  7572. std::string toString( long long value ) {
  7573. std::ostringstream oss;
  7574. oss << value;
  7575. if( value > Detail::hexThreshold )
  7576. oss << " (0x" << std::hex << value << ')';
  7577. return oss.str();
  7578. }
  7579. std::string toString( unsigned long long value ) {
  7580. std::ostringstream oss;
  7581. oss << value;
  7582. if( value > Detail::hexThreshold )
  7583. oss << " (0x" << std::hex << value << ')';
  7584. return oss.str();
  7585. }
  7586. #endif
  7587. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  7588. std::string toString( std::nullptr_t ) {
  7589. return "nullptr";
  7590. }
  7591. #endif
  7592. #ifdef __OBJC__
  7593. std::string toString( NSString const * const& nsstring ) {
  7594. if( !nsstring )
  7595. return "nil";
  7596. return "@" + toString([nsstring UTF8String]);
  7597. }
  7598. std::string toString( NSString * CATCH_ARC_STRONG & nsstring ) {
  7599. if( !nsstring )
  7600. return "nil";
  7601. return "@" + toString([nsstring UTF8String]);
  7602. }
  7603. std::string toString( NSObject* const& nsObject ) {
  7604. return toString( [nsObject description] );
  7605. }
  7606. #endif
  7607. } // end namespace Catch
  7608. // #included from: catch_result_builder.hpp
  7609. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
  7610. #include <cassert>
  7611. namespace Catch {
  7612. ResultBuilder::ResultBuilder( char const* macroName,
  7613. SourceLineInfo const& lineInfo,
  7614. char const* capturedExpression,
  7615. ResultDisposition::Flags resultDisposition,
  7616. char const* secondArg )
  7617. : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition, secondArg ),
  7618. m_shouldDebugBreak( false ),
  7619. m_shouldThrow( false ),
  7620. m_guardException( false ),
  7621. m_usedStream( false )
  7622. {}
  7623. ResultBuilder::~ResultBuilder() {
  7624. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7625. if ( m_guardException ) {
  7626. stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
  7627. captureResult( ResultWas::ThrewException );
  7628. getCurrentContext().getResultCapture()->exceptionEarlyReported();
  7629. }
  7630. #endif
  7631. }
  7632. ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
  7633. m_data.resultType = result;
  7634. return *this;
  7635. }
  7636. ResultBuilder& ResultBuilder::setResultType( bool result ) {
  7637. m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
  7638. return *this;
  7639. }
  7640. void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
  7641. // Flip bool results if FalseTest flag is set
  7642. if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
  7643. m_data.negate( expr.isBinaryExpression() );
  7644. }
  7645. getResultCapture().assertionRun();
  7646. if(getCurrentContext().getConfig()->includeSuccessfulResults() || m_data.resultType != ResultWas::Ok)
  7647. {
  7648. AssertionResult result = build( expr );
  7649. handleResult( result );
  7650. }
  7651. else
  7652. getResultCapture().assertionPassed();
  7653. }
  7654. void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
  7655. m_assertionInfo.resultDisposition = resultDisposition;
  7656. stream().oss << Catch::translateActiveException();
  7657. captureResult( ResultWas::ThrewException );
  7658. }
  7659. void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
  7660. setResultType( resultType );
  7661. captureExpression();
  7662. }
  7663. void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
  7664. if( expectedMessage.empty() )
  7665. captureExpectedException( Matchers::Impl::MatchAllOf<std::string>() );
  7666. else
  7667. captureExpectedException( Matchers::Equals( expectedMessage ) );
  7668. }
  7669. void ResultBuilder::captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher ) {
  7670. assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
  7671. AssertionResultData data = m_data;
  7672. data.resultType = ResultWas::Ok;
  7673. data.reconstructedExpression = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7674. std::string actualMessage = Catch::translateActiveException();
  7675. if( !matcher.match( actualMessage ) ) {
  7676. data.resultType = ResultWas::ExpressionFailed;
  7677. data.reconstructedExpression = actualMessage;
  7678. }
  7679. AssertionResult result( m_assertionInfo, data );
  7680. handleResult( result );
  7681. }
  7682. void ResultBuilder::captureExpression() {
  7683. AssertionResult result = build();
  7684. handleResult( result );
  7685. }
  7686. void ResultBuilder::handleResult( AssertionResult const& result )
  7687. {
  7688. getResultCapture().assertionEnded( result );
  7689. if( !result.isOk() ) {
  7690. if( getCurrentContext().getConfig()->shouldDebugBreak() )
  7691. m_shouldDebugBreak = true;
  7692. if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
  7693. m_shouldThrow = true;
  7694. }
  7695. }
  7696. void ResultBuilder::react() {
  7697. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7698. if (m_shouldDebugBreak) {
  7699. ///////////////////////////////////////////////////////////////////
  7700. // To inspect the state during test, you need to go one level up the callstack
  7701. // To go back to the test and change execution, jump over the throw statement
  7702. ///////////////////////////////////////////////////////////////////
  7703. CATCH_BREAK_INTO_DEBUGGER();
  7704. }
  7705. #endif
  7706. if( m_shouldThrow )
  7707. throw Catch::TestFailureException();
  7708. }
  7709. bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
  7710. bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
  7711. AssertionResult ResultBuilder::build() const
  7712. {
  7713. return build( *this );
  7714. }
  7715. // CAVEAT: The returned AssertionResult stores a pointer to the argument expr,
  7716. // a temporary DecomposedExpression, which in turn holds references to
  7717. // operands, possibly temporary as well.
  7718. // It should immediately be passed to handleResult; if the expression
  7719. // needs to be reported, its string expansion must be composed before
  7720. // the temporaries are destroyed.
  7721. AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
  7722. {
  7723. assert( m_data.resultType != ResultWas::Unknown );
  7724. AssertionResultData data = m_data;
  7725. if(m_usedStream)
  7726. data.message = m_stream().oss.str();
  7727. data.decomposedExpression = &expr; // for lazy reconstruction
  7728. return AssertionResult( m_assertionInfo, data );
  7729. }
  7730. void ResultBuilder::reconstructExpression( std::string& dest ) const {
  7731. dest = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7732. }
  7733. void ResultBuilder::setExceptionGuard() {
  7734. m_guardException = true;
  7735. }
  7736. void ResultBuilder::unsetExceptionGuard() {
  7737. m_guardException = false;
  7738. }
  7739. } // end namespace Catch
  7740. // #included from: catch_tag_alias_registry.hpp
  7741. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7742. namespace Catch {
  7743. TagAliasRegistry::~TagAliasRegistry() {}
  7744. Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
  7745. std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
  7746. if( it != m_registry.end() )
  7747. return it->second;
  7748. else
  7749. return Option<TagAlias>();
  7750. }
  7751. std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
  7752. std::string expandedTestSpec = unexpandedTestSpec;
  7753. for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
  7754. it != itEnd;
  7755. ++it ) {
  7756. std::size_t pos = expandedTestSpec.find( it->first );
  7757. if( pos != std::string::npos ) {
  7758. expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
  7759. it->second.tag +
  7760. expandedTestSpec.substr( pos + it->first.size() );
  7761. }
  7762. }
  7763. return expandedTestSpec;
  7764. }
  7765. void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
  7766. if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) {
  7767. std::ostringstream oss;
  7768. oss << Colour( Colour::Red )
  7769. << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n"
  7770. << Colour( Colour::FileName )
  7771. << lineInfo << '\n';
  7772. throw std::domain_error( oss.str().c_str() );
  7773. }
  7774. if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
  7775. std::ostringstream oss;
  7776. oss << Colour( Colour::Red )
  7777. << "error: tag alias, \"" << alias << "\" already registered.\n"
  7778. << "\tFirst seen at "
  7779. << Colour( Colour::Red ) << find(alias)->lineInfo << '\n'
  7780. << Colour( Colour::Red ) << "\tRedefined at "
  7781. << Colour( Colour::FileName) << lineInfo << '\n';
  7782. throw std::domain_error( oss.str().c_str() );
  7783. }
  7784. }
  7785. ITagAliasRegistry::~ITagAliasRegistry() {}
  7786. ITagAliasRegistry const& ITagAliasRegistry::get() {
  7787. return getRegistryHub().getTagAliasRegistry();
  7788. }
  7789. RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
  7790. getMutableRegistryHub().registerTagAlias( alias, tag, lineInfo );
  7791. }
  7792. } // end namespace Catch
  7793. // #included from: catch_matchers_string.hpp
  7794. namespace Catch {
  7795. namespace Matchers {
  7796. namespace StdString {
  7797. CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
  7798. : m_caseSensitivity( caseSensitivity ),
  7799. m_str( adjustString( str ) )
  7800. {}
  7801. std::string CasedString::adjustString( std::string const& str ) const {
  7802. return m_caseSensitivity == CaseSensitive::No
  7803. ? toLower( str )
  7804. : str;
  7805. }
  7806. std::string CasedString::caseSensitivitySuffix() const {
  7807. return m_caseSensitivity == CaseSensitive::No
  7808. ? " (case insensitive)"
  7809. : std::string();
  7810. }
  7811. StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
  7812. : m_comparator( comparator ),
  7813. m_operation( operation ) {
  7814. }
  7815. std::string StringMatcherBase::describe() const {
  7816. std::string description;
  7817. description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
  7818. m_comparator.caseSensitivitySuffix().size());
  7819. description += m_operation;
  7820. description += ": \"";
  7821. description += m_comparator.m_str;
  7822. description += "\"";
  7823. description += m_comparator.caseSensitivitySuffix();
  7824. return description;
  7825. }
  7826. EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {}
  7827. bool EqualsMatcher::match( std::string const& source ) const {
  7828. return m_comparator.adjustString( source ) == m_comparator.m_str;
  7829. }
  7830. ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {}
  7831. bool ContainsMatcher::match( std::string const& source ) const {
  7832. return contains( m_comparator.adjustString( source ), m_comparator.m_str );
  7833. }
  7834. StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {}
  7835. bool StartsWithMatcher::match( std::string const& source ) const {
  7836. return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7837. }
  7838. EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {}
  7839. bool EndsWithMatcher::match( std::string const& source ) const {
  7840. return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7841. }
  7842. } // namespace StdString
  7843. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7844. return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
  7845. }
  7846. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7847. return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
  7848. }
  7849. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7850. return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7851. }
  7852. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7853. return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7854. }
  7855. } // namespace Matchers
  7856. } // namespace Catch
  7857. // #included from: ../reporters/catch_reporter_multi.hpp
  7858. #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
  7859. namespace Catch {
  7860. class MultipleReporters : public SharedImpl<IStreamingReporter> {
  7861. typedef std::vector<Ptr<IStreamingReporter> > Reporters;
  7862. Reporters m_reporters;
  7863. public:
  7864. void add( Ptr<IStreamingReporter> const& reporter ) {
  7865. m_reporters.push_back( reporter );
  7866. }
  7867. public: // IStreamingReporter
  7868. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7869. return m_reporters[0]->getPreferences();
  7870. }
  7871. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  7872. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7873. it != itEnd;
  7874. ++it )
  7875. (*it)->noMatchingTestCases( spec );
  7876. }
  7877. virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
  7878. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7879. it != itEnd;
  7880. ++it )
  7881. (*it)->testRunStarting( testRunInfo );
  7882. }
  7883. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  7884. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7885. it != itEnd;
  7886. ++it )
  7887. (*it)->testGroupStarting( groupInfo );
  7888. }
  7889. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7890. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7891. it != itEnd;
  7892. ++it )
  7893. (*it)->testCaseStarting( testInfo );
  7894. }
  7895. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  7896. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7897. it != itEnd;
  7898. ++it )
  7899. (*it)->sectionStarting( sectionInfo );
  7900. }
  7901. virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
  7902. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7903. it != itEnd;
  7904. ++it )
  7905. (*it)->assertionStarting( assertionInfo );
  7906. }
  7907. // The return value indicates if the messages buffer should be cleared:
  7908. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  7909. bool clearBuffer = false;
  7910. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7911. it != itEnd;
  7912. ++it )
  7913. clearBuffer |= (*it)->assertionEnded( assertionStats );
  7914. return clearBuffer;
  7915. }
  7916. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  7917. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7918. it != itEnd;
  7919. ++it )
  7920. (*it)->sectionEnded( sectionStats );
  7921. }
  7922. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  7923. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7924. it != itEnd;
  7925. ++it )
  7926. (*it)->testCaseEnded( testCaseStats );
  7927. }
  7928. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  7929. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7930. it != itEnd;
  7931. ++it )
  7932. (*it)->testGroupEnded( testGroupStats );
  7933. }
  7934. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  7935. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7936. it != itEnd;
  7937. ++it )
  7938. (*it)->testRunEnded( testRunStats );
  7939. }
  7940. virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7941. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7942. it != itEnd;
  7943. ++it )
  7944. (*it)->skipTest( testInfo );
  7945. }
  7946. virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
  7947. return this;
  7948. }
  7949. };
  7950. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
  7951. Ptr<IStreamingReporter> resultingReporter;
  7952. if( existingReporter ) {
  7953. MultipleReporters* multi = existingReporter->tryAsMulti();
  7954. if( !multi ) {
  7955. multi = new MultipleReporters;
  7956. resultingReporter = Ptr<IStreamingReporter>( multi );
  7957. if( existingReporter )
  7958. multi->add( existingReporter );
  7959. }
  7960. else
  7961. resultingReporter = existingReporter;
  7962. multi->add( additionalReporter );
  7963. }
  7964. else
  7965. resultingReporter = additionalReporter;
  7966. return resultingReporter;
  7967. }
  7968. } // end namespace Catch
  7969. // #included from: ../reporters/catch_reporter_xml.hpp
  7970. #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
  7971. // #included from: catch_reporter_bases.hpp
  7972. #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
  7973. #include <cstring>
  7974. #include <cfloat>
  7975. #include <cstdio>
  7976. #include <assert.h>
  7977. namespace Catch {
  7978. namespace {
  7979. // Because formatting using c++ streams is stateful, drop down to C is required
  7980. // Alternatively we could use stringstream, but its performance is... not good.
  7981. std::string getFormattedDuration( double duration ) {
  7982. // Max exponent + 1 is required to represent the whole part
  7983. // + 1 for decimal point
  7984. // + 3 for the 3 decimal places
  7985. // + 1 for null terminator
  7986. const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
  7987. char buffer[maxDoubleSize];
  7988. // Save previous errno, to prevent sprintf from overwriting it
  7989. ErrnoGuard guard;
  7990. #ifdef _MSC_VER
  7991. sprintf_s(buffer, "%.3f", duration);
  7992. #else
  7993. sprintf(buffer, "%.3f", duration);
  7994. #endif
  7995. return std::string(buffer);
  7996. }
  7997. }
  7998. struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
  7999. StreamingReporterBase( ReporterConfig const& _config )
  8000. : m_config( _config.fullConfig() ),
  8001. stream( _config.stream() )
  8002. {
  8003. m_reporterPrefs.shouldRedirectStdOut = false;
  8004. }
  8005. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8006. return m_reporterPrefs;
  8007. }
  8008. virtual ~StreamingReporterBase() CATCH_OVERRIDE;
  8009. virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
  8010. virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
  8011. currentTestRunInfo = _testRunInfo;
  8012. }
  8013. virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
  8014. currentGroupInfo = _groupInfo;
  8015. }
  8016. virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
  8017. currentTestCaseInfo = _testInfo;
  8018. }
  8019. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8020. m_sectionStack.push_back( _sectionInfo );
  8021. }
  8022. virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
  8023. m_sectionStack.pop_back();
  8024. }
  8025. virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
  8026. currentTestCaseInfo.reset();
  8027. }
  8028. virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
  8029. currentGroupInfo.reset();
  8030. }
  8031. virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
  8032. currentTestCaseInfo.reset();
  8033. currentGroupInfo.reset();
  8034. currentTestRunInfo.reset();
  8035. }
  8036. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
  8037. // Don't do anything with this by default.
  8038. // It can optionally be overridden in the derived class.
  8039. }
  8040. Ptr<IConfig const> m_config;
  8041. std::ostream& stream;
  8042. LazyStat<TestRunInfo> currentTestRunInfo;
  8043. LazyStat<GroupInfo> currentGroupInfo;
  8044. LazyStat<TestCaseInfo> currentTestCaseInfo;
  8045. std::vector<SectionInfo> m_sectionStack;
  8046. ReporterPreferences m_reporterPrefs;
  8047. };
  8048. struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
  8049. template<typename T, typename ChildNodeT>
  8050. struct Node : SharedImpl<> {
  8051. explicit Node( T const& _value ) : value( _value ) {}
  8052. virtual ~Node() {}
  8053. typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
  8054. T value;
  8055. ChildNodes children;
  8056. };
  8057. struct SectionNode : SharedImpl<> {
  8058. explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
  8059. virtual ~SectionNode();
  8060. bool operator == ( SectionNode const& other ) const {
  8061. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  8062. }
  8063. bool operator == ( Ptr<SectionNode> const& other ) const {
  8064. return operator==( *other );
  8065. }
  8066. SectionStats stats;
  8067. typedef std::vector<Ptr<SectionNode> > ChildSections;
  8068. typedef std::vector<AssertionStats> Assertions;
  8069. ChildSections childSections;
  8070. Assertions assertions;
  8071. std::string stdOut;
  8072. std::string stdErr;
  8073. };
  8074. struct BySectionInfo {
  8075. BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
  8076. BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
  8077. bool operator() ( Ptr<SectionNode> const& node ) const {
  8078. return ((node->stats.sectionInfo.name == m_other.name) &&
  8079. (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
  8080. }
  8081. private:
  8082. void operator=( BySectionInfo const& );
  8083. SectionInfo const& m_other;
  8084. };
  8085. typedef Node<TestCaseStats, SectionNode> TestCaseNode;
  8086. typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
  8087. typedef Node<TestRunStats, TestGroupNode> TestRunNode;
  8088. CumulativeReporterBase( ReporterConfig const& _config )
  8089. : m_config( _config.fullConfig() ),
  8090. stream( _config.stream() )
  8091. {
  8092. m_reporterPrefs.shouldRedirectStdOut = false;
  8093. }
  8094. ~CumulativeReporterBase();
  8095. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8096. return m_reporterPrefs;
  8097. }
  8098. virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
  8099. virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
  8100. virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8101. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8102. SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
  8103. Ptr<SectionNode> node;
  8104. if( m_sectionStack.empty() ) {
  8105. if( !m_rootSection )
  8106. m_rootSection = new SectionNode( incompleteStats );
  8107. node = m_rootSection;
  8108. }
  8109. else {
  8110. SectionNode& parentNode = *m_sectionStack.back();
  8111. SectionNode::ChildSections::const_iterator it =
  8112. std::find_if( parentNode.childSections.begin(),
  8113. parentNode.childSections.end(),
  8114. BySectionInfo( sectionInfo ) );
  8115. if( it == parentNode.childSections.end() ) {
  8116. node = new SectionNode( incompleteStats );
  8117. parentNode.childSections.push_back( node );
  8118. }
  8119. else
  8120. node = *it;
  8121. }
  8122. m_sectionStack.push_back( node );
  8123. m_deepestSection = node;
  8124. }
  8125. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8126. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8127. assert( !m_sectionStack.empty() );
  8128. SectionNode& sectionNode = *m_sectionStack.back();
  8129. sectionNode.assertions.push_back( assertionStats );
  8130. // AssertionResult holds a pointer to a temporary DecomposedExpression,
  8131. // which getExpandedExpression() calls to build the expression string.
  8132. // Our section stack copy of the assertionResult will likely outlive the
  8133. // temporary, so it must be expanded or discarded now to avoid calling
  8134. // a destroyed object later.
  8135. prepareExpandedExpression( sectionNode.assertions.back().assertionResult );
  8136. return true;
  8137. }
  8138. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8139. assert( !m_sectionStack.empty() );
  8140. SectionNode& node = *m_sectionStack.back();
  8141. node.stats = sectionStats;
  8142. m_sectionStack.pop_back();
  8143. }
  8144. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8145. Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
  8146. assert( m_sectionStack.size() == 0 );
  8147. node->children.push_back( m_rootSection );
  8148. m_testCases.push_back( node );
  8149. m_rootSection.reset();
  8150. assert( m_deepestSection );
  8151. m_deepestSection->stdOut = testCaseStats.stdOut;
  8152. m_deepestSection->stdErr = testCaseStats.stdErr;
  8153. }
  8154. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8155. Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
  8156. node->children.swap( m_testCases );
  8157. m_testGroups.push_back( node );
  8158. }
  8159. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8160. Ptr<TestRunNode> node = new TestRunNode( testRunStats );
  8161. node->children.swap( m_testGroups );
  8162. m_testRuns.push_back( node );
  8163. testRunEndedCumulative();
  8164. }
  8165. virtual void testRunEndedCumulative() = 0;
  8166. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8167. virtual void prepareExpandedExpression( AssertionResult& result ) const {
  8168. if( result.isOk() )
  8169. result.discardDecomposedExpression();
  8170. else
  8171. result.expandDecomposedExpression();
  8172. }
  8173. Ptr<IConfig const> m_config;
  8174. std::ostream& stream;
  8175. std::vector<AssertionStats> m_assertions;
  8176. std::vector<std::vector<Ptr<SectionNode> > > m_sections;
  8177. std::vector<Ptr<TestCaseNode> > m_testCases;
  8178. std::vector<Ptr<TestGroupNode> > m_testGroups;
  8179. std::vector<Ptr<TestRunNode> > m_testRuns;
  8180. Ptr<SectionNode> m_rootSection;
  8181. Ptr<SectionNode> m_deepestSection;
  8182. std::vector<Ptr<SectionNode> > m_sectionStack;
  8183. ReporterPreferences m_reporterPrefs;
  8184. };
  8185. template<char C>
  8186. char const* getLineOfChars() {
  8187. static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
  8188. if( !*line ) {
  8189. std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
  8190. line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
  8191. }
  8192. return line;
  8193. }
  8194. struct TestEventListenerBase : StreamingReporterBase {
  8195. TestEventListenerBase( ReporterConfig const& _config )
  8196. : StreamingReporterBase( _config )
  8197. {}
  8198. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8199. virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
  8200. return false;
  8201. }
  8202. };
  8203. } // end namespace Catch
  8204. // #included from: ../internal/catch_reporter_registrars.hpp
  8205. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  8206. namespace Catch {
  8207. template<typename T>
  8208. class LegacyReporterRegistrar {
  8209. class ReporterFactory : public IReporterFactory {
  8210. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8211. return new LegacyReporterAdapter( new T( config ) );
  8212. }
  8213. virtual std::string getDescription() const {
  8214. return T::getDescription();
  8215. }
  8216. };
  8217. public:
  8218. LegacyReporterRegistrar( std::string const& name ) {
  8219. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8220. }
  8221. };
  8222. template<typename T>
  8223. class ReporterRegistrar {
  8224. class ReporterFactory : public SharedImpl<IReporterFactory> {
  8225. // *** Please Note ***:
  8226. // - If you end up here looking at a compiler error because it's trying to register
  8227. // your custom reporter class be aware that the native reporter interface has changed
  8228. // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
  8229. // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
  8230. // However please consider updating to the new interface as the old one is now
  8231. // deprecated and will probably be removed quite soon!
  8232. // Please contact me via github if you have any questions at all about this.
  8233. // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
  8234. // no idea who is actually using custom reporters at all (possibly no-one!).
  8235. // The new interface is designed to minimise exposure to interface changes in the future.
  8236. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8237. return new T( config );
  8238. }
  8239. virtual std::string getDescription() const {
  8240. return T::getDescription();
  8241. }
  8242. };
  8243. public:
  8244. ReporterRegistrar( std::string const& name ) {
  8245. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8246. }
  8247. };
  8248. template<typename T>
  8249. class ListenerRegistrar {
  8250. class ListenerFactory : public SharedImpl<IReporterFactory> {
  8251. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8252. return new T( config );
  8253. }
  8254. virtual std::string getDescription() const {
  8255. return std::string();
  8256. }
  8257. };
  8258. public:
  8259. ListenerRegistrar() {
  8260. getMutableRegistryHub().registerListener( new ListenerFactory() );
  8261. }
  8262. };
  8263. }
  8264. #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
  8265. namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8266. #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
  8267. namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8268. // Deprecated - use the form without INTERNAL_
  8269. #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
  8270. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8271. #define CATCH_REGISTER_LISTENER( listenerType ) \
  8272. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8273. // #included from: ../internal/catch_xmlwriter.hpp
  8274. #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
  8275. #include <sstream>
  8276. #include <string>
  8277. #include <vector>
  8278. #include <iomanip>
  8279. namespace Catch {
  8280. class XmlEncode {
  8281. public:
  8282. enum ForWhat { ForTextNodes, ForAttributes };
  8283. XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
  8284. : m_str( str ),
  8285. m_forWhat( forWhat )
  8286. {}
  8287. void encodeTo( std::ostream& os ) const {
  8288. // Apostrophe escaping not necessary if we always use " to write attributes
  8289. // (see: http://www.w3.org/TR/xml/#syntax)
  8290. for( std::size_t i = 0; i < m_str.size(); ++ i ) {
  8291. char c = m_str[i];
  8292. switch( c ) {
  8293. case '<': os << "&lt;"; break;
  8294. case '&': os << "&amp;"; break;
  8295. case '>':
  8296. // See: http://www.w3.org/TR/xml/#syntax
  8297. if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
  8298. os << "&gt;";
  8299. else
  8300. os << c;
  8301. break;
  8302. case '\"':
  8303. if( m_forWhat == ForAttributes )
  8304. os << "&quot;";
  8305. else
  8306. os << c;
  8307. break;
  8308. default:
  8309. // Escape control chars - based on contribution by @espenalb in PR #465 and
  8310. // by @mrpi PR #588
  8311. if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) {
  8312. // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
  8313. os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
  8314. << static_cast<int>( c );
  8315. }
  8316. else
  8317. os << c;
  8318. }
  8319. }
  8320. }
  8321. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
  8322. xmlEncode.encodeTo( os );
  8323. return os;
  8324. }
  8325. private:
  8326. std::string m_str;
  8327. ForWhat m_forWhat;
  8328. };
  8329. class XmlWriter {
  8330. public:
  8331. class ScopedElement {
  8332. public:
  8333. ScopedElement( XmlWriter* writer )
  8334. : m_writer( writer )
  8335. {}
  8336. ScopedElement( ScopedElement const& other )
  8337. : m_writer( other.m_writer ){
  8338. other.m_writer = CATCH_NULL;
  8339. }
  8340. ~ScopedElement() {
  8341. if( m_writer )
  8342. m_writer->endElement();
  8343. }
  8344. ScopedElement& writeText( std::string const& text, bool indent = true ) {
  8345. m_writer->writeText( text, indent );
  8346. return *this;
  8347. }
  8348. template<typename T>
  8349. ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
  8350. m_writer->writeAttribute( name, attribute );
  8351. return *this;
  8352. }
  8353. private:
  8354. mutable XmlWriter* m_writer;
  8355. };
  8356. XmlWriter()
  8357. : m_tagIsOpen( false ),
  8358. m_needsNewline( false ),
  8359. m_os( Catch::cout() )
  8360. {
  8361. writeDeclaration();
  8362. }
  8363. XmlWriter( std::ostream& os )
  8364. : m_tagIsOpen( false ),
  8365. m_needsNewline( false ),
  8366. m_os( os )
  8367. {
  8368. writeDeclaration();
  8369. }
  8370. ~XmlWriter() {
  8371. while( !m_tags.empty() )
  8372. endElement();
  8373. }
  8374. XmlWriter& startElement( std::string const& name ) {
  8375. ensureTagClosed();
  8376. newlineIfNecessary();
  8377. m_os << m_indent << '<' << name;
  8378. m_tags.push_back( name );
  8379. m_indent += " ";
  8380. m_tagIsOpen = true;
  8381. return *this;
  8382. }
  8383. ScopedElement scopedElement( std::string const& name ) {
  8384. ScopedElement scoped( this );
  8385. startElement( name );
  8386. return scoped;
  8387. }
  8388. XmlWriter& endElement() {
  8389. newlineIfNecessary();
  8390. m_indent = m_indent.substr( 0, m_indent.size()-2 );
  8391. if( m_tagIsOpen ) {
  8392. m_os << "/>";
  8393. m_tagIsOpen = false;
  8394. }
  8395. else {
  8396. m_os << m_indent << "</" << m_tags.back() << ">";
  8397. }
  8398. m_os << std::endl;
  8399. m_tags.pop_back();
  8400. return *this;
  8401. }
  8402. XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
  8403. if( !name.empty() && !attribute.empty() )
  8404. m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
  8405. return *this;
  8406. }
  8407. XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
  8408. m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
  8409. return *this;
  8410. }
  8411. template<typename T>
  8412. XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
  8413. std::ostringstream oss;
  8414. oss << attribute;
  8415. return writeAttribute( name, oss.str() );
  8416. }
  8417. XmlWriter& writeText( std::string const& text, bool indent = true ) {
  8418. if( !text.empty() ){
  8419. bool tagWasOpen = m_tagIsOpen;
  8420. ensureTagClosed();
  8421. if( tagWasOpen && indent )
  8422. m_os << m_indent;
  8423. m_os << XmlEncode( text );
  8424. m_needsNewline = true;
  8425. }
  8426. return *this;
  8427. }
  8428. XmlWriter& writeComment( std::string const& text ) {
  8429. ensureTagClosed();
  8430. m_os << m_indent << "<!--" << text << "-->";
  8431. m_needsNewline = true;
  8432. return *this;
  8433. }
  8434. void writeStylesheetRef( std::string const& url ) {
  8435. m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
  8436. }
  8437. XmlWriter& writeBlankLine() {
  8438. ensureTagClosed();
  8439. m_os << '\n';
  8440. return *this;
  8441. }
  8442. void ensureTagClosed() {
  8443. if( m_tagIsOpen ) {
  8444. m_os << ">" << std::endl;
  8445. m_tagIsOpen = false;
  8446. }
  8447. }
  8448. private:
  8449. XmlWriter( XmlWriter const& );
  8450. void operator=( XmlWriter const& );
  8451. void writeDeclaration() {
  8452. m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  8453. }
  8454. void newlineIfNecessary() {
  8455. if( m_needsNewline ) {
  8456. m_os << std::endl;
  8457. m_needsNewline = false;
  8458. }
  8459. }
  8460. bool m_tagIsOpen;
  8461. bool m_needsNewline;
  8462. std::vector<std::string> m_tags;
  8463. std::string m_indent;
  8464. std::ostream& m_os;
  8465. };
  8466. }
  8467. namespace Catch {
  8468. class XmlReporter : public StreamingReporterBase {
  8469. public:
  8470. XmlReporter( ReporterConfig const& _config )
  8471. : StreamingReporterBase( _config ),
  8472. m_xml(_config.stream()),
  8473. m_sectionDepth( 0 )
  8474. {
  8475. m_reporterPrefs.shouldRedirectStdOut = true;
  8476. }
  8477. virtual ~XmlReporter() CATCH_OVERRIDE;
  8478. static std::string getDescription() {
  8479. return "Reports test results as an XML document";
  8480. }
  8481. virtual std::string getStylesheetRef() const {
  8482. return std::string();
  8483. }
  8484. void writeSourceInfo( SourceLineInfo const& sourceInfo ) {
  8485. m_xml
  8486. .writeAttribute( "filename", sourceInfo.file )
  8487. .writeAttribute( "line", sourceInfo.line );
  8488. }
  8489. public: // StreamingReporterBase
  8490. virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
  8491. StreamingReporterBase::noMatchingTestCases( s );
  8492. }
  8493. virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
  8494. StreamingReporterBase::testRunStarting( testInfo );
  8495. std::string stylesheetRef = getStylesheetRef();
  8496. if( !stylesheetRef.empty() )
  8497. m_xml.writeStylesheetRef( stylesheetRef );
  8498. m_xml.startElement( "Catch" );
  8499. if( !m_config->name().empty() )
  8500. m_xml.writeAttribute( "name", m_config->name() );
  8501. }
  8502. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8503. StreamingReporterBase::testGroupStarting( groupInfo );
  8504. m_xml.startElement( "Group" )
  8505. .writeAttribute( "name", groupInfo.name );
  8506. }
  8507. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  8508. StreamingReporterBase::testCaseStarting(testInfo);
  8509. m_xml.startElement( "TestCase" )
  8510. .writeAttribute( "name", trim( testInfo.name ) )
  8511. .writeAttribute( "description", testInfo.description )
  8512. .writeAttribute( "tags", testInfo.tagsAsString );
  8513. writeSourceInfo( testInfo.lineInfo );
  8514. if ( m_config->showDurations() == ShowDurations::Always )
  8515. m_testCaseTimer.start();
  8516. m_xml.ensureTagClosed();
  8517. }
  8518. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8519. StreamingReporterBase::sectionStarting( sectionInfo );
  8520. if( m_sectionDepth++ > 0 ) {
  8521. m_xml.startElement( "Section" )
  8522. .writeAttribute( "name", trim( sectionInfo.name ) )
  8523. .writeAttribute( "description", sectionInfo.description );
  8524. writeSourceInfo( sectionInfo.lineInfo );
  8525. m_xml.ensureTagClosed();
  8526. }
  8527. }
  8528. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
  8529. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8530. AssertionResult const& result = assertionStats.assertionResult;
  8531. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8532. if( includeResults || result.getResultType() == ResultWas::Warning ) {
  8533. // Print any info messages in <Info> tags.
  8534. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  8535. it != itEnd;
  8536. ++it ) {
  8537. if( it->type == ResultWas::Info && includeResults ) {
  8538. m_xml.scopedElement( "Info" )
  8539. .writeText( it->message );
  8540. } else if ( it->type == ResultWas::Warning ) {
  8541. m_xml.scopedElement( "Warning" )
  8542. .writeText( it->message );
  8543. }
  8544. }
  8545. }
  8546. // Drop out if result was successful but we're not printing them.
  8547. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8548. return true;
  8549. // Print the expression if there is one.
  8550. if( result.hasExpression() ) {
  8551. m_xml.startElement( "Expression" )
  8552. .writeAttribute( "success", result.succeeded() )
  8553. .writeAttribute( "type", result.getTestMacroName() );
  8554. writeSourceInfo( result.getSourceInfo() );
  8555. m_xml.scopedElement( "Original" )
  8556. .writeText( result.getExpression() );
  8557. m_xml.scopedElement( "Expanded" )
  8558. .writeText( result.getExpandedExpression() );
  8559. }
  8560. // And... Print a result applicable to each result type.
  8561. switch( result.getResultType() ) {
  8562. case ResultWas::ThrewException:
  8563. m_xml.startElement( "Exception" );
  8564. writeSourceInfo( result.getSourceInfo() );
  8565. m_xml.writeText( result.getMessage() );
  8566. m_xml.endElement();
  8567. break;
  8568. case ResultWas::FatalErrorCondition:
  8569. m_xml.startElement( "FatalErrorCondition" );
  8570. writeSourceInfo( result.getSourceInfo() );
  8571. m_xml.writeText( result.getMessage() );
  8572. m_xml.endElement();
  8573. break;
  8574. case ResultWas::Info:
  8575. m_xml.scopedElement( "Info" )
  8576. .writeText( result.getMessage() );
  8577. break;
  8578. case ResultWas::Warning:
  8579. // Warning will already have been written
  8580. break;
  8581. case ResultWas::ExplicitFailure:
  8582. m_xml.startElement( "Failure" );
  8583. writeSourceInfo( result.getSourceInfo() );
  8584. m_xml.writeText( result.getMessage() );
  8585. m_xml.endElement();
  8586. break;
  8587. default:
  8588. break;
  8589. }
  8590. if( result.hasExpression() )
  8591. m_xml.endElement();
  8592. return true;
  8593. }
  8594. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8595. StreamingReporterBase::sectionEnded( sectionStats );
  8596. if( --m_sectionDepth > 0 ) {
  8597. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
  8598. e.writeAttribute( "successes", sectionStats.assertions.passed );
  8599. e.writeAttribute( "failures", sectionStats.assertions.failed );
  8600. e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
  8601. if ( m_config->showDurations() == ShowDurations::Always )
  8602. e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
  8603. m_xml.endElement();
  8604. }
  8605. }
  8606. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8607. StreamingReporterBase::testCaseEnded( testCaseStats );
  8608. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
  8609. e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
  8610. if ( m_config->showDurations() == ShowDurations::Always )
  8611. e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
  8612. if( !testCaseStats.stdOut.empty() )
  8613. m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false );
  8614. if( !testCaseStats.stdErr.empty() )
  8615. m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false );
  8616. m_xml.endElement();
  8617. }
  8618. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8619. StreamingReporterBase::testGroupEnded( testGroupStats );
  8620. // TODO: Check testGroupStats.aborting and act accordingly.
  8621. m_xml.scopedElement( "OverallResults" )
  8622. .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
  8623. .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
  8624. .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
  8625. m_xml.endElement();
  8626. }
  8627. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8628. StreamingReporterBase::testRunEnded( testRunStats );
  8629. m_xml.scopedElement( "OverallResults" )
  8630. .writeAttribute( "successes", testRunStats.totals.assertions.passed )
  8631. .writeAttribute( "failures", testRunStats.totals.assertions.failed )
  8632. .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
  8633. m_xml.endElement();
  8634. }
  8635. private:
  8636. Timer m_testCaseTimer;
  8637. XmlWriter m_xml;
  8638. int m_sectionDepth;
  8639. };
  8640. INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
  8641. } // end namespace Catch
  8642. // #included from: ../reporters/catch_reporter_junit.hpp
  8643. #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
  8644. #include <assert.h>
  8645. namespace Catch {
  8646. namespace {
  8647. std::string getCurrentTimestamp() {
  8648. // Beware, this is not reentrant because of backward compatibility issues
  8649. // Also, UTC only, again because of backward compatibility (%z is C++11)
  8650. time_t rawtime;
  8651. std::time(&rawtime);
  8652. const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z");
  8653. #ifdef _MSC_VER
  8654. std::tm timeInfo = {};
  8655. gmtime_s(&timeInfo, &rawtime);
  8656. #else
  8657. std::tm* timeInfo;
  8658. timeInfo = std::gmtime(&rawtime);
  8659. #endif
  8660. char timeStamp[timeStampSize];
  8661. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  8662. #ifdef _MSC_VER
  8663. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  8664. #else
  8665. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  8666. #endif
  8667. return std::string(timeStamp);
  8668. }
  8669. }
  8670. class JunitReporter : public CumulativeReporterBase {
  8671. public:
  8672. JunitReporter( ReporterConfig const& _config )
  8673. : CumulativeReporterBase( _config ),
  8674. xml( _config.stream() ),
  8675. unexpectedExceptions( 0 ),
  8676. m_okToFail( false )
  8677. {
  8678. m_reporterPrefs.shouldRedirectStdOut = true;
  8679. }
  8680. virtual ~JunitReporter() CATCH_OVERRIDE;
  8681. static std::string getDescription() {
  8682. return "Reports test results in an XML format that looks like Ant's junitreport target";
  8683. }
  8684. virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
  8685. virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
  8686. CumulativeReporterBase::testRunStarting( runInfo );
  8687. xml.startElement( "testsuites" );
  8688. }
  8689. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8690. suiteTimer.start();
  8691. stdOutForSuite.str("");
  8692. stdErrForSuite.str("");
  8693. unexpectedExceptions = 0;
  8694. CumulativeReporterBase::testGroupStarting( groupInfo );
  8695. }
  8696. virtual void testCaseStarting( TestCaseInfo const& testCaseInfo ) CATCH_OVERRIDE {
  8697. m_okToFail = testCaseInfo.okToFail();
  8698. }
  8699. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8700. if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail )
  8701. unexpectedExceptions++;
  8702. return CumulativeReporterBase::assertionEnded( assertionStats );
  8703. }
  8704. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8705. stdOutForSuite << testCaseStats.stdOut;
  8706. stdErrForSuite << testCaseStats.stdErr;
  8707. CumulativeReporterBase::testCaseEnded( testCaseStats );
  8708. }
  8709. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8710. double suiteTime = suiteTimer.getElapsedSeconds();
  8711. CumulativeReporterBase::testGroupEnded( testGroupStats );
  8712. writeGroup( *m_testGroups.back(), suiteTime );
  8713. }
  8714. virtual void testRunEndedCumulative() CATCH_OVERRIDE {
  8715. xml.endElement();
  8716. }
  8717. void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
  8718. XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
  8719. TestGroupStats const& stats = groupNode.value;
  8720. xml.writeAttribute( "name", stats.groupInfo.name );
  8721. xml.writeAttribute( "errors", unexpectedExceptions );
  8722. xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
  8723. xml.writeAttribute( "tests", stats.totals.assertions.total() );
  8724. xml.writeAttribute( "hostname", "tbd" ); // !TBD
  8725. if( m_config->showDurations() == ShowDurations::Never )
  8726. xml.writeAttribute( "time", "" );
  8727. else
  8728. xml.writeAttribute( "time", suiteTime );
  8729. xml.writeAttribute( "timestamp", getCurrentTimestamp() );
  8730. // Write test cases
  8731. for( TestGroupNode::ChildNodes::const_iterator
  8732. it = groupNode.children.begin(), itEnd = groupNode.children.end();
  8733. it != itEnd;
  8734. ++it )
  8735. writeTestCase( **it );
  8736. xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
  8737. xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
  8738. }
  8739. void writeTestCase( TestCaseNode const& testCaseNode ) {
  8740. TestCaseStats const& stats = testCaseNode.value;
  8741. // All test cases have exactly one section - which represents the
  8742. // test case itself. That section may have 0-n nested sections
  8743. assert( testCaseNode.children.size() == 1 );
  8744. SectionNode const& rootSection = *testCaseNode.children.front();
  8745. std::string className = stats.testInfo.className;
  8746. if( className.empty() ) {
  8747. if( rootSection.childSections.empty() )
  8748. className = "global";
  8749. }
  8750. writeSection( className, "", rootSection );
  8751. }
  8752. void writeSection( std::string const& className,
  8753. std::string const& rootName,
  8754. SectionNode const& sectionNode ) {
  8755. std::string name = trim( sectionNode.stats.sectionInfo.name );
  8756. if( !rootName.empty() )
  8757. name = rootName + '/' + name;
  8758. if( !sectionNode.assertions.empty() ||
  8759. !sectionNode.stdOut.empty() ||
  8760. !sectionNode.stdErr.empty() ) {
  8761. XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
  8762. if( className.empty() ) {
  8763. xml.writeAttribute( "classname", name );
  8764. xml.writeAttribute( "name", "root" );
  8765. }
  8766. else {
  8767. xml.writeAttribute( "classname", className );
  8768. xml.writeAttribute( "name", name );
  8769. }
  8770. xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
  8771. writeAssertions( sectionNode );
  8772. if( !sectionNode.stdOut.empty() )
  8773. xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
  8774. if( !sectionNode.stdErr.empty() )
  8775. xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
  8776. }
  8777. for( SectionNode::ChildSections::const_iterator
  8778. it = sectionNode.childSections.begin(),
  8779. itEnd = sectionNode.childSections.end();
  8780. it != itEnd;
  8781. ++it )
  8782. if( className.empty() )
  8783. writeSection( name, "", **it );
  8784. else
  8785. writeSection( className, name, **it );
  8786. }
  8787. void writeAssertions( SectionNode const& sectionNode ) {
  8788. for( SectionNode::Assertions::const_iterator
  8789. it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
  8790. it != itEnd;
  8791. ++it )
  8792. writeAssertion( *it );
  8793. }
  8794. void writeAssertion( AssertionStats const& stats ) {
  8795. AssertionResult const& result = stats.assertionResult;
  8796. if( !result.isOk() ) {
  8797. std::string elementName;
  8798. switch( result.getResultType() ) {
  8799. case ResultWas::ThrewException:
  8800. case ResultWas::FatalErrorCondition:
  8801. elementName = "error";
  8802. break;
  8803. case ResultWas::ExplicitFailure:
  8804. elementName = "failure";
  8805. break;
  8806. case ResultWas::ExpressionFailed:
  8807. elementName = "failure";
  8808. break;
  8809. case ResultWas::DidntThrowException:
  8810. elementName = "failure";
  8811. break;
  8812. // We should never see these here:
  8813. case ResultWas::Info:
  8814. case ResultWas::Warning:
  8815. case ResultWas::Ok:
  8816. case ResultWas::Unknown:
  8817. case ResultWas::FailureBit:
  8818. case ResultWas::Exception:
  8819. elementName = "internalError";
  8820. break;
  8821. }
  8822. XmlWriter::ScopedElement e = xml.scopedElement( elementName );
  8823. xml.writeAttribute( "message", result.getExpandedExpression() );
  8824. xml.writeAttribute( "type", result.getTestMacroName() );
  8825. std::ostringstream oss;
  8826. if( !result.getMessage().empty() )
  8827. oss << result.getMessage() << '\n';
  8828. for( std::vector<MessageInfo>::const_iterator
  8829. it = stats.infoMessages.begin(),
  8830. itEnd = stats.infoMessages.end();
  8831. it != itEnd;
  8832. ++it )
  8833. if( it->type == ResultWas::Info )
  8834. oss << it->message << '\n';
  8835. oss << "at " << result.getSourceInfo();
  8836. xml.writeText( oss.str(), false );
  8837. }
  8838. }
  8839. XmlWriter xml;
  8840. Timer suiteTimer;
  8841. std::ostringstream stdOutForSuite;
  8842. std::ostringstream stdErrForSuite;
  8843. unsigned int unexpectedExceptions;
  8844. bool m_okToFail;
  8845. };
  8846. INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
  8847. } // end namespace Catch
  8848. // #included from: ../reporters/catch_reporter_console.hpp
  8849. #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8850. #include <cassert>
  8851. #include <cfloat>
  8852. #include <cstdio>
  8853. namespace Catch {
  8854. struct ConsoleReporter : StreamingReporterBase {
  8855. ConsoleReporter( ReporterConfig const& _config )
  8856. : StreamingReporterBase( _config ),
  8857. m_headerPrinted( false )
  8858. {}
  8859. virtual ~ConsoleReporter() CATCH_OVERRIDE;
  8860. static std::string getDescription() {
  8861. return "Reports test results as plain lines of text";
  8862. }
  8863. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  8864. stream << "No test cases matched '" << spec << '\'' << std::endl;
  8865. }
  8866. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
  8867. }
  8868. virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
  8869. AssertionResult const& result = _assertionStats.assertionResult;
  8870. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8871. // Drop out if result was successful but we're not printing them.
  8872. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8873. return false;
  8874. lazyPrint();
  8875. AssertionPrinter printer( stream, _assertionStats, includeResults );
  8876. printer.print();
  8877. stream << std::endl;
  8878. return true;
  8879. }
  8880. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8881. m_headerPrinted = false;
  8882. StreamingReporterBase::sectionStarting( _sectionInfo );
  8883. }
  8884. virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
  8885. if( _sectionStats.missingAssertions ) {
  8886. lazyPrint();
  8887. Colour colour( Colour::ResultError );
  8888. if( m_sectionStack.size() > 1 )
  8889. stream << "\nNo assertions in section";
  8890. else
  8891. stream << "\nNo assertions in test case";
  8892. stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
  8893. }
  8894. if( m_config->showDurations() == ShowDurations::Always ) {
  8895. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  8896. }
  8897. if( m_headerPrinted ) {
  8898. m_headerPrinted = false;
  8899. }
  8900. StreamingReporterBase::sectionEnded( _sectionStats );
  8901. }
  8902. virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
  8903. StreamingReporterBase::testCaseEnded( _testCaseStats );
  8904. m_headerPrinted = false;
  8905. }
  8906. virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
  8907. if( currentGroupInfo.used ) {
  8908. printSummaryDivider();
  8909. stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
  8910. printTotals( _testGroupStats.totals );
  8911. stream << '\n' << std::endl;
  8912. }
  8913. StreamingReporterBase::testGroupEnded( _testGroupStats );
  8914. }
  8915. virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
  8916. printTotalsDivider( _testRunStats.totals );
  8917. printTotals( _testRunStats.totals );
  8918. stream << std::endl;
  8919. StreamingReporterBase::testRunEnded( _testRunStats );
  8920. }
  8921. private:
  8922. class AssertionPrinter {
  8923. void operator= ( AssertionPrinter const& );
  8924. public:
  8925. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  8926. : stream( _stream ),
  8927. stats( _stats ),
  8928. result( _stats.assertionResult ),
  8929. colour( Colour::None ),
  8930. message( result.getMessage() ),
  8931. messages( _stats.infoMessages ),
  8932. printInfoMessages( _printInfoMessages )
  8933. {
  8934. switch( result.getResultType() ) {
  8935. case ResultWas::Ok:
  8936. colour = Colour::Success;
  8937. passOrFail = "PASSED";
  8938. //if( result.hasMessage() )
  8939. if( _stats.infoMessages.size() == 1 )
  8940. messageLabel = "with message";
  8941. if( _stats.infoMessages.size() > 1 )
  8942. messageLabel = "with messages";
  8943. break;
  8944. case ResultWas::ExpressionFailed:
  8945. if( result.isOk() ) {
  8946. colour = Colour::Success;
  8947. passOrFail = "FAILED - but was ok";
  8948. }
  8949. else {
  8950. colour = Colour::Error;
  8951. passOrFail = "FAILED";
  8952. }
  8953. if( _stats.infoMessages.size() == 1 )
  8954. messageLabel = "with message";
  8955. if( _stats.infoMessages.size() > 1 )
  8956. messageLabel = "with messages";
  8957. break;
  8958. case ResultWas::ThrewException:
  8959. colour = Colour::Error;
  8960. passOrFail = "FAILED";
  8961. messageLabel = "due to unexpected exception with ";
  8962. if (_stats.infoMessages.size() == 1)
  8963. messageLabel += "message";
  8964. if (_stats.infoMessages.size() > 1)
  8965. messageLabel += "messages";
  8966. break;
  8967. case ResultWas::FatalErrorCondition:
  8968. colour = Colour::Error;
  8969. passOrFail = "FAILED";
  8970. messageLabel = "due to a fatal error condition";
  8971. break;
  8972. case ResultWas::DidntThrowException:
  8973. colour = Colour::Error;
  8974. passOrFail = "FAILED";
  8975. messageLabel = "because no exception was thrown where one was expected";
  8976. break;
  8977. case ResultWas::Info:
  8978. messageLabel = "info";
  8979. break;
  8980. case ResultWas::Warning:
  8981. messageLabel = "warning";
  8982. break;
  8983. case ResultWas::ExplicitFailure:
  8984. passOrFail = "FAILED";
  8985. colour = Colour::Error;
  8986. if( _stats.infoMessages.size() == 1 )
  8987. messageLabel = "explicitly with message";
  8988. if( _stats.infoMessages.size() > 1 )
  8989. messageLabel = "explicitly with messages";
  8990. break;
  8991. // These cases are here to prevent compiler warnings
  8992. case ResultWas::Unknown:
  8993. case ResultWas::FailureBit:
  8994. case ResultWas::Exception:
  8995. passOrFail = "** internal error **";
  8996. colour = Colour::Error;
  8997. break;
  8998. }
  8999. }
  9000. void print() const {
  9001. printSourceInfo();
  9002. if( stats.totals.assertions.total() > 0 ) {
  9003. if( result.isOk() )
  9004. stream << '\n';
  9005. printResultType();
  9006. printOriginalExpression();
  9007. printReconstructedExpression();
  9008. }
  9009. else {
  9010. stream << '\n';
  9011. }
  9012. printMessage();
  9013. }
  9014. private:
  9015. void printResultType() const {
  9016. if( !passOrFail.empty() ) {
  9017. Colour colourGuard( colour );
  9018. stream << passOrFail << ":\n";
  9019. }
  9020. }
  9021. void printOriginalExpression() const {
  9022. if( result.hasExpression() ) {
  9023. Colour colourGuard( Colour::OriginalExpression );
  9024. stream << " ";
  9025. stream << result.getExpressionInMacro();
  9026. stream << '\n';
  9027. }
  9028. }
  9029. void printReconstructedExpression() const {
  9030. if( result.hasExpandedExpression() ) {
  9031. stream << "with expansion:\n";
  9032. Colour colourGuard( Colour::ReconstructedExpression );
  9033. stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n';
  9034. }
  9035. }
  9036. void printMessage() const {
  9037. if( !messageLabel.empty() )
  9038. stream << messageLabel << ':' << '\n';
  9039. for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
  9040. it != itEnd;
  9041. ++it ) {
  9042. // If this assertion is a warning ignore any INFO messages
  9043. if( printInfoMessages || it->type != ResultWas::Info )
  9044. stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
  9045. }
  9046. }
  9047. void printSourceInfo() const {
  9048. Colour colourGuard( Colour::FileName );
  9049. stream << result.getSourceInfo() << ": ";
  9050. }
  9051. std::ostream& stream;
  9052. AssertionStats const& stats;
  9053. AssertionResult const& result;
  9054. Colour::Code colour;
  9055. std::string passOrFail;
  9056. std::string messageLabel;
  9057. std::string message;
  9058. std::vector<MessageInfo> messages;
  9059. bool printInfoMessages;
  9060. };
  9061. void lazyPrint() {
  9062. if( !currentTestRunInfo.used )
  9063. lazyPrintRunInfo();
  9064. if( !currentGroupInfo.used )
  9065. lazyPrintGroupInfo();
  9066. if( !m_headerPrinted ) {
  9067. printTestCaseAndSectionHeader();
  9068. m_headerPrinted = true;
  9069. }
  9070. }
  9071. void lazyPrintRunInfo() {
  9072. stream << '\n' << getLineOfChars<'~'>() << '\n';
  9073. Colour colour( Colour::SecondaryText );
  9074. stream << currentTestRunInfo->name
  9075. << " is a Catch v" << libraryVersion() << " host application.\n"
  9076. << "Run with -? for options\n\n";
  9077. if( m_config->rngSeed() != 0 )
  9078. stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
  9079. currentTestRunInfo.used = true;
  9080. }
  9081. void lazyPrintGroupInfo() {
  9082. if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
  9083. printClosedHeader( "Group: " + currentGroupInfo->name );
  9084. currentGroupInfo.used = true;
  9085. }
  9086. }
  9087. void printTestCaseAndSectionHeader() {
  9088. assert( !m_sectionStack.empty() );
  9089. printOpenHeader( currentTestCaseInfo->name );
  9090. if( m_sectionStack.size() > 1 ) {
  9091. Colour colourGuard( Colour::Headers );
  9092. std::vector<SectionInfo>::const_iterator
  9093. it = m_sectionStack.begin()+1, // Skip first section (test case)
  9094. itEnd = m_sectionStack.end();
  9095. for( ; it != itEnd; ++it )
  9096. printHeaderString( it->name, 2 );
  9097. }
  9098. SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
  9099. if( !lineInfo.empty() ){
  9100. stream << getLineOfChars<'-'>() << '\n';
  9101. Colour colourGuard( Colour::FileName );
  9102. stream << lineInfo << '\n';
  9103. }
  9104. stream << getLineOfChars<'.'>() << '\n' << std::endl;
  9105. }
  9106. void printClosedHeader( std::string const& _name ) {
  9107. printOpenHeader( _name );
  9108. stream << getLineOfChars<'.'>() << '\n';
  9109. }
  9110. void printOpenHeader( std::string const& _name ) {
  9111. stream << getLineOfChars<'-'>() << '\n';
  9112. {
  9113. Colour colourGuard( Colour::Headers );
  9114. printHeaderString( _name );
  9115. }
  9116. }
  9117. // if string has a : in first line will set indent to follow it on
  9118. // subsequent lines
  9119. void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
  9120. std::size_t i = _string.find( ": " );
  9121. if( i != std::string::npos )
  9122. i+=2;
  9123. else
  9124. i = 0;
  9125. stream << Text( _string, TextAttributes()
  9126. .setIndent( indent+i)
  9127. .setInitialIndent( indent ) ) << '\n';
  9128. }
  9129. struct SummaryColumn {
  9130. SummaryColumn( std::string const& _label, Colour::Code _colour )
  9131. : label( _label ),
  9132. colour( _colour )
  9133. {}
  9134. SummaryColumn addRow( std::size_t count ) {
  9135. std::ostringstream oss;
  9136. oss << count;
  9137. std::string row = oss.str();
  9138. for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
  9139. while( it->size() < row.size() )
  9140. *it = ' ' + *it;
  9141. while( it->size() > row.size() )
  9142. row = ' ' + row;
  9143. }
  9144. rows.push_back( row );
  9145. return *this;
  9146. }
  9147. std::string label;
  9148. Colour::Code colour;
  9149. std::vector<std::string> rows;
  9150. };
  9151. void printTotals( Totals const& totals ) {
  9152. if( totals.testCases.total() == 0 ) {
  9153. stream << Colour( Colour::Warning ) << "No tests ran\n";
  9154. }
  9155. else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
  9156. stream << Colour( Colour::ResultSuccess ) << "All tests passed";
  9157. stream << " ("
  9158. << pluralise( totals.assertions.passed, "assertion" ) << " in "
  9159. << pluralise( totals.testCases.passed, "test case" ) << ')'
  9160. << '\n';
  9161. }
  9162. else {
  9163. std::vector<SummaryColumn> columns;
  9164. columns.push_back( SummaryColumn( "", Colour::None )
  9165. .addRow( totals.testCases.total() )
  9166. .addRow( totals.assertions.total() ) );
  9167. columns.push_back( SummaryColumn( "passed", Colour::Success )
  9168. .addRow( totals.testCases.passed )
  9169. .addRow( totals.assertions.passed ) );
  9170. columns.push_back( SummaryColumn( "failed", Colour::ResultError )
  9171. .addRow( totals.testCases.failed )
  9172. .addRow( totals.assertions.failed ) );
  9173. columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
  9174. .addRow( totals.testCases.failedButOk )
  9175. .addRow( totals.assertions.failedButOk ) );
  9176. printSummaryRow( "test cases", columns, 0 );
  9177. printSummaryRow( "assertions", columns, 1 );
  9178. }
  9179. }
  9180. void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
  9181. for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
  9182. std::string value = it->rows[row];
  9183. if( it->label.empty() ) {
  9184. stream << label << ": ";
  9185. if( value != "0" )
  9186. stream << value;
  9187. else
  9188. stream << Colour( Colour::Warning ) << "- none -";
  9189. }
  9190. else if( value != "0" ) {
  9191. stream << Colour( Colour::LightGrey ) << " | ";
  9192. stream << Colour( it->colour )
  9193. << value << ' ' << it->label;
  9194. }
  9195. }
  9196. stream << '\n';
  9197. }
  9198. static std::size_t makeRatio( std::size_t number, std::size_t total ) {
  9199. std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
  9200. return ( ratio == 0 && number > 0 ) ? 1 : ratio;
  9201. }
  9202. static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
  9203. if( i > j && i > k )
  9204. return i;
  9205. else if( j > k )
  9206. return j;
  9207. else
  9208. return k;
  9209. }
  9210. void printTotalsDivider( Totals const& totals ) {
  9211. if( totals.testCases.total() > 0 ) {
  9212. std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
  9213. std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
  9214. std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
  9215. while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9216. findMax( failedRatio, failedButOkRatio, passedRatio )++;
  9217. while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9218. findMax( failedRatio, failedButOkRatio, passedRatio )--;
  9219. stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
  9220. stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
  9221. if( totals.testCases.allPassed() )
  9222. stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
  9223. else
  9224. stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
  9225. }
  9226. else {
  9227. stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
  9228. }
  9229. stream << '\n';
  9230. }
  9231. void printSummaryDivider() {
  9232. stream << getLineOfChars<'-'>() << '\n';
  9233. }
  9234. private:
  9235. bool m_headerPrinted;
  9236. };
  9237. INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
  9238. } // end namespace Catch
  9239. // #included from: ../reporters/catch_reporter_compact.hpp
  9240. #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
  9241. namespace Catch {
  9242. struct CompactReporter : StreamingReporterBase {
  9243. CompactReporter( ReporterConfig const& _config )
  9244. : StreamingReporterBase( _config )
  9245. {}
  9246. virtual ~CompactReporter();
  9247. static std::string getDescription() {
  9248. return "Reports test results on a single line, suitable for IDEs";
  9249. }
  9250. virtual ReporterPreferences getPreferences() const {
  9251. ReporterPreferences prefs;
  9252. prefs.shouldRedirectStdOut = false;
  9253. return prefs;
  9254. }
  9255. virtual void noMatchingTestCases( std::string const& spec ) {
  9256. stream << "No test cases matched '" << spec << '\'' << std::endl;
  9257. }
  9258. virtual void assertionStarting( AssertionInfo const& ) {}
  9259. virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
  9260. AssertionResult const& result = _assertionStats.assertionResult;
  9261. bool printInfoMessages = true;
  9262. // Drop out if result was successful and we're not printing those
  9263. if( !m_config->includeSuccessfulResults() && result.isOk() ) {
  9264. if( result.getResultType() != ResultWas::Warning )
  9265. return false;
  9266. printInfoMessages = false;
  9267. }
  9268. AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
  9269. printer.print();
  9270. stream << std::endl;
  9271. return true;
  9272. }
  9273. virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE {
  9274. if (m_config->showDurations() == ShowDurations::Always) {
  9275. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  9276. }
  9277. }
  9278. virtual void testRunEnded( TestRunStats const& _testRunStats ) {
  9279. printTotals( _testRunStats.totals );
  9280. stream << '\n' << std::endl;
  9281. StreamingReporterBase::testRunEnded( _testRunStats );
  9282. }
  9283. private:
  9284. class AssertionPrinter {
  9285. void operator= ( AssertionPrinter const& );
  9286. public:
  9287. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  9288. : stream( _stream )
  9289. , stats( _stats )
  9290. , result( _stats.assertionResult )
  9291. , messages( _stats.infoMessages )
  9292. , itMessage( _stats.infoMessages.begin() )
  9293. , printInfoMessages( _printInfoMessages )
  9294. {}
  9295. void print() {
  9296. printSourceInfo();
  9297. itMessage = messages.begin();
  9298. switch( result.getResultType() ) {
  9299. case ResultWas::Ok:
  9300. printResultType( Colour::ResultSuccess, passedString() );
  9301. printOriginalExpression();
  9302. printReconstructedExpression();
  9303. if ( ! result.hasExpression() )
  9304. printRemainingMessages( Colour::None );
  9305. else
  9306. printRemainingMessages();
  9307. break;
  9308. case ResultWas::ExpressionFailed:
  9309. if( result.isOk() )
  9310. printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
  9311. else
  9312. printResultType( Colour::Error, failedString() );
  9313. printOriginalExpression();
  9314. printReconstructedExpression();
  9315. printRemainingMessages();
  9316. break;
  9317. case ResultWas::ThrewException:
  9318. printResultType( Colour::Error, failedString() );
  9319. printIssue( "unexpected exception with message:" );
  9320. printMessage();
  9321. printExpressionWas();
  9322. printRemainingMessages();
  9323. break;
  9324. case ResultWas::FatalErrorCondition:
  9325. printResultType( Colour::Error, failedString() );
  9326. printIssue( "fatal error condition with message:" );
  9327. printMessage();
  9328. printExpressionWas();
  9329. printRemainingMessages();
  9330. break;
  9331. case ResultWas::DidntThrowException:
  9332. printResultType( Colour::Error, failedString() );
  9333. printIssue( "expected exception, got none" );
  9334. printExpressionWas();
  9335. printRemainingMessages();
  9336. break;
  9337. case ResultWas::Info:
  9338. printResultType( Colour::None, "info" );
  9339. printMessage();
  9340. printRemainingMessages();
  9341. break;
  9342. case ResultWas::Warning:
  9343. printResultType( Colour::None, "warning" );
  9344. printMessage();
  9345. printRemainingMessages();
  9346. break;
  9347. case ResultWas::ExplicitFailure:
  9348. printResultType( Colour::Error, failedString() );
  9349. printIssue( "explicitly" );
  9350. printRemainingMessages( Colour::None );
  9351. break;
  9352. // These cases are here to prevent compiler warnings
  9353. case ResultWas::Unknown:
  9354. case ResultWas::FailureBit:
  9355. case ResultWas::Exception:
  9356. printResultType( Colour::Error, "** internal error **" );
  9357. break;
  9358. }
  9359. }
  9360. private:
  9361. // Colour::LightGrey
  9362. static Colour::Code dimColour() { return Colour::FileName; }
  9363. #ifdef CATCH_PLATFORM_MAC
  9364. static const char* failedString() { return "FAILED"; }
  9365. static const char* passedString() { return "PASSED"; }
  9366. #else
  9367. static const char* failedString() { return "failed"; }
  9368. static const char* passedString() { return "passed"; }
  9369. #endif
  9370. void printSourceInfo() const {
  9371. Colour colourGuard( Colour::FileName );
  9372. stream << result.getSourceInfo() << ':';
  9373. }
  9374. void printResultType( Colour::Code colour, std::string const& passOrFail ) const {
  9375. if( !passOrFail.empty() ) {
  9376. {
  9377. Colour colourGuard( colour );
  9378. stream << ' ' << passOrFail;
  9379. }
  9380. stream << ':';
  9381. }
  9382. }
  9383. void printIssue( std::string const& issue ) const {
  9384. stream << ' ' << issue;
  9385. }
  9386. void printExpressionWas() {
  9387. if( result.hasExpression() ) {
  9388. stream << ';';
  9389. {
  9390. Colour colour( dimColour() );
  9391. stream << " expression was:";
  9392. }
  9393. printOriginalExpression();
  9394. }
  9395. }
  9396. void printOriginalExpression() const {
  9397. if( result.hasExpression() ) {
  9398. stream << ' ' << result.getExpression();
  9399. }
  9400. }
  9401. void printReconstructedExpression() const {
  9402. if( result.hasExpandedExpression() ) {
  9403. {
  9404. Colour colour( dimColour() );
  9405. stream << " for: ";
  9406. }
  9407. stream << result.getExpandedExpression();
  9408. }
  9409. }
  9410. void printMessage() {
  9411. if ( itMessage != messages.end() ) {
  9412. stream << " '" << itMessage->message << '\'';
  9413. ++itMessage;
  9414. }
  9415. }
  9416. void printRemainingMessages( Colour::Code colour = dimColour() ) {
  9417. if ( itMessage == messages.end() )
  9418. return;
  9419. // using messages.end() directly yields compilation error:
  9420. std::vector<MessageInfo>::const_iterator itEnd = messages.end();
  9421. const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
  9422. {
  9423. Colour colourGuard( colour );
  9424. stream << " with " << pluralise( N, "message" ) << ':';
  9425. }
  9426. for(; itMessage != itEnd; ) {
  9427. // If this assertion is a warning ignore any INFO messages
  9428. if( printInfoMessages || itMessage->type != ResultWas::Info ) {
  9429. stream << " '" << itMessage->message << '\'';
  9430. if ( ++itMessage != itEnd ) {
  9431. Colour colourGuard( dimColour() );
  9432. stream << " and";
  9433. }
  9434. }
  9435. }
  9436. }
  9437. private:
  9438. std::ostream& stream;
  9439. AssertionStats const& stats;
  9440. AssertionResult const& result;
  9441. std::vector<MessageInfo> messages;
  9442. std::vector<MessageInfo>::const_iterator itMessage;
  9443. bool printInfoMessages;
  9444. };
  9445. // Colour, message variants:
  9446. // - white: No tests ran.
  9447. // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
  9448. // - white: Passed [both/all] N test cases (no assertions).
  9449. // - red: Failed N tests cases, failed M assertions.
  9450. // - green: Passed [both/all] N tests cases with M assertions.
  9451. std::string bothOrAll( std::size_t count ) const {
  9452. return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
  9453. }
  9454. void printTotals( const Totals& totals ) const {
  9455. if( totals.testCases.total() == 0 ) {
  9456. stream << "No tests ran.";
  9457. }
  9458. else if( totals.testCases.failed == totals.testCases.total() ) {
  9459. Colour colour( Colour::ResultError );
  9460. const std::string qualify_assertions_failed =
  9461. totals.assertions.failed == totals.assertions.total() ?
  9462. bothOrAll( totals.assertions.failed ) : std::string();
  9463. stream <<
  9464. "Failed " << bothOrAll( totals.testCases.failed )
  9465. << pluralise( totals.testCases.failed, "test case" ) << ", "
  9466. "failed " << qualify_assertions_failed <<
  9467. pluralise( totals.assertions.failed, "assertion" ) << '.';
  9468. }
  9469. else if( totals.assertions.total() == 0 ) {
  9470. stream <<
  9471. "Passed " << bothOrAll( totals.testCases.total() )
  9472. << pluralise( totals.testCases.total(), "test case" )
  9473. << " (no assertions).";
  9474. }
  9475. else if( totals.assertions.failed ) {
  9476. Colour colour( Colour::ResultError );
  9477. stream <<
  9478. "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
  9479. "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
  9480. }
  9481. else {
  9482. Colour colour( Colour::ResultSuccess );
  9483. stream <<
  9484. "Passed " << bothOrAll( totals.testCases.passed )
  9485. << pluralise( totals.testCases.passed, "test case" ) <<
  9486. " with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
  9487. }
  9488. }
  9489. };
  9490. INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
  9491. } // end namespace Catch
  9492. namespace Catch {
  9493. // These are all here to avoid warnings about not having any out of line
  9494. // virtual methods
  9495. NonCopyable::~NonCopyable() {}
  9496. IShared::~IShared() {}
  9497. IStream::~IStream() CATCH_NOEXCEPT {}
  9498. FileStream::~FileStream() CATCH_NOEXCEPT {}
  9499. CoutStream::~CoutStream() CATCH_NOEXCEPT {}
  9500. DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
  9501. StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
  9502. IContext::~IContext() {}
  9503. IResultCapture::~IResultCapture() {}
  9504. ITestCase::~ITestCase() {}
  9505. ITestCaseRegistry::~ITestCaseRegistry() {}
  9506. IRegistryHub::~IRegistryHub() {}
  9507. IMutableRegistryHub::~IMutableRegistryHub() {}
  9508. IExceptionTranslator::~IExceptionTranslator() {}
  9509. IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
  9510. IReporter::~IReporter() {}
  9511. IReporterFactory::~IReporterFactory() {}
  9512. IReporterRegistry::~IReporterRegistry() {}
  9513. IStreamingReporter::~IStreamingReporter() {}
  9514. AssertionStats::~AssertionStats() {}
  9515. SectionStats::~SectionStats() {}
  9516. TestCaseStats::~TestCaseStats() {}
  9517. TestGroupStats::~TestGroupStats() {}
  9518. TestRunStats::~TestRunStats() {}
  9519. CumulativeReporterBase::SectionNode::~SectionNode() {}
  9520. CumulativeReporterBase::~CumulativeReporterBase() {}
  9521. StreamingReporterBase::~StreamingReporterBase() {}
  9522. ConsoleReporter::~ConsoleReporter() {}
  9523. CompactReporter::~CompactReporter() {}
  9524. IRunner::~IRunner() {}
  9525. IMutableContext::~IMutableContext() {}
  9526. IConfig::~IConfig() {}
  9527. XmlReporter::~XmlReporter() {}
  9528. JunitReporter::~JunitReporter() {}
  9529. TestRegistry::~TestRegistry() {}
  9530. FreeFunctionTestCase::~FreeFunctionTestCase() {}
  9531. IGeneratorInfo::~IGeneratorInfo() {}
  9532. IGeneratorsForTest::~IGeneratorsForTest() {}
  9533. WildcardPattern::~WildcardPattern() {}
  9534. TestSpec::Pattern::~Pattern() {}
  9535. TestSpec::NamePattern::~NamePattern() {}
  9536. TestSpec::TagPattern::~TagPattern() {}
  9537. TestSpec::ExcludedPattern::~ExcludedPattern() {}
  9538. Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {}
  9539. void Config::dummy() {}
  9540. namespace TestCaseTracking {
  9541. ITracker::~ITracker() {}
  9542. TrackerBase::~TrackerBase() {}
  9543. SectionTracker::~SectionTracker() {}
  9544. IndexTracker::~IndexTracker() {}
  9545. }
  9546. }
  9547. #ifdef __clang__
  9548. #pragma clang diagnostic pop
  9549. #endif
  9550. #endif
  9551. #ifdef CATCH_CONFIG_MAIN
  9552. // #included from: internal/catch_default_main.hpp
  9553. #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
  9554. #ifndef __OBJC__
  9555. #if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
  9556. // Standard C/C++ Win32 Unicode wmain entry point
  9557. extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
  9558. #else
  9559. // Standard C/C++ main entry point
  9560. int main (int argc, char * argv[]) {
  9561. #endif
  9562. int result = Catch::Session().run( argc, argv );
  9563. return ( result < 0xff ? result : 0xff );
  9564. }
  9565. #else // __OBJC__
  9566. // Objective-C entry point
  9567. int main (int argc, char * const argv[]) {
  9568. #if !CATCH_ARC_ENABLED
  9569. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9570. #endif
  9571. Catch::registerTestMethods();
  9572. int result = Catch::Session().run( argc, (char* const*)argv );
  9573. #if !CATCH_ARC_ENABLED
  9574. [pool drain];
  9575. #endif
  9576. return ( result < 0xff ? result : 0xff );
  9577. }
  9578. #endif // __OBJC__
  9579. #endif
  9580. #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
  9581. # undef CLARA_CONFIG_MAIN
  9582. #endif
  9583. //////
  9584. // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
  9585. #ifdef CATCH_CONFIG_PREFIX_ALL
  9586. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9587. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9588. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9589. #else
  9590. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9591. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9592. #endif
  9593. #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9594. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9595. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9596. #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9597. #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9598. #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9599. #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9600. #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9601. #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9602. #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9603. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9604. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9605. #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9606. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9607. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9608. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9609. #else
  9610. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9611. #endif
  9612. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9613. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9614. #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9615. #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9616. #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9617. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9618. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9619. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9620. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9621. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9622. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9623. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9624. #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9625. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9626. #else
  9627. #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9628. #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9629. #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9630. #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
  9631. #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9632. #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9633. #define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9634. #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9635. #endif
  9636. #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9637. #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9638. #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9639. #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9640. // "BDD-style" convenience wrappers
  9641. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9642. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  9643. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9644. #else
  9645. #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
  9646. #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9647. #endif
  9648. #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
  9649. #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
  9650. #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9651. #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
  9652. #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9653. // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
  9654. #else
  9655. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9656. #define REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9657. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9658. #else
  9659. #define REQUIRE( expr ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9660. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9661. #endif
  9662. #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9663. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9664. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9665. #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9666. #define CHECK( expr ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9667. #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9668. #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9669. #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9670. #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9671. #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9672. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9673. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9674. #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9675. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9676. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9677. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9678. #else
  9679. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9680. #endif
  9681. #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9682. #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9683. #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9684. #define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9685. #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9686. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9687. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9688. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9689. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9690. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9691. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9692. #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9693. #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9694. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9695. #else
  9696. #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9697. #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9698. #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9699. #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
  9700. #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9701. #define FAIL( msg ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9702. #define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9703. #define SUCCEED( msg ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9704. #endif
  9705. #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9706. #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9707. #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9708. #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9709. #endif
  9710. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  9711. // "BDD-style" convenience wrappers
  9712. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9713. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  9714. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9715. #else
  9716. #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
  9717. #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9718. #endif
  9719. #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
  9720. #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
  9721. #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
  9722. #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
  9723. #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
  9724. using Catch::Detail::Approx;
  9725. // #included from: internal/catch_reenable_warnings.h
  9726. #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
  9727. #ifdef __clang__
  9728. # ifdef __ICC // icpc defines the __clang__ macro
  9729. # pragma warning(pop)
  9730. # else
  9731. # pragma clang diagnostic pop
  9732. # endif
  9733. #elif defined __GNUC__
  9734. # pragma GCC diagnostic pop
  9735. #endif
  9736. #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED