catch.hpp 399 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283
  1. /*
  2. * Catch v1.8.1
  3. * Generated: 2017-03-01 16:04:19.016511
  4. * ----------------------------------------------------------
  5. * This file has been merged from multiple headers. Please don't edit it directly
  6. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
  7. *
  8. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. */
  11. #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  12. #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  13. #define TWOBLUECUBES_CATCH_HPP_INCLUDED
  14. #ifdef __clang__
  15. # pragma clang system_header
  16. #elif defined __GNUC__
  17. # pragma GCC system_header
  18. #endif
  19. // #included from: internal/catch_suppress_warnings.h
  20. #ifdef __clang__
  21. # ifdef __ICC // icpc defines the __clang__ macro
  22. # pragma warning(push)
  23. # pragma warning(disable: 161 1682)
  24. # else // __ICC
  25. # pragma clang diagnostic ignored "-Wglobal-constructors"
  26. # pragma clang diagnostic ignored "-Wvariadic-macros"
  27. # pragma clang diagnostic ignored "-Wc99-extensions"
  28. # pragma clang diagnostic ignored "-Wunused-variable"
  29. # pragma clang diagnostic push
  30. # pragma clang diagnostic ignored "-Wpadded"
  31. # pragma clang diagnostic ignored "-Wc++98-compat"
  32. # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
  33. # pragma clang diagnostic ignored "-Wswitch-enum"
  34. # pragma clang diagnostic ignored "-Wcovered-switch-default"
  35. # endif
  36. #elif defined __GNUC__
  37. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  38. # pragma GCC diagnostic ignored "-Wunused-variable"
  39. // For newer version we can use __Pragma to disable the warnings locally
  40. # if __GNUC__ == 4 && __GNUC_MINOR__ >= 4 && __GNUC_MINOR__ <= 7
  41. # pragma GCC diagnostic ignored "-Wparentheses"
  42. # endif
  43. # pragma GCC diagnostic push
  44. # pragma GCC diagnostic ignored "-Wpadded"
  45. #endif
  46. #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
  47. # define CATCH_IMPL
  48. #endif
  49. #ifdef CATCH_IMPL
  50. # ifndef CLARA_CONFIG_MAIN
  51. # define CLARA_CONFIG_MAIN_NOT_DEFINED
  52. # define CLARA_CONFIG_MAIN
  53. # endif
  54. #endif
  55. // #included from: internal/catch_notimplemented_exception.h
  56. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
  57. // #included from: catch_common.h
  58. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  59. // #included from: catch_compiler_capabilities.h
  60. #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  61. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  62. // The following features are defined:
  63. //
  64. // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
  65. // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  66. // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  67. // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
  68. // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
  69. // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
  70. // CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
  71. // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  72. // CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
  73. // CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
  74. // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  75. // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  76. // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
  77. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  78. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  79. // ****************
  80. // Note to maintainers: if new toggles are added please document them
  81. // in configuration.md, too
  82. // ****************
  83. // In general each macro has a _NO_<feature name> form
  84. // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  85. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  86. // can be combined, en-mass, with the _NO_ forms later.
  87. // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
  88. #ifdef __cplusplus
  89. # if __cplusplus >= 201103L
  90. # define CATCH_CPP11_OR_GREATER
  91. # endif
  92. # if __cplusplus >= 201402L
  93. # define CATCH_CPP14_OR_GREATER
  94. # endif
  95. #endif
  96. #ifdef __clang__
  97. # if __has_feature(cxx_nullptr)
  98. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  99. # endif
  100. # if __has_feature(cxx_noexcept)
  101. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  102. # endif
  103. # if defined(CATCH_CPP11_OR_GREATER)
  104. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  105. _Pragma( "clang diagnostic push" ) \
  106. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  107. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  108. _Pragma( "clang diagnostic pop" )
  109. # endif
  110. #endif // __clang__
  111. ////////////////////////////////////////////////////////////////////////////////
  112. // Cygwin
  113. #ifdef __CYGWIN__
  114. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  115. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  116. # endif
  117. // Required for some versions of Cygwin to declare gettimeofday
  118. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  119. # define _BSD_SOURCE
  120. #endif // __CYGWIN__
  121. ////////////////////////////////////////////////////////////////////////////////
  122. // Borland
  123. #ifdef __BORLANDC__
  124. #endif // __BORLANDC__
  125. ////////////////////////////////////////////////////////////////////////////////
  126. // EDG
  127. #ifdef __EDG_VERSION__
  128. #endif // __EDG_VERSION__
  129. ////////////////////////////////////////////////////////////////////////////////
  130. // Digital Mars
  131. #ifdef __DMC__
  132. #endif // __DMC__
  133. ////////////////////////////////////////////////////////////////////////////////
  134. // GCC
  135. #ifdef __GNUC__
  136. # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)
  137. # define CATCH_GCC_HAS_NEW_PRAGMA
  138. # endif
  139. # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  140. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  141. # endif
  142. # if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) && defined(CATCH_GCC_HAS_NEW_PRAGMA)
  143. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  144. _Pragma( "GCC diagnostic push" ) \
  145. _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" )
  146. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  147. _Pragma( "GCC diagnostic pop" )
  148. # endif
  149. // - otherwise more recent versions define __cplusplus >= 201103L
  150. // and will get picked up below
  151. #endif // __GNUC__
  152. ////////////////////////////////////////////////////////////////////////////////
  153. // Visual C++
  154. #ifdef _MSC_VER
  155. #define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  156. #if (_MSC_VER >= 1600)
  157. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  158. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  159. #endif
  160. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  161. #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  162. #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  163. #define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  164. #define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  165. #endif
  166. #endif // _MSC_VER
  167. ////////////////////////////////////////////////////////////////////////////////
  168. // Use variadic macros if the compiler supports them
  169. #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
  170. ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
  171. ( defined __GNUC__ && __GNUC__ >= 3 ) || \
  172. ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
  173. #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  174. #endif
  175. // Use __COUNTER__ if the compiler supports it
  176. #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
  177. ( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \
  178. ( defined __clang__ && __clang_major__ >= 3 )
  179. #define CATCH_INTERNAL_CONFIG_COUNTER
  180. #endif
  181. ////////////////////////////////////////////////////////////////////////////////
  182. // C++ language feature support
  183. // catch all support for C++11
  184. #if defined(CATCH_CPP11_OR_GREATER)
  185. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
  186. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  187. # endif
  188. # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  189. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  190. # endif
  191. # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  192. # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  193. # endif
  194. # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  195. # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  196. # endif
  197. # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  198. # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  199. # endif
  200. # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  201. # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  202. # endif
  203. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
  204. # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
  205. # endif
  206. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
  207. # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
  208. # endif
  209. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  210. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  211. # endif
  212. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
  213. # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  214. # endif
  215. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
  216. # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  217. # endif
  218. #endif // __cplusplus >= 201103L
  219. // Now set the actual defines based on the above + anything the user has configured
  220. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
  221. # define CATCH_CONFIG_CPP11_NULLPTR
  222. #endif
  223. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
  224. # define CATCH_CONFIG_CPP11_NOEXCEPT
  225. #endif
  226. #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)
  227. # define CATCH_CONFIG_CPP11_GENERATED_METHODS
  228. #endif
  229. #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)
  230. # define CATCH_CONFIG_CPP11_IS_ENUM
  231. #endif
  232. #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
  233. # define CATCH_CONFIG_CPP11_TUPLE
  234. #endif
  235. #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
  236. # define CATCH_CONFIG_VARIADIC_MACROS
  237. #endif
  238. #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)
  239. # define CATCH_CONFIG_CPP11_LONG_LONG
  240. #endif
  241. #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
  242. # define CATCH_CONFIG_CPP11_OVERRIDE
  243. #endif
  244. #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)
  245. # define CATCH_CONFIG_CPP11_UNIQUE_PTR
  246. #endif
  247. // Use of __COUNTER__ is suppressed if __JETBRAINS_IDE__ is #defined (meaning we're being parsed by a JetBrains IDE for
  248. // analytics) because, at time of writing, __COUNTER__ is not properly handled by it.
  249. // This does not affect compilation
  250. #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) && !defined(__JETBRAINS_IDE__)
  251. # define CATCH_CONFIG_COUNTER
  252. #endif
  253. #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
  254. # define CATCH_CONFIG_CPP11_SHUFFLE
  255. #endif
  256. # 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)
  257. # define CATCH_CONFIG_CPP11_TYPE_TRAITS
  258. # endif
  259. #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
  260. # define CATCH_CONFIG_WINDOWS_SEH
  261. #endif
  262. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  263. #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
  264. # define CATCH_CONFIG_POSIX_SIGNALS
  265. #endif
  266. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  267. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  268. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
  269. #endif
  270. // noexcept support:
  271. #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
  272. # define CATCH_NOEXCEPT noexcept
  273. # define CATCH_NOEXCEPT_IS(x) noexcept(x)
  274. #else
  275. # define CATCH_NOEXCEPT throw()
  276. # define CATCH_NOEXCEPT_IS(x)
  277. #endif
  278. // nullptr support
  279. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  280. # define CATCH_NULL nullptr
  281. #else
  282. # define CATCH_NULL NULL
  283. #endif
  284. // override support
  285. #ifdef CATCH_CONFIG_CPP11_OVERRIDE
  286. # define CATCH_OVERRIDE override
  287. #else
  288. # define CATCH_OVERRIDE
  289. #endif
  290. // unique_ptr support
  291. #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
  292. # define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
  293. #else
  294. # define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
  295. #endif
  296. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  297. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  298. #ifdef CATCH_CONFIG_COUNTER
  299. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  300. #else
  301. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  302. #endif
  303. #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
  304. #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
  305. #include <sstream>
  306. #include <algorithm>
  307. namespace Catch {
  308. struct IConfig;
  309. struct CaseSensitive { enum Choice {
  310. Yes,
  311. No
  312. }; };
  313. class NonCopyable {
  314. #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  315. NonCopyable( NonCopyable const& ) = delete;
  316. NonCopyable( NonCopyable && ) = delete;
  317. NonCopyable& operator = ( NonCopyable const& ) = delete;
  318. NonCopyable& operator = ( NonCopyable && ) = delete;
  319. #else
  320. NonCopyable( NonCopyable const& info );
  321. NonCopyable& operator = ( NonCopyable const& );
  322. #endif
  323. protected:
  324. NonCopyable() {}
  325. virtual ~NonCopyable();
  326. };
  327. class SafeBool {
  328. public:
  329. typedef void (SafeBool::*type)() const;
  330. static type makeSafe( bool value ) {
  331. return value ? &SafeBool::trueValue : 0;
  332. }
  333. private:
  334. void trueValue() const {}
  335. };
  336. template<typename ContainerT>
  337. inline void deleteAll( ContainerT& container ) {
  338. typename ContainerT::const_iterator it = container.begin();
  339. typename ContainerT::const_iterator itEnd = container.end();
  340. for(; it != itEnd; ++it )
  341. delete *it;
  342. }
  343. template<typename AssociativeContainerT>
  344. inline void deleteAllValues( AssociativeContainerT& container ) {
  345. typename AssociativeContainerT::const_iterator it = container.begin();
  346. typename AssociativeContainerT::const_iterator itEnd = container.end();
  347. for(; it != itEnd; ++it )
  348. delete it->second;
  349. }
  350. bool startsWith( std::string const& s, std::string const& prefix );
  351. bool startsWith( std::string const& s, char prefix );
  352. bool endsWith( std::string const& s, std::string const& suffix );
  353. bool endsWith( std::string const& s, char suffix );
  354. bool contains( std::string const& s, std::string const& infix );
  355. void toLowerInPlace( std::string& s );
  356. std::string toLower( std::string const& s );
  357. std::string trim( std::string const& str );
  358. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  359. struct pluralise {
  360. pluralise( std::size_t count, std::string const& label );
  361. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  362. std::size_t m_count;
  363. std::string m_label;
  364. };
  365. struct SourceLineInfo {
  366. SourceLineInfo();
  367. SourceLineInfo( char const* _file, std::size_t _line );
  368. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  369. SourceLineInfo(SourceLineInfo const& other) = default;
  370. SourceLineInfo( SourceLineInfo && ) = default;
  371. SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
  372. SourceLineInfo& operator = ( SourceLineInfo && ) = default;
  373. # endif
  374. bool empty() const;
  375. bool operator == ( SourceLineInfo const& other ) const;
  376. bool operator < ( SourceLineInfo const& other ) const;
  377. char const* file;
  378. std::size_t line;
  379. };
  380. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
  381. // This is just here to avoid compiler warnings with macro constants and boolean literals
  382. inline bool isTrue( bool value ){ return value; }
  383. inline bool alwaysTrue() { return true; }
  384. inline bool alwaysFalse() { return false; }
  385. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
  386. void seedRng( IConfig const& config );
  387. unsigned int rngSeed();
  388. // Use this in variadic streaming macros to allow
  389. // >> +StreamEndStop
  390. // as well as
  391. // >> stuff +StreamEndStop
  392. struct StreamEndStop {
  393. std::string operator+() {
  394. return std::string();
  395. }
  396. };
  397. template<typename T>
  398. T const& operator + ( T const& value, StreamEndStop ) {
  399. return value;
  400. }
  401. }
  402. #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  403. #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
  404. namespace Catch {
  405. class NotImplementedException : public std::exception
  406. {
  407. public:
  408. NotImplementedException( SourceLineInfo const& lineInfo );
  409. NotImplementedException( NotImplementedException const& ) {}
  410. virtual ~NotImplementedException() CATCH_NOEXCEPT {}
  411. virtual const char* what() const CATCH_NOEXCEPT;
  412. private:
  413. std::string m_what;
  414. SourceLineInfo m_lineInfo;
  415. };
  416. } // end namespace Catch
  417. ///////////////////////////////////////////////////////////////////////////////
  418. #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
  419. // #included from: internal/catch_context.h
  420. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  421. // #included from: catch_interfaces_generators.h
  422. #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
  423. #include <string>
  424. namespace Catch {
  425. struct IGeneratorInfo {
  426. virtual ~IGeneratorInfo();
  427. virtual bool moveNext() = 0;
  428. virtual std::size_t getCurrentIndex() const = 0;
  429. };
  430. struct IGeneratorsForTest {
  431. virtual ~IGeneratorsForTest();
  432. virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
  433. virtual bool moveNext() = 0;
  434. };
  435. IGeneratorsForTest* createGeneratorsForTest();
  436. } // end namespace Catch
  437. // #included from: catch_ptr.hpp
  438. #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
  439. #ifdef __clang__
  440. #pragma clang diagnostic push
  441. #pragma clang diagnostic ignored "-Wpadded"
  442. #endif
  443. namespace Catch {
  444. // An intrusive reference counting smart pointer.
  445. // T must implement addRef() and release() methods
  446. // typically implementing the IShared interface
  447. template<typename T>
  448. class Ptr {
  449. public:
  450. Ptr() : m_p( CATCH_NULL ){}
  451. Ptr( T* p ) : m_p( p ){
  452. if( m_p )
  453. m_p->addRef();
  454. }
  455. Ptr( Ptr const& other ) : m_p( other.m_p ){
  456. if( m_p )
  457. m_p->addRef();
  458. }
  459. ~Ptr(){
  460. if( m_p )
  461. m_p->release();
  462. }
  463. void reset() {
  464. if( m_p )
  465. m_p->release();
  466. m_p = CATCH_NULL;
  467. }
  468. Ptr& operator = ( T* p ){
  469. Ptr temp( p );
  470. swap( temp );
  471. return *this;
  472. }
  473. Ptr& operator = ( Ptr const& other ){
  474. Ptr temp( other );
  475. swap( temp );
  476. return *this;
  477. }
  478. void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
  479. T* get() const{ return m_p; }
  480. T& operator*() const { return *m_p; }
  481. T* operator->() const { return m_p; }
  482. bool operator !() const { return m_p == CATCH_NULL; }
  483. operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
  484. private:
  485. T* m_p;
  486. };
  487. struct IShared : NonCopyable {
  488. virtual ~IShared();
  489. virtual void addRef() const = 0;
  490. virtual void release() const = 0;
  491. };
  492. template<typename T = IShared>
  493. struct SharedImpl : T {
  494. SharedImpl() : m_rc( 0 ){}
  495. virtual void addRef() const {
  496. ++m_rc;
  497. }
  498. virtual void release() const {
  499. if( --m_rc == 0 )
  500. delete this;
  501. }
  502. mutable unsigned int m_rc;
  503. };
  504. } // end namespace Catch
  505. #ifdef __clang__
  506. #pragma clang diagnostic pop
  507. #endif
  508. namespace Catch {
  509. class TestCase;
  510. class Stream;
  511. struct IResultCapture;
  512. struct IRunner;
  513. struct IGeneratorsForTest;
  514. struct IConfig;
  515. struct IContext
  516. {
  517. virtual ~IContext();
  518. virtual IResultCapture* getResultCapture() = 0;
  519. virtual IRunner* getRunner() = 0;
  520. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
  521. virtual bool advanceGeneratorsForCurrentTest() = 0;
  522. virtual Ptr<IConfig const> getConfig() const = 0;
  523. };
  524. struct IMutableContext : IContext
  525. {
  526. virtual ~IMutableContext();
  527. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  528. virtual void setRunner( IRunner* runner ) = 0;
  529. virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
  530. };
  531. IContext& getCurrentContext();
  532. IMutableContext& getCurrentMutableContext();
  533. void cleanUpContext();
  534. Stream createStream( std::string const& streamName );
  535. }
  536. // #included from: internal/catch_test_registry.hpp
  537. #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
  538. // #included from: catch_interfaces_testcase.h
  539. #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
  540. #include <vector>
  541. namespace Catch {
  542. class TestSpec;
  543. struct ITestCase : IShared {
  544. virtual void invoke () const = 0;
  545. protected:
  546. virtual ~ITestCase();
  547. };
  548. class TestCase;
  549. struct IConfig;
  550. struct ITestCaseRegistry {
  551. virtual ~ITestCaseRegistry();
  552. virtual std::vector<TestCase> const& getAllTests() const = 0;
  553. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
  554. };
  555. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
  556. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
  557. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
  558. }
  559. namespace Catch {
  560. template<typename C>
  561. class MethodTestCase : public SharedImpl<ITestCase> {
  562. public:
  563. MethodTestCase( void (C::*method)() ) : m_method( method ) {}
  564. virtual void invoke() const {
  565. C obj;
  566. (obj.*m_method)();
  567. }
  568. private:
  569. virtual ~MethodTestCase() {}
  570. void (C::*m_method)();
  571. };
  572. typedef void(*TestFunction)();
  573. struct NameAndDesc {
  574. NameAndDesc( const char* _name = "", const char* _description= "" )
  575. : name( _name ), description( _description )
  576. {}
  577. const char* name;
  578. const char* description;
  579. };
  580. void registerTestCase
  581. ( ITestCase* testCase,
  582. char const* className,
  583. NameAndDesc const& nameAndDesc,
  584. SourceLineInfo const& lineInfo );
  585. struct AutoReg {
  586. AutoReg
  587. ( TestFunction function,
  588. SourceLineInfo const& lineInfo,
  589. NameAndDesc const& nameAndDesc );
  590. template<typename C>
  591. AutoReg
  592. ( void (C::*method)(),
  593. char const* className,
  594. NameAndDesc const& nameAndDesc,
  595. SourceLineInfo const& lineInfo ) {
  596. registerTestCase
  597. ( new MethodTestCase<C>( method ),
  598. className,
  599. nameAndDesc,
  600. lineInfo );
  601. }
  602. ~AutoReg();
  603. private:
  604. AutoReg( AutoReg const& );
  605. void operator= ( AutoReg const& );
  606. };
  607. void registerTestCaseFunction
  608. ( TestFunction function,
  609. SourceLineInfo const& lineInfo,
  610. NameAndDesc const& nameAndDesc );
  611. } // end namespace Catch
  612. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  613. ///////////////////////////////////////////////////////////////////////////////
  614. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  615. static void TestName(); \
  616. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
  617. static void TestName()
  618. #define INTERNAL_CATCH_TESTCASE( ... ) \
  619. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
  620. ///////////////////////////////////////////////////////////////////////////////
  621. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  622. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); }
  623. ///////////////////////////////////////////////////////////////////////////////
  624. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  625. namespace{ \
  626. struct TestName : ClassName{ \
  627. void test(); \
  628. }; \
  629. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \
  630. } \
  631. void TestName::test()
  632. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  633. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
  634. ///////////////////////////////////////////////////////////////////////////////
  635. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  636. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) );
  637. #else
  638. ///////////////////////////////////////////////////////////////////////////////
  639. #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
  640. static void TestName(); \
  641. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\
  642. static void TestName()
  643. #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
  644. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
  645. ///////////////////////////////////////////////////////////////////////////////
  646. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
  647. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); }
  648. ///////////////////////////////////////////////////////////////////////////////
  649. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
  650. namespace{ \
  651. struct TestCaseName : ClassName{ \
  652. void test(); \
  653. }; \
  654. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \
  655. } \
  656. void TestCaseName::test()
  657. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
  658. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
  659. ///////////////////////////////////////////////////////////////////////////////
  660. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
  661. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) );
  662. #endif
  663. // #included from: internal/catch_capture.hpp
  664. #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
  665. // #included from: catch_result_builder.h
  666. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
  667. // #included from: catch_result_type.h
  668. #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
  669. namespace Catch {
  670. // ResultWas::OfType enum
  671. struct ResultWas { enum OfType {
  672. Unknown = -1,
  673. Ok = 0,
  674. Info = 1,
  675. Warning = 2,
  676. FailureBit = 0x10,
  677. ExpressionFailed = FailureBit | 1,
  678. ExplicitFailure = FailureBit | 2,
  679. Exception = 0x100 | FailureBit,
  680. ThrewException = Exception | 1,
  681. DidntThrowException = Exception | 2,
  682. FatalErrorCondition = 0x200 | FailureBit
  683. }; };
  684. inline bool isOk( ResultWas::OfType resultType ) {
  685. return ( resultType & ResultWas::FailureBit ) == 0;
  686. }
  687. inline bool isJustInfo( int flags ) {
  688. return flags == ResultWas::Info;
  689. }
  690. // ResultDisposition::Flags enum
  691. struct ResultDisposition { enum Flags {
  692. Normal = 0x01,
  693. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  694. FalseTest = 0x04, // Prefix expression with !
  695. SuppressFail = 0x08 // Failures are reported but do not fail the test
  696. }; };
  697. inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
  698. return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
  699. }
  700. inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
  701. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  702. inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
  703. } // end namespace Catch
  704. // #included from: catch_assertionresult.h
  705. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
  706. #include <string>
  707. namespace Catch {
  708. struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
  709. struct DecomposedExpression
  710. {
  711. virtual ~DecomposedExpression() {}
  712. virtual bool isBinaryExpression() const {
  713. return false;
  714. }
  715. virtual void reconstructExpression( std::string& dest ) const = 0;
  716. // Only simple binary comparisons can be decomposed.
  717. // If more complex check is required then wrap sub-expressions in parentheses.
  718. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& );
  719. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& );
  720. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& );
  721. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& );
  722. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& );
  723. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& );
  724. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& );
  725. private:
  726. DecomposedExpression& operator = (DecomposedExpression const&);
  727. };
  728. struct AssertionInfo
  729. {
  730. AssertionInfo() {}
  731. AssertionInfo( std::string const& _macroName,
  732. SourceLineInfo const& _lineInfo,
  733. std::string const& _capturedExpression,
  734. ResultDisposition::Flags _resultDisposition );
  735. std::string macroName;
  736. SourceLineInfo lineInfo;
  737. std::string capturedExpression;
  738. ResultDisposition::Flags resultDisposition;
  739. };
  740. struct AssertionResultData
  741. {
  742. AssertionResultData() : decomposedExpression( CATCH_NULL )
  743. , resultType( ResultWas::Unknown )
  744. , negated( false )
  745. , parenthesized( false ) {}
  746. void negate( bool parenthesize ) {
  747. negated = !negated;
  748. parenthesized = parenthesize;
  749. if( resultType == ResultWas::Ok )
  750. resultType = ResultWas::ExpressionFailed;
  751. else if( resultType == ResultWas::ExpressionFailed )
  752. resultType = ResultWas::Ok;
  753. }
  754. std::string const& reconstructExpression() const {
  755. if( decomposedExpression != CATCH_NULL ) {
  756. decomposedExpression->reconstructExpression( reconstructedExpression );
  757. if( parenthesized ) {
  758. reconstructedExpression.insert( 0, 1, '(' );
  759. reconstructedExpression.append( 1, ')' );
  760. }
  761. if( negated ) {
  762. reconstructedExpression.insert( 0, 1, '!' );
  763. }
  764. decomposedExpression = CATCH_NULL;
  765. }
  766. return reconstructedExpression;
  767. }
  768. mutable DecomposedExpression const* decomposedExpression;
  769. mutable std::string reconstructedExpression;
  770. std::string message;
  771. ResultWas::OfType resultType;
  772. bool negated;
  773. bool parenthesized;
  774. };
  775. class AssertionResult {
  776. public:
  777. AssertionResult();
  778. AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
  779. ~AssertionResult();
  780. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  781. AssertionResult( AssertionResult const& ) = default;
  782. AssertionResult( AssertionResult && ) = default;
  783. AssertionResult& operator = ( AssertionResult const& ) = default;
  784. AssertionResult& operator = ( AssertionResult && ) = default;
  785. # endif
  786. bool isOk() const;
  787. bool succeeded() const;
  788. ResultWas::OfType getResultType() const;
  789. bool hasExpression() const;
  790. bool hasMessage() const;
  791. std::string getExpression() const;
  792. std::string getExpressionInMacro() const;
  793. bool hasExpandedExpression() const;
  794. std::string getExpandedExpression() const;
  795. std::string getMessage() const;
  796. SourceLineInfo getSourceInfo() const;
  797. std::string getTestMacroName() const;
  798. void discardDecomposedExpression() const;
  799. void expandDecomposedExpression() const;
  800. protected:
  801. AssertionInfo m_info;
  802. AssertionResultData m_resultData;
  803. };
  804. } // end namespace Catch
  805. // #included from: catch_matchers.hpp
  806. #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
  807. namespace Catch {
  808. namespace Matchers {
  809. namespace Impl {
  810. template<typename ArgT> struct MatchAllOf;
  811. template<typename ArgT> struct MatchAnyOf;
  812. template<typename ArgT> struct MatchNotOf;
  813. class MatcherUntypedBase {
  814. public:
  815. std::string toString() const {
  816. if( m_cachedToString.empty() )
  817. m_cachedToString = describe();
  818. return m_cachedToString;
  819. }
  820. protected:
  821. virtual std::string describe() const = 0;
  822. mutable std::string m_cachedToString;
  823. private:
  824. MatcherUntypedBase& operator = ( MatcherUntypedBase const& );
  825. };
  826. template<typename ObjectT, typename ComparatorT = ObjectT>
  827. struct MatcherBase : MatcherUntypedBase {
  828. virtual bool match( ObjectT const& arg ) const = 0;
  829. MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
  830. MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
  831. MatchNotOf<ComparatorT> operator ! () const;
  832. };
  833. template<typename ArgT>
  834. struct MatchAllOf : MatcherBase<ArgT> {
  835. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  836. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  837. if (!m_matchers[i]->match(arg))
  838. return false;
  839. }
  840. return true;
  841. }
  842. virtual std::string describe() const CATCH_OVERRIDE {
  843. std::string description;
  844. description.reserve( 4 + m_matchers.size()*32 );
  845. description += "( ";
  846. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  847. if( i != 0 )
  848. description += " and ";
  849. description += m_matchers[i]->toString();
  850. }
  851. description += " )";
  852. return description;
  853. }
  854. MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
  855. m_matchers.push_back( &other );
  856. return *this;
  857. }
  858. std::vector<MatcherBase<ArgT> const*> m_matchers;
  859. };
  860. template<typename ArgT>
  861. struct MatchAnyOf : MatcherBase<ArgT> {
  862. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  863. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  864. if (m_matchers[i]->match(arg))
  865. return true;
  866. }
  867. return false;
  868. }
  869. virtual std::string describe() const CATCH_OVERRIDE {
  870. std::string description;
  871. description.reserve( 4 + m_matchers.size()*32 );
  872. description += "( ";
  873. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  874. if( i != 0 )
  875. description += " or ";
  876. description += m_matchers[i]->toString();
  877. }
  878. description += " )";
  879. return description;
  880. }
  881. MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
  882. m_matchers.push_back( &other );
  883. return *this;
  884. }
  885. std::vector<MatcherBase<ArgT> const*> m_matchers;
  886. };
  887. template<typename ArgT>
  888. struct MatchNotOf : MatcherBase<ArgT> {
  889. MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
  890. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  891. return !m_underlyingMatcher.match( arg );
  892. }
  893. virtual std::string describe() const CATCH_OVERRIDE {
  894. return "not " + m_underlyingMatcher.toString();
  895. }
  896. MatcherBase<ArgT> const& m_underlyingMatcher;
  897. };
  898. template<typename ObjectT, typename ComparatorT>
  899. MatchAllOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator && ( MatcherBase const& other ) const {
  900. return MatchAllOf<ComparatorT>() && *this && other;
  901. }
  902. template<typename ObjectT, typename ComparatorT>
  903. MatchAnyOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator || ( MatcherBase const& other ) const {
  904. return MatchAnyOf<ComparatorT>() || *this || other;
  905. }
  906. template<typename ObjectT, typename ComparatorT>
  907. MatchNotOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator ! () const {
  908. return MatchNotOf<ComparatorT>( *this );
  909. }
  910. } // namespace Impl
  911. // The following functions create the actual matcher objects.
  912. // This allows the types to be inferred
  913. // - deprecated: prefer ||, && and !
  914. template<typename T>
  915. inline Impl::MatchNotOf<T> Not( Impl::MatcherBase<T> const& underlyingMatcher ) {
  916. return Impl::MatchNotOf<T>( underlyingMatcher );
  917. }
  918. template<typename T>
  919. inline Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  920. return Impl::MatchAllOf<T>() && m1 && m2;
  921. }
  922. template<typename T>
  923. inline Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  924. return Impl::MatchAllOf<T>() && m1 && m2 && m3;
  925. }
  926. template<typename T>
  927. inline Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  928. return Impl::MatchAnyOf<T>() || m1 || m2;
  929. }
  930. template<typename T>
  931. inline Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  932. return Impl::MatchAnyOf<T>() || m1 || m2 || m3;
  933. }
  934. } // namespace Matchers
  935. using namespace Matchers;
  936. using Matchers::Impl::MatcherBase;
  937. } // namespace Catch
  938. namespace Catch {
  939. struct TestFailureException{};
  940. template<typename T> class ExpressionLhs;
  941. struct CopyableStream {
  942. CopyableStream() {}
  943. CopyableStream( CopyableStream const& other ) {
  944. oss << other.oss.str();
  945. }
  946. CopyableStream& operator=( CopyableStream const& other ) {
  947. oss.str(std::string());
  948. oss << other.oss.str();
  949. return *this;
  950. }
  951. std::ostringstream oss;
  952. };
  953. class ResultBuilder : public DecomposedExpression {
  954. public:
  955. ResultBuilder( char const* macroName,
  956. SourceLineInfo const& lineInfo,
  957. char const* capturedExpression,
  958. ResultDisposition::Flags resultDisposition,
  959. char const* secondArg = "" );
  960. template<typename T>
  961. ExpressionLhs<T const&> operator <= ( T const& operand );
  962. ExpressionLhs<bool> operator <= ( bool value );
  963. template<typename T>
  964. ResultBuilder& operator << ( T const& value ) {
  965. m_stream.oss << value;
  966. return *this;
  967. }
  968. ResultBuilder& setResultType( ResultWas::OfType result );
  969. ResultBuilder& setResultType( bool result );
  970. void endExpression( DecomposedExpression const& expr );
  971. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE;
  972. AssertionResult build() const;
  973. AssertionResult build( DecomposedExpression const& expr ) const;
  974. void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
  975. void captureResult( ResultWas::OfType resultType );
  976. void captureExpression();
  977. void captureExpectedException( std::string const& expectedMessage );
  978. void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher );
  979. void handleResult( AssertionResult const& result );
  980. void react();
  981. bool shouldDebugBreak() const;
  982. bool allowThrows() const;
  983. template<typename ArgT, typename MatcherT>
  984. void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
  985. private:
  986. AssertionInfo m_assertionInfo;
  987. AssertionResultData m_data;
  988. CopyableStream m_stream;
  989. bool m_shouldDebugBreak;
  990. bool m_shouldThrow;
  991. };
  992. } // namespace Catch
  993. // Include after due to circular dependency:
  994. // #included from: catch_expression_lhs.hpp
  995. #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
  996. // #included from: catch_evaluate.hpp
  997. #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
  998. #ifdef _MSC_VER
  999. #pragma warning(push)
  1000. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  1001. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  1002. #endif
  1003. #include <cstddef>
  1004. namespace Catch {
  1005. namespace Internal {
  1006. enum Operator {
  1007. IsEqualTo,
  1008. IsNotEqualTo,
  1009. IsLessThan,
  1010. IsGreaterThan,
  1011. IsLessThanOrEqualTo,
  1012. IsGreaterThanOrEqualTo
  1013. };
  1014. template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
  1015. template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
  1016. template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
  1017. template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
  1018. template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
  1019. template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
  1020. template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
  1021. template<typename T>
  1022. inline T& opCast(T const& t) { return const_cast<T&>(t); }
  1023. // nullptr_t support based on pull request #154 from Konstantin Baumann
  1024. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1025. inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
  1026. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1027. // So the compare overloads can be operator agnostic we convey the operator as a template
  1028. // enum, which is used to specialise an Evaluator for doing the comparison.
  1029. template<typename T1, typename T2, Operator Op>
  1030. class Evaluator{};
  1031. template<typename T1, typename T2>
  1032. struct Evaluator<T1, T2, IsEqualTo> {
  1033. static bool evaluate( T1 const& lhs, T2 const& rhs) {
  1034. return bool( opCast( lhs ) == opCast( rhs ) );
  1035. }
  1036. };
  1037. template<typename T1, typename T2>
  1038. struct Evaluator<T1, T2, IsNotEqualTo> {
  1039. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1040. return bool( opCast( lhs ) != opCast( rhs ) );
  1041. }
  1042. };
  1043. template<typename T1, typename T2>
  1044. struct Evaluator<T1, T2, IsLessThan> {
  1045. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1046. return bool( opCast( lhs ) < opCast( rhs ) );
  1047. }
  1048. };
  1049. template<typename T1, typename T2>
  1050. struct Evaluator<T1, T2, IsGreaterThan> {
  1051. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1052. return bool( opCast( lhs ) > opCast( rhs ) );
  1053. }
  1054. };
  1055. template<typename T1, typename T2>
  1056. struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
  1057. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1058. return bool( opCast( lhs ) >= opCast( rhs ) );
  1059. }
  1060. };
  1061. template<typename T1, typename T2>
  1062. struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
  1063. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1064. return bool( opCast( lhs ) <= opCast( rhs ) );
  1065. }
  1066. };
  1067. template<Operator Op, typename T1, typename T2>
  1068. bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
  1069. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1070. }
  1071. // This level of indirection allows us to specialise for integer types
  1072. // to avoid signed/ unsigned warnings
  1073. // "base" overload
  1074. template<Operator Op, typename T1, typename T2>
  1075. bool compare( T1 const& lhs, T2 const& rhs ) {
  1076. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1077. }
  1078. // unsigned X to int
  1079. template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
  1080. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1081. }
  1082. template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
  1083. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1084. }
  1085. template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
  1086. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1087. }
  1088. // unsigned X to long
  1089. template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
  1090. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1091. }
  1092. template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
  1093. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1094. }
  1095. template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
  1096. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1097. }
  1098. // int to unsigned X
  1099. template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
  1100. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1101. }
  1102. template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
  1103. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1104. }
  1105. template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
  1106. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1107. }
  1108. // long to unsigned X
  1109. template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
  1110. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1111. }
  1112. template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
  1113. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1114. }
  1115. template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
  1116. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1117. }
  1118. // pointer to long (when comparing against NULL)
  1119. template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
  1120. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1121. }
  1122. template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
  1123. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1124. }
  1125. // pointer to int (when comparing against NULL)
  1126. template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
  1127. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1128. }
  1129. template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
  1130. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1131. }
  1132. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1133. // long long to unsigned X
  1134. template<Operator Op> bool compare( long long lhs, unsigned int rhs ) {
  1135. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1136. }
  1137. template<Operator Op> bool compare( long long lhs, unsigned long rhs ) {
  1138. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1139. }
  1140. template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) {
  1141. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1142. }
  1143. template<Operator Op> bool compare( long long lhs, unsigned char rhs ) {
  1144. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1145. }
  1146. // unsigned long long to X
  1147. template<Operator Op> bool compare( unsigned long long lhs, int rhs ) {
  1148. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1149. }
  1150. template<Operator Op> bool compare( unsigned long long lhs, long rhs ) {
  1151. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1152. }
  1153. template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) {
  1154. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1155. }
  1156. template<Operator Op> bool compare( unsigned long long lhs, char rhs ) {
  1157. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1158. }
  1159. // pointer to long long (when comparing against NULL)
  1160. template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) {
  1161. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1162. }
  1163. template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) {
  1164. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1165. }
  1166. #endif // CATCH_CONFIG_CPP11_LONG_LONG
  1167. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1168. // pointer to nullptr_t (when comparing against nullptr)
  1169. template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
  1170. return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs );
  1171. }
  1172. template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
  1173. return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr );
  1174. }
  1175. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1176. } // end of namespace Internal
  1177. } // end of namespace Catch
  1178. #ifdef _MSC_VER
  1179. #pragma warning(pop)
  1180. #endif
  1181. // #included from: catch_tostring.h
  1182. #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
  1183. #include <sstream>
  1184. #include <iomanip>
  1185. #include <limits>
  1186. #include <vector>
  1187. #include <cstddef>
  1188. #ifdef __OBJC__
  1189. // #included from: catch_objc_arc.hpp
  1190. #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
  1191. #import <Foundation/Foundation.h>
  1192. #ifdef __has_feature
  1193. #define CATCH_ARC_ENABLED __has_feature(objc_arc)
  1194. #else
  1195. #define CATCH_ARC_ENABLED 0
  1196. #endif
  1197. void arcSafeRelease( NSObject* obj );
  1198. id performOptionalSelector( id obj, SEL sel );
  1199. #if !CATCH_ARC_ENABLED
  1200. inline void arcSafeRelease( NSObject* obj ) {
  1201. [obj release];
  1202. }
  1203. inline id performOptionalSelector( id obj, SEL sel ) {
  1204. if( [obj respondsToSelector: sel] )
  1205. return [obj performSelector: sel];
  1206. return nil;
  1207. }
  1208. #define CATCH_UNSAFE_UNRETAINED
  1209. #define CATCH_ARC_STRONG
  1210. #else
  1211. inline void arcSafeRelease( NSObject* ){}
  1212. inline id performOptionalSelector( id obj, SEL sel ) {
  1213. #ifdef __clang__
  1214. #pragma clang diagnostic push
  1215. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  1216. #endif
  1217. if( [obj respondsToSelector: sel] )
  1218. return [obj performSelector: sel];
  1219. #ifdef __clang__
  1220. #pragma clang diagnostic pop
  1221. #endif
  1222. return nil;
  1223. }
  1224. #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
  1225. #define CATCH_ARC_STRONG __strong
  1226. #endif
  1227. #endif
  1228. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1229. #include <tuple>
  1230. #endif
  1231. #ifdef CATCH_CONFIG_CPP11_IS_ENUM
  1232. #include <type_traits>
  1233. #endif
  1234. namespace Catch {
  1235. // Why we're here.
  1236. template<typename T>
  1237. std::string toString( T const& value );
  1238. // Built in overloads
  1239. std::string toString( std::string const& value );
  1240. std::string toString( std::wstring const& value );
  1241. std::string toString( const char* const value );
  1242. std::string toString( char* const value );
  1243. std::string toString( const wchar_t* const value );
  1244. std::string toString( wchar_t* const value );
  1245. std::string toString( int value );
  1246. std::string toString( unsigned long value );
  1247. std::string toString( unsigned int value );
  1248. std::string toString( const double value );
  1249. std::string toString( const float value );
  1250. std::string toString( bool value );
  1251. std::string toString( char value );
  1252. std::string toString( signed char value );
  1253. std::string toString( unsigned char value );
  1254. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1255. std::string toString( long long value );
  1256. std::string toString( unsigned long long value );
  1257. #endif
  1258. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1259. std::string toString( std::nullptr_t );
  1260. #endif
  1261. #ifdef __OBJC__
  1262. std::string toString( NSString const * const& nsstring );
  1263. std::string toString( NSString * CATCH_ARC_STRONG const& nsstring );
  1264. std::string toString( NSObject* const& nsObject );
  1265. #endif
  1266. namespace Detail {
  1267. extern const std::string unprintableString;
  1268. struct BorgType {
  1269. template<typename T> BorgType( T const& );
  1270. };
  1271. struct TrueType { char sizer[1]; };
  1272. struct FalseType { char sizer[2]; };
  1273. TrueType& testStreamable( std::ostream& );
  1274. FalseType testStreamable( FalseType );
  1275. FalseType operator<<( std::ostream const&, BorgType const& );
  1276. template<typename T>
  1277. struct IsStreamInsertable {
  1278. static std::ostream &s;
  1279. static T const&t;
  1280. enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
  1281. };
  1282. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1283. template<typename T,
  1284. bool IsEnum = std::is_enum<T>::value
  1285. >
  1286. struct EnumStringMaker
  1287. {
  1288. static std::string convert( T const& ) { return unprintableString; }
  1289. };
  1290. template<typename T>
  1291. struct EnumStringMaker<T,true>
  1292. {
  1293. static std::string convert( T const& v )
  1294. {
  1295. return ::Catch::toString(
  1296. static_cast<typename std::underlying_type<T>::type>(v)
  1297. );
  1298. }
  1299. };
  1300. #endif
  1301. template<bool C>
  1302. struct StringMakerBase {
  1303. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1304. template<typename T>
  1305. static std::string convert( T const& v )
  1306. {
  1307. return EnumStringMaker<T>::convert( v );
  1308. }
  1309. #else
  1310. template<typename T>
  1311. static std::string convert( T const& ) { return unprintableString; }
  1312. #endif
  1313. };
  1314. template<>
  1315. struct StringMakerBase<true> {
  1316. template<typename T>
  1317. static std::string convert( T const& _value ) {
  1318. std::ostringstream oss;
  1319. oss << _value;
  1320. return oss.str();
  1321. }
  1322. };
  1323. std::string rawMemoryToString( const void *object, std::size_t size );
  1324. template<typename T>
  1325. inline std::string rawMemoryToString( const T& object ) {
  1326. return rawMemoryToString( &object, sizeof(object) );
  1327. }
  1328. } // end namespace Detail
  1329. template<typename T>
  1330. struct StringMaker :
  1331. Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
  1332. template<typename T>
  1333. struct StringMaker<T*> {
  1334. template<typename U>
  1335. static std::string convert( U* p ) {
  1336. if( !p )
  1337. return "NULL";
  1338. else
  1339. return Detail::rawMemoryToString( p );
  1340. }
  1341. };
  1342. template<typename R, typename C>
  1343. struct StringMaker<R C::*> {
  1344. static std::string convert( R C::* p ) {
  1345. if( !p )
  1346. return "NULL";
  1347. else
  1348. return Detail::rawMemoryToString( p );
  1349. }
  1350. };
  1351. namespace Detail {
  1352. template<typename InputIterator>
  1353. std::string rangeToString( InputIterator first, InputIterator last );
  1354. }
  1355. //template<typename T, typename Allocator>
  1356. //struct StringMaker<std::vector<T, Allocator> > {
  1357. // static std::string convert( std::vector<T,Allocator> const& v ) {
  1358. // return Detail::rangeToString( v.begin(), v.end() );
  1359. // }
  1360. //};
  1361. template<typename T, typename Allocator>
  1362. std::string toString( std::vector<T,Allocator> const& v ) {
  1363. return Detail::rangeToString( v.begin(), v.end() );
  1364. }
  1365. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1366. // toString for tuples
  1367. namespace TupleDetail {
  1368. template<
  1369. typename Tuple,
  1370. std::size_t N = 0,
  1371. bool = (N < std::tuple_size<Tuple>::value)
  1372. >
  1373. struct ElementPrinter {
  1374. static void print( const Tuple& tuple, std::ostream& os )
  1375. {
  1376. os << ( N ? ", " : " " )
  1377. << Catch::toString(std::get<N>(tuple));
  1378. ElementPrinter<Tuple,N+1>::print(tuple,os);
  1379. }
  1380. };
  1381. template<
  1382. typename Tuple,
  1383. std::size_t N
  1384. >
  1385. struct ElementPrinter<Tuple,N,false> {
  1386. static void print( const Tuple&, std::ostream& ) {}
  1387. };
  1388. }
  1389. template<typename ...Types>
  1390. struct StringMaker<std::tuple<Types...>> {
  1391. static std::string convert( const std::tuple<Types...>& tuple )
  1392. {
  1393. std::ostringstream os;
  1394. os << '{';
  1395. TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
  1396. os << " }";
  1397. return os.str();
  1398. }
  1399. };
  1400. #endif // CATCH_CONFIG_CPP11_TUPLE
  1401. namespace Detail {
  1402. template<typename T>
  1403. std::string makeString( T const& value ) {
  1404. return StringMaker<T>::convert( value );
  1405. }
  1406. } // end namespace Detail
  1407. /// \brief converts any type to a string
  1408. ///
  1409. /// The default template forwards on to ostringstream - except when an
  1410. /// ostringstream overload does not exist - in which case it attempts to detect
  1411. /// that and writes {?}.
  1412. /// Overload (not specialise) this template for custom typs that you don't want
  1413. /// to provide an ostream overload for.
  1414. template<typename T>
  1415. std::string toString( T const& value ) {
  1416. return StringMaker<T>::convert( value );
  1417. }
  1418. namespace Detail {
  1419. template<typename InputIterator>
  1420. std::string rangeToString( InputIterator first, InputIterator last ) {
  1421. std::ostringstream oss;
  1422. oss << "{ ";
  1423. if( first != last ) {
  1424. oss << Catch::toString( *first );
  1425. for( ++first ; first != last ; ++first )
  1426. oss << ", " << Catch::toString( *first );
  1427. }
  1428. oss << " }";
  1429. return oss.str();
  1430. }
  1431. }
  1432. } // end namespace Catch
  1433. namespace Catch {
  1434. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1435. class BinaryExpression;
  1436. template<typename ArgT, typename MatcherT>
  1437. class MatchExpression;
  1438. // Wraps the LHS of an expression and overloads comparison operators
  1439. // for also capturing those and RHS (if any)
  1440. template<typename T>
  1441. class ExpressionLhs : public DecomposedExpression {
  1442. public:
  1443. ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {}
  1444. ExpressionLhs& operator = ( const ExpressionLhs& );
  1445. template<typename RhsT>
  1446. BinaryExpression<T, Internal::IsEqualTo, RhsT const&>
  1447. operator == ( RhsT const& rhs ) {
  1448. return captureExpression<Internal::IsEqualTo>( rhs );
  1449. }
  1450. template<typename RhsT>
  1451. BinaryExpression<T, Internal::IsNotEqualTo, RhsT const&>
  1452. operator != ( RhsT const& rhs ) {
  1453. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1454. }
  1455. template<typename RhsT>
  1456. BinaryExpression<T, Internal::IsLessThan, RhsT const&>
  1457. operator < ( RhsT const& rhs ) {
  1458. return captureExpression<Internal::IsLessThan>( rhs );
  1459. }
  1460. template<typename RhsT>
  1461. BinaryExpression<T, Internal::IsGreaterThan, RhsT const&>
  1462. operator > ( RhsT const& rhs ) {
  1463. return captureExpression<Internal::IsGreaterThan>( rhs );
  1464. }
  1465. template<typename RhsT>
  1466. BinaryExpression<T, Internal::IsLessThanOrEqualTo, RhsT const&>
  1467. operator <= ( RhsT const& rhs ) {
  1468. return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
  1469. }
  1470. template<typename RhsT>
  1471. BinaryExpression<T, Internal::IsGreaterThanOrEqualTo, RhsT const&>
  1472. operator >= ( RhsT const& rhs ) {
  1473. return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
  1474. }
  1475. BinaryExpression<T, Internal::IsEqualTo, bool> operator == ( bool rhs ) {
  1476. return captureExpression<Internal::IsEqualTo>( rhs );
  1477. }
  1478. BinaryExpression<T, Internal::IsNotEqualTo, bool> operator != ( bool rhs ) {
  1479. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1480. }
  1481. void endExpression() {
  1482. m_truthy = m_lhs ? true : false;
  1483. m_rb
  1484. .setResultType( m_truthy )
  1485. .endExpression( *this );
  1486. }
  1487. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1488. dest = Catch::toString( m_truthy );
  1489. }
  1490. private:
  1491. template<Internal::Operator Op, typename RhsT>
  1492. BinaryExpression<T, Op, RhsT&> captureExpression( RhsT& rhs ) const {
  1493. return BinaryExpression<T, Op, RhsT&>( m_rb, m_lhs, rhs );
  1494. }
  1495. template<Internal::Operator Op>
  1496. BinaryExpression<T, Op, bool> captureExpression( bool rhs ) const {
  1497. return BinaryExpression<T, Op, bool>( m_rb, m_lhs, rhs );
  1498. }
  1499. private:
  1500. ResultBuilder& m_rb;
  1501. T m_lhs;
  1502. bool m_truthy;
  1503. };
  1504. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1505. class BinaryExpression : public DecomposedExpression {
  1506. public:
  1507. BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs )
  1508. : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {}
  1509. BinaryExpression& operator = ( BinaryExpression& );
  1510. void endExpression() const {
  1511. m_rb
  1512. .setResultType( Internal::compare<Op>( m_lhs, m_rhs ) )
  1513. .endExpression( *this );
  1514. }
  1515. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1516. return true;
  1517. }
  1518. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1519. std::string lhs = Catch::toString( m_lhs );
  1520. std::string rhs = Catch::toString( m_rhs );
  1521. char delim = lhs.size() + rhs.size() < 40 &&
  1522. lhs.find('\n') == std::string::npos &&
  1523. rhs.find('\n') == std::string::npos ? ' ' : '\n';
  1524. dest.reserve( 7 + lhs.size() + rhs.size() );
  1525. // 2 for spaces around operator
  1526. // 2 for operator
  1527. // 2 for parentheses (conditionally added later)
  1528. // 1 for negation (conditionally added later)
  1529. dest = lhs;
  1530. dest += delim;
  1531. dest += Internal::OperatorTraits<Op>::getName();
  1532. dest += delim;
  1533. dest += rhs;
  1534. }
  1535. private:
  1536. ResultBuilder& m_rb;
  1537. LhsT m_lhs;
  1538. RhsT m_rhs;
  1539. };
  1540. template<typename ArgT, typename MatcherT>
  1541. class MatchExpression : public DecomposedExpression {
  1542. public:
  1543. MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString )
  1544. : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {}
  1545. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1546. return true;
  1547. }
  1548. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1549. std::string matcherAsString = m_matcher.toString();
  1550. dest = Catch::toString( m_arg );
  1551. dest += ' ';
  1552. if( matcherAsString == Detail::unprintableString )
  1553. dest += m_matcherString;
  1554. else
  1555. dest += matcherAsString;
  1556. }
  1557. private:
  1558. ArgT m_arg;
  1559. MatcherT m_matcher;
  1560. char const* m_matcherString;
  1561. };
  1562. } // end namespace Catch
  1563. namespace Catch {
  1564. template<typename T>
  1565. inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
  1566. return ExpressionLhs<T const&>( *this, operand );
  1567. }
  1568. inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
  1569. return ExpressionLhs<bool>( *this, value );
  1570. }
  1571. template<typename ArgT, typename MatcherT>
  1572. inline void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
  1573. char const* matcherString ) {
  1574. MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString );
  1575. setResultType( matcher.match( arg ) );
  1576. endExpression( expr );
  1577. }
  1578. } // namespace Catch
  1579. // #included from: catch_message.h
  1580. #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
  1581. #include <string>
  1582. namespace Catch {
  1583. struct MessageInfo {
  1584. MessageInfo( std::string const& _macroName,
  1585. SourceLineInfo const& _lineInfo,
  1586. ResultWas::OfType _type );
  1587. std::string macroName;
  1588. SourceLineInfo lineInfo;
  1589. ResultWas::OfType type;
  1590. std::string message;
  1591. unsigned int sequence;
  1592. bool operator == ( MessageInfo const& other ) const {
  1593. return sequence == other.sequence;
  1594. }
  1595. bool operator < ( MessageInfo const& other ) const {
  1596. return sequence < other.sequence;
  1597. }
  1598. private:
  1599. static unsigned int globalCount;
  1600. };
  1601. struct MessageBuilder {
  1602. MessageBuilder( std::string const& macroName,
  1603. SourceLineInfo const& lineInfo,
  1604. ResultWas::OfType type )
  1605. : m_info( macroName, lineInfo, type )
  1606. {}
  1607. template<typename T>
  1608. MessageBuilder& operator << ( T const& value ) {
  1609. m_stream << value;
  1610. return *this;
  1611. }
  1612. MessageInfo m_info;
  1613. std::ostringstream m_stream;
  1614. };
  1615. class ScopedMessage {
  1616. public:
  1617. ScopedMessage( MessageBuilder const& builder );
  1618. ScopedMessage( ScopedMessage const& other );
  1619. ~ScopedMessage();
  1620. MessageInfo m_info;
  1621. };
  1622. } // end namespace Catch
  1623. // #included from: catch_interfaces_capture.h
  1624. #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
  1625. #include <string>
  1626. namespace Catch {
  1627. class TestCase;
  1628. class AssertionResult;
  1629. struct AssertionInfo;
  1630. struct SectionInfo;
  1631. struct SectionEndInfo;
  1632. struct MessageInfo;
  1633. class ScopedMessageBuilder;
  1634. struct Counts;
  1635. struct IResultCapture {
  1636. virtual ~IResultCapture();
  1637. virtual void assertionEnded( AssertionResult const& result ) = 0;
  1638. virtual bool sectionStarted( SectionInfo const& sectionInfo,
  1639. Counts& assertions ) = 0;
  1640. virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
  1641. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
  1642. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  1643. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  1644. virtual std::string getCurrentTestName() const = 0;
  1645. virtual const AssertionResult* getLastResult() const = 0;
  1646. virtual void handleFatalErrorCondition( std::string const& message ) = 0;
  1647. };
  1648. IResultCapture& getResultCapture();
  1649. }
  1650. // #included from: catch_debugger.h
  1651. #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
  1652. // #included from: catch_platform.h
  1653. #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED
  1654. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  1655. # define CATCH_PLATFORM_MAC
  1656. #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  1657. # define CATCH_PLATFORM_IPHONE
  1658. #elif defined(linux) || defined(__linux) || defined(__linux__)
  1659. # define CATCH_PLATFORM_LINUX
  1660. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  1661. # define CATCH_PLATFORM_WINDOWS
  1662. # if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
  1663. # define CATCH_DEFINES_NOMINMAX
  1664. # endif
  1665. # if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
  1666. # define CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  1667. # endif
  1668. #endif
  1669. #include <string>
  1670. namespace Catch{
  1671. bool isDebuggerActive();
  1672. void writeToDebugConsole( std::string const& text );
  1673. }
  1674. #ifdef CATCH_PLATFORM_MAC
  1675. // The following code snippet based on:
  1676. // http://cocoawithlove.com/2008/03/break-into-debugger.html
  1677. #if defined(__ppc64__) || defined(__ppc__)
  1678. #define CATCH_TRAP() \
  1679. __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  1680. : : : "memory","r0","r3","r4" )
  1681. #else
  1682. #define CATCH_TRAP() __asm__("int $3\n" : : )
  1683. #endif
  1684. #elif defined(CATCH_PLATFORM_LINUX)
  1685. // If we can use inline assembler, do it because this allows us to break
  1686. // directly at the location of the failing check instead of breaking inside
  1687. // raise() called from it, i.e. one stack frame below.
  1688. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  1689. #define CATCH_TRAP() asm volatile ("int $3")
  1690. #else // Fall back to the generic way.
  1691. #include <signal.h>
  1692. #define CATCH_TRAP() raise(SIGTRAP)
  1693. #endif
  1694. #elif defined(_MSC_VER)
  1695. #define CATCH_TRAP() __debugbreak()
  1696. #elif defined(__MINGW32__)
  1697. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  1698. #define CATCH_TRAP() DebugBreak()
  1699. #endif
  1700. #ifdef CATCH_TRAP
  1701. #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
  1702. #else
  1703. #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
  1704. #endif
  1705. // #included from: catch_interfaces_runner.h
  1706. #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
  1707. namespace Catch {
  1708. class TestCase;
  1709. struct IRunner {
  1710. virtual ~IRunner();
  1711. virtual bool aborting() const = 0;
  1712. };
  1713. }
  1714. // #included from: catch_type_traits.hpp
  1715. #define TWOBLUECUBES_CATCH_TYPE_TRAITS_HPP_INCLUDED
  1716. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  1717. #include <type_traits>
  1718. #endif
  1719. namespace Catch {
  1720. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  1721. template <typename T>
  1722. using add_lvalue_reference = std::add_lvalue_reference<T>;
  1723. template <typename T>
  1724. using add_const = std::add_const<T>;
  1725. #else
  1726. template <typename T>
  1727. struct add_const {
  1728. typedef const T type;
  1729. };
  1730. template <typename T>
  1731. struct add_lvalue_reference {
  1732. typedef T& type;
  1733. };
  1734. template <typename T>
  1735. struct add_lvalue_reference<T&> {
  1736. typedef T& type;
  1737. };
  1738. // No && overload, because that is C++11, in which case we have
  1739. // proper type_traits implementation from the standard library
  1740. #endif
  1741. }
  1742. #if defined(CATCH_CONFIG_FAST_COMPILE)
  1743. ///////////////////////////////////////////////////////////////////////////////
  1744. // We can speedup compilation significantly by breaking into debugger lower in
  1745. // the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
  1746. // macro in each assertion
  1747. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1748. resultBuilder.react();
  1749. #else
  1750. ///////////////////////////////////////////////////////////////////////////////
  1751. // In the event of a failure works out if the debugger needs to be invoked
  1752. // and/or an exception thrown and takes appropriate action.
  1753. // This needs to be done as a macro so the debugger will stop in the user
  1754. // source code rather than in Catch library code
  1755. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1756. if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
  1757. resultBuilder.react();
  1758. #endif
  1759. ///////////////////////////////////////////////////////////////////////////////
  1760. #define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
  1761. do { \
  1762. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
  1763. try { \
  1764. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1765. ( __catchResult <= expr ).endExpression(); \
  1766. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1767. } \
  1768. catch( ... ) { \
  1769. __catchResult.useActiveException( resultDisposition ); \
  1770. } \
  1771. INTERNAL_CATCH_REACT( __catchResult ) \
  1772. } 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
  1773. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1774. ///////////////////////////////////////////////////////////////////////////////
  1775. #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
  1776. INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
  1777. if( Catch::getResultCapture().getLastResult()->succeeded() )
  1778. ///////////////////////////////////////////////////////////////////////////////
  1779. #define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
  1780. INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
  1781. if( !Catch::getResultCapture().getLastResult()->succeeded() )
  1782. ///////////////////////////////////////////////////////////////////////////////
  1783. #define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
  1784. do { \
  1785. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
  1786. try { \
  1787. static_cast<void>(expr); \
  1788. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1789. } \
  1790. catch( ... ) { \
  1791. __catchResult.useActiveException( resultDisposition ); \
  1792. } \
  1793. INTERNAL_CATCH_REACT( __catchResult ) \
  1794. } while( Catch::alwaysFalse() )
  1795. ///////////////////////////////////////////////////////////////////////////////
  1796. #define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \
  1797. do { \
  1798. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
  1799. if( __catchResult.allowThrows() ) \
  1800. try { \
  1801. static_cast<void>(expr); \
  1802. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1803. } \
  1804. catch( ... ) { \
  1805. __catchResult.captureExpectedException( matcher ); \
  1806. } \
  1807. else \
  1808. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1809. INTERNAL_CATCH_REACT( __catchResult ) \
  1810. } while( Catch::alwaysFalse() )
  1811. ///////////////////////////////////////////////////////////////////////////////
  1812. #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
  1813. do { \
  1814. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr ", " #exceptionType, resultDisposition ); \
  1815. if( __catchResult.allowThrows() ) \
  1816. try { \
  1817. static_cast<void>(expr); \
  1818. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1819. } \
  1820. catch( Catch::add_const<Catch::add_lvalue_reference<exceptionType>::type>::type ) { \
  1821. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1822. } \
  1823. catch( ... ) { \
  1824. __catchResult.useActiveException( resultDisposition ); \
  1825. } \
  1826. else \
  1827. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1828. INTERNAL_CATCH_REACT( __catchResult ) \
  1829. } while( Catch::alwaysFalse() )
  1830. ///////////////////////////////////////////////////////////////////////////////
  1831. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  1832. #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \
  1833. do { \
  1834. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1835. __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
  1836. __catchResult.captureResult( messageType ); \
  1837. INTERNAL_CATCH_REACT( __catchResult ) \
  1838. } while( Catch::alwaysFalse() )
  1839. #else
  1840. #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \
  1841. do { \
  1842. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1843. __catchResult << log + ::Catch::StreamEndStop(); \
  1844. __catchResult.captureResult( messageType ); \
  1845. INTERNAL_CATCH_REACT( __catchResult ) \
  1846. } while( Catch::alwaysFalse() )
  1847. #endif
  1848. ///////////////////////////////////////////////////////////////////////////////
  1849. #define INTERNAL_CATCH_INFO( log, macroName ) \
  1850. Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
  1851. ///////////////////////////////////////////////////////////////////////////////
  1852. #define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \
  1853. do { \
  1854. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
  1855. try { \
  1856. __catchResult.captureMatch( arg, matcher, #matcher ); \
  1857. } catch( ... ) { \
  1858. __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
  1859. } \
  1860. INTERNAL_CATCH_REACT( __catchResult ) \
  1861. } while( Catch::alwaysFalse() )
  1862. // #included from: internal/catch_section.h
  1863. #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
  1864. // #included from: catch_section_info.h
  1865. #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
  1866. // #included from: catch_totals.hpp
  1867. #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
  1868. #include <cstddef>
  1869. namespace Catch {
  1870. struct Counts {
  1871. Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
  1872. Counts operator - ( Counts const& other ) const {
  1873. Counts diff;
  1874. diff.passed = passed - other.passed;
  1875. diff.failed = failed - other.failed;
  1876. diff.failedButOk = failedButOk - other.failedButOk;
  1877. return diff;
  1878. }
  1879. Counts& operator += ( Counts const& other ) {
  1880. passed += other.passed;
  1881. failed += other.failed;
  1882. failedButOk += other.failedButOk;
  1883. return *this;
  1884. }
  1885. std::size_t total() const {
  1886. return passed + failed + failedButOk;
  1887. }
  1888. bool allPassed() const {
  1889. return failed == 0 && failedButOk == 0;
  1890. }
  1891. bool allOk() const {
  1892. return failed == 0;
  1893. }
  1894. std::size_t passed;
  1895. std::size_t failed;
  1896. std::size_t failedButOk;
  1897. };
  1898. struct Totals {
  1899. Totals operator - ( Totals const& other ) const {
  1900. Totals diff;
  1901. diff.assertions = assertions - other.assertions;
  1902. diff.testCases = testCases - other.testCases;
  1903. return diff;
  1904. }
  1905. Totals delta( Totals const& prevTotals ) const {
  1906. Totals diff = *this - prevTotals;
  1907. if( diff.assertions.failed > 0 )
  1908. ++diff.testCases.failed;
  1909. else if( diff.assertions.failedButOk > 0 )
  1910. ++diff.testCases.failedButOk;
  1911. else
  1912. ++diff.testCases.passed;
  1913. return diff;
  1914. }
  1915. Totals& operator += ( Totals const& other ) {
  1916. assertions += other.assertions;
  1917. testCases += other.testCases;
  1918. return *this;
  1919. }
  1920. Counts assertions;
  1921. Counts testCases;
  1922. };
  1923. }
  1924. #include <string>
  1925. namespace Catch {
  1926. struct SectionInfo {
  1927. SectionInfo
  1928. ( SourceLineInfo const& _lineInfo,
  1929. std::string const& _name,
  1930. std::string const& _description = std::string() );
  1931. std::string name;
  1932. std::string description;
  1933. SourceLineInfo lineInfo;
  1934. };
  1935. struct SectionEndInfo {
  1936. SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
  1937. : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
  1938. {}
  1939. SectionInfo sectionInfo;
  1940. Counts prevAssertions;
  1941. double durationInSeconds;
  1942. };
  1943. } // end namespace Catch
  1944. // #included from: catch_timer.h
  1945. #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED
  1946. #ifdef CATCH_PLATFORM_WINDOWS
  1947. typedef unsigned long long uint64_t;
  1948. #else
  1949. #include <stdint.h>
  1950. #endif
  1951. namespace Catch {
  1952. class Timer {
  1953. public:
  1954. Timer() : m_ticks( 0 ) {}
  1955. void start();
  1956. unsigned int getElapsedMicroseconds() const;
  1957. unsigned int getElapsedMilliseconds() const;
  1958. double getElapsedSeconds() const;
  1959. private:
  1960. uint64_t m_ticks;
  1961. };
  1962. } // namespace Catch
  1963. #include <string>
  1964. namespace Catch {
  1965. class Section : NonCopyable {
  1966. public:
  1967. Section( SectionInfo const& info );
  1968. ~Section();
  1969. // This indicates whether the section should be executed or not
  1970. operator bool() const;
  1971. private:
  1972. SectionInfo m_info;
  1973. std::string m_name;
  1974. Counts m_assertions;
  1975. bool m_sectionIncluded;
  1976. Timer m_timer;
  1977. };
  1978. } // end namespace Catch
  1979. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  1980. #define INTERNAL_CATCH_SECTION( ... ) \
  1981. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
  1982. #else
  1983. #define INTERNAL_CATCH_SECTION( name, desc ) \
  1984. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
  1985. #endif
  1986. // #included from: internal/catch_generators.hpp
  1987. #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
  1988. #include <iterator>
  1989. #include <vector>
  1990. #include <string>
  1991. #include <stdlib.h>
  1992. namespace Catch {
  1993. template<typename T>
  1994. struct IGenerator {
  1995. virtual ~IGenerator() {}
  1996. virtual T getValue( std::size_t index ) const = 0;
  1997. virtual std::size_t size () const = 0;
  1998. };
  1999. template<typename T>
  2000. class BetweenGenerator : public IGenerator<T> {
  2001. public:
  2002. BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
  2003. virtual T getValue( std::size_t index ) const {
  2004. return m_from+static_cast<int>( index );
  2005. }
  2006. virtual std::size_t size() const {
  2007. return static_cast<std::size_t>( 1+m_to-m_from );
  2008. }
  2009. private:
  2010. T m_from;
  2011. T m_to;
  2012. };
  2013. template<typename T>
  2014. class ValuesGenerator : public IGenerator<T> {
  2015. public:
  2016. ValuesGenerator(){}
  2017. void add( T value ) {
  2018. m_values.push_back( value );
  2019. }
  2020. virtual T getValue( std::size_t index ) const {
  2021. return m_values[index];
  2022. }
  2023. virtual std::size_t size() const {
  2024. return m_values.size();
  2025. }
  2026. private:
  2027. std::vector<T> m_values;
  2028. };
  2029. template<typename T>
  2030. class CompositeGenerator {
  2031. public:
  2032. CompositeGenerator() : m_totalSize( 0 ) {}
  2033. // *** Move semantics, similar to auto_ptr ***
  2034. CompositeGenerator( CompositeGenerator& other )
  2035. : m_fileInfo( other.m_fileInfo ),
  2036. m_totalSize( 0 )
  2037. {
  2038. move( other );
  2039. }
  2040. CompositeGenerator& setFileInfo( const char* fileInfo ) {
  2041. m_fileInfo = fileInfo;
  2042. return *this;
  2043. }
  2044. ~CompositeGenerator() {
  2045. deleteAll( m_composed );
  2046. }
  2047. operator T () const {
  2048. size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
  2049. typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
  2050. typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
  2051. for( size_t index = 0; it != itEnd; ++it )
  2052. {
  2053. const IGenerator<T>* generator = *it;
  2054. if( overallIndex >= index && overallIndex < index + generator->size() )
  2055. {
  2056. return generator->getValue( overallIndex-index );
  2057. }
  2058. index += generator->size();
  2059. }
  2060. CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
  2061. 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
  2062. }
  2063. void add( const IGenerator<T>* generator ) {
  2064. m_totalSize += generator->size();
  2065. m_composed.push_back( generator );
  2066. }
  2067. CompositeGenerator& then( CompositeGenerator& other ) {
  2068. move( other );
  2069. return *this;
  2070. }
  2071. CompositeGenerator& then( T value ) {
  2072. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2073. valuesGen->add( value );
  2074. add( valuesGen );
  2075. return *this;
  2076. }
  2077. private:
  2078. void move( CompositeGenerator& other ) {
  2079. std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
  2080. m_totalSize += other.m_totalSize;
  2081. other.m_composed.clear();
  2082. }
  2083. std::vector<const IGenerator<T>*> m_composed;
  2084. std::string m_fileInfo;
  2085. size_t m_totalSize;
  2086. };
  2087. namespace Generators
  2088. {
  2089. template<typename T>
  2090. CompositeGenerator<T> between( T from, T to ) {
  2091. CompositeGenerator<T> generators;
  2092. generators.add( new BetweenGenerator<T>( from, to ) );
  2093. return generators;
  2094. }
  2095. template<typename T>
  2096. CompositeGenerator<T> values( T val1, T val2 ) {
  2097. CompositeGenerator<T> generators;
  2098. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2099. valuesGen->add( val1 );
  2100. valuesGen->add( val2 );
  2101. generators.add( valuesGen );
  2102. return generators;
  2103. }
  2104. template<typename T>
  2105. CompositeGenerator<T> values( T val1, T val2, T val3 ){
  2106. CompositeGenerator<T> generators;
  2107. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2108. valuesGen->add( val1 );
  2109. valuesGen->add( val2 );
  2110. valuesGen->add( val3 );
  2111. generators.add( valuesGen );
  2112. return generators;
  2113. }
  2114. template<typename T>
  2115. CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
  2116. CompositeGenerator<T> generators;
  2117. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2118. valuesGen->add( val1 );
  2119. valuesGen->add( val2 );
  2120. valuesGen->add( val3 );
  2121. valuesGen->add( val4 );
  2122. generators.add( valuesGen );
  2123. return generators;
  2124. }
  2125. } // end namespace Generators
  2126. using namespace Generators;
  2127. } // end namespace Catch
  2128. #define INTERNAL_CATCH_LINESTR2( line ) #line
  2129. #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
  2130. #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
  2131. // #included from: internal/catch_interfaces_exception.h
  2132. #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
  2133. #include <string>
  2134. #include <vector>
  2135. // #included from: catch_interfaces_registry_hub.h
  2136. #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
  2137. #include <string>
  2138. namespace Catch {
  2139. class TestCase;
  2140. struct ITestCaseRegistry;
  2141. struct IExceptionTranslatorRegistry;
  2142. struct IExceptionTranslator;
  2143. struct IReporterRegistry;
  2144. struct IReporterFactory;
  2145. struct IRegistryHub {
  2146. virtual ~IRegistryHub();
  2147. virtual IReporterRegistry const& getReporterRegistry() const = 0;
  2148. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  2149. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
  2150. };
  2151. struct IMutableRegistryHub {
  2152. virtual ~IMutableRegistryHub();
  2153. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
  2154. virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
  2155. virtual void registerTest( TestCase const& testInfo ) = 0;
  2156. virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
  2157. };
  2158. IRegistryHub& getRegistryHub();
  2159. IMutableRegistryHub& getMutableRegistryHub();
  2160. void cleanUp();
  2161. std::string translateActiveException();
  2162. }
  2163. namespace Catch {
  2164. typedef std::string(*exceptionTranslateFunction)();
  2165. struct IExceptionTranslator;
  2166. typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
  2167. struct IExceptionTranslator {
  2168. virtual ~IExceptionTranslator();
  2169. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  2170. };
  2171. struct IExceptionTranslatorRegistry {
  2172. virtual ~IExceptionTranslatorRegistry();
  2173. virtual std::string translateActiveException() const = 0;
  2174. };
  2175. class ExceptionTranslatorRegistrar {
  2176. template<typename T>
  2177. class ExceptionTranslator : public IExceptionTranslator {
  2178. public:
  2179. ExceptionTranslator( std::string(*translateFunction)( T& ) )
  2180. : m_translateFunction( translateFunction )
  2181. {}
  2182. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
  2183. try {
  2184. if( it == itEnd )
  2185. throw;
  2186. else
  2187. return (*it)->translate( it+1, itEnd );
  2188. }
  2189. catch( T& ex ) {
  2190. return m_translateFunction( ex );
  2191. }
  2192. }
  2193. protected:
  2194. std::string(*m_translateFunction)( T& );
  2195. };
  2196. public:
  2197. template<typename T>
  2198. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
  2199. getMutableRegistryHub().registerTranslator
  2200. ( new ExceptionTranslator<T>( translateFunction ) );
  2201. }
  2202. };
  2203. }
  2204. ///////////////////////////////////////////////////////////////////////////////
  2205. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  2206. static std::string translatorName( signature ); \
  2207. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\
  2208. static std::string translatorName( signature )
  2209. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  2210. // #included from: internal/catch_approx.hpp
  2211. #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
  2212. #include <cmath>
  2213. #include <limits>
  2214. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2215. #include <type_traits>
  2216. #endif
  2217. namespace Catch {
  2218. namespace Detail {
  2219. class Approx {
  2220. public:
  2221. explicit Approx ( double value )
  2222. : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
  2223. m_margin( 0.0 ),
  2224. m_scale( 1.0 ),
  2225. m_value( value )
  2226. {}
  2227. Approx( Approx const& other )
  2228. : m_epsilon( other.m_epsilon ),
  2229. m_margin( other.m_margin ),
  2230. m_scale( other.m_scale ),
  2231. m_value( other.m_value )
  2232. {}
  2233. static Approx custom() {
  2234. return Approx( 0 );
  2235. }
  2236. Approx operator()( double value ) {
  2237. Approx approx( value );
  2238. approx.epsilon( m_epsilon );
  2239. approx.margin( m_margin );
  2240. approx.scale( m_scale );
  2241. return approx;
  2242. }
  2243. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2244. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2245. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2246. // Thanks to Richard Harris for his help refining this formula
  2247. auto lhs_v = double(lhs);
  2248. 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)));
  2249. if (relativeOK) {
  2250. return true;
  2251. }
  2252. return std::fabs(lhs_v - rhs.m_value) < rhs.m_margin;
  2253. }
  2254. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2255. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2256. return operator==( rhs, lhs );
  2257. }
  2258. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2259. friend bool operator != ( T lhs, Approx const& rhs ) {
  2260. return !operator==( lhs, rhs );
  2261. }
  2262. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2263. friend bool operator != ( Approx const& lhs, T rhs ) {
  2264. return !operator==( rhs, lhs );
  2265. }
  2266. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2267. friend bool operator <= ( T lhs, Approx const& rhs )
  2268. {
  2269. return double(lhs) < rhs.m_value || lhs == rhs;
  2270. }
  2271. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2272. friend bool operator <= ( Approx const& lhs, T rhs )
  2273. {
  2274. return lhs.m_value < double(rhs) || lhs == rhs;
  2275. }
  2276. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2277. friend bool operator >= ( T lhs, Approx const& rhs )
  2278. {
  2279. return double(lhs) > rhs.m_value || lhs == rhs;
  2280. }
  2281. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2282. friend bool operator >= ( Approx const& lhs, T rhs )
  2283. {
  2284. return lhs.m_value > double(rhs) || lhs == rhs;
  2285. }
  2286. #else
  2287. friend bool operator == ( double lhs, Approx const& rhs ) {
  2288. // Thanks to Richard Harris for his help refining this formula
  2289. bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) );
  2290. if (relativeOK) {
  2291. return true;
  2292. }
  2293. return std::fabs(lhs - rhs.m_value) < rhs.m_margin;
  2294. }
  2295. friend bool operator == ( Approx const& lhs, double rhs ) {
  2296. return operator==( rhs, lhs );
  2297. }
  2298. friend bool operator != ( double lhs, Approx const& rhs ) {
  2299. return !operator==( lhs, rhs );
  2300. }
  2301. friend bool operator != ( Approx const& lhs, double rhs ) {
  2302. return !operator==( rhs, lhs );
  2303. }
  2304. friend bool operator <= ( double lhs, Approx const& rhs )
  2305. {
  2306. return lhs < rhs.m_value || lhs == rhs;
  2307. }
  2308. friend bool operator <= ( Approx const& lhs, double rhs )
  2309. {
  2310. return lhs.m_value < rhs || lhs == rhs;
  2311. }
  2312. friend bool operator >= ( double lhs, Approx const& rhs )
  2313. {
  2314. return lhs > rhs.m_value || lhs == rhs;
  2315. }
  2316. friend bool operator >= ( Approx const& lhs, double rhs )
  2317. {
  2318. return lhs.m_value > rhs || lhs == rhs;
  2319. }
  2320. #endif
  2321. Approx& epsilon( double newEpsilon ) {
  2322. m_epsilon = newEpsilon;
  2323. return *this;
  2324. }
  2325. Approx& margin( double newMargin ) {
  2326. m_margin = newMargin;
  2327. return *this;
  2328. }
  2329. Approx& scale( double newScale ) {
  2330. m_scale = newScale;
  2331. return *this;
  2332. }
  2333. std::string toString() const {
  2334. std::ostringstream oss;
  2335. oss << "Approx( " << Catch::toString( m_value ) << " )";
  2336. return oss.str();
  2337. }
  2338. private:
  2339. double m_epsilon;
  2340. double m_margin;
  2341. double m_scale;
  2342. double m_value;
  2343. };
  2344. }
  2345. template<>
  2346. inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
  2347. return value.toString();
  2348. }
  2349. } // end namespace Catch
  2350. // #included from: internal/catch_matchers_string.h
  2351. #define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
  2352. namespace Catch {
  2353. namespace Matchers {
  2354. namespace StdString {
  2355. struct CasedString
  2356. {
  2357. CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
  2358. std::string adjustString( std::string const& str ) const;
  2359. std::string caseSensitivitySuffix() const;
  2360. CaseSensitive::Choice m_caseSensitivity;
  2361. std::string m_str;
  2362. };
  2363. struct StringMatcherBase : MatcherBase<std::string> {
  2364. StringMatcherBase( std::string operation, CasedString const& comparator );
  2365. virtual std::string describe() const CATCH_OVERRIDE;
  2366. CasedString m_comparator;
  2367. std::string m_operation;
  2368. };
  2369. struct EqualsMatcher : StringMatcherBase {
  2370. EqualsMatcher( CasedString const& comparator );
  2371. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2372. };
  2373. struct ContainsMatcher : StringMatcherBase {
  2374. ContainsMatcher( CasedString const& comparator );
  2375. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2376. };
  2377. struct StartsWithMatcher : StringMatcherBase {
  2378. StartsWithMatcher( CasedString const& comparator );
  2379. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2380. };
  2381. struct EndsWithMatcher : StringMatcherBase {
  2382. EndsWithMatcher( CasedString const& comparator );
  2383. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2384. };
  2385. } // namespace StdString
  2386. // The following functions create the actual matcher objects.
  2387. // This allows the types to be inferred
  2388. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2389. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2390. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2391. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2392. } // namespace Matchers
  2393. } // namespace Catch
  2394. // #included from: internal/catch_matchers_vector.h
  2395. #define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED
  2396. namespace Catch {
  2397. namespace Matchers {
  2398. namespace Vector {
  2399. template<typename T>
  2400. struct ContainsElementMatcher : MatcherBase<std::vector<T>, T> {
  2401. ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
  2402. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2403. return std::find(v.begin(), v.end(), m_comparator) != v.end();
  2404. }
  2405. virtual std::string describe() const CATCH_OVERRIDE {
  2406. return "Contains: " + Catch::toString( m_comparator );
  2407. }
  2408. T const& m_comparator;
  2409. };
  2410. template<typename T>
  2411. struct ContainsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2412. ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2413. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2414. // !TBD: see note in EqualsMatcher
  2415. if (m_comparator.size() > v.size())
  2416. return false;
  2417. for (size_t i = 0; i < m_comparator.size(); ++i)
  2418. if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end())
  2419. return false;
  2420. return true;
  2421. }
  2422. virtual std::string describe() const CATCH_OVERRIDE {
  2423. return "Contains: " + Catch::toString( m_comparator );
  2424. }
  2425. std::vector<T> const& m_comparator;
  2426. };
  2427. template<typename T>
  2428. struct EqualsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2429. EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2430. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2431. // !TBD: This currently works if all elements can be compared using !=
  2432. // - a more general approach would be via a compare template that defaults
  2433. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  2434. // - then just call that directly
  2435. if (m_comparator.size() != v.size())
  2436. return false;
  2437. for (size_t i = 0; i < v.size(); ++i)
  2438. if (m_comparator[i] != v[i])
  2439. return false;
  2440. return true;
  2441. }
  2442. virtual std::string describe() const CATCH_OVERRIDE {
  2443. return "Equals: " + Catch::toString( m_comparator );
  2444. }
  2445. std::vector<T> const& m_comparator;
  2446. };
  2447. } // namespace Vector
  2448. // The following functions create the actual matcher objects.
  2449. // This allows the types to be inferred
  2450. template<typename T>
  2451. Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
  2452. return Vector::ContainsMatcher<T>( comparator );
  2453. }
  2454. template<typename T>
  2455. Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) {
  2456. return Vector::ContainsElementMatcher<T>( comparator );
  2457. }
  2458. template<typename T>
  2459. Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
  2460. return Vector::EqualsMatcher<T>( comparator );
  2461. }
  2462. } // namespace Matchers
  2463. } // namespace Catch
  2464. // #included from: internal/catch_interfaces_tag_alias_registry.h
  2465. #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
  2466. // #included from: catch_tag_alias.h
  2467. #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED
  2468. #include <string>
  2469. namespace Catch {
  2470. struct TagAlias {
  2471. TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
  2472. std::string tag;
  2473. SourceLineInfo lineInfo;
  2474. };
  2475. struct RegistrarForTagAliases {
  2476. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  2477. };
  2478. } // end namespace Catch
  2479. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); }
  2480. // #included from: catch_option.hpp
  2481. #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
  2482. namespace Catch {
  2483. // An optional type
  2484. template<typename T>
  2485. class Option {
  2486. public:
  2487. Option() : nullableValue( CATCH_NULL ) {}
  2488. Option( T const& _value )
  2489. : nullableValue( new( storage ) T( _value ) )
  2490. {}
  2491. Option( Option const& _other )
  2492. : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
  2493. {}
  2494. ~Option() {
  2495. reset();
  2496. }
  2497. Option& operator= ( Option const& _other ) {
  2498. if( &_other != this ) {
  2499. reset();
  2500. if( _other )
  2501. nullableValue = new( storage ) T( *_other );
  2502. }
  2503. return *this;
  2504. }
  2505. Option& operator = ( T const& _value ) {
  2506. reset();
  2507. nullableValue = new( storage ) T( _value );
  2508. return *this;
  2509. }
  2510. void reset() {
  2511. if( nullableValue )
  2512. nullableValue->~T();
  2513. nullableValue = CATCH_NULL;
  2514. }
  2515. T& operator*() { return *nullableValue; }
  2516. T const& operator*() const { return *nullableValue; }
  2517. T* operator->() { return nullableValue; }
  2518. const T* operator->() const { return nullableValue; }
  2519. T valueOr( T const& defaultValue ) const {
  2520. return nullableValue ? *nullableValue : defaultValue;
  2521. }
  2522. bool some() const { return nullableValue != CATCH_NULL; }
  2523. bool none() const { return nullableValue == CATCH_NULL; }
  2524. bool operator !() const { return nullableValue == CATCH_NULL; }
  2525. operator SafeBool::type() const {
  2526. return SafeBool::makeSafe( some() );
  2527. }
  2528. private:
  2529. T* nullableValue;
  2530. char storage[sizeof(T)];
  2531. };
  2532. } // end namespace Catch
  2533. namespace Catch {
  2534. struct ITagAliasRegistry {
  2535. virtual ~ITagAliasRegistry();
  2536. virtual Option<TagAlias> find( std::string const& alias ) const = 0;
  2537. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  2538. static ITagAliasRegistry const& get();
  2539. };
  2540. } // end namespace Catch
  2541. // These files are included here so the single_include script doesn't put them
  2542. // in the conditionally compiled sections
  2543. // #included from: internal/catch_test_case_info.h
  2544. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
  2545. #include <string>
  2546. #include <set>
  2547. #ifdef __clang__
  2548. #pragma clang diagnostic push
  2549. #pragma clang diagnostic ignored "-Wpadded"
  2550. #endif
  2551. namespace Catch {
  2552. struct ITestCase;
  2553. struct TestCaseInfo {
  2554. enum SpecialProperties{
  2555. None = 0,
  2556. IsHidden = 1 << 1,
  2557. ShouldFail = 1 << 2,
  2558. MayFail = 1 << 3,
  2559. Throws = 1 << 4,
  2560. NonPortable = 1 << 5
  2561. };
  2562. TestCaseInfo( std::string const& _name,
  2563. std::string const& _className,
  2564. std::string const& _description,
  2565. std::set<std::string> const& _tags,
  2566. SourceLineInfo const& _lineInfo );
  2567. TestCaseInfo( TestCaseInfo const& other );
  2568. friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
  2569. bool isHidden() const;
  2570. bool throws() const;
  2571. bool okToFail() const;
  2572. bool expectedToFail() const;
  2573. std::string name;
  2574. std::string className;
  2575. std::string description;
  2576. std::set<std::string> tags;
  2577. std::set<std::string> lcaseTags;
  2578. std::string tagsAsString;
  2579. SourceLineInfo lineInfo;
  2580. SpecialProperties properties;
  2581. };
  2582. class TestCase : public TestCaseInfo {
  2583. public:
  2584. TestCase( ITestCase* testCase, TestCaseInfo const& info );
  2585. TestCase( TestCase const& other );
  2586. TestCase withName( std::string const& _newName ) const;
  2587. void invoke() const;
  2588. TestCaseInfo const& getTestCaseInfo() const;
  2589. void swap( TestCase& other );
  2590. bool operator == ( TestCase const& other ) const;
  2591. bool operator < ( TestCase const& other ) const;
  2592. TestCase& operator = ( TestCase const& other );
  2593. private:
  2594. Ptr<ITestCase> test;
  2595. };
  2596. TestCase makeTestCase( ITestCase* testCase,
  2597. std::string const& className,
  2598. std::string const& name,
  2599. std::string const& description,
  2600. SourceLineInfo const& lineInfo );
  2601. }
  2602. #ifdef __clang__
  2603. #pragma clang diagnostic pop
  2604. #endif
  2605. #ifdef __OBJC__
  2606. // #included from: internal/catch_objc.hpp
  2607. #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
  2608. #import <objc/runtime.h>
  2609. #include <string>
  2610. // NB. Any general catch headers included here must be included
  2611. // in catch.hpp first to make sure they are included by the single
  2612. // header for non obj-usage
  2613. ///////////////////////////////////////////////////////////////////////////////
  2614. // This protocol is really only here for (self) documenting purposes, since
  2615. // all its methods are optional.
  2616. @protocol OcFixture
  2617. @optional
  2618. -(void) setUp;
  2619. -(void) tearDown;
  2620. @end
  2621. namespace Catch {
  2622. class OcMethod : public SharedImpl<ITestCase> {
  2623. public:
  2624. OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
  2625. virtual void invoke() const {
  2626. id obj = [[m_cls alloc] init];
  2627. performOptionalSelector( obj, @selector(setUp) );
  2628. performOptionalSelector( obj, m_sel );
  2629. performOptionalSelector( obj, @selector(tearDown) );
  2630. arcSafeRelease( obj );
  2631. }
  2632. private:
  2633. virtual ~OcMethod() {}
  2634. Class m_cls;
  2635. SEL m_sel;
  2636. };
  2637. namespace Detail{
  2638. inline std::string getAnnotation( Class cls,
  2639. std::string const& annotationName,
  2640. std::string const& testCaseName ) {
  2641. NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
  2642. SEL sel = NSSelectorFromString( selStr );
  2643. arcSafeRelease( selStr );
  2644. id value = performOptionalSelector( cls, sel );
  2645. if( value )
  2646. return [(NSString*)value UTF8String];
  2647. return "";
  2648. }
  2649. }
  2650. inline size_t registerTestMethods() {
  2651. size_t noTestMethods = 0;
  2652. int noClasses = objc_getClassList( CATCH_NULL, 0 );
  2653. Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
  2654. objc_getClassList( classes, noClasses );
  2655. for( int c = 0; c < noClasses; c++ ) {
  2656. Class cls = classes[c];
  2657. {
  2658. u_int count;
  2659. Method* methods = class_copyMethodList( cls, &count );
  2660. for( u_int m = 0; m < count ; m++ ) {
  2661. SEL selector = method_getName(methods[m]);
  2662. std::string methodName = sel_getName(selector);
  2663. if( startsWith( methodName, "Catch_TestCase_" ) ) {
  2664. std::string testCaseName = methodName.substr( 15 );
  2665. std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
  2666. std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
  2667. const char* className = class_getName( cls );
  2668. getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
  2669. noTestMethods++;
  2670. }
  2671. }
  2672. free(methods);
  2673. }
  2674. }
  2675. return noTestMethods;
  2676. }
  2677. namespace Matchers {
  2678. namespace Impl {
  2679. namespace NSStringMatchers {
  2680. template<typename MatcherT>
  2681. struct StringHolder : MatcherImpl<MatcherT, NSString*>{
  2682. StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
  2683. StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
  2684. StringHolder() {
  2685. arcSafeRelease( m_substr );
  2686. }
  2687. NSString* m_substr;
  2688. };
  2689. struct Equals : StringHolder<Equals> {
  2690. Equals( NSString* substr ) : StringHolder( substr ){}
  2691. virtual bool match( ExpressionType const& str ) const {
  2692. return (str != nil || m_substr == nil ) &&
  2693. [str isEqualToString:m_substr];
  2694. }
  2695. virtual std::string toString() const {
  2696. return "equals string: " + Catch::toString( m_substr );
  2697. }
  2698. };
  2699. struct Contains : StringHolder<Contains> {
  2700. Contains( NSString* substr ) : StringHolder( substr ){}
  2701. virtual bool match( ExpressionType const& str ) const {
  2702. return (str != nil || m_substr == nil ) &&
  2703. [str rangeOfString:m_substr].location != NSNotFound;
  2704. }
  2705. virtual std::string toString() const {
  2706. return "contains string: " + Catch::toString( m_substr );
  2707. }
  2708. };
  2709. struct StartsWith : StringHolder<StartsWith> {
  2710. StartsWith( NSString* substr ) : StringHolder( substr ){}
  2711. virtual bool match( ExpressionType const& str ) const {
  2712. return (str != nil || m_substr == nil ) &&
  2713. [str rangeOfString:m_substr].location == 0;
  2714. }
  2715. virtual std::string toString() const {
  2716. return "starts with: " + Catch::toString( m_substr );
  2717. }
  2718. };
  2719. struct EndsWith : StringHolder<EndsWith> {
  2720. EndsWith( NSString* substr ) : StringHolder( substr ){}
  2721. virtual bool match( ExpressionType const& str ) const {
  2722. return (str != nil || m_substr == nil ) &&
  2723. [str rangeOfString:m_substr].location == [str length] - [m_substr length];
  2724. }
  2725. virtual std::string toString() const {
  2726. return "ends with: " + Catch::toString( m_substr );
  2727. }
  2728. };
  2729. } // namespace NSStringMatchers
  2730. } // namespace Impl
  2731. inline Impl::NSStringMatchers::Equals
  2732. Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
  2733. inline Impl::NSStringMatchers::Contains
  2734. Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
  2735. inline Impl::NSStringMatchers::StartsWith
  2736. StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
  2737. inline Impl::NSStringMatchers::EndsWith
  2738. EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
  2739. } // namespace Matchers
  2740. using namespace Matchers;
  2741. } // namespace Catch
  2742. ///////////////////////////////////////////////////////////////////////////////
  2743. #define OC_TEST_CASE( name, desc )\
  2744. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
  2745. {\
  2746. return @ name; \
  2747. }\
  2748. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
  2749. { \
  2750. return @ desc; \
  2751. } \
  2752. -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
  2753. #endif
  2754. #ifdef CATCH_IMPL
  2755. // !TBD: Move the leak detector code into a separate header
  2756. #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
  2757. #include <crtdbg.h>
  2758. class LeakDetector {
  2759. public:
  2760. LeakDetector() {
  2761. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  2762. flag |= _CRTDBG_LEAK_CHECK_DF;
  2763. flag |= _CRTDBG_ALLOC_MEM_DF;
  2764. _CrtSetDbgFlag(flag);
  2765. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  2766. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  2767. // Change this to leaking allocation's number to break there
  2768. _CrtSetBreakAlloc(-1);
  2769. }
  2770. };
  2771. #else
  2772. class LeakDetector {};
  2773. #endif
  2774. LeakDetector leakDetector;
  2775. // #included from: internal/catch_impl.hpp
  2776. #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
  2777. // Collect all the implementation files together here
  2778. // These are the equivalent of what would usually be cpp files
  2779. #ifdef __clang__
  2780. #pragma clang diagnostic push
  2781. #pragma clang diagnostic ignored "-Wweak-vtables"
  2782. #endif
  2783. // #included from: ../catch_session.hpp
  2784. #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
  2785. // #included from: internal/catch_commandline.hpp
  2786. #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
  2787. // #included from: catch_config.hpp
  2788. #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
  2789. // #included from: catch_test_spec_parser.hpp
  2790. #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  2791. #ifdef __clang__
  2792. #pragma clang diagnostic push
  2793. #pragma clang diagnostic ignored "-Wpadded"
  2794. #endif
  2795. // #included from: catch_test_spec.hpp
  2796. #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  2797. #ifdef __clang__
  2798. #pragma clang diagnostic push
  2799. #pragma clang diagnostic ignored "-Wpadded"
  2800. #endif
  2801. // #included from: catch_wildcard_pattern.hpp
  2802. #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2803. #include <stdexcept>
  2804. namespace Catch
  2805. {
  2806. class WildcardPattern {
  2807. enum WildcardPosition {
  2808. NoWildcard = 0,
  2809. WildcardAtStart = 1,
  2810. WildcardAtEnd = 2,
  2811. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2812. };
  2813. public:
  2814. WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
  2815. : m_caseSensitivity( caseSensitivity ),
  2816. m_wildcard( NoWildcard ),
  2817. m_pattern( adjustCase( pattern ) )
  2818. {
  2819. if( startsWith( m_pattern, '*' ) ) {
  2820. m_pattern = m_pattern.substr( 1 );
  2821. m_wildcard = WildcardAtStart;
  2822. }
  2823. if( endsWith( m_pattern, '*' ) ) {
  2824. m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
  2825. m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
  2826. }
  2827. }
  2828. virtual ~WildcardPattern();
  2829. virtual bool matches( std::string const& str ) const {
  2830. switch( m_wildcard ) {
  2831. case NoWildcard:
  2832. return m_pattern == adjustCase( str );
  2833. case WildcardAtStart:
  2834. return endsWith( adjustCase( str ), m_pattern );
  2835. case WildcardAtEnd:
  2836. return startsWith( adjustCase( str ), m_pattern );
  2837. case WildcardAtBothEnds:
  2838. return contains( adjustCase( str ), m_pattern );
  2839. }
  2840. #ifdef __clang__
  2841. #pragma clang diagnostic push
  2842. #pragma clang diagnostic ignored "-Wunreachable-code"
  2843. #endif
  2844. throw std::logic_error( "Unknown enum" );
  2845. #ifdef __clang__
  2846. #pragma clang diagnostic pop
  2847. #endif
  2848. }
  2849. private:
  2850. std::string adjustCase( std::string const& str ) const {
  2851. return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
  2852. }
  2853. CaseSensitive::Choice m_caseSensitivity;
  2854. WildcardPosition m_wildcard;
  2855. std::string m_pattern;
  2856. };
  2857. }
  2858. #include <string>
  2859. #include <vector>
  2860. namespace Catch {
  2861. class TestSpec {
  2862. struct Pattern : SharedImpl<> {
  2863. virtual ~Pattern();
  2864. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2865. };
  2866. class NamePattern : public Pattern {
  2867. public:
  2868. NamePattern( std::string const& name )
  2869. : m_wildcardPattern( toLower( name ), CaseSensitive::No )
  2870. {}
  2871. virtual ~NamePattern();
  2872. virtual bool matches( TestCaseInfo const& testCase ) const {
  2873. return m_wildcardPattern.matches( toLower( testCase.name ) );
  2874. }
  2875. private:
  2876. WildcardPattern m_wildcardPattern;
  2877. };
  2878. class TagPattern : public Pattern {
  2879. public:
  2880. TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
  2881. virtual ~TagPattern();
  2882. virtual bool matches( TestCaseInfo const& testCase ) const {
  2883. return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
  2884. }
  2885. private:
  2886. std::string m_tag;
  2887. };
  2888. class ExcludedPattern : public Pattern {
  2889. public:
  2890. ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
  2891. virtual ~ExcludedPattern();
  2892. virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
  2893. private:
  2894. Ptr<Pattern> m_underlyingPattern;
  2895. };
  2896. struct Filter {
  2897. std::vector<Ptr<Pattern> > m_patterns;
  2898. bool matches( TestCaseInfo const& testCase ) const {
  2899. // All patterns in a filter must match for the filter to be a match
  2900. for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
  2901. if( !(*it)->matches( testCase ) )
  2902. return false;
  2903. }
  2904. return true;
  2905. }
  2906. };
  2907. public:
  2908. bool hasFilters() const {
  2909. return !m_filters.empty();
  2910. }
  2911. bool matches( TestCaseInfo const& testCase ) const {
  2912. // A TestSpec matches if any filter matches
  2913. for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
  2914. if( it->matches( testCase ) )
  2915. return true;
  2916. return false;
  2917. }
  2918. private:
  2919. std::vector<Filter> m_filters;
  2920. friend class TestSpecParser;
  2921. };
  2922. }
  2923. #ifdef __clang__
  2924. #pragma clang diagnostic pop
  2925. #endif
  2926. namespace Catch {
  2927. class TestSpecParser {
  2928. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  2929. Mode m_mode;
  2930. bool m_exclusion;
  2931. std::size_t m_start, m_pos;
  2932. std::string m_arg;
  2933. std::vector<std::size_t> m_escapeChars;
  2934. TestSpec::Filter m_currentFilter;
  2935. TestSpec m_testSpec;
  2936. ITagAliasRegistry const* m_tagAliases;
  2937. public:
  2938. TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
  2939. TestSpecParser& parse( std::string const& arg ) {
  2940. m_mode = None;
  2941. m_exclusion = false;
  2942. m_start = std::string::npos;
  2943. m_arg = m_tagAliases->expandAliases( arg );
  2944. m_escapeChars.clear();
  2945. for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
  2946. visitChar( m_arg[m_pos] );
  2947. if( m_mode == Name )
  2948. addPattern<TestSpec::NamePattern>();
  2949. return *this;
  2950. }
  2951. TestSpec testSpec() {
  2952. addFilter();
  2953. return m_testSpec;
  2954. }
  2955. private:
  2956. void visitChar( char c ) {
  2957. if( m_mode == None ) {
  2958. switch( c ) {
  2959. case ' ': return;
  2960. case '~': m_exclusion = true; return;
  2961. case '[': return startNewMode( Tag, ++m_pos );
  2962. case '"': return startNewMode( QuotedName, ++m_pos );
  2963. case '\\': return escape();
  2964. default: startNewMode( Name, m_pos ); break;
  2965. }
  2966. }
  2967. if( m_mode == Name ) {
  2968. if( c == ',' ) {
  2969. addPattern<TestSpec::NamePattern>();
  2970. addFilter();
  2971. }
  2972. else if( c == '[' ) {
  2973. if( subString() == "exclude:" )
  2974. m_exclusion = true;
  2975. else
  2976. addPattern<TestSpec::NamePattern>();
  2977. startNewMode( Tag, ++m_pos );
  2978. }
  2979. else if( c == '\\' )
  2980. escape();
  2981. }
  2982. else if( m_mode == EscapedName )
  2983. m_mode = Name;
  2984. else if( m_mode == QuotedName && c == '"' )
  2985. addPattern<TestSpec::NamePattern>();
  2986. else if( m_mode == Tag && c == ']' )
  2987. addPattern<TestSpec::TagPattern>();
  2988. }
  2989. void startNewMode( Mode mode, std::size_t start ) {
  2990. m_mode = mode;
  2991. m_start = start;
  2992. }
  2993. void escape() {
  2994. if( m_mode == None )
  2995. m_start = m_pos;
  2996. m_mode = EscapedName;
  2997. m_escapeChars.push_back( m_pos );
  2998. }
  2999. std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
  3000. template<typename T>
  3001. void addPattern() {
  3002. std::string token = subString();
  3003. for( size_t i = 0; i < m_escapeChars.size(); ++i )
  3004. token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
  3005. m_escapeChars.clear();
  3006. if( startsWith( token, "exclude:" ) ) {
  3007. m_exclusion = true;
  3008. token = token.substr( 8 );
  3009. }
  3010. if( !token.empty() ) {
  3011. Ptr<TestSpec::Pattern> pattern = new T( token );
  3012. if( m_exclusion )
  3013. pattern = new TestSpec::ExcludedPattern( pattern );
  3014. m_currentFilter.m_patterns.push_back( pattern );
  3015. }
  3016. m_exclusion = false;
  3017. m_mode = None;
  3018. }
  3019. void addFilter() {
  3020. if( !m_currentFilter.m_patterns.empty() ) {
  3021. m_testSpec.m_filters.push_back( m_currentFilter );
  3022. m_currentFilter = TestSpec::Filter();
  3023. }
  3024. }
  3025. };
  3026. inline TestSpec parseTestSpec( std::string const& arg ) {
  3027. return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
  3028. }
  3029. } // namespace Catch
  3030. #ifdef __clang__
  3031. #pragma clang diagnostic pop
  3032. #endif
  3033. // #included from: catch_interfaces_config.h
  3034. #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
  3035. #include <iosfwd>
  3036. #include <string>
  3037. #include <vector>
  3038. namespace Catch {
  3039. struct Verbosity { enum Level {
  3040. NoOutput = 0,
  3041. Quiet,
  3042. Normal
  3043. }; };
  3044. struct WarnAbout { enum What {
  3045. Nothing = 0x00,
  3046. NoAssertions = 0x01
  3047. }; };
  3048. struct ShowDurations { enum OrNot {
  3049. DefaultForReporter,
  3050. Always,
  3051. Never
  3052. }; };
  3053. struct RunTests { enum InWhatOrder {
  3054. InDeclarationOrder,
  3055. InLexicographicalOrder,
  3056. InRandomOrder
  3057. }; };
  3058. struct UseColour { enum YesOrNo {
  3059. Auto,
  3060. Yes,
  3061. No
  3062. }; };
  3063. class TestSpec;
  3064. struct IConfig : IShared {
  3065. virtual ~IConfig();
  3066. virtual bool allowThrows() const = 0;
  3067. virtual std::ostream& stream() const = 0;
  3068. virtual std::string name() const = 0;
  3069. virtual bool includeSuccessfulResults() const = 0;
  3070. virtual bool shouldDebugBreak() const = 0;
  3071. virtual bool warnAboutMissingAssertions() const = 0;
  3072. virtual int abortAfter() const = 0;
  3073. virtual bool showInvisibles() const = 0;
  3074. virtual ShowDurations::OrNot showDurations() const = 0;
  3075. virtual TestSpec const& testSpec() const = 0;
  3076. virtual RunTests::InWhatOrder runOrder() const = 0;
  3077. virtual unsigned int rngSeed() const = 0;
  3078. virtual UseColour::YesOrNo useColour() const = 0;
  3079. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  3080. };
  3081. }
  3082. // #included from: catch_stream.h
  3083. #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
  3084. // #included from: catch_streambuf.h
  3085. #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
  3086. #include <streambuf>
  3087. namespace Catch {
  3088. class StreamBufBase : public std::streambuf {
  3089. public:
  3090. virtual ~StreamBufBase() CATCH_NOEXCEPT;
  3091. };
  3092. }
  3093. #include <streambuf>
  3094. #include <ostream>
  3095. #include <fstream>
  3096. #include <memory>
  3097. namespace Catch {
  3098. std::ostream& cout();
  3099. std::ostream& cerr();
  3100. struct IStream {
  3101. virtual ~IStream() CATCH_NOEXCEPT;
  3102. virtual std::ostream& stream() const = 0;
  3103. };
  3104. class FileStream : public IStream {
  3105. mutable std::ofstream m_ofs;
  3106. public:
  3107. FileStream( std::string const& filename );
  3108. virtual ~FileStream() CATCH_NOEXCEPT;
  3109. public: // IStream
  3110. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3111. };
  3112. class CoutStream : public IStream {
  3113. mutable std::ostream m_os;
  3114. public:
  3115. CoutStream();
  3116. virtual ~CoutStream() CATCH_NOEXCEPT;
  3117. public: // IStream
  3118. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3119. };
  3120. class DebugOutStream : public IStream {
  3121. CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
  3122. mutable std::ostream m_os;
  3123. public:
  3124. DebugOutStream();
  3125. virtual ~DebugOutStream() CATCH_NOEXCEPT;
  3126. public: // IStream
  3127. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3128. };
  3129. }
  3130. #include <memory>
  3131. #include <vector>
  3132. #include <string>
  3133. #include <stdexcept>
  3134. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  3135. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  3136. #endif
  3137. namespace Catch {
  3138. struct ConfigData {
  3139. ConfigData()
  3140. : listTests( false ),
  3141. listTags( false ),
  3142. listReporters( false ),
  3143. listTestNamesOnly( false ),
  3144. showSuccessfulTests( false ),
  3145. shouldDebugBreak( false ),
  3146. noThrow( false ),
  3147. showHelp( false ),
  3148. showInvisibles( false ),
  3149. filenamesAsTags( false ),
  3150. abortAfter( -1 ),
  3151. rngSeed( 0 ),
  3152. verbosity( Verbosity::Normal ),
  3153. warnings( WarnAbout::Nothing ),
  3154. showDurations( ShowDurations::DefaultForReporter ),
  3155. runOrder( RunTests::InDeclarationOrder ),
  3156. useColour( UseColour::Auto )
  3157. {}
  3158. bool listTests;
  3159. bool listTags;
  3160. bool listReporters;
  3161. bool listTestNamesOnly;
  3162. bool showSuccessfulTests;
  3163. bool shouldDebugBreak;
  3164. bool noThrow;
  3165. bool showHelp;
  3166. bool showInvisibles;
  3167. bool filenamesAsTags;
  3168. int abortAfter;
  3169. unsigned int rngSeed;
  3170. Verbosity::Level verbosity;
  3171. WarnAbout::What warnings;
  3172. ShowDurations::OrNot showDurations;
  3173. RunTests::InWhatOrder runOrder;
  3174. UseColour::YesOrNo useColour;
  3175. std::string outputFilename;
  3176. std::string name;
  3177. std::string processName;
  3178. std::vector<std::string> reporterNames;
  3179. std::vector<std::string> testsOrTags;
  3180. std::vector<std::string> sectionsToRun;
  3181. };
  3182. class Config : public SharedImpl<IConfig> {
  3183. private:
  3184. Config( Config const& other );
  3185. Config& operator = ( Config const& other );
  3186. virtual void dummy();
  3187. public:
  3188. Config()
  3189. {}
  3190. Config( ConfigData const& data )
  3191. : m_data( data ),
  3192. m_stream( openStream() )
  3193. {
  3194. if( !data.testsOrTags.empty() ) {
  3195. TestSpecParser parser( ITagAliasRegistry::get() );
  3196. for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
  3197. parser.parse( data.testsOrTags[i] );
  3198. m_testSpec = parser.testSpec();
  3199. }
  3200. }
  3201. virtual ~Config() {}
  3202. std::string const& getFilename() const {
  3203. return m_data.outputFilename ;
  3204. }
  3205. bool listTests() const { return m_data.listTests; }
  3206. bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
  3207. bool listTags() const { return m_data.listTags; }
  3208. bool listReporters() const { return m_data.listReporters; }
  3209. std::string getProcessName() const { return m_data.processName; }
  3210. std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
  3211. std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; }
  3212. virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; }
  3213. bool showHelp() const { return m_data.showHelp; }
  3214. // IConfig interface
  3215. virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; }
  3216. virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); }
  3217. virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; }
  3218. virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; }
  3219. virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; }
  3220. virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; }
  3221. virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; }
  3222. virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; }
  3223. virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; }
  3224. virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; }
  3225. virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; }
  3226. virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; }
  3227. private:
  3228. IStream const* openStream() {
  3229. if( m_data.outputFilename.empty() )
  3230. return new CoutStream();
  3231. else if( m_data.outputFilename[0] == '%' ) {
  3232. if( m_data.outputFilename == "%debug" )
  3233. return new DebugOutStream();
  3234. else
  3235. throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
  3236. }
  3237. else
  3238. return new FileStream( m_data.outputFilename );
  3239. }
  3240. ConfigData m_data;
  3241. CATCH_AUTO_PTR( IStream const ) m_stream;
  3242. TestSpec m_testSpec;
  3243. };
  3244. } // end namespace Catch
  3245. // #included from: catch_clara.h
  3246. #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
  3247. // Use Catch's value for console width (store Clara's off to the side, if present)
  3248. #ifdef CLARA_CONFIG_CONSOLE_WIDTH
  3249. #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
  3250. #undef CLARA_CONFIG_CONSOLE_WIDTH
  3251. #endif
  3252. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  3253. // Declare Clara inside the Catch namespace
  3254. #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
  3255. // #included from: ../external/clara.h
  3256. // Version 0.0.2.4
  3257. // Only use header guard if we are not using an outer namespace
  3258. #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
  3259. #ifndef STITCH_CLARA_OPEN_NAMESPACE
  3260. #define TWOBLUECUBES_CLARA_H_INCLUDED
  3261. #define STITCH_CLARA_OPEN_NAMESPACE
  3262. #define STITCH_CLARA_CLOSE_NAMESPACE
  3263. #else
  3264. #define STITCH_CLARA_CLOSE_NAMESPACE }
  3265. #endif
  3266. #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
  3267. // ----------- #included from tbc_text_format.h -----------
  3268. // Only use header guard if we are not using an outer namespace
  3269. #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
  3270. #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3271. #define TBC_TEXT_FORMAT_H_INCLUDED
  3272. #endif
  3273. #include <string>
  3274. #include <vector>
  3275. #include <sstream>
  3276. #include <algorithm>
  3277. // Use optional outer namespace
  3278. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3279. namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  3280. #endif
  3281. namespace Tbc {
  3282. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  3283. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  3284. #else
  3285. const unsigned int consoleWidth = 80;
  3286. #endif
  3287. struct TextAttributes {
  3288. TextAttributes()
  3289. : initialIndent( std::string::npos ),
  3290. indent( 0 ),
  3291. width( consoleWidth-1 ),
  3292. tabChar( '\t' )
  3293. {}
  3294. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  3295. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  3296. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  3297. TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
  3298. std::size_t initialIndent; // indent of first line, or npos
  3299. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  3300. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  3301. char tabChar; // If this char is seen the indent is changed to current pos
  3302. };
  3303. class Text {
  3304. public:
  3305. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  3306. : attr( _attr )
  3307. {
  3308. std::string wrappableChars = " [({.,/|\\-";
  3309. std::size_t indent = _attr.initialIndent != std::string::npos
  3310. ? _attr.initialIndent
  3311. : _attr.indent;
  3312. std::string remainder = _str;
  3313. while( !remainder.empty() ) {
  3314. if( lines.size() >= 1000 ) {
  3315. lines.push_back( "... message truncated due to excessive size" );
  3316. return;
  3317. }
  3318. std::size_t tabPos = std::string::npos;
  3319. std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
  3320. std::size_t pos = remainder.find_first_of( '\n' );
  3321. if( pos <= width ) {
  3322. width = pos;
  3323. }
  3324. pos = remainder.find_last_of( _attr.tabChar, width );
  3325. if( pos != std::string::npos ) {
  3326. tabPos = pos;
  3327. if( remainder[width] == '\n' )
  3328. width--;
  3329. remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
  3330. }
  3331. if( width == remainder.size() ) {
  3332. spliceLine( indent, remainder, width );
  3333. }
  3334. else if( remainder[width] == '\n' ) {
  3335. spliceLine( indent, remainder, width );
  3336. if( width <= 1 || remainder.size() != 1 )
  3337. remainder = remainder.substr( 1 );
  3338. indent = _attr.indent;
  3339. }
  3340. else {
  3341. pos = remainder.find_last_of( wrappableChars, width );
  3342. if( pos != std::string::npos && pos > 0 ) {
  3343. spliceLine( indent, remainder, pos );
  3344. if( remainder[0] == ' ' )
  3345. remainder = remainder.substr( 1 );
  3346. }
  3347. else {
  3348. spliceLine( indent, remainder, width-1 );
  3349. lines.back() += "-";
  3350. }
  3351. if( lines.size() == 1 )
  3352. indent = _attr.indent;
  3353. if( tabPos != std::string::npos )
  3354. indent += tabPos;
  3355. }
  3356. }
  3357. }
  3358. void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
  3359. lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
  3360. _remainder = _remainder.substr( _pos );
  3361. }
  3362. typedef std::vector<std::string>::const_iterator const_iterator;
  3363. const_iterator begin() const { return lines.begin(); }
  3364. const_iterator end() const { return lines.end(); }
  3365. std::string const& last() const { return lines.back(); }
  3366. std::size_t size() const { return lines.size(); }
  3367. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  3368. std::string toString() const {
  3369. std::ostringstream oss;
  3370. oss << *this;
  3371. return oss.str();
  3372. }
  3373. inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  3374. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  3375. it != itEnd; ++it ) {
  3376. if( it != _text.begin() )
  3377. _stream << "\n";
  3378. _stream << *it;
  3379. }
  3380. return _stream;
  3381. }
  3382. private:
  3383. std::string str;
  3384. TextAttributes attr;
  3385. std::vector<std::string> lines;
  3386. };
  3387. } // end namespace Tbc
  3388. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3389. } // end outer namespace
  3390. #endif
  3391. #endif // TBC_TEXT_FORMAT_H_INCLUDED
  3392. // ----------- end of #include from tbc_text_format.h -----------
  3393. // ........... back in clara.h
  3394. #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
  3395. // ----------- #included from clara_compilers.h -----------
  3396. #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3397. #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3398. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  3399. // The following features are defined:
  3400. //
  3401. // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
  3402. // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  3403. // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  3404. // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
  3405. // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  3406. // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  3407. // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  3408. // In general each macro has a _NO_<feature name> form
  3409. // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  3410. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  3411. // can be combined, en-mass, with the _NO_ forms later.
  3412. // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
  3413. #ifdef __clang__
  3414. #if __has_feature(cxx_nullptr)
  3415. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3416. #endif
  3417. #if __has_feature(cxx_noexcept)
  3418. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3419. #endif
  3420. #endif // __clang__
  3421. ////////////////////////////////////////////////////////////////////////////////
  3422. // GCC
  3423. #ifdef __GNUC__
  3424. #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  3425. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3426. #endif
  3427. // - otherwise more recent versions define __cplusplus >= 201103L
  3428. // and will get picked up below
  3429. #endif // __GNUC__
  3430. ////////////////////////////////////////////////////////////////////////////////
  3431. // Visual C++
  3432. #ifdef _MSC_VER
  3433. #if (_MSC_VER >= 1600)
  3434. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3435. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3436. #endif
  3437. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  3438. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3439. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3440. #endif
  3441. #endif // _MSC_VER
  3442. ////////////////////////////////////////////////////////////////////////////////
  3443. // C++ language feature support
  3444. // catch all support for C++11
  3445. #if defined(__cplusplus) && __cplusplus >= 201103L
  3446. #define CLARA_CPP11_OR_GREATER
  3447. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
  3448. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3449. #endif
  3450. #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3451. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3452. #endif
  3453. #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3454. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3455. #endif
  3456. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
  3457. #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
  3458. #endif
  3459. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  3460. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3461. #endif
  3462. #endif // __cplusplus >= 201103L
  3463. // Now set the actual defines based on the above + anything the user has configured
  3464. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3465. #define CLARA_CONFIG_CPP11_NULLPTR
  3466. #endif
  3467. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
  3468. #define CLARA_CONFIG_CPP11_NOEXCEPT
  3469. #endif
  3470. #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)
  3471. #define CLARA_CONFIG_CPP11_GENERATED_METHODS
  3472. #endif
  3473. #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
  3474. #define CLARA_CONFIG_CPP11_OVERRIDE
  3475. #endif
  3476. #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)
  3477. #define CLARA_CONFIG_CPP11_UNIQUE_PTR
  3478. #endif
  3479. // noexcept support:
  3480. #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
  3481. #define CLARA_NOEXCEPT noexcept
  3482. # define CLARA_NOEXCEPT_IS(x) noexcept(x)
  3483. #else
  3484. #define CLARA_NOEXCEPT throw()
  3485. # define CLARA_NOEXCEPT_IS(x)
  3486. #endif
  3487. // nullptr support
  3488. #ifdef CLARA_CONFIG_CPP11_NULLPTR
  3489. #define CLARA_NULL nullptr
  3490. #else
  3491. #define CLARA_NULL NULL
  3492. #endif
  3493. // override support
  3494. #ifdef CLARA_CONFIG_CPP11_OVERRIDE
  3495. #define CLARA_OVERRIDE override
  3496. #else
  3497. #define CLARA_OVERRIDE
  3498. #endif
  3499. // unique_ptr support
  3500. #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
  3501. # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
  3502. #else
  3503. # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
  3504. #endif
  3505. #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3506. // ----------- end of #include from clara_compilers.h -----------
  3507. // ........... back in clara.h
  3508. #include <map>
  3509. #include <stdexcept>
  3510. #include <memory>
  3511. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  3512. #define CLARA_PLATFORM_WINDOWS
  3513. #endif
  3514. // Use optional outer namespace
  3515. #ifdef STITCH_CLARA_OPEN_NAMESPACE
  3516. STITCH_CLARA_OPEN_NAMESPACE
  3517. #endif
  3518. namespace Clara {
  3519. struct UnpositionalTag {};
  3520. extern UnpositionalTag _;
  3521. #ifdef CLARA_CONFIG_MAIN
  3522. UnpositionalTag _;
  3523. #endif
  3524. namespace Detail {
  3525. #ifdef CLARA_CONSOLE_WIDTH
  3526. const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
  3527. #else
  3528. const unsigned int consoleWidth = 80;
  3529. #endif
  3530. using namespace Tbc;
  3531. inline bool startsWith( std::string const& str, std::string const& prefix ) {
  3532. return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
  3533. }
  3534. template<typename T> struct RemoveConstRef{ typedef T type; };
  3535. template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
  3536. template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
  3537. template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
  3538. template<typename T> struct IsBool { static const bool value = false; };
  3539. template<> struct IsBool<bool> { static const bool value = true; };
  3540. template<typename T>
  3541. void convertInto( std::string const& _source, T& _dest ) {
  3542. std::stringstream ss;
  3543. ss << _source;
  3544. ss >> _dest;
  3545. if( ss.fail() )
  3546. throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
  3547. }
  3548. inline void convertInto( std::string const& _source, std::string& _dest ) {
  3549. _dest = _source;
  3550. }
  3551. char toLowerCh(char c) {
  3552. return static_cast<char>( ::tolower( c ) );
  3553. }
  3554. inline void convertInto( std::string const& _source, bool& _dest ) {
  3555. std::string sourceLC = _source;
  3556. std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
  3557. if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
  3558. _dest = true;
  3559. else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
  3560. _dest = false;
  3561. else
  3562. throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
  3563. }
  3564. template<typename ConfigT>
  3565. struct IArgFunction {
  3566. virtual ~IArgFunction() {}
  3567. #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
  3568. IArgFunction() = default;
  3569. IArgFunction( IArgFunction const& ) = default;
  3570. #endif
  3571. virtual void set( ConfigT& config, std::string const& value ) const = 0;
  3572. virtual bool takesArg() const = 0;
  3573. virtual IArgFunction* clone() const = 0;
  3574. };
  3575. template<typename ConfigT>
  3576. class BoundArgFunction {
  3577. public:
  3578. BoundArgFunction() : functionObj( CLARA_NULL ) {}
  3579. BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
  3580. BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
  3581. BoundArgFunction& operator = ( BoundArgFunction const& other ) {
  3582. IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
  3583. delete functionObj;
  3584. functionObj = newFunctionObj;
  3585. return *this;
  3586. }
  3587. ~BoundArgFunction() { delete functionObj; }
  3588. void set( ConfigT& config, std::string const& value ) const {
  3589. functionObj->set( config, value );
  3590. }
  3591. bool takesArg() const { return functionObj->takesArg(); }
  3592. bool isSet() const {
  3593. return functionObj != CLARA_NULL;
  3594. }
  3595. private:
  3596. IArgFunction<ConfigT>* functionObj;
  3597. };
  3598. template<typename C>
  3599. struct NullBinder : IArgFunction<C>{
  3600. virtual void set( C&, std::string const& ) const {}
  3601. virtual bool takesArg() const { return true; }
  3602. virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
  3603. };
  3604. template<typename C, typename M>
  3605. struct BoundDataMember : IArgFunction<C>{
  3606. BoundDataMember( M C::* _member ) : member( _member ) {}
  3607. virtual void set( C& p, std::string const& stringValue ) const {
  3608. convertInto( stringValue, p.*member );
  3609. }
  3610. virtual bool takesArg() const { return !IsBool<M>::value; }
  3611. virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
  3612. M C::* member;
  3613. };
  3614. template<typename C, typename M>
  3615. struct BoundUnaryMethod : IArgFunction<C>{
  3616. BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
  3617. virtual void set( C& p, std::string const& stringValue ) const {
  3618. typename RemoveConstRef<M>::type value;
  3619. convertInto( stringValue, value );
  3620. (p.*member)( value );
  3621. }
  3622. virtual bool takesArg() const { return !IsBool<M>::value; }
  3623. virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
  3624. void (C::*member)( M );
  3625. };
  3626. template<typename C>
  3627. struct BoundNullaryMethod : IArgFunction<C>{
  3628. BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
  3629. virtual void set( C& p, std::string const& stringValue ) const {
  3630. bool value;
  3631. convertInto( stringValue, value );
  3632. if( value )
  3633. (p.*member)();
  3634. }
  3635. virtual bool takesArg() const { return false; }
  3636. virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
  3637. void (C::*member)();
  3638. };
  3639. template<typename C>
  3640. struct BoundUnaryFunction : IArgFunction<C>{
  3641. BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
  3642. virtual void set( C& obj, std::string const& stringValue ) const {
  3643. bool value;
  3644. convertInto( stringValue, value );
  3645. if( value )
  3646. function( obj );
  3647. }
  3648. virtual bool takesArg() const { return false; }
  3649. virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
  3650. void (*function)( C& );
  3651. };
  3652. template<typename C, typename T>
  3653. struct BoundBinaryFunction : IArgFunction<C>{
  3654. BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
  3655. virtual void set( C& obj, std::string const& stringValue ) const {
  3656. typename RemoveConstRef<T>::type value;
  3657. convertInto( stringValue, value );
  3658. function( obj, value );
  3659. }
  3660. virtual bool takesArg() const { return !IsBool<T>::value; }
  3661. virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
  3662. void (*function)( C&, T );
  3663. };
  3664. } // namespace Detail
  3665. inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
  3666. std::vector<std::string> args( static_cast<std::size_t>( argc ) );
  3667. for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
  3668. args[i] = argv[i];
  3669. return args;
  3670. }
  3671. class Parser {
  3672. enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
  3673. Mode mode;
  3674. std::size_t from;
  3675. bool inQuotes;
  3676. public:
  3677. struct Token {
  3678. enum Type { Positional, ShortOpt, LongOpt };
  3679. Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
  3680. Type type;
  3681. std::string data;
  3682. };
  3683. Parser() : mode( None ), from( 0 ), inQuotes( false ){}
  3684. void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
  3685. const std::string doubleDash = "--";
  3686. for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
  3687. parseIntoTokens( args[i], tokens);
  3688. }
  3689. void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
  3690. for( std::size_t i = 0; i <= arg.size(); ++i ) {
  3691. char c = arg[i];
  3692. if( c == '"' )
  3693. inQuotes = !inQuotes;
  3694. mode = handleMode( i, c, arg, tokens );
  3695. }
  3696. }
  3697. Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3698. switch( mode ) {
  3699. case None: return handleNone( i, c );
  3700. case MaybeShortOpt: return handleMaybeShortOpt( i, c );
  3701. case ShortOpt:
  3702. case LongOpt:
  3703. case SlashOpt: return handleOpt( i, c, arg, tokens );
  3704. case Positional: return handlePositional( i, c, arg, tokens );
  3705. default: throw std::logic_error( "Unknown mode" );
  3706. }
  3707. }
  3708. Mode handleNone( std::size_t i, char c ) {
  3709. if( inQuotes ) {
  3710. from = i;
  3711. return Positional;
  3712. }
  3713. switch( c ) {
  3714. case '-': return MaybeShortOpt;
  3715. #ifdef CLARA_PLATFORM_WINDOWS
  3716. case '/': from = i+1; return SlashOpt;
  3717. #endif
  3718. default: from = i; return Positional;
  3719. }
  3720. }
  3721. Mode handleMaybeShortOpt( std::size_t i, char c ) {
  3722. switch( c ) {
  3723. case '-': from = i+1; return LongOpt;
  3724. default: from = i; return ShortOpt;
  3725. }
  3726. }
  3727. Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3728. if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
  3729. return mode;
  3730. std::string optName = arg.substr( from, i-from );
  3731. if( mode == ShortOpt )
  3732. for( std::size_t j = 0; j < optName.size(); ++j )
  3733. tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
  3734. else if( mode == SlashOpt && optName.size() == 1 )
  3735. tokens.push_back( Token( Token::ShortOpt, optName ) );
  3736. else
  3737. tokens.push_back( Token( Token::LongOpt, optName ) );
  3738. return None;
  3739. }
  3740. Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3741. if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
  3742. return mode;
  3743. std::string data = arg.substr( from, i-from );
  3744. tokens.push_back( Token( Token::Positional, data ) );
  3745. return None;
  3746. }
  3747. };
  3748. template<typename ConfigT>
  3749. struct CommonArgProperties {
  3750. CommonArgProperties() {}
  3751. CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
  3752. Detail::BoundArgFunction<ConfigT> boundField;
  3753. std::string description;
  3754. std::string detail;
  3755. std::string placeholder; // Only value if boundField takes an arg
  3756. bool takesArg() const {
  3757. return !placeholder.empty();
  3758. }
  3759. void validate() const {
  3760. if( !boundField.isSet() )
  3761. throw std::logic_error( "option not bound" );
  3762. }
  3763. };
  3764. struct OptionArgProperties {
  3765. std::vector<std::string> shortNames;
  3766. std::string longName;
  3767. bool hasShortName( std::string const& shortName ) const {
  3768. return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
  3769. }
  3770. bool hasLongName( std::string const& _longName ) const {
  3771. return _longName == longName;
  3772. }
  3773. };
  3774. struct PositionalArgProperties {
  3775. PositionalArgProperties() : position( -1 ) {}
  3776. int position; // -1 means non-positional (floating)
  3777. bool isFixedPositional() const {
  3778. return position != -1;
  3779. }
  3780. };
  3781. template<typename ConfigT>
  3782. class CommandLine {
  3783. struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
  3784. Arg() {}
  3785. Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
  3786. using CommonArgProperties<ConfigT>::placeholder; // !TBD
  3787. std::string dbgName() const {
  3788. if( !longName.empty() )
  3789. return "--" + longName;
  3790. if( !shortNames.empty() )
  3791. return "-" + shortNames[0];
  3792. return "positional args";
  3793. }
  3794. std::string commands() const {
  3795. std::ostringstream oss;
  3796. bool first = true;
  3797. std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
  3798. for(; it != itEnd; ++it ) {
  3799. if( first )
  3800. first = false;
  3801. else
  3802. oss << ", ";
  3803. oss << "-" << *it;
  3804. }
  3805. if( !longName.empty() ) {
  3806. if( !first )
  3807. oss << ", ";
  3808. oss << "--" << longName;
  3809. }
  3810. if( !placeholder.empty() )
  3811. oss << " <" << placeholder << ">";
  3812. return oss.str();
  3813. }
  3814. };
  3815. typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
  3816. friend void addOptName( Arg& arg, std::string const& optName )
  3817. {
  3818. if( optName.empty() )
  3819. return;
  3820. if( Detail::startsWith( optName, "--" ) ) {
  3821. if( !arg.longName.empty() )
  3822. throw std::logic_error( "Only one long opt may be specified. '"
  3823. + arg.longName
  3824. + "' already specified, now attempting to add '"
  3825. + optName + "'" );
  3826. arg.longName = optName.substr( 2 );
  3827. }
  3828. else if( Detail::startsWith( optName, "-" ) )
  3829. arg.shortNames.push_back( optName.substr( 1 ) );
  3830. else
  3831. throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
  3832. }
  3833. friend void setPositionalArg( Arg& arg, int position )
  3834. {
  3835. arg.position = position;
  3836. }
  3837. class ArgBuilder {
  3838. public:
  3839. ArgBuilder( Arg* arg ) : m_arg( arg ) {}
  3840. // Bind a non-boolean data member (requires placeholder string)
  3841. template<typename C, typename M>
  3842. void bind( M C::* field, std::string const& placeholder ) {
  3843. m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
  3844. m_arg->placeholder = placeholder;
  3845. }
  3846. // Bind a boolean data member (no placeholder required)
  3847. template<typename C>
  3848. void bind( bool C::* field ) {
  3849. m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
  3850. }
  3851. // Bind a method taking a single, non-boolean argument (requires a placeholder string)
  3852. template<typename C, typename M>
  3853. void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
  3854. m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
  3855. m_arg->placeholder = placeholder;
  3856. }
  3857. // Bind a method taking a single, boolean argument (no placeholder string required)
  3858. template<typename C>
  3859. void bind( void (C::* unaryMethod)( bool ) ) {
  3860. m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
  3861. }
  3862. // Bind a method that takes no arguments (will be called if opt is present)
  3863. template<typename C>
  3864. void bind( void (C::* nullaryMethod)() ) {
  3865. m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
  3866. }
  3867. // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
  3868. template<typename C>
  3869. void bind( void (* unaryFunction)( C& ) ) {
  3870. m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
  3871. }
  3872. // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
  3873. template<typename C, typename T>
  3874. void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
  3875. m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
  3876. m_arg->placeholder = placeholder;
  3877. }
  3878. ArgBuilder& describe( std::string const& description ) {
  3879. m_arg->description = description;
  3880. return *this;
  3881. }
  3882. ArgBuilder& detail( std::string const& detail ) {
  3883. m_arg->detail = detail;
  3884. return *this;
  3885. }
  3886. protected:
  3887. Arg* m_arg;
  3888. };
  3889. class OptBuilder : public ArgBuilder {
  3890. public:
  3891. OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
  3892. OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
  3893. OptBuilder& operator[]( std::string const& optName ) {
  3894. addOptName( *ArgBuilder::m_arg, optName );
  3895. return *this;
  3896. }
  3897. };
  3898. public:
  3899. CommandLine()
  3900. : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
  3901. m_highestSpecifiedArgPosition( 0 ),
  3902. m_throwOnUnrecognisedTokens( false )
  3903. {}
  3904. CommandLine( CommandLine const& other )
  3905. : m_boundProcessName( other.m_boundProcessName ),
  3906. m_options ( other.m_options ),
  3907. m_positionalArgs( other.m_positionalArgs ),
  3908. m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
  3909. m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
  3910. {
  3911. if( other.m_floatingArg.get() )
  3912. m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
  3913. }
  3914. CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
  3915. m_throwOnUnrecognisedTokens = shouldThrow;
  3916. return *this;
  3917. }
  3918. OptBuilder operator[]( std::string const& optName ) {
  3919. m_options.push_back( Arg() );
  3920. addOptName( m_options.back(), optName );
  3921. OptBuilder builder( &m_options.back() );
  3922. return builder;
  3923. }
  3924. ArgBuilder operator[]( int position ) {
  3925. m_positionalArgs.insert( std::make_pair( position, Arg() ) );
  3926. if( position > m_highestSpecifiedArgPosition )
  3927. m_highestSpecifiedArgPosition = position;
  3928. setPositionalArg( m_positionalArgs[position], position );
  3929. ArgBuilder builder( &m_positionalArgs[position] );
  3930. return builder;
  3931. }
  3932. // Invoke this with the _ instance
  3933. ArgBuilder operator[]( UnpositionalTag ) {
  3934. if( m_floatingArg.get() )
  3935. throw std::logic_error( "Only one unpositional argument can be added" );
  3936. m_floatingArg.reset( new Arg() );
  3937. ArgBuilder builder( m_floatingArg.get() );
  3938. return builder;
  3939. }
  3940. template<typename C, typename M>
  3941. void bindProcessName( M C::* field ) {
  3942. m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
  3943. }
  3944. template<typename C, typename M>
  3945. void bindProcessName( void (C::*_unaryMethod)( M ) ) {
  3946. m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
  3947. }
  3948. void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
  3949. typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
  3950. std::size_t maxWidth = 0;
  3951. for( it = itBegin; it != itEnd; ++it )
  3952. maxWidth = (std::max)( maxWidth, it->commands().size() );
  3953. for( it = itBegin; it != itEnd; ++it ) {
  3954. Detail::Text usage( it->commands(), Detail::TextAttributes()
  3955. .setWidth( maxWidth+indent )
  3956. .setIndent( indent ) );
  3957. Detail::Text desc( it->description, Detail::TextAttributes()
  3958. .setWidth( width - maxWidth - 3 ) );
  3959. for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
  3960. std::string usageCol = i < usage.size() ? usage[i] : "";
  3961. os << usageCol;
  3962. if( i < desc.size() && !desc[i].empty() )
  3963. os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
  3964. << desc[i];
  3965. os << "\n";
  3966. }
  3967. }
  3968. }
  3969. std::string optUsage() const {
  3970. std::ostringstream oss;
  3971. optUsage( oss );
  3972. return oss.str();
  3973. }
  3974. void argSynopsis( std::ostream& os ) const {
  3975. for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
  3976. if( i > 1 )
  3977. os << " ";
  3978. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
  3979. if( it != m_positionalArgs.end() )
  3980. os << "<" << it->second.placeholder << ">";
  3981. else if( m_floatingArg.get() )
  3982. os << "<" << m_floatingArg->placeholder << ">";
  3983. else
  3984. throw std::logic_error( "non consecutive positional arguments with no floating args" );
  3985. }
  3986. // !TBD No indication of mandatory args
  3987. if( m_floatingArg.get() ) {
  3988. if( m_highestSpecifiedArgPosition > 1 )
  3989. os << " ";
  3990. os << "[<" << m_floatingArg->placeholder << "> ...]";
  3991. }
  3992. }
  3993. std::string argSynopsis() const {
  3994. std::ostringstream oss;
  3995. argSynopsis( oss );
  3996. return oss.str();
  3997. }
  3998. void usage( std::ostream& os, std::string const& procName ) const {
  3999. validate();
  4000. os << "usage:\n " << procName << " ";
  4001. argSynopsis( os );
  4002. if( !m_options.empty() ) {
  4003. os << " [options]\n\nwhere options are: \n";
  4004. optUsage( os, 2 );
  4005. }
  4006. os << "\n";
  4007. }
  4008. std::string usage( std::string const& procName ) const {
  4009. std::ostringstream oss;
  4010. usage( oss, procName );
  4011. return oss.str();
  4012. }
  4013. ConfigT parse( std::vector<std::string> const& args ) const {
  4014. ConfigT config;
  4015. parseInto( args, config );
  4016. return config;
  4017. }
  4018. std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
  4019. std::string processName = args[0];
  4020. std::size_t lastSlash = processName.find_last_of( "/\\" );
  4021. if( lastSlash != std::string::npos )
  4022. processName = processName.substr( lastSlash+1 );
  4023. m_boundProcessName.set( config, processName );
  4024. std::vector<Parser::Token> tokens;
  4025. Parser parser;
  4026. parser.parseIntoTokens( args, tokens );
  4027. return populate( tokens, config );
  4028. }
  4029. std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4030. validate();
  4031. std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
  4032. unusedTokens = populateFixedArgs( unusedTokens, config );
  4033. unusedTokens = populateFloatingArgs( unusedTokens, config );
  4034. return unusedTokens;
  4035. }
  4036. std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4037. std::vector<Parser::Token> unusedTokens;
  4038. std::vector<std::string> errors;
  4039. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4040. Parser::Token const& token = tokens[i];
  4041. typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
  4042. for(; it != itEnd; ++it ) {
  4043. Arg const& arg = *it;
  4044. try {
  4045. if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
  4046. ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
  4047. if( arg.takesArg() ) {
  4048. if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
  4049. errors.push_back( "Expected argument to option: " + token.data );
  4050. else
  4051. arg.boundField.set( config, tokens[++i].data );
  4052. }
  4053. else {
  4054. arg.boundField.set( config, "true" );
  4055. }
  4056. break;
  4057. }
  4058. }
  4059. catch( std::exception& ex ) {
  4060. errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
  4061. }
  4062. }
  4063. if( it == itEnd ) {
  4064. if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
  4065. unusedTokens.push_back( token );
  4066. else if( errors.empty() && m_throwOnUnrecognisedTokens )
  4067. errors.push_back( "unrecognised option: " + token.data );
  4068. }
  4069. }
  4070. if( !errors.empty() ) {
  4071. std::ostringstream oss;
  4072. for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
  4073. it != itEnd;
  4074. ++it ) {
  4075. if( it != errors.begin() )
  4076. oss << "\n";
  4077. oss << *it;
  4078. }
  4079. throw std::runtime_error( oss.str() );
  4080. }
  4081. return unusedTokens;
  4082. }
  4083. std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4084. std::vector<Parser::Token> unusedTokens;
  4085. int position = 1;
  4086. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4087. Parser::Token const& token = tokens[i];
  4088. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
  4089. if( it != m_positionalArgs.end() )
  4090. it->second.boundField.set( config, token.data );
  4091. else
  4092. unusedTokens.push_back( token );
  4093. if( token.type == Parser::Token::Positional )
  4094. position++;
  4095. }
  4096. return unusedTokens;
  4097. }
  4098. std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4099. if( !m_floatingArg.get() )
  4100. return tokens;
  4101. std::vector<Parser::Token> unusedTokens;
  4102. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4103. Parser::Token const& token = tokens[i];
  4104. if( token.type == Parser::Token::Positional )
  4105. m_floatingArg->boundField.set( config, token.data );
  4106. else
  4107. unusedTokens.push_back( token );
  4108. }
  4109. return unusedTokens;
  4110. }
  4111. void validate() const
  4112. {
  4113. if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
  4114. throw std::logic_error( "No options or arguments specified" );
  4115. for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
  4116. itEnd = m_options.end();
  4117. it != itEnd; ++it )
  4118. it->validate();
  4119. }
  4120. private:
  4121. Detail::BoundArgFunction<ConfigT> m_boundProcessName;
  4122. std::vector<Arg> m_options;
  4123. std::map<int, Arg> m_positionalArgs;
  4124. ArgAutoPtr m_floatingArg;
  4125. int m_highestSpecifiedArgPosition;
  4126. bool m_throwOnUnrecognisedTokens;
  4127. };
  4128. } // end namespace Clara
  4129. STITCH_CLARA_CLOSE_NAMESPACE
  4130. #undef STITCH_CLARA_OPEN_NAMESPACE
  4131. #undef STITCH_CLARA_CLOSE_NAMESPACE
  4132. #endif // TWOBLUECUBES_CLARA_H_INCLUDED
  4133. #undef STITCH_CLARA_OPEN_NAMESPACE
  4134. // Restore Clara's value for console width, if present
  4135. #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4136. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4137. #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4138. #endif
  4139. #include <fstream>
  4140. #include <ctime>
  4141. namespace Catch {
  4142. inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
  4143. inline void abortAfterX( ConfigData& config, int x ) {
  4144. if( x < 1 )
  4145. throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
  4146. config.abortAfter = x;
  4147. }
  4148. inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
  4149. inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); }
  4150. inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
  4151. inline void addWarning( ConfigData& config, std::string const& _warning ) {
  4152. if( _warning == "NoAssertions" )
  4153. config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
  4154. else
  4155. throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' );
  4156. }
  4157. inline void setOrder( ConfigData& config, std::string const& order ) {
  4158. if( startsWith( "declared", order ) )
  4159. config.runOrder = RunTests::InDeclarationOrder;
  4160. else if( startsWith( "lexical", order ) )
  4161. config.runOrder = RunTests::InLexicographicalOrder;
  4162. else if( startsWith( "random", order ) )
  4163. config.runOrder = RunTests::InRandomOrder;
  4164. else
  4165. throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' );
  4166. }
  4167. inline void setRngSeed( ConfigData& config, std::string const& seed ) {
  4168. if( seed == "time" ) {
  4169. config.rngSeed = static_cast<unsigned int>( std::time(0) );
  4170. }
  4171. else {
  4172. std::stringstream ss;
  4173. ss << seed;
  4174. ss >> config.rngSeed;
  4175. if( ss.fail() )
  4176. throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" );
  4177. }
  4178. }
  4179. inline void setVerbosity( ConfigData& config, int level ) {
  4180. // !TBD: accept strings?
  4181. config.verbosity = static_cast<Verbosity::Level>( level );
  4182. }
  4183. inline void setShowDurations( ConfigData& config, bool _showDurations ) {
  4184. config.showDurations = _showDurations
  4185. ? ShowDurations::Always
  4186. : ShowDurations::Never;
  4187. }
  4188. inline void setUseColour( ConfigData& config, std::string const& value ) {
  4189. std::string mode = toLower( value );
  4190. if( mode == "yes" )
  4191. config.useColour = UseColour::Yes;
  4192. else if( mode == "no" )
  4193. config.useColour = UseColour::No;
  4194. else if( mode == "auto" )
  4195. config.useColour = UseColour::Auto;
  4196. else
  4197. throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
  4198. }
  4199. inline void forceColour( ConfigData& config ) {
  4200. config.useColour = UseColour::Yes;
  4201. }
  4202. inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
  4203. std::ifstream f( _filename.c_str() );
  4204. if( !f.is_open() )
  4205. throw std::domain_error( "Unable to load input file: " + _filename );
  4206. std::string line;
  4207. while( std::getline( f, line ) ) {
  4208. line = trim(line);
  4209. if( !line.empty() && !startsWith( line, '#' ) ) {
  4210. if( !startsWith( line, '"' ) )
  4211. line = '"' + line + '"';
  4212. addTestOrTags( config, line + ',' );
  4213. }
  4214. }
  4215. }
  4216. inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
  4217. using namespace Clara;
  4218. CommandLine<ConfigData> cli;
  4219. cli.bindProcessName( &ConfigData::processName );
  4220. cli["-?"]["-h"]["--help"]
  4221. .describe( "display usage information" )
  4222. .bind( &ConfigData::showHelp );
  4223. cli["-l"]["--list-tests"]
  4224. .describe( "list all/matching test cases" )
  4225. .bind( &ConfigData::listTests );
  4226. cli["-t"]["--list-tags"]
  4227. .describe( "list all/matching tags" )
  4228. .bind( &ConfigData::listTags );
  4229. cli["-s"]["--success"]
  4230. .describe( "include successful tests in output" )
  4231. .bind( &ConfigData::showSuccessfulTests );
  4232. cli["-b"]["--break"]
  4233. .describe( "break into debugger on failure" )
  4234. .bind( &ConfigData::shouldDebugBreak );
  4235. cli["-e"]["--nothrow"]
  4236. .describe( "skip exception tests" )
  4237. .bind( &ConfigData::noThrow );
  4238. cli["-i"]["--invisibles"]
  4239. .describe( "show invisibles (tabs, newlines)" )
  4240. .bind( &ConfigData::showInvisibles );
  4241. cli["-o"]["--out"]
  4242. .describe( "output filename" )
  4243. .bind( &ConfigData::outputFilename, "filename" );
  4244. cli["-r"]["--reporter"]
  4245. // .placeholder( "name[:filename]" )
  4246. .describe( "reporter to use (defaults to console)" )
  4247. .bind( &addReporterName, "name" );
  4248. cli["-n"]["--name"]
  4249. .describe( "suite name" )
  4250. .bind( &ConfigData::name, "name" );
  4251. cli["-a"]["--abort"]
  4252. .describe( "abort at first failure" )
  4253. .bind( &abortAfterFirst );
  4254. cli["-x"]["--abortx"]
  4255. .describe( "abort after x failures" )
  4256. .bind( &abortAfterX, "no. failures" );
  4257. cli["-w"]["--warn"]
  4258. .describe( "enable warnings" )
  4259. .bind( &addWarning, "warning name" );
  4260. // - needs updating if reinstated
  4261. // cli.into( &setVerbosity )
  4262. // .describe( "level of verbosity (0=no output)" )
  4263. // .shortOpt( "v")
  4264. // .longOpt( "verbosity" )
  4265. // .placeholder( "level" );
  4266. cli[_]
  4267. .describe( "which test or tests to use" )
  4268. .bind( &addTestOrTags, "test name, pattern or tags" );
  4269. cli["-d"]["--durations"]
  4270. .describe( "show test durations" )
  4271. .bind( &setShowDurations, "yes|no" );
  4272. cli["-f"]["--input-file"]
  4273. .describe( "load test names to run from a file" )
  4274. .bind( &loadTestNamesFromFile, "filename" );
  4275. cli["-#"]["--filenames-as-tags"]
  4276. .describe( "adds a tag for the filename" )
  4277. .bind( &ConfigData::filenamesAsTags );
  4278. cli["-c"]["--section"]
  4279. .describe( "specify section to run" )
  4280. .bind( &addSectionToRun, "section name" );
  4281. // Less common commands which don't have a short form
  4282. cli["--list-test-names-only"]
  4283. .describe( "list all/matching test cases names only" )
  4284. .bind( &ConfigData::listTestNamesOnly );
  4285. cli["--list-reporters"]
  4286. .describe( "list all reporters" )
  4287. .bind( &ConfigData::listReporters );
  4288. cli["--order"]
  4289. .describe( "test case order (defaults to decl)" )
  4290. .bind( &setOrder, "decl|lex|rand" );
  4291. cli["--rng-seed"]
  4292. .describe( "set a specific seed for random numbers" )
  4293. .bind( &setRngSeed, "'time'|number" );
  4294. cli["--force-colour"]
  4295. .describe( "force colourised output (deprecated)" )
  4296. .bind( &forceColour );
  4297. cli["--use-colour"]
  4298. .describe( "should output be colourised" )
  4299. .bind( &setUseColour, "yes|no" );
  4300. return cli;
  4301. }
  4302. } // end namespace Catch
  4303. // #included from: internal/catch_list.hpp
  4304. #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
  4305. // #included from: catch_text.h
  4306. #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
  4307. #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  4308. #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
  4309. // #included from: ../external/tbc_text_format.h
  4310. // Only use header guard if we are not using an outer namespace
  4311. #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4312. # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4313. # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4314. # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4315. # endif
  4316. # else
  4317. # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4318. # endif
  4319. #endif
  4320. #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4321. #include <string>
  4322. #include <vector>
  4323. #include <sstream>
  4324. // Use optional outer namespace
  4325. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4326. namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  4327. #endif
  4328. namespace Tbc {
  4329. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  4330. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  4331. #else
  4332. const unsigned int consoleWidth = 80;
  4333. #endif
  4334. struct TextAttributes {
  4335. TextAttributes()
  4336. : initialIndent( std::string::npos ),
  4337. indent( 0 ),
  4338. width( consoleWidth-1 )
  4339. {}
  4340. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  4341. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  4342. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  4343. std::size_t initialIndent; // indent of first line, or npos
  4344. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  4345. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  4346. };
  4347. class Text {
  4348. public:
  4349. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  4350. : attr( _attr )
  4351. {
  4352. const std::string wrappableBeforeChars = "[({<\t";
  4353. const std::string wrappableAfterChars = "])}>-,./|\\";
  4354. const std::string wrappableInsteadOfChars = " \n\r";
  4355. std::string indent = _attr.initialIndent != std::string::npos
  4356. ? std::string( _attr.initialIndent, ' ' )
  4357. : std::string( _attr.indent, ' ' );
  4358. typedef std::string::const_iterator iterator;
  4359. iterator it = _str.begin();
  4360. const iterator strEnd = _str.end();
  4361. while( it != strEnd ) {
  4362. if( lines.size() >= 1000 ) {
  4363. lines.push_back( "... message truncated due to excessive size" );
  4364. return;
  4365. }
  4366. std::string suffix;
  4367. std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
  4368. iterator itEnd = it+width;
  4369. iterator itNext = _str.end();
  4370. iterator itNewLine = std::find( it, itEnd, '\n' );
  4371. if( itNewLine != itEnd )
  4372. itEnd = itNewLine;
  4373. if( itEnd != strEnd ) {
  4374. bool foundWrapPoint = false;
  4375. iterator findIt = itEnd;
  4376. do {
  4377. if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
  4378. itEnd = findIt+1;
  4379. itNext = findIt+1;
  4380. foundWrapPoint = true;
  4381. }
  4382. else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
  4383. itEnd = findIt;
  4384. itNext = findIt;
  4385. foundWrapPoint = true;
  4386. }
  4387. else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
  4388. itNext = findIt+1;
  4389. itEnd = findIt;
  4390. foundWrapPoint = true;
  4391. }
  4392. if( findIt == it )
  4393. break;
  4394. else
  4395. --findIt;
  4396. }
  4397. while( !foundWrapPoint );
  4398. if( !foundWrapPoint ) {
  4399. // No good wrap char, so we'll break mid word and add a hyphen
  4400. --itEnd;
  4401. itNext = itEnd;
  4402. suffix = "-";
  4403. }
  4404. else {
  4405. while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
  4406. --itEnd;
  4407. }
  4408. }
  4409. lines.push_back( indent + std::string( it, itEnd ) + suffix );
  4410. if( indent.size() != _attr.indent )
  4411. indent = std::string( _attr.indent, ' ' );
  4412. it = itNext;
  4413. }
  4414. }
  4415. typedef std::vector<std::string>::const_iterator const_iterator;
  4416. const_iterator begin() const { return lines.begin(); }
  4417. const_iterator end() const { return lines.end(); }
  4418. std::string const& last() const { return lines.back(); }
  4419. std::size_t size() const { return lines.size(); }
  4420. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  4421. std::string toString() const {
  4422. std::ostringstream oss;
  4423. oss << *this;
  4424. return oss.str();
  4425. }
  4426. inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  4427. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  4428. it != itEnd; ++it ) {
  4429. if( it != _text.begin() )
  4430. _stream << "\n";
  4431. _stream << *it;
  4432. }
  4433. return _stream;
  4434. }
  4435. private:
  4436. std::string str;
  4437. TextAttributes attr;
  4438. std::vector<std::string> lines;
  4439. };
  4440. } // end namespace Tbc
  4441. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4442. } // end outer namespace
  4443. #endif
  4444. #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4445. #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4446. namespace Catch {
  4447. using Tbc::Text;
  4448. using Tbc::TextAttributes;
  4449. }
  4450. // #included from: catch_console_colour.hpp
  4451. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  4452. namespace Catch {
  4453. struct Colour {
  4454. enum Code {
  4455. None = 0,
  4456. White,
  4457. Red,
  4458. Green,
  4459. Blue,
  4460. Cyan,
  4461. Yellow,
  4462. Grey,
  4463. Bright = 0x10,
  4464. BrightRed = Bright | Red,
  4465. BrightGreen = Bright | Green,
  4466. LightGrey = Bright | Grey,
  4467. BrightWhite = Bright | White,
  4468. // By intention
  4469. FileName = LightGrey,
  4470. Warning = Yellow,
  4471. ResultError = BrightRed,
  4472. ResultSuccess = BrightGreen,
  4473. ResultExpectedFailure = Warning,
  4474. Error = BrightRed,
  4475. Success = Green,
  4476. OriginalExpression = Cyan,
  4477. ReconstructedExpression = Yellow,
  4478. SecondaryText = LightGrey,
  4479. Headers = White
  4480. };
  4481. // Use constructed object for RAII guard
  4482. Colour( Code _colourCode );
  4483. Colour( Colour const& other );
  4484. ~Colour();
  4485. // Use static method for one-shot changes
  4486. static void use( Code _colourCode );
  4487. private:
  4488. bool m_moved;
  4489. };
  4490. inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
  4491. } // end namespace Catch
  4492. // #included from: catch_interfaces_reporter.h
  4493. #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
  4494. #include <string>
  4495. #include <ostream>
  4496. #include <map>
  4497. namespace Catch
  4498. {
  4499. struct ReporterConfig {
  4500. explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
  4501. : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
  4502. ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
  4503. : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
  4504. std::ostream& stream() const { return *m_stream; }
  4505. Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
  4506. private:
  4507. std::ostream* m_stream;
  4508. Ptr<IConfig const> m_fullConfig;
  4509. };
  4510. struct ReporterPreferences {
  4511. ReporterPreferences()
  4512. : shouldRedirectStdOut( false )
  4513. {}
  4514. bool shouldRedirectStdOut;
  4515. };
  4516. template<typename T>
  4517. struct LazyStat : Option<T> {
  4518. LazyStat() : used( false ) {}
  4519. LazyStat& operator=( T const& _value ) {
  4520. Option<T>::operator=( _value );
  4521. used = false;
  4522. return *this;
  4523. }
  4524. void reset() {
  4525. Option<T>::reset();
  4526. used = false;
  4527. }
  4528. bool used;
  4529. };
  4530. struct TestRunInfo {
  4531. TestRunInfo( std::string const& _name ) : name( _name ) {}
  4532. std::string name;
  4533. };
  4534. struct GroupInfo {
  4535. GroupInfo( std::string const& _name,
  4536. std::size_t _groupIndex,
  4537. std::size_t _groupsCount )
  4538. : name( _name ),
  4539. groupIndex( _groupIndex ),
  4540. groupsCounts( _groupsCount )
  4541. {}
  4542. std::string name;
  4543. std::size_t groupIndex;
  4544. std::size_t groupsCounts;
  4545. };
  4546. struct AssertionStats {
  4547. AssertionStats( AssertionResult const& _assertionResult,
  4548. std::vector<MessageInfo> const& _infoMessages,
  4549. Totals const& _totals )
  4550. : assertionResult( _assertionResult ),
  4551. infoMessages( _infoMessages ),
  4552. totals( _totals )
  4553. {
  4554. if( assertionResult.hasMessage() ) {
  4555. // Copy message into messages list.
  4556. // !TBD This should have been done earlier, somewhere
  4557. MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
  4558. builder << assertionResult.getMessage();
  4559. builder.m_info.message = builder.m_stream.str();
  4560. infoMessages.push_back( builder.m_info );
  4561. }
  4562. }
  4563. virtual ~AssertionStats();
  4564. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4565. AssertionStats( AssertionStats const& ) = default;
  4566. AssertionStats( AssertionStats && ) = default;
  4567. AssertionStats& operator = ( AssertionStats const& ) = default;
  4568. AssertionStats& operator = ( AssertionStats && ) = default;
  4569. # endif
  4570. AssertionResult assertionResult;
  4571. std::vector<MessageInfo> infoMessages;
  4572. Totals totals;
  4573. };
  4574. struct SectionStats {
  4575. SectionStats( SectionInfo const& _sectionInfo,
  4576. Counts const& _assertions,
  4577. double _durationInSeconds,
  4578. bool _missingAssertions )
  4579. : sectionInfo( _sectionInfo ),
  4580. assertions( _assertions ),
  4581. durationInSeconds( _durationInSeconds ),
  4582. missingAssertions( _missingAssertions )
  4583. {}
  4584. virtual ~SectionStats();
  4585. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4586. SectionStats( SectionStats const& ) = default;
  4587. SectionStats( SectionStats && ) = default;
  4588. SectionStats& operator = ( SectionStats const& ) = default;
  4589. SectionStats& operator = ( SectionStats && ) = default;
  4590. # endif
  4591. SectionInfo sectionInfo;
  4592. Counts assertions;
  4593. double durationInSeconds;
  4594. bool missingAssertions;
  4595. };
  4596. struct TestCaseStats {
  4597. TestCaseStats( TestCaseInfo const& _testInfo,
  4598. Totals const& _totals,
  4599. std::string const& _stdOut,
  4600. std::string const& _stdErr,
  4601. bool _aborting )
  4602. : testInfo( _testInfo ),
  4603. totals( _totals ),
  4604. stdOut( _stdOut ),
  4605. stdErr( _stdErr ),
  4606. aborting( _aborting )
  4607. {}
  4608. virtual ~TestCaseStats();
  4609. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4610. TestCaseStats( TestCaseStats const& ) = default;
  4611. TestCaseStats( TestCaseStats && ) = default;
  4612. TestCaseStats& operator = ( TestCaseStats const& ) = default;
  4613. TestCaseStats& operator = ( TestCaseStats && ) = default;
  4614. # endif
  4615. TestCaseInfo testInfo;
  4616. Totals totals;
  4617. std::string stdOut;
  4618. std::string stdErr;
  4619. bool aborting;
  4620. };
  4621. struct TestGroupStats {
  4622. TestGroupStats( GroupInfo const& _groupInfo,
  4623. Totals const& _totals,
  4624. bool _aborting )
  4625. : groupInfo( _groupInfo ),
  4626. totals( _totals ),
  4627. aborting( _aborting )
  4628. {}
  4629. TestGroupStats( GroupInfo const& _groupInfo )
  4630. : groupInfo( _groupInfo ),
  4631. aborting( false )
  4632. {}
  4633. virtual ~TestGroupStats();
  4634. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4635. TestGroupStats( TestGroupStats const& ) = default;
  4636. TestGroupStats( TestGroupStats && ) = default;
  4637. TestGroupStats& operator = ( TestGroupStats const& ) = default;
  4638. TestGroupStats& operator = ( TestGroupStats && ) = default;
  4639. # endif
  4640. GroupInfo groupInfo;
  4641. Totals totals;
  4642. bool aborting;
  4643. };
  4644. struct TestRunStats {
  4645. TestRunStats( TestRunInfo const& _runInfo,
  4646. Totals const& _totals,
  4647. bool _aborting )
  4648. : runInfo( _runInfo ),
  4649. totals( _totals ),
  4650. aborting( _aborting )
  4651. {}
  4652. virtual ~TestRunStats();
  4653. # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4654. TestRunStats( TestRunStats const& _other )
  4655. : runInfo( _other.runInfo ),
  4656. totals( _other.totals ),
  4657. aborting( _other.aborting )
  4658. {}
  4659. # else
  4660. TestRunStats( TestRunStats const& ) = default;
  4661. TestRunStats( TestRunStats && ) = default;
  4662. TestRunStats& operator = ( TestRunStats const& ) = default;
  4663. TestRunStats& operator = ( TestRunStats && ) = default;
  4664. # endif
  4665. TestRunInfo runInfo;
  4666. Totals totals;
  4667. bool aborting;
  4668. };
  4669. class MultipleReporters;
  4670. struct IStreamingReporter : IShared {
  4671. virtual ~IStreamingReporter();
  4672. // Implementing class must also provide the following static method:
  4673. // static std::string getDescription();
  4674. virtual ReporterPreferences getPreferences() const = 0;
  4675. virtual void noMatchingTestCases( std::string const& spec ) = 0;
  4676. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  4677. virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
  4678. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  4679. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  4680. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  4681. // The return value indicates if the messages buffer should be cleared:
  4682. virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
  4683. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  4684. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  4685. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
  4686. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  4687. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  4688. virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
  4689. };
  4690. struct IReporterFactory : IShared {
  4691. virtual ~IReporterFactory();
  4692. virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
  4693. virtual std::string getDescription() const = 0;
  4694. };
  4695. struct IReporterRegistry {
  4696. typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
  4697. typedef std::vector<Ptr<IReporterFactory> > Listeners;
  4698. virtual ~IReporterRegistry();
  4699. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
  4700. virtual FactoryMap const& getFactories() const = 0;
  4701. virtual Listeners const& getListeners() const = 0;
  4702. };
  4703. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
  4704. }
  4705. #include <limits>
  4706. #include <algorithm>
  4707. namespace Catch {
  4708. inline std::size_t listTests( Config const& config ) {
  4709. TestSpec testSpec = config.testSpec();
  4710. if( config.testSpec().hasFilters() )
  4711. Catch::cout() << "Matching test cases:\n";
  4712. else {
  4713. Catch::cout() << "All available test cases:\n";
  4714. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4715. }
  4716. std::size_t matchedTests = 0;
  4717. TextAttributes nameAttr, tagsAttr;
  4718. nameAttr.setInitialIndent( 2 ).setIndent( 4 );
  4719. tagsAttr.setIndent( 6 );
  4720. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4721. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4722. it != itEnd;
  4723. ++it ) {
  4724. matchedTests++;
  4725. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4726. Colour::Code colour = testCaseInfo.isHidden()
  4727. ? Colour::SecondaryText
  4728. : Colour::None;
  4729. Colour colourGuard( colour );
  4730. Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
  4731. if( !testCaseInfo.tags.empty() )
  4732. Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
  4733. }
  4734. if( !config.testSpec().hasFilters() )
  4735. Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
  4736. else
  4737. Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
  4738. return matchedTests;
  4739. }
  4740. inline std::size_t listTestsNamesOnly( Config const& config ) {
  4741. TestSpec testSpec = config.testSpec();
  4742. if( !config.testSpec().hasFilters() )
  4743. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4744. std::size_t matchedTests = 0;
  4745. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4746. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4747. it != itEnd;
  4748. ++it ) {
  4749. matchedTests++;
  4750. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4751. if( startsWith( testCaseInfo.name, '#' ) )
  4752. Catch::cout() << '"' << testCaseInfo.name << '"' << std::endl;
  4753. else
  4754. Catch::cout() << testCaseInfo.name << std::endl;
  4755. }
  4756. return matchedTests;
  4757. }
  4758. struct TagInfo {
  4759. TagInfo() : count ( 0 ) {}
  4760. void add( std::string const& spelling ) {
  4761. ++count;
  4762. spellings.insert( spelling );
  4763. }
  4764. std::string all() const {
  4765. std::string out;
  4766. for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
  4767. it != itEnd;
  4768. ++it )
  4769. out += "[" + *it + "]";
  4770. return out;
  4771. }
  4772. std::set<std::string> spellings;
  4773. std::size_t count;
  4774. };
  4775. inline std::size_t listTags( Config const& config ) {
  4776. TestSpec testSpec = config.testSpec();
  4777. if( config.testSpec().hasFilters() )
  4778. Catch::cout() << "Tags for matching test cases:\n";
  4779. else {
  4780. Catch::cout() << "All available tags:\n";
  4781. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4782. }
  4783. std::map<std::string, TagInfo> tagCounts;
  4784. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4785. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4786. it != itEnd;
  4787. ++it ) {
  4788. for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
  4789. tagItEnd = it->getTestCaseInfo().tags.end();
  4790. tagIt != tagItEnd;
  4791. ++tagIt ) {
  4792. std::string tagName = *tagIt;
  4793. std::string lcaseTagName = toLower( tagName );
  4794. std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
  4795. if( countIt == tagCounts.end() )
  4796. countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
  4797. countIt->second.add( tagName );
  4798. }
  4799. }
  4800. for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
  4801. countItEnd = tagCounts.end();
  4802. countIt != countItEnd;
  4803. ++countIt ) {
  4804. std::ostringstream oss;
  4805. oss << " " << std::setw(2) << countIt->second.count << " ";
  4806. Text wrapper( countIt->second.all(), TextAttributes()
  4807. .setInitialIndent( 0 )
  4808. .setIndent( oss.str().size() )
  4809. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
  4810. Catch::cout() << oss.str() << wrapper << '\n';
  4811. }
  4812. Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
  4813. return tagCounts.size();
  4814. }
  4815. inline std::size_t listReporters( Config const& /*config*/ ) {
  4816. Catch::cout() << "Available reporters:\n";
  4817. IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
  4818. IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
  4819. std::size_t maxNameLen = 0;
  4820. for(it = itBegin; it != itEnd; ++it )
  4821. maxNameLen = (std::max)( maxNameLen, it->first.size() );
  4822. for(it = itBegin; it != itEnd; ++it ) {
  4823. Text wrapper( it->second->getDescription(), TextAttributes()
  4824. .setInitialIndent( 0 )
  4825. .setIndent( 7+maxNameLen )
  4826. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
  4827. Catch::cout() << " "
  4828. << it->first
  4829. << ':'
  4830. << std::string( maxNameLen - it->first.size() + 2, ' ' )
  4831. << wrapper << '\n';
  4832. }
  4833. Catch::cout() << std::endl;
  4834. return factories.size();
  4835. }
  4836. inline Option<std::size_t> list( Config const& config ) {
  4837. Option<std::size_t> listedCount;
  4838. if( config.listTests() )
  4839. listedCount = listedCount.valueOr(0) + listTests( config );
  4840. if( config.listTestNamesOnly() )
  4841. listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
  4842. if( config.listTags() )
  4843. listedCount = listedCount.valueOr(0) + listTags( config );
  4844. if( config.listReporters() )
  4845. listedCount = listedCount.valueOr(0) + listReporters( config );
  4846. return listedCount;
  4847. }
  4848. } // end namespace Catch
  4849. // #included from: internal/catch_run_context.hpp
  4850. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  4851. // #included from: catch_test_case_tracker.hpp
  4852. #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  4853. #include <map>
  4854. #include <string>
  4855. #include <assert.h>
  4856. #include <vector>
  4857. #include <iterator>
  4858. #include <stdexcept>
  4859. namespace Catch {
  4860. namespace TestCaseTracking {
  4861. struct NameAndLocation {
  4862. std::string name;
  4863. SourceLineInfo location;
  4864. NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
  4865. : name( _name ),
  4866. location( _location )
  4867. {}
  4868. };
  4869. struct ITracker : SharedImpl<> {
  4870. virtual ~ITracker();
  4871. // static queries
  4872. virtual NameAndLocation const& nameAndLocation() const = 0;
  4873. // dynamic queries
  4874. virtual bool isComplete() const = 0; // Successfully completed or failed
  4875. virtual bool isSuccessfullyCompleted() const = 0;
  4876. virtual bool isOpen() const = 0; // Started but not complete
  4877. virtual bool hasChildren() const = 0;
  4878. virtual ITracker& parent() = 0;
  4879. // actions
  4880. virtual void close() = 0; // Successfully complete
  4881. virtual void fail() = 0;
  4882. virtual void markAsNeedingAnotherRun() = 0;
  4883. virtual void addChild( Ptr<ITracker> const& child ) = 0;
  4884. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0;
  4885. virtual void openChild() = 0;
  4886. // Debug/ checking
  4887. virtual bool isSectionTracker() const = 0;
  4888. virtual bool isIndexTracker() const = 0;
  4889. };
  4890. class TrackerContext {
  4891. enum RunState {
  4892. NotStarted,
  4893. Executing,
  4894. CompletedCycle
  4895. };
  4896. Ptr<ITracker> m_rootTracker;
  4897. ITracker* m_currentTracker;
  4898. RunState m_runState;
  4899. public:
  4900. static TrackerContext& instance() {
  4901. static TrackerContext s_instance;
  4902. return s_instance;
  4903. }
  4904. TrackerContext()
  4905. : m_currentTracker( CATCH_NULL ),
  4906. m_runState( NotStarted )
  4907. {}
  4908. ITracker& startRun();
  4909. void endRun() {
  4910. m_rootTracker.reset();
  4911. m_currentTracker = CATCH_NULL;
  4912. m_runState = NotStarted;
  4913. }
  4914. void startCycle() {
  4915. m_currentTracker = m_rootTracker.get();
  4916. m_runState = Executing;
  4917. }
  4918. void completeCycle() {
  4919. m_runState = CompletedCycle;
  4920. }
  4921. bool completedCycle() const {
  4922. return m_runState == CompletedCycle;
  4923. }
  4924. ITracker& currentTracker() {
  4925. return *m_currentTracker;
  4926. }
  4927. void setCurrentTracker( ITracker* tracker ) {
  4928. m_currentTracker = tracker;
  4929. }
  4930. };
  4931. class TrackerBase : public ITracker {
  4932. protected:
  4933. enum CycleState {
  4934. NotStarted,
  4935. Executing,
  4936. ExecutingChildren,
  4937. NeedsAnotherRun,
  4938. CompletedSuccessfully,
  4939. Failed
  4940. };
  4941. class TrackerHasName {
  4942. NameAndLocation m_nameAndLocation;
  4943. public:
  4944. TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {}
  4945. bool operator ()( Ptr<ITracker> const& tracker ) {
  4946. return
  4947. tracker->nameAndLocation().name == m_nameAndLocation.name &&
  4948. tracker->nameAndLocation().location == m_nameAndLocation.location;
  4949. }
  4950. };
  4951. typedef std::vector<Ptr<ITracker> > Children;
  4952. NameAndLocation m_nameAndLocation;
  4953. TrackerContext& m_ctx;
  4954. ITracker* m_parent;
  4955. Children m_children;
  4956. CycleState m_runState;
  4957. public:
  4958. TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  4959. : m_nameAndLocation( nameAndLocation ),
  4960. m_ctx( ctx ),
  4961. m_parent( parent ),
  4962. m_runState( NotStarted )
  4963. {}
  4964. virtual ~TrackerBase();
  4965. virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE {
  4966. return m_nameAndLocation;
  4967. }
  4968. virtual bool isComplete() const CATCH_OVERRIDE {
  4969. return m_runState == CompletedSuccessfully || m_runState == Failed;
  4970. }
  4971. virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
  4972. return m_runState == CompletedSuccessfully;
  4973. }
  4974. virtual bool isOpen() const CATCH_OVERRIDE {
  4975. return m_runState != NotStarted && !isComplete();
  4976. }
  4977. virtual bool hasChildren() const CATCH_OVERRIDE {
  4978. return !m_children.empty();
  4979. }
  4980. virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
  4981. m_children.push_back( child );
  4982. }
  4983. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE {
  4984. Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
  4985. return( it != m_children.end() )
  4986. ? it->get()
  4987. : CATCH_NULL;
  4988. }
  4989. virtual ITracker& parent() CATCH_OVERRIDE {
  4990. assert( m_parent ); // Should always be non-null except for root
  4991. return *m_parent;
  4992. }
  4993. virtual void openChild() CATCH_OVERRIDE {
  4994. if( m_runState != ExecutingChildren ) {
  4995. m_runState = ExecutingChildren;
  4996. if( m_parent )
  4997. m_parent->openChild();
  4998. }
  4999. }
  5000. virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
  5001. virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
  5002. void open() {
  5003. m_runState = Executing;
  5004. moveToThis();
  5005. if( m_parent )
  5006. m_parent->openChild();
  5007. }
  5008. virtual void close() CATCH_OVERRIDE {
  5009. // Close any still open children (e.g. generators)
  5010. while( &m_ctx.currentTracker() != this )
  5011. m_ctx.currentTracker().close();
  5012. switch( m_runState ) {
  5013. case NotStarted:
  5014. case CompletedSuccessfully:
  5015. case Failed:
  5016. throw std::logic_error( "Illogical state" );
  5017. case NeedsAnotherRun:
  5018. break;;
  5019. case Executing:
  5020. m_runState = CompletedSuccessfully;
  5021. break;
  5022. case ExecutingChildren:
  5023. if( m_children.empty() || m_children.back()->isComplete() )
  5024. m_runState = CompletedSuccessfully;
  5025. break;
  5026. default:
  5027. throw std::logic_error( "Unexpected state" );
  5028. }
  5029. moveToParent();
  5030. m_ctx.completeCycle();
  5031. }
  5032. virtual void fail() CATCH_OVERRIDE {
  5033. m_runState = Failed;
  5034. if( m_parent )
  5035. m_parent->markAsNeedingAnotherRun();
  5036. moveToParent();
  5037. m_ctx.completeCycle();
  5038. }
  5039. virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
  5040. m_runState = NeedsAnotherRun;
  5041. }
  5042. private:
  5043. void moveToParent() {
  5044. assert( m_parent );
  5045. m_ctx.setCurrentTracker( m_parent );
  5046. }
  5047. void moveToThis() {
  5048. m_ctx.setCurrentTracker( this );
  5049. }
  5050. };
  5051. class SectionTracker : public TrackerBase {
  5052. std::vector<std::string> m_filters;
  5053. public:
  5054. SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5055. : TrackerBase( nameAndLocation, ctx, parent )
  5056. {
  5057. if( parent ) {
  5058. while( !parent->isSectionTracker() )
  5059. parent = &parent->parent();
  5060. SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
  5061. addNextFilters( parentSection.m_filters );
  5062. }
  5063. }
  5064. virtual ~SectionTracker();
  5065. virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
  5066. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
  5067. SectionTracker* section = CATCH_NULL;
  5068. ITracker& currentTracker = ctx.currentTracker();
  5069. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5070. assert( childTracker );
  5071. assert( childTracker->isSectionTracker() );
  5072. section = static_cast<SectionTracker*>( childTracker );
  5073. }
  5074. else {
  5075. section = new SectionTracker( nameAndLocation, ctx, &currentTracker );
  5076. currentTracker.addChild( section );
  5077. }
  5078. if( !ctx.completedCycle() )
  5079. section->tryOpen();
  5080. return *section;
  5081. }
  5082. void tryOpen() {
  5083. if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) )
  5084. open();
  5085. }
  5086. void addInitialFilters( std::vector<std::string> const& filters ) {
  5087. if( !filters.empty() ) {
  5088. m_filters.push_back(""); // Root - should never be consulted
  5089. m_filters.push_back(""); // Test Case - not a section filter
  5090. std::copy( filters.begin(), filters.end(), std::back_inserter( m_filters ) );
  5091. }
  5092. }
  5093. void addNextFilters( std::vector<std::string> const& filters ) {
  5094. if( filters.size() > 1 )
  5095. std::copy( filters.begin()+1, filters.end(), std::back_inserter( m_filters ) );
  5096. }
  5097. };
  5098. class IndexTracker : public TrackerBase {
  5099. int m_size;
  5100. int m_index;
  5101. public:
  5102. IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size )
  5103. : TrackerBase( nameAndLocation, ctx, parent ),
  5104. m_size( size ),
  5105. m_index( -1 )
  5106. {}
  5107. virtual ~IndexTracker();
  5108. virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
  5109. static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) {
  5110. IndexTracker* tracker = CATCH_NULL;
  5111. ITracker& currentTracker = ctx.currentTracker();
  5112. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5113. assert( childTracker );
  5114. assert( childTracker->isIndexTracker() );
  5115. tracker = static_cast<IndexTracker*>( childTracker );
  5116. }
  5117. else {
  5118. tracker = new IndexTracker( nameAndLocation, ctx, &currentTracker, size );
  5119. currentTracker.addChild( tracker );
  5120. }
  5121. if( !ctx.completedCycle() && !tracker->isComplete() ) {
  5122. if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
  5123. tracker->moveNext();
  5124. tracker->open();
  5125. }
  5126. return *tracker;
  5127. }
  5128. int index() const { return m_index; }
  5129. void moveNext() {
  5130. m_index++;
  5131. m_children.clear();
  5132. }
  5133. virtual void close() CATCH_OVERRIDE {
  5134. TrackerBase::close();
  5135. if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
  5136. m_runState = Executing;
  5137. }
  5138. };
  5139. inline ITracker& TrackerContext::startRun() {
  5140. m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL );
  5141. m_currentTracker = CATCH_NULL;
  5142. m_runState = Executing;
  5143. return *m_rootTracker;
  5144. }
  5145. } // namespace TestCaseTracking
  5146. using TestCaseTracking::ITracker;
  5147. using TestCaseTracking::TrackerContext;
  5148. using TestCaseTracking::SectionTracker;
  5149. using TestCaseTracking::IndexTracker;
  5150. } // namespace Catch
  5151. // #included from: catch_fatal_condition.hpp
  5152. #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
  5153. namespace Catch {
  5154. // Report the error condition
  5155. inline void reportFatal( std::string const& message ) {
  5156. IContext& context = Catch::getCurrentContext();
  5157. IResultCapture* resultCapture = context.getResultCapture();
  5158. resultCapture->handleFatalErrorCondition( message );
  5159. }
  5160. } // namespace Catch
  5161. #if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
  5162. // #included from: catch_windows_h_proxy.h
  5163. #define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED
  5164. #ifdef CATCH_DEFINES_NOMINMAX
  5165. # define NOMINMAX
  5166. #endif
  5167. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5168. # define WIN32_LEAN_AND_MEAN
  5169. #endif
  5170. #ifdef __AFXDLL
  5171. #include <AfxWin.h>
  5172. #else
  5173. #include <windows.h>
  5174. #endif
  5175. #ifdef CATCH_DEFINES_NOMINMAX
  5176. # undef NOMINMAX
  5177. #endif
  5178. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5179. # undef WIN32_LEAN_AND_MEAN
  5180. #endif
  5181. # if !defined ( CATCH_CONFIG_WINDOWS_SEH )
  5182. namespace Catch {
  5183. struct FatalConditionHandler {
  5184. void reset() {}
  5185. };
  5186. }
  5187. # else // CATCH_CONFIG_WINDOWS_SEH is defined
  5188. namespace Catch {
  5189. struct SignalDefs { DWORD id; const char* name; };
  5190. extern SignalDefs signalDefs[];
  5191. // There is no 1-1 mapping between signals and windows exceptions.
  5192. // Windows can easily distinguish between SO and SigSegV,
  5193. // but SigInt, SigTerm, etc are handled differently.
  5194. SignalDefs signalDefs[] = {
  5195. { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
  5196. { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
  5197. { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
  5198. { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" },
  5199. };
  5200. struct FatalConditionHandler {
  5201. static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
  5202. for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5203. if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
  5204. reset();
  5205. reportFatal(signalDefs[i].name);
  5206. }
  5207. }
  5208. // If its not an exception we care about, pass it along.
  5209. // This stops us from eating debugger breaks etc.
  5210. return EXCEPTION_CONTINUE_SEARCH;
  5211. }
  5212. FatalConditionHandler() {
  5213. isSet = true;
  5214. // 32k seems enough for Catch to handle stack overflow,
  5215. // but the value was found experimentally, so there is no strong guarantee
  5216. guaranteeSize = 32 * 1024;
  5217. exceptionHandlerHandle = CATCH_NULL;
  5218. // Register as first handler in current chain
  5219. exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
  5220. // Pass in guarantee size to be filled
  5221. SetThreadStackGuarantee(&guaranteeSize);
  5222. }
  5223. static void reset() {
  5224. if (isSet) {
  5225. // Unregister handler and restore the old guarantee
  5226. RemoveVectoredExceptionHandler(exceptionHandlerHandle);
  5227. SetThreadStackGuarantee(&guaranteeSize);
  5228. exceptionHandlerHandle = CATCH_NULL;
  5229. isSet = false;
  5230. }
  5231. }
  5232. ~FatalConditionHandler() {
  5233. reset();
  5234. }
  5235. private:
  5236. static bool isSet;
  5237. static ULONG guaranteeSize;
  5238. static PVOID exceptionHandlerHandle;
  5239. };
  5240. bool FatalConditionHandler::isSet = false;
  5241. ULONG FatalConditionHandler::guaranteeSize = 0;
  5242. PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL;
  5243. } // namespace Catch
  5244. # endif // CATCH_CONFIG_WINDOWS_SEH
  5245. #else // Not Windows - assumed to be POSIX compatible //////////////////////////
  5246. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  5247. namespace Catch {
  5248. struct FatalConditionHandler {
  5249. void reset() {}
  5250. };
  5251. }
  5252. # else // CATCH_CONFIG_POSIX_SIGNALS is defined
  5253. #include <signal.h>
  5254. namespace Catch {
  5255. struct SignalDefs {
  5256. int id;
  5257. const char* name;
  5258. };
  5259. extern SignalDefs signalDefs[];
  5260. SignalDefs signalDefs[] = {
  5261. { SIGINT, "SIGINT - Terminal interrupt signal" },
  5262. { SIGILL, "SIGILL - Illegal instruction signal" },
  5263. { SIGFPE, "SIGFPE - Floating point error signal" },
  5264. { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
  5265. { SIGTERM, "SIGTERM - Termination request signal" },
  5266. { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
  5267. };
  5268. struct FatalConditionHandler {
  5269. static bool isSet;
  5270. static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)];
  5271. static stack_t oldSigStack;
  5272. static char altStackMem[SIGSTKSZ];
  5273. static void handleSignal( int sig ) {
  5274. std::string name = "<unknown signal>";
  5275. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5276. SignalDefs &def = signalDefs[i];
  5277. if (sig == def.id) {
  5278. name = def.name;
  5279. break;
  5280. }
  5281. }
  5282. reset();
  5283. reportFatal(name);
  5284. raise( sig );
  5285. }
  5286. FatalConditionHandler() {
  5287. isSet = true;
  5288. stack_t sigStack;
  5289. sigStack.ss_sp = altStackMem;
  5290. sigStack.ss_size = SIGSTKSZ;
  5291. sigStack.ss_flags = 0;
  5292. sigaltstack(&sigStack, &oldSigStack);
  5293. struct sigaction sa = { 0 };
  5294. sa.sa_handler = handleSignal;
  5295. sa.sa_flags = SA_ONSTACK;
  5296. for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
  5297. sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
  5298. }
  5299. }
  5300. ~FatalConditionHandler() {
  5301. reset();
  5302. }
  5303. static void reset() {
  5304. if( isSet ) {
  5305. // Set signals back to previous values -- hopefully nobody overwrote them in the meantime
  5306. for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
  5307. sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL);
  5308. }
  5309. // Return the old stack
  5310. sigaltstack(&oldSigStack, CATCH_NULL);
  5311. isSet = false;
  5312. }
  5313. }
  5314. };
  5315. bool FatalConditionHandler::isSet = false;
  5316. struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
  5317. stack_t FatalConditionHandler::oldSigStack = {};
  5318. char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
  5319. } // namespace Catch
  5320. # endif // CATCH_CONFIG_POSIX_SIGNALS
  5321. #endif // not Windows
  5322. #include <set>
  5323. #include <string>
  5324. namespace Catch {
  5325. class StreamRedirect {
  5326. public:
  5327. StreamRedirect( std::ostream& stream, std::string& targetString )
  5328. : m_stream( stream ),
  5329. m_prevBuf( stream.rdbuf() ),
  5330. m_targetString( targetString )
  5331. {
  5332. stream.rdbuf( m_oss.rdbuf() );
  5333. }
  5334. ~StreamRedirect() {
  5335. m_targetString += m_oss.str();
  5336. m_stream.rdbuf( m_prevBuf );
  5337. }
  5338. private:
  5339. std::ostream& m_stream;
  5340. std::streambuf* m_prevBuf;
  5341. std::ostringstream m_oss;
  5342. std::string& m_targetString;
  5343. };
  5344. ///////////////////////////////////////////////////////////////////////////
  5345. class RunContext : public IResultCapture, public IRunner {
  5346. RunContext( RunContext const& );
  5347. void operator =( RunContext const& );
  5348. public:
  5349. explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
  5350. : m_runInfo( _config->name() ),
  5351. m_context( getCurrentMutableContext() ),
  5352. m_activeTestCase( CATCH_NULL ),
  5353. m_config( _config ),
  5354. m_reporter( reporter )
  5355. {
  5356. m_context.setRunner( this );
  5357. m_context.setConfig( m_config );
  5358. m_context.setResultCapture( this );
  5359. m_reporter->testRunStarting( m_runInfo );
  5360. }
  5361. virtual ~RunContext() {
  5362. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
  5363. }
  5364. void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
  5365. m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
  5366. }
  5367. void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
  5368. m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
  5369. }
  5370. Totals runTest( TestCase const& testCase ) {
  5371. Totals prevTotals = m_totals;
  5372. std::string redirectedCout;
  5373. std::string redirectedCerr;
  5374. TestCaseInfo testInfo = testCase.getTestCaseInfo();
  5375. m_reporter->testCaseStarting( testInfo );
  5376. m_activeTestCase = &testCase;
  5377. do {
  5378. ITracker& rootTracker = m_trackerContext.startRun();
  5379. assert( rootTracker.isSectionTracker() );
  5380. static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() );
  5381. do {
  5382. m_trackerContext.startCycle();
  5383. m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) );
  5384. runCurrentTest( redirectedCout, redirectedCerr );
  5385. }
  5386. while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
  5387. }
  5388. // !TBD: deprecated - this will be replaced by indexed trackers
  5389. while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
  5390. Totals deltaTotals = m_totals.delta( prevTotals );
  5391. if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
  5392. deltaTotals.assertions.failed++;
  5393. deltaTotals.testCases.passed--;
  5394. deltaTotals.testCases.failed++;
  5395. }
  5396. m_totals.testCases += deltaTotals.testCases;
  5397. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5398. deltaTotals,
  5399. redirectedCout,
  5400. redirectedCerr,
  5401. aborting() ) );
  5402. m_activeTestCase = CATCH_NULL;
  5403. m_testCaseTracker = CATCH_NULL;
  5404. return deltaTotals;
  5405. }
  5406. Ptr<IConfig const> config() const {
  5407. return m_config;
  5408. }
  5409. private: // IResultCapture
  5410. virtual void assertionEnded( AssertionResult const& result ) {
  5411. if( result.getResultType() == ResultWas::Ok ) {
  5412. m_totals.assertions.passed++;
  5413. }
  5414. else if( !result.isOk() ) {
  5415. m_totals.assertions.failed++;
  5416. }
  5417. if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) )
  5418. m_messages.clear();
  5419. // Reset working state
  5420. m_lastAssertionInfo = AssertionInfo( std::string(), m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
  5421. m_lastResult = result;
  5422. }
  5423. virtual bool sectionStarted (
  5424. SectionInfo const& sectionInfo,
  5425. Counts& assertions
  5426. )
  5427. {
  5428. ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) );
  5429. if( !sectionTracker.isOpen() )
  5430. return false;
  5431. m_activeSections.push_back( &sectionTracker );
  5432. m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
  5433. m_reporter->sectionStarting( sectionInfo );
  5434. assertions = m_totals.assertions;
  5435. return true;
  5436. }
  5437. bool testForMissingAssertions( Counts& assertions ) {
  5438. if( assertions.total() != 0 )
  5439. return false;
  5440. if( !m_config->warnAboutMissingAssertions() )
  5441. return false;
  5442. if( m_trackerContext.currentTracker().hasChildren() )
  5443. return false;
  5444. m_totals.assertions.failed++;
  5445. assertions.failed++;
  5446. return true;
  5447. }
  5448. virtual void sectionEnded( SectionEndInfo const& endInfo ) {
  5449. Counts assertions = m_totals.assertions - endInfo.prevAssertions;
  5450. bool missingAssertions = testForMissingAssertions( assertions );
  5451. if( !m_activeSections.empty() ) {
  5452. m_activeSections.back()->close();
  5453. m_activeSections.pop_back();
  5454. }
  5455. m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
  5456. m_messages.clear();
  5457. }
  5458. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
  5459. if( m_unfinishedSections.empty() )
  5460. m_activeSections.back()->fail();
  5461. else
  5462. m_activeSections.back()->close();
  5463. m_activeSections.pop_back();
  5464. m_unfinishedSections.push_back( endInfo );
  5465. }
  5466. virtual void pushScopedMessage( MessageInfo const& message ) {
  5467. m_messages.push_back( message );
  5468. }
  5469. virtual void popScopedMessage( MessageInfo const& message ) {
  5470. m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
  5471. }
  5472. virtual std::string getCurrentTestName() const {
  5473. return m_activeTestCase
  5474. ? m_activeTestCase->getTestCaseInfo().name
  5475. : std::string();
  5476. }
  5477. virtual const AssertionResult* getLastResult() const {
  5478. return &m_lastResult;
  5479. }
  5480. virtual void handleFatalErrorCondition( std::string const& message ) {
  5481. ResultBuilder resultBuilder = makeUnexpectedResultBuilder();
  5482. resultBuilder.setResultType( ResultWas::FatalErrorCondition );
  5483. resultBuilder << message;
  5484. resultBuilder.captureExpression();
  5485. handleUnfinishedSections();
  5486. // Recreate section for test case (as we will lose the one that was in scope)
  5487. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5488. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5489. Counts assertions;
  5490. assertions.failed = 1;
  5491. SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
  5492. m_reporter->sectionEnded( testCaseSectionStats );
  5493. TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
  5494. Totals deltaTotals;
  5495. deltaTotals.testCases.failed = 1;
  5496. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5497. deltaTotals,
  5498. std::string(),
  5499. std::string(),
  5500. false ) );
  5501. m_totals.testCases.failed++;
  5502. testGroupEnded( std::string(), m_totals, 1, 1 );
  5503. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
  5504. }
  5505. public:
  5506. // !TBD We need to do this another way!
  5507. bool aborting() const {
  5508. return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
  5509. }
  5510. private:
  5511. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
  5512. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5513. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5514. m_reporter->sectionStarting( testCaseSection );
  5515. Counts prevAssertions = m_totals.assertions;
  5516. double duration = 0;
  5517. try {
  5518. m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, std::string(), ResultDisposition::Normal );
  5519. seedRng( *m_config );
  5520. Timer timer;
  5521. timer.start();
  5522. if( m_reporter->getPreferences().shouldRedirectStdOut ) {
  5523. StreamRedirect coutRedir( Catch::cout(), redirectedCout );
  5524. StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr );
  5525. invokeActiveTestCase();
  5526. }
  5527. else {
  5528. invokeActiveTestCase();
  5529. }
  5530. duration = timer.getElapsedSeconds();
  5531. }
  5532. catch( TestFailureException& ) {
  5533. // This just means the test was aborted due to failure
  5534. }
  5535. catch(...) {
  5536. makeUnexpectedResultBuilder().useActiveException();
  5537. }
  5538. m_testCaseTracker->close();
  5539. handleUnfinishedSections();
  5540. m_messages.clear();
  5541. Counts assertions = m_totals.assertions - prevAssertions;
  5542. bool missingAssertions = testForMissingAssertions( assertions );
  5543. if( testCaseInfo.okToFail() ) {
  5544. std::swap( assertions.failedButOk, assertions.failed );
  5545. m_totals.assertions.failed -= assertions.failedButOk;
  5546. m_totals.assertions.failedButOk += assertions.failedButOk;
  5547. }
  5548. SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
  5549. m_reporter->sectionEnded( testCaseSectionStats );
  5550. }
  5551. void invokeActiveTestCase() {
  5552. FatalConditionHandler fatalConditionHandler; // Handle signals
  5553. m_activeTestCase->invoke();
  5554. fatalConditionHandler.reset();
  5555. }
  5556. private:
  5557. ResultBuilder makeUnexpectedResultBuilder() const {
  5558. return ResultBuilder( m_lastAssertionInfo.macroName.c_str(),
  5559. m_lastAssertionInfo.lineInfo,
  5560. m_lastAssertionInfo.capturedExpression.c_str(),
  5561. m_lastAssertionInfo.resultDisposition );
  5562. }
  5563. void handleUnfinishedSections() {
  5564. // If sections ended prematurely due to an exception we stored their
  5565. // infos here so we can tear them down outside the unwind process.
  5566. for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
  5567. itEnd = m_unfinishedSections.rend();
  5568. it != itEnd;
  5569. ++it )
  5570. sectionEnded( *it );
  5571. m_unfinishedSections.clear();
  5572. }
  5573. TestRunInfo m_runInfo;
  5574. IMutableContext& m_context;
  5575. TestCase const* m_activeTestCase;
  5576. ITracker* m_testCaseTracker;
  5577. ITracker* m_currentSectionTracker;
  5578. AssertionResult m_lastResult;
  5579. Ptr<IConfig const> m_config;
  5580. Totals m_totals;
  5581. Ptr<IStreamingReporter> m_reporter;
  5582. std::vector<MessageInfo> m_messages;
  5583. AssertionInfo m_lastAssertionInfo;
  5584. std::vector<SectionEndInfo> m_unfinishedSections;
  5585. std::vector<ITracker*> m_activeSections;
  5586. TrackerContext m_trackerContext;
  5587. };
  5588. IResultCapture& getResultCapture() {
  5589. if( IResultCapture* capture = getCurrentContext().getResultCapture() )
  5590. return *capture;
  5591. else
  5592. throw std::logic_error( "No result capture instance" );
  5593. }
  5594. } // end namespace Catch
  5595. // #included from: internal/catch_version.h
  5596. #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
  5597. namespace Catch {
  5598. // Versioning information
  5599. struct Version {
  5600. Version( unsigned int _majorVersion,
  5601. unsigned int _minorVersion,
  5602. unsigned int _patchNumber,
  5603. std::string const& _branchName,
  5604. unsigned int _buildNumber );
  5605. unsigned int const majorVersion;
  5606. unsigned int const minorVersion;
  5607. unsigned int const patchNumber;
  5608. // buildNumber is only used if branchName is not null
  5609. std::string const branchName;
  5610. unsigned int const buildNumber;
  5611. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5612. private:
  5613. void operator=( Version const& );
  5614. };
  5615. extern Version libraryVersion;
  5616. }
  5617. #include <fstream>
  5618. #include <stdlib.h>
  5619. #include <limits>
  5620. namespace Catch {
  5621. Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
  5622. Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
  5623. if( !reporter ) {
  5624. std::ostringstream oss;
  5625. oss << "No reporter registered with name: '" << reporterName << "'";
  5626. throw std::domain_error( oss.str() );
  5627. }
  5628. return reporter;
  5629. }
  5630. Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
  5631. std::vector<std::string> reporters = config->getReporterNames();
  5632. if( reporters.empty() )
  5633. reporters.push_back( "console" );
  5634. Ptr<IStreamingReporter> reporter;
  5635. for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
  5636. it != itEnd;
  5637. ++it )
  5638. reporter = addReporter( reporter, createReporter( *it, config ) );
  5639. return reporter;
  5640. }
  5641. Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
  5642. IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
  5643. for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
  5644. it != itEnd;
  5645. ++it )
  5646. reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
  5647. return reporters;
  5648. }
  5649. Totals runTests( Ptr<Config> const& config ) {
  5650. Ptr<IConfig const> iconfig = config.get();
  5651. Ptr<IStreamingReporter> reporter = makeReporter( config );
  5652. reporter = addListeners( iconfig, reporter );
  5653. RunContext context( iconfig, reporter );
  5654. Totals totals;
  5655. context.testGroupStarting( config->name(), 1, 1 );
  5656. TestSpec testSpec = config->testSpec();
  5657. if( !testSpec.hasFilters() )
  5658. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
  5659. std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
  5660. for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
  5661. it != itEnd;
  5662. ++it ) {
  5663. if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
  5664. totals += context.runTest( *it );
  5665. else
  5666. reporter->skipTest( *it );
  5667. }
  5668. context.testGroupEnded( iconfig->name(), totals, 1, 1 );
  5669. return totals;
  5670. }
  5671. void applyFilenamesAsTags( IConfig const& config ) {
  5672. std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
  5673. for(std::size_t i = 0; i < tests.size(); ++i ) {
  5674. TestCase& test = const_cast<TestCase&>( tests[i] );
  5675. std::set<std::string> tags = test.tags;
  5676. std::string filename = test.lineInfo.file;
  5677. std::string::size_type lastSlash = filename.find_last_of( "\\/" );
  5678. if( lastSlash != std::string::npos )
  5679. filename = filename.substr( lastSlash+1 );
  5680. std::string::size_type lastDot = filename.find_last_of( "." );
  5681. if( lastDot != std::string::npos )
  5682. filename = filename.substr( 0, lastDot );
  5683. tags.insert( "#" + filename );
  5684. setTags( test, tags );
  5685. }
  5686. }
  5687. class Session : NonCopyable {
  5688. static bool alreadyInstantiated;
  5689. public:
  5690. struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
  5691. Session()
  5692. : m_cli( makeCommandLineParser() ) {
  5693. if( alreadyInstantiated ) {
  5694. std::string msg = "Only one instance of Catch::Session can ever be used";
  5695. Catch::cerr() << msg << std::endl;
  5696. throw std::logic_error( msg );
  5697. }
  5698. alreadyInstantiated = true;
  5699. }
  5700. ~Session() {
  5701. Catch::cleanUp();
  5702. }
  5703. void showHelp( std::string const& processName ) {
  5704. Catch::cout() << "\nCatch v" << libraryVersion << "\n";
  5705. m_cli.usage( Catch::cout(), processName );
  5706. Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
  5707. }
  5708. int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
  5709. try {
  5710. m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
  5711. m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
  5712. if( m_configData.showHelp )
  5713. showHelp( m_configData.processName );
  5714. m_config.reset();
  5715. }
  5716. catch( std::exception& ex ) {
  5717. {
  5718. Colour colourGuard( Colour::Red );
  5719. Catch::cerr()
  5720. << "\nError(s) in input:\n"
  5721. << Text( ex.what(), TextAttributes().setIndent(2) )
  5722. << "\n\n";
  5723. }
  5724. m_cli.usage( Catch::cout(), m_configData.processName );
  5725. return (std::numeric_limits<int>::max)();
  5726. }
  5727. return 0;
  5728. }
  5729. void useConfigData( ConfigData const& _configData ) {
  5730. m_configData = _configData;
  5731. m_config.reset();
  5732. }
  5733. int run( int argc, char const* const* const argv ) {
  5734. int returnCode = applyCommandLine( argc, argv );
  5735. if( returnCode == 0 )
  5736. returnCode = run();
  5737. return returnCode;
  5738. }
  5739. int run() {
  5740. if( m_configData.showHelp )
  5741. return 0;
  5742. try
  5743. {
  5744. config(); // Force config to be constructed
  5745. seedRng( *m_config );
  5746. if( m_configData.filenamesAsTags )
  5747. applyFilenamesAsTags( *m_config );
  5748. // Handle list request
  5749. if( Option<std::size_t> listed = list( config() ) )
  5750. return static_cast<int>( *listed );
  5751. return static_cast<int>( runTests( m_config ).assertions.failed );
  5752. }
  5753. catch( std::exception& ex ) {
  5754. Catch::cerr() << ex.what() << std::endl;
  5755. return (std::numeric_limits<int>::max)();
  5756. }
  5757. }
  5758. Clara::CommandLine<ConfigData> const& cli() const {
  5759. return m_cli;
  5760. }
  5761. std::vector<Clara::Parser::Token> const& unusedTokens() const {
  5762. return m_unusedTokens;
  5763. }
  5764. ConfigData& configData() {
  5765. return m_configData;
  5766. }
  5767. Config& config() {
  5768. if( !m_config )
  5769. m_config = new Config( m_configData );
  5770. return *m_config;
  5771. }
  5772. private:
  5773. Clara::CommandLine<ConfigData> m_cli;
  5774. std::vector<Clara::Parser::Token> m_unusedTokens;
  5775. ConfigData m_configData;
  5776. Ptr<Config> m_config;
  5777. };
  5778. bool Session::alreadyInstantiated = false;
  5779. } // end namespace Catch
  5780. // #included from: catch_registry_hub.hpp
  5781. #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
  5782. // #included from: catch_test_case_registry_impl.hpp
  5783. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  5784. #include <vector>
  5785. #include <set>
  5786. #include <sstream>
  5787. #include <algorithm>
  5788. namespace Catch {
  5789. struct RandomNumberGenerator {
  5790. typedef std::ptrdiff_t result_type;
  5791. result_type operator()( result_type n ) const { return std::rand() % n; }
  5792. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  5793. static constexpr result_type min() { return 0; }
  5794. static constexpr result_type max() { return 1000000; }
  5795. result_type operator()() const { return std::rand() % max(); }
  5796. #endif
  5797. template<typename V>
  5798. static void shuffle( V& vector ) {
  5799. RandomNumberGenerator rng;
  5800. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  5801. std::shuffle( vector.begin(), vector.end(), rng );
  5802. #else
  5803. std::random_shuffle( vector.begin(), vector.end(), rng );
  5804. #endif
  5805. }
  5806. };
  5807. inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
  5808. std::vector<TestCase> sorted = unsortedTestCases;
  5809. switch( config.runOrder() ) {
  5810. case RunTests::InLexicographicalOrder:
  5811. std::sort( sorted.begin(), sorted.end() );
  5812. break;
  5813. case RunTests::InRandomOrder:
  5814. {
  5815. seedRng( config );
  5816. RandomNumberGenerator::shuffle( sorted );
  5817. }
  5818. break;
  5819. case RunTests::InDeclarationOrder:
  5820. // already in declaration order
  5821. break;
  5822. }
  5823. return sorted;
  5824. }
  5825. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
  5826. return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
  5827. }
  5828. void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
  5829. std::set<TestCase> seenFunctions;
  5830. for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
  5831. it != itEnd;
  5832. ++it ) {
  5833. std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
  5834. if( !prev.second ) {
  5835. std::ostringstream ss;
  5836. ss << Colour( Colour::Red )
  5837. << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
  5838. << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n'
  5839. << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
  5840. throw std::runtime_error(ss.str());
  5841. }
  5842. }
  5843. }
  5844. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
  5845. std::vector<TestCase> filtered;
  5846. filtered.reserve( testCases.size() );
  5847. for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
  5848. it != itEnd;
  5849. ++it )
  5850. if( matchTest( *it, testSpec, config ) )
  5851. filtered.push_back( *it );
  5852. return filtered;
  5853. }
  5854. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
  5855. return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
  5856. }
  5857. class TestRegistry : public ITestCaseRegistry {
  5858. public:
  5859. TestRegistry()
  5860. : m_currentSortOrder( RunTests::InDeclarationOrder ),
  5861. m_unnamedCount( 0 )
  5862. {}
  5863. virtual ~TestRegistry();
  5864. virtual void registerTest( TestCase const& testCase ) {
  5865. std::string name = testCase.getTestCaseInfo().name;
  5866. if( name.empty() ) {
  5867. std::ostringstream oss;
  5868. oss << "Anonymous test case " << ++m_unnamedCount;
  5869. return registerTest( testCase.withName( oss.str() ) );
  5870. }
  5871. m_functions.push_back( testCase );
  5872. }
  5873. virtual std::vector<TestCase> const& getAllTests() const {
  5874. return m_functions;
  5875. }
  5876. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
  5877. if( m_sortedFunctions.empty() )
  5878. enforceNoDuplicateTestCases( m_functions );
  5879. if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
  5880. m_sortedFunctions = sortTests( config, m_functions );
  5881. m_currentSortOrder = config.runOrder();
  5882. }
  5883. return m_sortedFunctions;
  5884. }
  5885. private:
  5886. std::vector<TestCase> m_functions;
  5887. mutable RunTests::InWhatOrder m_currentSortOrder;
  5888. mutable std::vector<TestCase> m_sortedFunctions;
  5889. size_t m_unnamedCount;
  5890. std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
  5891. };
  5892. ///////////////////////////////////////////////////////////////////////////
  5893. class FreeFunctionTestCase : public SharedImpl<ITestCase> {
  5894. public:
  5895. FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
  5896. virtual void invoke() const {
  5897. m_fun();
  5898. }
  5899. private:
  5900. virtual ~FreeFunctionTestCase();
  5901. TestFunction m_fun;
  5902. };
  5903. inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
  5904. std::string className = classOrQualifiedMethodName;
  5905. if( startsWith( className, '&' ) )
  5906. {
  5907. std::size_t lastColons = className.rfind( "::" );
  5908. std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
  5909. if( penultimateColons == std::string::npos )
  5910. penultimateColons = 1;
  5911. className = className.substr( penultimateColons, lastColons-penultimateColons );
  5912. }
  5913. return className;
  5914. }
  5915. void registerTestCase
  5916. ( ITestCase* testCase,
  5917. char const* classOrQualifiedMethodName,
  5918. NameAndDesc const& nameAndDesc,
  5919. SourceLineInfo const& lineInfo ) {
  5920. getMutableRegistryHub().registerTest
  5921. ( makeTestCase
  5922. ( testCase,
  5923. extractClassName( classOrQualifiedMethodName ),
  5924. nameAndDesc.name,
  5925. nameAndDesc.description,
  5926. lineInfo ) );
  5927. }
  5928. void registerTestCaseFunction
  5929. ( TestFunction function,
  5930. SourceLineInfo const& lineInfo,
  5931. NameAndDesc const& nameAndDesc ) {
  5932. registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
  5933. }
  5934. ///////////////////////////////////////////////////////////////////////////
  5935. AutoReg::AutoReg
  5936. ( TestFunction function,
  5937. SourceLineInfo const& lineInfo,
  5938. NameAndDesc const& nameAndDesc ) {
  5939. registerTestCaseFunction( function, lineInfo, nameAndDesc );
  5940. }
  5941. AutoReg::~AutoReg() {}
  5942. } // end namespace Catch
  5943. // #included from: catch_reporter_registry.hpp
  5944. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  5945. #include <map>
  5946. namespace Catch {
  5947. class ReporterRegistry : public IReporterRegistry {
  5948. public:
  5949. virtual ~ReporterRegistry() CATCH_OVERRIDE {}
  5950. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
  5951. FactoryMap::const_iterator it = m_factories.find( name );
  5952. if( it == m_factories.end() )
  5953. return CATCH_NULL;
  5954. return it->second->create( ReporterConfig( config ) );
  5955. }
  5956. void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
  5957. m_factories.insert( std::make_pair( name, factory ) );
  5958. }
  5959. void registerListener( Ptr<IReporterFactory> const& factory ) {
  5960. m_listeners.push_back( factory );
  5961. }
  5962. virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
  5963. return m_factories;
  5964. }
  5965. virtual Listeners const& getListeners() const CATCH_OVERRIDE {
  5966. return m_listeners;
  5967. }
  5968. private:
  5969. FactoryMap m_factories;
  5970. Listeners m_listeners;
  5971. };
  5972. }
  5973. // #included from: catch_exception_translator_registry.hpp
  5974. #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  5975. #ifdef __OBJC__
  5976. #import "Foundation/Foundation.h"
  5977. #endif
  5978. namespace Catch {
  5979. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  5980. public:
  5981. ~ExceptionTranslatorRegistry() {
  5982. deleteAll( m_translators );
  5983. }
  5984. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  5985. m_translators.push_back( translator );
  5986. }
  5987. virtual std::string translateActiveException() const {
  5988. try {
  5989. #ifdef __OBJC__
  5990. // In Objective-C try objective-c exceptions first
  5991. @try {
  5992. return tryTranslators();
  5993. }
  5994. @catch (NSException *exception) {
  5995. return Catch::toString( [exception description] );
  5996. }
  5997. #else
  5998. return tryTranslators();
  5999. #endif
  6000. }
  6001. catch( TestFailureException& ) {
  6002. throw;
  6003. }
  6004. catch( std::exception& ex ) {
  6005. return ex.what();
  6006. }
  6007. catch( std::string& msg ) {
  6008. return msg;
  6009. }
  6010. catch( const char* msg ) {
  6011. return msg;
  6012. }
  6013. catch(...) {
  6014. return "Unknown exception";
  6015. }
  6016. }
  6017. std::string tryTranslators() const {
  6018. if( m_translators.empty() )
  6019. throw;
  6020. else
  6021. return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
  6022. }
  6023. private:
  6024. std::vector<const IExceptionTranslator*> m_translators;
  6025. };
  6026. }
  6027. namespace Catch {
  6028. namespace {
  6029. class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
  6030. RegistryHub( RegistryHub const& );
  6031. void operator=( RegistryHub const& );
  6032. public: // IRegistryHub
  6033. RegistryHub() {
  6034. }
  6035. virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
  6036. return m_reporterRegistry;
  6037. }
  6038. virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
  6039. return m_testCaseRegistry;
  6040. }
  6041. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
  6042. return m_exceptionTranslatorRegistry;
  6043. }
  6044. public: // IMutableRegistryHub
  6045. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6046. m_reporterRegistry.registerReporter( name, factory );
  6047. }
  6048. virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6049. m_reporterRegistry.registerListener( factory );
  6050. }
  6051. virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
  6052. m_testCaseRegistry.registerTest( testInfo );
  6053. }
  6054. virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
  6055. m_exceptionTranslatorRegistry.registerTranslator( translator );
  6056. }
  6057. private:
  6058. TestRegistry m_testCaseRegistry;
  6059. ReporterRegistry m_reporterRegistry;
  6060. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  6061. };
  6062. // Single, global, instance
  6063. inline RegistryHub*& getTheRegistryHub() {
  6064. static RegistryHub* theRegistryHub = CATCH_NULL;
  6065. if( !theRegistryHub )
  6066. theRegistryHub = new RegistryHub();
  6067. return theRegistryHub;
  6068. }
  6069. }
  6070. IRegistryHub& getRegistryHub() {
  6071. return *getTheRegistryHub();
  6072. }
  6073. IMutableRegistryHub& getMutableRegistryHub() {
  6074. return *getTheRegistryHub();
  6075. }
  6076. void cleanUp() {
  6077. delete getTheRegistryHub();
  6078. getTheRegistryHub() = CATCH_NULL;
  6079. cleanUpContext();
  6080. }
  6081. std::string translateActiveException() {
  6082. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  6083. }
  6084. } // end namespace Catch
  6085. // #included from: catch_notimplemented_exception.hpp
  6086. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
  6087. #include <sstream>
  6088. namespace Catch {
  6089. NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
  6090. : m_lineInfo( lineInfo ) {
  6091. std::ostringstream oss;
  6092. oss << lineInfo << ": function ";
  6093. oss << "not implemented";
  6094. m_what = oss.str();
  6095. }
  6096. const char* NotImplementedException::what() const CATCH_NOEXCEPT {
  6097. return m_what.c_str();
  6098. }
  6099. } // end namespace Catch
  6100. // #included from: catch_context_impl.hpp
  6101. #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
  6102. // #included from: catch_stream.hpp
  6103. #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
  6104. #include <stdexcept>
  6105. #include <cstdio>
  6106. #include <iostream>
  6107. namespace Catch {
  6108. template<typename WriterF, size_t bufferSize=256>
  6109. class StreamBufImpl : public StreamBufBase {
  6110. char data[bufferSize];
  6111. WriterF m_writer;
  6112. public:
  6113. StreamBufImpl() {
  6114. setp( data, data + sizeof(data) );
  6115. }
  6116. ~StreamBufImpl() CATCH_NOEXCEPT {
  6117. sync();
  6118. }
  6119. private:
  6120. int overflow( int c ) {
  6121. sync();
  6122. if( c != EOF ) {
  6123. if( pbase() == epptr() )
  6124. m_writer( std::string( 1, static_cast<char>( c ) ) );
  6125. else
  6126. sputc( static_cast<char>( c ) );
  6127. }
  6128. return 0;
  6129. }
  6130. int sync() {
  6131. if( pbase() != pptr() ) {
  6132. m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
  6133. setp( pbase(), epptr() );
  6134. }
  6135. return 0;
  6136. }
  6137. };
  6138. ///////////////////////////////////////////////////////////////////////////
  6139. FileStream::FileStream( std::string const& filename ) {
  6140. m_ofs.open( filename.c_str() );
  6141. if( m_ofs.fail() ) {
  6142. std::ostringstream oss;
  6143. oss << "Unable to open file: '" << filename << '\'';
  6144. throw std::domain_error( oss.str() );
  6145. }
  6146. }
  6147. std::ostream& FileStream::stream() const {
  6148. return m_ofs;
  6149. }
  6150. struct OutputDebugWriter {
  6151. void operator()( std::string const&str ) {
  6152. writeToDebugConsole( str );
  6153. }
  6154. };
  6155. DebugOutStream::DebugOutStream()
  6156. : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
  6157. m_os( m_streamBuf.get() )
  6158. {}
  6159. std::ostream& DebugOutStream::stream() const {
  6160. return m_os;
  6161. }
  6162. // Store the streambuf from cout up-front because
  6163. // cout may get redirected when running tests
  6164. CoutStream::CoutStream()
  6165. : m_os( Catch::cout().rdbuf() )
  6166. {}
  6167. std::ostream& CoutStream::stream() const {
  6168. return m_os;
  6169. }
  6170. #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
  6171. std::ostream& cout() {
  6172. return std::cout;
  6173. }
  6174. std::ostream& cerr() {
  6175. return std::cerr;
  6176. }
  6177. #endif
  6178. }
  6179. namespace Catch {
  6180. class Context : public IMutableContext {
  6181. Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
  6182. Context( Context const& );
  6183. void operator=( Context const& );
  6184. public:
  6185. virtual ~Context() {
  6186. deleteAllValues( m_generatorsByTestName );
  6187. }
  6188. public: // IContext
  6189. virtual IResultCapture* getResultCapture() {
  6190. return m_resultCapture;
  6191. }
  6192. virtual IRunner* getRunner() {
  6193. return m_runner;
  6194. }
  6195. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
  6196. return getGeneratorsForCurrentTest()
  6197. .getGeneratorInfo( fileInfo, totalSize )
  6198. .getCurrentIndex();
  6199. }
  6200. virtual bool advanceGeneratorsForCurrentTest() {
  6201. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6202. return generators && generators->moveNext();
  6203. }
  6204. virtual Ptr<IConfig const> getConfig() const {
  6205. return m_config;
  6206. }
  6207. public: // IMutableContext
  6208. virtual void setResultCapture( IResultCapture* resultCapture ) {
  6209. m_resultCapture = resultCapture;
  6210. }
  6211. virtual void setRunner( IRunner* runner ) {
  6212. m_runner = runner;
  6213. }
  6214. virtual void setConfig( Ptr<IConfig const> const& config ) {
  6215. m_config = config;
  6216. }
  6217. friend IMutableContext& getCurrentMutableContext();
  6218. private:
  6219. IGeneratorsForTest* findGeneratorsForCurrentTest() {
  6220. std::string testName = getResultCapture()->getCurrentTestName();
  6221. std::map<std::string, IGeneratorsForTest*>::const_iterator it =
  6222. m_generatorsByTestName.find( testName );
  6223. return it != m_generatorsByTestName.end()
  6224. ? it->second
  6225. : CATCH_NULL;
  6226. }
  6227. IGeneratorsForTest& getGeneratorsForCurrentTest() {
  6228. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6229. if( !generators ) {
  6230. std::string testName = getResultCapture()->getCurrentTestName();
  6231. generators = createGeneratorsForTest();
  6232. m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
  6233. }
  6234. return *generators;
  6235. }
  6236. private:
  6237. Ptr<IConfig const> m_config;
  6238. IRunner* m_runner;
  6239. IResultCapture* m_resultCapture;
  6240. std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
  6241. };
  6242. namespace {
  6243. Context* currentContext = CATCH_NULL;
  6244. }
  6245. IMutableContext& getCurrentMutableContext() {
  6246. if( !currentContext )
  6247. currentContext = new Context();
  6248. return *currentContext;
  6249. }
  6250. IContext& getCurrentContext() {
  6251. return getCurrentMutableContext();
  6252. }
  6253. void cleanUpContext() {
  6254. delete currentContext;
  6255. currentContext = CATCH_NULL;
  6256. }
  6257. }
  6258. // #included from: catch_console_colour_impl.hpp
  6259. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
  6260. namespace Catch {
  6261. namespace {
  6262. struct IColourImpl {
  6263. virtual ~IColourImpl() {}
  6264. virtual void use( Colour::Code _colourCode ) = 0;
  6265. };
  6266. struct NoColourImpl : IColourImpl {
  6267. void use( Colour::Code ) {}
  6268. static IColourImpl* instance() {
  6269. static NoColourImpl s_instance;
  6270. return &s_instance;
  6271. }
  6272. };
  6273. } // anon namespace
  6274. } // namespace Catch
  6275. #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
  6276. # ifdef CATCH_PLATFORM_WINDOWS
  6277. # define CATCH_CONFIG_COLOUR_WINDOWS
  6278. # else
  6279. # define CATCH_CONFIG_COLOUR_ANSI
  6280. # endif
  6281. #endif
  6282. #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
  6283. namespace Catch {
  6284. namespace {
  6285. class Win32ColourImpl : public IColourImpl {
  6286. public:
  6287. Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
  6288. {
  6289. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  6290. GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
  6291. originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
  6292. originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
  6293. }
  6294. virtual void use( Colour::Code _colourCode ) {
  6295. switch( _colourCode ) {
  6296. case Colour::None: return setTextAttribute( originalForegroundAttributes );
  6297. case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6298. case Colour::Red: return setTextAttribute( FOREGROUND_RED );
  6299. case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
  6300. case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
  6301. case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
  6302. case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
  6303. case Colour::Grey: return setTextAttribute( 0 );
  6304. case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
  6305. case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
  6306. case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
  6307. case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6308. case Colour::Bright: throw std::logic_error( "not a colour" );
  6309. }
  6310. }
  6311. private:
  6312. void setTextAttribute( WORD _textAttribute ) {
  6313. SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
  6314. }
  6315. HANDLE stdoutHandle;
  6316. WORD originalForegroundAttributes;
  6317. WORD originalBackgroundAttributes;
  6318. };
  6319. IColourImpl* platformColourInstance() {
  6320. static Win32ColourImpl s_instance;
  6321. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6322. UseColour::YesOrNo colourMode = config
  6323. ? config->useColour()
  6324. : UseColour::Auto;
  6325. if( colourMode == UseColour::Auto )
  6326. colourMode = !isDebuggerActive()
  6327. ? UseColour::Yes
  6328. : UseColour::No;
  6329. return colourMode == UseColour::Yes
  6330. ? &s_instance
  6331. : NoColourImpl::instance();
  6332. }
  6333. } // end anon namespace
  6334. } // end namespace Catch
  6335. #elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
  6336. #include <unistd.h>
  6337. namespace Catch {
  6338. namespace {
  6339. // use POSIX/ ANSI console terminal codes
  6340. // Thanks to Adam Strzelecki for original contribution
  6341. // (http://github.com/nanoant)
  6342. // https://github.com/philsquared/Catch/pull/131
  6343. class PosixColourImpl : public IColourImpl {
  6344. public:
  6345. virtual void use( Colour::Code _colourCode ) {
  6346. switch( _colourCode ) {
  6347. case Colour::None:
  6348. case Colour::White: return setColour( "[0m" );
  6349. case Colour::Red: return setColour( "[0;31m" );
  6350. case Colour::Green: return setColour( "[0;32m" );
  6351. case Colour::Blue: return setColour( "[0;34m" );
  6352. case Colour::Cyan: return setColour( "[0;36m" );
  6353. case Colour::Yellow: return setColour( "[0;33m" );
  6354. case Colour::Grey: return setColour( "[1;30m" );
  6355. case Colour::LightGrey: return setColour( "[0;37m" );
  6356. case Colour::BrightRed: return setColour( "[1;31m" );
  6357. case Colour::BrightGreen: return setColour( "[1;32m" );
  6358. case Colour::BrightWhite: return setColour( "[1;37m" );
  6359. case Colour::Bright: throw std::logic_error( "not a colour" );
  6360. }
  6361. }
  6362. static IColourImpl* instance() {
  6363. static PosixColourImpl s_instance;
  6364. return &s_instance;
  6365. }
  6366. private:
  6367. void setColour( const char* _escapeCode ) {
  6368. Catch::cout() << '\033' << _escapeCode;
  6369. }
  6370. };
  6371. IColourImpl* platformColourInstance() {
  6372. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6373. UseColour::YesOrNo colourMode = config
  6374. ? config->useColour()
  6375. : UseColour::Auto;
  6376. if( colourMode == UseColour::Auto )
  6377. colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
  6378. ? UseColour::Yes
  6379. : UseColour::No;
  6380. return colourMode == UseColour::Yes
  6381. ? PosixColourImpl::instance()
  6382. : NoColourImpl::instance();
  6383. }
  6384. } // end anon namespace
  6385. } // end namespace Catch
  6386. #else // not Windows or ANSI ///////////////////////////////////////////////
  6387. namespace Catch {
  6388. static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
  6389. } // end namespace Catch
  6390. #endif // Windows/ ANSI/ None
  6391. namespace Catch {
  6392. Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
  6393. Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
  6394. Colour::~Colour(){ if( !m_moved ) use( None ); }
  6395. void Colour::use( Code _colourCode ) {
  6396. static IColourImpl* impl = platformColourInstance();
  6397. impl->use( _colourCode );
  6398. }
  6399. } // end namespace Catch
  6400. // #included from: catch_generators_impl.hpp
  6401. #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
  6402. #include <vector>
  6403. #include <string>
  6404. #include <map>
  6405. namespace Catch {
  6406. struct GeneratorInfo : IGeneratorInfo {
  6407. GeneratorInfo( std::size_t size )
  6408. : m_size( size ),
  6409. m_currentIndex( 0 )
  6410. {}
  6411. bool moveNext() {
  6412. if( ++m_currentIndex == m_size ) {
  6413. m_currentIndex = 0;
  6414. return false;
  6415. }
  6416. return true;
  6417. }
  6418. std::size_t getCurrentIndex() const {
  6419. return m_currentIndex;
  6420. }
  6421. std::size_t m_size;
  6422. std::size_t m_currentIndex;
  6423. };
  6424. ///////////////////////////////////////////////////////////////////////////
  6425. class GeneratorsForTest : public IGeneratorsForTest {
  6426. public:
  6427. ~GeneratorsForTest() {
  6428. deleteAll( m_generatorsInOrder );
  6429. }
  6430. IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
  6431. std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
  6432. if( it == m_generatorsByName.end() ) {
  6433. IGeneratorInfo* info = new GeneratorInfo( size );
  6434. m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
  6435. m_generatorsInOrder.push_back( info );
  6436. return *info;
  6437. }
  6438. return *it->second;
  6439. }
  6440. bool moveNext() {
  6441. std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
  6442. std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
  6443. for(; it != itEnd; ++it ) {
  6444. if( (*it)->moveNext() )
  6445. return true;
  6446. }
  6447. return false;
  6448. }
  6449. private:
  6450. std::map<std::string, IGeneratorInfo*> m_generatorsByName;
  6451. std::vector<IGeneratorInfo*> m_generatorsInOrder;
  6452. };
  6453. IGeneratorsForTest* createGeneratorsForTest()
  6454. {
  6455. return new GeneratorsForTest();
  6456. }
  6457. } // end namespace Catch
  6458. // #included from: catch_assertionresult.hpp
  6459. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
  6460. namespace Catch {
  6461. AssertionInfo::AssertionInfo( std::string const& _macroName,
  6462. SourceLineInfo const& _lineInfo,
  6463. std::string const& _capturedExpression,
  6464. ResultDisposition::Flags _resultDisposition )
  6465. : macroName( _macroName ),
  6466. lineInfo( _lineInfo ),
  6467. capturedExpression( _capturedExpression ),
  6468. resultDisposition( _resultDisposition )
  6469. {}
  6470. AssertionResult::AssertionResult() {}
  6471. AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
  6472. : m_info( info ),
  6473. m_resultData( data )
  6474. {}
  6475. AssertionResult::~AssertionResult() {}
  6476. // Result was a success
  6477. bool AssertionResult::succeeded() const {
  6478. return Catch::isOk( m_resultData.resultType );
  6479. }
  6480. // Result was a success, or failure is suppressed
  6481. bool AssertionResult::isOk() const {
  6482. return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
  6483. }
  6484. ResultWas::OfType AssertionResult::getResultType() const {
  6485. return m_resultData.resultType;
  6486. }
  6487. bool AssertionResult::hasExpression() const {
  6488. return !m_info.capturedExpression.empty();
  6489. }
  6490. bool AssertionResult::hasMessage() const {
  6491. return !m_resultData.message.empty();
  6492. }
  6493. std::string AssertionResult::getExpression() const {
  6494. if( isFalseTest( m_info.resultDisposition ) )
  6495. return '!' + m_info.capturedExpression;
  6496. else
  6497. return m_info.capturedExpression;
  6498. }
  6499. std::string AssertionResult::getExpressionInMacro() const {
  6500. if( m_info.macroName.empty() )
  6501. return m_info.capturedExpression;
  6502. else
  6503. return m_info.macroName + "( " + m_info.capturedExpression + " )";
  6504. }
  6505. bool AssertionResult::hasExpandedExpression() const {
  6506. return hasExpression() && getExpandedExpression() != getExpression();
  6507. }
  6508. std::string AssertionResult::getExpandedExpression() const {
  6509. return m_resultData.reconstructExpression();
  6510. }
  6511. std::string AssertionResult::getMessage() const {
  6512. return m_resultData.message;
  6513. }
  6514. SourceLineInfo AssertionResult::getSourceInfo() const {
  6515. return m_info.lineInfo;
  6516. }
  6517. std::string AssertionResult::getTestMacroName() const {
  6518. return m_info.macroName;
  6519. }
  6520. void AssertionResult::discardDecomposedExpression() const {
  6521. m_resultData.decomposedExpression = CATCH_NULL;
  6522. }
  6523. void AssertionResult::expandDecomposedExpression() const {
  6524. m_resultData.reconstructExpression();
  6525. }
  6526. } // end namespace Catch
  6527. // #included from: catch_test_case_info.hpp
  6528. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
  6529. #include <cctype>
  6530. namespace Catch {
  6531. inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
  6532. if( startsWith( tag, '.' ) ||
  6533. tag == "hide" ||
  6534. tag == "!hide" )
  6535. return TestCaseInfo::IsHidden;
  6536. else if( tag == "!throws" )
  6537. return TestCaseInfo::Throws;
  6538. else if( tag == "!shouldfail" )
  6539. return TestCaseInfo::ShouldFail;
  6540. else if( tag == "!mayfail" )
  6541. return TestCaseInfo::MayFail;
  6542. else if( tag == "!nonportable" )
  6543. return TestCaseInfo::NonPortable;
  6544. else
  6545. return TestCaseInfo::None;
  6546. }
  6547. inline bool isReservedTag( std::string const& tag ) {
  6548. return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] );
  6549. }
  6550. inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
  6551. if( isReservedTag( tag ) ) {
  6552. {
  6553. Colour colourGuard( Colour::Red );
  6554. Catch::cerr()
  6555. << "Tag name [" << tag << "] not allowed.\n"
  6556. << "Tag names starting with non alpha-numeric characters are reserved\n";
  6557. }
  6558. {
  6559. Colour colourGuard( Colour::FileName );
  6560. Catch::cerr() << _lineInfo << std::endl;
  6561. }
  6562. exit(1);
  6563. }
  6564. }
  6565. TestCase makeTestCase( ITestCase* _testCase,
  6566. std::string const& _className,
  6567. std::string const& _name,
  6568. std::string const& _descOrTags,
  6569. SourceLineInfo const& _lineInfo )
  6570. {
  6571. bool isHidden( startsWith( _name, "./" ) ); // Legacy support
  6572. // Parse out tags
  6573. std::set<std::string> tags;
  6574. std::string desc, tag;
  6575. bool inTag = false;
  6576. for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
  6577. char c = _descOrTags[i];
  6578. if( !inTag ) {
  6579. if( c == '[' )
  6580. inTag = true;
  6581. else
  6582. desc += c;
  6583. }
  6584. else {
  6585. if( c == ']' ) {
  6586. TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
  6587. if( prop == TestCaseInfo::IsHidden )
  6588. isHidden = true;
  6589. else if( prop == TestCaseInfo::None )
  6590. enforceNotReservedTag( tag, _lineInfo );
  6591. tags.insert( tag );
  6592. tag.clear();
  6593. inTag = false;
  6594. }
  6595. else
  6596. tag += c;
  6597. }
  6598. }
  6599. if( isHidden ) {
  6600. tags.insert( "hide" );
  6601. tags.insert( "." );
  6602. }
  6603. TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
  6604. return TestCase( _testCase, info );
  6605. }
  6606. void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
  6607. {
  6608. testCaseInfo.tags = tags;
  6609. testCaseInfo.lcaseTags.clear();
  6610. std::ostringstream oss;
  6611. for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
  6612. oss << '[' << *it << ']';
  6613. std::string lcaseTag = toLower( *it );
  6614. testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
  6615. testCaseInfo.lcaseTags.insert( lcaseTag );
  6616. }
  6617. testCaseInfo.tagsAsString = oss.str();
  6618. }
  6619. TestCaseInfo::TestCaseInfo( std::string const& _name,
  6620. std::string const& _className,
  6621. std::string const& _description,
  6622. std::set<std::string> const& _tags,
  6623. SourceLineInfo const& _lineInfo )
  6624. : name( _name ),
  6625. className( _className ),
  6626. description( _description ),
  6627. lineInfo( _lineInfo ),
  6628. properties( None )
  6629. {
  6630. setTags( *this, _tags );
  6631. }
  6632. TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
  6633. : name( other.name ),
  6634. className( other.className ),
  6635. description( other.description ),
  6636. tags( other.tags ),
  6637. lcaseTags( other.lcaseTags ),
  6638. tagsAsString( other.tagsAsString ),
  6639. lineInfo( other.lineInfo ),
  6640. properties( other.properties )
  6641. {}
  6642. bool TestCaseInfo::isHidden() const {
  6643. return ( properties & IsHidden ) != 0;
  6644. }
  6645. bool TestCaseInfo::throws() const {
  6646. return ( properties & Throws ) != 0;
  6647. }
  6648. bool TestCaseInfo::okToFail() const {
  6649. return ( properties & (ShouldFail | MayFail ) ) != 0;
  6650. }
  6651. bool TestCaseInfo::expectedToFail() const {
  6652. return ( properties & (ShouldFail ) ) != 0;
  6653. }
  6654. TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
  6655. TestCase::TestCase( TestCase const& other )
  6656. : TestCaseInfo( other ),
  6657. test( other.test )
  6658. {}
  6659. TestCase TestCase::withName( std::string const& _newName ) const {
  6660. TestCase other( *this );
  6661. other.name = _newName;
  6662. return other;
  6663. }
  6664. void TestCase::swap( TestCase& other ) {
  6665. test.swap( other.test );
  6666. name.swap( other.name );
  6667. className.swap( other.className );
  6668. description.swap( other.description );
  6669. tags.swap( other.tags );
  6670. lcaseTags.swap( other.lcaseTags );
  6671. tagsAsString.swap( other.tagsAsString );
  6672. std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
  6673. std::swap( lineInfo, other.lineInfo );
  6674. }
  6675. void TestCase::invoke() const {
  6676. test->invoke();
  6677. }
  6678. bool TestCase::operator == ( TestCase const& other ) const {
  6679. return test.get() == other.test.get() &&
  6680. name == other.name &&
  6681. className == other.className;
  6682. }
  6683. bool TestCase::operator < ( TestCase const& other ) const {
  6684. return name < other.name;
  6685. }
  6686. TestCase& TestCase::operator = ( TestCase const& other ) {
  6687. TestCase temp( other );
  6688. swap( temp );
  6689. return *this;
  6690. }
  6691. TestCaseInfo const& TestCase::getTestCaseInfo() const
  6692. {
  6693. return *this;
  6694. }
  6695. } // end namespace Catch
  6696. // #included from: catch_version.hpp
  6697. #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
  6698. namespace Catch {
  6699. Version::Version
  6700. ( unsigned int _majorVersion,
  6701. unsigned int _minorVersion,
  6702. unsigned int _patchNumber,
  6703. std::string const& _branchName,
  6704. unsigned int _buildNumber )
  6705. : majorVersion( _majorVersion ),
  6706. minorVersion( _minorVersion ),
  6707. patchNumber( _patchNumber ),
  6708. branchName( _branchName ),
  6709. buildNumber( _buildNumber )
  6710. {}
  6711. std::ostream& operator << ( std::ostream& os, Version const& version ) {
  6712. os << version.majorVersion << '.'
  6713. << version.minorVersion << '.'
  6714. << version.patchNumber;
  6715. if( !version.branchName.empty() ) {
  6716. os << '-' << version.branchName
  6717. << '.' << version.buildNumber;
  6718. }
  6719. return os;
  6720. }
  6721. Version libraryVersion( 1, 8, 1, "", 0 );
  6722. }
  6723. // #included from: catch_message.hpp
  6724. #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
  6725. namespace Catch {
  6726. MessageInfo::MessageInfo( std::string const& _macroName,
  6727. SourceLineInfo const& _lineInfo,
  6728. ResultWas::OfType _type )
  6729. : macroName( _macroName ),
  6730. lineInfo( _lineInfo ),
  6731. type( _type ),
  6732. sequence( ++globalCount )
  6733. {}
  6734. // This may need protecting if threading support is added
  6735. unsigned int MessageInfo::globalCount = 0;
  6736. ////////////////////////////////////////////////////////////////////////////
  6737. ScopedMessage::ScopedMessage( MessageBuilder const& builder )
  6738. : m_info( builder.m_info )
  6739. {
  6740. m_info.message = builder.m_stream.str();
  6741. getResultCapture().pushScopedMessage( m_info );
  6742. }
  6743. ScopedMessage::ScopedMessage( ScopedMessage const& other )
  6744. : m_info( other.m_info )
  6745. {}
  6746. ScopedMessage::~ScopedMessage() {
  6747. getResultCapture().popScopedMessage( m_info );
  6748. }
  6749. } // end namespace Catch
  6750. // #included from: catch_legacy_reporter_adapter.hpp
  6751. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
  6752. // #included from: catch_legacy_reporter_adapter.h
  6753. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
  6754. namespace Catch
  6755. {
  6756. // Deprecated
  6757. struct IReporter : IShared {
  6758. virtual ~IReporter();
  6759. virtual bool shouldRedirectStdout() const = 0;
  6760. virtual void StartTesting() = 0;
  6761. virtual void EndTesting( Totals const& totals ) = 0;
  6762. virtual void StartGroup( std::string const& groupName ) = 0;
  6763. virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
  6764. virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
  6765. virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
  6766. virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
  6767. virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
  6768. virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
  6769. virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
  6770. virtual void Aborted() = 0;
  6771. virtual void Result( AssertionResult const& result ) = 0;
  6772. };
  6773. class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
  6774. {
  6775. public:
  6776. LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
  6777. virtual ~LegacyReporterAdapter();
  6778. virtual ReporterPreferences getPreferences() const;
  6779. virtual void noMatchingTestCases( std::string const& );
  6780. virtual void testRunStarting( TestRunInfo const& );
  6781. virtual void testGroupStarting( GroupInfo const& groupInfo );
  6782. virtual void testCaseStarting( TestCaseInfo const& testInfo );
  6783. virtual void sectionStarting( SectionInfo const& sectionInfo );
  6784. virtual void assertionStarting( AssertionInfo const& );
  6785. virtual bool assertionEnded( AssertionStats const& assertionStats );
  6786. virtual void sectionEnded( SectionStats const& sectionStats );
  6787. virtual void testCaseEnded( TestCaseStats const& testCaseStats );
  6788. virtual void testGroupEnded( TestGroupStats const& testGroupStats );
  6789. virtual void testRunEnded( TestRunStats const& testRunStats );
  6790. virtual void skipTest( TestCaseInfo const& );
  6791. private:
  6792. Ptr<IReporter> m_legacyReporter;
  6793. };
  6794. }
  6795. namespace Catch
  6796. {
  6797. LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
  6798. : m_legacyReporter( legacyReporter )
  6799. {}
  6800. LegacyReporterAdapter::~LegacyReporterAdapter() {}
  6801. ReporterPreferences LegacyReporterAdapter::getPreferences() const {
  6802. ReporterPreferences prefs;
  6803. prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
  6804. return prefs;
  6805. }
  6806. void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
  6807. void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
  6808. m_legacyReporter->StartTesting();
  6809. }
  6810. void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
  6811. m_legacyReporter->StartGroup( groupInfo.name );
  6812. }
  6813. void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
  6814. m_legacyReporter->StartTestCase( testInfo );
  6815. }
  6816. void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
  6817. m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
  6818. }
  6819. void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
  6820. // Not on legacy interface
  6821. }
  6822. bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
  6823. if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
  6824. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  6825. it != itEnd;
  6826. ++it ) {
  6827. if( it->type == ResultWas::Info ) {
  6828. ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
  6829. rb << it->message;
  6830. rb.setResultType( ResultWas::Info );
  6831. AssertionResult result = rb.build();
  6832. m_legacyReporter->Result( result );
  6833. }
  6834. }
  6835. }
  6836. m_legacyReporter->Result( assertionStats.assertionResult );
  6837. return true;
  6838. }
  6839. void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
  6840. if( sectionStats.missingAssertions )
  6841. m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
  6842. m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
  6843. }
  6844. void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
  6845. m_legacyReporter->EndTestCase
  6846. ( testCaseStats.testInfo,
  6847. testCaseStats.totals,
  6848. testCaseStats.stdOut,
  6849. testCaseStats.stdErr );
  6850. }
  6851. void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
  6852. if( testGroupStats.aborting )
  6853. m_legacyReporter->Aborted();
  6854. m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
  6855. }
  6856. void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
  6857. m_legacyReporter->EndTesting( testRunStats.totals );
  6858. }
  6859. void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
  6860. }
  6861. }
  6862. // #included from: catch_timer.hpp
  6863. #ifdef __clang__
  6864. #pragma clang diagnostic push
  6865. #pragma clang diagnostic ignored "-Wc++11-long-long"
  6866. #endif
  6867. #ifdef CATCH_PLATFORM_WINDOWS
  6868. #else
  6869. #include <sys/time.h>
  6870. #endif
  6871. namespace Catch {
  6872. namespace {
  6873. #ifdef CATCH_PLATFORM_WINDOWS
  6874. uint64_t getCurrentTicks() {
  6875. static uint64_t hz=0, hzo=0;
  6876. if (!hz) {
  6877. QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
  6878. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
  6879. }
  6880. uint64_t t;
  6881. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
  6882. return ((t-hzo)*1000000)/hz;
  6883. }
  6884. #else
  6885. uint64_t getCurrentTicks() {
  6886. timeval t;
  6887. gettimeofday(&t,CATCH_NULL);
  6888. return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec );
  6889. }
  6890. #endif
  6891. }
  6892. void Timer::start() {
  6893. m_ticks = getCurrentTicks();
  6894. }
  6895. unsigned int Timer::getElapsedMicroseconds() const {
  6896. return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
  6897. }
  6898. unsigned int Timer::getElapsedMilliseconds() const {
  6899. return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
  6900. }
  6901. double Timer::getElapsedSeconds() const {
  6902. return getElapsedMicroseconds()/1000000.0;
  6903. }
  6904. } // namespace Catch
  6905. #ifdef __clang__
  6906. #pragma clang diagnostic pop
  6907. #endif
  6908. // #included from: catch_common.hpp
  6909. #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
  6910. #include <cstring>
  6911. #include <cctype>
  6912. namespace Catch {
  6913. bool startsWith( std::string const& s, std::string const& prefix ) {
  6914. return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
  6915. }
  6916. bool startsWith( std::string const& s, char prefix ) {
  6917. return !s.empty() && s[0] == prefix;
  6918. }
  6919. bool endsWith( std::string const& s, std::string const& suffix ) {
  6920. return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
  6921. }
  6922. bool endsWith( std::string const& s, char suffix ) {
  6923. return !s.empty() && s[s.size()-1] == suffix;
  6924. }
  6925. bool contains( std::string const& s, std::string const& infix ) {
  6926. return s.find( infix ) != std::string::npos;
  6927. }
  6928. char toLowerCh(char c) {
  6929. return static_cast<char>( std::tolower( c ) );
  6930. }
  6931. void toLowerInPlace( std::string& s ) {
  6932. std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
  6933. }
  6934. std::string toLower( std::string const& s ) {
  6935. std::string lc = s;
  6936. toLowerInPlace( lc );
  6937. return lc;
  6938. }
  6939. std::string trim( std::string const& str ) {
  6940. static char const* whitespaceChars = "\n\r\t ";
  6941. std::string::size_type start = str.find_first_not_of( whitespaceChars );
  6942. std::string::size_type end = str.find_last_not_of( whitespaceChars );
  6943. return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
  6944. }
  6945. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
  6946. bool replaced = false;
  6947. std::size_t i = str.find( replaceThis );
  6948. while( i != std::string::npos ) {
  6949. replaced = true;
  6950. str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
  6951. if( i < str.size()-withThis.size() )
  6952. i = str.find( replaceThis, i+withThis.size() );
  6953. else
  6954. i = std::string::npos;
  6955. }
  6956. return replaced;
  6957. }
  6958. pluralise::pluralise( std::size_t count, std::string const& label )
  6959. : m_count( count ),
  6960. m_label( label )
  6961. {}
  6962. std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
  6963. os << pluraliser.m_count << ' ' << pluraliser.m_label;
  6964. if( pluraliser.m_count != 1 )
  6965. os << 's';
  6966. return os;
  6967. }
  6968. SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
  6969. SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
  6970. : file( _file ),
  6971. line( _line )
  6972. {}
  6973. bool SourceLineInfo::empty() const {
  6974. return file[0] == '\0';
  6975. }
  6976. bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
  6977. return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
  6978. }
  6979. bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
  6980. return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
  6981. }
  6982. void seedRng( IConfig const& config ) {
  6983. if( config.rngSeed() != 0 )
  6984. std::srand( config.rngSeed() );
  6985. }
  6986. unsigned int rngSeed() {
  6987. return getCurrentContext().getConfig()->rngSeed();
  6988. }
  6989. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
  6990. #ifndef __GNUG__
  6991. os << info.file << '(' << info.line << ')';
  6992. #else
  6993. os << info.file << ':' << info.line;
  6994. #endif
  6995. return os;
  6996. }
  6997. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
  6998. std::ostringstream oss;
  6999. oss << locationInfo << ": Internal Catch error: '" << message << '\'';
  7000. if( alwaysTrue() )
  7001. throw std::logic_error( oss.str() );
  7002. }
  7003. }
  7004. // #included from: catch_section.hpp
  7005. #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
  7006. namespace Catch {
  7007. SectionInfo::SectionInfo
  7008. ( SourceLineInfo const& _lineInfo,
  7009. std::string const& _name,
  7010. std::string const& _description )
  7011. : name( _name ),
  7012. description( _description ),
  7013. lineInfo( _lineInfo )
  7014. {}
  7015. Section::Section( SectionInfo const& info )
  7016. : m_info( info ),
  7017. m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
  7018. {
  7019. m_timer.start();
  7020. }
  7021. Section::~Section() {
  7022. if( m_sectionIncluded ) {
  7023. SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
  7024. if( std::uncaught_exception() )
  7025. getResultCapture().sectionEndedEarly( endInfo );
  7026. else
  7027. getResultCapture().sectionEnded( endInfo );
  7028. }
  7029. }
  7030. // This indicates whether the section should be executed or not
  7031. Section::operator bool() const {
  7032. return m_sectionIncluded;
  7033. }
  7034. } // end namespace Catch
  7035. // #included from: catch_debugger.hpp
  7036. #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
  7037. #ifdef CATCH_PLATFORM_MAC
  7038. #include <assert.h>
  7039. #include <stdbool.h>
  7040. #include <sys/types.h>
  7041. #include <unistd.h>
  7042. #include <sys/sysctl.h>
  7043. namespace Catch{
  7044. // The following function is taken directly from the following technical note:
  7045. // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
  7046. // Returns true if the current process is being debugged (either
  7047. // running under the debugger or has a debugger attached post facto).
  7048. bool isDebuggerActive(){
  7049. int mib[4];
  7050. struct kinfo_proc info;
  7051. size_t size;
  7052. // Initialize the flags so that, if sysctl fails for some bizarre
  7053. // reason, we get a predictable result.
  7054. info.kp_proc.p_flag = 0;
  7055. // Initialize mib, which tells sysctl the info we want, in this case
  7056. // we're looking for information about a specific process ID.
  7057. mib[0] = CTL_KERN;
  7058. mib[1] = KERN_PROC;
  7059. mib[2] = KERN_PROC_PID;
  7060. mib[3] = getpid();
  7061. // Call sysctl.
  7062. size = sizeof(info);
  7063. if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
  7064. Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
  7065. return false;
  7066. }
  7067. // We're being debugged if the P_TRACED flag is set.
  7068. return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
  7069. }
  7070. } // namespace Catch
  7071. #elif defined(CATCH_PLATFORM_LINUX)
  7072. #include <fstream>
  7073. #include <string>
  7074. namespace Catch{
  7075. // The standard POSIX way of detecting a debugger is to attempt to
  7076. // ptrace() the process, but this needs to be done from a child and not
  7077. // this process itself to still allow attaching to this process later
  7078. // if wanted, so is rather heavy. Under Linux we have the PID of the
  7079. // "debugger" (which doesn't need to be gdb, of course, it could also
  7080. // be strace, for example) in /proc/$PID/status, so just get it from
  7081. // there instead.
  7082. bool isDebuggerActive(){
  7083. std::ifstream in("/proc/self/status");
  7084. for( std::string line; std::getline(in, line); ) {
  7085. static const int PREFIX_LEN = 11;
  7086. if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) {
  7087. // We're traced if the PID is not 0 and no other PID starts
  7088. // with 0 digit, so it's enough to check for just a single
  7089. // character.
  7090. return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0';
  7091. }
  7092. }
  7093. return false;
  7094. }
  7095. } // namespace Catch
  7096. #elif defined(_MSC_VER)
  7097. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7098. namespace Catch {
  7099. bool isDebuggerActive() {
  7100. return IsDebuggerPresent() != 0;
  7101. }
  7102. }
  7103. #elif defined(__MINGW32__)
  7104. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7105. namespace Catch {
  7106. bool isDebuggerActive() {
  7107. return IsDebuggerPresent() != 0;
  7108. }
  7109. }
  7110. #else
  7111. namespace Catch {
  7112. inline bool isDebuggerActive() { return false; }
  7113. }
  7114. #endif // Platform
  7115. #ifdef CATCH_PLATFORM_WINDOWS
  7116. namespace Catch {
  7117. void writeToDebugConsole( std::string const& text ) {
  7118. ::OutputDebugStringA( text.c_str() );
  7119. }
  7120. }
  7121. #else
  7122. namespace Catch {
  7123. void writeToDebugConsole( std::string const& text ) {
  7124. // !TBD: Need a version for Mac/ XCode and other IDEs
  7125. Catch::cout() << text;
  7126. }
  7127. }
  7128. #endif // Platform
  7129. // #included from: catch_tostring.hpp
  7130. #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
  7131. namespace Catch {
  7132. namespace Detail {
  7133. const std::string unprintableString = "{?}";
  7134. namespace {
  7135. const int hexThreshold = 255;
  7136. struct Endianness {
  7137. enum Arch { Big, Little };
  7138. static Arch which() {
  7139. union _{
  7140. int asInt;
  7141. char asChar[sizeof (int)];
  7142. } u;
  7143. u.asInt = 1;
  7144. return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
  7145. }
  7146. };
  7147. }
  7148. std::string rawMemoryToString( const void *object, std::size_t size )
  7149. {
  7150. // Reverse order for little endian architectures
  7151. int i = 0, end = static_cast<int>( size ), inc = 1;
  7152. if( Endianness::which() == Endianness::Little ) {
  7153. i = end-1;
  7154. end = inc = -1;
  7155. }
  7156. unsigned char const *bytes = static_cast<unsigned char const *>(object);
  7157. std::ostringstream os;
  7158. os << "0x" << std::setfill('0') << std::hex;
  7159. for( ; i != end; i += inc )
  7160. os << std::setw(2) << static_cast<unsigned>(bytes[i]);
  7161. return os.str();
  7162. }
  7163. }
  7164. std::string toString( std::string const& value ) {
  7165. std::string s = value;
  7166. if( getCurrentContext().getConfig()->showInvisibles() ) {
  7167. for(size_t i = 0; i < s.size(); ++i ) {
  7168. std::string subs;
  7169. switch( s[i] ) {
  7170. case '\n': subs = "\\n"; break;
  7171. case '\t': subs = "\\t"; break;
  7172. default: break;
  7173. }
  7174. if( !subs.empty() ) {
  7175. s = s.substr( 0, i ) + subs + s.substr( i+1 );
  7176. ++i;
  7177. }
  7178. }
  7179. }
  7180. return '"' + s + '"';
  7181. }
  7182. std::string toString( std::wstring const& value ) {
  7183. std::string s;
  7184. s.reserve( value.size() );
  7185. for(size_t i = 0; i < value.size(); ++i )
  7186. s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
  7187. return Catch::toString( s );
  7188. }
  7189. std::string toString( const char* const value ) {
  7190. return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
  7191. }
  7192. std::string toString( char* const value ) {
  7193. return Catch::toString( static_cast<const char*>( value ) );
  7194. }
  7195. std::string toString( const wchar_t* const value )
  7196. {
  7197. return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
  7198. }
  7199. std::string toString( wchar_t* const value )
  7200. {
  7201. return Catch::toString( static_cast<const wchar_t*>( value ) );
  7202. }
  7203. std::string toString( int value ) {
  7204. std::ostringstream oss;
  7205. oss << value;
  7206. if( value > Detail::hexThreshold )
  7207. oss << " (0x" << std::hex << value << ')';
  7208. return oss.str();
  7209. }
  7210. std::string toString( unsigned long value ) {
  7211. std::ostringstream oss;
  7212. oss << value;
  7213. if( value > Detail::hexThreshold )
  7214. oss << " (0x" << std::hex << value << ')';
  7215. return oss.str();
  7216. }
  7217. std::string toString( unsigned int value ) {
  7218. return Catch::toString( static_cast<unsigned long>( value ) );
  7219. }
  7220. template<typename T>
  7221. std::string fpToString( T value, int precision ) {
  7222. std::ostringstream oss;
  7223. oss << std::setprecision( precision )
  7224. << std::fixed
  7225. << value;
  7226. std::string d = oss.str();
  7227. std::size_t i = d.find_last_not_of( '0' );
  7228. if( i != std::string::npos && i != d.size()-1 ) {
  7229. if( d[i] == '.' )
  7230. i++;
  7231. d = d.substr( 0, i+1 );
  7232. }
  7233. return d;
  7234. }
  7235. std::string toString( const double value ) {
  7236. return fpToString( value, 10 );
  7237. }
  7238. std::string toString( const float value ) {
  7239. return fpToString( value, 5 ) + 'f';
  7240. }
  7241. std::string toString( bool value ) {
  7242. return value ? "true" : "false";
  7243. }
  7244. std::string toString( char value ) {
  7245. if ( value == '\r' )
  7246. return "'\\r'";
  7247. if ( value == '\f' )
  7248. return "'\\f'";
  7249. if ( value == '\n' )
  7250. return "'\\n'";
  7251. if ( value == '\t' )
  7252. return "'\\t'";
  7253. if ( '\0' <= value && value < ' ' )
  7254. return toString( static_cast<unsigned int>( value ) );
  7255. char chstr[] = "' '";
  7256. chstr[1] = value;
  7257. return chstr;
  7258. }
  7259. std::string toString( signed char value ) {
  7260. return toString( static_cast<char>( value ) );
  7261. }
  7262. std::string toString( unsigned char value ) {
  7263. return toString( static_cast<char>( value ) );
  7264. }
  7265. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  7266. std::string toString( long long value ) {
  7267. std::ostringstream oss;
  7268. oss << value;
  7269. if( value > Detail::hexThreshold )
  7270. oss << " (0x" << std::hex << value << ')';
  7271. return oss.str();
  7272. }
  7273. std::string toString( unsigned long long value ) {
  7274. std::ostringstream oss;
  7275. oss << value;
  7276. if( value > Detail::hexThreshold )
  7277. oss << " (0x" << std::hex << value << ')';
  7278. return oss.str();
  7279. }
  7280. #endif
  7281. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  7282. std::string toString( std::nullptr_t ) {
  7283. return "nullptr";
  7284. }
  7285. #endif
  7286. #ifdef __OBJC__
  7287. std::string toString( NSString const * const& nsstring ) {
  7288. if( !nsstring )
  7289. return "nil";
  7290. return "@" + toString([nsstring UTF8String]);
  7291. }
  7292. std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
  7293. if( !nsstring )
  7294. return "nil";
  7295. return "@" + toString([nsstring UTF8String]);
  7296. }
  7297. std::string toString( NSObject* const& nsObject ) {
  7298. return toString( [nsObject description] );
  7299. }
  7300. #endif
  7301. } // end namespace Catch
  7302. // #included from: catch_result_builder.hpp
  7303. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
  7304. namespace Catch {
  7305. std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
  7306. return secondArg.empty() || secondArg == "\"\""
  7307. ? capturedExpression
  7308. : capturedExpression + ", " + secondArg;
  7309. }
  7310. ResultBuilder::ResultBuilder( char const* macroName,
  7311. SourceLineInfo const& lineInfo,
  7312. char const* capturedExpression,
  7313. ResultDisposition::Flags resultDisposition,
  7314. char const* secondArg )
  7315. : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
  7316. m_shouldDebugBreak( false ),
  7317. m_shouldThrow( false )
  7318. {}
  7319. ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
  7320. m_data.resultType = result;
  7321. return *this;
  7322. }
  7323. ResultBuilder& ResultBuilder::setResultType( bool result ) {
  7324. m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
  7325. return *this;
  7326. }
  7327. void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
  7328. AssertionResult result = build( expr );
  7329. handleResult( result );
  7330. }
  7331. void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
  7332. m_assertionInfo.resultDisposition = resultDisposition;
  7333. m_stream.oss << Catch::translateActiveException();
  7334. captureResult( ResultWas::ThrewException );
  7335. }
  7336. void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
  7337. setResultType( resultType );
  7338. captureExpression();
  7339. }
  7340. void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
  7341. if( expectedMessage.empty() )
  7342. captureExpectedException( Matchers::Impl::MatchAllOf<std::string>() );
  7343. else
  7344. captureExpectedException( Matchers::Equals( expectedMessage ) );
  7345. }
  7346. void ResultBuilder::captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher ) {
  7347. assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
  7348. AssertionResultData data = m_data;
  7349. data.resultType = ResultWas::Ok;
  7350. data.reconstructedExpression = m_assertionInfo.capturedExpression;
  7351. std::string actualMessage = Catch::translateActiveException();
  7352. if( !matcher.match( actualMessage ) ) {
  7353. data.resultType = ResultWas::ExpressionFailed;
  7354. data.reconstructedExpression = actualMessage;
  7355. }
  7356. AssertionResult result( m_assertionInfo, data );
  7357. handleResult( result );
  7358. }
  7359. void ResultBuilder::captureExpression() {
  7360. AssertionResult result = build();
  7361. handleResult( result );
  7362. }
  7363. void ResultBuilder::handleResult( AssertionResult const& result )
  7364. {
  7365. getResultCapture().assertionEnded( result );
  7366. if( !result.isOk() ) {
  7367. if( getCurrentContext().getConfig()->shouldDebugBreak() )
  7368. m_shouldDebugBreak = true;
  7369. if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
  7370. m_shouldThrow = true;
  7371. }
  7372. }
  7373. void ResultBuilder::react() {
  7374. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7375. if (m_shouldDebugBreak) {
  7376. ///////////////////////////////////////////////////////////////////
  7377. // To inspect the state during test, you need to go one level up the callstack
  7378. // To go back to the test and change execution, jump over the throw statement
  7379. ///////////////////////////////////////////////////////////////////
  7380. CATCH_BREAK_INTO_DEBUGGER();
  7381. }
  7382. #endif
  7383. if( m_shouldThrow )
  7384. throw Catch::TestFailureException();
  7385. }
  7386. bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
  7387. bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
  7388. AssertionResult ResultBuilder::build() const
  7389. {
  7390. return build( *this );
  7391. }
  7392. // CAVEAT: The returned AssertionResult stores a pointer to the argument expr,
  7393. // a temporary DecomposedExpression, which in turn holds references to
  7394. // operands, possibly temporary as well.
  7395. // It should immediately be passed to handleResult; if the expression
  7396. // needs to be reported, its string expansion must be composed before
  7397. // the temporaries are destroyed.
  7398. AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
  7399. {
  7400. assert( m_data.resultType != ResultWas::Unknown );
  7401. AssertionResultData data = m_data;
  7402. // Flip bool results if FalseTest flag is set
  7403. if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
  7404. data.negate( expr.isBinaryExpression() );
  7405. }
  7406. data.message = m_stream.oss.str();
  7407. data.decomposedExpression = &expr; // for lazy reconstruction
  7408. return AssertionResult( m_assertionInfo, data );
  7409. }
  7410. void ResultBuilder::reconstructExpression( std::string& dest ) const {
  7411. dest = m_assertionInfo.capturedExpression;
  7412. }
  7413. } // end namespace Catch
  7414. // #included from: catch_tag_alias_registry.hpp
  7415. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7416. // #included from: catch_tag_alias_registry.h
  7417. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
  7418. #include <map>
  7419. namespace Catch {
  7420. class TagAliasRegistry : public ITagAliasRegistry {
  7421. public:
  7422. virtual ~TagAliasRegistry();
  7423. virtual Option<TagAlias> find( std::string const& alias ) const;
  7424. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
  7425. void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  7426. static TagAliasRegistry& get();
  7427. private:
  7428. std::map<std::string, TagAlias> m_registry;
  7429. };
  7430. } // end namespace Catch
  7431. namespace Catch {
  7432. TagAliasRegistry::~TagAliasRegistry() {}
  7433. Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
  7434. std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
  7435. if( it != m_registry.end() )
  7436. return it->second;
  7437. else
  7438. return Option<TagAlias>();
  7439. }
  7440. std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
  7441. std::string expandedTestSpec = unexpandedTestSpec;
  7442. for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
  7443. it != itEnd;
  7444. ++it ) {
  7445. std::size_t pos = expandedTestSpec.find( it->first );
  7446. if( pos != std::string::npos ) {
  7447. expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
  7448. it->second.tag +
  7449. expandedTestSpec.substr( pos + it->first.size() );
  7450. }
  7451. }
  7452. return expandedTestSpec;
  7453. }
  7454. void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
  7455. if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) {
  7456. std::ostringstream oss;
  7457. oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo;
  7458. throw std::domain_error( oss.str().c_str() );
  7459. }
  7460. if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
  7461. std::ostringstream oss;
  7462. oss << "error: tag alias, \"" << alias << "\" already registered.\n"
  7463. << "\tFirst seen at " << find(alias)->lineInfo << '\n'
  7464. << "\tRedefined at " << lineInfo;
  7465. throw std::domain_error( oss.str().c_str() );
  7466. }
  7467. }
  7468. TagAliasRegistry& TagAliasRegistry::get() {
  7469. static TagAliasRegistry instance;
  7470. return instance;
  7471. }
  7472. ITagAliasRegistry::~ITagAliasRegistry() {}
  7473. ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); }
  7474. RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
  7475. try {
  7476. TagAliasRegistry::get().add( alias, tag, lineInfo );
  7477. }
  7478. catch( std::exception& ex ) {
  7479. Colour colourGuard( Colour::Red );
  7480. Catch::cerr() << ex.what() << std::endl;
  7481. exit(1);
  7482. }
  7483. }
  7484. } // end namespace Catch
  7485. // #included from: catch_matchers_string.hpp
  7486. namespace Catch {
  7487. namespace Matchers {
  7488. namespace StdString {
  7489. CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
  7490. : m_caseSensitivity( caseSensitivity ),
  7491. m_str( adjustString( str ) )
  7492. {}
  7493. std::string CasedString::adjustString( std::string const& str ) const {
  7494. return m_caseSensitivity == CaseSensitive::No
  7495. ? toLower( str )
  7496. : str;
  7497. }
  7498. std::string CasedString::caseSensitivitySuffix() const {
  7499. return m_caseSensitivity == CaseSensitive::No
  7500. ? " (case insensitive)"
  7501. : std::string();
  7502. }
  7503. StringMatcherBase::StringMatcherBase( std::string operation, CasedString const& comparator )
  7504. : m_comparator( comparator ),
  7505. m_operation( operation ) {
  7506. }
  7507. std::string StringMatcherBase::describe() const {
  7508. std::string description;
  7509. description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
  7510. m_comparator.caseSensitivitySuffix().size());
  7511. description += m_operation;
  7512. description += ": \"";
  7513. description += m_comparator.m_str;
  7514. description += "\"";
  7515. description += m_comparator.caseSensitivitySuffix();
  7516. return description;
  7517. }
  7518. EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {}
  7519. bool EqualsMatcher::match( std::string const& source ) const {
  7520. return m_comparator.adjustString( source ) == m_comparator.m_str;
  7521. }
  7522. ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {}
  7523. bool ContainsMatcher::match( std::string const& source ) const {
  7524. return contains( m_comparator.adjustString( source ), m_comparator.m_str );
  7525. }
  7526. StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {}
  7527. bool StartsWithMatcher::match( std::string const& source ) const {
  7528. return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7529. }
  7530. EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {}
  7531. bool EndsWithMatcher::match( std::string const& source ) const {
  7532. return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7533. }
  7534. } // namespace StdString
  7535. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7536. return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
  7537. }
  7538. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7539. return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
  7540. }
  7541. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7542. return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7543. }
  7544. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7545. return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7546. }
  7547. } // namespace Matchers
  7548. } // namespace Catch
  7549. // #included from: ../reporters/catch_reporter_multi.hpp
  7550. #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
  7551. namespace Catch {
  7552. class MultipleReporters : public SharedImpl<IStreamingReporter> {
  7553. typedef std::vector<Ptr<IStreamingReporter> > Reporters;
  7554. Reporters m_reporters;
  7555. public:
  7556. void add( Ptr<IStreamingReporter> const& reporter ) {
  7557. m_reporters.push_back( reporter );
  7558. }
  7559. public: // IStreamingReporter
  7560. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7561. return m_reporters[0]->getPreferences();
  7562. }
  7563. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  7564. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7565. it != itEnd;
  7566. ++it )
  7567. (*it)->noMatchingTestCases( spec );
  7568. }
  7569. virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
  7570. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7571. it != itEnd;
  7572. ++it )
  7573. (*it)->testRunStarting( testRunInfo );
  7574. }
  7575. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  7576. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7577. it != itEnd;
  7578. ++it )
  7579. (*it)->testGroupStarting( groupInfo );
  7580. }
  7581. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7582. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7583. it != itEnd;
  7584. ++it )
  7585. (*it)->testCaseStarting( testInfo );
  7586. }
  7587. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  7588. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7589. it != itEnd;
  7590. ++it )
  7591. (*it)->sectionStarting( sectionInfo );
  7592. }
  7593. virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
  7594. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7595. it != itEnd;
  7596. ++it )
  7597. (*it)->assertionStarting( assertionInfo );
  7598. }
  7599. // The return value indicates if the messages buffer should be cleared:
  7600. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  7601. bool clearBuffer = false;
  7602. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7603. it != itEnd;
  7604. ++it )
  7605. clearBuffer |= (*it)->assertionEnded( assertionStats );
  7606. return clearBuffer;
  7607. }
  7608. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  7609. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7610. it != itEnd;
  7611. ++it )
  7612. (*it)->sectionEnded( sectionStats );
  7613. }
  7614. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  7615. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7616. it != itEnd;
  7617. ++it )
  7618. (*it)->testCaseEnded( testCaseStats );
  7619. }
  7620. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  7621. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7622. it != itEnd;
  7623. ++it )
  7624. (*it)->testGroupEnded( testGroupStats );
  7625. }
  7626. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  7627. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7628. it != itEnd;
  7629. ++it )
  7630. (*it)->testRunEnded( testRunStats );
  7631. }
  7632. virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7633. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7634. it != itEnd;
  7635. ++it )
  7636. (*it)->skipTest( testInfo );
  7637. }
  7638. virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
  7639. return this;
  7640. }
  7641. };
  7642. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
  7643. Ptr<IStreamingReporter> resultingReporter;
  7644. if( existingReporter ) {
  7645. MultipleReporters* multi = existingReporter->tryAsMulti();
  7646. if( !multi ) {
  7647. multi = new MultipleReporters;
  7648. resultingReporter = Ptr<IStreamingReporter>( multi );
  7649. if( existingReporter )
  7650. multi->add( existingReporter );
  7651. }
  7652. else
  7653. resultingReporter = existingReporter;
  7654. multi->add( additionalReporter );
  7655. }
  7656. else
  7657. resultingReporter = additionalReporter;
  7658. return resultingReporter;
  7659. }
  7660. } // end namespace Catch
  7661. // #included from: ../reporters/catch_reporter_xml.hpp
  7662. #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
  7663. // #included from: catch_reporter_bases.hpp
  7664. #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
  7665. #include <cstring>
  7666. #include <assert.h>
  7667. namespace Catch {
  7668. struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
  7669. StreamingReporterBase( ReporterConfig const& _config )
  7670. : m_config( _config.fullConfig() ),
  7671. stream( _config.stream() )
  7672. {
  7673. m_reporterPrefs.shouldRedirectStdOut = false;
  7674. }
  7675. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7676. return m_reporterPrefs;
  7677. }
  7678. virtual ~StreamingReporterBase() CATCH_OVERRIDE;
  7679. virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
  7680. virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
  7681. currentTestRunInfo = _testRunInfo;
  7682. }
  7683. virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
  7684. currentGroupInfo = _groupInfo;
  7685. }
  7686. virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
  7687. currentTestCaseInfo = _testInfo;
  7688. }
  7689. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  7690. m_sectionStack.push_back( _sectionInfo );
  7691. }
  7692. virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
  7693. m_sectionStack.pop_back();
  7694. }
  7695. virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
  7696. currentTestCaseInfo.reset();
  7697. }
  7698. virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
  7699. currentGroupInfo.reset();
  7700. }
  7701. virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
  7702. currentTestCaseInfo.reset();
  7703. currentGroupInfo.reset();
  7704. currentTestRunInfo.reset();
  7705. }
  7706. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
  7707. // Don't do anything with this by default.
  7708. // It can optionally be overridden in the derived class.
  7709. }
  7710. Ptr<IConfig const> m_config;
  7711. std::ostream& stream;
  7712. LazyStat<TestRunInfo> currentTestRunInfo;
  7713. LazyStat<GroupInfo> currentGroupInfo;
  7714. LazyStat<TestCaseInfo> currentTestCaseInfo;
  7715. std::vector<SectionInfo> m_sectionStack;
  7716. ReporterPreferences m_reporterPrefs;
  7717. };
  7718. struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
  7719. template<typename T, typename ChildNodeT>
  7720. struct Node : SharedImpl<> {
  7721. explicit Node( T const& _value ) : value( _value ) {}
  7722. virtual ~Node() {}
  7723. typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
  7724. T value;
  7725. ChildNodes children;
  7726. };
  7727. struct SectionNode : SharedImpl<> {
  7728. explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
  7729. virtual ~SectionNode();
  7730. bool operator == ( SectionNode const& other ) const {
  7731. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  7732. }
  7733. bool operator == ( Ptr<SectionNode> const& other ) const {
  7734. return operator==( *other );
  7735. }
  7736. SectionStats stats;
  7737. typedef std::vector<Ptr<SectionNode> > ChildSections;
  7738. typedef std::vector<AssertionStats> Assertions;
  7739. ChildSections childSections;
  7740. Assertions assertions;
  7741. std::string stdOut;
  7742. std::string stdErr;
  7743. };
  7744. struct BySectionInfo {
  7745. BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
  7746. BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
  7747. bool operator() ( Ptr<SectionNode> const& node ) const {
  7748. return node->stats.sectionInfo.lineInfo == m_other.lineInfo;
  7749. }
  7750. private:
  7751. void operator=( BySectionInfo const& );
  7752. SectionInfo const& m_other;
  7753. };
  7754. typedef Node<TestCaseStats, SectionNode> TestCaseNode;
  7755. typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
  7756. typedef Node<TestRunStats, TestGroupNode> TestRunNode;
  7757. CumulativeReporterBase( ReporterConfig const& _config )
  7758. : m_config( _config.fullConfig() ),
  7759. stream( _config.stream() )
  7760. {
  7761. m_reporterPrefs.shouldRedirectStdOut = false;
  7762. }
  7763. ~CumulativeReporterBase();
  7764. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7765. return m_reporterPrefs;
  7766. }
  7767. virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
  7768. virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
  7769. virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
  7770. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  7771. SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
  7772. Ptr<SectionNode> node;
  7773. if( m_sectionStack.empty() ) {
  7774. if( !m_rootSection )
  7775. m_rootSection = new SectionNode( incompleteStats );
  7776. node = m_rootSection;
  7777. }
  7778. else {
  7779. SectionNode& parentNode = *m_sectionStack.back();
  7780. SectionNode::ChildSections::const_iterator it =
  7781. std::find_if( parentNode.childSections.begin(),
  7782. parentNode.childSections.end(),
  7783. BySectionInfo( sectionInfo ) );
  7784. if( it == parentNode.childSections.end() ) {
  7785. node = new SectionNode( incompleteStats );
  7786. parentNode.childSections.push_back( node );
  7787. }
  7788. else
  7789. node = *it;
  7790. }
  7791. m_sectionStack.push_back( node );
  7792. m_deepestSection = node;
  7793. }
  7794. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  7795. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  7796. assert( !m_sectionStack.empty() );
  7797. SectionNode& sectionNode = *m_sectionStack.back();
  7798. sectionNode.assertions.push_back( assertionStats );
  7799. // AssertionResult holds a pointer to a temporary DecomposedExpression,
  7800. // which getExpandedExpression() calls to build the expression string.
  7801. // Our section stack copy of the assertionResult will likely outlive the
  7802. // temporary, so it must be expanded or discarded now to avoid calling
  7803. // a destroyed object later.
  7804. prepareExpandedExpression( sectionNode.assertions.back().assertionResult );
  7805. return true;
  7806. }
  7807. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  7808. assert( !m_sectionStack.empty() );
  7809. SectionNode& node = *m_sectionStack.back();
  7810. node.stats = sectionStats;
  7811. m_sectionStack.pop_back();
  7812. }
  7813. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  7814. Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
  7815. assert( m_sectionStack.size() == 0 );
  7816. node->children.push_back( m_rootSection );
  7817. m_testCases.push_back( node );
  7818. m_rootSection.reset();
  7819. assert( m_deepestSection );
  7820. m_deepestSection->stdOut = testCaseStats.stdOut;
  7821. m_deepestSection->stdErr = testCaseStats.stdErr;
  7822. }
  7823. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  7824. Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
  7825. node->children.swap( m_testCases );
  7826. m_testGroups.push_back( node );
  7827. }
  7828. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  7829. Ptr<TestRunNode> node = new TestRunNode( testRunStats );
  7830. node->children.swap( m_testGroups );
  7831. m_testRuns.push_back( node );
  7832. testRunEndedCumulative();
  7833. }
  7834. virtual void testRunEndedCumulative() = 0;
  7835. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
  7836. virtual void prepareExpandedExpression( AssertionResult& result ) const {
  7837. if( result.isOk() )
  7838. result.discardDecomposedExpression();
  7839. else
  7840. result.expandDecomposedExpression();
  7841. }
  7842. Ptr<IConfig const> m_config;
  7843. std::ostream& stream;
  7844. std::vector<AssertionStats> m_assertions;
  7845. std::vector<std::vector<Ptr<SectionNode> > > m_sections;
  7846. std::vector<Ptr<TestCaseNode> > m_testCases;
  7847. std::vector<Ptr<TestGroupNode> > m_testGroups;
  7848. std::vector<Ptr<TestRunNode> > m_testRuns;
  7849. Ptr<SectionNode> m_rootSection;
  7850. Ptr<SectionNode> m_deepestSection;
  7851. std::vector<Ptr<SectionNode> > m_sectionStack;
  7852. ReporterPreferences m_reporterPrefs;
  7853. };
  7854. template<char C>
  7855. char const* getLineOfChars() {
  7856. static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
  7857. if( !*line ) {
  7858. std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
  7859. line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
  7860. }
  7861. return line;
  7862. }
  7863. struct TestEventListenerBase : StreamingReporterBase {
  7864. TestEventListenerBase( ReporterConfig const& _config )
  7865. : StreamingReporterBase( _config )
  7866. {}
  7867. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  7868. virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
  7869. return false;
  7870. }
  7871. };
  7872. } // end namespace Catch
  7873. // #included from: ../internal/catch_reporter_registrars.hpp
  7874. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  7875. namespace Catch {
  7876. template<typename T>
  7877. class LegacyReporterRegistrar {
  7878. class ReporterFactory : public IReporterFactory {
  7879. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  7880. return new LegacyReporterAdapter( new T( config ) );
  7881. }
  7882. virtual std::string getDescription() const {
  7883. return T::getDescription();
  7884. }
  7885. };
  7886. public:
  7887. LegacyReporterRegistrar( std::string const& name ) {
  7888. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  7889. }
  7890. };
  7891. template<typename T>
  7892. class ReporterRegistrar {
  7893. class ReporterFactory : public SharedImpl<IReporterFactory> {
  7894. // *** Please Note ***:
  7895. // - If you end up here looking at a compiler error because it's trying to register
  7896. // your custom reporter class be aware that the native reporter interface has changed
  7897. // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
  7898. // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
  7899. // However please consider updating to the new interface as the old one is now
  7900. // deprecated and will probably be removed quite soon!
  7901. // Please contact me via github if you have any questions at all about this.
  7902. // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
  7903. // no idea who is actually using custom reporters at all (possibly no-one!).
  7904. // The new interface is designed to minimise exposure to interface changes in the future.
  7905. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  7906. return new T( config );
  7907. }
  7908. virtual std::string getDescription() const {
  7909. return T::getDescription();
  7910. }
  7911. };
  7912. public:
  7913. ReporterRegistrar( std::string const& name ) {
  7914. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  7915. }
  7916. };
  7917. template<typename T>
  7918. class ListenerRegistrar {
  7919. class ListenerFactory : public SharedImpl<IReporterFactory> {
  7920. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  7921. return new T( config );
  7922. }
  7923. virtual std::string getDescription() const {
  7924. return std::string();
  7925. }
  7926. };
  7927. public:
  7928. ListenerRegistrar() {
  7929. getMutableRegistryHub().registerListener( new ListenerFactory() );
  7930. }
  7931. };
  7932. }
  7933. #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
  7934. namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  7935. #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
  7936. namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  7937. #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
  7938. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  7939. // #included from: ../internal/catch_xmlwriter.hpp
  7940. #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
  7941. #include <sstream>
  7942. #include <string>
  7943. #include <vector>
  7944. #include <iomanip>
  7945. namespace Catch {
  7946. class XmlEncode {
  7947. public:
  7948. enum ForWhat { ForTextNodes, ForAttributes };
  7949. XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
  7950. : m_str( str ),
  7951. m_forWhat( forWhat )
  7952. {}
  7953. void encodeTo( std::ostream& os ) const {
  7954. // Apostrophe escaping not necessary if we always use " to write attributes
  7955. // (see: http://www.w3.org/TR/xml/#syntax)
  7956. for( std::size_t i = 0; i < m_str.size(); ++ i ) {
  7957. char c = m_str[i];
  7958. switch( c ) {
  7959. case '<': os << "&lt;"; break;
  7960. case '&': os << "&amp;"; break;
  7961. case '>':
  7962. // See: http://www.w3.org/TR/xml/#syntax
  7963. if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
  7964. os << "&gt;";
  7965. else
  7966. os << c;
  7967. break;
  7968. case '\"':
  7969. if( m_forWhat == ForAttributes )
  7970. os << "&quot;";
  7971. else
  7972. os << c;
  7973. break;
  7974. default:
  7975. // Escape control chars - based on contribution by @espenalb in PR #465 and
  7976. // by @mrpi PR #588
  7977. if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) {
  7978. // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
  7979. os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
  7980. << static_cast<int>( c );
  7981. }
  7982. else
  7983. os << c;
  7984. }
  7985. }
  7986. }
  7987. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
  7988. xmlEncode.encodeTo( os );
  7989. return os;
  7990. }
  7991. private:
  7992. std::string m_str;
  7993. ForWhat m_forWhat;
  7994. };
  7995. class XmlWriter {
  7996. public:
  7997. class ScopedElement {
  7998. public:
  7999. ScopedElement( XmlWriter* writer )
  8000. : m_writer( writer )
  8001. {}
  8002. ScopedElement( ScopedElement const& other )
  8003. : m_writer( other.m_writer ){
  8004. other.m_writer = CATCH_NULL;
  8005. }
  8006. ~ScopedElement() {
  8007. if( m_writer )
  8008. m_writer->endElement();
  8009. }
  8010. ScopedElement& writeText( std::string const& text, bool indent = true ) {
  8011. m_writer->writeText( text, indent );
  8012. return *this;
  8013. }
  8014. template<typename T>
  8015. ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
  8016. m_writer->writeAttribute( name, attribute );
  8017. return *this;
  8018. }
  8019. private:
  8020. mutable XmlWriter* m_writer;
  8021. };
  8022. XmlWriter()
  8023. : m_tagIsOpen( false ),
  8024. m_needsNewline( false ),
  8025. m_os( Catch::cout() )
  8026. {
  8027. writeDeclaration();
  8028. }
  8029. XmlWriter( std::ostream& os )
  8030. : m_tagIsOpen( false ),
  8031. m_needsNewline( false ),
  8032. m_os( os )
  8033. {
  8034. writeDeclaration();
  8035. }
  8036. ~XmlWriter() {
  8037. while( !m_tags.empty() )
  8038. endElement();
  8039. }
  8040. XmlWriter& startElement( std::string const& name ) {
  8041. ensureTagClosed();
  8042. newlineIfNecessary();
  8043. m_os << m_indent << '<' << name;
  8044. m_tags.push_back( name );
  8045. m_indent += " ";
  8046. m_tagIsOpen = true;
  8047. return *this;
  8048. }
  8049. ScopedElement scopedElement( std::string const& name ) {
  8050. ScopedElement scoped( this );
  8051. startElement( name );
  8052. return scoped;
  8053. }
  8054. XmlWriter& endElement() {
  8055. newlineIfNecessary();
  8056. m_indent = m_indent.substr( 0, m_indent.size()-2 );
  8057. if( m_tagIsOpen ) {
  8058. m_os << "/>";
  8059. m_tagIsOpen = false;
  8060. }
  8061. else {
  8062. m_os << m_indent << "</" << m_tags.back() << ">";
  8063. }
  8064. m_os << std::endl;
  8065. m_tags.pop_back();
  8066. return *this;
  8067. }
  8068. XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
  8069. if( !name.empty() && !attribute.empty() )
  8070. m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
  8071. return *this;
  8072. }
  8073. XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
  8074. m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
  8075. return *this;
  8076. }
  8077. template<typename T>
  8078. XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
  8079. std::ostringstream oss;
  8080. oss << attribute;
  8081. return writeAttribute( name, oss.str() );
  8082. }
  8083. XmlWriter& writeText( std::string const& text, bool indent = true ) {
  8084. if( !text.empty() ){
  8085. bool tagWasOpen = m_tagIsOpen;
  8086. ensureTagClosed();
  8087. if( tagWasOpen && indent )
  8088. m_os << m_indent;
  8089. m_os << XmlEncode( text );
  8090. m_needsNewline = true;
  8091. }
  8092. return *this;
  8093. }
  8094. XmlWriter& writeComment( std::string const& text ) {
  8095. ensureTagClosed();
  8096. m_os << m_indent << "<!--" << text << "-->";
  8097. m_needsNewline = true;
  8098. return *this;
  8099. }
  8100. void writeStylesheetRef( std::string const& url ) {
  8101. m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
  8102. }
  8103. XmlWriter& writeBlankLine() {
  8104. ensureTagClosed();
  8105. m_os << '\n';
  8106. return *this;
  8107. }
  8108. void ensureTagClosed() {
  8109. if( m_tagIsOpen ) {
  8110. m_os << ">" << std::endl;
  8111. m_tagIsOpen = false;
  8112. }
  8113. }
  8114. private:
  8115. XmlWriter( XmlWriter const& );
  8116. void operator=( XmlWriter const& );
  8117. void writeDeclaration() {
  8118. m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  8119. }
  8120. void newlineIfNecessary() {
  8121. if( m_needsNewline ) {
  8122. m_os << std::endl;
  8123. m_needsNewline = false;
  8124. }
  8125. }
  8126. bool m_tagIsOpen;
  8127. bool m_needsNewline;
  8128. std::vector<std::string> m_tags;
  8129. std::string m_indent;
  8130. std::ostream& m_os;
  8131. };
  8132. }
  8133. // #included from: catch_reenable_warnings.h
  8134. #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
  8135. #ifdef __clang__
  8136. # ifdef __ICC // icpc defines the __clang__ macro
  8137. # pragma warning(pop)
  8138. # else
  8139. # pragma clang diagnostic pop
  8140. # endif
  8141. #elif defined __GNUC__
  8142. # pragma GCC diagnostic pop
  8143. #endif
  8144. namespace Catch {
  8145. class XmlReporter : public StreamingReporterBase {
  8146. public:
  8147. XmlReporter( ReporterConfig const& _config )
  8148. : StreamingReporterBase( _config ),
  8149. m_xml(_config.stream()),
  8150. m_sectionDepth( 0 )
  8151. {
  8152. m_reporterPrefs.shouldRedirectStdOut = true;
  8153. }
  8154. virtual ~XmlReporter() CATCH_OVERRIDE;
  8155. static std::string getDescription() {
  8156. return "Reports test results as an XML document";
  8157. }
  8158. virtual std::string getStylesheetRef() const {
  8159. return std::string();
  8160. }
  8161. void writeSourceInfo( SourceLineInfo const& sourceInfo ) {
  8162. m_xml
  8163. .writeAttribute( "filename", sourceInfo.file )
  8164. .writeAttribute( "line", sourceInfo.line );
  8165. }
  8166. public: // StreamingReporterBase
  8167. virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
  8168. StreamingReporterBase::noMatchingTestCases( s );
  8169. }
  8170. virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
  8171. StreamingReporterBase::testRunStarting( testInfo );
  8172. std::string stylesheetRef = getStylesheetRef();
  8173. if( !stylesheetRef.empty() )
  8174. m_xml.writeStylesheetRef( stylesheetRef );
  8175. m_xml.startElement( "Catch" );
  8176. if( !m_config->name().empty() )
  8177. m_xml.writeAttribute( "name", m_config->name() );
  8178. }
  8179. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8180. StreamingReporterBase::testGroupStarting( groupInfo );
  8181. m_xml.startElement( "Group" )
  8182. .writeAttribute( "name", groupInfo.name );
  8183. }
  8184. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  8185. StreamingReporterBase::testCaseStarting(testInfo);
  8186. m_xml.startElement( "TestCase" )
  8187. .writeAttribute( "name", trim( testInfo.name ) )
  8188. .writeAttribute( "description", testInfo.description )
  8189. .writeAttribute( "tags", testInfo.tagsAsString );
  8190. writeSourceInfo( testInfo.lineInfo );
  8191. if ( m_config->showDurations() == ShowDurations::Always )
  8192. m_testCaseTimer.start();
  8193. m_xml.ensureTagClosed();
  8194. }
  8195. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8196. StreamingReporterBase::sectionStarting( sectionInfo );
  8197. if( m_sectionDepth++ > 0 ) {
  8198. m_xml.startElement( "Section" )
  8199. .writeAttribute( "name", trim( sectionInfo.name ) )
  8200. .writeAttribute( "description", sectionInfo.description );
  8201. writeSourceInfo( sectionInfo.lineInfo );
  8202. m_xml.ensureTagClosed();
  8203. }
  8204. }
  8205. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
  8206. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8207. const AssertionResult& assertionResult = assertionStats.assertionResult;
  8208. // Print any info messages in <Info> tags.
  8209. if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
  8210. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  8211. it != itEnd;
  8212. ++it ) {
  8213. if( it->type == ResultWas::Info ) {
  8214. m_xml.scopedElement( "Info" )
  8215. .writeText( it->message );
  8216. } else if ( it->type == ResultWas::Warning ) {
  8217. m_xml.scopedElement( "Warning" )
  8218. .writeText( it->message );
  8219. }
  8220. }
  8221. }
  8222. // Drop out if result was successful but we're not printing them.
  8223. if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) )
  8224. return true;
  8225. // Print the expression if there is one.
  8226. if( assertionResult.hasExpression() ) {
  8227. m_xml.startElement( "Expression" )
  8228. .writeAttribute( "success", assertionResult.succeeded() )
  8229. .writeAttribute( "type", assertionResult.getTestMacroName() );
  8230. writeSourceInfo( assertionResult.getSourceInfo() );
  8231. m_xml.scopedElement( "Original" )
  8232. .writeText( assertionResult.getExpression() );
  8233. m_xml.scopedElement( "Expanded" )
  8234. .writeText( assertionResult.getExpandedExpression() );
  8235. }
  8236. // And... Print a result applicable to each result type.
  8237. switch( assertionResult.getResultType() ) {
  8238. case ResultWas::ThrewException:
  8239. m_xml.startElement( "Exception" );
  8240. writeSourceInfo( assertionResult.getSourceInfo() );
  8241. m_xml.writeText( assertionResult.getMessage() );
  8242. m_xml.endElement();
  8243. break;
  8244. case ResultWas::FatalErrorCondition:
  8245. m_xml.startElement( "FatalErrorCondition" );
  8246. writeSourceInfo( assertionResult.getSourceInfo() );
  8247. m_xml.writeText( assertionResult.getMessage() );
  8248. m_xml.endElement();
  8249. break;
  8250. case ResultWas::Info:
  8251. m_xml.scopedElement( "Info" )
  8252. .writeText( assertionResult.getMessage() );
  8253. break;
  8254. case ResultWas::Warning:
  8255. // Warning will already have been written
  8256. break;
  8257. case ResultWas::ExplicitFailure:
  8258. m_xml.startElement( "Failure" );
  8259. writeSourceInfo( assertionResult.getSourceInfo() );
  8260. m_xml.writeText( assertionResult.getMessage() );
  8261. m_xml.endElement();
  8262. break;
  8263. default:
  8264. break;
  8265. }
  8266. if( assertionResult.hasExpression() )
  8267. m_xml.endElement();
  8268. return true;
  8269. }
  8270. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8271. StreamingReporterBase::sectionEnded( sectionStats );
  8272. if( --m_sectionDepth > 0 ) {
  8273. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
  8274. e.writeAttribute( "successes", sectionStats.assertions.passed );
  8275. e.writeAttribute( "failures", sectionStats.assertions.failed );
  8276. e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
  8277. if ( m_config->showDurations() == ShowDurations::Always )
  8278. e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
  8279. m_xml.endElement();
  8280. }
  8281. }
  8282. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8283. StreamingReporterBase::testCaseEnded( testCaseStats );
  8284. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
  8285. e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
  8286. if ( m_config->showDurations() == ShowDurations::Always )
  8287. e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
  8288. if( !testCaseStats.stdOut.empty() )
  8289. m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false );
  8290. if( !testCaseStats.stdErr.empty() )
  8291. m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false );
  8292. m_xml.endElement();
  8293. }
  8294. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8295. StreamingReporterBase::testGroupEnded( testGroupStats );
  8296. // TODO: Check testGroupStats.aborting and act accordingly.
  8297. m_xml.scopedElement( "OverallResults" )
  8298. .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
  8299. .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
  8300. .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
  8301. m_xml.endElement();
  8302. }
  8303. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8304. StreamingReporterBase::testRunEnded( testRunStats );
  8305. m_xml.scopedElement( "OverallResults" )
  8306. .writeAttribute( "successes", testRunStats.totals.assertions.passed )
  8307. .writeAttribute( "failures", testRunStats.totals.assertions.failed )
  8308. .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
  8309. m_xml.endElement();
  8310. }
  8311. private:
  8312. Timer m_testCaseTimer;
  8313. XmlWriter m_xml;
  8314. int m_sectionDepth;
  8315. };
  8316. INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
  8317. } // end namespace Catch
  8318. // #included from: ../reporters/catch_reporter_junit.hpp
  8319. #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
  8320. #include <assert.h>
  8321. namespace Catch {
  8322. namespace {
  8323. std::string getCurrentTimestamp() {
  8324. // Beware, this is not reentrant because of backward compatibility issues
  8325. // Also, UTC only, again because of backward compatibility (%z is C++11)
  8326. time_t rawtime;
  8327. std::time(&rawtime);
  8328. const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z");
  8329. #ifdef _MSC_VER
  8330. std::tm timeInfo = {};
  8331. gmtime_s(&timeInfo, &rawtime);
  8332. #else
  8333. std::tm* timeInfo;
  8334. timeInfo = std::gmtime(&rawtime);
  8335. #endif
  8336. char timeStamp[timeStampSize];
  8337. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  8338. #ifdef _MSC_VER
  8339. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  8340. #else
  8341. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  8342. #endif
  8343. return std::string(timeStamp);
  8344. }
  8345. }
  8346. class JunitReporter : public CumulativeReporterBase {
  8347. public:
  8348. JunitReporter( ReporterConfig const& _config )
  8349. : CumulativeReporterBase( _config ),
  8350. xml( _config.stream() )
  8351. {
  8352. m_reporterPrefs.shouldRedirectStdOut = true;
  8353. }
  8354. virtual ~JunitReporter() CATCH_OVERRIDE;
  8355. static std::string getDescription() {
  8356. return "Reports test results in an XML format that looks like Ant's junitreport target";
  8357. }
  8358. virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
  8359. virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
  8360. CumulativeReporterBase::testRunStarting( runInfo );
  8361. xml.startElement( "testsuites" );
  8362. }
  8363. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8364. suiteTimer.start();
  8365. stdOutForSuite.str("");
  8366. stdErrForSuite.str("");
  8367. unexpectedExceptions = 0;
  8368. CumulativeReporterBase::testGroupStarting( groupInfo );
  8369. }
  8370. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8371. if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException )
  8372. unexpectedExceptions++;
  8373. return CumulativeReporterBase::assertionEnded( assertionStats );
  8374. }
  8375. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8376. stdOutForSuite << testCaseStats.stdOut;
  8377. stdErrForSuite << testCaseStats.stdErr;
  8378. CumulativeReporterBase::testCaseEnded( testCaseStats );
  8379. }
  8380. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8381. double suiteTime = suiteTimer.getElapsedSeconds();
  8382. CumulativeReporterBase::testGroupEnded( testGroupStats );
  8383. writeGroup( *m_testGroups.back(), suiteTime );
  8384. }
  8385. virtual void testRunEndedCumulative() CATCH_OVERRIDE {
  8386. xml.endElement();
  8387. }
  8388. void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
  8389. XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
  8390. TestGroupStats const& stats = groupNode.value;
  8391. xml.writeAttribute( "name", stats.groupInfo.name );
  8392. xml.writeAttribute( "errors", unexpectedExceptions );
  8393. xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
  8394. xml.writeAttribute( "tests", stats.totals.assertions.total() );
  8395. xml.writeAttribute( "hostname", "tbd" ); // !TBD
  8396. if( m_config->showDurations() == ShowDurations::Never )
  8397. xml.writeAttribute( "time", "" );
  8398. else
  8399. xml.writeAttribute( "time", suiteTime );
  8400. xml.writeAttribute( "timestamp", getCurrentTimestamp() );
  8401. // Write test cases
  8402. for( TestGroupNode::ChildNodes::const_iterator
  8403. it = groupNode.children.begin(), itEnd = groupNode.children.end();
  8404. it != itEnd;
  8405. ++it )
  8406. writeTestCase( **it );
  8407. xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
  8408. xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
  8409. }
  8410. void writeTestCase( TestCaseNode const& testCaseNode ) {
  8411. TestCaseStats const& stats = testCaseNode.value;
  8412. // All test cases have exactly one section - which represents the
  8413. // test case itself. That section may have 0-n nested sections
  8414. assert( testCaseNode.children.size() == 1 );
  8415. SectionNode const& rootSection = *testCaseNode.children.front();
  8416. std::string className = stats.testInfo.className;
  8417. if( className.empty() ) {
  8418. if( rootSection.childSections.empty() )
  8419. className = "global";
  8420. }
  8421. writeSection( className, "", rootSection );
  8422. }
  8423. void writeSection( std::string const& className,
  8424. std::string const& rootName,
  8425. SectionNode const& sectionNode ) {
  8426. std::string name = trim( sectionNode.stats.sectionInfo.name );
  8427. if( !rootName.empty() )
  8428. name = rootName + '/' + name;
  8429. if( !sectionNode.assertions.empty() ||
  8430. !sectionNode.stdOut.empty() ||
  8431. !sectionNode.stdErr.empty() ) {
  8432. XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
  8433. if( className.empty() ) {
  8434. xml.writeAttribute( "classname", name );
  8435. xml.writeAttribute( "name", "root" );
  8436. }
  8437. else {
  8438. xml.writeAttribute( "classname", className );
  8439. xml.writeAttribute( "name", name );
  8440. }
  8441. xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
  8442. writeAssertions( sectionNode );
  8443. if( !sectionNode.stdOut.empty() )
  8444. xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
  8445. if( !sectionNode.stdErr.empty() )
  8446. xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
  8447. }
  8448. for( SectionNode::ChildSections::const_iterator
  8449. it = sectionNode.childSections.begin(),
  8450. itEnd = sectionNode.childSections.end();
  8451. it != itEnd;
  8452. ++it )
  8453. if( className.empty() )
  8454. writeSection( name, "", **it );
  8455. else
  8456. writeSection( className, name, **it );
  8457. }
  8458. void writeAssertions( SectionNode const& sectionNode ) {
  8459. for( SectionNode::Assertions::const_iterator
  8460. it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
  8461. it != itEnd;
  8462. ++it )
  8463. writeAssertion( *it );
  8464. }
  8465. void writeAssertion( AssertionStats const& stats ) {
  8466. AssertionResult const& result = stats.assertionResult;
  8467. if( !result.isOk() ) {
  8468. std::string elementName;
  8469. switch( result.getResultType() ) {
  8470. case ResultWas::ThrewException:
  8471. case ResultWas::FatalErrorCondition:
  8472. elementName = "error";
  8473. break;
  8474. case ResultWas::ExplicitFailure:
  8475. elementName = "failure";
  8476. break;
  8477. case ResultWas::ExpressionFailed:
  8478. elementName = "failure";
  8479. break;
  8480. case ResultWas::DidntThrowException:
  8481. elementName = "failure";
  8482. break;
  8483. // We should never see these here:
  8484. case ResultWas::Info:
  8485. case ResultWas::Warning:
  8486. case ResultWas::Ok:
  8487. case ResultWas::Unknown:
  8488. case ResultWas::FailureBit:
  8489. case ResultWas::Exception:
  8490. elementName = "internalError";
  8491. break;
  8492. }
  8493. XmlWriter::ScopedElement e = xml.scopedElement( elementName );
  8494. xml.writeAttribute( "message", result.getExpandedExpression() );
  8495. xml.writeAttribute( "type", result.getTestMacroName() );
  8496. std::ostringstream oss;
  8497. if( !result.getMessage().empty() )
  8498. oss << result.getMessage() << '\n';
  8499. for( std::vector<MessageInfo>::const_iterator
  8500. it = stats.infoMessages.begin(),
  8501. itEnd = stats.infoMessages.end();
  8502. it != itEnd;
  8503. ++it )
  8504. if( it->type == ResultWas::Info )
  8505. oss << it->message << '\n';
  8506. oss << "at " << result.getSourceInfo();
  8507. xml.writeText( oss.str(), false );
  8508. }
  8509. }
  8510. XmlWriter xml;
  8511. Timer suiteTimer;
  8512. std::ostringstream stdOutForSuite;
  8513. std::ostringstream stdErrForSuite;
  8514. unsigned int unexpectedExceptions;
  8515. };
  8516. INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
  8517. } // end namespace Catch
  8518. // #included from: ../reporters/catch_reporter_console.hpp
  8519. #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8520. #include <cfloat>
  8521. #include <cstdio>
  8522. namespace Catch {
  8523. namespace {
  8524. // Because formatting using c++ streams is stateful, drop down to C is required
  8525. // Alternatively we could use stringstream, but its performance is... not good.
  8526. std::string getFormattedDuration( double duration ) {
  8527. // Max exponent + 1 is required to represent the whole part
  8528. // + 1 for decimal point
  8529. // + 3 for the 3 decimal places
  8530. // + 1 for null terminator
  8531. const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
  8532. char buffer[maxDoubleSize];
  8533. #ifdef _MSC_VER
  8534. sprintf_s(buffer, "%.3f", duration);
  8535. #else
  8536. sprintf(buffer, "%.3f", duration);
  8537. #endif
  8538. return std::string(buffer);
  8539. }
  8540. }
  8541. struct ConsoleReporter : StreamingReporterBase {
  8542. ConsoleReporter( ReporterConfig const& _config )
  8543. : StreamingReporterBase( _config ),
  8544. m_headerPrinted( false )
  8545. {}
  8546. virtual ~ConsoleReporter() CATCH_OVERRIDE;
  8547. static std::string getDescription() {
  8548. return "Reports test results as plain lines of text";
  8549. }
  8550. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  8551. stream << "No test cases matched '" << spec << '\'' << std::endl;
  8552. }
  8553. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
  8554. }
  8555. virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
  8556. AssertionResult const& result = _assertionStats.assertionResult;
  8557. bool printInfoMessages = true;
  8558. // Drop out if result was successful and we're not printing those
  8559. if( !m_config->includeSuccessfulResults() && result.isOk() ) {
  8560. if( result.getResultType() != ResultWas::Warning )
  8561. return false;
  8562. printInfoMessages = false;
  8563. }
  8564. lazyPrint();
  8565. AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
  8566. printer.print();
  8567. stream << std::endl;
  8568. return true;
  8569. }
  8570. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8571. m_headerPrinted = false;
  8572. StreamingReporterBase::sectionStarting( _sectionInfo );
  8573. }
  8574. virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
  8575. if( _sectionStats.missingAssertions ) {
  8576. lazyPrint();
  8577. Colour colour( Colour::ResultError );
  8578. if( m_sectionStack.size() > 1 )
  8579. stream << "\nNo assertions in section";
  8580. else
  8581. stream << "\nNo assertions in test case";
  8582. stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
  8583. }
  8584. if( m_config->showDurations() == ShowDurations::Always ) {
  8585. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  8586. }
  8587. if( m_headerPrinted ) {
  8588. m_headerPrinted = false;
  8589. }
  8590. StreamingReporterBase::sectionEnded( _sectionStats );
  8591. }
  8592. virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
  8593. StreamingReporterBase::testCaseEnded( _testCaseStats );
  8594. m_headerPrinted = false;
  8595. }
  8596. virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
  8597. if( currentGroupInfo.used ) {
  8598. printSummaryDivider();
  8599. stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
  8600. printTotals( _testGroupStats.totals );
  8601. stream << '\n' << std::endl;
  8602. }
  8603. StreamingReporterBase::testGroupEnded( _testGroupStats );
  8604. }
  8605. virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
  8606. printTotalsDivider( _testRunStats.totals );
  8607. printTotals( _testRunStats.totals );
  8608. stream << std::endl;
  8609. StreamingReporterBase::testRunEnded( _testRunStats );
  8610. }
  8611. private:
  8612. class AssertionPrinter {
  8613. void operator= ( AssertionPrinter const& );
  8614. public:
  8615. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  8616. : stream( _stream ),
  8617. stats( _stats ),
  8618. result( _stats.assertionResult ),
  8619. colour( Colour::None ),
  8620. message( result.getMessage() ),
  8621. messages( _stats.infoMessages ),
  8622. printInfoMessages( _printInfoMessages )
  8623. {
  8624. switch( result.getResultType() ) {
  8625. case ResultWas::Ok:
  8626. colour = Colour::Success;
  8627. passOrFail = "PASSED";
  8628. //if( result.hasMessage() )
  8629. if( _stats.infoMessages.size() == 1 )
  8630. messageLabel = "with message";
  8631. if( _stats.infoMessages.size() > 1 )
  8632. messageLabel = "with messages";
  8633. break;
  8634. case ResultWas::ExpressionFailed:
  8635. if( result.isOk() ) {
  8636. colour = Colour::Success;
  8637. passOrFail = "FAILED - but was ok";
  8638. }
  8639. else {
  8640. colour = Colour::Error;
  8641. passOrFail = "FAILED";
  8642. }
  8643. if( _stats.infoMessages.size() == 1 )
  8644. messageLabel = "with message";
  8645. if( _stats.infoMessages.size() > 1 )
  8646. messageLabel = "with messages";
  8647. break;
  8648. case ResultWas::ThrewException:
  8649. colour = Colour::Error;
  8650. passOrFail = "FAILED";
  8651. messageLabel = "due to unexpected exception with message";
  8652. break;
  8653. case ResultWas::FatalErrorCondition:
  8654. colour = Colour::Error;
  8655. passOrFail = "FAILED";
  8656. messageLabel = "due to a fatal error condition";
  8657. break;
  8658. case ResultWas::DidntThrowException:
  8659. colour = Colour::Error;
  8660. passOrFail = "FAILED";
  8661. messageLabel = "because no exception was thrown where one was expected";
  8662. break;
  8663. case ResultWas::Info:
  8664. messageLabel = "info";
  8665. break;
  8666. case ResultWas::Warning:
  8667. messageLabel = "warning";
  8668. break;
  8669. case ResultWas::ExplicitFailure:
  8670. passOrFail = "FAILED";
  8671. colour = Colour::Error;
  8672. if( _stats.infoMessages.size() == 1 )
  8673. messageLabel = "explicitly with message";
  8674. if( _stats.infoMessages.size() > 1 )
  8675. messageLabel = "explicitly with messages";
  8676. break;
  8677. // These cases are here to prevent compiler warnings
  8678. case ResultWas::Unknown:
  8679. case ResultWas::FailureBit:
  8680. case ResultWas::Exception:
  8681. passOrFail = "** internal error **";
  8682. colour = Colour::Error;
  8683. break;
  8684. }
  8685. }
  8686. void print() const {
  8687. printSourceInfo();
  8688. if( stats.totals.assertions.total() > 0 ) {
  8689. if( result.isOk() )
  8690. stream << '\n';
  8691. printResultType();
  8692. printOriginalExpression();
  8693. printReconstructedExpression();
  8694. }
  8695. else {
  8696. stream << '\n';
  8697. }
  8698. printMessage();
  8699. }
  8700. private:
  8701. void printResultType() const {
  8702. if( !passOrFail.empty() ) {
  8703. Colour colourGuard( colour );
  8704. stream << passOrFail << ":\n";
  8705. }
  8706. }
  8707. void printOriginalExpression() const {
  8708. if( result.hasExpression() ) {
  8709. Colour colourGuard( Colour::OriginalExpression );
  8710. stream << " ";
  8711. stream << result.getExpressionInMacro();
  8712. stream << '\n';
  8713. }
  8714. }
  8715. void printReconstructedExpression() const {
  8716. if( result.hasExpandedExpression() ) {
  8717. stream << "with expansion:\n";
  8718. Colour colourGuard( Colour::ReconstructedExpression );
  8719. stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n';
  8720. }
  8721. }
  8722. void printMessage() const {
  8723. if( !messageLabel.empty() )
  8724. stream << messageLabel << ':' << '\n';
  8725. for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
  8726. it != itEnd;
  8727. ++it ) {
  8728. // If this assertion is a warning ignore any INFO messages
  8729. if( printInfoMessages || it->type != ResultWas::Info )
  8730. stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
  8731. }
  8732. }
  8733. void printSourceInfo() const {
  8734. Colour colourGuard( Colour::FileName );
  8735. stream << result.getSourceInfo() << ": ";
  8736. }
  8737. std::ostream& stream;
  8738. AssertionStats const& stats;
  8739. AssertionResult const& result;
  8740. Colour::Code colour;
  8741. std::string passOrFail;
  8742. std::string messageLabel;
  8743. std::string message;
  8744. std::vector<MessageInfo> messages;
  8745. bool printInfoMessages;
  8746. };
  8747. void lazyPrint() {
  8748. if( !currentTestRunInfo.used )
  8749. lazyPrintRunInfo();
  8750. if( !currentGroupInfo.used )
  8751. lazyPrintGroupInfo();
  8752. if( !m_headerPrinted ) {
  8753. printTestCaseAndSectionHeader();
  8754. m_headerPrinted = true;
  8755. }
  8756. }
  8757. void lazyPrintRunInfo() {
  8758. stream << '\n' << getLineOfChars<'~'>() << '\n';
  8759. Colour colour( Colour::SecondaryText );
  8760. stream << currentTestRunInfo->name
  8761. << " is a Catch v" << libraryVersion << " host application.\n"
  8762. << "Run with -? for options\n\n";
  8763. if( m_config->rngSeed() != 0 )
  8764. stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
  8765. currentTestRunInfo.used = true;
  8766. }
  8767. void lazyPrintGroupInfo() {
  8768. if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
  8769. printClosedHeader( "Group: " + currentGroupInfo->name );
  8770. currentGroupInfo.used = true;
  8771. }
  8772. }
  8773. void printTestCaseAndSectionHeader() {
  8774. assert( !m_sectionStack.empty() );
  8775. printOpenHeader( currentTestCaseInfo->name );
  8776. if( m_sectionStack.size() > 1 ) {
  8777. Colour colourGuard( Colour::Headers );
  8778. std::vector<SectionInfo>::const_iterator
  8779. it = m_sectionStack.begin()+1, // Skip first section (test case)
  8780. itEnd = m_sectionStack.end();
  8781. for( ; it != itEnd; ++it )
  8782. printHeaderString( it->name, 2 );
  8783. }
  8784. SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
  8785. if( !lineInfo.empty() ){
  8786. stream << getLineOfChars<'-'>() << '\n';
  8787. Colour colourGuard( Colour::FileName );
  8788. stream << lineInfo << '\n';
  8789. }
  8790. stream << getLineOfChars<'.'>() << '\n' << std::endl;
  8791. }
  8792. void printClosedHeader( std::string const& _name ) {
  8793. printOpenHeader( _name );
  8794. stream << getLineOfChars<'.'>() << '\n';
  8795. }
  8796. void printOpenHeader( std::string const& _name ) {
  8797. stream << getLineOfChars<'-'>() << '\n';
  8798. {
  8799. Colour colourGuard( Colour::Headers );
  8800. printHeaderString( _name );
  8801. }
  8802. }
  8803. // if string has a : in first line will set indent to follow it on
  8804. // subsequent lines
  8805. void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
  8806. std::size_t i = _string.find( ": " );
  8807. if( i != std::string::npos )
  8808. i+=2;
  8809. else
  8810. i = 0;
  8811. stream << Text( _string, TextAttributes()
  8812. .setIndent( indent+i)
  8813. .setInitialIndent( indent ) ) << '\n';
  8814. }
  8815. struct SummaryColumn {
  8816. SummaryColumn( std::string const& _label, Colour::Code _colour )
  8817. : label( _label ),
  8818. colour( _colour )
  8819. {}
  8820. SummaryColumn addRow( std::size_t count ) {
  8821. std::ostringstream oss;
  8822. oss << count;
  8823. std::string row = oss.str();
  8824. for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
  8825. while( it->size() < row.size() )
  8826. *it = ' ' + *it;
  8827. while( it->size() > row.size() )
  8828. row = ' ' + row;
  8829. }
  8830. rows.push_back( row );
  8831. return *this;
  8832. }
  8833. std::string label;
  8834. Colour::Code colour;
  8835. std::vector<std::string> rows;
  8836. };
  8837. void printTotals( Totals const& totals ) {
  8838. if( totals.testCases.total() == 0 ) {
  8839. stream << Colour( Colour::Warning ) << "No tests ran\n";
  8840. }
  8841. else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
  8842. stream << Colour( Colour::ResultSuccess ) << "All tests passed";
  8843. stream << " ("
  8844. << pluralise( totals.assertions.passed, "assertion" ) << " in "
  8845. << pluralise( totals.testCases.passed, "test case" ) << ')'
  8846. << '\n';
  8847. }
  8848. else {
  8849. std::vector<SummaryColumn> columns;
  8850. columns.push_back( SummaryColumn( "", Colour::None )
  8851. .addRow( totals.testCases.total() )
  8852. .addRow( totals.assertions.total() ) );
  8853. columns.push_back( SummaryColumn( "passed", Colour::Success )
  8854. .addRow( totals.testCases.passed )
  8855. .addRow( totals.assertions.passed ) );
  8856. columns.push_back( SummaryColumn( "failed", Colour::ResultError )
  8857. .addRow( totals.testCases.failed )
  8858. .addRow( totals.assertions.failed ) );
  8859. columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
  8860. .addRow( totals.testCases.failedButOk )
  8861. .addRow( totals.assertions.failedButOk ) );
  8862. printSummaryRow( "test cases", columns, 0 );
  8863. printSummaryRow( "assertions", columns, 1 );
  8864. }
  8865. }
  8866. void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
  8867. for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
  8868. std::string value = it->rows[row];
  8869. if( it->label.empty() ) {
  8870. stream << label << ": ";
  8871. if( value != "0" )
  8872. stream << value;
  8873. else
  8874. stream << Colour( Colour::Warning ) << "- none -";
  8875. }
  8876. else if( value != "0" ) {
  8877. stream << Colour( Colour::LightGrey ) << " | ";
  8878. stream << Colour( it->colour )
  8879. << value << ' ' << it->label;
  8880. }
  8881. }
  8882. stream << '\n';
  8883. }
  8884. static std::size_t makeRatio( std::size_t number, std::size_t total ) {
  8885. std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
  8886. return ( ratio == 0 && number > 0 ) ? 1 : ratio;
  8887. }
  8888. static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
  8889. if( i > j && i > k )
  8890. return i;
  8891. else if( j > k )
  8892. return j;
  8893. else
  8894. return k;
  8895. }
  8896. void printTotalsDivider( Totals const& totals ) {
  8897. if( totals.testCases.total() > 0 ) {
  8898. std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
  8899. std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
  8900. std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
  8901. while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
  8902. findMax( failedRatio, failedButOkRatio, passedRatio )++;
  8903. while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
  8904. findMax( failedRatio, failedButOkRatio, passedRatio )--;
  8905. stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
  8906. stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
  8907. if( totals.testCases.allPassed() )
  8908. stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
  8909. else
  8910. stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
  8911. }
  8912. else {
  8913. stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
  8914. }
  8915. stream << '\n';
  8916. }
  8917. void printSummaryDivider() {
  8918. stream << getLineOfChars<'-'>() << '\n';
  8919. }
  8920. private:
  8921. bool m_headerPrinted;
  8922. };
  8923. INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
  8924. } // end namespace Catch
  8925. // #included from: ../reporters/catch_reporter_compact.hpp
  8926. #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
  8927. namespace Catch {
  8928. struct CompactReporter : StreamingReporterBase {
  8929. CompactReporter( ReporterConfig const& _config )
  8930. : StreamingReporterBase( _config )
  8931. {}
  8932. virtual ~CompactReporter();
  8933. static std::string getDescription() {
  8934. return "Reports test results on a single line, suitable for IDEs";
  8935. }
  8936. virtual ReporterPreferences getPreferences() const {
  8937. ReporterPreferences prefs;
  8938. prefs.shouldRedirectStdOut = false;
  8939. return prefs;
  8940. }
  8941. virtual void noMatchingTestCases( std::string const& spec ) {
  8942. stream << "No test cases matched '" << spec << '\'' << std::endl;
  8943. }
  8944. virtual void assertionStarting( AssertionInfo const& ) {
  8945. }
  8946. virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
  8947. AssertionResult const& result = _assertionStats.assertionResult;
  8948. bool printInfoMessages = true;
  8949. // Drop out if result was successful and we're not printing those
  8950. if( !m_config->includeSuccessfulResults() && result.isOk() ) {
  8951. if( result.getResultType() != ResultWas::Warning )
  8952. return false;
  8953. printInfoMessages = false;
  8954. }
  8955. AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
  8956. printer.print();
  8957. stream << std::endl;
  8958. return true;
  8959. }
  8960. virtual void testRunEnded( TestRunStats const& _testRunStats ) {
  8961. printTotals( _testRunStats.totals );
  8962. stream << '\n' << std::endl;
  8963. StreamingReporterBase::testRunEnded( _testRunStats );
  8964. }
  8965. private:
  8966. class AssertionPrinter {
  8967. void operator= ( AssertionPrinter const& );
  8968. public:
  8969. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  8970. : stream( _stream )
  8971. , stats( _stats )
  8972. , result( _stats.assertionResult )
  8973. , messages( _stats.infoMessages )
  8974. , itMessage( _stats.infoMessages.begin() )
  8975. , printInfoMessages( _printInfoMessages )
  8976. {}
  8977. void print() {
  8978. printSourceInfo();
  8979. itMessage = messages.begin();
  8980. switch( result.getResultType() ) {
  8981. case ResultWas::Ok:
  8982. printResultType( Colour::ResultSuccess, passedString() );
  8983. printOriginalExpression();
  8984. printReconstructedExpression();
  8985. if ( ! result.hasExpression() )
  8986. printRemainingMessages( Colour::None );
  8987. else
  8988. printRemainingMessages();
  8989. break;
  8990. case ResultWas::ExpressionFailed:
  8991. if( result.isOk() )
  8992. printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
  8993. else
  8994. printResultType( Colour::Error, failedString() );
  8995. printOriginalExpression();
  8996. printReconstructedExpression();
  8997. printRemainingMessages();
  8998. break;
  8999. case ResultWas::ThrewException:
  9000. printResultType( Colour::Error, failedString() );
  9001. printIssue( "unexpected exception with message:" );
  9002. printMessage();
  9003. printExpressionWas();
  9004. printRemainingMessages();
  9005. break;
  9006. case ResultWas::FatalErrorCondition:
  9007. printResultType( Colour::Error, failedString() );
  9008. printIssue( "fatal error condition with message:" );
  9009. printMessage();
  9010. printExpressionWas();
  9011. printRemainingMessages();
  9012. break;
  9013. case ResultWas::DidntThrowException:
  9014. printResultType( Colour::Error, failedString() );
  9015. printIssue( "expected exception, got none" );
  9016. printExpressionWas();
  9017. printRemainingMessages();
  9018. break;
  9019. case ResultWas::Info:
  9020. printResultType( Colour::None, "info" );
  9021. printMessage();
  9022. printRemainingMessages();
  9023. break;
  9024. case ResultWas::Warning:
  9025. printResultType( Colour::None, "warning" );
  9026. printMessage();
  9027. printRemainingMessages();
  9028. break;
  9029. case ResultWas::ExplicitFailure:
  9030. printResultType( Colour::Error, failedString() );
  9031. printIssue( "explicitly" );
  9032. printRemainingMessages( Colour::None );
  9033. break;
  9034. // These cases are here to prevent compiler warnings
  9035. case ResultWas::Unknown:
  9036. case ResultWas::FailureBit:
  9037. case ResultWas::Exception:
  9038. printResultType( Colour::Error, "** internal error **" );
  9039. break;
  9040. }
  9041. }
  9042. private:
  9043. // Colour::LightGrey
  9044. static Colour::Code dimColour() { return Colour::FileName; }
  9045. #ifdef CATCH_PLATFORM_MAC
  9046. static const char* failedString() { return "FAILED"; }
  9047. static const char* passedString() { return "PASSED"; }
  9048. #else
  9049. static const char* failedString() { return "failed"; }
  9050. static const char* passedString() { return "passed"; }
  9051. #endif
  9052. void printSourceInfo() const {
  9053. Colour colourGuard( Colour::FileName );
  9054. stream << result.getSourceInfo() << ':';
  9055. }
  9056. void printResultType( Colour::Code colour, std::string passOrFail ) const {
  9057. if( !passOrFail.empty() ) {
  9058. {
  9059. Colour colourGuard( colour );
  9060. stream << ' ' << passOrFail;
  9061. }
  9062. stream << ':';
  9063. }
  9064. }
  9065. void printIssue( std::string issue ) const {
  9066. stream << ' ' << issue;
  9067. }
  9068. void printExpressionWas() {
  9069. if( result.hasExpression() ) {
  9070. stream << ';';
  9071. {
  9072. Colour colour( dimColour() );
  9073. stream << " expression was:";
  9074. }
  9075. printOriginalExpression();
  9076. }
  9077. }
  9078. void printOriginalExpression() const {
  9079. if( result.hasExpression() ) {
  9080. stream << ' ' << result.getExpression();
  9081. }
  9082. }
  9083. void printReconstructedExpression() const {
  9084. if( result.hasExpandedExpression() ) {
  9085. {
  9086. Colour colour( dimColour() );
  9087. stream << " for: ";
  9088. }
  9089. stream << result.getExpandedExpression();
  9090. }
  9091. }
  9092. void printMessage() {
  9093. if ( itMessage != messages.end() ) {
  9094. stream << " '" << itMessage->message << '\'';
  9095. ++itMessage;
  9096. }
  9097. }
  9098. void printRemainingMessages( Colour::Code colour = dimColour() ) {
  9099. if ( itMessage == messages.end() )
  9100. return;
  9101. // using messages.end() directly yields compilation error:
  9102. std::vector<MessageInfo>::const_iterator itEnd = messages.end();
  9103. const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
  9104. {
  9105. Colour colourGuard( colour );
  9106. stream << " with " << pluralise( N, "message" ) << ':';
  9107. }
  9108. for(; itMessage != itEnd; ) {
  9109. // If this assertion is a warning ignore any INFO messages
  9110. if( printInfoMessages || itMessage->type != ResultWas::Info ) {
  9111. stream << " '" << itMessage->message << '\'';
  9112. if ( ++itMessage != itEnd ) {
  9113. Colour colourGuard( dimColour() );
  9114. stream << " and";
  9115. }
  9116. }
  9117. }
  9118. }
  9119. private:
  9120. std::ostream& stream;
  9121. AssertionStats const& stats;
  9122. AssertionResult const& result;
  9123. std::vector<MessageInfo> messages;
  9124. std::vector<MessageInfo>::const_iterator itMessage;
  9125. bool printInfoMessages;
  9126. };
  9127. // Colour, message variants:
  9128. // - white: No tests ran.
  9129. // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
  9130. // - white: Passed [both/all] N test cases (no assertions).
  9131. // - red: Failed N tests cases, failed M assertions.
  9132. // - green: Passed [both/all] N tests cases with M assertions.
  9133. std::string bothOrAll( std::size_t count ) const {
  9134. return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
  9135. }
  9136. void printTotals( const Totals& totals ) const {
  9137. if( totals.testCases.total() == 0 ) {
  9138. stream << "No tests ran.";
  9139. }
  9140. else if( totals.testCases.failed == totals.testCases.total() ) {
  9141. Colour colour( Colour::ResultError );
  9142. const std::string qualify_assertions_failed =
  9143. totals.assertions.failed == totals.assertions.total() ?
  9144. bothOrAll( totals.assertions.failed ) : std::string();
  9145. stream <<
  9146. "Failed " << bothOrAll( totals.testCases.failed )
  9147. << pluralise( totals.testCases.failed, "test case" ) << ", "
  9148. "failed " << qualify_assertions_failed <<
  9149. pluralise( totals.assertions.failed, "assertion" ) << '.';
  9150. }
  9151. else if( totals.assertions.total() == 0 ) {
  9152. stream <<
  9153. "Passed " << bothOrAll( totals.testCases.total() )
  9154. << pluralise( totals.testCases.total(), "test case" )
  9155. << " (no assertions).";
  9156. }
  9157. else if( totals.assertions.failed ) {
  9158. Colour colour( Colour::ResultError );
  9159. stream <<
  9160. "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
  9161. "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
  9162. }
  9163. else {
  9164. Colour colour( Colour::ResultSuccess );
  9165. stream <<
  9166. "Passed " << bothOrAll( totals.testCases.passed )
  9167. << pluralise( totals.testCases.passed, "test case" ) <<
  9168. " with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
  9169. }
  9170. }
  9171. };
  9172. INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
  9173. } // end namespace Catch
  9174. namespace Catch {
  9175. // These are all here to avoid warnings about not having any out of line
  9176. // virtual methods
  9177. NonCopyable::~NonCopyable() {}
  9178. IShared::~IShared() {}
  9179. IStream::~IStream() CATCH_NOEXCEPT {}
  9180. FileStream::~FileStream() CATCH_NOEXCEPT {}
  9181. CoutStream::~CoutStream() CATCH_NOEXCEPT {}
  9182. DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
  9183. StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
  9184. IContext::~IContext() {}
  9185. IResultCapture::~IResultCapture() {}
  9186. ITestCase::~ITestCase() {}
  9187. ITestCaseRegistry::~ITestCaseRegistry() {}
  9188. IRegistryHub::~IRegistryHub() {}
  9189. IMutableRegistryHub::~IMutableRegistryHub() {}
  9190. IExceptionTranslator::~IExceptionTranslator() {}
  9191. IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
  9192. IReporter::~IReporter() {}
  9193. IReporterFactory::~IReporterFactory() {}
  9194. IReporterRegistry::~IReporterRegistry() {}
  9195. IStreamingReporter::~IStreamingReporter() {}
  9196. AssertionStats::~AssertionStats() {}
  9197. SectionStats::~SectionStats() {}
  9198. TestCaseStats::~TestCaseStats() {}
  9199. TestGroupStats::~TestGroupStats() {}
  9200. TestRunStats::~TestRunStats() {}
  9201. CumulativeReporterBase::SectionNode::~SectionNode() {}
  9202. CumulativeReporterBase::~CumulativeReporterBase() {}
  9203. StreamingReporterBase::~StreamingReporterBase() {}
  9204. ConsoleReporter::~ConsoleReporter() {}
  9205. CompactReporter::~CompactReporter() {}
  9206. IRunner::~IRunner() {}
  9207. IMutableContext::~IMutableContext() {}
  9208. IConfig::~IConfig() {}
  9209. XmlReporter::~XmlReporter() {}
  9210. JunitReporter::~JunitReporter() {}
  9211. TestRegistry::~TestRegistry() {}
  9212. FreeFunctionTestCase::~FreeFunctionTestCase() {}
  9213. IGeneratorInfo::~IGeneratorInfo() {}
  9214. IGeneratorsForTest::~IGeneratorsForTest() {}
  9215. WildcardPattern::~WildcardPattern() {}
  9216. TestSpec::Pattern::~Pattern() {}
  9217. TestSpec::NamePattern::~NamePattern() {}
  9218. TestSpec::TagPattern::~TagPattern() {}
  9219. TestSpec::ExcludedPattern::~ExcludedPattern() {}
  9220. void Config::dummy() {}
  9221. namespace TestCaseTracking {
  9222. ITracker::~ITracker() {}
  9223. TrackerBase::~TrackerBase() {}
  9224. SectionTracker::~SectionTracker() {}
  9225. IndexTracker::~IndexTracker() {}
  9226. }
  9227. }
  9228. #ifdef __clang__
  9229. #pragma clang diagnostic pop
  9230. #endif
  9231. #endif
  9232. #ifdef CATCH_CONFIG_MAIN
  9233. // #included from: internal/catch_default_main.hpp
  9234. #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
  9235. #ifndef __OBJC__
  9236. // Standard C/C++ main entry point
  9237. int main (int argc, char * argv[]) {
  9238. int result = Catch::Session().run( argc, argv );
  9239. return ( result < 0xff ? result : 0xff );
  9240. }
  9241. #else // __OBJC__
  9242. // Objective-C entry point
  9243. int main (int argc, char * const argv[]) {
  9244. #if !CATCH_ARC_ENABLED
  9245. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9246. #endif
  9247. Catch::registerTestMethods();
  9248. int result = Catch::Session().run( argc, (char* const*)argv );
  9249. #if !CATCH_ARC_ENABLED
  9250. [pool drain];
  9251. #endif
  9252. return ( result < 0xff ? result : 0xff );
  9253. }
  9254. #endif // __OBJC__
  9255. #endif
  9256. #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
  9257. # undef CLARA_CONFIG_MAIN
  9258. #endif
  9259. //////
  9260. // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
  9261. #ifdef CATCH_CONFIG_PREFIX_ALL
  9262. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" )
  9263. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" )
  9264. #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" )
  9265. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
  9266. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "CATCH_REQUIRE_THROWS_WITH" )
  9267. #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
  9268. #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
  9269. #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" )
  9270. #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" )
  9271. #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" )
  9272. #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" )
  9273. #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CATCH_CHECK_THROWS" )
  9274. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
  9275. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" )
  9276. #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
  9277. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
  9278. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" )
  9279. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
  9280. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg )
  9281. #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
  9282. #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
  9283. #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
  9284. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9285. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9286. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9287. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9288. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9289. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9290. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ )
  9291. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ )
  9292. #else
  9293. #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9294. #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9295. #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9296. #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
  9297. #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9298. #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg )
  9299. #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg )
  9300. #endif
  9301. #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9302. #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9303. #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9304. #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9305. // "BDD-style" convenience wrappers
  9306. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9307. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  9308. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9309. #else
  9310. #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
  9311. #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9312. #endif
  9313. #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
  9314. #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
  9315. #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9316. #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
  9317. #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9318. // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
  9319. #else
  9320. #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" )
  9321. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" )
  9322. #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" )
  9323. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
  9324. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "REQUIRE_THROWS_WITH" )
  9325. #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
  9326. #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
  9327. #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" )
  9328. #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" )
  9329. #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" )
  9330. #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" )
  9331. #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" )
  9332. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
  9333. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CHECK_THROWS_WITH" )
  9334. #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
  9335. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
  9336. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" )
  9337. #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
  9338. #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg )
  9339. #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
  9340. #define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
  9341. #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
  9342. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9343. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9344. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9345. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9346. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9347. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9348. #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ )
  9349. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ )
  9350. #else
  9351. #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9352. #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9353. #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9354. #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
  9355. #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9356. #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg )
  9357. #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg )
  9358. #endif
  9359. #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9360. #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9361. #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9362. #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9363. #endif
  9364. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  9365. // "BDD-style" convenience wrappers
  9366. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9367. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  9368. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9369. #else
  9370. #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
  9371. #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9372. #endif
  9373. #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
  9374. #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
  9375. #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
  9376. #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
  9377. #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
  9378. using Catch::Detail::Approx;
  9379. #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED