catch.hpp 329 KB

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