9
3

catch.hpp 416 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689
  1. /*
  2. * Catch v1.12.2
  3. * Generated: 2018-05-14 15:10:01.112442
  4. * ----------------------------------------------------------
  5. * This file has been merged from multiple headers. Please don't edit it directly
  6. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
  7. *
  8. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  9. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  10. */
  11. #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  12. #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  13. #define TWOBLUECUBES_CATCH_HPP_INCLUDED
  14. #ifdef __clang__
  15. # pragma clang system_header
  16. #elif defined __GNUC__
  17. # pragma GCC system_header
  18. #endif
  19. // #included from: internal/catch_suppress_warnings.h
  20. #ifdef __clang__
  21. # ifdef __ICC // icpc defines the __clang__ macro
  22. # pragma warning(push)
  23. # pragma warning(disable: 161 1682)
  24. # else // __ICC
  25. # pragma clang diagnostic ignored "-Wglobal-constructors"
  26. # pragma clang diagnostic ignored "-Wvariadic-macros"
  27. # pragma clang diagnostic ignored "-Wc99-extensions"
  28. # pragma clang diagnostic ignored "-Wunused-variable"
  29. # pragma clang diagnostic push
  30. # pragma clang diagnostic ignored "-Wpadded"
  31. # pragma clang diagnostic ignored "-Wc++98-compat"
  32. # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
  33. # pragma clang diagnostic ignored "-Wswitch-enum"
  34. # pragma clang diagnostic ignored "-Wcovered-switch-default"
  35. # endif
  36. #elif defined __GNUC__
  37. # pragma GCC diagnostic ignored "-Wvariadic-macros"
  38. # pragma GCC diagnostic ignored "-Wunused-variable"
  39. # pragma GCC diagnostic ignored "-Wparentheses"
  40. # pragma GCC diagnostic push
  41. # pragma GCC diagnostic ignored "-Wpadded"
  42. #endif
  43. #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
  44. # define CATCH_IMPL
  45. #endif
  46. #ifdef CATCH_IMPL
  47. # ifndef CLARA_CONFIG_MAIN
  48. # define CLARA_CONFIG_MAIN_NOT_DEFINED
  49. # define CLARA_CONFIG_MAIN
  50. # endif
  51. #endif
  52. // #included from: internal/catch_notimplemented_exception.h
  53. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
  54. // #included from: catch_common.h
  55. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  56. // #included from: catch_compiler_capabilities.h
  57. #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
  58. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  59. // The following features are defined:
  60. //
  61. // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
  62. // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  63. // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  64. // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
  65. // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
  66. // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
  67. // CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
  68. // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  69. // CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
  70. // CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
  71. // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  72. // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  73. // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
  74. // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
  75. // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
  76. // ****************
  77. // Note to maintainers: if new toggles are added please document them
  78. // in configuration.md, too
  79. // ****************
  80. // In general each macro has a _NO_<feature name> form
  81. // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  82. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  83. // can be combined, en-mass, with the _NO_ forms later.
  84. // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
  85. #ifdef __cplusplus
  86. # if __cplusplus >= 201103L
  87. # define CATCH_CPP11_OR_GREATER
  88. # endif
  89. # if __cplusplus >= 201402L
  90. # define CATCH_CPP14_OR_GREATER
  91. # endif
  92. #endif
  93. #ifdef __clang__
  94. # if __has_feature(cxx_nullptr)
  95. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  96. # endif
  97. # if __has_feature(cxx_noexcept)
  98. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  99. # endif
  100. # if defined(CATCH_CPP11_OR_GREATER)
  101. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  102. _Pragma( "clang diagnostic push" ) \
  103. _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" )
  104. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  105. _Pragma( "clang diagnostic pop" )
  106. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  107. _Pragma( "clang diagnostic push" ) \
  108. _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
  109. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  110. _Pragma( "clang diagnostic pop" )
  111. # endif
  112. #endif // __clang__
  113. ////////////////////////////////////////////////////////////////////////////////
  114. // We know some environments not to support full POSIX signals
  115. #if defined(__CYGWIN__) || defined(__QNX__)
  116. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  117. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  118. # endif
  119. #endif
  120. #ifdef __OS400__
  121. # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
  122. # define CATCH_CONFIG_COLOUR_NONE
  123. #endif
  124. ////////////////////////////////////////////////////////////////////////////////
  125. // Cygwin
  126. #ifdef __CYGWIN__
  127. // Required for some versions of Cygwin to declare gettimeofday
  128. // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
  129. # define _BSD_SOURCE
  130. #endif // __CYGWIN__
  131. ////////////////////////////////////////////////////////////////////////////////
  132. // Borland
  133. #ifdef __BORLANDC__
  134. #endif // __BORLANDC__
  135. ////////////////////////////////////////////////////////////////////////////////
  136. // EDG
  137. #ifdef __EDG_VERSION__
  138. #endif // __EDG_VERSION__
  139. ////////////////////////////////////////////////////////////////////////////////
  140. // Digital Mars
  141. #ifdef __DMC__
  142. #endif // __DMC__
  143. ////////////////////////////////////////////////////////////////////////////////
  144. // GCC
  145. #ifdef __GNUC__
  146. # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  147. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  148. # endif
  149. // - otherwise more recent versions define __cplusplus >= 201103L
  150. // and will get picked up below
  151. #endif // __GNUC__
  152. ////////////////////////////////////////////////////////////////////////////////
  153. // Visual C++
  154. #ifdef _MSC_VER
  155. #define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
  156. #if (_MSC_VER >= 1600)
  157. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  158. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  159. #endif
  160. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  161. #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  162. #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  163. #define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  164. #define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  165. #endif
  166. #endif // _MSC_VER
  167. ////////////////////////////////////////////////////////////////////////////////
  168. // Use variadic macros if the compiler supports them
  169. #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
  170. ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
  171. ( defined __GNUC__ && __GNUC__ >= 3 ) || \
  172. ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
  173. #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  174. #endif
  175. // Use __COUNTER__ if the compiler supports it
  176. #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
  177. ( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \
  178. ( defined __clang__ && __clang_major__ >= 3 )
  179. // Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former,
  180. // because __COUNTER__ is not properly handled by it.
  181. // This does not affect compilation
  182. #if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L )
  183. #define CATCH_INTERNAL_CONFIG_COUNTER
  184. #endif
  185. #endif
  186. ////////////////////////////////////////////////////////////////////////////////
  187. // C++ language feature support
  188. // catch all support for C++11
  189. #if defined(CATCH_CPP11_OR_GREATER)
  190. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
  191. # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
  192. # endif
  193. # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  194. # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
  195. # endif
  196. # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  197. # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  198. # endif
  199. # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  200. # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
  201. # endif
  202. # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  203. # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
  204. # endif
  205. # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  206. # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
  207. # endif
  208. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
  209. # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
  210. # endif
  211. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
  212. # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
  213. # endif
  214. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  215. # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  216. # endif
  217. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
  218. # define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
  219. # endif
  220. # if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
  221. # define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
  222. # endif
  223. #endif // __cplusplus >= 201103L
  224. // Now set the actual defines based on the above + anything the user has configured
  225. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
  226. # define CATCH_CONFIG_CPP11_NULLPTR
  227. #endif
  228. #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
  229. # define CATCH_CONFIG_CPP11_NOEXCEPT
  230. #endif
  231. #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)
  232. # define CATCH_CONFIG_CPP11_GENERATED_METHODS
  233. #endif
  234. #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)
  235. # define CATCH_CONFIG_CPP11_IS_ENUM
  236. #endif
  237. #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
  238. # define CATCH_CONFIG_CPP11_TUPLE
  239. #endif
  240. #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
  241. # define CATCH_CONFIG_VARIADIC_MACROS
  242. #endif
  243. #if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11)
  244. # define CATCH_CONFIG_CPP11_LONG_LONG
  245. #endif
  246. #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
  247. # define CATCH_CONFIG_CPP11_OVERRIDE
  248. #endif
  249. #if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11)
  250. # define CATCH_CONFIG_CPP11_UNIQUE_PTR
  251. #endif
  252. #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
  253. # define CATCH_CONFIG_COUNTER
  254. #endif
  255. #if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
  256. # define CATCH_CONFIG_CPP11_SHUFFLE
  257. #endif
  258. # if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11)
  259. # define CATCH_CONFIG_CPP11_TYPE_TRAITS
  260. # endif
  261. #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
  262. # define CATCH_CONFIG_WINDOWS_SEH
  263. #endif
  264. // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
  265. #if !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
  266. # define CATCH_CONFIG_POSIX_SIGNALS
  267. #endif
  268. #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
  269. # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
  270. # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
  271. #endif
  272. #if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
  273. # define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  274. # define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  275. #endif
  276. // noexcept support:
  277. #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
  278. # define CATCH_NOEXCEPT noexcept
  279. # define CATCH_NOEXCEPT_IS(x) noexcept(x)
  280. #else
  281. # define CATCH_NOEXCEPT throw()
  282. # define CATCH_NOEXCEPT_IS(x)
  283. #endif
  284. // nullptr support
  285. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  286. # define CATCH_NULL nullptr
  287. #else
  288. # define CATCH_NULL NULL
  289. #endif
  290. // override support
  291. #ifdef CATCH_CONFIG_CPP11_OVERRIDE
  292. # define CATCH_OVERRIDE override
  293. #else
  294. # define CATCH_OVERRIDE
  295. #endif
  296. // unique_ptr support
  297. #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
  298. # define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
  299. #else
  300. # define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
  301. #endif
  302. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  303. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  304. #ifdef CATCH_CONFIG_COUNTER
  305. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
  306. #else
  307. # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  308. #endif
  309. #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
  310. #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
  311. #include <sstream>
  312. #include <algorithm>
  313. namespace Catch {
  314. struct IConfig;
  315. struct CaseSensitive { enum Choice {
  316. Yes,
  317. No
  318. }; };
  319. class NonCopyable {
  320. #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  321. NonCopyable( NonCopyable const& ) = delete;
  322. NonCopyable( NonCopyable && ) = delete;
  323. NonCopyable& operator = ( NonCopyable const& ) = delete;
  324. NonCopyable& operator = ( NonCopyable && ) = delete;
  325. #else
  326. NonCopyable( NonCopyable const& info );
  327. NonCopyable& operator = ( NonCopyable const& );
  328. #endif
  329. protected:
  330. NonCopyable() {}
  331. virtual ~NonCopyable();
  332. };
  333. class SafeBool {
  334. public:
  335. typedef void (SafeBool::*type)() const;
  336. static type makeSafe( bool value ) {
  337. return value ? &SafeBool::trueValue : 0;
  338. }
  339. private:
  340. void trueValue() const {}
  341. };
  342. template<typename ContainerT>
  343. void deleteAll( ContainerT& container ) {
  344. typename ContainerT::const_iterator it = container.begin();
  345. typename ContainerT::const_iterator itEnd = container.end();
  346. for(; it != itEnd; ++it )
  347. delete *it;
  348. }
  349. template<typename AssociativeContainerT>
  350. void deleteAllValues( AssociativeContainerT& container ) {
  351. typename AssociativeContainerT::const_iterator it = container.begin();
  352. typename AssociativeContainerT::const_iterator itEnd = container.end();
  353. for(; it != itEnd; ++it )
  354. delete it->second;
  355. }
  356. bool startsWith( std::string const& s, std::string const& prefix );
  357. bool startsWith( std::string const& s, char prefix );
  358. bool endsWith( std::string const& s, std::string const& suffix );
  359. bool endsWith( std::string const& s, char suffix );
  360. bool contains( std::string const& s, std::string const& infix );
  361. void toLowerInPlace( std::string& s );
  362. std::string toLower( std::string const& s );
  363. std::string trim( std::string const& str );
  364. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
  365. struct pluralise {
  366. pluralise( std::size_t count, std::string const& label );
  367. friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
  368. std::size_t m_count;
  369. std::string m_label;
  370. };
  371. struct SourceLineInfo {
  372. SourceLineInfo();
  373. SourceLineInfo( char const* _file, std::size_t _line );
  374. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  375. SourceLineInfo(SourceLineInfo const& other) = default;
  376. SourceLineInfo( SourceLineInfo && ) = default;
  377. SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
  378. SourceLineInfo& operator = ( SourceLineInfo && ) = default;
  379. # endif
  380. bool empty() const;
  381. bool operator == ( SourceLineInfo const& other ) const;
  382. bool operator < ( SourceLineInfo const& other ) const;
  383. char const* file;
  384. std::size_t line;
  385. };
  386. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
  387. // This is just here to avoid compiler warnings with macro constants and boolean literals
  388. inline bool isTrue( bool value ){ return value; }
  389. inline bool alwaysTrue() { return true; }
  390. inline bool alwaysFalse() { return false; }
  391. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
  392. void seedRng( IConfig const& config );
  393. unsigned int rngSeed();
  394. // Use this in variadic streaming macros to allow
  395. // >> +StreamEndStop
  396. // as well as
  397. // >> stuff +StreamEndStop
  398. struct StreamEndStop {
  399. std::string operator+() {
  400. return std::string();
  401. }
  402. };
  403. template<typename T>
  404. T const& operator + ( T const& value, StreamEndStop ) {
  405. return value;
  406. }
  407. }
  408. #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  409. #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
  410. namespace Catch {
  411. class NotImplementedException : public std::exception
  412. {
  413. public:
  414. NotImplementedException( SourceLineInfo const& lineInfo );
  415. virtual ~NotImplementedException() CATCH_NOEXCEPT {}
  416. virtual const char* what() const CATCH_NOEXCEPT;
  417. private:
  418. std::string m_what;
  419. SourceLineInfo m_lineInfo;
  420. };
  421. } // end namespace Catch
  422. ///////////////////////////////////////////////////////////////////////////////
  423. #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
  424. // #included from: internal/catch_context.h
  425. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  426. // #included from: catch_interfaces_generators.h
  427. #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
  428. #include <string>
  429. namespace Catch {
  430. struct IGeneratorInfo {
  431. virtual ~IGeneratorInfo();
  432. virtual bool moveNext() = 0;
  433. virtual std::size_t getCurrentIndex() const = 0;
  434. };
  435. struct IGeneratorsForTest {
  436. virtual ~IGeneratorsForTest();
  437. virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
  438. virtual bool moveNext() = 0;
  439. };
  440. IGeneratorsForTest* createGeneratorsForTest();
  441. } // end namespace Catch
  442. // #included from: catch_ptr.hpp
  443. #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
  444. #ifdef __clang__
  445. #pragma clang diagnostic push
  446. #pragma clang diagnostic ignored "-Wpadded"
  447. #endif
  448. namespace Catch {
  449. // An intrusive reference counting smart pointer.
  450. // T must implement addRef() and release() methods
  451. // typically implementing the IShared interface
  452. template<typename T>
  453. class Ptr {
  454. public:
  455. Ptr() : m_p( CATCH_NULL ){}
  456. Ptr( T* p ) : m_p( p ){
  457. if( m_p )
  458. m_p->addRef();
  459. }
  460. Ptr( Ptr const& other ) : m_p( other.m_p ){
  461. if( m_p )
  462. m_p->addRef();
  463. }
  464. ~Ptr(){
  465. if( m_p )
  466. m_p->release();
  467. }
  468. void reset() {
  469. if( m_p )
  470. m_p->release();
  471. m_p = CATCH_NULL;
  472. }
  473. Ptr& operator = ( T* p ){
  474. Ptr temp( p );
  475. swap( temp );
  476. return *this;
  477. }
  478. Ptr& operator = ( Ptr const& other ){
  479. Ptr temp( other );
  480. swap( temp );
  481. return *this;
  482. }
  483. void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
  484. T* get() const{ return m_p; }
  485. T& operator*() const { return *m_p; }
  486. T* operator->() const { return m_p; }
  487. bool operator !() const { return m_p == CATCH_NULL; }
  488. operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
  489. private:
  490. T* m_p;
  491. };
  492. struct IShared : NonCopyable {
  493. virtual ~IShared();
  494. virtual void addRef() const = 0;
  495. virtual void release() const = 0;
  496. };
  497. template<typename T = IShared>
  498. struct SharedImpl : T {
  499. SharedImpl() : m_rc( 0 ){}
  500. virtual void addRef() const {
  501. ++m_rc;
  502. }
  503. virtual void release() const {
  504. if( --m_rc == 0 )
  505. delete this;
  506. }
  507. mutable unsigned int m_rc;
  508. };
  509. } // end namespace Catch
  510. #ifdef __clang__
  511. #pragma clang diagnostic pop
  512. #endif
  513. namespace Catch {
  514. class TestCase;
  515. class Stream;
  516. struct IResultCapture;
  517. struct IRunner;
  518. struct IGeneratorsForTest;
  519. struct IConfig;
  520. struct IContext
  521. {
  522. virtual ~IContext();
  523. virtual IResultCapture* getResultCapture() = 0;
  524. virtual IRunner* getRunner() = 0;
  525. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
  526. virtual bool advanceGeneratorsForCurrentTest() = 0;
  527. virtual Ptr<IConfig const> getConfig() const = 0;
  528. };
  529. struct IMutableContext : IContext
  530. {
  531. virtual ~IMutableContext();
  532. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  533. virtual void setRunner( IRunner* runner ) = 0;
  534. virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
  535. };
  536. IContext& getCurrentContext();
  537. IMutableContext& getCurrentMutableContext();
  538. void cleanUpContext();
  539. Stream createStream( std::string const& streamName );
  540. }
  541. // #included from: internal/catch_test_registry.hpp
  542. #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
  543. // #included from: catch_interfaces_testcase.h
  544. #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
  545. #include <vector>
  546. namespace Catch {
  547. class TestSpec;
  548. struct ITestCase : IShared {
  549. virtual void invoke () const = 0;
  550. protected:
  551. virtual ~ITestCase();
  552. };
  553. class TestCase;
  554. struct IConfig;
  555. struct ITestCaseRegistry {
  556. virtual ~ITestCaseRegistry();
  557. virtual std::vector<TestCase> const& getAllTests() const = 0;
  558. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
  559. };
  560. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
  561. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
  562. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
  563. }
  564. namespace Catch {
  565. template<typename C>
  566. class MethodTestCase : public SharedImpl<ITestCase> {
  567. public:
  568. MethodTestCase( void (C::*method)() ) : m_method( method ) {}
  569. virtual void invoke() const {
  570. C obj;
  571. (obj.*m_method)();
  572. }
  573. private:
  574. virtual ~MethodTestCase() {}
  575. void (C::*m_method)();
  576. };
  577. typedef void(*TestFunction)();
  578. struct NameAndDesc {
  579. NameAndDesc( const char* _name = "", const char* _description= "" )
  580. : name( _name ), description( _description )
  581. {}
  582. const char* name;
  583. const char* description;
  584. };
  585. void registerTestCase
  586. ( ITestCase* testCase,
  587. char const* className,
  588. NameAndDesc const& nameAndDesc,
  589. SourceLineInfo const& lineInfo );
  590. struct AutoReg {
  591. AutoReg
  592. ( TestFunction function,
  593. SourceLineInfo const& lineInfo,
  594. NameAndDesc const& nameAndDesc );
  595. template<typename C>
  596. AutoReg
  597. ( void (C::*method)(),
  598. char const* className,
  599. NameAndDesc const& nameAndDesc,
  600. SourceLineInfo const& lineInfo ) {
  601. registerTestCase
  602. ( new MethodTestCase<C>( method ),
  603. className,
  604. nameAndDesc,
  605. lineInfo );
  606. }
  607. ~AutoReg();
  608. private:
  609. AutoReg( AutoReg const& );
  610. void operator= ( AutoReg const& );
  611. };
  612. void registerTestCaseFunction
  613. ( TestFunction function,
  614. SourceLineInfo const& lineInfo,
  615. NameAndDesc const& nameAndDesc );
  616. } // end namespace Catch
  617. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  618. ///////////////////////////////////////////////////////////////////////////////
  619. #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
  620. static void TestName(); \
  621. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  622. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); } /* NOLINT */ \
  623. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  624. static void TestName()
  625. #define INTERNAL_CATCH_TESTCASE( ... ) \
  626. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
  627. ///////////////////////////////////////////////////////////////////////////////
  628. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
  629. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  630. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  631. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  632. ///////////////////////////////////////////////////////////////////////////////
  633. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
  634. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  635. namespace{ \
  636. struct TestName : ClassName{ \
  637. void test(); \
  638. }; \
  639. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  640. } \
  641. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  642. void TestName::test()
  643. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
  644. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
  645. ///////////////////////////////////////////////////////////////////////////////
  646. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
  647. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  648. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); /* NOLINT */ \
  649. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  650. #else
  651. ///////////////////////////////////////////////////////////////////////////////
  652. #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
  653. static void TestName(); \
  654. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  655. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); } /* NOLINT */ \
  656. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  657. static void TestName()
  658. #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
  659. INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
  660. ///////////////////////////////////////////////////////////////////////////////
  661. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
  662. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  663. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } /* NOLINT */ \
  664. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  665. ///////////////////////////////////////////////////////////////////////////////
  666. #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
  667. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  668. namespace{ \
  669. struct TestCaseName : ClassName{ \
  670. void test(); \
  671. }; \
  672. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); /* NOLINT */ \
  673. } \
  674. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
  675. void TestCaseName::test()
  676. #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
  677. INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
  678. ///////////////////////////////////////////////////////////////////////////////
  679. #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
  680. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
  681. Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); /* NOLINT */ \
  682. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  683. #endif
  684. // #included from: internal/catch_capture.hpp
  685. #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
  686. // #included from: catch_result_builder.h
  687. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
  688. // #included from: catch_result_type.h
  689. #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
  690. namespace Catch {
  691. // ResultWas::OfType enum
  692. struct ResultWas { enum OfType {
  693. Unknown = -1,
  694. Ok = 0,
  695. Info = 1,
  696. Warning = 2,
  697. FailureBit = 0x10,
  698. ExpressionFailed = FailureBit | 1,
  699. ExplicitFailure = FailureBit | 2,
  700. Exception = 0x100 | FailureBit,
  701. ThrewException = Exception | 1,
  702. DidntThrowException = Exception | 2,
  703. FatalErrorCondition = 0x200 | FailureBit
  704. }; };
  705. inline bool isOk( ResultWas::OfType resultType ) {
  706. return ( resultType & ResultWas::FailureBit ) == 0;
  707. }
  708. inline bool isJustInfo( int flags ) {
  709. return flags == ResultWas::Info;
  710. }
  711. // ResultDisposition::Flags enum
  712. struct ResultDisposition { enum Flags {
  713. Normal = 0x01,
  714. ContinueOnFailure = 0x02, // Failures fail test, but execution continues
  715. FalseTest = 0x04, // Prefix expression with !
  716. SuppressFail = 0x08 // Failures are reported but do not fail the test
  717. }; };
  718. inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
  719. return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
  720. }
  721. inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
  722. inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
  723. inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
  724. } // end namespace Catch
  725. // #included from: catch_assertionresult.h
  726. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
  727. #include <string>
  728. namespace Catch {
  729. struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
  730. struct DecomposedExpression
  731. {
  732. virtual ~DecomposedExpression() {}
  733. virtual bool isBinaryExpression() const {
  734. return false;
  735. }
  736. virtual void reconstructExpression( std::string& dest ) const = 0;
  737. // Only simple binary comparisons can be decomposed.
  738. // If more complex check is required then wrap sub-expressions in parentheses.
  739. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& );
  740. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& );
  741. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& );
  742. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& );
  743. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& );
  744. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& );
  745. template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& );
  746. private:
  747. DecomposedExpression& operator = (DecomposedExpression const&);
  748. };
  749. struct AssertionInfo
  750. {
  751. AssertionInfo();
  752. AssertionInfo( char const * _macroName,
  753. SourceLineInfo const& _lineInfo,
  754. char const * _capturedExpression,
  755. ResultDisposition::Flags _resultDisposition,
  756. char const * _secondArg = "");
  757. char const * macroName;
  758. SourceLineInfo lineInfo;
  759. char const * capturedExpression;
  760. ResultDisposition::Flags resultDisposition;
  761. char const * secondArg;
  762. };
  763. struct AssertionResultData
  764. {
  765. AssertionResultData() : decomposedExpression( CATCH_NULL )
  766. , resultType( ResultWas::Unknown )
  767. , negated( false )
  768. , parenthesized( false ) {}
  769. void negate( bool parenthesize ) {
  770. negated = !negated;
  771. parenthesized = parenthesize;
  772. if( resultType == ResultWas::Ok )
  773. resultType = ResultWas::ExpressionFailed;
  774. else if( resultType == ResultWas::ExpressionFailed )
  775. resultType = ResultWas::Ok;
  776. }
  777. std::string const& reconstructExpression() const {
  778. if( decomposedExpression != CATCH_NULL ) {
  779. decomposedExpression->reconstructExpression( reconstructedExpression );
  780. if( parenthesized ) {
  781. reconstructedExpression.insert( 0, 1, '(' );
  782. reconstructedExpression.append( 1, ')' );
  783. }
  784. if( negated ) {
  785. reconstructedExpression.insert( 0, 1, '!' );
  786. }
  787. decomposedExpression = CATCH_NULL;
  788. }
  789. return reconstructedExpression;
  790. }
  791. mutable DecomposedExpression const* decomposedExpression;
  792. mutable std::string reconstructedExpression;
  793. std::string message;
  794. ResultWas::OfType resultType;
  795. bool negated;
  796. bool parenthesized;
  797. };
  798. class AssertionResult {
  799. public:
  800. AssertionResult();
  801. AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
  802. ~AssertionResult();
  803. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  804. AssertionResult( AssertionResult const& ) = default;
  805. AssertionResult( AssertionResult && ) = default;
  806. AssertionResult& operator = ( AssertionResult const& ) = default;
  807. AssertionResult& operator = ( AssertionResult && ) = default;
  808. # endif
  809. bool isOk() const;
  810. bool succeeded() const;
  811. ResultWas::OfType getResultType() const;
  812. bool hasExpression() const;
  813. bool hasMessage() const;
  814. std::string getExpression() const;
  815. std::string getExpressionInMacro() const;
  816. bool hasExpandedExpression() const;
  817. std::string getExpandedExpression() const;
  818. std::string getMessage() const;
  819. SourceLineInfo getSourceInfo() const;
  820. std::string getTestMacroName() const;
  821. void discardDecomposedExpression() const;
  822. void expandDecomposedExpression() const;
  823. protected:
  824. AssertionInfo m_info;
  825. AssertionResultData m_resultData;
  826. };
  827. } // end namespace Catch
  828. // #included from: catch_matchers.hpp
  829. #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
  830. namespace Catch {
  831. namespace Matchers {
  832. namespace Impl {
  833. template<typename ArgT> struct MatchAllOf;
  834. template<typename ArgT> struct MatchAnyOf;
  835. template<typename ArgT> struct MatchNotOf;
  836. class MatcherUntypedBase {
  837. public:
  838. std::string toString() const {
  839. if( m_cachedToString.empty() )
  840. m_cachedToString = describe();
  841. return m_cachedToString;
  842. }
  843. protected:
  844. virtual ~MatcherUntypedBase();
  845. virtual std::string describe() const = 0;
  846. mutable std::string m_cachedToString;
  847. private:
  848. MatcherUntypedBase& operator = ( MatcherUntypedBase const& );
  849. };
  850. template<typename ObjectT>
  851. struct MatcherMethod {
  852. virtual bool match( ObjectT const& arg ) const = 0;
  853. };
  854. template<typename PtrT>
  855. struct MatcherMethod<PtrT*> {
  856. virtual bool match( PtrT* arg ) const = 0;
  857. };
  858. template<typename ObjectT, typename ComparatorT = ObjectT>
  859. struct MatcherBase : MatcherUntypedBase, MatcherMethod<ObjectT> {
  860. MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
  861. MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
  862. MatchNotOf<ComparatorT> operator ! () const;
  863. };
  864. template<typename ArgT>
  865. struct MatchAllOf : MatcherBase<ArgT> {
  866. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  867. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  868. if (!m_matchers[i]->match(arg))
  869. return false;
  870. }
  871. return true;
  872. }
  873. virtual std::string describe() const CATCH_OVERRIDE {
  874. std::string description;
  875. description.reserve( 4 + m_matchers.size()*32 );
  876. description += "( ";
  877. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  878. if( i != 0 )
  879. description += " and ";
  880. description += m_matchers[i]->toString();
  881. }
  882. description += " )";
  883. return description;
  884. }
  885. MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
  886. m_matchers.push_back( &other );
  887. return *this;
  888. }
  889. std::vector<MatcherBase<ArgT> const*> m_matchers;
  890. };
  891. template<typename ArgT>
  892. struct MatchAnyOf : MatcherBase<ArgT> {
  893. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  894. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  895. if (m_matchers[i]->match(arg))
  896. return true;
  897. }
  898. return false;
  899. }
  900. virtual std::string describe() const CATCH_OVERRIDE {
  901. std::string description;
  902. description.reserve( 4 + m_matchers.size()*32 );
  903. description += "( ";
  904. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  905. if( i != 0 )
  906. description += " or ";
  907. description += m_matchers[i]->toString();
  908. }
  909. description += " )";
  910. return description;
  911. }
  912. MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
  913. m_matchers.push_back( &other );
  914. return *this;
  915. }
  916. std::vector<MatcherBase<ArgT> const*> m_matchers;
  917. };
  918. template<typename ArgT>
  919. struct MatchNotOf : MatcherBase<ArgT> {
  920. MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
  921. virtual bool match( ArgT const& arg ) const CATCH_OVERRIDE {
  922. return !m_underlyingMatcher.match( arg );
  923. }
  924. virtual std::string describe() const CATCH_OVERRIDE {
  925. return "not " + m_underlyingMatcher.toString();
  926. }
  927. MatcherBase<ArgT> const& m_underlyingMatcher;
  928. };
  929. template<typename ObjectT, typename ComparatorT>
  930. MatchAllOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator && ( MatcherBase const& other ) const {
  931. return MatchAllOf<ComparatorT>() && *this && other;
  932. }
  933. template<typename ObjectT, typename ComparatorT>
  934. MatchAnyOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator || ( MatcherBase const& other ) const {
  935. return MatchAnyOf<ComparatorT>() || *this || other;
  936. }
  937. template<typename ObjectT, typename ComparatorT>
  938. MatchNotOf<ComparatorT> MatcherBase<ObjectT, ComparatorT>::operator ! () const {
  939. return MatchNotOf<ComparatorT>( *this );
  940. }
  941. } // namespace Impl
  942. // The following functions create the actual matcher objects.
  943. // This allows the types to be inferred
  944. // - deprecated: prefer ||, && and !
  945. template<typename T>
  946. Impl::MatchNotOf<T> Not( Impl::MatcherBase<T> const& underlyingMatcher ) {
  947. return Impl::MatchNotOf<T>( underlyingMatcher );
  948. }
  949. template<typename T>
  950. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  951. return Impl::MatchAllOf<T>() && m1 && m2;
  952. }
  953. template<typename T>
  954. Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  955. return Impl::MatchAllOf<T>() && m1 && m2 && m3;
  956. }
  957. template<typename T>
  958. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) {
  959. return Impl::MatchAnyOf<T>() || m1 || m2;
  960. }
  961. template<typename T>
  962. Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) {
  963. return Impl::MatchAnyOf<T>() || m1 || m2 || m3;
  964. }
  965. } // namespace Matchers
  966. using namespace Matchers;
  967. using Matchers::Impl::MatcherBase;
  968. } // namespace Catch
  969. namespace Catch {
  970. struct TestFailureException{};
  971. template<typename T> class ExpressionLhs;
  972. struct CopyableStream {
  973. CopyableStream() {}
  974. CopyableStream( CopyableStream const& other ) {
  975. oss << other.oss.str();
  976. }
  977. CopyableStream& operator=( CopyableStream const& other ) {
  978. oss.str(std::string());
  979. oss << other.oss.str();
  980. return *this;
  981. }
  982. std::ostringstream oss;
  983. };
  984. class ResultBuilder : public DecomposedExpression {
  985. public:
  986. ResultBuilder( char const* macroName,
  987. SourceLineInfo const& lineInfo,
  988. char const* capturedExpression,
  989. ResultDisposition::Flags resultDisposition,
  990. char const* secondArg = "" );
  991. ~ResultBuilder();
  992. template<typename T>
  993. ExpressionLhs<T const&> operator <= ( T const& operand );
  994. ExpressionLhs<bool> operator <= ( bool value );
  995. template<typename T>
  996. ResultBuilder& operator << ( T const& value ) {
  997. stream().oss << value;
  998. return *this;
  999. }
  1000. ResultBuilder& setResultType( ResultWas::OfType result );
  1001. ResultBuilder& setResultType( bool result );
  1002. void endExpression( DecomposedExpression const& expr );
  1003. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE;
  1004. AssertionResult build() const;
  1005. AssertionResult build( DecomposedExpression const& expr ) const;
  1006. void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
  1007. void captureResult( ResultWas::OfType resultType );
  1008. void captureExpression();
  1009. void captureExpectedException( std::string const& expectedMessage );
  1010. void captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher );
  1011. void handleResult( AssertionResult const& result );
  1012. void react();
  1013. bool shouldDebugBreak() const;
  1014. bool allowThrows() const;
  1015. template<typename ArgT, typename MatcherT>
  1016. void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
  1017. void setExceptionGuard();
  1018. void unsetExceptionGuard();
  1019. private:
  1020. AssertionInfo m_assertionInfo;
  1021. AssertionResultData m_data;
  1022. CopyableStream &stream()
  1023. {
  1024. if(!m_usedStream)
  1025. {
  1026. m_usedStream = true;
  1027. m_stream().oss.str("");
  1028. }
  1029. return m_stream();
  1030. }
  1031. static CopyableStream &m_stream()
  1032. {
  1033. static CopyableStream s;
  1034. return s;
  1035. }
  1036. bool m_shouldDebugBreak;
  1037. bool m_shouldThrow;
  1038. bool m_guardException;
  1039. bool m_usedStream;
  1040. };
  1041. } // namespace Catch
  1042. // Include after due to circular dependency:
  1043. // #included from: catch_expression_lhs.hpp
  1044. #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
  1045. // #included from: catch_evaluate.hpp
  1046. #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
  1047. #ifdef _MSC_VER
  1048. #pragma warning(push)
  1049. #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
  1050. #pragma warning(disable:4018) // more "signed/unsigned mismatch"
  1051. #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
  1052. #endif
  1053. #include <cstddef>
  1054. namespace Catch {
  1055. namespace Internal {
  1056. enum Operator {
  1057. IsEqualTo,
  1058. IsNotEqualTo,
  1059. IsLessThan,
  1060. IsGreaterThan,
  1061. IsLessThanOrEqualTo,
  1062. IsGreaterThanOrEqualTo
  1063. };
  1064. template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
  1065. template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
  1066. template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
  1067. template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
  1068. template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
  1069. template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
  1070. template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
  1071. template<typename T>
  1072. T& opCast(T const& t) { return const_cast<T&>(t); }
  1073. // nullptr_t support based on pull request #154 from Konstantin Baumann
  1074. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1075. inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
  1076. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1077. // So the compare overloads can be operator agnostic we convey the operator as a template
  1078. // enum, which is used to specialise an Evaluator for doing the comparison.
  1079. template<typename T1, typename T2, Operator Op>
  1080. struct Evaluator{};
  1081. template<typename T1, typename T2>
  1082. struct Evaluator<T1, T2, IsEqualTo> {
  1083. static bool evaluate( T1 const& lhs, T2 const& rhs) {
  1084. return bool( opCast( lhs ) == opCast( rhs ) );
  1085. }
  1086. };
  1087. template<typename T1, typename T2>
  1088. struct Evaluator<T1, T2, IsNotEqualTo> {
  1089. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1090. return bool( opCast( lhs ) != opCast( rhs ) );
  1091. }
  1092. };
  1093. template<typename T1, typename T2>
  1094. struct Evaluator<T1, T2, IsLessThan> {
  1095. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1096. return bool( opCast( lhs ) < opCast( rhs ) );
  1097. }
  1098. };
  1099. template<typename T1, typename T2>
  1100. struct Evaluator<T1, T2, IsGreaterThan> {
  1101. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1102. return bool( opCast( lhs ) > opCast( rhs ) );
  1103. }
  1104. };
  1105. template<typename T1, typename T2>
  1106. struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
  1107. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1108. return bool( opCast( lhs ) >= opCast( rhs ) );
  1109. }
  1110. };
  1111. template<typename T1, typename T2>
  1112. struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
  1113. static bool evaluate( T1 const& lhs, T2 const& rhs ) {
  1114. return bool( opCast( lhs ) <= opCast( rhs ) );
  1115. }
  1116. };
  1117. template<Operator Op, typename T1, typename T2>
  1118. bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
  1119. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1120. }
  1121. // This level of indirection allows us to specialise for integer types
  1122. // to avoid signed/ unsigned warnings
  1123. // "base" overload
  1124. template<Operator Op, typename T1, typename T2>
  1125. bool compare( T1 const& lhs, T2 const& rhs ) {
  1126. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  1127. }
  1128. // unsigned X to int
  1129. template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
  1130. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1131. }
  1132. template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
  1133. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1134. }
  1135. template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
  1136. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  1137. }
  1138. // unsigned X to long
  1139. template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
  1140. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1141. }
  1142. template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
  1143. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1144. }
  1145. template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
  1146. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  1147. }
  1148. // int to unsigned X
  1149. template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
  1150. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1151. }
  1152. template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
  1153. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1154. }
  1155. template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
  1156. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  1157. }
  1158. // long to unsigned X
  1159. template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
  1160. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1161. }
  1162. template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
  1163. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1164. }
  1165. template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
  1166. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1167. }
  1168. // pointer to long (when comparing against NULL)
  1169. template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
  1170. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1171. }
  1172. template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
  1173. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1174. }
  1175. // pointer to int (when comparing against NULL)
  1176. template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
  1177. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1178. }
  1179. template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
  1180. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1181. }
  1182. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1183. // long long to unsigned X
  1184. template<Operator Op> bool compare( long long lhs, unsigned int rhs ) {
  1185. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1186. }
  1187. template<Operator Op> bool compare( long long lhs, unsigned long rhs ) {
  1188. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1189. }
  1190. template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) {
  1191. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1192. }
  1193. template<Operator Op> bool compare( long long lhs, unsigned char rhs ) {
  1194. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  1195. }
  1196. // unsigned long long to X
  1197. template<Operator Op> bool compare( unsigned long long lhs, int rhs ) {
  1198. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1199. }
  1200. template<Operator Op> bool compare( unsigned long long lhs, long rhs ) {
  1201. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1202. }
  1203. template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) {
  1204. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1205. }
  1206. template<Operator Op> bool compare( unsigned long long lhs, char rhs ) {
  1207. return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
  1208. }
  1209. // pointer to long long (when comparing against NULL)
  1210. template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) {
  1211. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  1212. }
  1213. template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) {
  1214. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  1215. }
  1216. #endif // CATCH_CONFIG_CPP11_LONG_LONG
  1217. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1218. // pointer to nullptr_t (when comparing against nullptr)
  1219. template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
  1220. return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs );
  1221. }
  1222. template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
  1223. return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr );
  1224. }
  1225. #endif // CATCH_CONFIG_CPP11_NULLPTR
  1226. } // end of namespace Internal
  1227. } // end of namespace Catch
  1228. #ifdef _MSC_VER
  1229. #pragma warning(pop)
  1230. #endif
  1231. // #included from: catch_tostring.h
  1232. #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
  1233. #include <sstream>
  1234. #include <iomanip>
  1235. #include <limits>
  1236. #include <vector>
  1237. #include <cstddef>
  1238. #ifdef __OBJC__
  1239. // #included from: catch_objc_arc.hpp
  1240. #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
  1241. #import <Foundation/Foundation.h>
  1242. #ifdef __has_feature
  1243. #define CATCH_ARC_ENABLED __has_feature(objc_arc)
  1244. #else
  1245. #define CATCH_ARC_ENABLED 0
  1246. #endif
  1247. void arcSafeRelease( NSObject* obj );
  1248. id performOptionalSelector( id obj, SEL sel );
  1249. #if !CATCH_ARC_ENABLED
  1250. inline void arcSafeRelease( NSObject* obj ) {
  1251. [obj release];
  1252. }
  1253. inline id performOptionalSelector( id obj, SEL sel ) {
  1254. if( [obj respondsToSelector: sel] )
  1255. return [obj performSelector: sel];
  1256. return nil;
  1257. }
  1258. #define CATCH_UNSAFE_UNRETAINED
  1259. #define CATCH_ARC_STRONG
  1260. #else
  1261. inline void arcSafeRelease( NSObject* ){}
  1262. inline id performOptionalSelector( id obj, SEL sel ) {
  1263. #ifdef __clang__
  1264. #pragma clang diagnostic push
  1265. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  1266. #endif
  1267. if( [obj respondsToSelector: sel] )
  1268. return [obj performSelector: sel];
  1269. #ifdef __clang__
  1270. #pragma clang diagnostic pop
  1271. #endif
  1272. return nil;
  1273. }
  1274. #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
  1275. #define CATCH_ARC_STRONG __strong
  1276. #endif
  1277. #endif
  1278. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1279. #include <tuple>
  1280. #endif
  1281. #ifdef CATCH_CONFIG_CPP11_IS_ENUM
  1282. #include <type_traits>
  1283. #endif
  1284. namespace Catch {
  1285. // Why we're here.
  1286. template<typename T>
  1287. std::string toString( T const& value );
  1288. // Built in overloads
  1289. std::string toString( std::string const& value );
  1290. std::string toString( std::wstring const& value );
  1291. std::string toString( const char* const value );
  1292. std::string toString( char* const value );
  1293. std::string toString( const wchar_t* const value );
  1294. std::string toString( wchar_t* const value );
  1295. std::string toString( int value );
  1296. std::string toString( unsigned long value );
  1297. std::string toString( unsigned int value );
  1298. std::string toString( const double value );
  1299. std::string toString( const float value );
  1300. std::string toString( bool value );
  1301. std::string toString( char value );
  1302. std::string toString( signed char value );
  1303. std::string toString( unsigned char value );
  1304. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  1305. std::string toString( long long value );
  1306. std::string toString( unsigned long long value );
  1307. #endif
  1308. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  1309. std::string toString( std::nullptr_t );
  1310. #endif
  1311. #ifdef __OBJC__
  1312. std::string toString( NSString const * const& nsstring );
  1313. std::string toString( NSString * CATCH_ARC_STRONG & nsstring );
  1314. std::string toString( NSObject* const& nsObject );
  1315. #endif
  1316. namespace Detail {
  1317. extern const std::string unprintableString;
  1318. #if !defined(CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK)
  1319. struct BorgType {
  1320. template<typename T> BorgType( T const& );
  1321. };
  1322. struct TrueType { char sizer[1]; };
  1323. struct FalseType { char sizer[2]; };
  1324. TrueType& testStreamable( std::ostream& );
  1325. FalseType testStreamable( FalseType );
  1326. FalseType operator<<( std::ostream const&, BorgType const& );
  1327. template<typename T>
  1328. struct IsStreamInsertable {
  1329. static std::ostream &s;
  1330. static T const&t;
  1331. enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
  1332. };
  1333. #else
  1334. template<typename T>
  1335. class IsStreamInsertable {
  1336. template<typename SS, typename TT>
  1337. static auto test(int)
  1338. -> decltype( std::declval<SS&>() << std::declval<TT>(), std::true_type() );
  1339. template<typename, typename>
  1340. static auto test(...) -> std::false_type;
  1341. public:
  1342. static const bool value = decltype(test<std::ostream,const T&>(0))::value;
  1343. };
  1344. #endif
  1345. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1346. template<typename T,
  1347. bool IsEnum = std::is_enum<T>::value
  1348. >
  1349. struct EnumStringMaker
  1350. {
  1351. static std::string convert( T const& ) { return unprintableString; }
  1352. };
  1353. template<typename T>
  1354. struct EnumStringMaker<T,true>
  1355. {
  1356. static std::string convert( T const& v )
  1357. {
  1358. return ::Catch::toString(
  1359. static_cast<typename std::underlying_type<T>::type>(v)
  1360. );
  1361. }
  1362. };
  1363. #endif
  1364. template<bool C>
  1365. struct StringMakerBase {
  1366. #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
  1367. template<typename T>
  1368. static std::string convert( T const& v )
  1369. {
  1370. return EnumStringMaker<T>::convert( v );
  1371. }
  1372. #else
  1373. template<typename T>
  1374. static std::string convert( T const& ) { return unprintableString; }
  1375. #endif
  1376. };
  1377. template<>
  1378. struct StringMakerBase<true> {
  1379. template<typename T>
  1380. static std::string convert( T const& _value ) {
  1381. std::ostringstream oss;
  1382. oss << _value;
  1383. return oss.str();
  1384. }
  1385. };
  1386. std::string rawMemoryToString( const void *object, std::size_t size );
  1387. template<typename T>
  1388. std::string rawMemoryToString( const T& object ) {
  1389. return rawMemoryToString( &object, sizeof(object) );
  1390. }
  1391. } // end namespace Detail
  1392. template<typename T>
  1393. struct StringMaker :
  1394. Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
  1395. template<typename T>
  1396. struct StringMaker<T*> {
  1397. template<typename U>
  1398. static std::string convert( U* p ) {
  1399. if( !p )
  1400. return "NULL";
  1401. else
  1402. return Detail::rawMemoryToString( p );
  1403. }
  1404. };
  1405. template<typename R, typename C>
  1406. struct StringMaker<R C::*> {
  1407. static std::string convert( R C::* p ) {
  1408. if( !p )
  1409. return "NULL";
  1410. else
  1411. return Detail::rawMemoryToString( p );
  1412. }
  1413. };
  1414. namespace Detail {
  1415. template<typename InputIterator>
  1416. std::string rangeToString( InputIterator first, InputIterator last );
  1417. }
  1418. //template<typename T, typename Allocator>
  1419. //struct StringMaker<std::vector<T, Allocator> > {
  1420. // static std::string convert( std::vector<T,Allocator> const& v ) {
  1421. // return Detail::rangeToString( v.begin(), v.end() );
  1422. // }
  1423. //};
  1424. template<typename T, typename Allocator>
  1425. std::string toString( std::vector<T,Allocator> const& v ) {
  1426. return Detail::rangeToString( v.begin(), v.end() );
  1427. }
  1428. #ifdef CATCH_CONFIG_CPP11_TUPLE
  1429. // toString for tuples
  1430. namespace TupleDetail {
  1431. template<
  1432. typename Tuple,
  1433. std::size_t N = 0,
  1434. bool = (N < std::tuple_size<Tuple>::value)
  1435. >
  1436. struct ElementPrinter {
  1437. static void print( const Tuple& tuple, std::ostream& os )
  1438. {
  1439. os << ( N ? ", " : " " )
  1440. << Catch::toString(std::get<N>(tuple));
  1441. ElementPrinter<Tuple,N+1>::print(tuple,os);
  1442. }
  1443. };
  1444. template<
  1445. typename Tuple,
  1446. std::size_t N
  1447. >
  1448. struct ElementPrinter<Tuple,N,false> {
  1449. static void print( const Tuple&, std::ostream& ) {}
  1450. };
  1451. }
  1452. template<typename ...Types>
  1453. struct StringMaker<std::tuple<Types...>> {
  1454. static std::string convert( const std::tuple<Types...>& tuple )
  1455. {
  1456. std::ostringstream os;
  1457. os << '{';
  1458. TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
  1459. os << " }";
  1460. return os.str();
  1461. }
  1462. };
  1463. #endif // CATCH_CONFIG_CPP11_TUPLE
  1464. namespace Detail {
  1465. template<typename T>
  1466. std::string makeString( T const& value ) {
  1467. return StringMaker<T>::convert( value );
  1468. }
  1469. } // end namespace Detail
  1470. /// \brief converts any type to a string
  1471. ///
  1472. /// The default template forwards on to ostringstream - except when an
  1473. /// ostringstream overload does not exist - in which case it attempts to detect
  1474. /// that and writes {?}.
  1475. /// Overload (not specialise) this template for custom typs that you don't want
  1476. /// to provide an ostream overload for.
  1477. template<typename T>
  1478. std::string toString( T const& value ) {
  1479. return StringMaker<T>::convert( value );
  1480. }
  1481. namespace Detail {
  1482. template<typename InputIterator>
  1483. std::string rangeToString( InputIterator first, InputIterator last ) {
  1484. std::ostringstream oss;
  1485. oss << "{ ";
  1486. if( first != last ) {
  1487. oss << Catch::toString( *first );
  1488. for( ++first ; first != last ; ++first )
  1489. oss << ", " << Catch::toString( *first );
  1490. }
  1491. oss << " }";
  1492. return oss.str();
  1493. }
  1494. }
  1495. } // end namespace Catch
  1496. namespace Catch {
  1497. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1498. class BinaryExpression;
  1499. template<typename ArgT, typename MatcherT>
  1500. class MatchExpression;
  1501. // Wraps the LHS of an expression and overloads comparison operators
  1502. // for also capturing those and RHS (if any)
  1503. template<typename T>
  1504. class ExpressionLhs : public DecomposedExpression {
  1505. public:
  1506. ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ), m_truthy(false) {}
  1507. ExpressionLhs& operator = ( const ExpressionLhs& );
  1508. template<typename RhsT>
  1509. BinaryExpression<T, Internal::IsEqualTo, RhsT const&>
  1510. operator == ( RhsT const& rhs ) {
  1511. return captureExpression<Internal::IsEqualTo>( rhs );
  1512. }
  1513. template<typename RhsT>
  1514. BinaryExpression<T, Internal::IsNotEqualTo, RhsT const&>
  1515. operator != ( RhsT const& rhs ) {
  1516. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1517. }
  1518. template<typename RhsT>
  1519. BinaryExpression<T, Internal::IsLessThan, RhsT const&>
  1520. operator < ( RhsT const& rhs ) {
  1521. return captureExpression<Internal::IsLessThan>( rhs );
  1522. }
  1523. template<typename RhsT>
  1524. BinaryExpression<T, Internal::IsGreaterThan, RhsT const&>
  1525. operator > ( RhsT const& rhs ) {
  1526. return captureExpression<Internal::IsGreaterThan>( rhs );
  1527. }
  1528. template<typename RhsT>
  1529. BinaryExpression<T, Internal::IsLessThanOrEqualTo, RhsT const&>
  1530. operator <= ( RhsT const& rhs ) {
  1531. return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
  1532. }
  1533. template<typename RhsT>
  1534. BinaryExpression<T, Internal::IsGreaterThanOrEqualTo, RhsT const&>
  1535. operator >= ( RhsT const& rhs ) {
  1536. return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
  1537. }
  1538. BinaryExpression<T, Internal::IsEqualTo, bool> operator == ( bool rhs ) {
  1539. return captureExpression<Internal::IsEqualTo>( rhs );
  1540. }
  1541. BinaryExpression<T, Internal::IsNotEqualTo, bool> operator != ( bool rhs ) {
  1542. return captureExpression<Internal::IsNotEqualTo>( rhs );
  1543. }
  1544. void endExpression() {
  1545. m_truthy = m_lhs ? true : false;
  1546. m_rb
  1547. .setResultType( m_truthy )
  1548. .endExpression( *this );
  1549. }
  1550. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1551. dest = Catch::toString( m_lhs );
  1552. }
  1553. private:
  1554. template<Internal::Operator Op, typename RhsT>
  1555. BinaryExpression<T, Op, RhsT&> captureExpression( RhsT& rhs ) const {
  1556. return BinaryExpression<T, Op, RhsT&>( m_rb, m_lhs, rhs );
  1557. }
  1558. template<Internal::Operator Op>
  1559. BinaryExpression<T, Op, bool> captureExpression( bool rhs ) const {
  1560. return BinaryExpression<T, Op, bool>( m_rb, m_lhs, rhs );
  1561. }
  1562. private:
  1563. ResultBuilder& m_rb;
  1564. T m_lhs;
  1565. bool m_truthy;
  1566. };
  1567. template<typename LhsT, Internal::Operator Op, typename RhsT>
  1568. class BinaryExpression : public DecomposedExpression {
  1569. public:
  1570. BinaryExpression( ResultBuilder& rb, LhsT lhs, RhsT rhs )
  1571. : m_rb( rb ), m_lhs( lhs ), m_rhs( rhs ) {}
  1572. BinaryExpression& operator = ( BinaryExpression& );
  1573. void endExpression() const {
  1574. m_rb
  1575. .setResultType( Internal::compare<Op>( m_lhs, m_rhs ) )
  1576. .endExpression( *this );
  1577. }
  1578. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1579. return true;
  1580. }
  1581. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1582. std::string lhs = Catch::toString( m_lhs );
  1583. std::string rhs = Catch::toString( m_rhs );
  1584. char delim = lhs.size() + rhs.size() < 40 &&
  1585. lhs.find('\n') == std::string::npos &&
  1586. rhs.find('\n') == std::string::npos ? ' ' : '\n';
  1587. dest.reserve( 7 + lhs.size() + rhs.size() );
  1588. // 2 for spaces around operator
  1589. // 2 for operator
  1590. // 2 for parentheses (conditionally added later)
  1591. // 1 for negation (conditionally added later)
  1592. dest = lhs;
  1593. dest += delim;
  1594. dest += Internal::OperatorTraits<Op>::getName();
  1595. dest += delim;
  1596. dest += rhs;
  1597. }
  1598. private:
  1599. ResultBuilder& m_rb;
  1600. LhsT m_lhs;
  1601. RhsT m_rhs;
  1602. };
  1603. template<typename ArgT, typename MatcherT>
  1604. class MatchExpression : public DecomposedExpression {
  1605. public:
  1606. MatchExpression( ArgT arg, MatcherT matcher, char const* matcherString )
  1607. : m_arg( arg ), m_matcher( matcher ), m_matcherString( matcherString ) {}
  1608. virtual bool isBinaryExpression() const CATCH_OVERRIDE {
  1609. return true;
  1610. }
  1611. virtual void reconstructExpression( std::string& dest ) const CATCH_OVERRIDE {
  1612. std::string matcherAsString = m_matcher.toString();
  1613. dest = Catch::toString( m_arg );
  1614. dest += ' ';
  1615. if( matcherAsString == Detail::unprintableString )
  1616. dest += m_matcherString;
  1617. else
  1618. dest += matcherAsString;
  1619. }
  1620. private:
  1621. ArgT m_arg;
  1622. MatcherT m_matcher;
  1623. char const* m_matcherString;
  1624. };
  1625. } // end namespace Catch
  1626. namespace Catch {
  1627. template<typename T>
  1628. ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
  1629. return ExpressionLhs<T const&>( *this, operand );
  1630. }
  1631. inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
  1632. return ExpressionLhs<bool>( *this, value );
  1633. }
  1634. template<typename ArgT, typename MatcherT>
  1635. void ResultBuilder::captureMatch( ArgT const& arg, MatcherT const& matcher,
  1636. char const* matcherString ) {
  1637. MatchExpression<ArgT const&, MatcherT const&> expr( arg, matcher, matcherString );
  1638. setResultType( matcher.match( arg ) );
  1639. endExpression( expr );
  1640. }
  1641. } // namespace Catch
  1642. // #included from: catch_message.h
  1643. #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
  1644. #include <string>
  1645. namespace Catch {
  1646. struct MessageInfo {
  1647. MessageInfo( std::string const& _macroName,
  1648. SourceLineInfo const& _lineInfo,
  1649. ResultWas::OfType _type );
  1650. std::string macroName;
  1651. SourceLineInfo lineInfo;
  1652. ResultWas::OfType type;
  1653. std::string message;
  1654. unsigned int sequence;
  1655. bool operator == ( MessageInfo const& other ) const {
  1656. return sequence == other.sequence;
  1657. }
  1658. bool operator < ( MessageInfo const& other ) const {
  1659. return sequence < other.sequence;
  1660. }
  1661. private:
  1662. static unsigned int globalCount;
  1663. };
  1664. struct MessageBuilder {
  1665. MessageBuilder( std::string const& macroName,
  1666. SourceLineInfo const& lineInfo,
  1667. ResultWas::OfType type )
  1668. : m_info( macroName, lineInfo, type )
  1669. {}
  1670. template<typename T>
  1671. MessageBuilder& operator << ( T const& value ) {
  1672. m_stream << value;
  1673. return *this;
  1674. }
  1675. MessageInfo m_info;
  1676. std::ostringstream m_stream;
  1677. };
  1678. class ScopedMessage {
  1679. public:
  1680. ScopedMessage( MessageBuilder const& builder );
  1681. ScopedMessage( ScopedMessage const& other );
  1682. ~ScopedMessage();
  1683. MessageInfo m_info;
  1684. };
  1685. } // end namespace Catch
  1686. // #included from: catch_interfaces_capture.h
  1687. #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
  1688. #include <string>
  1689. namespace Catch {
  1690. class TestCase;
  1691. class AssertionResult;
  1692. struct AssertionInfo;
  1693. struct SectionInfo;
  1694. struct SectionEndInfo;
  1695. struct MessageInfo;
  1696. class ScopedMessageBuilder;
  1697. struct Counts;
  1698. struct IResultCapture {
  1699. virtual ~IResultCapture();
  1700. virtual void assertionEnded( AssertionResult const& result ) = 0;
  1701. virtual bool sectionStarted( SectionInfo const& sectionInfo,
  1702. Counts& assertions ) = 0;
  1703. virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
  1704. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
  1705. virtual void pushScopedMessage( MessageInfo const& message ) = 0;
  1706. virtual void popScopedMessage( MessageInfo const& message ) = 0;
  1707. virtual std::string getCurrentTestName() const = 0;
  1708. virtual const AssertionResult* getLastResult() const = 0;
  1709. virtual void exceptionEarlyReported() = 0;
  1710. virtual void handleFatalErrorCondition( std::string const& message ) = 0;
  1711. virtual bool lastAssertionPassed() = 0;
  1712. virtual void assertionPassed() = 0;
  1713. virtual void assertionRun() = 0;
  1714. };
  1715. IResultCapture& getResultCapture();
  1716. }
  1717. // #included from: catch_debugger.h
  1718. #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
  1719. // #included from: catch_platform.h
  1720. #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED
  1721. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  1722. # define CATCH_PLATFORM_MAC
  1723. #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  1724. # define CATCH_PLATFORM_IPHONE
  1725. #elif defined(linux) || defined(__linux) || defined(__linux__)
  1726. # define CATCH_PLATFORM_LINUX
  1727. #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  1728. # define CATCH_PLATFORM_WINDOWS
  1729. # if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
  1730. # define CATCH_DEFINES_NOMINMAX
  1731. # endif
  1732. # if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
  1733. # define CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  1734. # endif
  1735. #endif
  1736. #include <string>
  1737. namespace Catch{
  1738. bool isDebuggerActive();
  1739. void writeToDebugConsole( std::string const& text );
  1740. }
  1741. #ifdef CATCH_PLATFORM_MAC
  1742. // The following code snippet based on:
  1743. // http://cocoawithlove.com/2008/03/break-into-debugger.html
  1744. #if defined(__ppc64__) || defined(__ppc__)
  1745. #define CATCH_TRAP() \
  1746. __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  1747. : : : "memory","r0","r3","r4" ) /* NOLINT */
  1748. #else
  1749. #define CATCH_TRAP() __asm__("int $3\n" : : /* NOLINT */ )
  1750. #endif
  1751. #elif defined(CATCH_PLATFORM_LINUX)
  1752. // If we can use inline assembler, do it because this allows us to break
  1753. // directly at the location of the failing check instead of breaking inside
  1754. // raise() called from it, i.e. one stack frame below.
  1755. #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
  1756. #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
  1757. #else // Fall back to the generic way.
  1758. #include <signal.h>
  1759. #define CATCH_TRAP() raise(SIGTRAP)
  1760. #endif
  1761. #elif defined(_MSC_VER)
  1762. #define CATCH_TRAP() __debugbreak()
  1763. #elif defined(__MINGW32__)
  1764. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  1765. #define CATCH_TRAP() DebugBreak()
  1766. #endif
  1767. #ifdef CATCH_TRAP
  1768. #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
  1769. #else
  1770. #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
  1771. #endif
  1772. // #included from: catch_interfaces_runner.h
  1773. #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
  1774. namespace Catch {
  1775. class TestCase;
  1776. struct IRunner {
  1777. virtual ~IRunner();
  1778. virtual bool aborting() const = 0;
  1779. };
  1780. }
  1781. #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
  1782. # define CATCH_INTERNAL_STRINGIFY(expr) #expr
  1783. #else
  1784. # define CATCH_INTERNAL_STRINGIFY(expr) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
  1785. #endif
  1786. #if defined(CATCH_CONFIG_FAST_COMPILE)
  1787. ///////////////////////////////////////////////////////////////////////////////
  1788. // We can speedup compilation significantly by breaking into debugger lower in
  1789. // the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
  1790. // macro in each assertion
  1791. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1792. resultBuilder.react();
  1793. ///////////////////////////////////////////////////////////////////////////////
  1794. // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
  1795. // macros.
  1796. // This can potentially cause false negative, if the test code catches
  1797. // the exception before it propagates back up to the runner.
  1798. #define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \
  1799. do { \
  1800. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1801. __catchResult.setExceptionGuard(); \
  1802. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1803. ( __catchResult <= expr ).endExpression(); \
  1804. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1805. __catchResult.unsetExceptionGuard(); \
  1806. INTERNAL_CATCH_REACT( __catchResult ) \
  1807. } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
  1808. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1809. #define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \
  1810. do { \
  1811. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1812. __catchResult.setExceptionGuard(); \
  1813. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1814. __catchResult.unsetExceptionGuard(); \
  1815. INTERNAL_CATCH_REACT( __catchResult ) \
  1816. } while( Catch::alwaysFalse() )
  1817. #else
  1818. ///////////////////////////////////////////////////////////////////////////////
  1819. // In the event of a failure works out if the debugger needs to be invoked
  1820. // and/or an exception thrown and takes appropriate action.
  1821. // This needs to be done as a macro so the debugger will stop in the user
  1822. // source code rather than in Catch library code
  1823. #define INTERNAL_CATCH_REACT( resultBuilder ) \
  1824. if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
  1825. resultBuilder.react();
  1826. #endif
  1827. ///////////////////////////////////////////////////////////////////////////////
  1828. #define INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ) \
  1829. do { \
  1830. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1831. try { \
  1832. CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
  1833. ( __catchResult <= expr ).endExpression(); \
  1834. CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
  1835. } \
  1836. catch( ... ) { \
  1837. __catchResult.useActiveException( resultDisposition ); \
  1838. } \
  1839. INTERNAL_CATCH_REACT( __catchResult ) \
  1840. } while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
  1841. // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
  1842. ///////////////////////////////////////////////////////////////////////////////
  1843. #define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \
  1844. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1845. if( Catch::getResultCapture().lastAssertionPassed() )
  1846. ///////////////////////////////////////////////////////////////////////////////
  1847. #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \
  1848. INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
  1849. if( !Catch::getResultCapture().lastAssertionPassed() )
  1850. ///////////////////////////////////////////////////////////////////////////////
  1851. #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \
  1852. do { \
  1853. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
  1854. try { \
  1855. static_cast<void>(expr); \
  1856. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1857. } \
  1858. catch( ... ) { \
  1859. __catchResult.useActiveException( resultDisposition ); \
  1860. } \
  1861. INTERNAL_CATCH_REACT( __catchResult ) \
  1862. } while( Catch::alwaysFalse() )
  1863. ///////////////////////////////////////////////////////////////////////////////
  1864. #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \
  1865. do { \
  1866. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1867. if( __catchResult.allowThrows() ) \
  1868. try { \
  1869. static_cast<void>(expr); \
  1870. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1871. } \
  1872. catch( ... ) { \
  1873. __catchResult.captureExpectedException( matcher ); \
  1874. } \
  1875. else \
  1876. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1877. INTERNAL_CATCH_REACT( __catchResult ) \
  1878. } while( Catch::alwaysFalse() )
  1879. ///////////////////////////////////////////////////////////////////////////////
  1880. #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
  1881. do { \
  1882. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
  1883. if( __catchResult.allowThrows() ) \
  1884. try { \
  1885. static_cast<void>(expr); \
  1886. __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
  1887. } \
  1888. catch( exceptionType ) { \
  1889. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1890. } \
  1891. catch( ... ) { \
  1892. __catchResult.useActiveException( resultDisposition ); \
  1893. } \
  1894. else \
  1895. __catchResult.captureResult( Catch::ResultWas::Ok ); \
  1896. INTERNAL_CATCH_REACT( __catchResult ) \
  1897. } while( Catch::alwaysFalse() )
  1898. ///////////////////////////////////////////////////////////////////////////////
  1899. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  1900. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
  1901. do { \
  1902. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1903. __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
  1904. __catchResult.captureResult( messageType ); \
  1905. INTERNAL_CATCH_REACT( __catchResult ) \
  1906. } while( Catch::alwaysFalse() )
  1907. #else
  1908. #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, log ) \
  1909. do { \
  1910. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
  1911. __catchResult << log + ::Catch::StreamEndStop(); \
  1912. __catchResult.captureResult( messageType ); \
  1913. INTERNAL_CATCH_REACT( __catchResult ) \
  1914. } while( Catch::alwaysFalse() )
  1915. #endif
  1916. ///////////////////////////////////////////////////////////////////////////////
  1917. #define INTERNAL_CATCH_INFO( macroName, log ) \
  1918. Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
  1919. ///////////////////////////////////////////////////////////////////////////////
  1920. #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
  1921. do { \
  1922. Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
  1923. try { \
  1924. __catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
  1925. } catch( ... ) { \
  1926. __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
  1927. } \
  1928. INTERNAL_CATCH_REACT( __catchResult ) \
  1929. } while( Catch::alwaysFalse() )
  1930. // #included from: internal/catch_section.h
  1931. #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
  1932. // #included from: catch_section_info.h
  1933. #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
  1934. // #included from: catch_totals.hpp
  1935. #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
  1936. #include <cstddef>
  1937. namespace Catch {
  1938. struct Counts {
  1939. Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
  1940. Counts operator - ( Counts const& other ) const {
  1941. Counts diff;
  1942. diff.passed = passed - other.passed;
  1943. diff.failed = failed - other.failed;
  1944. diff.failedButOk = failedButOk - other.failedButOk;
  1945. return diff;
  1946. }
  1947. Counts& operator += ( Counts const& other ) {
  1948. passed += other.passed;
  1949. failed += other.failed;
  1950. failedButOk += other.failedButOk;
  1951. return *this;
  1952. }
  1953. std::size_t total() const {
  1954. return passed + failed + failedButOk;
  1955. }
  1956. bool allPassed() const {
  1957. return failed == 0 && failedButOk == 0;
  1958. }
  1959. bool allOk() const {
  1960. return failed == 0;
  1961. }
  1962. std::size_t passed;
  1963. std::size_t failed;
  1964. std::size_t failedButOk;
  1965. };
  1966. struct Totals {
  1967. Totals operator - ( Totals const& other ) const {
  1968. Totals diff;
  1969. diff.assertions = assertions - other.assertions;
  1970. diff.testCases = testCases - other.testCases;
  1971. return diff;
  1972. }
  1973. Totals delta( Totals const& prevTotals ) const {
  1974. Totals diff = *this - prevTotals;
  1975. if( diff.assertions.failed > 0 )
  1976. ++diff.testCases.failed;
  1977. else if( diff.assertions.failedButOk > 0 )
  1978. ++diff.testCases.failedButOk;
  1979. else
  1980. ++diff.testCases.passed;
  1981. return diff;
  1982. }
  1983. Totals& operator += ( Totals const& other ) {
  1984. assertions += other.assertions;
  1985. testCases += other.testCases;
  1986. return *this;
  1987. }
  1988. Counts assertions;
  1989. Counts testCases;
  1990. };
  1991. }
  1992. #include <string>
  1993. namespace Catch {
  1994. struct SectionInfo {
  1995. SectionInfo
  1996. ( SourceLineInfo const& _lineInfo,
  1997. std::string const& _name,
  1998. std::string const& _description = std::string() );
  1999. std::string name;
  2000. std::string description;
  2001. SourceLineInfo lineInfo;
  2002. };
  2003. struct SectionEndInfo {
  2004. SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
  2005. : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
  2006. {}
  2007. SectionInfo sectionInfo;
  2008. Counts prevAssertions;
  2009. double durationInSeconds;
  2010. };
  2011. } // end namespace Catch
  2012. // #included from: catch_timer.h
  2013. #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED
  2014. #ifdef _MSC_VER
  2015. namespace Catch {
  2016. typedef unsigned long long UInt64;
  2017. }
  2018. #else
  2019. #include <stdint.h>
  2020. namespace Catch {
  2021. typedef uint64_t UInt64;
  2022. }
  2023. #endif
  2024. namespace Catch {
  2025. class Timer {
  2026. public:
  2027. Timer() : m_ticks( 0 ) {}
  2028. void start();
  2029. unsigned int getElapsedMicroseconds() const;
  2030. unsigned int getElapsedMilliseconds() const;
  2031. double getElapsedSeconds() const;
  2032. private:
  2033. UInt64 m_ticks;
  2034. };
  2035. } // namespace Catch
  2036. #include <string>
  2037. namespace Catch {
  2038. class Section : NonCopyable {
  2039. public:
  2040. Section( SectionInfo const& info );
  2041. ~Section();
  2042. // This indicates whether the section should be executed or not
  2043. operator bool() const;
  2044. private:
  2045. SectionInfo m_info;
  2046. std::string m_name;
  2047. Counts m_assertions;
  2048. bool m_sectionIncluded;
  2049. Timer m_timer;
  2050. };
  2051. } // end namespace Catch
  2052. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  2053. #define INTERNAL_CATCH_SECTION( ... ) \
  2054. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
  2055. #else
  2056. #define INTERNAL_CATCH_SECTION( name, desc ) \
  2057. if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
  2058. #endif
  2059. // #included from: internal/catch_generators.hpp
  2060. #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
  2061. #include <vector>
  2062. #include <string>
  2063. #include <stdlib.h>
  2064. namespace Catch {
  2065. template<typename T>
  2066. struct IGenerator {
  2067. virtual ~IGenerator() {}
  2068. virtual T getValue( std::size_t index ) const = 0;
  2069. virtual std::size_t size () const = 0;
  2070. };
  2071. template<typename T>
  2072. class BetweenGenerator : public IGenerator<T> {
  2073. public:
  2074. BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
  2075. virtual T getValue( std::size_t index ) const {
  2076. return m_from+static_cast<int>( index );
  2077. }
  2078. virtual std::size_t size() const {
  2079. return static_cast<std::size_t>( 1+m_to-m_from );
  2080. }
  2081. private:
  2082. T m_from;
  2083. T m_to;
  2084. };
  2085. template<typename T>
  2086. class ValuesGenerator : public IGenerator<T> {
  2087. public:
  2088. ValuesGenerator(){}
  2089. void add( T value ) {
  2090. m_values.push_back( value );
  2091. }
  2092. virtual T getValue( std::size_t index ) const {
  2093. return m_values[index];
  2094. }
  2095. virtual std::size_t size() const {
  2096. return m_values.size();
  2097. }
  2098. private:
  2099. std::vector<T> m_values;
  2100. };
  2101. template<typename T>
  2102. class CompositeGenerator {
  2103. public:
  2104. CompositeGenerator() : m_totalSize( 0 ) {}
  2105. // *** Move semantics, similar to auto_ptr ***
  2106. CompositeGenerator( CompositeGenerator& other )
  2107. : m_fileInfo( other.m_fileInfo ),
  2108. m_totalSize( 0 )
  2109. {
  2110. move( other );
  2111. }
  2112. CompositeGenerator& setFileInfo( const char* fileInfo ) {
  2113. m_fileInfo = fileInfo;
  2114. return *this;
  2115. }
  2116. ~CompositeGenerator() {
  2117. deleteAll( m_composed );
  2118. }
  2119. operator T () const {
  2120. size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
  2121. typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
  2122. typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
  2123. for( size_t index = 0; it != itEnd; ++it )
  2124. {
  2125. const IGenerator<T>* generator = *it;
  2126. if( overallIndex >= index && overallIndex < index + generator->size() )
  2127. {
  2128. return generator->getValue( overallIndex-index );
  2129. }
  2130. index += generator->size();
  2131. }
  2132. CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
  2133. 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
  2134. }
  2135. void add( const IGenerator<T>* generator ) {
  2136. m_totalSize += generator->size();
  2137. m_composed.push_back( generator );
  2138. }
  2139. CompositeGenerator& then( CompositeGenerator& other ) {
  2140. move( other );
  2141. return *this;
  2142. }
  2143. CompositeGenerator& then( T value ) {
  2144. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2145. valuesGen->add( value );
  2146. add( valuesGen );
  2147. return *this;
  2148. }
  2149. private:
  2150. void move( CompositeGenerator& other ) {
  2151. m_composed.insert( m_composed.end(), other.m_composed.begin(), other.m_composed.end() );
  2152. m_totalSize += other.m_totalSize;
  2153. other.m_composed.clear();
  2154. }
  2155. std::vector<const IGenerator<T>*> m_composed;
  2156. std::string m_fileInfo;
  2157. size_t m_totalSize;
  2158. };
  2159. namespace Generators
  2160. {
  2161. template<typename T>
  2162. CompositeGenerator<T> between( T from, T to ) {
  2163. CompositeGenerator<T> generators;
  2164. generators.add( new BetweenGenerator<T>( from, to ) );
  2165. return generators;
  2166. }
  2167. template<typename T>
  2168. CompositeGenerator<T> values( T val1, T val2 ) {
  2169. CompositeGenerator<T> generators;
  2170. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2171. valuesGen->add( val1 );
  2172. valuesGen->add( val2 );
  2173. generators.add( valuesGen );
  2174. return generators;
  2175. }
  2176. template<typename T>
  2177. CompositeGenerator<T> values( T val1, T val2, T val3 ){
  2178. CompositeGenerator<T> generators;
  2179. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2180. valuesGen->add( val1 );
  2181. valuesGen->add( val2 );
  2182. valuesGen->add( val3 );
  2183. generators.add( valuesGen );
  2184. return generators;
  2185. }
  2186. template<typename T>
  2187. CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
  2188. CompositeGenerator<T> generators;
  2189. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  2190. valuesGen->add( val1 );
  2191. valuesGen->add( val2 );
  2192. valuesGen->add( val3 );
  2193. valuesGen->add( val4 );
  2194. generators.add( valuesGen );
  2195. return generators;
  2196. }
  2197. } // end namespace Generators
  2198. using namespace Generators;
  2199. } // end namespace Catch
  2200. #define INTERNAL_CATCH_LINESTR2( line ) #line
  2201. #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
  2202. #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
  2203. // #included from: internal/catch_interfaces_exception.h
  2204. #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
  2205. #include <string>
  2206. #include <vector>
  2207. // #included from: catch_interfaces_registry_hub.h
  2208. #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
  2209. #include <string>
  2210. namespace Catch {
  2211. class TestCase;
  2212. struct ITestCaseRegistry;
  2213. struct IExceptionTranslatorRegistry;
  2214. struct IExceptionTranslator;
  2215. struct IReporterRegistry;
  2216. struct IReporterFactory;
  2217. struct ITagAliasRegistry;
  2218. struct IRegistryHub {
  2219. virtual ~IRegistryHub();
  2220. virtual IReporterRegistry const& getReporterRegistry() const = 0;
  2221. virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
  2222. virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
  2223. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
  2224. };
  2225. struct IMutableRegistryHub {
  2226. virtual ~IMutableRegistryHub();
  2227. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
  2228. virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
  2229. virtual void registerTest( TestCase const& testInfo ) = 0;
  2230. virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
  2231. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
  2232. };
  2233. IRegistryHub& getRegistryHub();
  2234. IMutableRegistryHub& getMutableRegistryHub();
  2235. void cleanUp();
  2236. std::string translateActiveException();
  2237. }
  2238. namespace Catch {
  2239. typedef std::string(*exceptionTranslateFunction)();
  2240. struct IExceptionTranslator;
  2241. typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
  2242. struct IExceptionTranslator {
  2243. virtual ~IExceptionTranslator();
  2244. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
  2245. };
  2246. struct IExceptionTranslatorRegistry {
  2247. virtual ~IExceptionTranslatorRegistry();
  2248. virtual std::string translateActiveException() const = 0;
  2249. };
  2250. class ExceptionTranslatorRegistrar {
  2251. template<typename T>
  2252. class ExceptionTranslator : public IExceptionTranslator {
  2253. public:
  2254. ExceptionTranslator( std::string(*translateFunction)( T& ) )
  2255. : m_translateFunction( translateFunction )
  2256. {}
  2257. virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
  2258. try {
  2259. if( it == itEnd )
  2260. throw;
  2261. else
  2262. return (*it)->translate( it+1, itEnd );
  2263. }
  2264. catch( T& ex ) {
  2265. return m_translateFunction( ex );
  2266. }
  2267. }
  2268. protected:
  2269. std::string(*m_translateFunction)( T& );
  2270. };
  2271. public:
  2272. template<typename T>
  2273. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
  2274. getMutableRegistryHub().registerTranslator
  2275. ( new ExceptionTranslator<T>( translateFunction ) );
  2276. }
  2277. };
  2278. }
  2279. ///////////////////////////////////////////////////////////////////////////////
  2280. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
  2281. static std::string translatorName( signature ); \
  2282. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\
  2283. static std::string translatorName( signature )
  2284. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
  2285. // #included from: internal/catch_approx.hpp
  2286. #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
  2287. #include <cmath>
  2288. #include <limits>
  2289. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2290. #include <type_traits>
  2291. #endif
  2292. namespace Catch {
  2293. namespace Detail {
  2294. class Approx {
  2295. public:
  2296. explicit Approx ( double value )
  2297. : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
  2298. m_margin( 0.0 ),
  2299. m_scale( 1.0 ),
  2300. m_value( value )
  2301. {}
  2302. static Approx custom() {
  2303. return Approx( 0 );
  2304. }
  2305. #if defined(CATCH_CONFIG_CPP11_TYPE_TRAITS)
  2306. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2307. Approx operator()( T value ) {
  2308. Approx approx( static_cast<double>(value) );
  2309. approx.epsilon( m_epsilon );
  2310. approx.margin( m_margin );
  2311. approx.scale( m_scale );
  2312. return approx;
  2313. }
  2314. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2315. explicit Approx( T value ): Approx(static_cast<double>(value))
  2316. {}
  2317. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2318. friend bool operator == ( const T& lhs, Approx const& rhs ) {
  2319. // Thanks to Richard Harris for his help refining this formula
  2320. auto lhs_v = double(lhs);
  2321. bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale + (std::max)(std::fabs(lhs_v), std::fabs(rhs.m_value)));
  2322. if (relativeOK) {
  2323. return true;
  2324. }
  2325. return std::fabs(lhs_v - rhs.m_value) <= rhs.m_margin;
  2326. }
  2327. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2328. friend bool operator == ( Approx const& lhs, const T& rhs ) {
  2329. return operator==( rhs, lhs );
  2330. }
  2331. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2332. friend bool operator != ( T lhs, Approx const& rhs ) {
  2333. return !operator==( lhs, rhs );
  2334. }
  2335. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2336. friend bool operator != ( Approx const& lhs, T rhs ) {
  2337. return !operator==( rhs, lhs );
  2338. }
  2339. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2340. friend bool operator <= ( T lhs, Approx const& rhs ) {
  2341. return double(lhs) < rhs.m_value || lhs == rhs;
  2342. }
  2343. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2344. friend bool operator <= ( Approx const& lhs, T rhs ) {
  2345. return lhs.m_value < double(rhs) || lhs == rhs;
  2346. }
  2347. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2348. friend bool operator >= ( T lhs, Approx const& rhs ) {
  2349. return double(lhs) > rhs.m_value || lhs == rhs;
  2350. }
  2351. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2352. friend bool operator >= ( Approx const& lhs, T rhs ) {
  2353. return lhs.m_value > double(rhs) || lhs == rhs;
  2354. }
  2355. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2356. Approx& epsilon( T newEpsilon ) {
  2357. m_epsilon = double(newEpsilon);
  2358. return *this;
  2359. }
  2360. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2361. Approx& margin( T newMargin ) {
  2362. m_margin = double(newMargin);
  2363. return *this;
  2364. }
  2365. template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
  2366. Approx& scale( T newScale ) {
  2367. m_scale = double(newScale);
  2368. return *this;
  2369. }
  2370. #else
  2371. Approx operator()( double value ) {
  2372. Approx approx( value );
  2373. approx.epsilon( m_epsilon );
  2374. approx.margin( m_margin );
  2375. approx.scale( m_scale );
  2376. return approx;
  2377. }
  2378. friend bool operator == ( double lhs, Approx const& rhs ) {
  2379. // Thanks to Richard Harris for his help refining this formula
  2380. bool relativeOK = std::fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( std::fabs(lhs), std::fabs(rhs.m_value) ) );
  2381. if (relativeOK) {
  2382. return true;
  2383. }
  2384. return std::fabs(lhs - rhs.m_value) <= rhs.m_margin;
  2385. }
  2386. friend bool operator == ( Approx const& lhs, double rhs ) {
  2387. return operator==( rhs, lhs );
  2388. }
  2389. friend bool operator != ( double lhs, Approx const& rhs ) {
  2390. return !operator==( lhs, rhs );
  2391. }
  2392. friend bool operator != ( Approx const& lhs, double rhs ) {
  2393. return !operator==( rhs, lhs );
  2394. }
  2395. friend bool operator <= ( double lhs, Approx const& rhs ) {
  2396. return lhs < rhs.m_value || lhs == rhs;
  2397. }
  2398. friend bool operator <= ( Approx const& lhs, double rhs ) {
  2399. return lhs.m_value < rhs || lhs == rhs;
  2400. }
  2401. friend bool operator >= ( double lhs, Approx const& rhs ) {
  2402. return lhs > rhs.m_value || lhs == rhs;
  2403. }
  2404. friend bool operator >= ( Approx const& lhs, double rhs ) {
  2405. return lhs.m_value > rhs || lhs == rhs;
  2406. }
  2407. Approx& epsilon( double newEpsilon ) {
  2408. m_epsilon = newEpsilon;
  2409. return *this;
  2410. }
  2411. Approx& margin( double newMargin ) {
  2412. m_margin = newMargin;
  2413. return *this;
  2414. }
  2415. Approx& scale( double newScale ) {
  2416. m_scale = newScale;
  2417. return *this;
  2418. }
  2419. #endif
  2420. std::string toString() const {
  2421. std::ostringstream oss;
  2422. oss << "Approx( " << Catch::toString( m_value ) << " )";
  2423. return oss.str();
  2424. }
  2425. private:
  2426. double m_epsilon;
  2427. double m_margin;
  2428. double m_scale;
  2429. double m_value;
  2430. };
  2431. }
  2432. template<>
  2433. inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
  2434. return value.toString();
  2435. }
  2436. } // end namespace Catch
  2437. // #included from: internal/catch_matchers_string.h
  2438. #define TWOBLUECUBES_CATCH_MATCHERS_STRING_H_INCLUDED
  2439. namespace Catch {
  2440. namespace Matchers {
  2441. namespace StdString {
  2442. struct CasedString
  2443. {
  2444. CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
  2445. std::string adjustString( std::string const& str ) const;
  2446. std::string caseSensitivitySuffix() const;
  2447. CaseSensitive::Choice m_caseSensitivity;
  2448. std::string m_str;
  2449. };
  2450. struct StringMatcherBase : MatcherBase<std::string> {
  2451. StringMatcherBase( std::string const& operation, CasedString const& comparator );
  2452. virtual std::string describe() const CATCH_OVERRIDE;
  2453. CasedString m_comparator;
  2454. std::string m_operation;
  2455. };
  2456. struct EqualsMatcher : StringMatcherBase {
  2457. EqualsMatcher( CasedString const& comparator );
  2458. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2459. };
  2460. struct ContainsMatcher : StringMatcherBase {
  2461. ContainsMatcher( CasedString const& comparator );
  2462. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2463. };
  2464. struct StartsWithMatcher : StringMatcherBase {
  2465. StartsWithMatcher( CasedString const& comparator );
  2466. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2467. };
  2468. struct EndsWithMatcher : StringMatcherBase {
  2469. EndsWithMatcher( CasedString const& comparator );
  2470. virtual bool match( std::string const& source ) const CATCH_OVERRIDE;
  2471. };
  2472. } // namespace StdString
  2473. // The following functions create the actual matcher objects.
  2474. // This allows the types to be inferred
  2475. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2476. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2477. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2478. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
  2479. } // namespace Matchers
  2480. } // namespace Catch
  2481. // #included from: internal/catch_matchers_vector.h
  2482. #define TWOBLUECUBES_CATCH_MATCHERS_VECTOR_H_INCLUDED
  2483. namespace Catch {
  2484. namespace Matchers {
  2485. namespace Vector {
  2486. template<typename T>
  2487. struct ContainsElementMatcher : MatcherBase<std::vector<T>, T> {
  2488. ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
  2489. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2490. return std::find(v.begin(), v.end(), m_comparator) != v.end();
  2491. }
  2492. virtual std::string describe() const CATCH_OVERRIDE {
  2493. return "Contains: " + Catch::toString( m_comparator );
  2494. }
  2495. T const& m_comparator;
  2496. };
  2497. template<typename T>
  2498. struct ContainsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2499. ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2500. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2501. // !TBD: see note in EqualsMatcher
  2502. if (m_comparator.size() > v.size())
  2503. return false;
  2504. for (size_t i = 0; i < m_comparator.size(); ++i)
  2505. if (std::find(v.begin(), v.end(), m_comparator[i]) == v.end())
  2506. return false;
  2507. return true;
  2508. }
  2509. virtual std::string describe() const CATCH_OVERRIDE {
  2510. return "Contains: " + Catch::toString( m_comparator );
  2511. }
  2512. std::vector<T> const& m_comparator;
  2513. };
  2514. template<typename T>
  2515. struct EqualsMatcher : MatcherBase<std::vector<T>, std::vector<T> > {
  2516. EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
  2517. bool match(std::vector<T> const &v) const CATCH_OVERRIDE {
  2518. // !TBD: This currently works if all elements can be compared using !=
  2519. // - a more general approach would be via a compare template that defaults
  2520. // to using !=. but could be specialised for, e.g. std::vector<T> etc
  2521. // - then just call that directly
  2522. if (m_comparator.size() != v.size())
  2523. return false;
  2524. for (size_t i = 0; i < v.size(); ++i)
  2525. if (m_comparator[i] != v[i])
  2526. return false;
  2527. return true;
  2528. }
  2529. virtual std::string describe() const CATCH_OVERRIDE {
  2530. return "Equals: " + Catch::toString( m_comparator );
  2531. }
  2532. std::vector<T> const& m_comparator;
  2533. };
  2534. } // namespace Vector
  2535. // The following functions create the actual matcher objects.
  2536. // This allows the types to be inferred
  2537. template<typename T>
  2538. Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
  2539. return Vector::ContainsMatcher<T>( comparator );
  2540. }
  2541. template<typename T>
  2542. Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) {
  2543. return Vector::ContainsElementMatcher<T>( comparator );
  2544. }
  2545. template<typename T>
  2546. Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
  2547. return Vector::EqualsMatcher<T>( comparator );
  2548. }
  2549. } // namespace Matchers
  2550. } // namespace Catch
  2551. // #included from: internal/catch_interfaces_tag_alias_registry.h
  2552. #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
  2553. // #included from: catch_tag_alias.h
  2554. #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED
  2555. #include <string>
  2556. namespace Catch {
  2557. struct TagAlias {
  2558. TagAlias( std::string const& _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
  2559. std::string tag;
  2560. SourceLineInfo lineInfo;
  2561. };
  2562. struct RegistrarForTagAliases {
  2563. RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
  2564. };
  2565. } // end namespace Catch
  2566. #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); }
  2567. // #included from: catch_option.hpp
  2568. #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
  2569. namespace Catch {
  2570. // An optional type
  2571. template<typename T>
  2572. class Option {
  2573. public:
  2574. Option() : nullableValue( CATCH_NULL ) {}
  2575. Option( T const& _value )
  2576. : nullableValue( new( storage ) T( _value ) )
  2577. {}
  2578. Option( Option const& _other )
  2579. : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
  2580. {}
  2581. ~Option() {
  2582. reset();
  2583. }
  2584. Option& operator= ( Option const& _other ) {
  2585. if( &_other != this ) {
  2586. reset();
  2587. if( _other )
  2588. nullableValue = new( storage ) T( *_other );
  2589. }
  2590. return *this;
  2591. }
  2592. Option& operator = ( T const& _value ) {
  2593. reset();
  2594. nullableValue = new( storage ) T( _value );
  2595. return *this;
  2596. }
  2597. void reset() {
  2598. if( nullableValue )
  2599. nullableValue->~T();
  2600. nullableValue = CATCH_NULL;
  2601. }
  2602. T& operator*() { return *nullableValue; }
  2603. T const& operator*() const { return *nullableValue; }
  2604. T* operator->() { return nullableValue; }
  2605. const T* operator->() const { return nullableValue; }
  2606. T valueOr( T const& defaultValue ) const {
  2607. return nullableValue ? *nullableValue : defaultValue;
  2608. }
  2609. bool some() const { return nullableValue != CATCH_NULL; }
  2610. bool none() const { return nullableValue == CATCH_NULL; }
  2611. bool operator !() const { return nullableValue == CATCH_NULL; }
  2612. operator SafeBool::type() const {
  2613. return SafeBool::makeSafe( some() );
  2614. }
  2615. private:
  2616. T *nullableValue;
  2617. union {
  2618. char storage[sizeof(T)];
  2619. // These are here to force alignment for the storage
  2620. long double dummy1;
  2621. void (*dummy2)();
  2622. long double dummy3;
  2623. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  2624. long long dummy4;
  2625. #endif
  2626. };
  2627. };
  2628. } // end namespace Catch
  2629. namespace Catch {
  2630. struct ITagAliasRegistry {
  2631. virtual ~ITagAliasRegistry();
  2632. virtual Option<TagAlias> find( std::string const& alias ) const = 0;
  2633. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
  2634. static ITagAliasRegistry const& get();
  2635. };
  2636. } // end namespace Catch
  2637. // These files are included here so the single_include script doesn't put them
  2638. // in the conditionally compiled sections
  2639. // #included from: internal/catch_test_case_info.h
  2640. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
  2641. #include <string>
  2642. #include <set>
  2643. #ifdef __clang__
  2644. #pragma clang diagnostic push
  2645. #pragma clang diagnostic ignored "-Wpadded"
  2646. #endif
  2647. namespace Catch {
  2648. struct ITestCase;
  2649. struct TestCaseInfo {
  2650. enum SpecialProperties{
  2651. None = 0,
  2652. IsHidden = 1 << 1,
  2653. ShouldFail = 1 << 2,
  2654. MayFail = 1 << 3,
  2655. Throws = 1 << 4,
  2656. NonPortable = 1 << 5
  2657. };
  2658. TestCaseInfo( std::string const& _name,
  2659. std::string const& _className,
  2660. std::string const& _description,
  2661. std::set<std::string> const& _tags,
  2662. SourceLineInfo const& _lineInfo );
  2663. TestCaseInfo( TestCaseInfo const& other );
  2664. friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
  2665. bool isHidden() const;
  2666. bool throws() const;
  2667. bool okToFail() const;
  2668. bool expectedToFail() const;
  2669. std::string name;
  2670. std::string className;
  2671. std::string description;
  2672. std::set<std::string> tags;
  2673. std::set<std::string> lcaseTags;
  2674. std::string tagsAsString;
  2675. SourceLineInfo lineInfo;
  2676. SpecialProperties properties;
  2677. };
  2678. class TestCase : public TestCaseInfo {
  2679. public:
  2680. TestCase( ITestCase* testCase, TestCaseInfo const& info );
  2681. TestCase( TestCase const& other );
  2682. TestCase withName( std::string const& _newName ) const;
  2683. void invoke() const;
  2684. TestCaseInfo const& getTestCaseInfo() const;
  2685. void swap( TestCase& other );
  2686. bool operator == ( TestCase const& other ) const;
  2687. bool operator < ( TestCase const& other ) const;
  2688. TestCase& operator = ( TestCase const& other );
  2689. private:
  2690. Ptr<ITestCase> test;
  2691. };
  2692. TestCase makeTestCase( ITestCase* testCase,
  2693. std::string const& className,
  2694. std::string const& name,
  2695. std::string const& description,
  2696. SourceLineInfo const& lineInfo );
  2697. }
  2698. #ifdef __clang__
  2699. #pragma clang diagnostic pop
  2700. #endif
  2701. #ifdef __OBJC__
  2702. // #included from: internal/catch_objc.hpp
  2703. #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
  2704. #import <objc/runtime.h>
  2705. #include <string>
  2706. // NB. Any general catch headers included here must be included
  2707. // in catch.hpp first to make sure they are included by the single
  2708. // header for non obj-usage
  2709. ///////////////////////////////////////////////////////////////////////////////
  2710. // This protocol is really only here for (self) documenting purposes, since
  2711. // all its methods are optional.
  2712. @protocol OcFixture
  2713. @optional
  2714. -(void) setUp;
  2715. -(void) tearDown;
  2716. @end
  2717. namespace Catch {
  2718. class OcMethod : public SharedImpl<ITestCase> {
  2719. public:
  2720. OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
  2721. virtual void invoke() const {
  2722. id obj = [[m_cls alloc] init];
  2723. performOptionalSelector( obj, @selector(setUp) );
  2724. performOptionalSelector( obj, m_sel );
  2725. performOptionalSelector( obj, @selector(tearDown) );
  2726. arcSafeRelease( obj );
  2727. }
  2728. private:
  2729. virtual ~OcMethod() {}
  2730. Class m_cls;
  2731. SEL m_sel;
  2732. };
  2733. namespace Detail{
  2734. inline std::string getAnnotation( Class cls,
  2735. std::string const& annotationName,
  2736. std::string const& testCaseName ) {
  2737. NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
  2738. SEL sel = NSSelectorFromString( selStr );
  2739. arcSafeRelease( selStr );
  2740. id value = performOptionalSelector( cls, sel );
  2741. if( value )
  2742. return [(NSString*)value UTF8String];
  2743. return "";
  2744. }
  2745. }
  2746. inline size_t registerTestMethods() {
  2747. size_t noTestMethods = 0;
  2748. int noClasses = objc_getClassList( CATCH_NULL, 0 );
  2749. Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
  2750. objc_getClassList( classes, noClasses );
  2751. for( int c = 0; c < noClasses; c++ ) {
  2752. Class cls = classes[c];
  2753. {
  2754. u_int count;
  2755. Method* methods = class_copyMethodList( cls, &count );
  2756. for( u_int m = 0; m < count ; m++ ) {
  2757. SEL selector = method_getName(methods[m]);
  2758. std::string methodName = sel_getName(selector);
  2759. if( startsWith( methodName, "Catch_TestCase_" ) ) {
  2760. std::string testCaseName = methodName.substr( 15 );
  2761. std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
  2762. std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
  2763. const char* className = class_getName( cls );
  2764. getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
  2765. noTestMethods++;
  2766. }
  2767. }
  2768. free(methods);
  2769. }
  2770. }
  2771. return noTestMethods;
  2772. }
  2773. namespace Matchers {
  2774. namespace Impl {
  2775. namespace NSStringMatchers {
  2776. struct StringHolder : MatcherBase<NSString*>{
  2777. StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
  2778. StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
  2779. StringHolder() {
  2780. arcSafeRelease( m_substr );
  2781. }
  2782. virtual bool match( NSString* arg ) const CATCH_OVERRIDE {
  2783. return false;
  2784. }
  2785. NSString* m_substr;
  2786. };
  2787. struct Equals : StringHolder {
  2788. Equals( NSString* substr ) : StringHolder( substr ){}
  2789. virtual bool match( NSString* str ) const CATCH_OVERRIDE {
  2790. return (str != nil || m_substr == nil ) &&
  2791. [str isEqualToString:m_substr];
  2792. }
  2793. virtual std::string describe() const CATCH_OVERRIDE {
  2794. return "equals string: " + Catch::toString( m_substr );
  2795. }
  2796. };
  2797. struct Contains : StringHolder {
  2798. Contains( NSString* substr ) : StringHolder( substr ){}
  2799. virtual bool match( NSString* str ) const {
  2800. return (str != nil || m_substr == nil ) &&
  2801. [str rangeOfString:m_substr].location != NSNotFound;
  2802. }
  2803. virtual std::string describe() const CATCH_OVERRIDE {
  2804. return "contains string: " + Catch::toString( m_substr );
  2805. }
  2806. };
  2807. struct StartsWith : StringHolder {
  2808. StartsWith( NSString* substr ) : StringHolder( substr ){}
  2809. virtual bool match( NSString* str ) const {
  2810. return (str != nil || m_substr == nil ) &&
  2811. [str rangeOfString:m_substr].location == 0;
  2812. }
  2813. virtual std::string describe() const CATCH_OVERRIDE {
  2814. return "starts with: " + Catch::toString( m_substr );
  2815. }
  2816. };
  2817. struct EndsWith : StringHolder {
  2818. EndsWith( NSString* substr ) : StringHolder( substr ){}
  2819. virtual bool match( NSString* str ) const {
  2820. return (str != nil || m_substr == nil ) &&
  2821. [str rangeOfString:m_substr].location == [str length] - [m_substr length];
  2822. }
  2823. virtual std::string describe() const CATCH_OVERRIDE {
  2824. return "ends with: " + Catch::toString( m_substr );
  2825. }
  2826. };
  2827. } // namespace NSStringMatchers
  2828. } // namespace Impl
  2829. inline Impl::NSStringMatchers::Equals
  2830. Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
  2831. inline Impl::NSStringMatchers::Contains
  2832. Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
  2833. inline Impl::NSStringMatchers::StartsWith
  2834. StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
  2835. inline Impl::NSStringMatchers::EndsWith
  2836. EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
  2837. } // namespace Matchers
  2838. using namespace Matchers;
  2839. } // namespace Catch
  2840. ///////////////////////////////////////////////////////////////////////////////
  2841. #define OC_TEST_CASE( name, desc )\
  2842. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
  2843. {\
  2844. return @ name; \
  2845. }\
  2846. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
  2847. { \
  2848. return @ desc; \
  2849. } \
  2850. -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
  2851. #endif
  2852. #ifdef CATCH_IMPL
  2853. // !TBD: Move the leak detector code into a separate header
  2854. #ifdef CATCH_CONFIG_WINDOWS_CRTDBG
  2855. #include <crtdbg.h>
  2856. class LeakDetector {
  2857. public:
  2858. LeakDetector() {
  2859. int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  2860. flag |= _CRTDBG_LEAK_CHECK_DF;
  2861. flag |= _CRTDBG_ALLOC_MEM_DF;
  2862. _CrtSetDbgFlag(flag);
  2863. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
  2864. _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
  2865. // Change this to leaking allocation's number to break there
  2866. _CrtSetBreakAlloc(-1);
  2867. }
  2868. };
  2869. #else
  2870. class LeakDetector {};
  2871. #endif
  2872. LeakDetector leakDetector;
  2873. // #included from: internal/catch_impl.hpp
  2874. #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
  2875. // Collect all the implementation files together here
  2876. // These are the equivalent of what would usually be cpp files
  2877. #ifdef __clang__
  2878. #pragma clang diagnostic push
  2879. #pragma clang diagnostic ignored "-Wweak-vtables"
  2880. #endif
  2881. // #included from: ../catch_session.hpp
  2882. #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
  2883. // #included from: internal/catch_commandline.hpp
  2884. #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
  2885. // #included from: catch_config.hpp
  2886. #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
  2887. // #included from: catch_test_spec_parser.hpp
  2888. #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
  2889. #ifdef __clang__
  2890. #pragma clang diagnostic push
  2891. #pragma clang diagnostic ignored "-Wpadded"
  2892. #endif
  2893. // #included from: catch_test_spec.hpp
  2894. #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
  2895. #ifdef __clang__
  2896. #pragma clang diagnostic push
  2897. #pragma clang diagnostic ignored "-Wpadded"
  2898. #endif
  2899. // #included from: catch_wildcard_pattern.hpp
  2900. #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
  2901. #include <stdexcept>
  2902. namespace Catch
  2903. {
  2904. class WildcardPattern {
  2905. enum WildcardPosition {
  2906. NoWildcard = 0,
  2907. WildcardAtStart = 1,
  2908. WildcardAtEnd = 2,
  2909. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  2910. };
  2911. public:
  2912. WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
  2913. : m_caseSensitivity( caseSensitivity ),
  2914. m_wildcard( NoWildcard ),
  2915. m_pattern( adjustCase( pattern ) )
  2916. {
  2917. if( startsWith( m_pattern, '*' ) ) {
  2918. m_pattern = m_pattern.substr( 1 );
  2919. m_wildcard = WildcardAtStart;
  2920. }
  2921. if( endsWith( m_pattern, '*' ) ) {
  2922. m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
  2923. m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
  2924. }
  2925. }
  2926. virtual ~WildcardPattern();
  2927. virtual bool matches( std::string const& str ) const {
  2928. switch( m_wildcard ) {
  2929. case NoWildcard:
  2930. return m_pattern == adjustCase( str );
  2931. case WildcardAtStart:
  2932. return endsWith( adjustCase( str ), m_pattern );
  2933. case WildcardAtEnd:
  2934. return startsWith( adjustCase( str ), m_pattern );
  2935. case WildcardAtBothEnds:
  2936. return contains( adjustCase( str ), m_pattern );
  2937. }
  2938. #ifdef __clang__
  2939. #pragma clang diagnostic push
  2940. #pragma clang diagnostic ignored "-Wunreachable-code"
  2941. #endif
  2942. throw std::logic_error( "Unknown enum" );
  2943. #ifdef __clang__
  2944. #pragma clang diagnostic pop
  2945. #endif
  2946. }
  2947. private:
  2948. std::string adjustCase( std::string const& str ) const {
  2949. return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
  2950. }
  2951. CaseSensitive::Choice m_caseSensitivity;
  2952. WildcardPosition m_wildcard;
  2953. std::string m_pattern;
  2954. };
  2955. }
  2956. #include <string>
  2957. #include <vector>
  2958. namespace Catch {
  2959. class TestSpec {
  2960. struct Pattern : SharedImpl<> {
  2961. virtual ~Pattern();
  2962. virtual bool matches( TestCaseInfo const& testCase ) const = 0;
  2963. };
  2964. class NamePattern : public Pattern {
  2965. public:
  2966. NamePattern( std::string const& name )
  2967. : m_wildcardPattern( toLower( name ), CaseSensitive::No )
  2968. {}
  2969. virtual ~NamePattern();
  2970. virtual bool matches( TestCaseInfo const& testCase ) const {
  2971. return m_wildcardPattern.matches( toLower( testCase.name ) );
  2972. }
  2973. private:
  2974. WildcardPattern m_wildcardPattern;
  2975. };
  2976. class TagPattern : public Pattern {
  2977. public:
  2978. TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
  2979. virtual ~TagPattern();
  2980. virtual bool matches( TestCaseInfo const& testCase ) const {
  2981. return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
  2982. }
  2983. private:
  2984. std::string m_tag;
  2985. };
  2986. class ExcludedPattern : public Pattern {
  2987. public:
  2988. ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
  2989. virtual ~ExcludedPattern();
  2990. virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
  2991. private:
  2992. Ptr<Pattern> m_underlyingPattern;
  2993. };
  2994. struct Filter {
  2995. std::vector<Ptr<Pattern> > m_patterns;
  2996. bool matches( TestCaseInfo const& testCase ) const {
  2997. // All patterns in a filter must match for the filter to be a match
  2998. for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
  2999. if( !(*it)->matches( testCase ) )
  3000. return false;
  3001. }
  3002. return true;
  3003. }
  3004. };
  3005. public:
  3006. bool hasFilters() const {
  3007. return !m_filters.empty();
  3008. }
  3009. bool matches( TestCaseInfo const& testCase ) const {
  3010. // A TestSpec matches if any filter matches
  3011. for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
  3012. if( it->matches( testCase ) )
  3013. return true;
  3014. return false;
  3015. }
  3016. private:
  3017. std::vector<Filter> m_filters;
  3018. friend class TestSpecParser;
  3019. };
  3020. }
  3021. #ifdef __clang__
  3022. #pragma clang diagnostic pop
  3023. #endif
  3024. namespace Catch {
  3025. class TestSpecParser {
  3026. enum Mode{ None, Name, QuotedName, Tag, EscapedName };
  3027. Mode m_mode;
  3028. bool m_exclusion;
  3029. std::size_t m_start, m_pos;
  3030. std::string m_arg;
  3031. std::vector<std::size_t> m_escapeChars;
  3032. TestSpec::Filter m_currentFilter;
  3033. TestSpec m_testSpec;
  3034. ITagAliasRegistry const* m_tagAliases;
  3035. public:
  3036. TestSpecParser( ITagAliasRegistry const& tagAliases ) :m_mode(None), m_exclusion(false), m_start(0), m_pos(0), m_tagAliases( &tagAliases ) {}
  3037. TestSpecParser& parse( std::string const& arg ) {
  3038. m_mode = None;
  3039. m_exclusion = false;
  3040. m_start = std::string::npos;
  3041. m_arg = m_tagAliases->expandAliases( arg );
  3042. m_escapeChars.clear();
  3043. for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
  3044. visitChar( m_arg[m_pos] );
  3045. if( m_mode == Name )
  3046. addPattern<TestSpec::NamePattern>();
  3047. return *this;
  3048. }
  3049. TestSpec testSpec() {
  3050. addFilter();
  3051. return m_testSpec;
  3052. }
  3053. private:
  3054. void visitChar( char c ) {
  3055. if( m_mode == None ) {
  3056. switch( c ) {
  3057. case ' ': return;
  3058. case '~': m_exclusion = true; return;
  3059. case '[': return startNewMode( Tag, ++m_pos );
  3060. case '"': return startNewMode( QuotedName, ++m_pos );
  3061. case '\\': return escape();
  3062. default: startNewMode( Name, m_pos ); break;
  3063. }
  3064. }
  3065. if( m_mode == Name ) {
  3066. if( c == ',' ) {
  3067. addPattern<TestSpec::NamePattern>();
  3068. addFilter();
  3069. }
  3070. else if( c == '[' ) {
  3071. if( subString() == "exclude:" )
  3072. m_exclusion = true;
  3073. else
  3074. addPattern<TestSpec::NamePattern>();
  3075. startNewMode( Tag, ++m_pos );
  3076. }
  3077. else if( c == '\\' )
  3078. escape();
  3079. }
  3080. else if( m_mode == EscapedName )
  3081. m_mode = Name;
  3082. else if( m_mode == QuotedName && c == '"' )
  3083. addPattern<TestSpec::NamePattern>();
  3084. else if( m_mode == Tag && c == ']' )
  3085. addPattern<TestSpec::TagPattern>();
  3086. }
  3087. void startNewMode( Mode mode, std::size_t start ) {
  3088. m_mode = mode;
  3089. m_start = start;
  3090. }
  3091. void escape() {
  3092. if( m_mode == None )
  3093. m_start = m_pos;
  3094. m_mode = EscapedName;
  3095. m_escapeChars.push_back( m_pos );
  3096. }
  3097. std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
  3098. template<typename T>
  3099. void addPattern() {
  3100. std::string token = subString();
  3101. for( size_t i = 0; i < m_escapeChars.size(); ++i )
  3102. token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
  3103. m_escapeChars.clear();
  3104. if( startsWith( token, "exclude:" ) ) {
  3105. m_exclusion = true;
  3106. token = token.substr( 8 );
  3107. }
  3108. if( !token.empty() ) {
  3109. Ptr<TestSpec::Pattern> pattern = new T( token );
  3110. if( m_exclusion )
  3111. pattern = new TestSpec::ExcludedPattern( pattern );
  3112. m_currentFilter.m_patterns.push_back( pattern );
  3113. }
  3114. m_exclusion = false;
  3115. m_mode = None;
  3116. }
  3117. void addFilter() {
  3118. if( !m_currentFilter.m_patterns.empty() ) {
  3119. m_testSpec.m_filters.push_back( m_currentFilter );
  3120. m_currentFilter = TestSpec::Filter();
  3121. }
  3122. }
  3123. };
  3124. inline TestSpec parseTestSpec( std::string const& arg ) {
  3125. return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
  3126. }
  3127. } // namespace Catch
  3128. #ifdef __clang__
  3129. #pragma clang diagnostic pop
  3130. #endif
  3131. // #included from: catch_interfaces_config.h
  3132. #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
  3133. #include <iosfwd>
  3134. #include <string>
  3135. #include <vector>
  3136. namespace Catch {
  3137. struct Verbosity { enum Level {
  3138. NoOutput = 0,
  3139. Quiet,
  3140. Normal
  3141. }; };
  3142. struct WarnAbout { enum What {
  3143. Nothing = 0x00,
  3144. NoAssertions = 0x01
  3145. }; };
  3146. struct ShowDurations { enum OrNot {
  3147. DefaultForReporter,
  3148. Always,
  3149. Never
  3150. }; };
  3151. struct RunTests { enum InWhatOrder {
  3152. InDeclarationOrder,
  3153. InLexicographicalOrder,
  3154. InRandomOrder
  3155. }; };
  3156. struct UseColour { enum YesOrNo {
  3157. Auto,
  3158. Yes,
  3159. No
  3160. }; };
  3161. struct WaitForKeypress { enum When {
  3162. Never,
  3163. BeforeStart = 1,
  3164. BeforeExit = 2,
  3165. BeforeStartAndExit = BeforeStart | BeforeExit
  3166. }; };
  3167. class TestSpec;
  3168. struct IConfig : IShared {
  3169. virtual ~IConfig();
  3170. virtual bool allowThrows() const = 0;
  3171. virtual std::ostream& stream() const = 0;
  3172. virtual std::string name() const = 0;
  3173. virtual bool includeSuccessfulResults() const = 0;
  3174. virtual bool shouldDebugBreak() const = 0;
  3175. virtual bool warnAboutMissingAssertions() const = 0;
  3176. virtual int abortAfter() const = 0;
  3177. virtual bool showInvisibles() const = 0;
  3178. virtual ShowDurations::OrNot showDurations() const = 0;
  3179. virtual TestSpec const& testSpec() const = 0;
  3180. virtual RunTests::InWhatOrder runOrder() const = 0;
  3181. virtual unsigned int rngSeed() const = 0;
  3182. virtual UseColour::YesOrNo useColour() const = 0;
  3183. virtual std::vector<std::string> const& getSectionsToRun() const = 0;
  3184. };
  3185. }
  3186. // #included from: catch_stream.h
  3187. #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
  3188. // #included from: catch_streambuf.h
  3189. #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
  3190. #include <streambuf>
  3191. namespace Catch {
  3192. class StreamBufBase : public std::streambuf {
  3193. public:
  3194. virtual ~StreamBufBase() CATCH_NOEXCEPT;
  3195. };
  3196. }
  3197. #include <streambuf>
  3198. #include <ostream>
  3199. #include <fstream>
  3200. #include <memory>
  3201. namespace Catch {
  3202. std::ostream& cout();
  3203. std::ostream& cerr();
  3204. std::ostream& clog();
  3205. struct IStream {
  3206. virtual ~IStream() CATCH_NOEXCEPT;
  3207. virtual std::ostream& stream() const = 0;
  3208. };
  3209. class FileStream : public IStream {
  3210. mutable std::ofstream m_ofs;
  3211. public:
  3212. FileStream( std::string const& filename );
  3213. virtual ~FileStream() CATCH_NOEXCEPT;
  3214. public: // IStream
  3215. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3216. };
  3217. class CoutStream : public IStream {
  3218. mutable std::ostream m_os;
  3219. public:
  3220. CoutStream();
  3221. virtual ~CoutStream() CATCH_NOEXCEPT;
  3222. public: // IStream
  3223. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3224. };
  3225. class DebugOutStream : public IStream {
  3226. CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
  3227. mutable std::ostream m_os;
  3228. public:
  3229. DebugOutStream();
  3230. virtual ~DebugOutStream() CATCH_NOEXCEPT;
  3231. public: // IStream
  3232. virtual std::ostream& stream() const CATCH_OVERRIDE;
  3233. };
  3234. }
  3235. #include <memory>
  3236. #include <vector>
  3237. #include <string>
  3238. #include <stdexcept>
  3239. #ifndef CATCH_CONFIG_CONSOLE_WIDTH
  3240. #define CATCH_CONFIG_CONSOLE_WIDTH 80
  3241. #endif
  3242. namespace Catch {
  3243. struct ConfigData {
  3244. ConfigData()
  3245. : listTests( false ),
  3246. listTags( false ),
  3247. listReporters( false ),
  3248. listTestNamesOnly( false ),
  3249. listExtraInfo( false ),
  3250. showSuccessfulTests( false ),
  3251. shouldDebugBreak( false ),
  3252. noThrow( false ),
  3253. showHelp( false ),
  3254. showInvisibles( false ),
  3255. filenamesAsTags( false ),
  3256. libIdentify( false ),
  3257. abortAfter( -1 ),
  3258. rngSeed( 0 ),
  3259. verbosity( Verbosity::Normal ),
  3260. warnings( WarnAbout::Nothing ),
  3261. showDurations( ShowDurations::DefaultForReporter ),
  3262. runOrder( RunTests::InDeclarationOrder ),
  3263. useColour( UseColour::Auto ),
  3264. waitForKeypress( WaitForKeypress::Never )
  3265. {}
  3266. bool listTests;
  3267. bool listTags;
  3268. bool listReporters;
  3269. bool listTestNamesOnly;
  3270. bool listExtraInfo;
  3271. bool showSuccessfulTests;
  3272. bool shouldDebugBreak;
  3273. bool noThrow;
  3274. bool showHelp;
  3275. bool showInvisibles;
  3276. bool filenamesAsTags;
  3277. bool libIdentify;
  3278. int abortAfter;
  3279. unsigned int rngSeed;
  3280. Verbosity::Level verbosity;
  3281. WarnAbout::What warnings;
  3282. ShowDurations::OrNot showDurations;
  3283. RunTests::InWhatOrder runOrder;
  3284. UseColour::YesOrNo useColour;
  3285. WaitForKeypress::When waitForKeypress;
  3286. std::string outputFilename;
  3287. std::string name;
  3288. std::string processName;
  3289. std::vector<std::string> reporterNames;
  3290. std::vector<std::string> testsOrTags;
  3291. std::vector<std::string> sectionsToRun;
  3292. };
  3293. class Config : public SharedImpl<IConfig> {
  3294. private:
  3295. Config( Config const& other );
  3296. Config& operator = ( Config const& other );
  3297. virtual void dummy();
  3298. public:
  3299. Config()
  3300. {}
  3301. Config( ConfigData const& data )
  3302. : m_data( data ),
  3303. m_stream( openStream() )
  3304. {
  3305. if( !data.testsOrTags.empty() ) {
  3306. TestSpecParser parser( ITagAliasRegistry::get() );
  3307. for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
  3308. parser.parse( data.testsOrTags[i] );
  3309. m_testSpec = parser.testSpec();
  3310. }
  3311. }
  3312. virtual ~Config() {}
  3313. std::string const& getFilename() const {
  3314. return m_data.outputFilename ;
  3315. }
  3316. bool listTests() const { return m_data.listTests; }
  3317. bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
  3318. bool listTags() const { return m_data.listTags; }
  3319. bool listReporters() const { return m_data.listReporters; }
  3320. bool listExtraInfo() const { return m_data.listExtraInfo; }
  3321. std::string getProcessName() const { return m_data.processName; }
  3322. std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
  3323. std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; }
  3324. virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; }
  3325. bool showHelp() const { return m_data.showHelp; }
  3326. // IConfig interface
  3327. virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; }
  3328. virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); }
  3329. virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; }
  3330. virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; }
  3331. virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; }
  3332. virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; }
  3333. virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; }
  3334. virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; }
  3335. virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; }
  3336. virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; }
  3337. virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; }
  3338. virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; }
  3339. private:
  3340. IStream const* openStream() {
  3341. if( m_data.outputFilename.empty() )
  3342. return new CoutStream();
  3343. else if( m_data.outputFilename[0] == '%' ) {
  3344. if( m_data.outputFilename == "%debug" )
  3345. return new DebugOutStream();
  3346. else
  3347. throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
  3348. }
  3349. else
  3350. return new FileStream( m_data.outputFilename );
  3351. }
  3352. ConfigData m_data;
  3353. CATCH_AUTO_PTR( IStream const ) m_stream;
  3354. TestSpec m_testSpec;
  3355. };
  3356. } // end namespace Catch
  3357. // #included from: catch_clara.h
  3358. #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
  3359. // Use Catch's value for console width (store Clara's off to the side, if present)
  3360. #ifdef CLARA_CONFIG_CONSOLE_WIDTH
  3361. #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
  3362. #undef CLARA_CONFIG_CONSOLE_WIDTH
  3363. #endif
  3364. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  3365. // Declare Clara inside the Catch namespace
  3366. #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
  3367. // #included from: ../external/clara.h
  3368. // Version 0.0.2.4
  3369. // Only use header guard if we are not using an outer namespace
  3370. #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
  3371. #ifndef STITCH_CLARA_OPEN_NAMESPACE
  3372. #define TWOBLUECUBES_CLARA_H_INCLUDED
  3373. #define STITCH_CLARA_OPEN_NAMESPACE
  3374. #define STITCH_CLARA_CLOSE_NAMESPACE
  3375. #else
  3376. #define STITCH_CLARA_CLOSE_NAMESPACE }
  3377. #endif
  3378. #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
  3379. // ----------- #included from tbc_text_format.h -----------
  3380. // Only use header guard if we are not using an outer namespace
  3381. #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
  3382. #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3383. #define TBC_TEXT_FORMAT_H_INCLUDED
  3384. #endif
  3385. #include <string>
  3386. #include <vector>
  3387. #include <sstream>
  3388. #include <algorithm>
  3389. #include <cctype>
  3390. // Use optional outer namespace
  3391. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3392. namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  3393. #endif
  3394. namespace Tbc {
  3395. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  3396. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  3397. #else
  3398. const unsigned int consoleWidth = 80;
  3399. #endif
  3400. struct TextAttributes {
  3401. TextAttributes()
  3402. : initialIndent( std::string::npos ),
  3403. indent( 0 ),
  3404. width( consoleWidth-1 ),
  3405. tabChar( '\t' )
  3406. {}
  3407. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  3408. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  3409. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  3410. TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
  3411. std::size_t initialIndent; // indent of first line, or npos
  3412. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  3413. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  3414. char tabChar; // If this char is seen the indent is changed to current pos
  3415. };
  3416. class Text {
  3417. public:
  3418. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  3419. : attr( _attr )
  3420. {
  3421. std::string wrappableChars = " [({.,/|\\-";
  3422. std::size_t indent = _attr.initialIndent != std::string::npos
  3423. ? _attr.initialIndent
  3424. : _attr.indent;
  3425. std::string remainder = _str;
  3426. while( !remainder.empty() ) {
  3427. if( lines.size() >= 1000 ) {
  3428. lines.push_back( "... message truncated due to excessive size" );
  3429. return;
  3430. }
  3431. std::size_t tabPos = std::string::npos;
  3432. std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
  3433. std::size_t pos = remainder.find_first_of( '\n' );
  3434. if( pos <= width ) {
  3435. width = pos;
  3436. }
  3437. pos = remainder.find_last_of( _attr.tabChar, width );
  3438. if( pos != std::string::npos ) {
  3439. tabPos = pos;
  3440. if( remainder[width] == '\n' )
  3441. width--;
  3442. remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
  3443. }
  3444. if( width == remainder.size() ) {
  3445. spliceLine( indent, remainder, width );
  3446. }
  3447. else if( remainder[width] == '\n' ) {
  3448. spliceLine( indent, remainder, width );
  3449. if( width <= 1 || remainder.size() != 1 )
  3450. remainder = remainder.substr( 1 );
  3451. indent = _attr.indent;
  3452. }
  3453. else {
  3454. pos = remainder.find_last_of( wrappableChars, width );
  3455. if( pos != std::string::npos && pos > 0 ) {
  3456. spliceLine( indent, remainder, pos );
  3457. if( remainder[0] == ' ' )
  3458. remainder = remainder.substr( 1 );
  3459. }
  3460. else {
  3461. spliceLine( indent, remainder, width-1 );
  3462. lines.back() += "-";
  3463. }
  3464. if( lines.size() == 1 )
  3465. indent = _attr.indent;
  3466. if( tabPos != std::string::npos )
  3467. indent += tabPos;
  3468. }
  3469. }
  3470. }
  3471. void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
  3472. lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
  3473. _remainder = _remainder.substr( _pos );
  3474. }
  3475. typedef std::vector<std::string>::const_iterator const_iterator;
  3476. const_iterator begin() const { return lines.begin(); }
  3477. const_iterator end() const { return lines.end(); }
  3478. std::string const& last() const { return lines.back(); }
  3479. std::size_t size() const { return lines.size(); }
  3480. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  3481. std::string toString() const {
  3482. std::ostringstream oss;
  3483. oss << *this;
  3484. return oss.str();
  3485. }
  3486. friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  3487. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  3488. it != itEnd; ++it ) {
  3489. if( it != _text.begin() )
  3490. _stream << "\n";
  3491. _stream << *it;
  3492. }
  3493. return _stream;
  3494. }
  3495. private:
  3496. std::string str;
  3497. TextAttributes attr;
  3498. std::vector<std::string> lines;
  3499. };
  3500. } // end namespace Tbc
  3501. #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  3502. } // end outer namespace
  3503. #endif
  3504. #endif // TBC_TEXT_FORMAT_H_INCLUDED
  3505. // ----------- end of #include from tbc_text_format.h -----------
  3506. // ........... back in clara.h
  3507. #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
  3508. // ----------- #included from clara_compilers.h -----------
  3509. #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3510. #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3511. // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
  3512. // The following features are defined:
  3513. //
  3514. // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
  3515. // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
  3516. // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
  3517. // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
  3518. // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
  3519. // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
  3520. // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
  3521. // In general each macro has a _NO_<feature name> form
  3522. // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
  3523. // Many features, at point of detection, define an _INTERNAL_ macro, so they
  3524. // can be combined, en-mass, with the _NO_ forms later.
  3525. // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
  3526. #ifdef __clang__
  3527. #if __has_feature(cxx_nullptr)
  3528. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3529. #endif
  3530. #if __has_feature(cxx_noexcept)
  3531. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3532. #endif
  3533. #endif // __clang__
  3534. ////////////////////////////////////////////////////////////////////////////////
  3535. // GCC
  3536. #ifdef __GNUC__
  3537. #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
  3538. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3539. #endif
  3540. // - otherwise more recent versions define __cplusplus >= 201103L
  3541. // and will get picked up below
  3542. #endif // __GNUC__
  3543. ////////////////////////////////////////////////////////////////////////////////
  3544. // Visual C++
  3545. #ifdef _MSC_VER
  3546. #if (_MSC_VER >= 1600)
  3547. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3548. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3549. #endif
  3550. #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
  3551. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3552. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3553. #endif
  3554. #endif // _MSC_VER
  3555. ////////////////////////////////////////////////////////////////////////////////
  3556. // C++ language feature support
  3557. // catch all support for C++11
  3558. #if defined(__cplusplus) && __cplusplus >= 201103L
  3559. #define CLARA_CPP11_OR_GREATER
  3560. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
  3561. #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
  3562. #endif
  3563. #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3564. #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
  3565. #endif
  3566. #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3567. #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
  3568. #endif
  3569. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
  3570. #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
  3571. #endif
  3572. #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
  3573. #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
  3574. #endif
  3575. #endif // __cplusplus >= 201103L
  3576. // Now set the actual defines based on the above + anything the user has configured
  3577. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3578. #define CLARA_CONFIG_CPP11_NULLPTR
  3579. #endif
  3580. #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
  3581. #define CLARA_CONFIG_CPP11_NOEXCEPT
  3582. #endif
  3583. #if defined(CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_NO_CPP11)
  3584. #define CLARA_CONFIG_CPP11_GENERATED_METHODS
  3585. #endif
  3586. #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
  3587. #define CLARA_CONFIG_CPP11_OVERRIDE
  3588. #endif
  3589. #if defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_UNIQUE_PTR) && !defined(CLARA_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_CPP11)
  3590. #define CLARA_CONFIG_CPP11_UNIQUE_PTR
  3591. #endif
  3592. // noexcept support:
  3593. #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
  3594. #define CLARA_NOEXCEPT noexcept
  3595. # define CLARA_NOEXCEPT_IS(x) noexcept(x)
  3596. #else
  3597. #define CLARA_NOEXCEPT throw()
  3598. # define CLARA_NOEXCEPT_IS(x)
  3599. #endif
  3600. // nullptr support
  3601. #ifdef CLARA_CONFIG_CPP11_NULLPTR
  3602. #define CLARA_NULL nullptr
  3603. #else
  3604. #define CLARA_NULL NULL
  3605. #endif
  3606. // override support
  3607. #ifdef CLARA_CONFIG_CPP11_OVERRIDE
  3608. #define CLARA_OVERRIDE override
  3609. #else
  3610. #define CLARA_OVERRIDE
  3611. #endif
  3612. // unique_ptr support
  3613. #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
  3614. # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
  3615. #else
  3616. # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
  3617. #endif
  3618. #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
  3619. // ----------- end of #include from clara_compilers.h -----------
  3620. // ........... back in clara.h
  3621. #include <map>
  3622. #include <stdexcept>
  3623. #include <memory>
  3624. #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  3625. #define CLARA_PLATFORM_WINDOWS
  3626. #endif
  3627. // Use optional outer namespace
  3628. #ifdef STITCH_CLARA_OPEN_NAMESPACE
  3629. STITCH_CLARA_OPEN_NAMESPACE
  3630. #endif
  3631. namespace Clara {
  3632. struct UnpositionalTag {};
  3633. extern UnpositionalTag _;
  3634. #ifdef CLARA_CONFIG_MAIN
  3635. UnpositionalTag _;
  3636. #endif
  3637. namespace Detail {
  3638. #ifdef CLARA_CONSOLE_WIDTH
  3639. const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
  3640. #else
  3641. const unsigned int consoleWidth = 80;
  3642. #endif
  3643. using namespace Tbc;
  3644. inline bool startsWith( std::string const& str, std::string const& prefix ) {
  3645. return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
  3646. }
  3647. template<typename T> struct RemoveConstRef{ typedef T type; };
  3648. template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
  3649. template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
  3650. template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
  3651. template<typename T> struct IsBool { static const bool value = false; };
  3652. template<> struct IsBool<bool> { static const bool value = true; };
  3653. template<typename T>
  3654. void convertInto( std::string const& _source, T& _dest ) {
  3655. std::stringstream ss;
  3656. ss << _source;
  3657. ss >> _dest;
  3658. if( ss.fail() )
  3659. throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
  3660. }
  3661. inline void convertInto( std::string const& _source, std::string& _dest ) {
  3662. _dest = _source;
  3663. }
  3664. char toLowerCh(char c) {
  3665. return static_cast<char>( std::tolower( c ) );
  3666. }
  3667. inline void convertInto( std::string const& _source, bool& _dest ) {
  3668. std::string sourceLC = _source;
  3669. std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
  3670. if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
  3671. _dest = true;
  3672. else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
  3673. _dest = false;
  3674. else
  3675. throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
  3676. }
  3677. template<typename ConfigT>
  3678. struct IArgFunction {
  3679. virtual ~IArgFunction() {}
  3680. #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
  3681. IArgFunction() = default;
  3682. IArgFunction( IArgFunction const& ) = default;
  3683. #endif
  3684. virtual void set( ConfigT& config, std::string const& value ) const = 0;
  3685. virtual bool takesArg() const = 0;
  3686. virtual IArgFunction* clone() const = 0;
  3687. };
  3688. template<typename ConfigT>
  3689. class BoundArgFunction {
  3690. public:
  3691. BoundArgFunction() : functionObj( CLARA_NULL ) {}
  3692. BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
  3693. BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
  3694. BoundArgFunction& operator = ( BoundArgFunction const& other ) {
  3695. IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
  3696. delete functionObj;
  3697. functionObj = newFunctionObj;
  3698. return *this;
  3699. }
  3700. ~BoundArgFunction() { delete functionObj; }
  3701. void set( ConfigT& config, std::string const& value ) const {
  3702. functionObj->set( config, value );
  3703. }
  3704. bool takesArg() const { return functionObj->takesArg(); }
  3705. bool isSet() const {
  3706. return functionObj != CLARA_NULL;
  3707. }
  3708. private:
  3709. IArgFunction<ConfigT>* functionObj;
  3710. };
  3711. template<typename C>
  3712. struct NullBinder : IArgFunction<C>{
  3713. virtual void set( C&, std::string const& ) const {}
  3714. virtual bool takesArg() const { return true; }
  3715. virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
  3716. };
  3717. template<typename C, typename M>
  3718. struct BoundDataMember : IArgFunction<C>{
  3719. BoundDataMember( M C::* _member ) : member( _member ) {}
  3720. virtual void set( C& p, std::string const& stringValue ) const {
  3721. convertInto( stringValue, p.*member );
  3722. }
  3723. virtual bool takesArg() const { return !IsBool<M>::value; }
  3724. virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
  3725. M C::* member;
  3726. };
  3727. template<typename C, typename M>
  3728. struct BoundUnaryMethod : IArgFunction<C>{
  3729. BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
  3730. virtual void set( C& p, std::string const& stringValue ) const {
  3731. typename RemoveConstRef<M>::type value;
  3732. convertInto( stringValue, value );
  3733. (p.*member)( value );
  3734. }
  3735. virtual bool takesArg() const { return !IsBool<M>::value; }
  3736. virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
  3737. void (C::*member)( M );
  3738. };
  3739. template<typename C>
  3740. struct BoundNullaryMethod : IArgFunction<C>{
  3741. BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
  3742. virtual void set( C& p, std::string const& stringValue ) const {
  3743. bool value;
  3744. convertInto( stringValue, value );
  3745. if( value )
  3746. (p.*member)();
  3747. }
  3748. virtual bool takesArg() const { return false; }
  3749. virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
  3750. void (C::*member)();
  3751. };
  3752. template<typename C>
  3753. struct BoundUnaryFunction : IArgFunction<C>{
  3754. BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
  3755. virtual void set( C& obj, std::string const& stringValue ) const {
  3756. bool value;
  3757. convertInto( stringValue, value );
  3758. if( value )
  3759. function( obj );
  3760. }
  3761. virtual bool takesArg() const { return false; }
  3762. virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
  3763. void (*function)( C& );
  3764. };
  3765. template<typename C, typename T>
  3766. struct BoundBinaryFunction : IArgFunction<C>{
  3767. BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
  3768. virtual void set( C& obj, std::string const& stringValue ) const {
  3769. typename RemoveConstRef<T>::type value;
  3770. convertInto( stringValue, value );
  3771. function( obj, value );
  3772. }
  3773. virtual bool takesArg() const { return !IsBool<T>::value; }
  3774. virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
  3775. void (*function)( C&, T );
  3776. };
  3777. } // namespace Detail
  3778. inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
  3779. std::vector<std::string> args( static_cast<std::size_t>( argc ) );
  3780. for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
  3781. args[i] = argv[i];
  3782. return args;
  3783. }
  3784. class Parser {
  3785. enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
  3786. Mode mode;
  3787. std::size_t from;
  3788. bool inQuotes;
  3789. public:
  3790. struct Token {
  3791. enum Type { Positional, ShortOpt, LongOpt };
  3792. Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
  3793. Type type;
  3794. std::string data;
  3795. };
  3796. Parser() : mode( None ), from( 0 ), inQuotes( false ){}
  3797. void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
  3798. const std::string doubleDash = "--";
  3799. for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
  3800. parseIntoTokens( args[i], tokens);
  3801. }
  3802. void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
  3803. for( std::size_t i = 0; i < arg.size(); ++i ) {
  3804. char c = arg[i];
  3805. if( c == '"' )
  3806. inQuotes = !inQuotes;
  3807. mode = handleMode( i, c, arg, tokens );
  3808. }
  3809. mode = handleMode( arg.size(), '\0', arg, tokens );
  3810. }
  3811. Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3812. switch( mode ) {
  3813. case None: return handleNone( i, c );
  3814. case MaybeShortOpt: return handleMaybeShortOpt( i, c );
  3815. case ShortOpt:
  3816. case LongOpt:
  3817. case SlashOpt: return handleOpt( i, c, arg, tokens );
  3818. case Positional: return handlePositional( i, c, arg, tokens );
  3819. default: throw std::logic_error( "Unknown mode" );
  3820. }
  3821. }
  3822. Mode handleNone( std::size_t i, char c ) {
  3823. if( inQuotes ) {
  3824. from = i;
  3825. return Positional;
  3826. }
  3827. switch( c ) {
  3828. case '-': return MaybeShortOpt;
  3829. #ifdef CLARA_PLATFORM_WINDOWS
  3830. case '/': from = i+1; return SlashOpt;
  3831. #endif
  3832. default: from = i; return Positional;
  3833. }
  3834. }
  3835. Mode handleMaybeShortOpt( std::size_t i, char c ) {
  3836. switch( c ) {
  3837. case '-': from = i+1; return LongOpt;
  3838. default: from = i; return ShortOpt;
  3839. }
  3840. }
  3841. Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3842. if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
  3843. return mode;
  3844. std::string optName = arg.substr( from, i-from );
  3845. if( mode == ShortOpt )
  3846. for( std::size_t j = 0; j < optName.size(); ++j )
  3847. tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
  3848. else if( mode == SlashOpt && optName.size() == 1 )
  3849. tokens.push_back( Token( Token::ShortOpt, optName ) );
  3850. else
  3851. tokens.push_back( Token( Token::LongOpt, optName ) );
  3852. return None;
  3853. }
  3854. Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
  3855. if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
  3856. return mode;
  3857. std::string data = arg.substr( from, i-from );
  3858. tokens.push_back( Token( Token::Positional, data ) );
  3859. return None;
  3860. }
  3861. };
  3862. template<typename ConfigT>
  3863. struct CommonArgProperties {
  3864. CommonArgProperties() {}
  3865. CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
  3866. Detail::BoundArgFunction<ConfigT> boundField;
  3867. std::string description;
  3868. std::string detail;
  3869. std::string placeholder; // Only value if boundField takes an arg
  3870. bool takesArg() const {
  3871. return !placeholder.empty();
  3872. }
  3873. void validate() const {
  3874. if( !boundField.isSet() )
  3875. throw std::logic_error( "option not bound" );
  3876. }
  3877. };
  3878. struct OptionArgProperties {
  3879. std::vector<std::string> shortNames;
  3880. std::string longName;
  3881. bool hasShortName( std::string const& shortName ) const {
  3882. return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
  3883. }
  3884. bool hasLongName( std::string const& _longName ) const {
  3885. return _longName == longName;
  3886. }
  3887. };
  3888. struct PositionalArgProperties {
  3889. PositionalArgProperties() : position( -1 ) {}
  3890. int position; // -1 means non-positional (floating)
  3891. bool isFixedPositional() const {
  3892. return position != -1;
  3893. }
  3894. };
  3895. template<typename ConfigT>
  3896. class CommandLine {
  3897. struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
  3898. Arg() {}
  3899. Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
  3900. using CommonArgProperties<ConfigT>::placeholder; // !TBD
  3901. std::string dbgName() const {
  3902. if( !longName.empty() )
  3903. return "--" + longName;
  3904. if( !shortNames.empty() )
  3905. return "-" + shortNames[0];
  3906. return "positional args";
  3907. }
  3908. std::string commands() const {
  3909. std::ostringstream oss;
  3910. bool first = true;
  3911. std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
  3912. for(; it != itEnd; ++it ) {
  3913. if( first )
  3914. first = false;
  3915. else
  3916. oss << ", ";
  3917. oss << "-" << *it;
  3918. }
  3919. if( !longName.empty() ) {
  3920. if( !first )
  3921. oss << ", ";
  3922. oss << "--" << longName;
  3923. }
  3924. if( !placeholder.empty() )
  3925. oss << " <" << placeholder << ">";
  3926. return oss.str();
  3927. }
  3928. };
  3929. typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
  3930. friend void addOptName( Arg& arg, std::string const& optName )
  3931. {
  3932. if( optName.empty() )
  3933. return;
  3934. if( Detail::startsWith( optName, "--" ) ) {
  3935. if( !arg.longName.empty() )
  3936. throw std::logic_error( "Only one long opt may be specified. '"
  3937. + arg.longName
  3938. + "' already specified, now attempting to add '"
  3939. + optName + "'" );
  3940. arg.longName = optName.substr( 2 );
  3941. }
  3942. else if( Detail::startsWith( optName, "-" ) )
  3943. arg.shortNames.push_back( optName.substr( 1 ) );
  3944. else
  3945. throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
  3946. }
  3947. friend void setPositionalArg( Arg& arg, int position )
  3948. {
  3949. arg.position = position;
  3950. }
  3951. class ArgBuilder {
  3952. public:
  3953. ArgBuilder( Arg* arg ) : m_arg( arg ) {}
  3954. // Bind a non-boolean data member (requires placeholder string)
  3955. template<typename C, typename M>
  3956. void bind( M C::* field, std::string const& placeholder ) {
  3957. m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
  3958. m_arg->placeholder = placeholder;
  3959. }
  3960. // Bind a boolean data member (no placeholder required)
  3961. template<typename C>
  3962. void bind( bool C::* field ) {
  3963. m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
  3964. }
  3965. // Bind a method taking a single, non-boolean argument (requires a placeholder string)
  3966. template<typename C, typename M>
  3967. void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
  3968. m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
  3969. m_arg->placeholder = placeholder;
  3970. }
  3971. // Bind a method taking a single, boolean argument (no placeholder string required)
  3972. template<typename C>
  3973. void bind( void (C::* unaryMethod)( bool ) ) {
  3974. m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
  3975. }
  3976. // Bind a method that takes no arguments (will be called if opt is present)
  3977. template<typename C>
  3978. void bind( void (C::* nullaryMethod)() ) {
  3979. m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
  3980. }
  3981. // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
  3982. template<typename C>
  3983. void bind( void (* unaryFunction)( C& ) ) {
  3984. m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
  3985. }
  3986. // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
  3987. template<typename C, typename T>
  3988. void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
  3989. m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
  3990. m_arg->placeholder = placeholder;
  3991. }
  3992. ArgBuilder& describe( std::string const& description ) {
  3993. m_arg->description = description;
  3994. return *this;
  3995. }
  3996. ArgBuilder& detail( std::string const& detail ) {
  3997. m_arg->detail = detail;
  3998. return *this;
  3999. }
  4000. protected:
  4001. Arg* m_arg;
  4002. };
  4003. class OptBuilder : public ArgBuilder {
  4004. public:
  4005. OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
  4006. OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
  4007. OptBuilder& operator[]( std::string const& optName ) {
  4008. addOptName( *ArgBuilder::m_arg, optName );
  4009. return *this;
  4010. }
  4011. };
  4012. public:
  4013. CommandLine()
  4014. : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
  4015. m_highestSpecifiedArgPosition( 0 ),
  4016. m_throwOnUnrecognisedTokens( false )
  4017. {}
  4018. CommandLine( CommandLine const& other )
  4019. : m_boundProcessName( other.m_boundProcessName ),
  4020. m_options ( other.m_options ),
  4021. m_positionalArgs( other.m_positionalArgs ),
  4022. m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
  4023. m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
  4024. {
  4025. if( other.m_floatingArg.get() )
  4026. m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
  4027. }
  4028. CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
  4029. m_throwOnUnrecognisedTokens = shouldThrow;
  4030. return *this;
  4031. }
  4032. OptBuilder operator[]( std::string const& optName ) {
  4033. m_options.push_back( Arg() );
  4034. addOptName( m_options.back(), optName );
  4035. OptBuilder builder( &m_options.back() );
  4036. return builder;
  4037. }
  4038. ArgBuilder operator[]( int position ) {
  4039. m_positionalArgs.insert( std::make_pair( position, Arg() ) );
  4040. if( position > m_highestSpecifiedArgPosition )
  4041. m_highestSpecifiedArgPosition = position;
  4042. setPositionalArg( m_positionalArgs[position], position );
  4043. ArgBuilder builder( &m_positionalArgs[position] );
  4044. return builder;
  4045. }
  4046. // Invoke this with the _ instance
  4047. ArgBuilder operator[]( UnpositionalTag ) {
  4048. if( m_floatingArg.get() )
  4049. throw std::logic_error( "Only one unpositional argument can be added" );
  4050. m_floatingArg.reset( new Arg() );
  4051. ArgBuilder builder( m_floatingArg.get() );
  4052. return builder;
  4053. }
  4054. template<typename C, typename M>
  4055. void bindProcessName( M C::* field ) {
  4056. m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
  4057. }
  4058. template<typename C, typename M>
  4059. void bindProcessName( void (C::*_unaryMethod)( M ) ) {
  4060. m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
  4061. }
  4062. void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
  4063. typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
  4064. std::size_t maxWidth = 0;
  4065. for( it = itBegin; it != itEnd; ++it )
  4066. maxWidth = (std::max)( maxWidth, it->commands().size() );
  4067. for( it = itBegin; it != itEnd; ++it ) {
  4068. Detail::Text usage( it->commands(), Detail::TextAttributes()
  4069. .setWidth( maxWidth+indent )
  4070. .setIndent( indent ) );
  4071. Detail::Text desc( it->description, Detail::TextAttributes()
  4072. .setWidth( width - maxWidth - 3 ) );
  4073. for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
  4074. std::string usageCol = i < usage.size() ? usage[i] : "";
  4075. os << usageCol;
  4076. if( i < desc.size() && !desc[i].empty() )
  4077. os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
  4078. << desc[i];
  4079. os << "\n";
  4080. }
  4081. }
  4082. }
  4083. std::string optUsage() const {
  4084. std::ostringstream oss;
  4085. optUsage( oss );
  4086. return oss.str();
  4087. }
  4088. void argSynopsis( std::ostream& os ) const {
  4089. for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
  4090. if( i > 1 )
  4091. os << " ";
  4092. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
  4093. if( it != m_positionalArgs.end() )
  4094. os << "<" << it->second.placeholder << ">";
  4095. else if( m_floatingArg.get() )
  4096. os << "<" << m_floatingArg->placeholder << ">";
  4097. else
  4098. throw std::logic_error( "non consecutive positional arguments with no floating args" );
  4099. }
  4100. // !TBD No indication of mandatory args
  4101. if( m_floatingArg.get() ) {
  4102. if( m_highestSpecifiedArgPosition > 1 )
  4103. os << " ";
  4104. os << "[<" << m_floatingArg->placeholder << "> ...]";
  4105. }
  4106. }
  4107. std::string argSynopsis() const {
  4108. std::ostringstream oss;
  4109. argSynopsis( oss );
  4110. return oss.str();
  4111. }
  4112. void usage( std::ostream& os, std::string const& procName ) const {
  4113. validate();
  4114. os << "usage:\n " << procName << " ";
  4115. argSynopsis( os );
  4116. if( !m_options.empty() ) {
  4117. os << " [options]\n\nwhere options are: \n";
  4118. optUsage( os, 2 );
  4119. }
  4120. os << "\n";
  4121. }
  4122. std::string usage( std::string const& procName ) const {
  4123. std::ostringstream oss;
  4124. usage( oss, procName );
  4125. return oss.str();
  4126. }
  4127. ConfigT parse( std::vector<std::string> const& args ) const {
  4128. ConfigT config;
  4129. parseInto( args, config );
  4130. return config;
  4131. }
  4132. std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
  4133. std::string processName = args.empty() ? std::string() : args[0];
  4134. std::size_t lastSlash = processName.find_last_of( "/\\" );
  4135. if( lastSlash != std::string::npos )
  4136. processName = processName.substr( lastSlash+1 );
  4137. m_boundProcessName.set( config, processName );
  4138. std::vector<Parser::Token> tokens;
  4139. Parser parser;
  4140. parser.parseIntoTokens( args, tokens );
  4141. return populate( tokens, config );
  4142. }
  4143. std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4144. validate();
  4145. std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
  4146. unusedTokens = populateFixedArgs( unusedTokens, config );
  4147. unusedTokens = populateFloatingArgs( unusedTokens, config );
  4148. return unusedTokens;
  4149. }
  4150. std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4151. std::vector<Parser::Token> unusedTokens;
  4152. std::vector<std::string> errors;
  4153. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4154. Parser::Token const& token = tokens[i];
  4155. typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
  4156. for(; it != itEnd; ++it ) {
  4157. Arg const& arg = *it;
  4158. try {
  4159. if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
  4160. ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
  4161. if( arg.takesArg() ) {
  4162. if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
  4163. errors.push_back( "Expected argument to option: " + token.data );
  4164. else
  4165. arg.boundField.set( config, tokens[++i].data );
  4166. }
  4167. else {
  4168. arg.boundField.set( config, "true" );
  4169. }
  4170. break;
  4171. }
  4172. }
  4173. catch( std::exception& ex ) {
  4174. errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
  4175. }
  4176. }
  4177. if( it == itEnd ) {
  4178. if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
  4179. unusedTokens.push_back( token );
  4180. else if( errors.empty() && m_throwOnUnrecognisedTokens )
  4181. errors.push_back( "unrecognised option: " + token.data );
  4182. }
  4183. }
  4184. if( !errors.empty() ) {
  4185. std::ostringstream oss;
  4186. for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
  4187. it != itEnd;
  4188. ++it ) {
  4189. if( it != errors.begin() )
  4190. oss << "\n";
  4191. oss << *it;
  4192. }
  4193. throw std::runtime_error( oss.str() );
  4194. }
  4195. return unusedTokens;
  4196. }
  4197. std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4198. std::vector<Parser::Token> unusedTokens;
  4199. int position = 1;
  4200. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4201. Parser::Token const& token = tokens[i];
  4202. typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
  4203. if( it != m_positionalArgs.end() )
  4204. it->second.boundField.set( config, token.data );
  4205. else
  4206. unusedTokens.push_back( token );
  4207. if( token.type == Parser::Token::Positional )
  4208. position++;
  4209. }
  4210. return unusedTokens;
  4211. }
  4212. std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
  4213. if( !m_floatingArg.get() )
  4214. return tokens;
  4215. std::vector<Parser::Token> unusedTokens;
  4216. for( std::size_t i = 0; i < tokens.size(); ++i ) {
  4217. Parser::Token const& token = tokens[i];
  4218. if( token.type == Parser::Token::Positional )
  4219. m_floatingArg->boundField.set( config, token.data );
  4220. else
  4221. unusedTokens.push_back( token );
  4222. }
  4223. return unusedTokens;
  4224. }
  4225. void validate() const
  4226. {
  4227. if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
  4228. throw std::logic_error( "No options or arguments specified" );
  4229. for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
  4230. itEnd = m_options.end();
  4231. it != itEnd; ++it )
  4232. it->validate();
  4233. }
  4234. private:
  4235. Detail::BoundArgFunction<ConfigT> m_boundProcessName;
  4236. std::vector<Arg> m_options;
  4237. std::map<int, Arg> m_positionalArgs;
  4238. ArgAutoPtr m_floatingArg;
  4239. int m_highestSpecifiedArgPosition;
  4240. bool m_throwOnUnrecognisedTokens;
  4241. };
  4242. } // end namespace Clara
  4243. STITCH_CLARA_CLOSE_NAMESPACE
  4244. #undef STITCH_CLARA_OPEN_NAMESPACE
  4245. #undef STITCH_CLARA_CLOSE_NAMESPACE
  4246. #endif // TWOBLUECUBES_CLARA_H_INCLUDED
  4247. #undef STITCH_CLARA_OPEN_NAMESPACE
  4248. // Restore Clara's value for console width, if present
  4249. #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4250. #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4251. #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
  4252. #endif
  4253. #include <fstream>
  4254. #include <ctime>
  4255. namespace Catch {
  4256. inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
  4257. inline void abortAfterX( ConfigData& config, int x ) {
  4258. if( x < 1 )
  4259. throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
  4260. config.abortAfter = x;
  4261. }
  4262. inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
  4263. inline void addSectionToRun( ConfigData& config, std::string const& sectionName ) { config.sectionsToRun.push_back( sectionName ); }
  4264. inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
  4265. inline void addWarning( ConfigData& config, std::string const& _warning ) {
  4266. if( _warning == "NoAssertions" )
  4267. config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
  4268. else
  4269. throw std::runtime_error( "Unrecognised warning: '" + _warning + '\'' );
  4270. }
  4271. inline void setOrder( ConfigData& config, std::string const& order ) {
  4272. if( startsWith( "declared", order ) )
  4273. config.runOrder = RunTests::InDeclarationOrder;
  4274. else if( startsWith( "lexical", order ) )
  4275. config.runOrder = RunTests::InLexicographicalOrder;
  4276. else if( startsWith( "random", order ) )
  4277. config.runOrder = RunTests::InRandomOrder;
  4278. else
  4279. throw std::runtime_error( "Unrecognised ordering: '" + order + '\'' );
  4280. }
  4281. inline void setRngSeed( ConfigData& config, std::string const& seed ) {
  4282. if( seed == "time" ) {
  4283. config.rngSeed = static_cast<unsigned int>( std::time(0) );
  4284. }
  4285. else {
  4286. std::stringstream ss;
  4287. ss << seed;
  4288. ss >> config.rngSeed;
  4289. if( ss.fail() )
  4290. throw std::runtime_error( "Argument to --rng-seed should be the word 'time' or a number" );
  4291. }
  4292. }
  4293. inline void setVerbosity( ConfigData& config, int level ) {
  4294. // !TBD: accept strings?
  4295. config.verbosity = static_cast<Verbosity::Level>( level );
  4296. }
  4297. inline void setShowDurations( ConfigData& config, bool _showDurations ) {
  4298. config.showDurations = _showDurations
  4299. ? ShowDurations::Always
  4300. : ShowDurations::Never;
  4301. }
  4302. inline void setUseColour( ConfigData& config, std::string const& value ) {
  4303. std::string mode = toLower( value );
  4304. if( mode == "yes" )
  4305. config.useColour = UseColour::Yes;
  4306. else if( mode == "no" )
  4307. config.useColour = UseColour::No;
  4308. else if( mode == "auto" )
  4309. config.useColour = UseColour::Auto;
  4310. else
  4311. throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
  4312. }
  4313. inline void setWaitForKeypress( ConfigData& config, std::string const& keypress ) {
  4314. std::string keypressLc = toLower( keypress );
  4315. if( keypressLc == "start" )
  4316. config.waitForKeypress = WaitForKeypress::BeforeStart;
  4317. else if( keypressLc == "exit" )
  4318. config.waitForKeypress = WaitForKeypress::BeforeExit;
  4319. else if( keypressLc == "both" )
  4320. config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
  4321. else
  4322. throw std::runtime_error( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
  4323. };
  4324. inline void forceColour( ConfigData& config ) {
  4325. config.useColour = UseColour::Yes;
  4326. }
  4327. inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
  4328. std::ifstream f( _filename.c_str() );
  4329. if( !f.is_open() )
  4330. throw std::domain_error( "Unable to load input file: " + _filename );
  4331. std::string line;
  4332. while( std::getline( f, line ) ) {
  4333. line = trim(line);
  4334. if( !line.empty() && !startsWith( line, '#' ) ) {
  4335. if( !startsWith( line, '"' ) )
  4336. line = '"' + line + '"';
  4337. addTestOrTags( config, line + ',' );
  4338. }
  4339. }
  4340. }
  4341. inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
  4342. using namespace Clara;
  4343. CommandLine<ConfigData> cli;
  4344. cli.bindProcessName( &ConfigData::processName );
  4345. cli["-?"]["-h"]["--help"]
  4346. .describe( "display usage information" )
  4347. .bind( &ConfigData::showHelp );
  4348. cli["-l"]["--list-tests"]
  4349. .describe( "list all/matching test cases" )
  4350. .bind( &ConfigData::listTests );
  4351. cli["-t"]["--list-tags"]
  4352. .describe( "list all/matching tags" )
  4353. .bind( &ConfigData::listTags );
  4354. cli["-s"]["--success"]
  4355. .describe( "include successful tests in output" )
  4356. .bind( &ConfigData::showSuccessfulTests );
  4357. cli["-b"]["--break"]
  4358. .describe( "break into debugger on failure" )
  4359. .bind( &ConfigData::shouldDebugBreak );
  4360. cli["-e"]["--nothrow"]
  4361. .describe( "skip exception tests" )
  4362. .bind( &ConfigData::noThrow );
  4363. cli["-i"]["--invisibles"]
  4364. .describe( "show invisibles (tabs, newlines)" )
  4365. .bind( &ConfigData::showInvisibles );
  4366. cli["-o"]["--out"]
  4367. .describe( "output filename" )
  4368. .bind( &ConfigData::outputFilename, "filename" );
  4369. cli["-r"]["--reporter"]
  4370. // .placeholder( "name[:filename]" )
  4371. .describe( "reporter to use (defaults to console)" )
  4372. .bind( &addReporterName, "name" );
  4373. cli["-n"]["--name"]
  4374. .describe( "suite name" )
  4375. .bind( &ConfigData::name, "name" );
  4376. cli["-a"]["--abort"]
  4377. .describe( "abort at first failure" )
  4378. .bind( &abortAfterFirst );
  4379. cli["-x"]["--abortx"]
  4380. .describe( "abort after x failures" )
  4381. .bind( &abortAfterX, "no. failures" );
  4382. cli["-w"]["--warn"]
  4383. .describe( "enable warnings" )
  4384. .bind( &addWarning, "warning name" );
  4385. // - needs updating if reinstated
  4386. // cli.into( &setVerbosity )
  4387. // .describe( "level of verbosity (0=no output)" )
  4388. // .shortOpt( "v")
  4389. // .longOpt( "verbosity" )
  4390. // .placeholder( "level" );
  4391. cli[_]
  4392. .describe( "which test or tests to use" )
  4393. .bind( &addTestOrTags, "test name, pattern or tags" );
  4394. cli["-d"]["--durations"]
  4395. .describe( "show test durations" )
  4396. .bind( &setShowDurations, "yes|no" );
  4397. cli["-f"]["--input-file"]
  4398. .describe( "load test names to run from a file" )
  4399. .bind( &loadTestNamesFromFile, "filename" );
  4400. cli["-#"]["--filenames-as-tags"]
  4401. .describe( "adds a tag for the filename" )
  4402. .bind( &ConfigData::filenamesAsTags );
  4403. cli["-c"]["--section"]
  4404. .describe( "specify section to run" )
  4405. .bind( &addSectionToRun, "section name" );
  4406. // Less common commands which don't have a short form
  4407. cli["--list-test-names-only"]
  4408. .describe( "list all/matching test cases names only" )
  4409. .bind( &ConfigData::listTestNamesOnly );
  4410. cli["--list-extra-info"]
  4411. .describe( "list all/matching test cases with more info" )
  4412. .bind( &ConfigData::listExtraInfo );
  4413. cli["--list-reporters"]
  4414. .describe( "list all reporters" )
  4415. .bind( &ConfigData::listReporters );
  4416. cli["--order"]
  4417. .describe( "test case order (defaults to decl)" )
  4418. .bind( &setOrder, "decl|lex|rand" );
  4419. cli["--rng-seed"]
  4420. .describe( "set a specific seed for random numbers" )
  4421. .bind( &setRngSeed, "'time'|number" );
  4422. cli["--force-colour"]
  4423. .describe( "force colourised output (deprecated)" )
  4424. .bind( &forceColour );
  4425. cli["--use-colour"]
  4426. .describe( "should output be colourised" )
  4427. .bind( &setUseColour, "yes|no" );
  4428. cli["--libidentify"]
  4429. .describe( "report name and version according to libidentify standard" )
  4430. .bind( &ConfigData::libIdentify );
  4431. cli["--wait-for-keypress"]
  4432. .describe( "waits for a keypress before exiting" )
  4433. .bind( &setWaitForKeypress, "start|exit|both" );
  4434. return cli;
  4435. }
  4436. } // end namespace Catch
  4437. // #included from: internal/catch_list.hpp
  4438. #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
  4439. // #included from: catch_text.h
  4440. #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
  4441. #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
  4442. #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
  4443. // #included from: ../external/tbc_text_format.h
  4444. // Only use header guard if we are not using an outer namespace
  4445. #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4446. # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4447. # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4448. # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4449. # endif
  4450. # else
  4451. # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
  4452. # endif
  4453. #endif
  4454. #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4455. #include <string>
  4456. #include <vector>
  4457. #include <sstream>
  4458. // Use optional outer namespace
  4459. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4460. namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
  4461. #endif
  4462. namespace Tbc {
  4463. #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
  4464. const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
  4465. #else
  4466. const unsigned int consoleWidth = 80;
  4467. #endif
  4468. struct TextAttributes {
  4469. TextAttributes()
  4470. : initialIndent( std::string::npos ),
  4471. indent( 0 ),
  4472. width( consoleWidth-1 )
  4473. {}
  4474. TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
  4475. TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
  4476. TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
  4477. std::size_t initialIndent; // indent of first line, or npos
  4478. std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
  4479. std::size_t width; // maximum width of text, including indent. Longer text will wrap
  4480. };
  4481. class Text {
  4482. public:
  4483. Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
  4484. : attr( _attr )
  4485. {
  4486. const std::string wrappableBeforeChars = "[({<\t";
  4487. const std::string wrappableAfterChars = "])}>-,./|\\";
  4488. const std::string wrappableInsteadOfChars = " \n\r";
  4489. std::string indent = _attr.initialIndent != std::string::npos
  4490. ? std::string( _attr.initialIndent, ' ' )
  4491. : std::string( _attr.indent, ' ' );
  4492. typedef std::string::const_iterator iterator;
  4493. iterator it = _str.begin();
  4494. const iterator strEnd = _str.end();
  4495. while( it != strEnd ) {
  4496. if( lines.size() >= 1000 ) {
  4497. lines.push_back( "... message truncated due to excessive size" );
  4498. return;
  4499. }
  4500. std::string suffix;
  4501. std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
  4502. iterator itEnd = it+width;
  4503. iterator itNext = _str.end();
  4504. iterator itNewLine = std::find( it, itEnd, '\n' );
  4505. if( itNewLine != itEnd )
  4506. itEnd = itNewLine;
  4507. if( itEnd != strEnd ) {
  4508. bool foundWrapPoint = false;
  4509. iterator findIt = itEnd;
  4510. do {
  4511. if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
  4512. itEnd = findIt+1;
  4513. itNext = findIt+1;
  4514. foundWrapPoint = true;
  4515. }
  4516. else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
  4517. itEnd = findIt;
  4518. itNext = findIt;
  4519. foundWrapPoint = true;
  4520. }
  4521. else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
  4522. itNext = findIt+1;
  4523. itEnd = findIt;
  4524. foundWrapPoint = true;
  4525. }
  4526. if( findIt == it )
  4527. break;
  4528. else
  4529. --findIt;
  4530. }
  4531. while( !foundWrapPoint );
  4532. if( !foundWrapPoint ) {
  4533. // No good wrap char, so we'll break mid word and add a hyphen
  4534. --itEnd;
  4535. itNext = itEnd;
  4536. suffix = "-";
  4537. }
  4538. else {
  4539. while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
  4540. --itEnd;
  4541. }
  4542. }
  4543. lines.push_back( indent + std::string( it, itEnd ) + suffix );
  4544. if( indent.size() != _attr.indent )
  4545. indent = std::string( _attr.indent, ' ' );
  4546. it = itNext;
  4547. }
  4548. }
  4549. typedef std::vector<std::string>::const_iterator const_iterator;
  4550. const_iterator begin() const { return lines.begin(); }
  4551. const_iterator end() const { return lines.end(); }
  4552. std::string const& last() const { return lines.back(); }
  4553. std::size_t size() const { return lines.size(); }
  4554. std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
  4555. std::string toString() const {
  4556. std::ostringstream oss;
  4557. oss << *this;
  4558. return oss.str();
  4559. }
  4560. inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
  4561. for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
  4562. it != itEnd; ++it ) {
  4563. if( it != _text.begin() )
  4564. _stream << "\n";
  4565. _stream << *it;
  4566. }
  4567. return _stream;
  4568. }
  4569. private:
  4570. std::string str;
  4571. TextAttributes attr;
  4572. std::vector<std::string> lines;
  4573. };
  4574. } // end namespace Tbc
  4575. #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4576. } // end outer namespace
  4577. #endif
  4578. #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
  4579. #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
  4580. namespace Catch {
  4581. using Tbc::Text;
  4582. using Tbc::TextAttributes;
  4583. }
  4584. // #included from: catch_console_colour.hpp
  4585. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  4586. namespace Catch {
  4587. struct Colour {
  4588. enum Code {
  4589. None = 0,
  4590. White,
  4591. Red,
  4592. Green,
  4593. Blue,
  4594. Cyan,
  4595. Yellow,
  4596. Grey,
  4597. Bright = 0x10,
  4598. BrightRed = Bright | Red,
  4599. BrightGreen = Bright | Green,
  4600. LightGrey = Bright | Grey,
  4601. BrightWhite = Bright | White,
  4602. // By intention
  4603. FileName = LightGrey,
  4604. Warning = Yellow,
  4605. ResultError = BrightRed,
  4606. ResultSuccess = BrightGreen,
  4607. ResultExpectedFailure = Warning,
  4608. Error = BrightRed,
  4609. Success = Green,
  4610. OriginalExpression = Cyan,
  4611. ReconstructedExpression = Yellow,
  4612. SecondaryText = LightGrey,
  4613. Headers = White
  4614. };
  4615. // Use constructed object for RAII guard
  4616. Colour( Code _colourCode );
  4617. Colour( Colour const& other );
  4618. ~Colour();
  4619. // Use static method for one-shot changes
  4620. static void use( Code _colourCode );
  4621. private:
  4622. bool m_moved;
  4623. };
  4624. inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
  4625. } // end namespace Catch
  4626. // #included from: catch_interfaces_reporter.h
  4627. #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
  4628. #include <string>
  4629. #include <ostream>
  4630. #include <map>
  4631. namespace Catch
  4632. {
  4633. struct ReporterConfig {
  4634. explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
  4635. : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
  4636. ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
  4637. : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
  4638. std::ostream& stream() const { return *m_stream; }
  4639. Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
  4640. private:
  4641. std::ostream* m_stream;
  4642. Ptr<IConfig const> m_fullConfig;
  4643. };
  4644. struct ReporterPreferences {
  4645. ReporterPreferences()
  4646. : shouldRedirectStdOut( false )
  4647. {}
  4648. bool shouldRedirectStdOut;
  4649. };
  4650. template<typename T>
  4651. struct LazyStat : Option<T> {
  4652. LazyStat() : used( false ) {}
  4653. LazyStat& operator=( T const& _value ) {
  4654. Option<T>::operator=( _value );
  4655. used = false;
  4656. return *this;
  4657. }
  4658. void reset() {
  4659. Option<T>::reset();
  4660. used = false;
  4661. }
  4662. bool used;
  4663. };
  4664. struct TestRunInfo {
  4665. TestRunInfo( std::string const& _name ) : name( _name ) {}
  4666. std::string name;
  4667. };
  4668. struct GroupInfo {
  4669. GroupInfo( std::string const& _name,
  4670. std::size_t _groupIndex,
  4671. std::size_t _groupsCount )
  4672. : name( _name ),
  4673. groupIndex( _groupIndex ),
  4674. groupsCounts( _groupsCount )
  4675. {}
  4676. std::string name;
  4677. std::size_t groupIndex;
  4678. std::size_t groupsCounts;
  4679. };
  4680. struct AssertionStats {
  4681. AssertionStats( AssertionResult const& _assertionResult,
  4682. std::vector<MessageInfo> const& _infoMessages,
  4683. Totals const& _totals )
  4684. : assertionResult( _assertionResult ),
  4685. infoMessages( _infoMessages ),
  4686. totals( _totals )
  4687. {
  4688. if( assertionResult.hasMessage() ) {
  4689. // Copy message into messages list.
  4690. // !TBD This should have been done earlier, somewhere
  4691. MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
  4692. builder << assertionResult.getMessage();
  4693. builder.m_info.message = builder.m_stream.str();
  4694. infoMessages.push_back( builder.m_info );
  4695. }
  4696. }
  4697. virtual ~AssertionStats();
  4698. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4699. AssertionStats( AssertionStats const& ) = default;
  4700. AssertionStats( AssertionStats && ) = default;
  4701. AssertionStats& operator = ( AssertionStats const& ) = default;
  4702. AssertionStats& operator = ( AssertionStats && ) = default;
  4703. # endif
  4704. AssertionResult assertionResult;
  4705. std::vector<MessageInfo> infoMessages;
  4706. Totals totals;
  4707. };
  4708. struct SectionStats {
  4709. SectionStats( SectionInfo const& _sectionInfo,
  4710. Counts const& _assertions,
  4711. double _durationInSeconds,
  4712. bool _missingAssertions )
  4713. : sectionInfo( _sectionInfo ),
  4714. assertions( _assertions ),
  4715. durationInSeconds( _durationInSeconds ),
  4716. missingAssertions( _missingAssertions )
  4717. {}
  4718. virtual ~SectionStats();
  4719. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4720. SectionStats( SectionStats const& ) = default;
  4721. SectionStats( SectionStats && ) = default;
  4722. SectionStats& operator = ( SectionStats const& ) = default;
  4723. SectionStats& operator = ( SectionStats && ) = default;
  4724. # endif
  4725. SectionInfo sectionInfo;
  4726. Counts assertions;
  4727. double durationInSeconds;
  4728. bool missingAssertions;
  4729. };
  4730. struct TestCaseStats {
  4731. TestCaseStats( TestCaseInfo const& _testInfo,
  4732. Totals const& _totals,
  4733. std::string const& _stdOut,
  4734. std::string const& _stdErr,
  4735. bool _aborting )
  4736. : testInfo( _testInfo ),
  4737. totals( _totals ),
  4738. stdOut( _stdOut ),
  4739. stdErr( _stdErr ),
  4740. aborting( _aborting )
  4741. {}
  4742. virtual ~TestCaseStats();
  4743. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4744. TestCaseStats( TestCaseStats const& ) = default;
  4745. TestCaseStats( TestCaseStats && ) = default;
  4746. TestCaseStats& operator = ( TestCaseStats const& ) = default;
  4747. TestCaseStats& operator = ( TestCaseStats && ) = default;
  4748. # endif
  4749. TestCaseInfo testInfo;
  4750. Totals totals;
  4751. std::string stdOut;
  4752. std::string stdErr;
  4753. bool aborting;
  4754. };
  4755. struct TestGroupStats {
  4756. TestGroupStats( GroupInfo const& _groupInfo,
  4757. Totals const& _totals,
  4758. bool _aborting )
  4759. : groupInfo( _groupInfo ),
  4760. totals( _totals ),
  4761. aborting( _aborting )
  4762. {}
  4763. TestGroupStats( GroupInfo const& _groupInfo )
  4764. : groupInfo( _groupInfo ),
  4765. aborting( false )
  4766. {}
  4767. virtual ~TestGroupStats();
  4768. # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4769. TestGroupStats( TestGroupStats const& ) = default;
  4770. TestGroupStats( TestGroupStats && ) = default;
  4771. TestGroupStats& operator = ( TestGroupStats const& ) = default;
  4772. TestGroupStats& operator = ( TestGroupStats && ) = default;
  4773. # endif
  4774. GroupInfo groupInfo;
  4775. Totals totals;
  4776. bool aborting;
  4777. };
  4778. struct TestRunStats {
  4779. TestRunStats( TestRunInfo const& _runInfo,
  4780. Totals const& _totals,
  4781. bool _aborting )
  4782. : runInfo( _runInfo ),
  4783. totals( _totals ),
  4784. aborting( _aborting )
  4785. {}
  4786. virtual ~TestRunStats();
  4787. # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
  4788. TestRunStats( TestRunStats const& _other )
  4789. : runInfo( _other.runInfo ),
  4790. totals( _other.totals ),
  4791. aborting( _other.aborting )
  4792. {}
  4793. # else
  4794. TestRunStats( TestRunStats const& ) = default;
  4795. TestRunStats( TestRunStats && ) = default;
  4796. TestRunStats& operator = ( TestRunStats const& ) = default;
  4797. TestRunStats& operator = ( TestRunStats && ) = default;
  4798. # endif
  4799. TestRunInfo runInfo;
  4800. Totals totals;
  4801. bool aborting;
  4802. };
  4803. class MultipleReporters;
  4804. struct IStreamingReporter : IShared {
  4805. virtual ~IStreamingReporter();
  4806. // Implementing class must also provide the following static method:
  4807. // static std::string getDescription();
  4808. virtual ReporterPreferences getPreferences() const = 0;
  4809. virtual void noMatchingTestCases( std::string const& spec ) = 0;
  4810. virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
  4811. virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
  4812. virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
  4813. virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
  4814. virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
  4815. // The return value indicates if the messages buffer should be cleared:
  4816. virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
  4817. virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
  4818. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
  4819. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
  4820. virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
  4821. virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
  4822. virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
  4823. };
  4824. struct IReporterFactory : IShared {
  4825. virtual ~IReporterFactory();
  4826. virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
  4827. virtual std::string getDescription() const = 0;
  4828. };
  4829. struct IReporterRegistry {
  4830. typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
  4831. typedef std::vector<Ptr<IReporterFactory> > Listeners;
  4832. virtual ~IReporterRegistry();
  4833. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
  4834. virtual FactoryMap const& getFactories() const = 0;
  4835. virtual Listeners const& getListeners() const = 0;
  4836. };
  4837. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
  4838. }
  4839. #include <limits>
  4840. #include <algorithm>
  4841. namespace Catch {
  4842. inline std::size_t listTests( Config const& config ) {
  4843. TestSpec testSpec = config.testSpec();
  4844. if( config.testSpec().hasFilters() )
  4845. Catch::cout() << "Matching test cases:\n";
  4846. else {
  4847. Catch::cout() << "All available test cases:\n";
  4848. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4849. }
  4850. std::size_t matchedTests = 0;
  4851. TextAttributes nameAttr, descAttr, tagsAttr;
  4852. nameAttr.setInitialIndent( 2 ).setIndent( 4 );
  4853. descAttr.setIndent( 4 );
  4854. tagsAttr.setIndent( 6 );
  4855. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4856. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4857. it != itEnd;
  4858. ++it ) {
  4859. matchedTests++;
  4860. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4861. Colour::Code colour = testCaseInfo.isHidden()
  4862. ? Colour::SecondaryText
  4863. : Colour::None;
  4864. Colour colourGuard( colour );
  4865. Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
  4866. if( config.listExtraInfo() ) {
  4867. Catch::cout() << " " << testCaseInfo.lineInfo << std::endl;
  4868. std::string description = testCaseInfo.description;
  4869. if( description.empty() )
  4870. description = "(NO DESCRIPTION)";
  4871. Catch::cout() << Text( description, descAttr ) << std::endl;
  4872. }
  4873. if( !testCaseInfo.tags.empty() )
  4874. Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
  4875. }
  4876. if( !config.testSpec().hasFilters() )
  4877. Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
  4878. else
  4879. Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
  4880. return matchedTests;
  4881. }
  4882. inline std::size_t listTestsNamesOnly( Config const& config ) {
  4883. TestSpec testSpec = config.testSpec();
  4884. if( !config.testSpec().hasFilters() )
  4885. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4886. std::size_t matchedTests = 0;
  4887. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4888. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4889. it != itEnd;
  4890. ++it ) {
  4891. matchedTests++;
  4892. TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
  4893. if( startsWith( testCaseInfo.name, '#' ) )
  4894. Catch::cout() << '"' << testCaseInfo.name << '"';
  4895. else
  4896. Catch::cout() << testCaseInfo.name;
  4897. if ( config.listExtraInfo() )
  4898. Catch::cout() << "\t@" << testCaseInfo.lineInfo;
  4899. Catch::cout() << std::endl;
  4900. }
  4901. return matchedTests;
  4902. }
  4903. struct TagInfo {
  4904. TagInfo() : count ( 0 ) {}
  4905. void add( std::string const& spelling ) {
  4906. ++count;
  4907. spellings.insert( spelling );
  4908. }
  4909. std::string all() const {
  4910. std::string out;
  4911. for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
  4912. it != itEnd;
  4913. ++it )
  4914. out += "[" + *it + "]";
  4915. return out;
  4916. }
  4917. std::set<std::string> spellings;
  4918. std::size_t count;
  4919. };
  4920. inline std::size_t listTags( Config const& config ) {
  4921. TestSpec testSpec = config.testSpec();
  4922. if( config.testSpec().hasFilters() )
  4923. Catch::cout() << "Tags for matching test cases:\n";
  4924. else {
  4925. Catch::cout() << "All available tags:\n";
  4926. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
  4927. }
  4928. std::map<std::string, TagInfo> tagCounts;
  4929. std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
  4930. for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
  4931. it != itEnd;
  4932. ++it ) {
  4933. for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
  4934. tagItEnd = it->getTestCaseInfo().tags.end();
  4935. tagIt != tagItEnd;
  4936. ++tagIt ) {
  4937. std::string tagName = *tagIt;
  4938. std::string lcaseTagName = toLower( tagName );
  4939. std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
  4940. if( countIt == tagCounts.end() )
  4941. countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
  4942. countIt->second.add( tagName );
  4943. }
  4944. }
  4945. for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
  4946. countItEnd = tagCounts.end();
  4947. countIt != countItEnd;
  4948. ++countIt ) {
  4949. std::ostringstream oss;
  4950. oss << " " << std::setw(2) << countIt->second.count << " ";
  4951. Text wrapper( countIt->second.all(), TextAttributes()
  4952. .setInitialIndent( 0 )
  4953. .setIndent( oss.str().size() )
  4954. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
  4955. Catch::cout() << oss.str() << wrapper << '\n';
  4956. }
  4957. Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
  4958. return tagCounts.size();
  4959. }
  4960. inline std::size_t listReporters( Config const& /*config*/ ) {
  4961. Catch::cout() << "Available reporters:\n";
  4962. IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
  4963. IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
  4964. std::size_t maxNameLen = 0;
  4965. for(it = itBegin; it != itEnd; ++it )
  4966. maxNameLen = (std::max)( maxNameLen, it->first.size() );
  4967. for(it = itBegin; it != itEnd; ++it ) {
  4968. Text wrapper( it->second->getDescription(), TextAttributes()
  4969. .setInitialIndent( 0 )
  4970. .setIndent( 7+maxNameLen )
  4971. .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
  4972. Catch::cout() << " "
  4973. << it->first
  4974. << ':'
  4975. << std::string( maxNameLen - it->first.size() + 2, ' ' )
  4976. << wrapper << '\n';
  4977. }
  4978. Catch::cout() << std::endl;
  4979. return factories.size();
  4980. }
  4981. inline Option<std::size_t> list( Config const& config ) {
  4982. Option<std::size_t> listedCount;
  4983. if( config.listTests() || ( config.listExtraInfo() && !config.listTestNamesOnly() ) )
  4984. listedCount = listedCount.valueOr(0) + listTests( config );
  4985. if( config.listTestNamesOnly() )
  4986. listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
  4987. if( config.listTags() )
  4988. listedCount = listedCount.valueOr(0) + listTags( config );
  4989. if( config.listReporters() )
  4990. listedCount = listedCount.valueOr(0) + listReporters( config );
  4991. return listedCount;
  4992. }
  4993. } // end namespace Catch
  4994. // #included from: internal/catch_run_context.hpp
  4995. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  4996. // #included from: catch_test_case_tracker.hpp
  4997. #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
  4998. #include <algorithm>
  4999. #include <string>
  5000. #include <assert.h>
  5001. #include <vector>
  5002. #include <stdexcept>
  5003. CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
  5004. namespace Catch {
  5005. namespace TestCaseTracking {
  5006. struct NameAndLocation {
  5007. std::string name;
  5008. SourceLineInfo location;
  5009. NameAndLocation( std::string const& _name, SourceLineInfo const& _location )
  5010. : name( _name ),
  5011. location( _location )
  5012. {}
  5013. };
  5014. struct ITracker : SharedImpl<> {
  5015. virtual ~ITracker();
  5016. // static queries
  5017. virtual NameAndLocation const& nameAndLocation() const = 0;
  5018. // dynamic queries
  5019. virtual bool isComplete() const = 0; // Successfully completed or failed
  5020. virtual bool isSuccessfullyCompleted() const = 0;
  5021. virtual bool isOpen() const = 0; // Started but not complete
  5022. virtual bool hasChildren() const = 0;
  5023. virtual ITracker& parent() = 0;
  5024. // actions
  5025. virtual void close() = 0; // Successfully complete
  5026. virtual void fail() = 0;
  5027. virtual void markAsNeedingAnotherRun() = 0;
  5028. virtual void addChild( Ptr<ITracker> const& child ) = 0;
  5029. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) = 0;
  5030. virtual void openChild() = 0;
  5031. // Debug/ checking
  5032. virtual bool isSectionTracker() const = 0;
  5033. virtual bool isIndexTracker() const = 0;
  5034. };
  5035. class TrackerContext {
  5036. enum RunState {
  5037. NotStarted,
  5038. Executing,
  5039. CompletedCycle
  5040. };
  5041. Ptr<ITracker> m_rootTracker;
  5042. ITracker* m_currentTracker;
  5043. RunState m_runState;
  5044. public:
  5045. static TrackerContext& instance() {
  5046. static TrackerContext s_instance;
  5047. return s_instance;
  5048. }
  5049. TrackerContext()
  5050. : m_currentTracker( CATCH_NULL ),
  5051. m_runState( NotStarted )
  5052. {}
  5053. ITracker& startRun();
  5054. void endRun() {
  5055. m_rootTracker.reset();
  5056. m_currentTracker = CATCH_NULL;
  5057. m_runState = NotStarted;
  5058. }
  5059. void startCycle() {
  5060. m_currentTracker = m_rootTracker.get();
  5061. m_runState = Executing;
  5062. }
  5063. void completeCycle() {
  5064. m_runState = CompletedCycle;
  5065. }
  5066. bool completedCycle() const {
  5067. return m_runState == CompletedCycle;
  5068. }
  5069. ITracker& currentTracker() {
  5070. return *m_currentTracker;
  5071. }
  5072. void setCurrentTracker( ITracker* tracker ) {
  5073. m_currentTracker = tracker;
  5074. }
  5075. };
  5076. class TrackerBase : public ITracker {
  5077. protected:
  5078. enum CycleState {
  5079. NotStarted,
  5080. Executing,
  5081. ExecutingChildren,
  5082. NeedsAnotherRun,
  5083. CompletedSuccessfully,
  5084. Failed
  5085. };
  5086. class TrackerHasName {
  5087. NameAndLocation m_nameAndLocation;
  5088. public:
  5089. TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {}
  5090. bool operator ()( Ptr<ITracker> const& tracker ) {
  5091. return
  5092. tracker->nameAndLocation().name == m_nameAndLocation.name &&
  5093. tracker->nameAndLocation().location == m_nameAndLocation.location;
  5094. }
  5095. };
  5096. typedef std::vector<Ptr<ITracker> > Children;
  5097. NameAndLocation m_nameAndLocation;
  5098. TrackerContext& m_ctx;
  5099. ITracker* m_parent;
  5100. Children m_children;
  5101. CycleState m_runState;
  5102. public:
  5103. TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5104. : m_nameAndLocation( nameAndLocation ),
  5105. m_ctx( ctx ),
  5106. m_parent( parent ),
  5107. m_runState( NotStarted )
  5108. {}
  5109. virtual ~TrackerBase();
  5110. virtual NameAndLocation const& nameAndLocation() const CATCH_OVERRIDE {
  5111. return m_nameAndLocation;
  5112. }
  5113. virtual bool isComplete() const CATCH_OVERRIDE {
  5114. return m_runState == CompletedSuccessfully || m_runState == Failed;
  5115. }
  5116. virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
  5117. return m_runState == CompletedSuccessfully;
  5118. }
  5119. virtual bool isOpen() const CATCH_OVERRIDE {
  5120. return m_runState != NotStarted && !isComplete();
  5121. }
  5122. virtual bool hasChildren() const CATCH_OVERRIDE {
  5123. return !m_children.empty();
  5124. }
  5125. virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
  5126. m_children.push_back( child );
  5127. }
  5128. virtual ITracker* findChild( NameAndLocation const& nameAndLocation ) CATCH_OVERRIDE {
  5129. Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( nameAndLocation ) );
  5130. return( it != m_children.end() )
  5131. ? it->get()
  5132. : CATCH_NULL;
  5133. }
  5134. virtual ITracker& parent() CATCH_OVERRIDE {
  5135. assert( m_parent ); // Should always be non-null except for root
  5136. return *m_parent;
  5137. }
  5138. virtual void openChild() CATCH_OVERRIDE {
  5139. if( m_runState != ExecutingChildren ) {
  5140. m_runState = ExecutingChildren;
  5141. if( m_parent )
  5142. m_parent->openChild();
  5143. }
  5144. }
  5145. virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
  5146. virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
  5147. void open() {
  5148. m_runState = Executing;
  5149. moveToThis();
  5150. if( m_parent )
  5151. m_parent->openChild();
  5152. }
  5153. virtual void close() CATCH_OVERRIDE {
  5154. // Close any still open children (e.g. generators)
  5155. while( &m_ctx.currentTracker() != this )
  5156. m_ctx.currentTracker().close();
  5157. switch( m_runState ) {
  5158. case NotStarted:
  5159. case CompletedSuccessfully:
  5160. case Failed:
  5161. throw std::logic_error( "Illogical state" );
  5162. case NeedsAnotherRun:
  5163. break;;
  5164. case Executing:
  5165. m_runState = CompletedSuccessfully;
  5166. break;
  5167. case ExecutingChildren:
  5168. if( m_children.empty() || m_children.back()->isComplete() )
  5169. m_runState = CompletedSuccessfully;
  5170. break;
  5171. default:
  5172. throw std::logic_error( "Unexpected state" );
  5173. }
  5174. moveToParent();
  5175. m_ctx.completeCycle();
  5176. }
  5177. virtual void fail() CATCH_OVERRIDE {
  5178. m_runState = Failed;
  5179. if( m_parent )
  5180. m_parent->markAsNeedingAnotherRun();
  5181. moveToParent();
  5182. m_ctx.completeCycle();
  5183. }
  5184. virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
  5185. m_runState = NeedsAnotherRun;
  5186. }
  5187. private:
  5188. void moveToParent() {
  5189. assert( m_parent );
  5190. m_ctx.setCurrentTracker( m_parent );
  5191. }
  5192. void moveToThis() {
  5193. m_ctx.setCurrentTracker( this );
  5194. }
  5195. };
  5196. class SectionTracker : public TrackerBase {
  5197. std::vector<std::string> m_filters;
  5198. public:
  5199. SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent )
  5200. : TrackerBase( nameAndLocation, ctx, parent )
  5201. {
  5202. if( parent ) {
  5203. while( !parent->isSectionTracker() )
  5204. parent = &parent->parent();
  5205. SectionTracker& parentSection = static_cast<SectionTracker&>( *parent );
  5206. addNextFilters( parentSection.m_filters );
  5207. }
  5208. }
  5209. virtual ~SectionTracker();
  5210. virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
  5211. static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ) {
  5212. SectionTracker* section = CATCH_NULL;
  5213. ITracker& currentTracker = ctx.currentTracker();
  5214. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5215. assert( childTracker );
  5216. assert( childTracker->isSectionTracker() );
  5217. section = static_cast<SectionTracker*>( childTracker );
  5218. }
  5219. else {
  5220. section = new SectionTracker( nameAndLocation, ctx, &currentTracker );
  5221. currentTracker.addChild( section );
  5222. }
  5223. if( !ctx.completedCycle() )
  5224. section->tryOpen();
  5225. return *section;
  5226. }
  5227. void tryOpen() {
  5228. if( !isComplete() && (m_filters.empty() || m_filters[0].empty() || m_filters[0] == m_nameAndLocation.name ) )
  5229. open();
  5230. }
  5231. void addInitialFilters( std::vector<std::string> const& filters ) {
  5232. if( !filters.empty() ) {
  5233. m_filters.push_back(""); // Root - should never be consulted
  5234. m_filters.push_back(""); // Test Case - not a section filter
  5235. m_filters.insert( m_filters.end(), filters.begin(), filters.end() );
  5236. }
  5237. }
  5238. void addNextFilters( std::vector<std::string> const& filters ) {
  5239. if( filters.size() > 1 )
  5240. m_filters.insert( m_filters.end(), ++filters.begin(), filters.end() );
  5241. }
  5242. };
  5243. class IndexTracker : public TrackerBase {
  5244. int m_size;
  5245. int m_index;
  5246. public:
  5247. IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size )
  5248. : TrackerBase( nameAndLocation, ctx, parent ),
  5249. m_size( size ),
  5250. m_index( -1 )
  5251. {}
  5252. virtual ~IndexTracker();
  5253. virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
  5254. static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ) {
  5255. IndexTracker* tracker = CATCH_NULL;
  5256. ITracker& currentTracker = ctx.currentTracker();
  5257. if( ITracker* childTracker = currentTracker.findChild( nameAndLocation ) ) {
  5258. assert( childTracker );
  5259. assert( childTracker->isIndexTracker() );
  5260. tracker = static_cast<IndexTracker*>( childTracker );
  5261. }
  5262. else {
  5263. tracker = new IndexTracker( nameAndLocation, ctx, &currentTracker, size );
  5264. currentTracker.addChild( tracker );
  5265. }
  5266. if( !ctx.completedCycle() && !tracker->isComplete() ) {
  5267. if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
  5268. tracker->moveNext();
  5269. tracker->open();
  5270. }
  5271. return *tracker;
  5272. }
  5273. int index() const { return m_index; }
  5274. void moveNext() {
  5275. m_index++;
  5276. m_children.clear();
  5277. }
  5278. virtual void close() CATCH_OVERRIDE {
  5279. TrackerBase::close();
  5280. if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
  5281. m_runState = Executing;
  5282. }
  5283. };
  5284. inline ITracker& TrackerContext::startRun() {
  5285. m_rootTracker = new SectionTracker( NameAndLocation( "{root}", CATCH_INTERNAL_LINEINFO ), *this, CATCH_NULL );
  5286. m_currentTracker = CATCH_NULL;
  5287. m_runState = Executing;
  5288. return *m_rootTracker;
  5289. }
  5290. } // namespace TestCaseTracking
  5291. using TestCaseTracking::ITracker;
  5292. using TestCaseTracking::TrackerContext;
  5293. using TestCaseTracking::SectionTracker;
  5294. using TestCaseTracking::IndexTracker;
  5295. } // namespace Catch
  5296. CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
  5297. // #included from: catch_fatal_condition.hpp
  5298. #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
  5299. namespace Catch {
  5300. // Report the error condition
  5301. inline void reportFatal( std::string const& message ) {
  5302. IContext& context = Catch::getCurrentContext();
  5303. IResultCapture* resultCapture = context.getResultCapture();
  5304. resultCapture->handleFatalErrorCondition( message );
  5305. }
  5306. } // namespace Catch
  5307. #if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
  5308. // #included from: catch_windows_h_proxy.h
  5309. #define TWOBLUECUBES_CATCH_WINDOWS_H_PROXY_H_INCLUDED
  5310. #ifdef CATCH_DEFINES_NOMINMAX
  5311. # define NOMINMAX
  5312. #endif
  5313. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5314. # define WIN32_LEAN_AND_MEAN
  5315. #endif
  5316. #ifdef __AFXDLL
  5317. #include <AfxWin.h>
  5318. #else
  5319. #include <windows.h>
  5320. #endif
  5321. #ifdef CATCH_DEFINES_NOMINMAX
  5322. # undef NOMINMAX
  5323. #endif
  5324. #ifdef CATCH_DEFINES_WIN32_LEAN_AND_MEAN
  5325. # undef WIN32_LEAN_AND_MEAN
  5326. #endif
  5327. # if !defined ( CATCH_CONFIG_WINDOWS_SEH )
  5328. namespace Catch {
  5329. struct FatalConditionHandler {
  5330. void reset() {}
  5331. };
  5332. }
  5333. # else // CATCH_CONFIG_WINDOWS_SEH is defined
  5334. namespace Catch {
  5335. struct SignalDefs { DWORD id; const char* name; };
  5336. extern SignalDefs signalDefs[];
  5337. // There is no 1-1 mapping between signals and windows exceptions.
  5338. // Windows can easily distinguish between SO and SigSegV,
  5339. // but SigInt, SigTerm, etc are handled differently.
  5340. SignalDefs signalDefs[] = {
  5341. { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
  5342. { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
  5343. { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
  5344. { EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" },
  5345. };
  5346. struct FatalConditionHandler {
  5347. static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
  5348. for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5349. if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
  5350. reportFatal(signalDefs[i].name);
  5351. }
  5352. }
  5353. // If its not an exception we care about, pass it along.
  5354. // This stops us from eating debugger breaks etc.
  5355. return EXCEPTION_CONTINUE_SEARCH;
  5356. }
  5357. FatalConditionHandler() {
  5358. isSet = true;
  5359. // 32k seems enough for Catch to handle stack overflow,
  5360. // but the value was found experimentally, so there is no strong guarantee
  5361. guaranteeSize = 32 * 1024;
  5362. exceptionHandlerHandle = CATCH_NULL;
  5363. // Register as first handler in current chain
  5364. exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
  5365. // Pass in guarantee size to be filled
  5366. SetThreadStackGuarantee(&guaranteeSize);
  5367. }
  5368. static void reset() {
  5369. if (isSet) {
  5370. // Unregister handler and restore the old guarantee
  5371. RemoveVectoredExceptionHandler(exceptionHandlerHandle);
  5372. SetThreadStackGuarantee(&guaranteeSize);
  5373. exceptionHandlerHandle = CATCH_NULL;
  5374. isSet = false;
  5375. }
  5376. }
  5377. ~FatalConditionHandler() {
  5378. reset();
  5379. }
  5380. private:
  5381. static bool isSet;
  5382. static ULONG guaranteeSize;
  5383. static PVOID exceptionHandlerHandle;
  5384. };
  5385. bool FatalConditionHandler::isSet = false;
  5386. ULONG FatalConditionHandler::guaranteeSize = 0;
  5387. PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL;
  5388. } // namespace Catch
  5389. # endif // CATCH_CONFIG_WINDOWS_SEH
  5390. #else // Not Windows - assumed to be POSIX compatible //////////////////////////
  5391. # if !defined(CATCH_CONFIG_POSIX_SIGNALS)
  5392. namespace Catch {
  5393. struct FatalConditionHandler {
  5394. void reset() {}
  5395. };
  5396. }
  5397. # else // CATCH_CONFIG_POSIX_SIGNALS is defined
  5398. #include <signal.h>
  5399. namespace Catch {
  5400. struct SignalDefs {
  5401. int id;
  5402. const char* name;
  5403. };
  5404. extern SignalDefs signalDefs[];
  5405. SignalDefs signalDefs[] = {
  5406. { SIGINT, "SIGINT - Terminal interrupt signal" },
  5407. { SIGILL, "SIGILL - Illegal instruction signal" },
  5408. { SIGFPE, "SIGFPE - Floating point error signal" },
  5409. { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
  5410. { SIGTERM, "SIGTERM - Termination request signal" },
  5411. { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
  5412. };
  5413. struct FatalConditionHandler {
  5414. static bool isSet;
  5415. static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)];
  5416. static stack_t oldSigStack;
  5417. static char altStackMem[SIGSTKSZ];
  5418. static void handleSignal( int sig ) {
  5419. std::string name = "<unknown signal>";
  5420. for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
  5421. SignalDefs &def = signalDefs[i];
  5422. if (sig == def.id) {
  5423. name = def.name;
  5424. break;
  5425. }
  5426. }
  5427. reset();
  5428. reportFatal(name);
  5429. raise( sig );
  5430. }
  5431. FatalConditionHandler() {
  5432. isSet = true;
  5433. stack_t sigStack;
  5434. sigStack.ss_sp = altStackMem;
  5435. sigStack.ss_size = SIGSTKSZ;
  5436. sigStack.ss_flags = 0;
  5437. sigaltstack(&sigStack, &oldSigStack);
  5438. struct sigaction sa = { 0 };
  5439. sa.sa_handler = handleSignal;
  5440. sa.sa_flags = SA_ONSTACK;
  5441. for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
  5442. sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
  5443. }
  5444. }
  5445. ~FatalConditionHandler() {
  5446. reset();
  5447. }
  5448. static void reset() {
  5449. if( isSet ) {
  5450. // Set signals back to previous values -- hopefully nobody overwrote them in the meantime
  5451. for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
  5452. sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL);
  5453. }
  5454. // Return the old stack
  5455. sigaltstack(&oldSigStack, CATCH_NULL);
  5456. isSet = false;
  5457. }
  5458. }
  5459. };
  5460. bool FatalConditionHandler::isSet = false;
  5461. struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
  5462. stack_t FatalConditionHandler::oldSigStack = {};
  5463. char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
  5464. } // namespace Catch
  5465. # endif // CATCH_CONFIG_POSIX_SIGNALS
  5466. #endif // not Windows
  5467. #include <cassert>
  5468. #include <set>
  5469. #include <string>
  5470. namespace Catch {
  5471. class StreamRedirect {
  5472. public:
  5473. StreamRedirect( std::ostream& stream, std::string& targetString )
  5474. : m_stream( stream ),
  5475. m_prevBuf( stream.rdbuf() ),
  5476. m_targetString( targetString )
  5477. {
  5478. stream.rdbuf( m_oss.rdbuf() );
  5479. }
  5480. ~StreamRedirect() {
  5481. m_targetString += m_oss.str();
  5482. m_stream.rdbuf( m_prevBuf );
  5483. }
  5484. private:
  5485. std::ostream& m_stream;
  5486. std::streambuf* m_prevBuf;
  5487. std::ostringstream m_oss;
  5488. std::string& m_targetString;
  5489. };
  5490. // StdErr has two constituent streams in C++, std::cerr and std::clog
  5491. // This means that we need to redirect 2 streams into 1 to keep proper
  5492. // order of writes and cannot use StreamRedirect on its own
  5493. class StdErrRedirect {
  5494. public:
  5495. StdErrRedirect(std::string& targetString)
  5496. :m_cerrBuf( cerr().rdbuf() ), m_clogBuf(clog().rdbuf()),
  5497. m_targetString(targetString){
  5498. cerr().rdbuf(m_oss.rdbuf());
  5499. clog().rdbuf(m_oss.rdbuf());
  5500. }
  5501. ~StdErrRedirect() {
  5502. m_targetString += m_oss.str();
  5503. cerr().rdbuf(m_cerrBuf);
  5504. clog().rdbuf(m_clogBuf);
  5505. }
  5506. private:
  5507. std::streambuf* m_cerrBuf;
  5508. std::streambuf* m_clogBuf;
  5509. std::ostringstream m_oss;
  5510. std::string& m_targetString;
  5511. };
  5512. ///////////////////////////////////////////////////////////////////////////
  5513. class RunContext : public IResultCapture, public IRunner {
  5514. RunContext( RunContext const& );
  5515. void operator =( RunContext const& );
  5516. public:
  5517. explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
  5518. : m_runInfo( _config->name() ),
  5519. m_context( getCurrentMutableContext() ),
  5520. m_activeTestCase( CATCH_NULL ),
  5521. m_config( _config ),
  5522. m_reporter( reporter ),
  5523. m_shouldReportUnexpected ( true )
  5524. {
  5525. m_context.setRunner( this );
  5526. m_context.setConfig( m_config );
  5527. m_context.setResultCapture( this );
  5528. m_reporter->testRunStarting( m_runInfo );
  5529. }
  5530. virtual ~RunContext() {
  5531. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
  5532. }
  5533. void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
  5534. m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
  5535. }
  5536. void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
  5537. m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
  5538. }
  5539. Totals runTest( TestCase const& testCase ) {
  5540. Totals prevTotals = m_totals;
  5541. std::string redirectedCout;
  5542. std::string redirectedCerr;
  5543. TestCaseInfo testInfo = testCase.getTestCaseInfo();
  5544. m_reporter->testCaseStarting( testInfo );
  5545. m_activeTestCase = &testCase;
  5546. do {
  5547. ITracker& rootTracker = m_trackerContext.startRun();
  5548. assert( rootTracker.isSectionTracker() );
  5549. static_cast<SectionTracker&>( rootTracker ).addInitialFilters( m_config->getSectionsToRun() );
  5550. do {
  5551. m_trackerContext.startCycle();
  5552. m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( testInfo.name, testInfo.lineInfo ) );
  5553. runCurrentTest( redirectedCout, redirectedCerr );
  5554. }
  5555. while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
  5556. }
  5557. // !TBD: deprecated - this will be replaced by indexed trackers
  5558. while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
  5559. Totals deltaTotals = m_totals.delta( prevTotals );
  5560. if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
  5561. deltaTotals.assertions.failed++;
  5562. deltaTotals.testCases.passed--;
  5563. deltaTotals.testCases.failed++;
  5564. }
  5565. m_totals.testCases += deltaTotals.testCases;
  5566. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5567. deltaTotals,
  5568. redirectedCout,
  5569. redirectedCerr,
  5570. aborting() ) );
  5571. m_activeTestCase = CATCH_NULL;
  5572. m_testCaseTracker = CATCH_NULL;
  5573. return deltaTotals;
  5574. }
  5575. Ptr<IConfig const> config() const {
  5576. return m_config;
  5577. }
  5578. private: // IResultCapture
  5579. virtual void assertionEnded( AssertionResult const& result ) {
  5580. if( result.getResultType() == ResultWas::Ok ) {
  5581. m_totals.assertions.passed++;
  5582. }
  5583. else if( !result.isOk() ) {
  5584. if( m_activeTestCase->getTestCaseInfo().okToFail() )
  5585. m_totals.assertions.failedButOk++;
  5586. else
  5587. m_totals.assertions.failed++;
  5588. }
  5589. // We have no use for the return value (whether messages should be cleared), because messages were made scoped
  5590. // and should be let to clear themselves out.
  5591. static_cast<void>(m_reporter->assertionEnded(AssertionStats(result, m_messages, m_totals)));
  5592. // Reset working state
  5593. m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
  5594. m_lastResult = result;
  5595. }
  5596. virtual bool lastAssertionPassed()
  5597. {
  5598. return m_totals.assertions.passed == (m_prevPassed + 1);
  5599. }
  5600. virtual void assertionPassed()
  5601. {
  5602. m_totals.assertions.passed++;
  5603. m_lastAssertionInfo.capturedExpression = "{Unknown expression after the reported line}";
  5604. m_lastAssertionInfo.macroName = "";
  5605. }
  5606. virtual void assertionRun()
  5607. {
  5608. m_prevPassed = m_totals.assertions.passed;
  5609. }
  5610. virtual bool sectionStarted (
  5611. SectionInfo const& sectionInfo,
  5612. Counts& assertions
  5613. )
  5614. {
  5615. ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, TestCaseTracking::NameAndLocation( sectionInfo.name, sectionInfo.lineInfo ) );
  5616. if( !sectionTracker.isOpen() )
  5617. return false;
  5618. m_activeSections.push_back( &sectionTracker );
  5619. m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
  5620. m_reporter->sectionStarting( sectionInfo );
  5621. assertions = m_totals.assertions;
  5622. return true;
  5623. }
  5624. bool testForMissingAssertions( Counts& assertions ) {
  5625. if( assertions.total() != 0 )
  5626. return false;
  5627. if( !m_config->warnAboutMissingAssertions() )
  5628. return false;
  5629. if( m_trackerContext.currentTracker().hasChildren() )
  5630. return false;
  5631. m_totals.assertions.failed++;
  5632. assertions.failed++;
  5633. return true;
  5634. }
  5635. virtual void sectionEnded( SectionEndInfo const& endInfo ) {
  5636. Counts assertions = m_totals.assertions - endInfo.prevAssertions;
  5637. bool missingAssertions = testForMissingAssertions( assertions );
  5638. if( !m_activeSections.empty() ) {
  5639. m_activeSections.back()->close();
  5640. m_activeSections.pop_back();
  5641. }
  5642. m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
  5643. m_messages.clear();
  5644. }
  5645. virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
  5646. if( m_unfinishedSections.empty() )
  5647. m_activeSections.back()->fail();
  5648. else
  5649. m_activeSections.back()->close();
  5650. m_activeSections.pop_back();
  5651. m_unfinishedSections.push_back( endInfo );
  5652. }
  5653. virtual void pushScopedMessage( MessageInfo const& message ) {
  5654. m_messages.push_back( message );
  5655. }
  5656. virtual void popScopedMessage( MessageInfo const& message ) {
  5657. m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
  5658. }
  5659. virtual std::string getCurrentTestName() const {
  5660. return m_activeTestCase
  5661. ? m_activeTestCase->getTestCaseInfo().name
  5662. : std::string();
  5663. }
  5664. virtual const AssertionResult* getLastResult() const {
  5665. return &m_lastResult;
  5666. }
  5667. virtual void exceptionEarlyReported() {
  5668. m_shouldReportUnexpected = false;
  5669. }
  5670. virtual void handleFatalErrorCondition( std::string const& message ) {
  5671. // Don't rebuild the result -- the stringification itself can cause more fatal errors
  5672. // Instead, fake a result data.
  5673. AssertionResultData tempResult;
  5674. tempResult.resultType = ResultWas::FatalErrorCondition;
  5675. tempResult.message = message;
  5676. AssertionResult result(m_lastAssertionInfo, tempResult);
  5677. getResultCapture().assertionEnded(result);
  5678. handleUnfinishedSections();
  5679. // Recreate section for test case (as we will lose the one that was in scope)
  5680. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5681. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5682. Counts assertions;
  5683. assertions.failed = 1;
  5684. SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
  5685. m_reporter->sectionEnded( testCaseSectionStats );
  5686. TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
  5687. Totals deltaTotals;
  5688. deltaTotals.testCases.failed = 1;
  5689. deltaTotals.assertions.failed = 1;
  5690. m_reporter->testCaseEnded( TestCaseStats( testInfo,
  5691. deltaTotals,
  5692. std::string(),
  5693. std::string(),
  5694. false ) );
  5695. m_totals.testCases.failed++;
  5696. testGroupEnded( std::string(), m_totals, 1, 1 );
  5697. m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
  5698. }
  5699. public:
  5700. // !TBD We need to do this another way!
  5701. bool aborting() const {
  5702. return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
  5703. }
  5704. private:
  5705. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
  5706. TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
  5707. SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
  5708. m_reporter->sectionStarting( testCaseSection );
  5709. Counts prevAssertions = m_totals.assertions;
  5710. double duration = 0;
  5711. m_shouldReportUnexpected = true;
  5712. try {
  5713. m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
  5714. seedRng( *m_config );
  5715. Timer timer;
  5716. timer.start();
  5717. if( m_reporter->getPreferences().shouldRedirectStdOut ) {
  5718. StreamRedirect coutRedir( Catch::cout(), redirectedCout );
  5719. StdErrRedirect errRedir( redirectedCerr );
  5720. invokeActiveTestCase();
  5721. }
  5722. else {
  5723. invokeActiveTestCase();
  5724. }
  5725. duration = timer.getElapsedSeconds();
  5726. }
  5727. catch( TestFailureException& ) {
  5728. // This just means the test was aborted due to failure
  5729. }
  5730. catch(...) {
  5731. // Under CATCH_CONFIG_FAST_COMPILE, unexpected exceptions under REQUIRE assertions
  5732. // are reported without translation at the point of origin.
  5733. if (m_shouldReportUnexpected) {
  5734. makeUnexpectedResultBuilder().useActiveException();
  5735. }
  5736. }
  5737. m_testCaseTracker->close();
  5738. handleUnfinishedSections();
  5739. m_messages.clear();
  5740. Counts assertions = m_totals.assertions - prevAssertions;
  5741. bool missingAssertions = testForMissingAssertions( assertions );
  5742. SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
  5743. m_reporter->sectionEnded( testCaseSectionStats );
  5744. }
  5745. void invokeActiveTestCase() {
  5746. FatalConditionHandler fatalConditionHandler; // Handle signals
  5747. m_activeTestCase->invoke();
  5748. fatalConditionHandler.reset();
  5749. }
  5750. private:
  5751. ResultBuilder makeUnexpectedResultBuilder() const {
  5752. return ResultBuilder( m_lastAssertionInfo.macroName,
  5753. m_lastAssertionInfo.lineInfo,
  5754. m_lastAssertionInfo.capturedExpression,
  5755. m_lastAssertionInfo.resultDisposition );
  5756. }
  5757. void handleUnfinishedSections() {
  5758. // If sections ended prematurely due to an exception we stored their
  5759. // infos here so we can tear them down outside the unwind process.
  5760. for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
  5761. itEnd = m_unfinishedSections.rend();
  5762. it != itEnd;
  5763. ++it )
  5764. sectionEnded( *it );
  5765. m_unfinishedSections.clear();
  5766. }
  5767. TestRunInfo m_runInfo;
  5768. IMutableContext& m_context;
  5769. TestCase const* m_activeTestCase;
  5770. ITracker* m_testCaseTracker;
  5771. ITracker* m_currentSectionTracker;
  5772. AssertionResult m_lastResult;
  5773. Ptr<IConfig const> m_config;
  5774. Totals m_totals;
  5775. Ptr<IStreamingReporter> m_reporter;
  5776. std::vector<MessageInfo> m_messages;
  5777. AssertionInfo m_lastAssertionInfo;
  5778. std::vector<SectionEndInfo> m_unfinishedSections;
  5779. std::vector<ITracker*> m_activeSections;
  5780. TrackerContext m_trackerContext;
  5781. size_t m_prevPassed;
  5782. bool m_shouldReportUnexpected;
  5783. };
  5784. IResultCapture& getResultCapture() {
  5785. if( IResultCapture* capture = getCurrentContext().getResultCapture() )
  5786. return *capture;
  5787. else
  5788. throw std::logic_error( "No result capture instance" );
  5789. }
  5790. } // end namespace Catch
  5791. // #included from: internal/catch_version.h
  5792. #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
  5793. namespace Catch {
  5794. // Versioning information
  5795. struct Version {
  5796. Version( unsigned int _majorVersion,
  5797. unsigned int _minorVersion,
  5798. unsigned int _patchNumber,
  5799. char const * const _branchName,
  5800. unsigned int _buildNumber );
  5801. unsigned int const majorVersion;
  5802. unsigned int const minorVersion;
  5803. unsigned int const patchNumber;
  5804. // buildNumber is only used if branchName is not null
  5805. char const * const branchName;
  5806. unsigned int const buildNumber;
  5807. friend std::ostream& operator << ( std::ostream& os, Version const& version );
  5808. private:
  5809. void operator=( Version const& );
  5810. };
  5811. inline Version libraryVersion();
  5812. }
  5813. #include <fstream>
  5814. #include <stdlib.h>
  5815. #include <limits>
  5816. namespace Catch {
  5817. Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
  5818. Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
  5819. if( !reporter ) {
  5820. std::ostringstream oss;
  5821. oss << "No reporter registered with name: '" << reporterName << "'";
  5822. throw std::domain_error( oss.str() );
  5823. }
  5824. return reporter;
  5825. }
  5826. #if !defined(CATCH_CONFIG_DEFAULT_REPORTER)
  5827. #define CATCH_CONFIG_DEFAULT_REPORTER "console"
  5828. #endif
  5829. Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
  5830. std::vector<std::string> reporters = config->getReporterNames();
  5831. if( reporters.empty() )
  5832. reporters.push_back( CATCH_CONFIG_DEFAULT_REPORTER );
  5833. Ptr<IStreamingReporter> reporter;
  5834. for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
  5835. it != itEnd;
  5836. ++it )
  5837. reporter = addReporter( reporter, createReporter( *it, config ) );
  5838. return reporter;
  5839. }
  5840. Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
  5841. IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
  5842. for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
  5843. it != itEnd;
  5844. ++it )
  5845. reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
  5846. return reporters;
  5847. }
  5848. Totals runTests( Ptr<Config> const& config ) {
  5849. Ptr<IConfig const> iconfig = config.get();
  5850. Ptr<IStreamingReporter> reporter = makeReporter( config );
  5851. reporter = addListeners( iconfig, reporter );
  5852. RunContext context( iconfig, reporter );
  5853. Totals totals;
  5854. context.testGroupStarting( config->name(), 1, 1 );
  5855. TestSpec testSpec = config->testSpec();
  5856. if( !testSpec.hasFilters() )
  5857. testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
  5858. std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
  5859. for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
  5860. it != itEnd;
  5861. ++it ) {
  5862. if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
  5863. totals += context.runTest( *it );
  5864. else
  5865. reporter->skipTest( *it );
  5866. }
  5867. context.testGroupEnded( iconfig->name(), totals, 1, 1 );
  5868. return totals;
  5869. }
  5870. void applyFilenamesAsTags( IConfig const& config ) {
  5871. std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
  5872. for(std::size_t i = 0; i < tests.size(); ++i ) {
  5873. TestCase& test = const_cast<TestCase&>( tests[i] );
  5874. std::set<std::string> tags = test.tags;
  5875. std::string filename = test.lineInfo.file;
  5876. std::string::size_type lastSlash = filename.find_last_of( "\\/" );
  5877. if( lastSlash != std::string::npos )
  5878. filename = filename.substr( lastSlash+1 );
  5879. std::string::size_type lastDot = filename.find_last_of( '.' );
  5880. if( lastDot != std::string::npos )
  5881. filename = filename.substr( 0, lastDot );
  5882. tags.insert( '#' + filename );
  5883. setTags( test, tags );
  5884. }
  5885. }
  5886. class Session : NonCopyable {
  5887. static bool alreadyInstantiated;
  5888. public:
  5889. struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
  5890. Session()
  5891. : m_cli( makeCommandLineParser() ) {
  5892. if( alreadyInstantiated ) {
  5893. std::string msg = "Only one instance of Catch::Session can ever be used";
  5894. Catch::cerr() << msg << std::endl;
  5895. throw std::logic_error( msg );
  5896. }
  5897. alreadyInstantiated = true;
  5898. }
  5899. ~Session() {
  5900. Catch::cleanUp();
  5901. }
  5902. void showHelp( std::string const& processName ) {
  5903. Catch::cout() << "\nCatch v" << libraryVersion() << "\n";
  5904. m_cli.usage( Catch::cout(), processName );
  5905. Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
  5906. }
  5907. void libIdentify() {
  5908. Catch::cout()
  5909. << std::left << std::setw(16) << "description: " << "A Catch test executable\n"
  5910. << std::left << std::setw(16) << "category: " << "testframework\n"
  5911. << std::left << std::setw(16) << "framework: " << "Catch Test\n"
  5912. << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl;
  5913. }
  5914. int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
  5915. try {
  5916. m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
  5917. m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
  5918. if( m_configData.showHelp )
  5919. showHelp( m_configData.processName );
  5920. if( m_configData.libIdentify )
  5921. libIdentify();
  5922. m_config.reset();
  5923. }
  5924. catch( std::exception& ex ) {
  5925. {
  5926. Colour colourGuard( Colour::Red );
  5927. Catch::cerr()
  5928. << "\nError(s) in input:\n"
  5929. << Text( ex.what(), TextAttributes().setIndent(2) )
  5930. << "\n\n";
  5931. }
  5932. m_cli.usage( Catch::cout(), m_configData.processName );
  5933. return (std::numeric_limits<int>::max)();
  5934. }
  5935. return 0;
  5936. }
  5937. void useConfigData( ConfigData const& _configData ) {
  5938. m_configData = _configData;
  5939. m_config.reset();
  5940. }
  5941. int run( int argc, char const* const* const argv ) {
  5942. int returnCode = applyCommandLine( argc, argv );
  5943. if( returnCode == 0 )
  5944. returnCode = run();
  5945. return returnCode;
  5946. }
  5947. #if defined(WIN32) && defined(UNICODE)
  5948. int run( int argc, wchar_t const* const* const argv ) {
  5949. char **utf8Argv = new char *[ argc ];
  5950. for ( int i = 0; i < argc; ++i ) {
  5951. int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL );
  5952. utf8Argv[ i ] = new char[ bufSize ];
  5953. WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL );
  5954. }
  5955. int returnCode = applyCommandLine( argc, utf8Argv );
  5956. if( returnCode == 0 )
  5957. returnCode = run();
  5958. for ( int i = 0; i < argc; ++i )
  5959. delete [] utf8Argv[ i ];
  5960. delete [] utf8Argv;
  5961. return returnCode;
  5962. }
  5963. #endif
  5964. int run() {
  5965. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) {
  5966. Catch::cout() << "...waiting for enter/ return before starting" << std::endl;
  5967. static_cast<void>(std::getchar());
  5968. }
  5969. int exitCode = runInternal();
  5970. if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) {
  5971. Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl;
  5972. static_cast<void>(std::getchar());
  5973. }
  5974. return exitCode;
  5975. }
  5976. Clara::CommandLine<ConfigData> const& cli() const {
  5977. return m_cli;
  5978. }
  5979. std::vector<Clara::Parser::Token> const& unusedTokens() const {
  5980. return m_unusedTokens;
  5981. }
  5982. ConfigData& configData() {
  5983. return m_configData;
  5984. }
  5985. Config& config() {
  5986. if( !m_config )
  5987. m_config = new Config( m_configData );
  5988. return *m_config;
  5989. }
  5990. private:
  5991. int runInternal() {
  5992. if( m_configData.showHelp || m_configData.libIdentify )
  5993. return 0;
  5994. try
  5995. {
  5996. config(); // Force config to be constructed
  5997. seedRng( *m_config );
  5998. if( m_configData.filenamesAsTags )
  5999. applyFilenamesAsTags( *m_config );
  6000. // Handle list request
  6001. if( Option<std::size_t> listed = list( config() ) )
  6002. return static_cast<int>( *listed );
  6003. return static_cast<int>( runTests( m_config ).assertions.failed );
  6004. }
  6005. catch( std::exception& ex ) {
  6006. Catch::cerr() << ex.what() << std::endl;
  6007. return (std::numeric_limits<int>::max)();
  6008. }
  6009. }
  6010. Clara::CommandLine<ConfigData> m_cli;
  6011. std::vector<Clara::Parser::Token> m_unusedTokens;
  6012. ConfigData m_configData;
  6013. Ptr<Config> m_config;
  6014. };
  6015. bool Session::alreadyInstantiated = false;
  6016. } // end namespace Catch
  6017. // #included from: catch_registry_hub.hpp
  6018. #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
  6019. // #included from: catch_test_case_registry_impl.hpp
  6020. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  6021. #include <vector>
  6022. #include <set>
  6023. #include <sstream>
  6024. #include <algorithm>
  6025. namespace Catch {
  6026. struct RandomNumberGenerator {
  6027. typedef unsigned int result_type;
  6028. result_type operator()( result_type n ) const { return std::rand() % n; }
  6029. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6030. static constexpr result_type (min)() { return 0; }
  6031. static constexpr result_type (max)() { return 1000000; }
  6032. result_type operator()() const { return std::rand() % (max)(); }
  6033. #endif
  6034. template<typename V>
  6035. static void shuffle( V& vector ) {
  6036. RandomNumberGenerator rng;
  6037. #ifdef CATCH_CONFIG_CPP11_SHUFFLE
  6038. std::shuffle( vector.begin(), vector.end(), rng );
  6039. #else
  6040. std::random_shuffle( vector.begin(), vector.end(), rng );
  6041. #endif
  6042. }
  6043. };
  6044. inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
  6045. std::vector<TestCase> sorted = unsortedTestCases;
  6046. switch( config.runOrder() ) {
  6047. case RunTests::InLexicographicalOrder:
  6048. std::sort( sorted.begin(), sorted.end() );
  6049. break;
  6050. case RunTests::InRandomOrder:
  6051. {
  6052. seedRng( config );
  6053. RandomNumberGenerator::shuffle( sorted );
  6054. }
  6055. break;
  6056. case RunTests::InDeclarationOrder:
  6057. // already in declaration order
  6058. break;
  6059. }
  6060. return sorted;
  6061. }
  6062. bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
  6063. return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
  6064. }
  6065. void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
  6066. std::set<TestCase> seenFunctions;
  6067. for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
  6068. it != itEnd;
  6069. ++it ) {
  6070. std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
  6071. if( !prev.second ) {
  6072. std::ostringstream ss;
  6073. ss << Colour( Colour::Red )
  6074. << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
  6075. << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << '\n'
  6076. << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
  6077. throw std::runtime_error(ss.str());
  6078. }
  6079. }
  6080. }
  6081. std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
  6082. std::vector<TestCase> filtered;
  6083. filtered.reserve( testCases.size() );
  6084. for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
  6085. it != itEnd;
  6086. ++it )
  6087. if( matchTest( *it, testSpec, config ) )
  6088. filtered.push_back( *it );
  6089. return filtered;
  6090. }
  6091. std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
  6092. return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
  6093. }
  6094. class TestRegistry : public ITestCaseRegistry {
  6095. public:
  6096. TestRegistry()
  6097. : m_currentSortOrder( RunTests::InDeclarationOrder ),
  6098. m_unnamedCount( 0 )
  6099. {}
  6100. virtual ~TestRegistry();
  6101. virtual void registerTest( TestCase const& testCase ) {
  6102. std::string name = testCase.getTestCaseInfo().name;
  6103. if( name.empty() ) {
  6104. std::ostringstream oss;
  6105. oss << "Anonymous test case " << ++m_unnamedCount;
  6106. return registerTest( testCase.withName( oss.str() ) );
  6107. }
  6108. m_functions.push_back( testCase );
  6109. }
  6110. virtual std::vector<TestCase> const& getAllTests() const {
  6111. return m_functions;
  6112. }
  6113. virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
  6114. if( m_sortedFunctions.empty() )
  6115. enforceNoDuplicateTestCases( m_functions );
  6116. if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
  6117. m_sortedFunctions = sortTests( config, m_functions );
  6118. m_currentSortOrder = config.runOrder();
  6119. }
  6120. return m_sortedFunctions;
  6121. }
  6122. private:
  6123. std::vector<TestCase> m_functions;
  6124. mutable RunTests::InWhatOrder m_currentSortOrder;
  6125. mutable std::vector<TestCase> m_sortedFunctions;
  6126. size_t m_unnamedCount;
  6127. std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
  6128. };
  6129. ///////////////////////////////////////////////////////////////////////////
  6130. class FreeFunctionTestCase : public SharedImpl<ITestCase> {
  6131. public:
  6132. FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
  6133. virtual void invoke() const {
  6134. m_fun();
  6135. }
  6136. private:
  6137. virtual ~FreeFunctionTestCase();
  6138. TestFunction m_fun;
  6139. };
  6140. inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
  6141. std::string className = classOrQualifiedMethodName;
  6142. if( startsWith( className, '&' ) )
  6143. {
  6144. std::size_t lastColons = className.rfind( "::" );
  6145. std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
  6146. if( penultimateColons == std::string::npos )
  6147. penultimateColons = 1;
  6148. className = className.substr( penultimateColons, lastColons-penultimateColons );
  6149. }
  6150. return className;
  6151. }
  6152. void registerTestCase
  6153. ( ITestCase* testCase,
  6154. char const* classOrQualifiedMethodName,
  6155. NameAndDesc const& nameAndDesc,
  6156. SourceLineInfo const& lineInfo ) {
  6157. getMutableRegistryHub().registerTest
  6158. ( makeTestCase
  6159. ( testCase,
  6160. extractClassName( classOrQualifiedMethodName ),
  6161. nameAndDesc.name,
  6162. nameAndDesc.description,
  6163. lineInfo ) );
  6164. }
  6165. void registerTestCaseFunction
  6166. ( TestFunction function,
  6167. SourceLineInfo const& lineInfo,
  6168. NameAndDesc const& nameAndDesc ) {
  6169. registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
  6170. }
  6171. ///////////////////////////////////////////////////////////////////////////
  6172. AutoReg::AutoReg
  6173. ( TestFunction function,
  6174. SourceLineInfo const& lineInfo,
  6175. NameAndDesc const& nameAndDesc ) {
  6176. registerTestCaseFunction( function, lineInfo, nameAndDesc );
  6177. }
  6178. AutoReg::~AutoReg() {}
  6179. } // end namespace Catch
  6180. // #included from: catch_reporter_registry.hpp
  6181. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  6182. #include <map>
  6183. namespace Catch {
  6184. class ReporterRegistry : public IReporterRegistry {
  6185. public:
  6186. virtual ~ReporterRegistry() CATCH_OVERRIDE {}
  6187. virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
  6188. FactoryMap::const_iterator it = m_factories.find( name );
  6189. if( it == m_factories.end() )
  6190. return CATCH_NULL;
  6191. return it->second->create( ReporterConfig( config ) );
  6192. }
  6193. void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
  6194. m_factories.insert( std::make_pair( name, factory ) );
  6195. }
  6196. void registerListener( Ptr<IReporterFactory> const& factory ) {
  6197. m_listeners.push_back( factory );
  6198. }
  6199. virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
  6200. return m_factories;
  6201. }
  6202. virtual Listeners const& getListeners() const CATCH_OVERRIDE {
  6203. return m_listeners;
  6204. }
  6205. private:
  6206. FactoryMap m_factories;
  6207. Listeners m_listeners;
  6208. };
  6209. }
  6210. // #included from: catch_exception_translator_registry.hpp
  6211. #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  6212. #ifdef __OBJC__
  6213. #import "Foundation/Foundation.h"
  6214. #endif
  6215. namespace Catch {
  6216. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  6217. public:
  6218. ~ExceptionTranslatorRegistry() {
  6219. deleteAll( m_translators );
  6220. }
  6221. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  6222. m_translators.push_back( translator );
  6223. }
  6224. virtual std::string translateActiveException() const {
  6225. try {
  6226. #ifdef __OBJC__
  6227. // In Objective-C try objective-c exceptions first
  6228. @try {
  6229. return tryTranslators();
  6230. }
  6231. @catch (NSException *exception) {
  6232. return Catch::toString( [exception description] );
  6233. }
  6234. #else
  6235. return tryTranslators();
  6236. #endif
  6237. }
  6238. catch( TestFailureException& ) {
  6239. throw;
  6240. }
  6241. catch( std::exception& ex ) {
  6242. return ex.what();
  6243. }
  6244. catch( std::string& msg ) {
  6245. return msg;
  6246. }
  6247. catch( const char* msg ) {
  6248. return msg;
  6249. }
  6250. catch(...) {
  6251. return "Unknown exception";
  6252. }
  6253. }
  6254. std::string tryTranslators() const {
  6255. if( m_translators.empty() )
  6256. throw;
  6257. else
  6258. return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
  6259. }
  6260. private:
  6261. std::vector<const IExceptionTranslator*> m_translators;
  6262. };
  6263. }
  6264. // #included from: catch_tag_alias_registry.h
  6265. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
  6266. #include <map>
  6267. namespace Catch {
  6268. class TagAliasRegistry : public ITagAliasRegistry {
  6269. public:
  6270. virtual ~TagAliasRegistry();
  6271. virtual Option<TagAlias> find( std::string const& alias ) const;
  6272. virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
  6273. void add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo );
  6274. private:
  6275. std::map<std::string, TagAlias> m_registry;
  6276. };
  6277. } // end namespace Catch
  6278. namespace Catch {
  6279. namespace {
  6280. class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
  6281. RegistryHub( RegistryHub const& );
  6282. void operator=( RegistryHub const& );
  6283. public: // IRegistryHub
  6284. RegistryHub() {
  6285. }
  6286. virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
  6287. return m_reporterRegistry;
  6288. }
  6289. virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
  6290. return m_testCaseRegistry;
  6291. }
  6292. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
  6293. return m_exceptionTranslatorRegistry;
  6294. }
  6295. virtual ITagAliasRegistry const& getTagAliasRegistry() const CATCH_OVERRIDE {
  6296. return m_tagAliasRegistry;
  6297. }
  6298. public: // IMutableRegistryHub
  6299. virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6300. m_reporterRegistry.registerReporter( name, factory );
  6301. }
  6302. virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
  6303. m_reporterRegistry.registerListener( factory );
  6304. }
  6305. virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
  6306. m_testCaseRegistry.registerTest( testInfo );
  6307. }
  6308. virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
  6309. m_exceptionTranslatorRegistry.registerTranslator( translator );
  6310. }
  6311. virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) CATCH_OVERRIDE {
  6312. m_tagAliasRegistry.add( alias, tag, lineInfo );
  6313. }
  6314. private:
  6315. TestRegistry m_testCaseRegistry;
  6316. ReporterRegistry m_reporterRegistry;
  6317. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  6318. TagAliasRegistry m_tagAliasRegistry;
  6319. };
  6320. // Single, global, instance
  6321. inline RegistryHub*& getTheRegistryHub() {
  6322. static RegistryHub* theRegistryHub = CATCH_NULL;
  6323. if( !theRegistryHub )
  6324. theRegistryHub = new RegistryHub();
  6325. return theRegistryHub;
  6326. }
  6327. }
  6328. IRegistryHub& getRegistryHub() {
  6329. return *getTheRegistryHub();
  6330. }
  6331. IMutableRegistryHub& getMutableRegistryHub() {
  6332. return *getTheRegistryHub();
  6333. }
  6334. void cleanUp() {
  6335. delete getTheRegistryHub();
  6336. getTheRegistryHub() = CATCH_NULL;
  6337. cleanUpContext();
  6338. }
  6339. std::string translateActiveException() {
  6340. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  6341. }
  6342. } // end namespace Catch
  6343. // #included from: catch_notimplemented_exception.hpp
  6344. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
  6345. #include <sstream>
  6346. namespace Catch {
  6347. NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
  6348. : m_lineInfo( lineInfo ) {
  6349. std::ostringstream oss;
  6350. oss << lineInfo << ": function ";
  6351. oss << "not implemented";
  6352. m_what = oss.str();
  6353. }
  6354. const char* NotImplementedException::what() const CATCH_NOEXCEPT {
  6355. return m_what.c_str();
  6356. }
  6357. } // end namespace Catch
  6358. // #included from: catch_context_impl.hpp
  6359. #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
  6360. // #included from: catch_stream.hpp
  6361. #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
  6362. #include <stdexcept>
  6363. #include <cstdio>
  6364. #include <iostream>
  6365. namespace Catch {
  6366. template<typename WriterF, size_t bufferSize=256>
  6367. class StreamBufImpl : public StreamBufBase {
  6368. char data[bufferSize];
  6369. WriterF m_writer;
  6370. public:
  6371. StreamBufImpl() {
  6372. setp( data, data + sizeof(data) );
  6373. }
  6374. ~StreamBufImpl() CATCH_NOEXCEPT {
  6375. sync();
  6376. }
  6377. private:
  6378. int overflow( int c ) {
  6379. sync();
  6380. if( c != EOF ) {
  6381. if( pbase() == epptr() )
  6382. m_writer( std::string( 1, static_cast<char>( c ) ) );
  6383. else
  6384. sputc( static_cast<char>( c ) );
  6385. }
  6386. return 0;
  6387. }
  6388. int sync() {
  6389. if( pbase() != pptr() ) {
  6390. m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
  6391. setp( pbase(), epptr() );
  6392. }
  6393. return 0;
  6394. }
  6395. };
  6396. ///////////////////////////////////////////////////////////////////////////
  6397. FileStream::FileStream( std::string const& filename ) {
  6398. m_ofs.open( filename.c_str() );
  6399. if( m_ofs.fail() ) {
  6400. std::ostringstream oss;
  6401. oss << "Unable to open file: '" << filename << '\'';
  6402. throw std::domain_error( oss.str() );
  6403. }
  6404. }
  6405. std::ostream& FileStream::stream() const {
  6406. return m_ofs;
  6407. }
  6408. struct OutputDebugWriter {
  6409. void operator()( std::string const&str ) {
  6410. writeToDebugConsole( str );
  6411. }
  6412. };
  6413. DebugOutStream::DebugOutStream()
  6414. : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
  6415. m_os( m_streamBuf.get() )
  6416. {}
  6417. std::ostream& DebugOutStream::stream() const {
  6418. return m_os;
  6419. }
  6420. // Store the streambuf from cout up-front because
  6421. // cout may get redirected when running tests
  6422. CoutStream::CoutStream()
  6423. : m_os( Catch::cout().rdbuf() )
  6424. {}
  6425. std::ostream& CoutStream::stream() const {
  6426. return m_os;
  6427. }
  6428. #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
  6429. std::ostream& cout() {
  6430. return std::cout;
  6431. }
  6432. std::ostream& cerr() {
  6433. return std::cerr;
  6434. }
  6435. std::ostream& clog() {
  6436. return std::clog;
  6437. }
  6438. #endif
  6439. }
  6440. namespace Catch {
  6441. class Context : public IMutableContext {
  6442. Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
  6443. Context( Context const& );
  6444. void operator=( Context const& );
  6445. public:
  6446. virtual ~Context() {
  6447. deleteAllValues( m_generatorsByTestName );
  6448. }
  6449. public: // IContext
  6450. virtual IResultCapture* getResultCapture() {
  6451. return m_resultCapture;
  6452. }
  6453. virtual IRunner* getRunner() {
  6454. return m_runner;
  6455. }
  6456. virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
  6457. return getGeneratorsForCurrentTest()
  6458. .getGeneratorInfo( fileInfo, totalSize )
  6459. .getCurrentIndex();
  6460. }
  6461. virtual bool advanceGeneratorsForCurrentTest() {
  6462. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6463. return generators && generators->moveNext();
  6464. }
  6465. virtual Ptr<IConfig const> getConfig() const {
  6466. return m_config;
  6467. }
  6468. public: // IMutableContext
  6469. virtual void setResultCapture( IResultCapture* resultCapture ) {
  6470. m_resultCapture = resultCapture;
  6471. }
  6472. virtual void setRunner( IRunner* runner ) {
  6473. m_runner = runner;
  6474. }
  6475. virtual void setConfig( Ptr<IConfig const> const& config ) {
  6476. m_config = config;
  6477. }
  6478. friend IMutableContext& getCurrentMutableContext();
  6479. private:
  6480. IGeneratorsForTest* findGeneratorsForCurrentTest() {
  6481. std::string testName = getResultCapture()->getCurrentTestName();
  6482. std::map<std::string, IGeneratorsForTest*>::const_iterator it =
  6483. m_generatorsByTestName.find( testName );
  6484. return it != m_generatorsByTestName.end()
  6485. ? it->second
  6486. : CATCH_NULL;
  6487. }
  6488. IGeneratorsForTest& getGeneratorsForCurrentTest() {
  6489. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  6490. if( !generators ) {
  6491. std::string testName = getResultCapture()->getCurrentTestName();
  6492. generators = createGeneratorsForTest();
  6493. m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
  6494. }
  6495. return *generators;
  6496. }
  6497. private:
  6498. Ptr<IConfig const> m_config;
  6499. IRunner* m_runner;
  6500. IResultCapture* m_resultCapture;
  6501. std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
  6502. };
  6503. namespace {
  6504. Context* currentContext = CATCH_NULL;
  6505. }
  6506. IMutableContext& getCurrentMutableContext() {
  6507. if( !currentContext )
  6508. currentContext = new Context();
  6509. return *currentContext;
  6510. }
  6511. IContext& getCurrentContext() {
  6512. return getCurrentMutableContext();
  6513. }
  6514. void cleanUpContext() {
  6515. delete currentContext;
  6516. currentContext = CATCH_NULL;
  6517. }
  6518. }
  6519. // #included from: catch_console_colour_impl.hpp
  6520. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
  6521. // #included from: catch_errno_guard.hpp
  6522. #define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
  6523. #include <cerrno>
  6524. namespace Catch {
  6525. class ErrnoGuard {
  6526. public:
  6527. ErrnoGuard():m_oldErrno(errno){}
  6528. ~ErrnoGuard() { errno = m_oldErrno; }
  6529. private:
  6530. int m_oldErrno;
  6531. };
  6532. }
  6533. namespace Catch {
  6534. namespace {
  6535. struct IColourImpl {
  6536. virtual ~IColourImpl() {}
  6537. virtual void use( Colour::Code _colourCode ) = 0;
  6538. };
  6539. struct NoColourImpl : IColourImpl {
  6540. void use( Colour::Code ) {}
  6541. static IColourImpl* instance() {
  6542. static NoColourImpl s_instance;
  6543. return &s_instance;
  6544. }
  6545. };
  6546. } // anon namespace
  6547. } // namespace Catch
  6548. #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
  6549. # ifdef CATCH_PLATFORM_WINDOWS
  6550. # define CATCH_CONFIG_COLOUR_WINDOWS
  6551. # else
  6552. # define CATCH_CONFIG_COLOUR_ANSI
  6553. # endif
  6554. #endif
  6555. #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
  6556. namespace Catch {
  6557. namespace {
  6558. class Win32ColourImpl : public IColourImpl {
  6559. public:
  6560. Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
  6561. {
  6562. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  6563. GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
  6564. originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
  6565. originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
  6566. }
  6567. virtual void use( Colour::Code _colourCode ) {
  6568. switch( _colourCode ) {
  6569. case Colour::None: return setTextAttribute( originalForegroundAttributes );
  6570. case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6571. case Colour::Red: return setTextAttribute( FOREGROUND_RED );
  6572. case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
  6573. case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
  6574. case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
  6575. case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
  6576. case Colour::Grey: return setTextAttribute( 0 );
  6577. case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
  6578. case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
  6579. case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
  6580. case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
  6581. case Colour::Bright: throw std::logic_error( "not a colour" );
  6582. }
  6583. }
  6584. private:
  6585. void setTextAttribute( WORD _textAttribute ) {
  6586. SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
  6587. }
  6588. HANDLE stdoutHandle;
  6589. WORD originalForegroundAttributes;
  6590. WORD originalBackgroundAttributes;
  6591. };
  6592. IColourImpl* platformColourInstance() {
  6593. static Win32ColourImpl s_instance;
  6594. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6595. UseColour::YesOrNo colourMode = config
  6596. ? config->useColour()
  6597. : UseColour::Auto;
  6598. if( colourMode == UseColour::Auto )
  6599. colourMode = !isDebuggerActive()
  6600. ? UseColour::Yes
  6601. : UseColour::No;
  6602. return colourMode == UseColour::Yes
  6603. ? &s_instance
  6604. : NoColourImpl::instance();
  6605. }
  6606. } // end anon namespace
  6607. } // end namespace Catch
  6608. #elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
  6609. #include <unistd.h>
  6610. namespace Catch {
  6611. namespace {
  6612. // use POSIX/ ANSI console terminal codes
  6613. // Thanks to Adam Strzelecki for original contribution
  6614. // (http://github.com/nanoant)
  6615. // https://github.com/philsquared/Catch/pull/131
  6616. class PosixColourImpl : public IColourImpl {
  6617. public:
  6618. virtual void use( Colour::Code _colourCode ) {
  6619. switch( _colourCode ) {
  6620. case Colour::None:
  6621. case Colour::White: return setColour( "[0m" );
  6622. case Colour::Red: return setColour( "[0;31m" );
  6623. case Colour::Green: return setColour( "[0;32m" );
  6624. case Colour::Blue: return setColour( "[0;34m" );
  6625. case Colour::Cyan: return setColour( "[0;36m" );
  6626. case Colour::Yellow: return setColour( "[0;33m" );
  6627. case Colour::Grey: return setColour( "[1;30m" );
  6628. case Colour::LightGrey: return setColour( "[0;37m" );
  6629. case Colour::BrightRed: return setColour( "[1;31m" );
  6630. case Colour::BrightGreen: return setColour( "[1;32m" );
  6631. case Colour::BrightWhite: return setColour( "[1;37m" );
  6632. case Colour::Bright: throw std::logic_error( "not a colour" );
  6633. }
  6634. }
  6635. static IColourImpl* instance() {
  6636. static PosixColourImpl s_instance;
  6637. return &s_instance;
  6638. }
  6639. private:
  6640. void setColour( const char* _escapeCode ) {
  6641. Catch::cout() << '\033' << _escapeCode;
  6642. }
  6643. };
  6644. IColourImpl* platformColourInstance() {
  6645. ErrnoGuard guard;
  6646. Ptr<IConfig const> config = getCurrentContext().getConfig();
  6647. UseColour::YesOrNo colourMode = config
  6648. ? config->useColour()
  6649. : UseColour::Auto;
  6650. if( colourMode == UseColour::Auto )
  6651. colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
  6652. ? UseColour::Yes
  6653. : UseColour::No;
  6654. return colourMode == UseColour::Yes
  6655. ? PosixColourImpl::instance()
  6656. : NoColourImpl::instance();
  6657. }
  6658. } // end anon namespace
  6659. } // end namespace Catch
  6660. #else // not Windows or ANSI ///////////////////////////////////////////////
  6661. namespace Catch {
  6662. static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
  6663. } // end namespace Catch
  6664. #endif // Windows/ ANSI/ None
  6665. namespace Catch {
  6666. Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
  6667. Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
  6668. Colour::~Colour(){ if( !m_moved ) use( None ); }
  6669. void Colour::use( Code _colourCode ) {
  6670. static IColourImpl* impl = platformColourInstance();
  6671. impl->use( _colourCode );
  6672. }
  6673. } // end namespace Catch
  6674. // #included from: catch_generators_impl.hpp
  6675. #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
  6676. #include <vector>
  6677. #include <string>
  6678. #include <map>
  6679. namespace Catch {
  6680. struct GeneratorInfo : IGeneratorInfo {
  6681. GeneratorInfo( std::size_t size )
  6682. : m_size( size ),
  6683. m_currentIndex( 0 )
  6684. {}
  6685. bool moveNext() {
  6686. if( ++m_currentIndex == m_size ) {
  6687. m_currentIndex = 0;
  6688. return false;
  6689. }
  6690. return true;
  6691. }
  6692. std::size_t getCurrentIndex() const {
  6693. return m_currentIndex;
  6694. }
  6695. std::size_t m_size;
  6696. std::size_t m_currentIndex;
  6697. };
  6698. ///////////////////////////////////////////////////////////////////////////
  6699. class GeneratorsForTest : public IGeneratorsForTest {
  6700. public:
  6701. ~GeneratorsForTest() {
  6702. deleteAll( m_generatorsInOrder );
  6703. }
  6704. IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
  6705. std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
  6706. if( it == m_generatorsByName.end() ) {
  6707. IGeneratorInfo* info = new GeneratorInfo( size );
  6708. m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
  6709. m_generatorsInOrder.push_back( info );
  6710. return *info;
  6711. }
  6712. return *it->second;
  6713. }
  6714. bool moveNext() {
  6715. std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
  6716. std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
  6717. for(; it != itEnd; ++it ) {
  6718. if( (*it)->moveNext() )
  6719. return true;
  6720. }
  6721. return false;
  6722. }
  6723. private:
  6724. std::map<std::string, IGeneratorInfo*> m_generatorsByName;
  6725. std::vector<IGeneratorInfo*> m_generatorsInOrder;
  6726. };
  6727. IGeneratorsForTest* createGeneratorsForTest()
  6728. {
  6729. return new GeneratorsForTest();
  6730. }
  6731. } // end namespace Catch
  6732. // #included from: catch_assertionresult.hpp
  6733. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
  6734. namespace Catch {
  6735. AssertionInfo::AssertionInfo():macroName(""), capturedExpression(""), resultDisposition(ResultDisposition::Normal), secondArg(""){}
  6736. AssertionInfo::AssertionInfo( char const * _macroName,
  6737. SourceLineInfo const& _lineInfo,
  6738. char const * _capturedExpression,
  6739. ResultDisposition::Flags _resultDisposition,
  6740. char const * _secondArg)
  6741. : macroName( _macroName ),
  6742. lineInfo( _lineInfo ),
  6743. capturedExpression( _capturedExpression ),
  6744. resultDisposition( _resultDisposition ),
  6745. secondArg( _secondArg )
  6746. {}
  6747. AssertionResult::AssertionResult() {}
  6748. AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
  6749. : m_info( info ),
  6750. m_resultData( data )
  6751. {}
  6752. AssertionResult::~AssertionResult() {}
  6753. // Result was a success
  6754. bool AssertionResult::succeeded() const {
  6755. return Catch::isOk( m_resultData.resultType );
  6756. }
  6757. // Result was a success, or failure is suppressed
  6758. bool AssertionResult::isOk() const {
  6759. return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
  6760. }
  6761. ResultWas::OfType AssertionResult::getResultType() const {
  6762. return m_resultData.resultType;
  6763. }
  6764. bool AssertionResult::hasExpression() const {
  6765. return m_info.capturedExpression[0] != 0;
  6766. }
  6767. bool AssertionResult::hasMessage() const {
  6768. return !m_resultData.message.empty();
  6769. }
  6770. std::string capturedExpressionWithSecondArgument( char const * capturedExpression, char const * secondArg ) {
  6771. return (secondArg[0] == 0 || secondArg[0] == '"' && secondArg[1] == '"')
  6772. ? capturedExpression
  6773. : std::string(capturedExpression) + ", " + secondArg;
  6774. }
  6775. std::string AssertionResult::getExpression() const {
  6776. if( isFalseTest( m_info.resultDisposition ) )
  6777. return "!(" + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + ")";
  6778. else
  6779. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6780. }
  6781. std::string AssertionResult::getExpressionInMacro() const {
  6782. if( m_info.macroName[0] == 0 )
  6783. return capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg);
  6784. else
  6785. return std::string(m_info.macroName) + "( " + capturedExpressionWithSecondArgument(m_info.capturedExpression, m_info.secondArg) + " )";
  6786. }
  6787. bool AssertionResult::hasExpandedExpression() const {
  6788. return hasExpression() && getExpandedExpression() != getExpression();
  6789. }
  6790. std::string AssertionResult::getExpandedExpression() const {
  6791. return m_resultData.reconstructExpression();
  6792. }
  6793. std::string AssertionResult::getMessage() const {
  6794. return m_resultData.message;
  6795. }
  6796. SourceLineInfo AssertionResult::getSourceInfo() const {
  6797. return m_info.lineInfo;
  6798. }
  6799. std::string AssertionResult::getTestMacroName() const {
  6800. return m_info.macroName;
  6801. }
  6802. void AssertionResult::discardDecomposedExpression() const {
  6803. m_resultData.decomposedExpression = CATCH_NULL;
  6804. }
  6805. void AssertionResult::expandDecomposedExpression() const {
  6806. m_resultData.reconstructExpression();
  6807. }
  6808. } // end namespace Catch
  6809. // #included from: catch_test_case_info.hpp
  6810. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
  6811. #include <cctype>
  6812. namespace Catch {
  6813. inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
  6814. if( startsWith( tag, '.' ) ||
  6815. tag == "hide" ||
  6816. tag == "!hide" )
  6817. return TestCaseInfo::IsHidden;
  6818. else if( tag == "!throws" )
  6819. return TestCaseInfo::Throws;
  6820. else if( tag == "!shouldfail" )
  6821. return TestCaseInfo::ShouldFail;
  6822. else if( tag == "!mayfail" )
  6823. return TestCaseInfo::MayFail;
  6824. else if( tag == "!nonportable" )
  6825. return TestCaseInfo::NonPortable;
  6826. else
  6827. return TestCaseInfo::None;
  6828. }
  6829. inline bool isReservedTag( std::string const& tag ) {
  6830. return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !std::isalnum( tag[0] );
  6831. }
  6832. inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
  6833. if( isReservedTag( tag ) ) {
  6834. std::ostringstream ss;
  6835. ss << Colour(Colour::Red)
  6836. << "Tag name [" << tag << "] not allowed.\n"
  6837. << "Tag names starting with non alpha-numeric characters are reserved\n"
  6838. << Colour(Colour::FileName)
  6839. << _lineInfo << '\n';
  6840. throw std::runtime_error(ss.str());
  6841. }
  6842. }
  6843. TestCase makeTestCase( ITestCase* _testCase,
  6844. std::string const& _className,
  6845. std::string const& _name,
  6846. std::string const& _descOrTags,
  6847. SourceLineInfo const& _lineInfo )
  6848. {
  6849. bool isHidden( startsWith( _name, "./" ) ); // Legacy support
  6850. // Parse out tags
  6851. std::set<std::string> tags;
  6852. std::string desc, tag;
  6853. bool inTag = false;
  6854. for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
  6855. char c = _descOrTags[i];
  6856. if( !inTag ) {
  6857. if( c == '[' )
  6858. inTag = true;
  6859. else
  6860. desc += c;
  6861. }
  6862. else {
  6863. if( c == ']' ) {
  6864. TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
  6865. if( prop == TestCaseInfo::IsHidden )
  6866. isHidden = true;
  6867. else if( prop == TestCaseInfo::None )
  6868. enforceNotReservedTag( tag, _lineInfo );
  6869. tags.insert( tag );
  6870. tag.clear();
  6871. inTag = false;
  6872. }
  6873. else
  6874. tag += c;
  6875. }
  6876. }
  6877. if( isHidden ) {
  6878. tags.insert( "hide" );
  6879. tags.insert( "." );
  6880. }
  6881. TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
  6882. return TestCase( _testCase, info );
  6883. }
  6884. void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
  6885. {
  6886. testCaseInfo.tags = tags;
  6887. testCaseInfo.lcaseTags.clear();
  6888. std::ostringstream oss;
  6889. for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
  6890. oss << '[' << *it << ']';
  6891. std::string lcaseTag = toLower( *it );
  6892. testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
  6893. testCaseInfo.lcaseTags.insert( lcaseTag );
  6894. }
  6895. testCaseInfo.tagsAsString = oss.str();
  6896. }
  6897. TestCaseInfo::TestCaseInfo( std::string const& _name,
  6898. std::string const& _className,
  6899. std::string const& _description,
  6900. std::set<std::string> const& _tags,
  6901. SourceLineInfo const& _lineInfo )
  6902. : name( _name ),
  6903. className( _className ),
  6904. description( _description ),
  6905. lineInfo( _lineInfo ),
  6906. properties( None )
  6907. {
  6908. setTags( *this, _tags );
  6909. }
  6910. TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
  6911. : name( other.name ),
  6912. className( other.className ),
  6913. description( other.description ),
  6914. tags( other.tags ),
  6915. lcaseTags( other.lcaseTags ),
  6916. tagsAsString( other.tagsAsString ),
  6917. lineInfo( other.lineInfo ),
  6918. properties( other.properties )
  6919. {}
  6920. bool TestCaseInfo::isHidden() const {
  6921. return ( properties & IsHidden ) != 0;
  6922. }
  6923. bool TestCaseInfo::throws() const {
  6924. return ( properties & Throws ) != 0;
  6925. }
  6926. bool TestCaseInfo::okToFail() const {
  6927. return ( properties & (ShouldFail | MayFail ) ) != 0;
  6928. }
  6929. bool TestCaseInfo::expectedToFail() const {
  6930. return ( properties & (ShouldFail ) ) != 0;
  6931. }
  6932. TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
  6933. TestCase::TestCase( TestCase const& other )
  6934. : TestCaseInfo( other ),
  6935. test( other.test )
  6936. {}
  6937. TestCase TestCase::withName( std::string const& _newName ) const {
  6938. TestCase other( *this );
  6939. other.name = _newName;
  6940. return other;
  6941. }
  6942. void TestCase::swap( TestCase& other ) {
  6943. test.swap( other.test );
  6944. name.swap( other.name );
  6945. className.swap( other.className );
  6946. description.swap( other.description );
  6947. tags.swap( other.tags );
  6948. lcaseTags.swap( other.lcaseTags );
  6949. tagsAsString.swap( other.tagsAsString );
  6950. std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
  6951. std::swap( lineInfo, other.lineInfo );
  6952. }
  6953. void TestCase::invoke() const {
  6954. test->invoke();
  6955. }
  6956. bool TestCase::operator == ( TestCase const& other ) const {
  6957. return test.get() == other.test.get() &&
  6958. name == other.name &&
  6959. className == other.className;
  6960. }
  6961. bool TestCase::operator < ( TestCase const& other ) const {
  6962. return name < other.name;
  6963. }
  6964. TestCase& TestCase::operator = ( TestCase const& other ) {
  6965. TestCase temp( other );
  6966. swap( temp );
  6967. return *this;
  6968. }
  6969. TestCaseInfo const& TestCase::getTestCaseInfo() const
  6970. {
  6971. return *this;
  6972. }
  6973. } // end namespace Catch
  6974. // #included from: catch_version.hpp
  6975. #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
  6976. namespace Catch {
  6977. Version::Version
  6978. ( unsigned int _majorVersion,
  6979. unsigned int _minorVersion,
  6980. unsigned int _patchNumber,
  6981. char const * const _branchName,
  6982. unsigned int _buildNumber )
  6983. : majorVersion( _majorVersion ),
  6984. minorVersion( _minorVersion ),
  6985. patchNumber( _patchNumber ),
  6986. branchName( _branchName ),
  6987. buildNumber( _buildNumber )
  6988. {}
  6989. std::ostream& operator << ( std::ostream& os, Version const& version ) {
  6990. os << version.majorVersion << '.'
  6991. << version.minorVersion << '.'
  6992. << version.patchNumber;
  6993. // branchName is never null -> 0th char is \0 if it is empty
  6994. if (version.branchName[0]) {
  6995. os << '-' << version.branchName
  6996. << '.' << version.buildNumber;
  6997. }
  6998. return os;
  6999. }
  7000. inline Version libraryVersion() {
  7001. static Version version( 1, 12, 2, "", 0 );
  7002. return version;
  7003. }
  7004. }
  7005. // #included from: catch_message.hpp
  7006. #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
  7007. namespace Catch {
  7008. MessageInfo::MessageInfo( std::string const& _macroName,
  7009. SourceLineInfo const& _lineInfo,
  7010. ResultWas::OfType _type )
  7011. : macroName( _macroName ),
  7012. lineInfo( _lineInfo ),
  7013. type( _type ),
  7014. sequence( ++globalCount )
  7015. {}
  7016. // This may need protecting if threading support is added
  7017. unsigned int MessageInfo::globalCount = 0;
  7018. ////////////////////////////////////////////////////////////////////////////
  7019. ScopedMessage::ScopedMessage( MessageBuilder const& builder )
  7020. : m_info( builder.m_info )
  7021. {
  7022. m_info.message = builder.m_stream.str();
  7023. getResultCapture().pushScopedMessage( m_info );
  7024. }
  7025. ScopedMessage::ScopedMessage( ScopedMessage const& other )
  7026. : m_info( other.m_info )
  7027. {}
  7028. #if defined(_MSC_VER)
  7029. #pragma warning(push)
  7030. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7031. #endif
  7032. ScopedMessage::~ScopedMessage() {
  7033. if ( !std::uncaught_exception() ){
  7034. getResultCapture().popScopedMessage(m_info);
  7035. }
  7036. }
  7037. #if defined(_MSC_VER)
  7038. #pragma warning(pop)
  7039. #endif
  7040. } // end namespace Catch
  7041. // #included from: catch_legacy_reporter_adapter.hpp
  7042. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
  7043. // #included from: catch_legacy_reporter_adapter.h
  7044. #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
  7045. namespace Catch
  7046. {
  7047. // Deprecated
  7048. struct IReporter : IShared {
  7049. virtual ~IReporter();
  7050. virtual bool shouldRedirectStdout() const = 0;
  7051. virtual void StartTesting() = 0;
  7052. virtual void EndTesting( Totals const& totals ) = 0;
  7053. virtual void StartGroup( std::string const& groupName ) = 0;
  7054. virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
  7055. virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
  7056. virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
  7057. virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
  7058. virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
  7059. virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
  7060. virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
  7061. virtual void Aborted() = 0;
  7062. virtual void Result( AssertionResult const& result ) = 0;
  7063. };
  7064. class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
  7065. {
  7066. public:
  7067. LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
  7068. virtual ~LegacyReporterAdapter();
  7069. virtual ReporterPreferences getPreferences() const;
  7070. virtual void noMatchingTestCases( std::string const& );
  7071. virtual void testRunStarting( TestRunInfo const& );
  7072. virtual void testGroupStarting( GroupInfo const& groupInfo );
  7073. virtual void testCaseStarting( TestCaseInfo const& testInfo );
  7074. virtual void sectionStarting( SectionInfo const& sectionInfo );
  7075. virtual void assertionStarting( AssertionInfo const& );
  7076. virtual bool assertionEnded( AssertionStats const& assertionStats );
  7077. virtual void sectionEnded( SectionStats const& sectionStats );
  7078. virtual void testCaseEnded( TestCaseStats const& testCaseStats );
  7079. virtual void testGroupEnded( TestGroupStats const& testGroupStats );
  7080. virtual void testRunEnded( TestRunStats const& testRunStats );
  7081. virtual void skipTest( TestCaseInfo const& );
  7082. private:
  7083. Ptr<IReporter> m_legacyReporter;
  7084. };
  7085. }
  7086. namespace Catch
  7087. {
  7088. LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
  7089. : m_legacyReporter( legacyReporter )
  7090. {}
  7091. LegacyReporterAdapter::~LegacyReporterAdapter() {}
  7092. ReporterPreferences LegacyReporterAdapter::getPreferences() const {
  7093. ReporterPreferences prefs;
  7094. prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
  7095. return prefs;
  7096. }
  7097. void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
  7098. void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
  7099. m_legacyReporter->StartTesting();
  7100. }
  7101. void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
  7102. m_legacyReporter->StartGroup( groupInfo.name );
  7103. }
  7104. void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
  7105. m_legacyReporter->StartTestCase( testInfo );
  7106. }
  7107. void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
  7108. m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
  7109. }
  7110. void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
  7111. // Not on legacy interface
  7112. }
  7113. bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
  7114. if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
  7115. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  7116. it != itEnd;
  7117. ++it ) {
  7118. if( it->type == ResultWas::Info ) {
  7119. ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
  7120. rb << it->message;
  7121. rb.setResultType( ResultWas::Info );
  7122. AssertionResult result = rb.build();
  7123. m_legacyReporter->Result( result );
  7124. }
  7125. }
  7126. }
  7127. m_legacyReporter->Result( assertionStats.assertionResult );
  7128. return true;
  7129. }
  7130. void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
  7131. if( sectionStats.missingAssertions )
  7132. m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
  7133. m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
  7134. }
  7135. void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
  7136. m_legacyReporter->EndTestCase
  7137. ( testCaseStats.testInfo,
  7138. testCaseStats.totals,
  7139. testCaseStats.stdOut,
  7140. testCaseStats.stdErr );
  7141. }
  7142. void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
  7143. if( testGroupStats.aborting )
  7144. m_legacyReporter->Aborted();
  7145. m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
  7146. }
  7147. void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
  7148. m_legacyReporter->EndTesting( testRunStats.totals );
  7149. }
  7150. void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
  7151. }
  7152. }
  7153. // #included from: catch_timer.hpp
  7154. #ifdef __clang__
  7155. #pragma clang diagnostic push
  7156. #pragma clang diagnostic ignored "-Wc++11-long-long"
  7157. #endif
  7158. #ifdef CATCH_PLATFORM_WINDOWS
  7159. #else
  7160. #include <sys/time.h>
  7161. #endif
  7162. namespace Catch {
  7163. namespace {
  7164. #ifdef CATCH_PLATFORM_WINDOWS
  7165. UInt64 getCurrentTicks() {
  7166. static UInt64 hz=0, hzo=0;
  7167. if (!hz) {
  7168. QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
  7169. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
  7170. }
  7171. UInt64 t;
  7172. QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
  7173. return ((t-hzo)*1000000)/hz;
  7174. }
  7175. #else
  7176. UInt64 getCurrentTicks() {
  7177. timeval t;
  7178. gettimeofday(&t,CATCH_NULL);
  7179. return static_cast<UInt64>( t.tv_sec ) * 1000000ull + static_cast<UInt64>( t.tv_usec );
  7180. }
  7181. #endif
  7182. }
  7183. void Timer::start() {
  7184. m_ticks = getCurrentTicks();
  7185. }
  7186. unsigned int Timer::getElapsedMicroseconds() const {
  7187. return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
  7188. }
  7189. unsigned int Timer::getElapsedMilliseconds() const {
  7190. return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
  7191. }
  7192. double Timer::getElapsedSeconds() const {
  7193. return getElapsedMicroseconds()/1000000.0;
  7194. }
  7195. } // namespace Catch
  7196. #ifdef __clang__
  7197. #pragma clang diagnostic pop
  7198. #endif
  7199. // #included from: catch_common.hpp
  7200. #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
  7201. #include <cstring>
  7202. #include <cctype>
  7203. namespace Catch {
  7204. bool startsWith( std::string const& s, std::string const& prefix ) {
  7205. return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin());
  7206. }
  7207. bool startsWith( std::string const& s, char prefix ) {
  7208. return !s.empty() && s[0] == prefix;
  7209. }
  7210. bool endsWith( std::string const& s, std::string const& suffix ) {
  7211. return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin());
  7212. }
  7213. bool endsWith( std::string const& s, char suffix ) {
  7214. return !s.empty() && s[s.size()-1] == suffix;
  7215. }
  7216. bool contains( std::string const& s, std::string const& infix ) {
  7217. return s.find( infix ) != std::string::npos;
  7218. }
  7219. char toLowerCh(char c) {
  7220. return static_cast<char>( std::tolower( c ) );
  7221. }
  7222. void toLowerInPlace( std::string& s ) {
  7223. std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
  7224. }
  7225. std::string toLower( std::string const& s ) {
  7226. std::string lc = s;
  7227. toLowerInPlace( lc );
  7228. return lc;
  7229. }
  7230. std::string trim( std::string const& str ) {
  7231. static char const* whitespaceChars = "\n\r\t ";
  7232. std::string::size_type start = str.find_first_not_of( whitespaceChars );
  7233. std::string::size_type end = str.find_last_not_of( whitespaceChars );
  7234. return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string();
  7235. }
  7236. bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
  7237. bool replaced = false;
  7238. std::size_t i = str.find( replaceThis );
  7239. while( i != std::string::npos ) {
  7240. replaced = true;
  7241. str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
  7242. if( i < str.size()-withThis.size() )
  7243. i = str.find( replaceThis, i+withThis.size() );
  7244. else
  7245. i = std::string::npos;
  7246. }
  7247. return replaced;
  7248. }
  7249. pluralise::pluralise( std::size_t count, std::string const& label )
  7250. : m_count( count ),
  7251. m_label( label )
  7252. {}
  7253. std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
  7254. os << pluraliser.m_count << ' ' << pluraliser.m_label;
  7255. if( pluraliser.m_count != 1 )
  7256. os << 's';
  7257. return os;
  7258. }
  7259. SourceLineInfo::SourceLineInfo() : file(""), line( 0 ){}
  7260. SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
  7261. : file( _file ),
  7262. line( _line )
  7263. {}
  7264. bool SourceLineInfo::empty() const {
  7265. return file[0] == '\0';
  7266. }
  7267. bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
  7268. return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
  7269. }
  7270. bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
  7271. return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
  7272. }
  7273. void seedRng( IConfig const& config ) {
  7274. if( config.rngSeed() != 0 )
  7275. std::srand( config.rngSeed() );
  7276. }
  7277. unsigned int rngSeed() {
  7278. return getCurrentContext().getConfig()->rngSeed();
  7279. }
  7280. std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
  7281. #ifndef __GNUG__
  7282. os << info.file << '(' << info.line << ')';
  7283. #else
  7284. os << info.file << ':' << info.line;
  7285. #endif
  7286. return os;
  7287. }
  7288. void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
  7289. std::ostringstream oss;
  7290. oss << locationInfo << ": Internal Catch error: '" << message << '\'';
  7291. if( alwaysTrue() )
  7292. throw std::logic_error( oss.str() );
  7293. }
  7294. }
  7295. // #included from: catch_section.hpp
  7296. #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
  7297. namespace Catch {
  7298. SectionInfo::SectionInfo
  7299. ( SourceLineInfo const& _lineInfo,
  7300. std::string const& _name,
  7301. std::string const& _description )
  7302. : name( _name ),
  7303. description( _description ),
  7304. lineInfo( _lineInfo )
  7305. {}
  7306. Section::Section( SectionInfo const& info )
  7307. : m_info( info ),
  7308. m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
  7309. {
  7310. m_timer.start();
  7311. }
  7312. #if defined(_MSC_VER)
  7313. #pragma warning(push)
  7314. #pragma warning(disable:4996) // std::uncaught_exception is deprecated in C++17
  7315. #endif
  7316. Section::~Section() {
  7317. if( m_sectionIncluded ) {
  7318. SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
  7319. if( std::uncaught_exception() )
  7320. getResultCapture().sectionEndedEarly( endInfo );
  7321. else
  7322. getResultCapture().sectionEnded( endInfo );
  7323. }
  7324. }
  7325. #if defined(_MSC_VER)
  7326. #pragma warning(pop)
  7327. #endif
  7328. // This indicates whether the section should be executed or not
  7329. Section::operator bool() const {
  7330. return m_sectionIncluded;
  7331. }
  7332. } // end namespace Catch
  7333. // #included from: catch_debugger.hpp
  7334. #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
  7335. #ifdef CATCH_PLATFORM_MAC
  7336. #include <assert.h>
  7337. #include <stdbool.h>
  7338. #include <sys/types.h>
  7339. #include <unistd.h>
  7340. #include <sys/sysctl.h>
  7341. namespace Catch{
  7342. // The following function is taken directly from the following technical note:
  7343. // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
  7344. // Returns true if the current process is being debugged (either
  7345. // running under the debugger or has a debugger attached post facto).
  7346. bool isDebuggerActive(){
  7347. int mib[4];
  7348. struct kinfo_proc info;
  7349. size_t size;
  7350. // Initialize the flags so that, if sysctl fails for some bizarre
  7351. // reason, we get a predictable result.
  7352. info.kp_proc.p_flag = 0;
  7353. // Initialize mib, which tells sysctl the info we want, in this case
  7354. // we're looking for information about a specific process ID.
  7355. mib[0] = CTL_KERN;
  7356. mib[1] = KERN_PROC;
  7357. mib[2] = KERN_PROC_PID;
  7358. mib[3] = getpid();
  7359. // Call sysctl.
  7360. size = sizeof(info);
  7361. if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
  7362. Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
  7363. return false;
  7364. }
  7365. // We're being debugged if the P_TRACED flag is set.
  7366. return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
  7367. }
  7368. } // namespace Catch
  7369. #elif defined(CATCH_PLATFORM_LINUX)
  7370. #include <fstream>
  7371. #include <string>
  7372. namespace Catch{
  7373. // The standard POSIX way of detecting a debugger is to attempt to
  7374. // ptrace() the process, but this needs to be done from a child and not
  7375. // this process itself to still allow attaching to this process later
  7376. // if wanted, so is rather heavy. Under Linux we have the PID of the
  7377. // "debugger" (which doesn't need to be gdb, of course, it could also
  7378. // be strace, for example) in /proc/$PID/status, so just get it from
  7379. // there instead.
  7380. bool isDebuggerActive(){
  7381. // Libstdc++ has a bug, where std::ifstream sets errno to 0
  7382. // This way our users can properly assert over errno values
  7383. ErrnoGuard guard;
  7384. std::ifstream in("/proc/self/status");
  7385. for( std::string line; std::getline(in, line); ) {
  7386. static const int PREFIX_LEN = 11;
  7387. if( line.compare(0, PREFIX_LEN, "TracerPid:\t") == 0 ) {
  7388. // We're traced if the PID is not 0 and no other PID starts
  7389. // with 0 digit, so it's enough to check for just a single
  7390. // character.
  7391. return line.length() > PREFIX_LEN && line[PREFIX_LEN] != '0';
  7392. }
  7393. }
  7394. return false;
  7395. }
  7396. } // namespace Catch
  7397. #elif defined(_MSC_VER)
  7398. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7399. namespace Catch {
  7400. bool isDebuggerActive() {
  7401. return IsDebuggerPresent() != 0;
  7402. }
  7403. }
  7404. #elif defined(__MINGW32__)
  7405. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  7406. namespace Catch {
  7407. bool isDebuggerActive() {
  7408. return IsDebuggerPresent() != 0;
  7409. }
  7410. }
  7411. #else
  7412. namespace Catch {
  7413. inline bool isDebuggerActive() { return false; }
  7414. }
  7415. #endif // Platform
  7416. #ifdef CATCH_PLATFORM_WINDOWS
  7417. namespace Catch {
  7418. void writeToDebugConsole( std::string const& text ) {
  7419. ::OutputDebugStringA( text.c_str() );
  7420. }
  7421. }
  7422. #else
  7423. namespace Catch {
  7424. void writeToDebugConsole( std::string const& text ) {
  7425. // !TBD: Need a version for Mac/ XCode and other IDEs
  7426. Catch::cout() << text;
  7427. }
  7428. }
  7429. #endif // Platform
  7430. // #included from: catch_tostring.hpp
  7431. #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
  7432. namespace Catch {
  7433. namespace Detail {
  7434. const std::string unprintableString = "{?}";
  7435. namespace {
  7436. const int hexThreshold = 255;
  7437. struct Endianness {
  7438. enum Arch { Big, Little };
  7439. static Arch which() {
  7440. union _{
  7441. int asInt;
  7442. char asChar[sizeof (int)];
  7443. } u;
  7444. u.asInt = 1;
  7445. return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
  7446. }
  7447. };
  7448. }
  7449. std::string rawMemoryToString( const void *object, std::size_t size )
  7450. {
  7451. // Reverse order for little endian architectures
  7452. int i = 0, end = static_cast<int>( size ), inc = 1;
  7453. if( Endianness::which() == Endianness::Little ) {
  7454. i = end-1;
  7455. end = inc = -1;
  7456. }
  7457. unsigned char const *bytes = static_cast<unsigned char const *>(object);
  7458. std::ostringstream os;
  7459. os << "0x" << std::setfill('0') << std::hex;
  7460. for( ; i != end; i += inc )
  7461. os << std::setw(2) << static_cast<unsigned>(bytes[i]);
  7462. return os.str();
  7463. }
  7464. }
  7465. std::string toString( std::string const& value ) {
  7466. std::string s = value;
  7467. if( getCurrentContext().getConfig()->showInvisibles() ) {
  7468. for(size_t i = 0; i < s.size(); ++i ) {
  7469. std::string subs;
  7470. switch( s[i] ) {
  7471. case '\n': subs = "\\n"; break;
  7472. case '\t': subs = "\\t"; break;
  7473. default: break;
  7474. }
  7475. if( !subs.empty() ) {
  7476. s = s.substr( 0, i ) + subs + s.substr( i+1 );
  7477. ++i;
  7478. }
  7479. }
  7480. }
  7481. return '"' + s + '"';
  7482. }
  7483. std::string toString( std::wstring const& value ) {
  7484. std::string s;
  7485. s.reserve( value.size() );
  7486. for(size_t i = 0; i < value.size(); ++i )
  7487. s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
  7488. return Catch::toString( s );
  7489. }
  7490. std::string toString( const char* const value ) {
  7491. return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
  7492. }
  7493. std::string toString( char* const value ) {
  7494. return Catch::toString( static_cast<const char*>( value ) );
  7495. }
  7496. std::string toString( const wchar_t* const value )
  7497. {
  7498. return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
  7499. }
  7500. std::string toString( wchar_t* const value )
  7501. {
  7502. return Catch::toString( static_cast<const wchar_t*>( value ) );
  7503. }
  7504. std::string toString( int value ) {
  7505. std::ostringstream oss;
  7506. oss << value;
  7507. if( value > Detail::hexThreshold )
  7508. oss << " (0x" << std::hex << value << ')';
  7509. return oss.str();
  7510. }
  7511. std::string toString( unsigned long value ) {
  7512. std::ostringstream oss;
  7513. oss << value;
  7514. if( value > Detail::hexThreshold )
  7515. oss << " (0x" << std::hex << value << ')';
  7516. return oss.str();
  7517. }
  7518. std::string toString( unsigned int value ) {
  7519. return Catch::toString( static_cast<unsigned long>( value ) );
  7520. }
  7521. template<typename T>
  7522. std::string fpToString( T value, int precision ) {
  7523. std::ostringstream oss;
  7524. oss << std::setprecision( precision )
  7525. << std::fixed
  7526. << value;
  7527. std::string d = oss.str();
  7528. std::size_t i = d.find_last_not_of( '0' );
  7529. if( i != std::string::npos && i != d.size()-1 ) {
  7530. if( d[i] == '.' )
  7531. i++;
  7532. d = d.substr( 0, i+1 );
  7533. }
  7534. return d;
  7535. }
  7536. std::string toString( const double value ) {
  7537. return fpToString( value, 10 );
  7538. }
  7539. std::string toString( const float value ) {
  7540. return fpToString( value, 5 ) + 'f';
  7541. }
  7542. std::string toString( bool value ) {
  7543. return value ? "true" : "false";
  7544. }
  7545. std::string toString( char value ) {
  7546. if ( value == '\r' )
  7547. return "'\\r'";
  7548. if ( value == '\f' )
  7549. return "'\\f'";
  7550. if ( value == '\n' )
  7551. return "'\\n'";
  7552. if ( value == '\t' )
  7553. return "'\\t'";
  7554. if ( '\0' <= value && value < ' ' )
  7555. return toString( static_cast<unsigned int>( value ) );
  7556. char chstr[] = "' '";
  7557. chstr[1] = value;
  7558. return chstr;
  7559. }
  7560. std::string toString( signed char value ) {
  7561. return toString( static_cast<char>( value ) );
  7562. }
  7563. std::string toString( unsigned char value ) {
  7564. return toString( static_cast<char>( value ) );
  7565. }
  7566. #ifdef CATCH_CONFIG_CPP11_LONG_LONG
  7567. std::string toString( long long value ) {
  7568. std::ostringstream oss;
  7569. oss << value;
  7570. if( value > Detail::hexThreshold )
  7571. oss << " (0x" << std::hex << value << ')';
  7572. return oss.str();
  7573. }
  7574. std::string toString( unsigned long long value ) {
  7575. std::ostringstream oss;
  7576. oss << value;
  7577. if( value > Detail::hexThreshold )
  7578. oss << " (0x" << std::hex << value << ')';
  7579. return oss.str();
  7580. }
  7581. #endif
  7582. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  7583. std::string toString( std::nullptr_t ) {
  7584. return "nullptr";
  7585. }
  7586. #endif
  7587. #ifdef __OBJC__
  7588. std::string toString( NSString const * const& nsstring ) {
  7589. if( !nsstring )
  7590. return "nil";
  7591. return "@" + toString([nsstring UTF8String]);
  7592. }
  7593. std::string toString( NSString * CATCH_ARC_STRONG & nsstring ) {
  7594. if( !nsstring )
  7595. return "nil";
  7596. return "@" + toString([nsstring UTF8String]);
  7597. }
  7598. std::string toString( NSObject* const& nsObject ) {
  7599. return toString( [nsObject description] );
  7600. }
  7601. #endif
  7602. } // end namespace Catch
  7603. // #included from: catch_result_builder.hpp
  7604. #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
  7605. #include <cassert>
  7606. namespace Catch {
  7607. ResultBuilder::ResultBuilder( char const* macroName,
  7608. SourceLineInfo const& lineInfo,
  7609. char const* capturedExpression,
  7610. ResultDisposition::Flags resultDisposition,
  7611. char const* secondArg )
  7612. : m_assertionInfo( macroName, lineInfo, capturedExpression, resultDisposition, secondArg ),
  7613. m_shouldDebugBreak( false ),
  7614. m_shouldThrow( false ),
  7615. m_guardException( false ),
  7616. m_usedStream( false )
  7617. {}
  7618. ResultBuilder::~ResultBuilder() {
  7619. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7620. if ( m_guardException ) {
  7621. stream().oss << "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE";
  7622. captureResult( ResultWas::ThrewException );
  7623. getCurrentContext().getResultCapture()->exceptionEarlyReported();
  7624. }
  7625. #endif
  7626. }
  7627. ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
  7628. m_data.resultType = result;
  7629. return *this;
  7630. }
  7631. ResultBuilder& ResultBuilder::setResultType( bool result ) {
  7632. m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
  7633. return *this;
  7634. }
  7635. void ResultBuilder::endExpression( DecomposedExpression const& expr ) {
  7636. // Flip bool results if FalseTest flag is set
  7637. if( isFalseTest( m_assertionInfo.resultDisposition ) ) {
  7638. m_data.negate( expr.isBinaryExpression() );
  7639. }
  7640. getResultCapture().assertionRun();
  7641. if(getCurrentContext().getConfig()->includeSuccessfulResults() || m_data.resultType != ResultWas::Ok)
  7642. {
  7643. AssertionResult result = build( expr );
  7644. handleResult( result );
  7645. }
  7646. else
  7647. getResultCapture().assertionPassed();
  7648. }
  7649. void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
  7650. m_assertionInfo.resultDisposition = resultDisposition;
  7651. stream().oss << Catch::translateActiveException();
  7652. captureResult( ResultWas::ThrewException );
  7653. }
  7654. void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
  7655. setResultType( resultType );
  7656. captureExpression();
  7657. }
  7658. void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
  7659. if( expectedMessage.empty() )
  7660. captureExpectedException( Matchers::Impl::MatchAllOf<std::string>() );
  7661. else
  7662. captureExpectedException( Matchers::Equals( expectedMessage ) );
  7663. }
  7664. void ResultBuilder::captureExpectedException( Matchers::Impl::MatcherBase<std::string> const& matcher ) {
  7665. assert( !isFalseTest( m_assertionInfo.resultDisposition ) );
  7666. AssertionResultData data = m_data;
  7667. data.resultType = ResultWas::Ok;
  7668. data.reconstructedExpression = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7669. std::string actualMessage = Catch::translateActiveException();
  7670. if( !matcher.match( actualMessage ) ) {
  7671. data.resultType = ResultWas::ExpressionFailed;
  7672. data.reconstructedExpression = actualMessage;
  7673. }
  7674. AssertionResult result( m_assertionInfo, data );
  7675. handleResult( result );
  7676. }
  7677. void ResultBuilder::captureExpression() {
  7678. AssertionResult result = build();
  7679. handleResult( result );
  7680. }
  7681. void ResultBuilder::handleResult( AssertionResult const& result )
  7682. {
  7683. getResultCapture().assertionEnded( result );
  7684. if( !result.isOk() ) {
  7685. if( getCurrentContext().getConfig()->shouldDebugBreak() )
  7686. m_shouldDebugBreak = true;
  7687. if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
  7688. m_shouldThrow = true;
  7689. }
  7690. }
  7691. void ResultBuilder::react() {
  7692. #if defined(CATCH_CONFIG_FAST_COMPILE)
  7693. if (m_shouldDebugBreak) {
  7694. ///////////////////////////////////////////////////////////////////
  7695. // To inspect the state during test, you need to go one level up the callstack
  7696. // To go back to the test and change execution, jump over the throw statement
  7697. ///////////////////////////////////////////////////////////////////
  7698. CATCH_BREAK_INTO_DEBUGGER();
  7699. }
  7700. #endif
  7701. if( m_shouldThrow )
  7702. throw Catch::TestFailureException();
  7703. }
  7704. bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
  7705. bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
  7706. AssertionResult ResultBuilder::build() const
  7707. {
  7708. return build( *this );
  7709. }
  7710. // CAVEAT: The returned AssertionResult stores a pointer to the argument expr,
  7711. // a temporary DecomposedExpression, which in turn holds references to
  7712. // operands, possibly temporary as well.
  7713. // It should immediately be passed to handleResult; if the expression
  7714. // needs to be reported, its string expansion must be composed before
  7715. // the temporaries are destroyed.
  7716. AssertionResult ResultBuilder::build( DecomposedExpression const& expr ) const
  7717. {
  7718. assert( m_data.resultType != ResultWas::Unknown );
  7719. AssertionResultData data = m_data;
  7720. if(m_usedStream)
  7721. data.message = m_stream().oss.str();
  7722. data.decomposedExpression = &expr; // for lazy reconstruction
  7723. return AssertionResult( m_assertionInfo, data );
  7724. }
  7725. void ResultBuilder::reconstructExpression( std::string& dest ) const {
  7726. dest = capturedExpressionWithSecondArgument(m_assertionInfo.capturedExpression, m_assertionInfo.secondArg);
  7727. }
  7728. void ResultBuilder::setExceptionGuard() {
  7729. m_guardException = true;
  7730. }
  7731. void ResultBuilder::unsetExceptionGuard() {
  7732. m_guardException = false;
  7733. }
  7734. } // end namespace Catch
  7735. // #included from: catch_tag_alias_registry.hpp
  7736. #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
  7737. namespace Catch {
  7738. TagAliasRegistry::~TagAliasRegistry() {}
  7739. Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
  7740. std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
  7741. if( it != m_registry.end() )
  7742. return it->second;
  7743. else
  7744. return Option<TagAlias>();
  7745. }
  7746. std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
  7747. std::string expandedTestSpec = unexpandedTestSpec;
  7748. for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
  7749. it != itEnd;
  7750. ++it ) {
  7751. std::size_t pos = expandedTestSpec.find( it->first );
  7752. if( pos != std::string::npos ) {
  7753. expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
  7754. it->second.tag +
  7755. expandedTestSpec.substr( pos + it->first.size() );
  7756. }
  7757. }
  7758. return expandedTestSpec;
  7759. }
  7760. void TagAliasRegistry::add( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) {
  7761. if( !startsWith( alias, "[@" ) || !endsWith( alias, ']' ) ) {
  7762. std::ostringstream oss;
  7763. oss << Colour( Colour::Red )
  7764. << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n"
  7765. << Colour( Colour::FileName )
  7766. << lineInfo << '\n';
  7767. throw std::domain_error( oss.str().c_str() );
  7768. }
  7769. if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
  7770. std::ostringstream oss;
  7771. oss << Colour( Colour::Red )
  7772. << "error: tag alias, \"" << alias << "\" already registered.\n"
  7773. << "\tFirst seen at "
  7774. << Colour( Colour::Red ) << find(alias)->lineInfo << '\n'
  7775. << Colour( Colour::Red ) << "\tRedefined at "
  7776. << Colour( Colour::FileName) << lineInfo << '\n';
  7777. throw std::domain_error( oss.str().c_str() );
  7778. }
  7779. }
  7780. ITagAliasRegistry::~ITagAliasRegistry() {}
  7781. ITagAliasRegistry const& ITagAliasRegistry::get() {
  7782. return getRegistryHub().getTagAliasRegistry();
  7783. }
  7784. RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
  7785. getMutableRegistryHub().registerTagAlias( alias, tag, lineInfo );
  7786. }
  7787. } // end namespace Catch
  7788. // #included from: catch_matchers_string.hpp
  7789. namespace Catch {
  7790. namespace Matchers {
  7791. namespace StdString {
  7792. CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
  7793. : m_caseSensitivity( caseSensitivity ),
  7794. m_str( adjustString( str ) )
  7795. {}
  7796. std::string CasedString::adjustString( std::string const& str ) const {
  7797. return m_caseSensitivity == CaseSensitive::No
  7798. ? toLower( str )
  7799. : str;
  7800. }
  7801. std::string CasedString::caseSensitivitySuffix() const {
  7802. return m_caseSensitivity == CaseSensitive::No
  7803. ? " (case insensitive)"
  7804. : std::string();
  7805. }
  7806. StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
  7807. : m_comparator( comparator ),
  7808. m_operation( operation ) {
  7809. }
  7810. std::string StringMatcherBase::describe() const {
  7811. std::string description;
  7812. description.reserve(5 + m_operation.size() + m_comparator.m_str.size() +
  7813. m_comparator.caseSensitivitySuffix().size());
  7814. description += m_operation;
  7815. description += ": \"";
  7816. description += m_comparator.m_str;
  7817. description += "\"";
  7818. description += m_comparator.caseSensitivitySuffix();
  7819. return description;
  7820. }
  7821. EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {}
  7822. bool EqualsMatcher::match( std::string const& source ) const {
  7823. return m_comparator.adjustString( source ) == m_comparator.m_str;
  7824. }
  7825. ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {}
  7826. bool ContainsMatcher::match( std::string const& source ) const {
  7827. return contains( m_comparator.adjustString( source ), m_comparator.m_str );
  7828. }
  7829. StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {}
  7830. bool StartsWithMatcher::match( std::string const& source ) const {
  7831. return startsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7832. }
  7833. EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {}
  7834. bool EndsWithMatcher::match( std::string const& source ) const {
  7835. return endsWith( m_comparator.adjustString( source ), m_comparator.m_str );
  7836. }
  7837. } // namespace StdString
  7838. StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7839. return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) );
  7840. }
  7841. StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7842. return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) );
  7843. }
  7844. StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7845. return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7846. }
  7847. StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) {
  7848. return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) );
  7849. }
  7850. } // namespace Matchers
  7851. } // namespace Catch
  7852. // #included from: ../reporters/catch_reporter_multi.hpp
  7853. #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
  7854. namespace Catch {
  7855. class MultipleReporters : public SharedImpl<IStreamingReporter> {
  7856. typedef std::vector<Ptr<IStreamingReporter> > Reporters;
  7857. Reporters m_reporters;
  7858. public:
  7859. void add( Ptr<IStreamingReporter> const& reporter ) {
  7860. m_reporters.push_back( reporter );
  7861. }
  7862. public: // IStreamingReporter
  7863. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  7864. return m_reporters[0]->getPreferences();
  7865. }
  7866. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  7867. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7868. it != itEnd;
  7869. ++it )
  7870. (*it)->noMatchingTestCases( spec );
  7871. }
  7872. virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
  7873. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7874. it != itEnd;
  7875. ++it )
  7876. (*it)->testRunStarting( testRunInfo );
  7877. }
  7878. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  7879. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7880. it != itEnd;
  7881. ++it )
  7882. (*it)->testGroupStarting( groupInfo );
  7883. }
  7884. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7885. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7886. it != itEnd;
  7887. ++it )
  7888. (*it)->testCaseStarting( testInfo );
  7889. }
  7890. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  7891. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7892. it != itEnd;
  7893. ++it )
  7894. (*it)->sectionStarting( sectionInfo );
  7895. }
  7896. virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
  7897. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7898. it != itEnd;
  7899. ++it )
  7900. (*it)->assertionStarting( assertionInfo );
  7901. }
  7902. // The return value indicates if the messages buffer should be cleared:
  7903. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  7904. bool clearBuffer = false;
  7905. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7906. it != itEnd;
  7907. ++it )
  7908. clearBuffer |= (*it)->assertionEnded( assertionStats );
  7909. return clearBuffer;
  7910. }
  7911. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  7912. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7913. it != itEnd;
  7914. ++it )
  7915. (*it)->sectionEnded( sectionStats );
  7916. }
  7917. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  7918. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7919. it != itEnd;
  7920. ++it )
  7921. (*it)->testCaseEnded( testCaseStats );
  7922. }
  7923. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  7924. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7925. it != itEnd;
  7926. ++it )
  7927. (*it)->testGroupEnded( testGroupStats );
  7928. }
  7929. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  7930. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7931. it != itEnd;
  7932. ++it )
  7933. (*it)->testRunEnded( testRunStats );
  7934. }
  7935. virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  7936. for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
  7937. it != itEnd;
  7938. ++it )
  7939. (*it)->skipTest( testInfo );
  7940. }
  7941. virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
  7942. return this;
  7943. }
  7944. };
  7945. Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
  7946. Ptr<IStreamingReporter> resultingReporter;
  7947. if( existingReporter ) {
  7948. MultipleReporters* multi = existingReporter->tryAsMulti();
  7949. if( !multi ) {
  7950. multi = new MultipleReporters;
  7951. resultingReporter = Ptr<IStreamingReporter>( multi );
  7952. if( existingReporter )
  7953. multi->add( existingReporter );
  7954. }
  7955. else
  7956. resultingReporter = existingReporter;
  7957. multi->add( additionalReporter );
  7958. }
  7959. else
  7960. resultingReporter = additionalReporter;
  7961. return resultingReporter;
  7962. }
  7963. } // end namespace Catch
  7964. // #included from: ../reporters/catch_reporter_xml.hpp
  7965. #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
  7966. // #included from: catch_reporter_bases.hpp
  7967. #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
  7968. #include <cstring>
  7969. #include <cfloat>
  7970. #include <cstdio>
  7971. #include <assert.h>
  7972. namespace Catch {
  7973. namespace {
  7974. // Because formatting using c++ streams is stateful, drop down to C is required
  7975. // Alternatively we could use stringstream, but its performance is... not good.
  7976. std::string getFormattedDuration( double duration ) {
  7977. // Max exponent + 1 is required to represent the whole part
  7978. // + 1 for decimal point
  7979. // + 3 for the 3 decimal places
  7980. // + 1 for null terminator
  7981. const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
  7982. char buffer[maxDoubleSize];
  7983. // Save previous errno, to prevent sprintf from overwriting it
  7984. ErrnoGuard guard;
  7985. #ifdef _MSC_VER
  7986. sprintf_s(buffer, "%.3f", duration);
  7987. #else
  7988. sprintf(buffer, "%.3f", duration);
  7989. #endif
  7990. return std::string(buffer);
  7991. }
  7992. }
  7993. struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
  7994. StreamingReporterBase( ReporterConfig const& _config )
  7995. : m_config( _config.fullConfig() ),
  7996. stream( _config.stream() )
  7997. {
  7998. m_reporterPrefs.shouldRedirectStdOut = false;
  7999. }
  8000. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8001. return m_reporterPrefs;
  8002. }
  8003. virtual ~StreamingReporterBase() CATCH_OVERRIDE;
  8004. virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
  8005. virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
  8006. currentTestRunInfo = _testRunInfo;
  8007. }
  8008. virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
  8009. currentGroupInfo = _groupInfo;
  8010. }
  8011. virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
  8012. currentTestCaseInfo = _testInfo;
  8013. }
  8014. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8015. m_sectionStack.push_back( _sectionInfo );
  8016. }
  8017. virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
  8018. m_sectionStack.pop_back();
  8019. }
  8020. virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
  8021. currentTestCaseInfo.reset();
  8022. }
  8023. virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
  8024. currentGroupInfo.reset();
  8025. }
  8026. virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
  8027. currentTestCaseInfo.reset();
  8028. currentGroupInfo.reset();
  8029. currentTestRunInfo.reset();
  8030. }
  8031. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
  8032. // Don't do anything with this by default.
  8033. // It can optionally be overridden in the derived class.
  8034. }
  8035. Ptr<IConfig const> m_config;
  8036. std::ostream& stream;
  8037. LazyStat<TestRunInfo> currentTestRunInfo;
  8038. LazyStat<GroupInfo> currentGroupInfo;
  8039. LazyStat<TestCaseInfo> currentTestCaseInfo;
  8040. std::vector<SectionInfo> m_sectionStack;
  8041. ReporterPreferences m_reporterPrefs;
  8042. };
  8043. struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
  8044. template<typename T, typename ChildNodeT>
  8045. struct Node : SharedImpl<> {
  8046. explicit Node( T const& _value ) : value( _value ) {}
  8047. virtual ~Node() {}
  8048. typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
  8049. T value;
  8050. ChildNodes children;
  8051. };
  8052. struct SectionNode : SharedImpl<> {
  8053. explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
  8054. virtual ~SectionNode();
  8055. bool operator == ( SectionNode const& other ) const {
  8056. return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
  8057. }
  8058. bool operator == ( Ptr<SectionNode> const& other ) const {
  8059. return operator==( *other );
  8060. }
  8061. SectionStats stats;
  8062. typedef std::vector<Ptr<SectionNode> > ChildSections;
  8063. typedef std::vector<AssertionStats> Assertions;
  8064. ChildSections childSections;
  8065. Assertions assertions;
  8066. std::string stdOut;
  8067. std::string stdErr;
  8068. };
  8069. struct BySectionInfo {
  8070. BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
  8071. BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
  8072. bool operator() ( Ptr<SectionNode> const& node ) const {
  8073. return ((node->stats.sectionInfo.name == m_other.name) &&
  8074. (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
  8075. }
  8076. private:
  8077. void operator=( BySectionInfo const& );
  8078. SectionInfo const& m_other;
  8079. };
  8080. typedef Node<TestCaseStats, SectionNode> TestCaseNode;
  8081. typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
  8082. typedef Node<TestRunStats, TestGroupNode> TestRunNode;
  8083. CumulativeReporterBase( ReporterConfig const& _config )
  8084. : m_config( _config.fullConfig() ),
  8085. stream( _config.stream() )
  8086. {
  8087. m_reporterPrefs.shouldRedirectStdOut = false;
  8088. }
  8089. ~CumulativeReporterBase();
  8090. virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
  8091. return m_reporterPrefs;
  8092. }
  8093. virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
  8094. virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
  8095. virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8096. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8097. SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
  8098. Ptr<SectionNode> node;
  8099. if( m_sectionStack.empty() ) {
  8100. if( !m_rootSection )
  8101. m_rootSection = new SectionNode( incompleteStats );
  8102. node = m_rootSection;
  8103. }
  8104. else {
  8105. SectionNode& parentNode = *m_sectionStack.back();
  8106. SectionNode::ChildSections::const_iterator it =
  8107. std::find_if( parentNode.childSections.begin(),
  8108. parentNode.childSections.end(),
  8109. BySectionInfo( sectionInfo ) );
  8110. if( it == parentNode.childSections.end() ) {
  8111. node = new SectionNode( incompleteStats );
  8112. parentNode.childSections.push_back( node );
  8113. }
  8114. else
  8115. node = *it;
  8116. }
  8117. m_sectionStack.push_back( node );
  8118. m_deepestSection = node;
  8119. }
  8120. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8121. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8122. assert( !m_sectionStack.empty() );
  8123. SectionNode& sectionNode = *m_sectionStack.back();
  8124. sectionNode.assertions.push_back( assertionStats );
  8125. // AssertionResult holds a pointer to a temporary DecomposedExpression,
  8126. // which getExpandedExpression() calls to build the expression string.
  8127. // Our section stack copy of the assertionResult will likely outlive the
  8128. // temporary, so it must be expanded or discarded now to avoid calling
  8129. // a destroyed object later.
  8130. prepareExpandedExpression( sectionNode.assertions.back().assertionResult );
  8131. return true;
  8132. }
  8133. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8134. assert( !m_sectionStack.empty() );
  8135. SectionNode& node = *m_sectionStack.back();
  8136. node.stats = sectionStats;
  8137. m_sectionStack.pop_back();
  8138. }
  8139. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8140. Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
  8141. assert( m_sectionStack.size() == 0 );
  8142. node->children.push_back( m_rootSection );
  8143. m_testCases.push_back( node );
  8144. m_rootSection.reset();
  8145. assert( m_deepestSection );
  8146. m_deepestSection->stdOut = testCaseStats.stdOut;
  8147. m_deepestSection->stdErr = testCaseStats.stdErr;
  8148. }
  8149. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8150. Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
  8151. node->children.swap( m_testCases );
  8152. m_testGroups.push_back( node );
  8153. }
  8154. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8155. Ptr<TestRunNode> node = new TestRunNode( testRunStats );
  8156. node->children.swap( m_testGroups );
  8157. m_testRuns.push_back( node );
  8158. testRunEndedCumulative();
  8159. }
  8160. virtual void testRunEndedCumulative() = 0;
  8161. virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
  8162. virtual void prepareExpandedExpression( AssertionResult& result ) const {
  8163. if( result.isOk() )
  8164. result.discardDecomposedExpression();
  8165. else
  8166. result.expandDecomposedExpression();
  8167. }
  8168. Ptr<IConfig const> m_config;
  8169. std::ostream& stream;
  8170. std::vector<AssertionStats> m_assertions;
  8171. std::vector<std::vector<Ptr<SectionNode> > > m_sections;
  8172. std::vector<Ptr<TestCaseNode> > m_testCases;
  8173. std::vector<Ptr<TestGroupNode> > m_testGroups;
  8174. std::vector<Ptr<TestRunNode> > m_testRuns;
  8175. Ptr<SectionNode> m_rootSection;
  8176. Ptr<SectionNode> m_deepestSection;
  8177. std::vector<Ptr<SectionNode> > m_sectionStack;
  8178. ReporterPreferences m_reporterPrefs;
  8179. };
  8180. template<char C>
  8181. char const* getLineOfChars() {
  8182. static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
  8183. if( !*line ) {
  8184. std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
  8185. line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
  8186. }
  8187. return line;
  8188. }
  8189. struct TestEventListenerBase : StreamingReporterBase {
  8190. TestEventListenerBase( ReporterConfig const& _config )
  8191. : StreamingReporterBase( _config )
  8192. {}
  8193. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
  8194. virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
  8195. return false;
  8196. }
  8197. };
  8198. } // end namespace Catch
  8199. // #included from: ../internal/catch_reporter_registrars.hpp
  8200. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  8201. namespace Catch {
  8202. template<typename T>
  8203. class LegacyReporterRegistrar {
  8204. class ReporterFactory : public IReporterFactory {
  8205. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8206. return new LegacyReporterAdapter( new T( config ) );
  8207. }
  8208. virtual std::string getDescription() const {
  8209. return T::getDescription();
  8210. }
  8211. };
  8212. public:
  8213. LegacyReporterRegistrar( std::string const& name ) {
  8214. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8215. }
  8216. };
  8217. template<typename T>
  8218. class ReporterRegistrar {
  8219. class ReporterFactory : public SharedImpl<IReporterFactory> {
  8220. // *** Please Note ***:
  8221. // - If you end up here looking at a compiler error because it's trying to register
  8222. // your custom reporter class be aware that the native reporter interface has changed
  8223. // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
  8224. // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
  8225. // However please consider updating to the new interface as the old one is now
  8226. // deprecated and will probably be removed quite soon!
  8227. // Please contact me via github if you have any questions at all about this.
  8228. // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
  8229. // no idea who is actually using custom reporters at all (possibly no-one!).
  8230. // The new interface is designed to minimise exposure to interface changes in the future.
  8231. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8232. return new T( config );
  8233. }
  8234. virtual std::string getDescription() const {
  8235. return T::getDescription();
  8236. }
  8237. };
  8238. public:
  8239. ReporterRegistrar( std::string const& name ) {
  8240. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  8241. }
  8242. };
  8243. template<typename T>
  8244. class ListenerRegistrar {
  8245. class ListenerFactory : public SharedImpl<IReporterFactory> {
  8246. virtual IStreamingReporter* create( ReporterConfig const& config ) const {
  8247. return new T( config );
  8248. }
  8249. virtual std::string getDescription() const {
  8250. return std::string();
  8251. }
  8252. };
  8253. public:
  8254. ListenerRegistrar() {
  8255. getMutableRegistryHub().registerListener( new ListenerFactory() );
  8256. }
  8257. };
  8258. }
  8259. #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
  8260. namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8261. #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
  8262. namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
  8263. // Deprecated - use the form without INTERNAL_
  8264. #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
  8265. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8266. #define CATCH_REGISTER_LISTENER( listenerType ) \
  8267. namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
  8268. // #included from: ../internal/catch_xmlwriter.hpp
  8269. #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
  8270. #include <sstream>
  8271. #include <string>
  8272. #include <vector>
  8273. #include <iomanip>
  8274. namespace Catch {
  8275. class XmlEncode {
  8276. public:
  8277. enum ForWhat { ForTextNodes, ForAttributes };
  8278. XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
  8279. : m_str( str ),
  8280. m_forWhat( forWhat )
  8281. {}
  8282. void encodeTo( std::ostream& os ) const {
  8283. // Apostrophe escaping not necessary if we always use " to write attributes
  8284. // (see: http://www.w3.org/TR/xml/#syntax)
  8285. for( std::size_t i = 0; i < m_str.size(); ++ i ) {
  8286. char c = m_str[i];
  8287. switch( c ) {
  8288. case '<': os << "&lt;"; break;
  8289. case '&': os << "&amp;"; break;
  8290. case '>':
  8291. // See: http://www.w3.org/TR/xml/#syntax
  8292. if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
  8293. os << "&gt;";
  8294. else
  8295. os << c;
  8296. break;
  8297. case '\"':
  8298. if( m_forWhat == ForAttributes )
  8299. os << "&quot;";
  8300. else
  8301. os << c;
  8302. break;
  8303. default:
  8304. // Escape control chars - based on contribution by @espenalb in PR #465 and
  8305. // by @mrpi PR #588
  8306. if ( ( c >= 0 && c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) {
  8307. // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
  8308. os << "\\x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2)
  8309. << static_cast<int>( c );
  8310. }
  8311. else
  8312. os << c;
  8313. }
  8314. }
  8315. }
  8316. friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
  8317. xmlEncode.encodeTo( os );
  8318. return os;
  8319. }
  8320. private:
  8321. std::string m_str;
  8322. ForWhat m_forWhat;
  8323. };
  8324. class XmlWriter {
  8325. public:
  8326. class ScopedElement {
  8327. public:
  8328. ScopedElement( XmlWriter* writer )
  8329. : m_writer( writer )
  8330. {}
  8331. ScopedElement( ScopedElement const& other )
  8332. : m_writer( other.m_writer ){
  8333. other.m_writer = CATCH_NULL;
  8334. }
  8335. ~ScopedElement() {
  8336. if( m_writer )
  8337. m_writer->endElement();
  8338. }
  8339. ScopedElement& writeText( std::string const& text, bool indent = true ) {
  8340. m_writer->writeText( text, indent );
  8341. return *this;
  8342. }
  8343. template<typename T>
  8344. ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
  8345. m_writer->writeAttribute( name, attribute );
  8346. return *this;
  8347. }
  8348. private:
  8349. mutable XmlWriter* m_writer;
  8350. };
  8351. XmlWriter()
  8352. : m_tagIsOpen( false ),
  8353. m_needsNewline( false ),
  8354. m_os( Catch::cout() )
  8355. {
  8356. writeDeclaration();
  8357. }
  8358. XmlWriter( std::ostream& os )
  8359. : m_tagIsOpen( false ),
  8360. m_needsNewline( false ),
  8361. m_os( os )
  8362. {
  8363. writeDeclaration();
  8364. }
  8365. ~XmlWriter() {
  8366. while( !m_tags.empty() )
  8367. endElement();
  8368. }
  8369. XmlWriter& startElement( std::string const& name ) {
  8370. ensureTagClosed();
  8371. newlineIfNecessary();
  8372. m_os << m_indent << '<' << name;
  8373. m_tags.push_back( name );
  8374. m_indent += " ";
  8375. m_tagIsOpen = true;
  8376. return *this;
  8377. }
  8378. ScopedElement scopedElement( std::string const& name ) {
  8379. ScopedElement scoped( this );
  8380. startElement( name );
  8381. return scoped;
  8382. }
  8383. XmlWriter& endElement() {
  8384. newlineIfNecessary();
  8385. m_indent = m_indent.substr( 0, m_indent.size()-2 );
  8386. if( m_tagIsOpen ) {
  8387. m_os << "/>";
  8388. m_tagIsOpen = false;
  8389. }
  8390. else {
  8391. m_os << m_indent << "</" << m_tags.back() << ">";
  8392. }
  8393. m_os << std::endl;
  8394. m_tags.pop_back();
  8395. return *this;
  8396. }
  8397. XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
  8398. if( !name.empty() && !attribute.empty() )
  8399. m_os << ' ' << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << '"';
  8400. return *this;
  8401. }
  8402. XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
  8403. m_os << ' ' << name << "=\"" << ( attribute ? "true" : "false" ) << '"';
  8404. return *this;
  8405. }
  8406. template<typename T>
  8407. XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
  8408. std::ostringstream oss;
  8409. oss << attribute;
  8410. return writeAttribute( name, oss.str() );
  8411. }
  8412. XmlWriter& writeText( std::string const& text, bool indent = true ) {
  8413. if( !text.empty() ){
  8414. bool tagWasOpen = m_tagIsOpen;
  8415. ensureTagClosed();
  8416. if( tagWasOpen && indent )
  8417. m_os << m_indent;
  8418. m_os << XmlEncode( text );
  8419. m_needsNewline = true;
  8420. }
  8421. return *this;
  8422. }
  8423. XmlWriter& writeComment( std::string const& text ) {
  8424. ensureTagClosed();
  8425. m_os << m_indent << "<!--" << text << "-->";
  8426. m_needsNewline = true;
  8427. return *this;
  8428. }
  8429. void writeStylesheetRef( std::string const& url ) {
  8430. m_os << "<?xml-stylesheet type=\"text/xsl\" href=\"" << url << "\"?>\n";
  8431. }
  8432. XmlWriter& writeBlankLine() {
  8433. ensureTagClosed();
  8434. m_os << '\n';
  8435. return *this;
  8436. }
  8437. void ensureTagClosed() {
  8438. if( m_tagIsOpen ) {
  8439. m_os << ">" << std::endl;
  8440. m_tagIsOpen = false;
  8441. }
  8442. }
  8443. private:
  8444. XmlWriter( XmlWriter const& );
  8445. void operator=( XmlWriter const& );
  8446. void writeDeclaration() {
  8447. m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  8448. }
  8449. void newlineIfNecessary() {
  8450. if( m_needsNewline ) {
  8451. m_os << std::endl;
  8452. m_needsNewline = false;
  8453. }
  8454. }
  8455. bool m_tagIsOpen;
  8456. bool m_needsNewline;
  8457. std::vector<std::string> m_tags;
  8458. std::string m_indent;
  8459. std::ostream& m_os;
  8460. };
  8461. }
  8462. namespace Catch {
  8463. class XmlReporter : public StreamingReporterBase {
  8464. public:
  8465. XmlReporter( ReporterConfig const& _config )
  8466. : StreamingReporterBase( _config ),
  8467. m_xml(_config.stream()),
  8468. m_sectionDepth( 0 )
  8469. {
  8470. m_reporterPrefs.shouldRedirectStdOut = true;
  8471. }
  8472. virtual ~XmlReporter() CATCH_OVERRIDE;
  8473. static std::string getDescription() {
  8474. return "Reports test results as an XML document";
  8475. }
  8476. virtual std::string getStylesheetRef() const {
  8477. return std::string();
  8478. }
  8479. void writeSourceInfo( SourceLineInfo const& sourceInfo ) {
  8480. m_xml
  8481. .writeAttribute( "filename", sourceInfo.file )
  8482. .writeAttribute( "line", sourceInfo.line );
  8483. }
  8484. public: // StreamingReporterBase
  8485. virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
  8486. StreamingReporterBase::noMatchingTestCases( s );
  8487. }
  8488. virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
  8489. StreamingReporterBase::testRunStarting( testInfo );
  8490. std::string stylesheetRef = getStylesheetRef();
  8491. if( !stylesheetRef.empty() )
  8492. m_xml.writeStylesheetRef( stylesheetRef );
  8493. m_xml.startElement( "Catch" );
  8494. if( !m_config->name().empty() )
  8495. m_xml.writeAttribute( "name", m_config->name() );
  8496. }
  8497. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8498. StreamingReporterBase::testGroupStarting( groupInfo );
  8499. m_xml.startElement( "Group" )
  8500. .writeAttribute( "name", groupInfo.name );
  8501. }
  8502. virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
  8503. StreamingReporterBase::testCaseStarting(testInfo);
  8504. m_xml.startElement( "TestCase" )
  8505. .writeAttribute( "name", trim( testInfo.name ) )
  8506. .writeAttribute( "description", testInfo.description )
  8507. .writeAttribute( "tags", testInfo.tagsAsString );
  8508. writeSourceInfo( testInfo.lineInfo );
  8509. if ( m_config->showDurations() == ShowDurations::Always )
  8510. m_testCaseTimer.start();
  8511. m_xml.ensureTagClosed();
  8512. }
  8513. virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
  8514. StreamingReporterBase::sectionStarting( sectionInfo );
  8515. if( m_sectionDepth++ > 0 ) {
  8516. m_xml.startElement( "Section" )
  8517. .writeAttribute( "name", trim( sectionInfo.name ) )
  8518. .writeAttribute( "description", sectionInfo.description );
  8519. writeSourceInfo( sectionInfo.lineInfo );
  8520. m_xml.ensureTagClosed();
  8521. }
  8522. }
  8523. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
  8524. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8525. AssertionResult const& result = assertionStats.assertionResult;
  8526. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8527. if( includeResults || result.getResultType() == ResultWas::Warning ) {
  8528. // Print any info messages in <Info> tags.
  8529. for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
  8530. it != itEnd;
  8531. ++it ) {
  8532. if( it->type == ResultWas::Info && includeResults ) {
  8533. m_xml.scopedElement( "Info" )
  8534. .writeText( it->message );
  8535. } else if ( it->type == ResultWas::Warning ) {
  8536. m_xml.scopedElement( "Warning" )
  8537. .writeText( it->message );
  8538. }
  8539. }
  8540. }
  8541. // Drop out if result was successful but we're not printing them.
  8542. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8543. return true;
  8544. // Print the expression if there is one.
  8545. if( result.hasExpression() ) {
  8546. m_xml.startElement( "Expression" )
  8547. .writeAttribute( "success", result.succeeded() )
  8548. .writeAttribute( "type", result.getTestMacroName() );
  8549. writeSourceInfo( result.getSourceInfo() );
  8550. m_xml.scopedElement( "Original" )
  8551. .writeText( result.getExpression() );
  8552. m_xml.scopedElement( "Expanded" )
  8553. .writeText( result.getExpandedExpression() );
  8554. }
  8555. // And... Print a result applicable to each result type.
  8556. switch( result.getResultType() ) {
  8557. case ResultWas::ThrewException:
  8558. m_xml.startElement( "Exception" );
  8559. writeSourceInfo( result.getSourceInfo() );
  8560. m_xml.writeText( result.getMessage() );
  8561. m_xml.endElement();
  8562. break;
  8563. case ResultWas::FatalErrorCondition:
  8564. m_xml.startElement( "FatalErrorCondition" );
  8565. writeSourceInfo( result.getSourceInfo() );
  8566. m_xml.writeText( result.getMessage() );
  8567. m_xml.endElement();
  8568. break;
  8569. case ResultWas::Info:
  8570. m_xml.scopedElement( "Info" )
  8571. .writeText( result.getMessage() );
  8572. break;
  8573. case ResultWas::Warning:
  8574. // Warning will already have been written
  8575. break;
  8576. case ResultWas::ExplicitFailure:
  8577. m_xml.startElement( "Failure" );
  8578. writeSourceInfo( result.getSourceInfo() );
  8579. m_xml.writeText( result.getMessage() );
  8580. m_xml.endElement();
  8581. break;
  8582. default:
  8583. break;
  8584. }
  8585. if( result.hasExpression() )
  8586. m_xml.endElement();
  8587. return true;
  8588. }
  8589. virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
  8590. StreamingReporterBase::sectionEnded( sectionStats );
  8591. if( --m_sectionDepth > 0 ) {
  8592. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
  8593. e.writeAttribute( "successes", sectionStats.assertions.passed );
  8594. e.writeAttribute( "failures", sectionStats.assertions.failed );
  8595. e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
  8596. if ( m_config->showDurations() == ShowDurations::Always )
  8597. e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
  8598. m_xml.endElement();
  8599. }
  8600. }
  8601. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8602. StreamingReporterBase::testCaseEnded( testCaseStats );
  8603. XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
  8604. e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
  8605. if ( m_config->showDurations() == ShowDurations::Always )
  8606. e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
  8607. if( !testCaseStats.stdOut.empty() )
  8608. m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false );
  8609. if( !testCaseStats.stdErr.empty() )
  8610. m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false );
  8611. m_xml.endElement();
  8612. }
  8613. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8614. StreamingReporterBase::testGroupEnded( testGroupStats );
  8615. // TODO: Check testGroupStats.aborting and act accordingly.
  8616. m_xml.scopedElement( "OverallResults" )
  8617. .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
  8618. .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
  8619. .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
  8620. m_xml.endElement();
  8621. }
  8622. virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
  8623. StreamingReporterBase::testRunEnded( testRunStats );
  8624. m_xml.scopedElement( "OverallResults" )
  8625. .writeAttribute( "successes", testRunStats.totals.assertions.passed )
  8626. .writeAttribute( "failures", testRunStats.totals.assertions.failed )
  8627. .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
  8628. m_xml.endElement();
  8629. }
  8630. private:
  8631. Timer m_testCaseTimer;
  8632. XmlWriter m_xml;
  8633. int m_sectionDepth;
  8634. };
  8635. INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
  8636. } // end namespace Catch
  8637. // #included from: ../reporters/catch_reporter_junit.hpp
  8638. #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
  8639. #include <assert.h>
  8640. namespace Catch {
  8641. namespace {
  8642. std::string getCurrentTimestamp() {
  8643. // Beware, this is not reentrant because of backward compatibility issues
  8644. // Also, UTC only, again because of backward compatibility (%z is C++11)
  8645. time_t rawtime;
  8646. std::time(&rawtime);
  8647. const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z");
  8648. #ifdef _MSC_VER
  8649. std::tm timeInfo = {};
  8650. gmtime_s(&timeInfo, &rawtime);
  8651. #else
  8652. std::tm* timeInfo;
  8653. timeInfo = std::gmtime(&rawtime);
  8654. #endif
  8655. char timeStamp[timeStampSize];
  8656. const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
  8657. #ifdef _MSC_VER
  8658. std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
  8659. #else
  8660. std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
  8661. #endif
  8662. return std::string(timeStamp);
  8663. }
  8664. }
  8665. class JunitReporter : public CumulativeReporterBase {
  8666. public:
  8667. JunitReporter( ReporterConfig const& _config )
  8668. : CumulativeReporterBase( _config ),
  8669. xml( _config.stream() ),
  8670. unexpectedExceptions( 0 ),
  8671. m_okToFail( false )
  8672. {
  8673. m_reporterPrefs.shouldRedirectStdOut = true;
  8674. }
  8675. virtual ~JunitReporter() CATCH_OVERRIDE;
  8676. static std::string getDescription() {
  8677. return "Reports test results in an XML format that looks like Ant's junitreport target";
  8678. }
  8679. virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
  8680. virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
  8681. CumulativeReporterBase::testRunStarting( runInfo );
  8682. xml.startElement( "testsuites" );
  8683. }
  8684. virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
  8685. suiteTimer.start();
  8686. stdOutForSuite.str("");
  8687. stdErrForSuite.str("");
  8688. unexpectedExceptions = 0;
  8689. CumulativeReporterBase::testGroupStarting( groupInfo );
  8690. }
  8691. virtual void testCaseStarting( TestCaseInfo const& testCaseInfo ) CATCH_OVERRIDE {
  8692. m_okToFail = testCaseInfo.okToFail();
  8693. }
  8694. virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
  8695. if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException && !m_okToFail )
  8696. unexpectedExceptions++;
  8697. return CumulativeReporterBase::assertionEnded( assertionStats );
  8698. }
  8699. virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
  8700. stdOutForSuite << testCaseStats.stdOut;
  8701. stdErrForSuite << testCaseStats.stdErr;
  8702. CumulativeReporterBase::testCaseEnded( testCaseStats );
  8703. }
  8704. virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
  8705. double suiteTime = suiteTimer.getElapsedSeconds();
  8706. CumulativeReporterBase::testGroupEnded( testGroupStats );
  8707. writeGroup( *m_testGroups.back(), suiteTime );
  8708. }
  8709. virtual void testRunEndedCumulative() CATCH_OVERRIDE {
  8710. xml.endElement();
  8711. }
  8712. void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
  8713. XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
  8714. TestGroupStats const& stats = groupNode.value;
  8715. xml.writeAttribute( "name", stats.groupInfo.name );
  8716. xml.writeAttribute( "errors", unexpectedExceptions );
  8717. xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
  8718. xml.writeAttribute( "tests", stats.totals.assertions.total() );
  8719. xml.writeAttribute( "hostname", "tbd" ); // !TBD
  8720. if( m_config->showDurations() == ShowDurations::Never )
  8721. xml.writeAttribute( "time", "" );
  8722. else
  8723. xml.writeAttribute( "time", suiteTime );
  8724. xml.writeAttribute( "timestamp", getCurrentTimestamp() );
  8725. // Write test cases
  8726. for( TestGroupNode::ChildNodes::const_iterator
  8727. it = groupNode.children.begin(), itEnd = groupNode.children.end();
  8728. it != itEnd;
  8729. ++it )
  8730. writeTestCase( **it );
  8731. xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
  8732. xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
  8733. }
  8734. void writeTestCase( TestCaseNode const& testCaseNode ) {
  8735. TestCaseStats const& stats = testCaseNode.value;
  8736. // All test cases have exactly one section - which represents the
  8737. // test case itself. That section may have 0-n nested sections
  8738. assert( testCaseNode.children.size() == 1 );
  8739. SectionNode const& rootSection = *testCaseNode.children.front();
  8740. std::string className = stats.testInfo.className;
  8741. if( className.empty() ) {
  8742. if( rootSection.childSections.empty() )
  8743. className = "global";
  8744. }
  8745. writeSection( className, "", rootSection );
  8746. }
  8747. void writeSection( std::string const& className,
  8748. std::string const& rootName,
  8749. SectionNode const& sectionNode ) {
  8750. std::string name = trim( sectionNode.stats.sectionInfo.name );
  8751. if( !rootName.empty() )
  8752. name = rootName + '/' + name;
  8753. if( !sectionNode.assertions.empty() ||
  8754. !sectionNode.stdOut.empty() ||
  8755. !sectionNode.stdErr.empty() ) {
  8756. XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
  8757. if( className.empty() ) {
  8758. xml.writeAttribute( "classname", name );
  8759. xml.writeAttribute( "name", "root" );
  8760. }
  8761. else {
  8762. xml.writeAttribute( "classname", className );
  8763. xml.writeAttribute( "name", name );
  8764. }
  8765. xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
  8766. writeAssertions( sectionNode );
  8767. if( !sectionNode.stdOut.empty() )
  8768. xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
  8769. if( !sectionNode.stdErr.empty() )
  8770. xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
  8771. }
  8772. for( SectionNode::ChildSections::const_iterator
  8773. it = sectionNode.childSections.begin(),
  8774. itEnd = sectionNode.childSections.end();
  8775. it != itEnd;
  8776. ++it )
  8777. if( className.empty() )
  8778. writeSection( name, "", **it );
  8779. else
  8780. writeSection( className, name, **it );
  8781. }
  8782. void writeAssertions( SectionNode const& sectionNode ) {
  8783. for( SectionNode::Assertions::const_iterator
  8784. it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
  8785. it != itEnd;
  8786. ++it )
  8787. writeAssertion( *it );
  8788. }
  8789. void writeAssertion( AssertionStats const& stats ) {
  8790. AssertionResult const& result = stats.assertionResult;
  8791. if( !result.isOk() ) {
  8792. std::string elementName;
  8793. switch( result.getResultType() ) {
  8794. case ResultWas::ThrewException:
  8795. case ResultWas::FatalErrorCondition:
  8796. elementName = "error";
  8797. break;
  8798. case ResultWas::ExplicitFailure:
  8799. elementName = "failure";
  8800. break;
  8801. case ResultWas::ExpressionFailed:
  8802. elementName = "failure";
  8803. break;
  8804. case ResultWas::DidntThrowException:
  8805. elementName = "failure";
  8806. break;
  8807. // We should never see these here:
  8808. case ResultWas::Info:
  8809. case ResultWas::Warning:
  8810. case ResultWas::Ok:
  8811. case ResultWas::Unknown:
  8812. case ResultWas::FailureBit:
  8813. case ResultWas::Exception:
  8814. elementName = "internalError";
  8815. break;
  8816. }
  8817. XmlWriter::ScopedElement e = xml.scopedElement( elementName );
  8818. xml.writeAttribute( "message", result.getExpandedExpression() );
  8819. xml.writeAttribute( "type", result.getTestMacroName() );
  8820. std::ostringstream oss;
  8821. if( !result.getMessage().empty() )
  8822. oss << result.getMessage() << '\n';
  8823. for( std::vector<MessageInfo>::const_iterator
  8824. it = stats.infoMessages.begin(),
  8825. itEnd = stats.infoMessages.end();
  8826. it != itEnd;
  8827. ++it )
  8828. if( it->type == ResultWas::Info )
  8829. oss << it->message << '\n';
  8830. oss << "at " << result.getSourceInfo();
  8831. xml.writeText( oss.str(), false );
  8832. }
  8833. }
  8834. XmlWriter xml;
  8835. Timer suiteTimer;
  8836. std::ostringstream stdOutForSuite;
  8837. std::ostringstream stdErrForSuite;
  8838. unsigned int unexpectedExceptions;
  8839. bool m_okToFail;
  8840. };
  8841. INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
  8842. } // end namespace Catch
  8843. // #included from: ../reporters/catch_reporter_console.hpp
  8844. #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
  8845. #include <cassert>
  8846. #include <cfloat>
  8847. #include <cstdio>
  8848. namespace Catch {
  8849. struct ConsoleReporter : StreamingReporterBase {
  8850. ConsoleReporter( ReporterConfig const& _config )
  8851. : StreamingReporterBase( _config ),
  8852. m_headerPrinted( false )
  8853. {}
  8854. virtual ~ConsoleReporter() CATCH_OVERRIDE;
  8855. static std::string getDescription() {
  8856. return "Reports test results as plain lines of text";
  8857. }
  8858. virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
  8859. stream << "No test cases matched '" << spec << '\'' << std::endl;
  8860. }
  8861. virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
  8862. }
  8863. virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
  8864. AssertionResult const& result = _assertionStats.assertionResult;
  8865. bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
  8866. // Drop out if result was successful but we're not printing them.
  8867. if( !includeResults && result.getResultType() != ResultWas::Warning )
  8868. return false;
  8869. lazyPrint();
  8870. AssertionPrinter printer( stream, _assertionStats, includeResults );
  8871. printer.print();
  8872. stream << std::endl;
  8873. return true;
  8874. }
  8875. virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
  8876. m_headerPrinted = false;
  8877. StreamingReporterBase::sectionStarting( _sectionInfo );
  8878. }
  8879. virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
  8880. if( _sectionStats.missingAssertions ) {
  8881. lazyPrint();
  8882. Colour colour( Colour::ResultError );
  8883. if( m_sectionStack.size() > 1 )
  8884. stream << "\nNo assertions in section";
  8885. else
  8886. stream << "\nNo assertions in test case";
  8887. stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
  8888. }
  8889. if( m_config->showDurations() == ShowDurations::Always ) {
  8890. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  8891. }
  8892. if( m_headerPrinted ) {
  8893. m_headerPrinted = false;
  8894. }
  8895. StreamingReporterBase::sectionEnded( _sectionStats );
  8896. }
  8897. virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
  8898. StreamingReporterBase::testCaseEnded( _testCaseStats );
  8899. m_headerPrinted = false;
  8900. }
  8901. virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
  8902. if( currentGroupInfo.used ) {
  8903. printSummaryDivider();
  8904. stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
  8905. printTotals( _testGroupStats.totals );
  8906. stream << '\n' << std::endl;
  8907. }
  8908. StreamingReporterBase::testGroupEnded( _testGroupStats );
  8909. }
  8910. virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
  8911. printTotalsDivider( _testRunStats.totals );
  8912. printTotals( _testRunStats.totals );
  8913. stream << std::endl;
  8914. StreamingReporterBase::testRunEnded( _testRunStats );
  8915. }
  8916. private:
  8917. class AssertionPrinter {
  8918. void operator= ( AssertionPrinter const& );
  8919. public:
  8920. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  8921. : stream( _stream ),
  8922. stats( _stats ),
  8923. result( _stats.assertionResult ),
  8924. colour( Colour::None ),
  8925. message( result.getMessage() ),
  8926. messages( _stats.infoMessages ),
  8927. printInfoMessages( _printInfoMessages )
  8928. {
  8929. switch( result.getResultType() ) {
  8930. case ResultWas::Ok:
  8931. colour = Colour::Success;
  8932. passOrFail = "PASSED";
  8933. //if( result.hasMessage() )
  8934. if( _stats.infoMessages.size() == 1 )
  8935. messageLabel = "with message";
  8936. if( _stats.infoMessages.size() > 1 )
  8937. messageLabel = "with messages";
  8938. break;
  8939. case ResultWas::ExpressionFailed:
  8940. if( result.isOk() ) {
  8941. colour = Colour::Success;
  8942. passOrFail = "FAILED - but was ok";
  8943. }
  8944. else {
  8945. colour = Colour::Error;
  8946. passOrFail = "FAILED";
  8947. }
  8948. if( _stats.infoMessages.size() == 1 )
  8949. messageLabel = "with message";
  8950. if( _stats.infoMessages.size() > 1 )
  8951. messageLabel = "with messages";
  8952. break;
  8953. case ResultWas::ThrewException:
  8954. colour = Colour::Error;
  8955. passOrFail = "FAILED";
  8956. messageLabel = "due to unexpected exception with ";
  8957. if (_stats.infoMessages.size() == 1)
  8958. messageLabel += "message";
  8959. if (_stats.infoMessages.size() > 1)
  8960. messageLabel += "messages";
  8961. break;
  8962. case ResultWas::FatalErrorCondition:
  8963. colour = Colour::Error;
  8964. passOrFail = "FAILED";
  8965. messageLabel = "due to a fatal error condition";
  8966. break;
  8967. case ResultWas::DidntThrowException:
  8968. colour = Colour::Error;
  8969. passOrFail = "FAILED";
  8970. messageLabel = "because no exception was thrown where one was expected";
  8971. break;
  8972. case ResultWas::Info:
  8973. messageLabel = "info";
  8974. break;
  8975. case ResultWas::Warning:
  8976. messageLabel = "warning";
  8977. break;
  8978. case ResultWas::ExplicitFailure:
  8979. passOrFail = "FAILED";
  8980. colour = Colour::Error;
  8981. if( _stats.infoMessages.size() == 1 )
  8982. messageLabel = "explicitly with message";
  8983. if( _stats.infoMessages.size() > 1 )
  8984. messageLabel = "explicitly with messages";
  8985. break;
  8986. // These cases are here to prevent compiler warnings
  8987. case ResultWas::Unknown:
  8988. case ResultWas::FailureBit:
  8989. case ResultWas::Exception:
  8990. passOrFail = "** internal error **";
  8991. colour = Colour::Error;
  8992. break;
  8993. }
  8994. }
  8995. void print() const {
  8996. printSourceInfo();
  8997. if( stats.totals.assertions.total() > 0 ) {
  8998. if( result.isOk() )
  8999. stream << '\n';
  9000. printResultType();
  9001. printOriginalExpression();
  9002. printReconstructedExpression();
  9003. }
  9004. else {
  9005. stream << '\n';
  9006. }
  9007. printMessage();
  9008. }
  9009. private:
  9010. void printResultType() const {
  9011. if( !passOrFail.empty() ) {
  9012. Colour colourGuard( colour );
  9013. stream << passOrFail << ":\n";
  9014. }
  9015. }
  9016. void printOriginalExpression() const {
  9017. if( result.hasExpression() ) {
  9018. Colour colourGuard( Colour::OriginalExpression );
  9019. stream << " ";
  9020. stream << result.getExpressionInMacro();
  9021. stream << '\n';
  9022. }
  9023. }
  9024. void printReconstructedExpression() const {
  9025. if( result.hasExpandedExpression() ) {
  9026. stream << "with expansion:\n";
  9027. Colour colourGuard( Colour::ReconstructedExpression );
  9028. stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << '\n';
  9029. }
  9030. }
  9031. void printMessage() const {
  9032. if( !messageLabel.empty() )
  9033. stream << messageLabel << ':' << '\n';
  9034. for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
  9035. it != itEnd;
  9036. ++it ) {
  9037. // If this assertion is a warning ignore any INFO messages
  9038. if( printInfoMessages || it->type != ResultWas::Info )
  9039. stream << Text( it->message, TextAttributes().setIndent(2) ) << '\n';
  9040. }
  9041. }
  9042. void printSourceInfo() const {
  9043. Colour colourGuard( Colour::FileName );
  9044. stream << result.getSourceInfo() << ": ";
  9045. }
  9046. std::ostream& stream;
  9047. AssertionStats const& stats;
  9048. AssertionResult const& result;
  9049. Colour::Code colour;
  9050. std::string passOrFail;
  9051. std::string messageLabel;
  9052. std::string message;
  9053. std::vector<MessageInfo> messages;
  9054. bool printInfoMessages;
  9055. };
  9056. void lazyPrint() {
  9057. if( !currentTestRunInfo.used )
  9058. lazyPrintRunInfo();
  9059. if( !currentGroupInfo.used )
  9060. lazyPrintGroupInfo();
  9061. if( !m_headerPrinted ) {
  9062. printTestCaseAndSectionHeader();
  9063. m_headerPrinted = true;
  9064. }
  9065. }
  9066. void lazyPrintRunInfo() {
  9067. stream << '\n' << getLineOfChars<'~'>() << '\n';
  9068. Colour colour( Colour::SecondaryText );
  9069. stream << currentTestRunInfo->name
  9070. << " is a Catch v" << libraryVersion() << " host application.\n"
  9071. << "Run with -? for options\n\n";
  9072. if( m_config->rngSeed() != 0 )
  9073. stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
  9074. currentTestRunInfo.used = true;
  9075. }
  9076. void lazyPrintGroupInfo() {
  9077. if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
  9078. printClosedHeader( "Group: " + currentGroupInfo->name );
  9079. currentGroupInfo.used = true;
  9080. }
  9081. }
  9082. void printTestCaseAndSectionHeader() {
  9083. assert( !m_sectionStack.empty() );
  9084. printOpenHeader( currentTestCaseInfo->name );
  9085. if( m_sectionStack.size() > 1 ) {
  9086. Colour colourGuard( Colour::Headers );
  9087. std::vector<SectionInfo>::const_iterator
  9088. it = m_sectionStack.begin()+1, // Skip first section (test case)
  9089. itEnd = m_sectionStack.end();
  9090. for( ; it != itEnd; ++it )
  9091. printHeaderString( it->name, 2 );
  9092. }
  9093. SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
  9094. if( !lineInfo.empty() ){
  9095. stream << getLineOfChars<'-'>() << '\n';
  9096. Colour colourGuard( Colour::FileName );
  9097. stream << lineInfo << '\n';
  9098. }
  9099. stream << getLineOfChars<'.'>() << '\n' << std::endl;
  9100. }
  9101. void printClosedHeader( std::string const& _name ) {
  9102. printOpenHeader( _name );
  9103. stream << getLineOfChars<'.'>() << '\n';
  9104. }
  9105. void printOpenHeader( std::string const& _name ) {
  9106. stream << getLineOfChars<'-'>() << '\n';
  9107. {
  9108. Colour colourGuard( Colour::Headers );
  9109. printHeaderString( _name );
  9110. }
  9111. }
  9112. // if string has a : in first line will set indent to follow it on
  9113. // subsequent lines
  9114. void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
  9115. std::size_t i = _string.find( ": " );
  9116. if( i != std::string::npos )
  9117. i+=2;
  9118. else
  9119. i = 0;
  9120. stream << Text( _string, TextAttributes()
  9121. .setIndent( indent+i)
  9122. .setInitialIndent( indent ) ) << '\n';
  9123. }
  9124. struct SummaryColumn {
  9125. SummaryColumn( std::string const& _label, Colour::Code _colour )
  9126. : label( _label ),
  9127. colour( _colour )
  9128. {}
  9129. SummaryColumn addRow( std::size_t count ) {
  9130. std::ostringstream oss;
  9131. oss << count;
  9132. std::string row = oss.str();
  9133. for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
  9134. while( it->size() < row.size() )
  9135. *it = ' ' + *it;
  9136. while( it->size() > row.size() )
  9137. row = ' ' + row;
  9138. }
  9139. rows.push_back( row );
  9140. return *this;
  9141. }
  9142. std::string label;
  9143. Colour::Code colour;
  9144. std::vector<std::string> rows;
  9145. };
  9146. void printTotals( Totals const& totals ) {
  9147. if( totals.testCases.total() == 0 ) {
  9148. stream << Colour( Colour::Warning ) << "No tests ran\n";
  9149. }
  9150. else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
  9151. stream << Colour( Colour::ResultSuccess ) << "All tests passed";
  9152. stream << " ("
  9153. << pluralise( totals.assertions.passed, "assertion" ) << " in "
  9154. << pluralise( totals.testCases.passed, "test case" ) << ')'
  9155. << '\n';
  9156. }
  9157. else {
  9158. std::vector<SummaryColumn> columns;
  9159. columns.push_back( SummaryColumn( "", Colour::None )
  9160. .addRow( totals.testCases.total() )
  9161. .addRow( totals.assertions.total() ) );
  9162. columns.push_back( SummaryColumn( "passed", Colour::Success )
  9163. .addRow( totals.testCases.passed )
  9164. .addRow( totals.assertions.passed ) );
  9165. columns.push_back( SummaryColumn( "failed", Colour::ResultError )
  9166. .addRow( totals.testCases.failed )
  9167. .addRow( totals.assertions.failed ) );
  9168. columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
  9169. .addRow( totals.testCases.failedButOk )
  9170. .addRow( totals.assertions.failedButOk ) );
  9171. printSummaryRow( "test cases", columns, 0 );
  9172. printSummaryRow( "assertions", columns, 1 );
  9173. }
  9174. }
  9175. void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
  9176. for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
  9177. std::string value = it->rows[row];
  9178. if( it->label.empty() ) {
  9179. stream << label << ": ";
  9180. if( value != "0" )
  9181. stream << value;
  9182. else
  9183. stream << Colour( Colour::Warning ) << "- none -";
  9184. }
  9185. else if( value != "0" ) {
  9186. stream << Colour( Colour::LightGrey ) << " | ";
  9187. stream << Colour( it->colour )
  9188. << value << ' ' << it->label;
  9189. }
  9190. }
  9191. stream << '\n';
  9192. }
  9193. static std::size_t makeRatio( std::size_t number, std::size_t total ) {
  9194. std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
  9195. return ( ratio == 0 && number > 0 ) ? 1 : ratio;
  9196. }
  9197. static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
  9198. if( i > j && i > k )
  9199. return i;
  9200. else if( j > k )
  9201. return j;
  9202. else
  9203. return k;
  9204. }
  9205. void printTotalsDivider( Totals const& totals ) {
  9206. if( totals.testCases.total() > 0 ) {
  9207. std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
  9208. std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
  9209. std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
  9210. while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9211. findMax( failedRatio, failedButOkRatio, passedRatio )++;
  9212. while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
  9213. findMax( failedRatio, failedButOkRatio, passedRatio )--;
  9214. stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
  9215. stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
  9216. if( totals.testCases.allPassed() )
  9217. stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
  9218. else
  9219. stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
  9220. }
  9221. else {
  9222. stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
  9223. }
  9224. stream << '\n';
  9225. }
  9226. void printSummaryDivider() {
  9227. stream << getLineOfChars<'-'>() << '\n';
  9228. }
  9229. private:
  9230. bool m_headerPrinted;
  9231. };
  9232. INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
  9233. } // end namespace Catch
  9234. // #included from: ../reporters/catch_reporter_compact.hpp
  9235. #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
  9236. namespace Catch {
  9237. struct CompactReporter : StreamingReporterBase {
  9238. CompactReporter( ReporterConfig const& _config )
  9239. : StreamingReporterBase( _config )
  9240. {}
  9241. virtual ~CompactReporter();
  9242. static std::string getDescription() {
  9243. return "Reports test results on a single line, suitable for IDEs";
  9244. }
  9245. virtual ReporterPreferences getPreferences() const {
  9246. ReporterPreferences prefs;
  9247. prefs.shouldRedirectStdOut = false;
  9248. return prefs;
  9249. }
  9250. virtual void noMatchingTestCases( std::string const& spec ) {
  9251. stream << "No test cases matched '" << spec << '\'' << std::endl;
  9252. }
  9253. virtual void assertionStarting( AssertionInfo const& ) {}
  9254. virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
  9255. AssertionResult const& result = _assertionStats.assertionResult;
  9256. bool printInfoMessages = true;
  9257. // Drop out if result was successful and we're not printing those
  9258. if( !m_config->includeSuccessfulResults() && result.isOk() ) {
  9259. if( result.getResultType() != ResultWas::Warning )
  9260. return false;
  9261. printInfoMessages = false;
  9262. }
  9263. AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
  9264. printer.print();
  9265. stream << std::endl;
  9266. return true;
  9267. }
  9268. virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE {
  9269. if (m_config->showDurations() == ShowDurations::Always) {
  9270. stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
  9271. }
  9272. }
  9273. virtual void testRunEnded( TestRunStats const& _testRunStats ) {
  9274. printTotals( _testRunStats.totals );
  9275. stream << '\n' << std::endl;
  9276. StreamingReporterBase::testRunEnded( _testRunStats );
  9277. }
  9278. private:
  9279. class AssertionPrinter {
  9280. void operator= ( AssertionPrinter const& );
  9281. public:
  9282. AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
  9283. : stream( _stream )
  9284. , stats( _stats )
  9285. , result( _stats.assertionResult )
  9286. , messages( _stats.infoMessages )
  9287. , itMessage( _stats.infoMessages.begin() )
  9288. , printInfoMessages( _printInfoMessages )
  9289. {}
  9290. void print() {
  9291. printSourceInfo();
  9292. itMessage = messages.begin();
  9293. switch( result.getResultType() ) {
  9294. case ResultWas::Ok:
  9295. printResultType( Colour::ResultSuccess, passedString() );
  9296. printOriginalExpression();
  9297. printReconstructedExpression();
  9298. if ( ! result.hasExpression() )
  9299. printRemainingMessages( Colour::None );
  9300. else
  9301. printRemainingMessages();
  9302. break;
  9303. case ResultWas::ExpressionFailed:
  9304. if( result.isOk() )
  9305. printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
  9306. else
  9307. printResultType( Colour::Error, failedString() );
  9308. printOriginalExpression();
  9309. printReconstructedExpression();
  9310. printRemainingMessages();
  9311. break;
  9312. case ResultWas::ThrewException:
  9313. printResultType( Colour::Error, failedString() );
  9314. printIssue( "unexpected exception with message:" );
  9315. printMessage();
  9316. printExpressionWas();
  9317. printRemainingMessages();
  9318. break;
  9319. case ResultWas::FatalErrorCondition:
  9320. printResultType( Colour::Error, failedString() );
  9321. printIssue( "fatal error condition with message:" );
  9322. printMessage();
  9323. printExpressionWas();
  9324. printRemainingMessages();
  9325. break;
  9326. case ResultWas::DidntThrowException:
  9327. printResultType( Colour::Error, failedString() );
  9328. printIssue( "expected exception, got none" );
  9329. printExpressionWas();
  9330. printRemainingMessages();
  9331. break;
  9332. case ResultWas::Info:
  9333. printResultType( Colour::None, "info" );
  9334. printMessage();
  9335. printRemainingMessages();
  9336. break;
  9337. case ResultWas::Warning:
  9338. printResultType( Colour::None, "warning" );
  9339. printMessage();
  9340. printRemainingMessages();
  9341. break;
  9342. case ResultWas::ExplicitFailure:
  9343. printResultType( Colour::Error, failedString() );
  9344. printIssue( "explicitly" );
  9345. printRemainingMessages( Colour::None );
  9346. break;
  9347. // These cases are here to prevent compiler warnings
  9348. case ResultWas::Unknown:
  9349. case ResultWas::FailureBit:
  9350. case ResultWas::Exception:
  9351. printResultType( Colour::Error, "** internal error **" );
  9352. break;
  9353. }
  9354. }
  9355. private:
  9356. // Colour::LightGrey
  9357. static Colour::Code dimColour() { return Colour::FileName; }
  9358. #ifdef CATCH_PLATFORM_MAC
  9359. static const char* failedString() { return "FAILED"; }
  9360. static const char* passedString() { return "PASSED"; }
  9361. #else
  9362. static const char* failedString() { return "failed"; }
  9363. static const char* passedString() { return "passed"; }
  9364. #endif
  9365. void printSourceInfo() const {
  9366. Colour colourGuard( Colour::FileName );
  9367. stream << result.getSourceInfo() << ':';
  9368. }
  9369. void printResultType( Colour::Code colour, std::string const& passOrFail ) const {
  9370. if( !passOrFail.empty() ) {
  9371. {
  9372. Colour colourGuard( colour );
  9373. stream << ' ' << passOrFail;
  9374. }
  9375. stream << ':';
  9376. }
  9377. }
  9378. void printIssue( std::string const& issue ) const {
  9379. stream << ' ' << issue;
  9380. }
  9381. void printExpressionWas() {
  9382. if( result.hasExpression() ) {
  9383. stream << ';';
  9384. {
  9385. Colour colour( dimColour() );
  9386. stream << " expression was:";
  9387. }
  9388. printOriginalExpression();
  9389. }
  9390. }
  9391. void printOriginalExpression() const {
  9392. if( result.hasExpression() ) {
  9393. stream << ' ' << result.getExpression();
  9394. }
  9395. }
  9396. void printReconstructedExpression() const {
  9397. if( result.hasExpandedExpression() ) {
  9398. {
  9399. Colour colour( dimColour() );
  9400. stream << " for: ";
  9401. }
  9402. stream << result.getExpandedExpression();
  9403. }
  9404. }
  9405. void printMessage() {
  9406. if ( itMessage != messages.end() ) {
  9407. stream << " '" << itMessage->message << '\'';
  9408. ++itMessage;
  9409. }
  9410. }
  9411. void printRemainingMessages( Colour::Code colour = dimColour() ) {
  9412. if ( itMessage == messages.end() )
  9413. return;
  9414. // using messages.end() directly yields compilation error:
  9415. std::vector<MessageInfo>::const_iterator itEnd = messages.end();
  9416. const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
  9417. {
  9418. Colour colourGuard( colour );
  9419. stream << " with " << pluralise( N, "message" ) << ':';
  9420. }
  9421. for(; itMessage != itEnd; ) {
  9422. // If this assertion is a warning ignore any INFO messages
  9423. if( printInfoMessages || itMessage->type != ResultWas::Info ) {
  9424. stream << " '" << itMessage->message << '\'';
  9425. if ( ++itMessage != itEnd ) {
  9426. Colour colourGuard( dimColour() );
  9427. stream << " and";
  9428. }
  9429. }
  9430. }
  9431. }
  9432. private:
  9433. std::ostream& stream;
  9434. AssertionStats const& stats;
  9435. AssertionResult const& result;
  9436. std::vector<MessageInfo> messages;
  9437. std::vector<MessageInfo>::const_iterator itMessage;
  9438. bool printInfoMessages;
  9439. };
  9440. // Colour, message variants:
  9441. // - white: No tests ran.
  9442. // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
  9443. // - white: Passed [both/all] N test cases (no assertions).
  9444. // - red: Failed N tests cases, failed M assertions.
  9445. // - green: Passed [both/all] N tests cases with M assertions.
  9446. std::string bothOrAll( std::size_t count ) const {
  9447. return count == 1 ? std::string() : count == 2 ? "both " : "all " ;
  9448. }
  9449. void printTotals( const Totals& totals ) const {
  9450. if( totals.testCases.total() == 0 ) {
  9451. stream << "No tests ran.";
  9452. }
  9453. else if( totals.testCases.failed == totals.testCases.total() ) {
  9454. Colour colour( Colour::ResultError );
  9455. const std::string qualify_assertions_failed =
  9456. totals.assertions.failed == totals.assertions.total() ?
  9457. bothOrAll( totals.assertions.failed ) : std::string();
  9458. stream <<
  9459. "Failed " << bothOrAll( totals.testCases.failed )
  9460. << pluralise( totals.testCases.failed, "test case" ) << ", "
  9461. "failed " << qualify_assertions_failed <<
  9462. pluralise( totals.assertions.failed, "assertion" ) << '.';
  9463. }
  9464. else if( totals.assertions.total() == 0 ) {
  9465. stream <<
  9466. "Passed " << bothOrAll( totals.testCases.total() )
  9467. << pluralise( totals.testCases.total(), "test case" )
  9468. << " (no assertions).";
  9469. }
  9470. else if( totals.assertions.failed ) {
  9471. Colour colour( Colour::ResultError );
  9472. stream <<
  9473. "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
  9474. "failed " << pluralise( totals.assertions.failed, "assertion" ) << '.';
  9475. }
  9476. else {
  9477. Colour colour( Colour::ResultSuccess );
  9478. stream <<
  9479. "Passed " << bothOrAll( totals.testCases.passed )
  9480. << pluralise( totals.testCases.passed, "test case" ) <<
  9481. " with " << pluralise( totals.assertions.passed, "assertion" ) << '.';
  9482. }
  9483. }
  9484. };
  9485. INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
  9486. } // end namespace Catch
  9487. namespace Catch {
  9488. // These are all here to avoid warnings about not having any out of line
  9489. // virtual methods
  9490. NonCopyable::~NonCopyable() {}
  9491. IShared::~IShared() {}
  9492. IStream::~IStream() CATCH_NOEXCEPT {}
  9493. FileStream::~FileStream() CATCH_NOEXCEPT {}
  9494. CoutStream::~CoutStream() CATCH_NOEXCEPT {}
  9495. DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
  9496. StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
  9497. IContext::~IContext() {}
  9498. IResultCapture::~IResultCapture() {}
  9499. ITestCase::~ITestCase() {}
  9500. ITestCaseRegistry::~ITestCaseRegistry() {}
  9501. IRegistryHub::~IRegistryHub() {}
  9502. IMutableRegistryHub::~IMutableRegistryHub() {}
  9503. IExceptionTranslator::~IExceptionTranslator() {}
  9504. IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
  9505. IReporter::~IReporter() {}
  9506. IReporterFactory::~IReporterFactory() {}
  9507. IReporterRegistry::~IReporterRegistry() {}
  9508. IStreamingReporter::~IStreamingReporter() {}
  9509. AssertionStats::~AssertionStats() {}
  9510. SectionStats::~SectionStats() {}
  9511. TestCaseStats::~TestCaseStats() {}
  9512. TestGroupStats::~TestGroupStats() {}
  9513. TestRunStats::~TestRunStats() {}
  9514. CumulativeReporterBase::SectionNode::~SectionNode() {}
  9515. CumulativeReporterBase::~CumulativeReporterBase() {}
  9516. StreamingReporterBase::~StreamingReporterBase() {}
  9517. ConsoleReporter::~ConsoleReporter() {}
  9518. CompactReporter::~CompactReporter() {}
  9519. IRunner::~IRunner() {}
  9520. IMutableContext::~IMutableContext() {}
  9521. IConfig::~IConfig() {}
  9522. XmlReporter::~XmlReporter() {}
  9523. JunitReporter::~JunitReporter() {}
  9524. TestRegistry::~TestRegistry() {}
  9525. FreeFunctionTestCase::~FreeFunctionTestCase() {}
  9526. IGeneratorInfo::~IGeneratorInfo() {}
  9527. IGeneratorsForTest::~IGeneratorsForTest() {}
  9528. WildcardPattern::~WildcardPattern() {}
  9529. TestSpec::Pattern::~Pattern() {}
  9530. TestSpec::NamePattern::~NamePattern() {}
  9531. TestSpec::TagPattern::~TagPattern() {}
  9532. TestSpec::ExcludedPattern::~ExcludedPattern() {}
  9533. Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {}
  9534. void Config::dummy() {}
  9535. namespace TestCaseTracking {
  9536. ITracker::~ITracker() {}
  9537. TrackerBase::~TrackerBase() {}
  9538. SectionTracker::~SectionTracker() {}
  9539. IndexTracker::~IndexTracker() {}
  9540. }
  9541. }
  9542. #ifdef __clang__
  9543. #pragma clang diagnostic pop
  9544. #endif
  9545. #endif
  9546. #ifdef CATCH_CONFIG_MAIN
  9547. // #included from: internal/catch_default_main.hpp
  9548. #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
  9549. #ifndef __OBJC__
  9550. #if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
  9551. // Standard C/C++ Win32 Unicode wmain entry point
  9552. extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
  9553. #else
  9554. // Standard C/C++ main entry point
  9555. int main (int argc, char * argv[]) {
  9556. #endif
  9557. int result = Catch::Session().run( argc, argv );
  9558. return ( result < 0xff ? result : 0xff );
  9559. }
  9560. #else // __OBJC__
  9561. // Objective-C entry point
  9562. int main (int argc, char * const argv[]) {
  9563. #if !CATCH_ARC_ENABLED
  9564. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  9565. #endif
  9566. Catch::registerTestMethods();
  9567. int result = Catch::Session().run( argc, (char* const*)argv );
  9568. #if !CATCH_ARC_ENABLED
  9569. [pool drain];
  9570. #endif
  9571. return ( result < 0xff ? result : 0xff );
  9572. }
  9573. #endif // __OBJC__
  9574. #endif
  9575. #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
  9576. # undef CLARA_CONFIG_MAIN
  9577. #endif
  9578. //////
  9579. // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
  9580. #ifdef CATCH_CONFIG_PREFIX_ALL
  9581. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9582. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9583. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9584. #else
  9585. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
  9586. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9587. #endif
  9588. #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9589. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9590. #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9591. #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9592. #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9593. #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9594. #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9595. #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9596. #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9597. #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9598. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9599. #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9600. #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9601. #define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9602. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9603. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9604. #else
  9605. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9606. #endif
  9607. #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9608. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9609. #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
  9610. #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9611. #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
  9612. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9613. #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9614. #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9615. #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9616. #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9617. #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9618. #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9619. #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9620. #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9621. #else
  9622. #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9623. #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9624. #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9625. #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
  9626. #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9627. #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9628. #define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9629. #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9630. #endif
  9631. #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9632. #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9633. #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9634. #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9635. // "BDD-style" convenience wrappers
  9636. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9637. #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
  9638. #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9639. #else
  9640. #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
  9641. #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9642. #endif
  9643. #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
  9644. #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
  9645. #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9646. #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
  9647. #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
  9648. // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
  9649. #else
  9650. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9651. #define REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9652. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9653. #else
  9654. #define REQUIRE( expr ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, expr )
  9655. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
  9656. #endif
  9657. #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
  9658. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
  9659. #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
  9660. #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
  9661. #define CHECK( expr ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
  9662. #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
  9663. #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
  9664. #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
  9665. #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
  9666. #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
  9667. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
  9668. #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
  9669. #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
  9670. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
  9671. #if defined(CATCH_CONFIG_FAST_COMPILE)
  9672. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9673. #else
  9674. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
  9675. #endif
  9676. #define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9677. #define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
  9678. #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
  9679. #define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9680. #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
  9681. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9682. #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
  9683. #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
  9684. #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
  9685. #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
  9686. #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
  9687. #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ )
  9688. #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9689. #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
  9690. #else
  9691. #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  9692. #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
  9693. #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  9694. #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
  9695. #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  9696. #define FAIL( msg ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
  9697. #define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
  9698. #define SUCCEED( msg ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
  9699. #endif
  9700. #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
  9701. #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  9702. #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
  9703. #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  9704. #endif
  9705. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  9706. // "BDD-style" convenience wrappers
  9707. #ifdef CATCH_CONFIG_VARIADIC_MACROS
  9708. #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
  9709. #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
  9710. #else
  9711. #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
  9712. #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
  9713. #endif
  9714. #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
  9715. #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
  9716. #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
  9717. #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
  9718. #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
  9719. using Catch::Detail::Approx;
  9720. // #included from: internal/catch_reenable_warnings.h
  9721. #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
  9722. #ifdef __clang__
  9723. # ifdef __ICC // icpc defines the __clang__ macro
  9724. # pragma warning(pop)
  9725. # else
  9726. # pragma clang diagnostic pop
  9727. # endif
  9728. #elif defined __GNUC__
  9729. # pragma GCC diagnostic pop
  9730. #endif
  9731. #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED