catch.hpp 370 KB

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