catch.hpp 412 KB

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