catch.hpp 219 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446
  1. /*
  2. * Generated: 2013-02-19 08:44:57.311773
  3. * ----------------------------------------------------------
  4. * This file has been merged from multiple headers. Please don't edit it directly
  5. * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
  6. *
  7. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. */
  10. #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  11. #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
  12. #define TWOBLUECUBES_CATCH_HPP_INCLUDED
  13. #ifdef __clang__
  14. #pragma clang diagnostic ignored "-Wglobal-constructors"
  15. #pragma clang diagnostic push
  16. #pragma clang diagnostic ignored "-Wpadded"
  17. #endif
  18. // #included from: internal/catch_notimplemented_exception.h
  19. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
  20. // #included from: catch_common.h
  21. #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
  22. #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
  23. #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
  24. #define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
  25. #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
  26. #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
  27. #ifdef __GNUC__
  28. #define CATCH_ATTRIBUTE_NORETURN __attribute__ ((noreturn))
  29. #else
  30. #define CATCH_ATTRIBUTE_NORETURN
  31. #endif
  32. #include <sstream>
  33. #include <stdexcept>
  34. #include <algorithm>
  35. namespace Catch {
  36. class NonCopyable {
  37. NonCopyable( const NonCopyable& );
  38. void operator = ( const NonCopyable& );
  39. protected:
  40. NonCopyable() {}
  41. virtual ~NonCopyable();
  42. };
  43. class SafeBool {
  44. public:
  45. typedef void (SafeBool::*type)() const;
  46. static type makeSafe( bool value ) {
  47. return value ? &SafeBool::trueValue : 0;
  48. }
  49. private:
  50. void trueValue() const {}
  51. };
  52. template<typename ContainerT>
  53. inline void deleteAll( ContainerT& container ) {
  54. typename ContainerT::const_iterator it = container.begin();
  55. typename ContainerT::const_iterator itEnd = container.end();
  56. for(; it != itEnd; ++it )
  57. {
  58. delete *it;
  59. }
  60. }
  61. template<typename AssociativeContainerT>
  62. inline void deleteAllValues( AssociativeContainerT& container ) {
  63. typename AssociativeContainerT::const_iterator it = container.begin();
  64. typename AssociativeContainerT::const_iterator itEnd = container.end();
  65. for(; it != itEnd; ++it )
  66. {
  67. delete it->second;
  68. }
  69. }
  70. template<typename ContainerT, typename Function>
  71. inline void forEach( ContainerT& container, Function function ) {
  72. std::for_each( container.begin(), container.end(), function );
  73. }
  74. template<typename ContainerT, typename Function>
  75. inline void forEach( const ContainerT& container, Function function ) {
  76. std::for_each( container.begin(), container.end(), function );
  77. }
  78. inline bool startsWith( const std::string& s, const std::string& prefix ) {
  79. return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix;
  80. }
  81. inline bool endsWith( const std::string& s, const std::string& suffix ) {
  82. return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix;
  83. }
  84. inline bool contains( const std::string& s, const std::string& infix ) {
  85. return s.find( infix ) != std::string::npos;
  86. }
  87. struct pluralise {
  88. pluralise( std::size_t count, const std::string& label )
  89. : m_count( count ),
  90. m_label( label )
  91. {}
  92. friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) {
  93. os << pluraliser.m_count << " " << pluraliser.m_label;
  94. if( pluraliser.m_count != 1 )
  95. os << "s";
  96. return os;
  97. }
  98. std::size_t m_count;
  99. std::string m_label;
  100. };
  101. struct SourceLineInfo {
  102. SourceLineInfo() : line( 0 ){}
  103. SourceLineInfo( const std::string& _file, std::size_t _line )
  104. : file( _file ),
  105. line( _line )
  106. {}
  107. SourceLineInfo( const SourceLineInfo& other )
  108. : file( other.file ),
  109. line( other.line )
  110. {}
  111. bool empty() const {
  112. return file.empty();
  113. }
  114. std::string file;
  115. std::size_t line;
  116. };
  117. inline std::ostream& operator << ( std::ostream& os, const SourceLineInfo& info ) {
  118. #ifndef __GNUG__
  119. os << info.file << "(" << info.line << "): ";
  120. #else
  121. os << info.file << ":" << info.line << ": ";
  122. #endif
  123. return os;
  124. }
  125. CATCH_ATTRIBUTE_NORETURN
  126. inline void throwLogicError( const std::string& message, const SourceLineInfo& locationInfo ) {
  127. std::ostringstream oss;
  128. oss << "Internal Catch error: '" << message << "' at: " << locationInfo;
  129. throw std::logic_error( oss.str() );
  130. }
  131. }
  132. #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
  133. #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
  134. #include <ostream>
  135. namespace Catch {
  136. class NotImplementedException : public std::exception
  137. {
  138. public:
  139. NotImplementedException( const SourceLineInfo& lineInfo );
  140. virtual ~NotImplementedException() throw() {}
  141. virtual const char* what() const throw();
  142. private:
  143. std::string m_what;
  144. SourceLineInfo m_lineInfo;
  145. };
  146. } // end namespace Catch
  147. ///////////////////////////////////////////////////////////////////////////////
  148. #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
  149. // #included from: internal/catch_context.h
  150. #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
  151. // #included from: catch_interfaces_generators.h
  152. #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
  153. #include <string>
  154. namespace Catch {
  155. struct IGeneratorInfo {
  156. virtual ~IGeneratorInfo();
  157. virtual bool moveNext() = 0;
  158. virtual std::size_t getCurrentIndex() const = 0;
  159. };
  160. struct IGeneratorsForTest {
  161. virtual ~IGeneratorsForTest();
  162. virtual IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) = 0;
  163. virtual bool moveNext() = 0;
  164. };
  165. IGeneratorsForTest* createGeneratorsForTest();
  166. } // end namespace Catch
  167. #include <memory>
  168. #include <vector>
  169. #include <stdlib.h>
  170. namespace Catch {
  171. class TestCaseInfo;
  172. class Stream;
  173. struct IResultCapture;
  174. struct IRunner;
  175. struct IGeneratorsForTest;
  176. struct IConfig;
  177. struct IContext
  178. {
  179. virtual ~IContext();
  180. virtual IResultCapture& getResultCapture() = 0;
  181. virtual IRunner& getRunner() = 0;
  182. virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) = 0;
  183. virtual bool advanceGeneratorsForCurrentTest() = 0;
  184. virtual const IConfig* getConfig() const = 0;
  185. };
  186. struct IMutableContext : IContext
  187. {
  188. virtual ~IMutableContext();
  189. virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
  190. virtual void setRunner( IRunner* runner ) = 0;
  191. virtual void setConfig( const IConfig* config ) = 0;
  192. };
  193. IContext& getCurrentContext();
  194. IMutableContext& getCurrentMutableContext();
  195. void cleanUpContext();
  196. Stream createStream( const std::string& streamName );
  197. }
  198. // #included from: internal/catch_test_registry.hpp
  199. #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
  200. // #included from: catch_interfaces_testcase.h
  201. #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
  202. // #included from: catch_ptr.hpp
  203. #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
  204. namespace Catch {
  205. // An intrusive reference counting smart pointer.
  206. // T must implement addRef() and release() methods
  207. // typically implementing the IShared interface
  208. template<typename T>
  209. class Ptr {
  210. public:
  211. Ptr() : m_p( NULL ){}
  212. Ptr( T* p ) : m_p( p ){
  213. if( m_p )
  214. m_p->addRef();
  215. }
  216. Ptr( const Ptr& other ) : m_p( other.m_p ){
  217. if( m_p )
  218. m_p->addRef();
  219. }
  220. ~Ptr(){
  221. if( m_p )
  222. m_p->release();
  223. }
  224. Ptr& operator = ( T* p ){
  225. Ptr temp( p );
  226. swap( temp );
  227. return *this;
  228. }
  229. Ptr& operator = ( const Ptr& other ){
  230. Ptr temp( other );
  231. swap( temp );
  232. return *this;
  233. }
  234. void swap( Ptr& other ){
  235. std::swap( m_p, other.m_p );
  236. }
  237. T* get(){
  238. return m_p;
  239. }
  240. const T* get() const{
  241. return m_p;
  242. }
  243. T& operator*() const {
  244. return *m_p;
  245. }
  246. T* operator->() const {
  247. return m_p;
  248. }
  249. bool operator !() const {
  250. return m_p == NULL;
  251. }
  252. private:
  253. T* m_p;
  254. };
  255. struct IShared : NonCopyable {
  256. virtual ~IShared();
  257. virtual void addRef() = 0;
  258. virtual void release() = 0;
  259. };
  260. template<typename T>
  261. struct SharedImpl : T {
  262. SharedImpl() : m_rc( 0 ){}
  263. virtual void addRef(){
  264. ++m_rc;
  265. }
  266. virtual void release(){
  267. if( --m_rc == 0 )
  268. delete this;
  269. }
  270. int m_rc;
  271. };
  272. } // end namespace Catch
  273. #include <vector>
  274. namespace Catch {
  275. class TestCaseFilters;
  276. struct ITestCase : IShared {
  277. virtual void invoke () const = 0;
  278. protected:
  279. virtual ~ITestCase();
  280. };
  281. class TestCaseInfo;
  282. struct ITestCaseRegistry {
  283. virtual ~ITestCaseRegistry();
  284. virtual const std::vector<TestCaseInfo>& getAllTests() const = 0;
  285. virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const = 0;
  286. };
  287. }
  288. namespace Catch {
  289. template<typename C>
  290. class MethodTestCase : public SharedImpl<ITestCase> {
  291. public:
  292. MethodTestCase( void (C::*method)() ) : m_method( method ) {}
  293. virtual void invoke() const {
  294. C obj;
  295. (obj.*m_method)();
  296. }
  297. private:
  298. virtual ~MethodTestCase() {}
  299. void (C::*m_method)();
  300. };
  301. typedef void(*TestFunction)();
  302. struct AutoReg {
  303. AutoReg( TestFunction function,
  304. const char* name,
  305. const char* description,
  306. const SourceLineInfo& lineInfo );
  307. template<typename C>
  308. AutoReg( void (C::*method)(),
  309. const char* className,
  310. const char* name,
  311. const char* description,
  312. const SourceLineInfo& lineInfo ) {
  313. registerTestCase( new MethodTestCase<C>( method ), className, name, description, lineInfo );
  314. }
  315. void registerTestCase( ITestCase* testCase,
  316. const char* className,
  317. const char* name,
  318. const char* description,
  319. const SourceLineInfo& lineInfo );
  320. ~AutoReg();
  321. private:
  322. AutoReg( const AutoReg& );
  323. void operator= ( const AutoReg& );
  324. };
  325. } // end namespace Catch
  326. ///////////////////////////////////////////////////////////////////////////////
  327. #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
  328. static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )(); \
  329. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
  330. static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
  331. ///////////////////////////////////////////////////////////////////////////////
  332. #define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \
  333. static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )() CATCH_ATTRIBUTE_NORETURN; \
  334. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
  335. static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
  336. ///////////////////////////////////////////////////////////////////////////////
  337. #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
  338. namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Name, Desc, CATCH_INTERNAL_LINEINFO ); }
  339. ///////////////////////////////////////////////////////////////////////////////
  340. #define TEST_CASE_METHOD( ClassName, TestName, Desc )\
  341. namespace{ \
  342. struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
  343. void test(); \
  344. }; \
  345. Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test, #ClassName, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
  346. } \
  347. void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test()
  348. // #included from: internal/catch_capture.hpp
  349. #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
  350. // #included from: catch_expression_decomposer.hpp
  351. #define TWOBLUECUBES_CATCH_EXPRESSION_DECOMPOSER_HPP_INCLUDED
  352. // #included from: catch_expression_lhs.hpp
  353. #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
  354. // #included from: catch_expressionresult_builder.h
  355. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_BUILDER_H_INCLUDED
  356. // #included from: catch_tostring.hpp
  357. #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
  358. #include <sstream>
  359. #ifdef __OBJC__
  360. // #included from: catch_objc_arc.hpp
  361. #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
  362. #import <Foundation/Foundation.h>
  363. #ifdef __has_feature
  364. #define CATCH_ARC_ENABLED __has_feature(objc_arc)
  365. #else
  366. #define CATCH_ARC_ENABLED 0
  367. #endif
  368. void arcSafeRelease( NSObject* obj );
  369. id performOptionalSelector( id obj, SEL sel );
  370. #if !CATCH_ARC_ENABLED
  371. inline void arcSafeRelease( NSObject* obj ) {
  372. [obj release];
  373. }
  374. inline id performOptionalSelector( id obj, SEL sel ) {
  375. if( [obj respondsToSelector: sel] )
  376. return [obj performSelector: sel];
  377. return nil;
  378. }
  379. #define CATCH_UNSAFE_UNRETAINED
  380. #define CATCH_ARC_STRONG
  381. #else
  382. inline void arcSafeRelease( NSObject* ){}
  383. inline id performOptionalSelector( id obj, SEL sel ) {
  384. #ifdef __clang__
  385. #pragma clang diagnostic push
  386. #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
  387. #endif
  388. if( [obj respondsToSelector: sel] )
  389. return [obj performSelector: sel];
  390. #ifdef __clang__
  391. #pragma clang diagnostic pop
  392. #endif
  393. return nil;
  394. }
  395. #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
  396. #define CATCH_ARC_STRONG __strong
  397. #endif
  398. #endif
  399. namespace Catch {
  400. namespace Detail {
  401. struct NonStreamable {
  402. template<typename T> NonStreamable( const T& ){}
  403. };
  404. // If the type does not have its own << overload for ostream then
  405. // this one will be used instead
  406. inline std::ostream& operator << ( std::ostream& ss, NonStreamable ){
  407. return ss << "{?}";
  408. }
  409. template<typename T>
  410. inline std::string makeString( const T& value ) {
  411. std::ostringstream oss;
  412. oss << value;
  413. return oss.str();
  414. }
  415. template<typename T>
  416. inline std::string makeString( T* p ) {
  417. if( !p )
  418. return INTERNAL_CATCH_STRINGIFY( NULL );
  419. std::ostringstream oss;
  420. oss << p;
  421. return oss.str();
  422. }
  423. template<typename T>
  424. inline std::string makeString( const T* p ) {
  425. if( !p )
  426. return INTERNAL_CATCH_STRINGIFY( NULL );
  427. std::ostringstream oss;
  428. oss << p;
  429. return oss.str();
  430. }
  431. } // end namespace Detail
  432. /// \brief converts any type to a string
  433. ///
  434. /// The default template forwards on to ostringstream - except when an
  435. /// ostringstream overload does not exist - in which case it attempts to detect
  436. /// that and writes {?}.
  437. /// Overload (not specialise) this template for custom typs that you don't want
  438. /// to provide an ostream overload for.
  439. template<typename T>
  440. std::string toString( const T& value ) {
  441. return Detail::makeString( value );
  442. }
  443. // Built in overloads
  444. inline std::string toString( const std::string& value ) {
  445. return "\"" + value + "\"";
  446. }
  447. inline std::string toString( const std::wstring& value ) {
  448. std::ostringstream oss;
  449. oss << "\"";
  450. for(size_t i = 0; i < value.size(); ++i )
  451. oss << static_cast<char>( value[i] <= 0xff ? value[i] : '?');
  452. oss << "\"";
  453. return oss.str();
  454. }
  455. inline std::string toString( const char* const value ) {
  456. return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
  457. }
  458. inline std::string toString( char* const value ) {
  459. return Catch::toString( static_cast<const char*>( value ) );
  460. }
  461. inline std::string toString( int value ) {
  462. std::ostringstream oss;
  463. oss << value;
  464. return oss.str();
  465. }
  466. inline std::string toString( unsigned long value ) {
  467. std::ostringstream oss;
  468. if( value > 8192 )
  469. oss << "0x" << std::hex << value;
  470. else
  471. oss << value;
  472. return oss.str();
  473. }
  474. inline std::string toString( unsigned int value ) {
  475. return toString( static_cast<unsigned long>( value ) );
  476. }
  477. inline std::string toString( const double value ) {
  478. std::ostringstream oss;
  479. oss << value;
  480. return oss.str();
  481. }
  482. inline std::string toString( bool value ) {
  483. return value ? "true" : "false";
  484. }
  485. inline std::string toString( char value ) {
  486. return value < ' '
  487. ? toString( (unsigned int)value )
  488. : Detail::makeString( value );
  489. }
  490. inline std::string toString( signed char value ) {
  491. return toString( static_cast<char>( value ) );
  492. }
  493. #ifdef CATCH_CONFIG_CPP11_NULLPTR
  494. inline std::string toString( std::nullptr_t ) {
  495. return "nullptr";
  496. }
  497. #endif
  498. #ifdef __OBJC__
  499. inline std::string toString( NSString const * const& nsstring ) {
  500. return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
  501. }
  502. inline std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
  503. return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
  504. }
  505. inline std::string toString( NSObject* const& nsObject ) {
  506. return toString( [nsObject description] );
  507. }
  508. #endif
  509. } // end namespace Catch
  510. // #included from: catch_assertionresult.h
  511. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
  512. #include <string>
  513. // #included from: catch_result_type.h
  514. #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
  515. namespace Catch {
  516. // ResultWas::OfType enum
  517. struct ResultWas { enum OfType {
  518. Unknown = -1,
  519. Ok = 0,
  520. Info = 1,
  521. Warning = 2,
  522. FailureBit = 0x10,
  523. ExpressionFailed = FailureBit | 1,
  524. ExplicitFailure = FailureBit | 2,
  525. Exception = 0x100 | FailureBit,
  526. ThrewException = Exception | 1,
  527. DidntThrowException = Exception | 2
  528. }; };
  529. inline bool isOk( ResultWas::OfType resultType ) {
  530. return ( resultType & ResultWas::FailureBit ) == 0;
  531. }
  532. // ResultAction::Value enum
  533. struct ResultAction { enum Value {
  534. None,
  535. Failed = 1, // Failure - but no debug break if Debug bit not set
  536. Debug = 2, // If this bit is set, invoke the debugger
  537. Abort = 4 // Test run should abort
  538. }; };
  539. // ResultDisposition::Flags enum
  540. struct ResultDisposition { enum Flags {
  541. Normal = 0x00,
  542. ContinueOnFailure = 0x01, // Failures fail test, but execution continues
  543. NegateResult = 0x02, // Prefix expressiom with !
  544. SuppressFail = 0x04 // Failures are reported but do not fail the test
  545. }; };
  546. inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
  547. return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
  548. }
  549. inline bool shouldContinueOnFailure( int flags ) { return flags & ResultDisposition::ContinueOnFailure; }
  550. inline bool shouldNegate( int flags ) { return flags & ResultDisposition::NegateResult; }
  551. inline bool shouldSuppressFailure( int flags ) { return flags & ResultDisposition::SuppressFail; }
  552. } // end namespace Catch
  553. namespace Catch {
  554. struct AssertionInfo
  555. {
  556. AssertionInfo() {}
  557. AssertionInfo( const std::string& _macroName,
  558. const SourceLineInfo& _lineInfo,
  559. const std::string& _capturedExpression,
  560. ResultDisposition::Flags _resultDisposition );
  561. std::string macroName;
  562. SourceLineInfo lineInfo;
  563. std::string capturedExpression;
  564. ResultDisposition::Flags resultDisposition;
  565. };
  566. struct AssertionResultData
  567. {
  568. AssertionResultData() : resultType( ResultWas::Unknown ) {}
  569. std::string reconstructedExpression;
  570. std::string message;
  571. ResultWas::OfType resultType;
  572. };
  573. class AssertionResult {
  574. public:
  575. AssertionResult();
  576. AssertionResult( const AssertionInfo& info, const AssertionResultData& data );
  577. ~AssertionResult();
  578. bool isOk() const;
  579. bool succeeded() const;
  580. ResultWas::OfType getResultType() const;
  581. bool hasExpression() const;
  582. bool hasMessage() const;
  583. std::string getExpression() const;
  584. bool hasExpandedExpression() const;
  585. std::string getExpandedExpression() const;
  586. std::string getMessage() const;
  587. SourceLineInfo getSourceInfo() const;
  588. std::string getTestMacroName() const;
  589. protected:
  590. AssertionInfo m_info;
  591. AssertionResultData m_resultData;
  592. };
  593. } // end namespace Catch
  594. // #included from: catch_evaluate.hpp
  595. #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
  596. namespace Catch {
  597. namespace Internal {
  598. enum Operator {
  599. IsEqualTo,
  600. IsNotEqualTo,
  601. IsLessThan,
  602. IsGreaterThan,
  603. IsLessThanOrEqualTo,
  604. IsGreaterThanOrEqualTo
  605. };
  606. template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
  607. template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
  608. template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
  609. template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
  610. template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
  611. template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
  612. template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
  613. // So the compare overloads can be operator agnostic we convey the operator as a template
  614. // enum, which is used to specialise an Evaluator for doing the comparison.
  615. template<typename T1, typename T2, Operator Op>
  616. class Evaluator{};
  617. template<typename T1, typename T2>
  618. struct Evaluator<T1, T2, IsEqualTo> {
  619. static bool evaluate( const T1& lhs, const T2& rhs) {
  620. return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
  621. }
  622. };
  623. template<typename T1, typename T2>
  624. struct Evaluator<T1, T2, IsNotEqualTo> {
  625. static bool evaluate( const T1& lhs, const T2& rhs ) {
  626. return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs );
  627. }
  628. };
  629. template<typename T1, typename T2>
  630. struct Evaluator<T1, T2, IsLessThan> {
  631. static bool evaluate( const T1& lhs, const T2& rhs ) {
  632. return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs );
  633. }
  634. };
  635. template<typename T1, typename T2>
  636. struct Evaluator<T1, T2, IsGreaterThan> {
  637. static bool evaluate( const T1& lhs, const T2& rhs ) {
  638. return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs );
  639. }
  640. };
  641. template<typename T1, typename T2>
  642. struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
  643. static bool evaluate( const T1& lhs, const T2& rhs ) {
  644. return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs );
  645. }
  646. };
  647. template<typename T1, typename T2>
  648. struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
  649. static bool evaluate( const T1& lhs, const T2& rhs ) {
  650. return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs );
  651. }
  652. };
  653. template<Operator Op, typename T1, typename T2>
  654. bool applyEvaluator( const T1& lhs, const T2& rhs ) {
  655. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  656. }
  657. // This level of indirection allows us to specialise for integer types
  658. // to avoid signed/ unsigned warnings
  659. // "base" overload
  660. template<Operator Op, typename T1, typename T2>
  661. bool compare( const T1& lhs, const T2& rhs ) {
  662. return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
  663. }
  664. // unsigned X to int
  665. template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
  666. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  667. }
  668. template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
  669. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  670. }
  671. template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
  672. return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
  673. }
  674. // unsigned X to long
  675. template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
  676. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  677. }
  678. template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
  679. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  680. }
  681. template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
  682. return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
  683. }
  684. // int to unsigned X
  685. template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
  686. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  687. }
  688. template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
  689. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  690. }
  691. template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
  692. return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
  693. }
  694. // long to unsigned X
  695. template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
  696. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  697. }
  698. template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
  699. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  700. }
  701. template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
  702. return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
  703. }
  704. // pointer to long (when comparing against NULL)
  705. template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
  706. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  707. }
  708. template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
  709. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  710. }
  711. // pointer to int (when comparing against NULL)
  712. template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
  713. return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
  714. }
  715. template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
  716. return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
  717. }
  718. } // end of namespace Internal
  719. } // end of namespace Catch
  720. namespace Catch {
  721. // Wraps the (stringised versions of) the lhs, operator and rhs of an expression - as well as
  722. // the result of evaluating it. This is used to build an AssertionResult object
  723. class ExpressionResultBuilder {
  724. public:
  725. ExpressionResultBuilder( ResultWas::OfType resultType = ResultWas::Unknown );
  726. ExpressionResultBuilder( const ExpressionResultBuilder& other );
  727. ExpressionResultBuilder& operator=(const ExpressionResultBuilder& other );
  728. ExpressionResultBuilder& setResultType( ResultWas::OfType result );
  729. ExpressionResultBuilder& setResultType( bool result );
  730. ExpressionResultBuilder& setLhs( const std::string& lhs );
  731. ExpressionResultBuilder& setRhs( const std::string& rhs );
  732. ExpressionResultBuilder& setOp( const std::string& op );
  733. ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition );
  734. template<typename T>
  735. ExpressionResultBuilder& operator << ( const T& value ) {
  736. m_stream << value;
  737. return *this;
  738. }
  739. std::string reconstructExpression( const AssertionInfo& info ) const;
  740. AssertionResult buildResult( const AssertionInfo& info ) const;
  741. private:
  742. AssertionResultData m_data;
  743. struct ExprComponents {
  744. ExprComponents() : shouldNegate( false ) {}
  745. bool shouldNegate;
  746. std::string lhs, rhs, op;
  747. } m_exprComponents;
  748. std::ostringstream m_stream;
  749. };
  750. } // end namespace Catch
  751. namespace Catch {
  752. struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
  753. // Wraps the LHS of an expression and captures the operator and RHS (if any) - wrapping them all
  754. // in an ExpressionResultBuilder object
  755. template<typename T>
  756. class ExpressionLhs {
  757. void operator = ( const ExpressionLhs& );
  758. public:
  759. ExpressionLhs( T lhs ) : m_lhs( lhs ) {}
  760. template<typename RhsT>
  761. ExpressionResultBuilder& operator == ( const RhsT& rhs ) {
  762. return captureExpression<Internal::IsEqualTo>( rhs );
  763. }
  764. template<typename RhsT>
  765. ExpressionResultBuilder& operator != ( const RhsT& rhs ) {
  766. return captureExpression<Internal::IsNotEqualTo>( rhs );
  767. }
  768. template<typename RhsT>
  769. ExpressionResultBuilder& operator < ( const RhsT& rhs ) {
  770. return captureExpression<Internal::IsLessThan>( rhs );
  771. }
  772. template<typename RhsT>
  773. ExpressionResultBuilder& operator > ( const RhsT& rhs ) {
  774. return captureExpression<Internal::IsGreaterThan>( rhs );
  775. }
  776. template<typename RhsT>
  777. ExpressionResultBuilder& operator <= ( const RhsT& rhs ) {
  778. return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
  779. }
  780. template<typename RhsT>
  781. ExpressionResultBuilder& operator >= ( const RhsT& rhs ) {
  782. return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
  783. }
  784. ExpressionResultBuilder& operator == ( bool rhs ) {
  785. return captureExpression<Internal::IsEqualTo>( rhs );
  786. }
  787. ExpressionResultBuilder& operator != ( bool rhs ) {
  788. return captureExpression<Internal::IsNotEqualTo>( rhs );
  789. }
  790. ExpressionResultBuilder& endExpression( ResultDisposition::Flags resultDisposition ) {
  791. bool value = m_lhs ? true : false;
  792. return m_result
  793. .setLhs( Catch::toString( value ) )
  794. .setResultType( value )
  795. .endExpression( resultDisposition );
  796. }
  797. // Only simple binary expressions are allowed on the LHS.
  798. // If more complex compositions are required then place the sub expression in parentheses
  799. template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
  800. template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
  801. template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( const RhsT& );
  802. template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( const RhsT& );
  803. private:
  804. template<Internal::Operator Op, typename RhsT>
  805. ExpressionResultBuilder& captureExpression( const RhsT& rhs ) {
  806. return m_result
  807. .setResultType( Internal::compare<Op>( m_lhs, rhs ) )
  808. .setLhs( Catch::toString( m_lhs ) )
  809. .setRhs( Catch::toString( rhs ) )
  810. .setOp( Internal::OperatorTraits<Op>::getName() );
  811. }
  812. private:
  813. ExpressionResultBuilder m_result;
  814. T m_lhs;
  815. };
  816. } // end namespace Catch
  817. namespace Catch {
  818. // Captures the LHS of the expression and wraps it in an Expression Lhs object
  819. class ExpressionDecomposer {
  820. public:
  821. template<typename T>
  822. ExpressionLhs<const T&> operator->* ( const T & operand ) {
  823. return ExpressionLhs<const T&>( operand );
  824. }
  825. ExpressionLhs<bool> operator->* ( bool value ) {
  826. return ExpressionLhs<bool>( value );
  827. }
  828. };
  829. } // end namespace Catch
  830. // #included from: catch_interfaces_capture.h
  831. #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
  832. #include <string>
  833. // #included from: catch_totals.hpp
  834. #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
  835. #include <cstddef>
  836. namespace Catch {
  837. struct Counts {
  838. Counts() : passed( 0 ), failed( 0 ) {}
  839. Counts operator - ( const Counts& other ) const {
  840. Counts diff;
  841. diff.passed = passed - other.passed;
  842. diff.failed = failed - other.failed;
  843. return diff;
  844. }
  845. Counts& operator += ( const Counts& other ) {
  846. passed += other.passed;
  847. failed += other.failed;
  848. return *this;
  849. }
  850. std::size_t total() const {
  851. return passed + failed;
  852. }
  853. std::size_t passed;
  854. std::size_t failed;
  855. };
  856. struct Totals {
  857. Totals operator - ( const Totals& other ) const {
  858. Totals diff;
  859. diff.assertions = assertions - other.assertions;
  860. diff.testCases = testCases - other.testCases;
  861. return diff;
  862. }
  863. Totals delta( const Totals& prevTotals ) const {
  864. Totals diff = *this - prevTotals;
  865. if( diff.assertions.failed > 0 )
  866. ++diff.testCases.failed;
  867. else
  868. ++diff.testCases.passed;
  869. return diff;
  870. }
  871. Totals& operator += ( const Totals& other ) {
  872. assertions += other.assertions;
  873. testCases += other.testCases;
  874. return *this;
  875. }
  876. Counts assertions;
  877. Counts testCases;
  878. };
  879. }
  880. namespace Catch {
  881. class TestCaseInfo;
  882. class ScopedInfo;
  883. class ExpressionResultBuilder;
  884. class AssertionResult;
  885. struct AssertionInfo;
  886. struct IResultCapture {
  887. virtual ~IResultCapture();
  888. virtual void testEnded( const AssertionResult& result ) = 0;
  889. virtual bool sectionStarted( const std::string& name,
  890. const std::string& description,
  891. const SourceLineInfo& lineInfo,
  892. Counts& assertions ) = 0;
  893. virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0;
  894. virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
  895. virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
  896. virtual bool shouldDebugBreak() const = 0;
  897. virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) = 0;
  898. virtual std::string getCurrentTestName() const = 0;
  899. virtual const AssertionResult* getLastResult() const = 0;
  900. };
  901. }
  902. // #included from: catch_debugger.hpp
  903. #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
  904. #include <iostream>
  905. #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
  906. #define CATCH_PLATFORM_MAC
  907. #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
  908. #define CATCH_PLATFORM_IPHONE
  909. #elif defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
  910. #define CATCH_PLATFORM_WINDOWS
  911. #endif
  912. #ifdef CATCH_PLATFORM_MAC
  913. #include <assert.h>
  914. #include <stdbool.h>
  915. #include <sys/types.h>
  916. #include <unistd.h>
  917. #include <sys/sysctl.h>
  918. namespace Catch{
  919. // The following function is taken directly from the following technical note:
  920. // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
  921. // Returns true if the current process is being debugged (either
  922. // running under the debugger or has a debugger attached post facto).
  923. inline bool isDebuggerActive(){
  924. int junk;
  925. int mib[4];
  926. struct kinfo_proc info;
  927. size_t size;
  928. // Initialize the flags so that, if sysctl fails for some bizarre
  929. // reason, we get a predictable result.
  930. info.kp_proc.p_flag = 0;
  931. // Initialize mib, which tells sysctl the info we want, in this case
  932. // we're looking for information about a specific process ID.
  933. mib[0] = CTL_KERN;
  934. mib[1] = KERN_PROC;
  935. mib[2] = KERN_PROC_PID;
  936. mib[3] = getpid();
  937. // Call sysctl.
  938. size = sizeof(info);
  939. junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
  940. assert(junk == 0);
  941. // We're being debugged if the P_TRACED flag is set.
  942. return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
  943. }
  944. }
  945. // The following code snippet taken from:
  946. // http://cocoawithlove.com/2008/03/break-into-debugger.html
  947. #ifdef DEBUG
  948. #if defined(__ppc64__) || defined(__ppc__)
  949. #define BreakIntoDebugger() \
  950. if( Catch::isDebuggerActive() ) { \
  951. __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
  952. : : : "memory","r0","r3","r4" ); \
  953. }
  954. #else
  955. #define BreakIntoDebugger() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );}
  956. #endif
  957. #else
  958. inline void BreakIntoDebugger(){}
  959. #endif
  960. #elif defined(_MSC_VER)
  961. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  962. #define BreakIntoDebugger() if (IsDebuggerPresent() ) { __debugbreak(); }
  963. inline bool isDebuggerActive() {
  964. return IsDebuggerPresent() != 0;
  965. }
  966. #elif defined(__MINGW32__)
  967. extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
  968. extern "C" __declspec(dllimport) void __stdcall DebugBreak();
  969. #define BreakIntoDebugger() if (IsDebuggerPresent() ) { DebugBreak(); }
  970. inline bool isDebuggerActive() {
  971. return IsDebuggerPresent() != 0;
  972. }
  973. #else
  974. inline void BreakIntoDebugger(){}
  975. inline bool isDebuggerActive() { return false; }
  976. #endif
  977. #ifdef CATCH_PLATFORM_WINDOWS
  978. extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );
  979. inline void writeToDebugConsole( const std::string& text ) {
  980. ::OutputDebugStringA( text.c_str() );
  981. }
  982. #else
  983. inline void writeToDebugConsole( const std::string& text ) {
  984. // !TBD: Need a version for Mac/ XCode and other IDEs
  985. std::cout << text;
  986. }
  987. #endif // CATCH_PLATFORM_WINDOWS
  988. // #included from: catch_interfaces_registry_hub.h
  989. #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
  990. // #included from: catch_interfaces_reporter.h
  991. #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
  992. // #included from: catch_config.hpp
  993. #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
  994. // #included from: catch_test_spec.h
  995. #define TWOBLUECUBES_CATCH_TEST_SPEC_H_INCLUDED
  996. // #included from: catch_test_case_info.h
  997. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
  998. #include <string>
  999. #include <set>
  1000. namespace Catch {
  1001. struct ITestCase;
  1002. class TestCaseInfo {
  1003. public:
  1004. TestCaseInfo();
  1005. TestCaseInfo( ITestCase* testCase,
  1006. const std::string& className,
  1007. const std::string& name,
  1008. const std::string& description,
  1009. const SourceLineInfo& lineInfo );
  1010. TestCaseInfo( const TestCaseInfo& other, const std::string& name );
  1011. TestCaseInfo( const TestCaseInfo& other );
  1012. void invoke() const;
  1013. const std::string& getClassName() const;
  1014. const std::string& getName() const;
  1015. const std::string& getDescription() const;
  1016. const SourceLineInfo& getLineInfo() const;
  1017. bool isHidden() const;
  1018. bool hasTag( const std::string& tag ) const;
  1019. bool matchesTags( const std::string& tagPattern ) const;
  1020. const std::set<std::string>& getTags() const;
  1021. void swap( TestCaseInfo& other );
  1022. bool operator == ( const TestCaseInfo& other ) const;
  1023. bool operator < ( const TestCaseInfo& other ) const;
  1024. TestCaseInfo& operator = ( const TestCaseInfo& other );
  1025. private:
  1026. Ptr<ITestCase> m_test;
  1027. std::string m_className;
  1028. std::string m_name;
  1029. std::string m_description;
  1030. std::set<std::string> m_tags;
  1031. SourceLineInfo m_lineInfo;
  1032. bool m_isHidden;
  1033. };
  1034. }
  1035. // #included from: catch_tags.hpp
  1036. #define TWOBLUECUBES_CATCH_TAGS_HPP_INCLUDED
  1037. #include <string>
  1038. #include <set>
  1039. #include <map>
  1040. #include <vector>
  1041. #ifdef __clang__
  1042. #pragma clang diagnostic ignored "-Wpadded"
  1043. #endif
  1044. namespace Catch {
  1045. class TagParser {
  1046. public:
  1047. virtual ~TagParser();
  1048. void parse( const std::string& str ) {
  1049. std::size_t pos = 0;
  1050. while( pos < str.size() ) {
  1051. char c = str[pos];
  1052. if( c == '[' ) {
  1053. std::size_t end = str.find_first_of( ']', pos );
  1054. if( end != std::string::npos ) {
  1055. acceptTag( str.substr( pos+1, end-pos-1 ) );
  1056. pos = end+1;
  1057. }
  1058. else {
  1059. acceptChar( c );
  1060. pos++;
  1061. }
  1062. }
  1063. else {
  1064. acceptChar( c );
  1065. pos++;
  1066. }
  1067. }
  1068. endParse();
  1069. }
  1070. protected:
  1071. virtual void acceptTag( const std::string& tag ) = 0;
  1072. virtual void acceptChar( char c ) = 0;
  1073. virtual void endParse() {}
  1074. private:
  1075. };
  1076. class TagExtracter : public TagParser {
  1077. public:
  1078. TagExtracter( std::set<std::string>& tags )
  1079. : m_tags( tags )
  1080. {}
  1081. virtual ~TagExtracter();
  1082. void parse( std::string& description ) {
  1083. TagParser::parse( description );
  1084. description = m_remainder;
  1085. }
  1086. private:
  1087. virtual void acceptTag( const std::string& tag ) {
  1088. m_tags.insert( tag );
  1089. }
  1090. virtual void acceptChar( char c ) {
  1091. m_remainder += c;
  1092. }
  1093. TagExtracter& operator=(const TagExtracter&);
  1094. std::set<std::string>& m_tags;
  1095. std::string m_remainder;
  1096. };
  1097. class Tag {
  1098. public:
  1099. Tag()
  1100. : m_isNegated( false )
  1101. {}
  1102. Tag( const std::string& name, bool isNegated )
  1103. : m_name( name ),
  1104. m_isNegated( isNegated )
  1105. {}
  1106. std::string getName() const {
  1107. return m_name;
  1108. }
  1109. bool isNegated() const {
  1110. return m_isNegated;
  1111. }
  1112. bool operator ! () const {
  1113. return m_name.empty();
  1114. }
  1115. private:
  1116. std::string m_name;
  1117. bool m_isNegated;
  1118. };
  1119. class TagSet {
  1120. typedef std::map<std::string, Tag> TagMap;
  1121. public:
  1122. void add( const Tag& tag ) {
  1123. m_tags.insert( std::make_pair( tag.getName(), tag ) );
  1124. }
  1125. bool empty() const {
  1126. return m_tags.empty();
  1127. }
  1128. bool matches( const std::set<std::string>& tags ) const {
  1129. TagMap::const_iterator it = m_tags.begin();
  1130. TagMap::const_iterator itEnd = m_tags.end();
  1131. for(; it != itEnd; ++it ) {
  1132. bool found = tags.find( it->first ) != tags.end();
  1133. if( found == it->second.isNegated() )
  1134. return false;
  1135. }
  1136. return true;
  1137. }
  1138. private:
  1139. TagMap m_tags;
  1140. };
  1141. class TagExpression {
  1142. public:
  1143. bool matches( const std::set<std::string>& tags ) const {
  1144. std::vector<TagSet>::const_iterator it = m_tagSets.begin();
  1145. std::vector<TagSet>::const_iterator itEnd = m_tagSets.end();
  1146. for(; it != itEnd; ++it )
  1147. if( it->matches( tags ) )
  1148. return true;
  1149. return false;
  1150. }
  1151. private:
  1152. friend class TagExpressionParser;
  1153. std::vector<TagSet> m_tagSets;
  1154. };
  1155. class TagExpressionParser : public TagParser {
  1156. public:
  1157. TagExpressionParser( TagExpression& exp )
  1158. : m_isNegated( false ),
  1159. m_exp( exp )
  1160. {}
  1161. ~TagExpressionParser();
  1162. private:
  1163. virtual void acceptTag( const std::string& tag ) {
  1164. m_currentTagSet.add( Tag( tag, m_isNegated ) );
  1165. m_isNegated = false;
  1166. }
  1167. virtual void acceptChar( char c ) {
  1168. switch( c ) {
  1169. case '~':
  1170. m_isNegated = true;
  1171. break;
  1172. case ',':
  1173. m_exp.m_tagSets.push_back( m_currentTagSet );
  1174. break;
  1175. }
  1176. }
  1177. virtual void endParse() {
  1178. if( !m_currentTagSet.empty() )
  1179. m_exp.m_tagSets.push_back( m_currentTagSet );
  1180. }
  1181. TagExpressionParser& operator=(const TagExpressionParser&);
  1182. bool m_isNegated;
  1183. TagSet m_currentTagSet;
  1184. TagExpression& m_exp;
  1185. };
  1186. } // end namespace Catch
  1187. #include <string>
  1188. #include <vector>
  1189. namespace Catch {
  1190. struct IfFilterMatches{ enum DoWhat {
  1191. AutoDetectBehaviour,
  1192. IncludeTests,
  1193. ExcludeTests
  1194. }; };
  1195. class TestCaseFilter {
  1196. enum WildcardPosition {
  1197. NoWildcard = 0,
  1198. WildcardAtStart = 1,
  1199. WildcardAtEnd = 2,
  1200. WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
  1201. };
  1202. public:
  1203. TestCaseFilter( const std::string& testSpec, IfFilterMatches::DoWhat matchBehaviour = IfFilterMatches::AutoDetectBehaviour )
  1204. : m_stringToMatch( testSpec ),
  1205. m_filterType( matchBehaviour ),
  1206. m_wildcardPosition( NoWildcard )
  1207. {
  1208. if( m_filterType == IfFilterMatches::AutoDetectBehaviour ) {
  1209. if( startsWith( m_stringToMatch, "exclude:" ) ) {
  1210. m_stringToMatch = m_stringToMatch.substr( 8 );
  1211. m_filterType = IfFilterMatches::ExcludeTests;
  1212. }
  1213. else if( startsWith( m_stringToMatch, "~" ) ) {
  1214. m_stringToMatch = m_stringToMatch.substr( 1 );
  1215. m_filterType = IfFilterMatches::ExcludeTests;
  1216. }
  1217. else {
  1218. m_filterType = IfFilterMatches::IncludeTests;
  1219. }
  1220. }
  1221. if( m_stringToMatch[0] == '*' ) {
  1222. m_stringToMatch = m_stringToMatch.substr( 1 );
  1223. m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtStart );
  1224. }
  1225. if( m_stringToMatch[m_stringToMatch.size()-1] == '*' ) {
  1226. m_stringToMatch = m_stringToMatch.substr( 0, m_stringToMatch.size()-1 );
  1227. m_wildcardPosition = (WildcardPosition)( m_wildcardPosition | WildcardAtEnd );
  1228. }
  1229. }
  1230. IfFilterMatches::DoWhat getFilterType() const {
  1231. return m_filterType;
  1232. }
  1233. bool shouldInclude( const TestCaseInfo& testCase ) const {
  1234. return isMatch( testCase ) == (m_filterType == IfFilterMatches::IncludeTests);
  1235. }
  1236. private:
  1237. #ifdef __clang__
  1238. #pragma clang diagnostic push
  1239. #pragma clang diagnostic ignored "-Wunreachable-code"
  1240. #endif
  1241. bool isMatch( const TestCaseInfo& testCase ) const {
  1242. const std::string& name = testCase.getName();
  1243. switch( m_wildcardPosition ) {
  1244. case NoWildcard:
  1245. return m_stringToMatch == name;
  1246. case WildcardAtStart:
  1247. return endsWith( name, m_stringToMatch );
  1248. case WildcardAtEnd:
  1249. return startsWith( name, m_stringToMatch );
  1250. case WildcardAtBothEnds:
  1251. return contains( name, m_stringToMatch );
  1252. }
  1253. throw std::logic_error( "Unhandled wildcard type" );
  1254. }
  1255. #ifdef __clang__
  1256. #pragma clang diagnostic pop
  1257. #endif
  1258. std::string m_stringToMatch;
  1259. IfFilterMatches::DoWhat m_filterType;
  1260. WildcardPosition m_wildcardPosition;
  1261. };
  1262. class TestCaseFilters {
  1263. public:
  1264. TestCaseFilters( const std::string& name ) : m_name( name ) {}
  1265. std::string getName() const {
  1266. return m_name;
  1267. }
  1268. void addFilter( const TestCaseFilter& filter ) {
  1269. if( filter.getFilterType() == IfFilterMatches::ExcludeTests )
  1270. m_exclusionFilters.push_back( filter );
  1271. else
  1272. m_inclusionFilters.push_back( filter );
  1273. }
  1274. void addTags( const std::string& tagPattern ) {
  1275. TagExpression exp;
  1276. TagExpressionParser( exp ).parse( tagPattern );
  1277. m_tagExpressions.push_back( exp );
  1278. }
  1279. bool shouldInclude( const TestCaseInfo& testCase ) const {
  1280. if( !m_tagExpressions.empty() ) {
  1281. std::vector<TagExpression>::const_iterator it = m_tagExpressions.begin();
  1282. std::vector<TagExpression>::const_iterator itEnd = m_tagExpressions.end();
  1283. for(; it != itEnd; ++it )
  1284. if( it->matches( testCase.getTags() ) )
  1285. break;
  1286. if( it == itEnd )
  1287. return false;
  1288. }
  1289. if( !m_inclusionFilters.empty() ) {
  1290. std::vector<TestCaseFilter>::const_iterator it = m_inclusionFilters.begin();
  1291. std::vector<TestCaseFilter>::const_iterator itEnd = m_inclusionFilters.end();
  1292. for(; it != itEnd; ++it )
  1293. if( it->shouldInclude( testCase ) )
  1294. break;
  1295. if( it == itEnd )
  1296. return false;
  1297. }
  1298. else if( m_exclusionFilters.empty() && m_tagExpressions.empty() ) {
  1299. return !testCase.isHidden();
  1300. }
  1301. std::vector<TestCaseFilter>::const_iterator it = m_exclusionFilters.begin();
  1302. std::vector<TestCaseFilter>::const_iterator itEnd = m_exclusionFilters.end();
  1303. for(; it != itEnd; ++it )
  1304. if( !it->shouldInclude( testCase ) )
  1305. return false;
  1306. return true;
  1307. }
  1308. private:
  1309. std::vector<TagExpression> m_tagExpressions;
  1310. std::vector<TestCaseFilter> m_inclusionFilters;
  1311. std::vector<TestCaseFilter> m_exclusionFilters;
  1312. std::string m_name;
  1313. };
  1314. }
  1315. // #included from: catch_interfaces_config.h
  1316. #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
  1317. namespace Catch {
  1318. struct IConfig {
  1319. virtual ~IConfig();
  1320. virtual bool allowThrows() const = 0;
  1321. };
  1322. }
  1323. // #included from: catch_stream.hpp
  1324. #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
  1325. // #included from: catch_streambuf.h
  1326. #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
  1327. #include <streambuf>
  1328. namespace Catch {
  1329. class StreamBufBase : public std::streambuf {
  1330. public:
  1331. virtual ~StreamBufBase();
  1332. };
  1333. }
  1334. #include <stdexcept>
  1335. #include <cstdio>
  1336. namespace Catch {
  1337. template<typename WriterF, size_t bufferSize=256>
  1338. class StreamBufImpl : public StreamBufBase {
  1339. char data[bufferSize];
  1340. WriterF m_writer;
  1341. public:
  1342. StreamBufImpl() {
  1343. setp( data, data + sizeof(data) );
  1344. }
  1345. ~StreamBufImpl() {
  1346. sync();
  1347. }
  1348. private:
  1349. int overflow( int c ) {
  1350. sync();
  1351. if( c != EOF ) {
  1352. if( pbase() == epptr() )
  1353. m_writer( std::string( 1, static_cast<char>( c ) ) );
  1354. else
  1355. sputc( static_cast<char>( c ) );
  1356. }
  1357. return 0;
  1358. }
  1359. int sync() {
  1360. if( pbase() != pptr() ) {
  1361. m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
  1362. setp( pbase(), epptr() );
  1363. }
  1364. return 0;
  1365. }
  1366. };
  1367. ///////////////////////////////////////////////////////////////////////////
  1368. struct OutputDebugWriter {
  1369. void operator()( const std::string &str ) {
  1370. writeToDebugConsole( str );
  1371. }
  1372. };
  1373. class Stream {
  1374. public:
  1375. Stream()
  1376. : streamBuf( NULL ), isOwned( false )
  1377. {}
  1378. Stream( std::streambuf* _streamBuf, bool _isOwned )
  1379. : streamBuf( _streamBuf ), isOwned( _isOwned )
  1380. {}
  1381. void release() {
  1382. if( isOwned ) {
  1383. delete streamBuf;
  1384. streamBuf = NULL;
  1385. isOwned = false;
  1386. }
  1387. }
  1388. std::streambuf* streamBuf;
  1389. private:
  1390. bool isOwned;
  1391. };
  1392. }
  1393. #include <memory>
  1394. #include <vector>
  1395. #include <string>
  1396. #include <iostream>
  1397. namespace Catch {
  1398. struct Include { enum WhichResults {
  1399. FailedOnly,
  1400. SuccessfulResults
  1401. }; };
  1402. struct List{ enum What {
  1403. None = 0,
  1404. Reports = 1,
  1405. Tests = 2,
  1406. All = 3,
  1407. TestNames = 6,
  1408. WhatMask = 0xf,
  1409. AsText = 0x10,
  1410. AsXml = 0x20,
  1411. AsMask = 0xf0
  1412. }; };
  1413. struct ConfigData {
  1414. struct WarnAbout { enum What {
  1415. Nothing = 0x00,
  1416. NoAssertions = 0x01
  1417. }; };
  1418. ConfigData()
  1419. : listSpec( List::None ),
  1420. shouldDebugBreak( false ),
  1421. includeWhichResults( Include::FailedOnly ),
  1422. cutoff( -1 ),
  1423. allowThrows( true ),
  1424. warnings( WarnAbout::Nothing )
  1425. {}
  1426. std::string reporter;
  1427. std::string outputFilename;
  1428. List::What listSpec;
  1429. std::vector<TestCaseFilters> filters;
  1430. bool shouldDebugBreak;
  1431. std::string stream;
  1432. Include::WhichResults includeWhichResults;
  1433. std::string name;
  1434. int cutoff;
  1435. bool allowThrows;
  1436. WarnAbout::What warnings;
  1437. };
  1438. class Config : public IConfig {
  1439. private:
  1440. Config( const Config& other );
  1441. Config& operator = ( const Config& other );
  1442. virtual void dummy();
  1443. public:
  1444. Config()
  1445. : m_os( std::cout.rdbuf() )
  1446. {}
  1447. Config( const ConfigData& data )
  1448. : m_data( data ),
  1449. m_os( std::cout.rdbuf() )
  1450. {}
  1451. virtual ~Config() {
  1452. m_os.rdbuf( std::cout.rdbuf() );
  1453. m_stream.release();
  1454. }
  1455. void setFilename( const std::string& filename ) {
  1456. m_data.outputFilename = filename;
  1457. }
  1458. List::What getListSpec( void ) const {
  1459. return m_data.listSpec;
  1460. }
  1461. const std::string& getFilename() const {
  1462. return m_data.outputFilename ;
  1463. }
  1464. List::What listWhat() const {
  1465. return static_cast<List::What>( m_data.listSpec & List::WhatMask );
  1466. }
  1467. List::What listAs() const {
  1468. return static_cast<List::What>( m_data.listSpec & List::AsMask );
  1469. }
  1470. std::string getName() const {
  1471. return m_data.name;
  1472. }
  1473. bool shouldDebugBreak() const {
  1474. return m_data.shouldDebugBreak;
  1475. }
  1476. virtual std::ostream& stream() const {
  1477. return m_os;
  1478. }
  1479. void setStreamBuf( std::streambuf* buf ) {
  1480. m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
  1481. }
  1482. void useStream( const std::string& streamName ) {
  1483. Stream stream = createStream( streamName );
  1484. setStreamBuf( stream.streamBuf );
  1485. m_stream.release();
  1486. m_stream = stream;
  1487. }
  1488. void addTestSpec( const std::string& testSpec ) {
  1489. TestCaseFilters filters( testSpec );
  1490. filters.addFilter( TestCaseFilter( testSpec ) );
  1491. m_data.filters.push_back( filters );
  1492. }
  1493. virtual bool includeSuccessfulResults() const {
  1494. return m_data.includeWhichResults == Include::SuccessfulResults;
  1495. }
  1496. int getCutoff() const {
  1497. return m_data.cutoff;
  1498. }
  1499. virtual bool allowThrows() const {
  1500. return m_data.allowThrows;
  1501. }
  1502. const ConfigData& data() const {
  1503. return m_data;
  1504. }
  1505. ConfigData& data() {
  1506. return m_data;
  1507. }
  1508. private:
  1509. ConfigData m_data;
  1510. // !TBD Move these out of here
  1511. Stream m_stream;
  1512. mutable std::ostream m_os;
  1513. };
  1514. } // end namespace Catch
  1515. #include <string>
  1516. #include <ostream>
  1517. #include <map>
  1518. namespace Catch
  1519. {
  1520. struct ReporterConfig
  1521. {
  1522. ReporterConfig( const std::string& _name,
  1523. std::ostream& _stream,
  1524. bool _includeSuccessfulResults,
  1525. const ConfigData& _fullConfig )
  1526. : name( _name ),
  1527. stream( _stream ),
  1528. includeSuccessfulResults( _includeSuccessfulResults ),
  1529. fullConfig( _fullConfig )
  1530. {}
  1531. ReporterConfig( const ReporterConfig& other )
  1532. : name( other.name ),
  1533. stream( other.stream ),
  1534. includeSuccessfulResults( other.includeSuccessfulResults ),
  1535. fullConfig( other.fullConfig )
  1536. {}
  1537. std::string name;
  1538. std::ostream& stream;
  1539. bool includeSuccessfulResults;
  1540. ConfigData fullConfig;
  1541. private:
  1542. void operator=(const ReporterConfig&);
  1543. };
  1544. class TestCaseInfo;
  1545. class AssertionResult;
  1546. struct IReporter : IShared {
  1547. virtual ~IReporter();
  1548. virtual bool shouldRedirectStdout() const = 0;
  1549. virtual void StartTesting() = 0;
  1550. virtual void EndTesting( const Totals& totals ) = 0;
  1551. virtual void StartGroup( const std::string& groupName ) = 0;
  1552. virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
  1553. virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
  1554. // TestCaseResult
  1555. virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
  1556. // SectionInfo
  1557. virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
  1558. // Section Result
  1559. virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
  1560. // - merge into SectionResult ?
  1561. virtual void NoAssertionsInSection( const std::string& sectionName ) = 0;
  1562. virtual void NoAssertionsInTestCase( const std::string& testName ) = 0;
  1563. // - merge into SectionResult, TestCaseResult, GroupResult & TestRunResult
  1564. virtual void Aborted() = 0;
  1565. // AssertionReslt
  1566. virtual void Result( const AssertionResult& result ) = 0;
  1567. };
  1568. struct IReporterFactory {
  1569. virtual ~IReporterFactory();
  1570. virtual IReporter* create( const ReporterConfig& config ) const = 0;
  1571. virtual std::string getDescription() const = 0;
  1572. };
  1573. struct IReporterRegistry {
  1574. typedef std::map<std::string, IReporterFactory*> FactoryMap;
  1575. virtual ~IReporterRegistry();
  1576. virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0;
  1577. virtual const FactoryMap& getFactories() const = 0;
  1578. };
  1579. inline std::string trim( const std::string& str ) {
  1580. std::string::size_type start = str.find_first_not_of( "\n\r\t " );
  1581. std::string::size_type end = str.find_last_not_of( "\n\r\t " );
  1582. return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
  1583. }
  1584. }
  1585. #include <vector>
  1586. namespace Catch {
  1587. class TestCaseInfo;
  1588. struct ITestCaseRegistry;
  1589. struct IExceptionTranslatorRegistry;
  1590. struct IExceptionTranslator;
  1591. struct IRegistryHub {
  1592. virtual ~IRegistryHub();
  1593. virtual const IReporterRegistry& getReporterRegistry() const = 0;
  1594. virtual const ITestCaseRegistry& getTestCaseRegistry() const = 0;
  1595. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
  1596. };
  1597. struct IMutableRegistryHub {
  1598. virtual ~IMutableRegistryHub();
  1599. virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0;
  1600. virtual void registerTest( const TestCaseInfo& testInfo ) = 0;
  1601. virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
  1602. };
  1603. IRegistryHub& getRegistryHub();
  1604. IMutableRegistryHub& getMutableRegistryHub();
  1605. void cleanUp();
  1606. std::string translateActiveException();
  1607. }
  1608. #include <ostream>
  1609. namespace Catch {
  1610. inline IResultCapture& getResultCapture() {
  1611. return getCurrentContext().getResultCapture();
  1612. }
  1613. template<typename MatcherT>
  1614. ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
  1615. const std::string& matcherCallAsString ) {
  1616. std::string matcherAsString = matcher.toString();
  1617. if( matcherAsString == "{?}" )
  1618. matcherAsString = matcherCallAsString;
  1619. return ExpressionResultBuilder()
  1620. .setRhs( matcherAsString )
  1621. .setOp( "matches" );
  1622. }
  1623. template<typename MatcherT, typename ArgT>
  1624. ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
  1625. const ArgT& arg,
  1626. const std::string& matcherCallAsString ) {
  1627. return expressionResultBuilderFromMatcher( matcher, matcherCallAsString )
  1628. .setLhs( Catch::toString( arg ) )
  1629. .setResultType( matcher.match( arg ) );
  1630. }
  1631. template<typename MatcherT, typename ArgT>
  1632. ExpressionResultBuilder expressionResultBuilderFromMatcher( const MatcherT& matcher,
  1633. ArgT* arg,
  1634. const std::string& matcherCallAsString ) {
  1635. return expressionResultBuilderFromMatcher( matcher, matcherCallAsString )
  1636. .setLhs( Catch::toString( arg ) )
  1637. .setResultType( matcher.match( arg ) );
  1638. }
  1639. struct TestFailureException{};
  1640. class ScopedInfo {
  1641. public:
  1642. ScopedInfo() : m_resultBuilder( ResultWas::Info ) {
  1643. getResultCapture().pushScopedInfo( this );
  1644. }
  1645. ~ScopedInfo() {
  1646. getResultCapture().popScopedInfo( this );
  1647. }
  1648. template<typename T>
  1649. ScopedInfo& operator << ( const T& value ) {
  1650. m_resultBuilder << value;
  1651. return *this;
  1652. }
  1653. AssertionResult buildResult( const AssertionInfo& assertionInfo ) const {
  1654. return m_resultBuilder.buildResult( assertionInfo );
  1655. }
  1656. private:
  1657. ExpressionResultBuilder m_resultBuilder;
  1658. };
  1659. // This is just here to avoid compiler warnings with macro constants and boolean literals
  1660. inline bool isTrue( bool value ){ return value; }
  1661. } // end namespace Catch
  1662. ///////////////////////////////////////////////////////////////////////////////
  1663. #define INTERNAL_CATCH_ASSERTIONINFO_NAME INTERNAL_CATCH_UNIQUE_NAME( __assertionInfo )
  1664. ///////////////////////////////////////////////////////////////////////////////
  1665. #define INTERNAL_CATCH_ACCEPT_EXPR( evaluatedExpr, resultDisposition, originalExpr ) \
  1666. if( Catch::ResultAction::Value internal_catch_action = Catch::getResultCapture().acceptExpression( evaluatedExpr, INTERNAL_CATCH_ASSERTIONINFO_NAME ) ) { \
  1667. if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
  1668. if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
  1669. if( !Catch::shouldContinueOnFailure( resultDisposition ) ) throw Catch::TestFailureException(); \
  1670. if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \
  1671. }
  1672. ///////////////////////////////////////////////////////////////////////////////
  1673. #define INTERNAL_CATCH_ACCEPT_INFO( expr, macroName, resultDisposition ) \
  1674. Catch::AssertionInfo INTERNAL_CATCH_ASSERTIONINFO_NAME( macroName, CATCH_INTERNAL_LINEINFO, expr, resultDisposition );
  1675. ///////////////////////////////////////////////////////////////////////////////
  1676. #define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
  1677. do { \
  1678. INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, resultDisposition ); \
  1679. try { \
  1680. INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionDecomposer()->*expr ).endExpression( resultDisposition ), resultDisposition, expr ); \
  1681. } catch( Catch::TestFailureException& ) { \
  1682. throw; \
  1683. } catch( ... ) { \
  1684. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), \
  1685. resultDisposition | Catch::ResultDisposition::ContinueOnFailure, expr ); \
  1686. throw; \
  1687. } \
  1688. } while( Catch::isTrue( false ) )
  1689. ///////////////////////////////////////////////////////////////////////////////
  1690. #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
  1691. INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
  1692. if( Catch::getResultCapture().getLastResult()->succeeded() )
  1693. ///////////////////////////////////////////////////////////////////////////////
  1694. #define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
  1695. INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
  1696. if( !Catch::getResultCapture().getLastResult()->succeeded() )
  1697. ///////////////////////////////////////////////////////////////////////////////
  1698. #define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
  1699. do { \
  1700. INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, resultDisposition ); \
  1701. try { \
  1702. expr; \
  1703. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), resultDisposition, false ); \
  1704. } \
  1705. catch( ... ) { \
  1706. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException(), resultDisposition, false ); \
  1707. } \
  1708. } while( Catch::isTrue( false ) )
  1709. ///////////////////////////////////////////////////////////////////////////////
  1710. #define INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, resultDisposition ) \
  1711. try { \
  1712. if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \
  1713. expr; \
  1714. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::DidntThrowException ), resultDisposition, false ); \
  1715. } \
  1716. } \
  1717. catch( Catch::TestFailureException& ) { \
  1718. throw; \
  1719. } \
  1720. catch( exceptionType ) { \
  1721. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( Catch::ResultWas::Ok ), resultDisposition, false ); \
  1722. }
  1723. ///////////////////////////////////////////////////////////////////////////////
  1724. #define INTERNAL_CATCH_THROWS( expr, exceptionType, resultDisposition, macroName ) \
  1725. do { \
  1726. INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, resultDisposition ); \
  1727. INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, resultDisposition ) \
  1728. } while( Catch::isTrue( false ) )
  1729. ///////////////////////////////////////////////////////////////////////////////
  1730. #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
  1731. do { \
  1732. INTERNAL_CATCH_ACCEPT_INFO( #expr, macroName, resultDisposition ); \
  1733. INTERNAL_CATCH_THROWS_IMPL( expr, exceptionType, resultDisposition ) \
  1734. catch( ... ) { \
  1735. INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \
  1736. resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \
  1737. } \
  1738. } while( Catch::isTrue( false ) )
  1739. ///////////////////////////////////////////////////////////////////////////////
  1740. #define INTERNAL_CATCH_MSG( reason, resultType, resultDisposition, macroName ) \
  1741. do { \
  1742. INTERNAL_CATCH_ACCEPT_INFO( "", macroName, resultDisposition ); \
  1743. INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionResultBuilder( resultType ) << reason, resultDisposition, true ) \
  1744. } while( Catch::isTrue( false ) )
  1745. ///////////////////////////////////////////////////////////////////////////////
  1746. #define INTERNAL_CATCH_SCOPED_INFO( log, macroName ) \
  1747. INTERNAL_CATCH_ACCEPT_INFO( "", macroName, Catch::ResultDisposition::Normal ); \
  1748. Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \
  1749. INTERNAL_CATCH_UNIQUE_NAME( info ) << log
  1750. ///////////////////////////////////////////////////////////////////////////////
  1751. #define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \
  1752. do { \
  1753. INTERNAL_CATCH_ACCEPT_INFO( #arg " " #matcher, macroName, resultDisposition ); \
  1754. try { \
  1755. INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::expressionResultBuilderFromMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), resultDisposition, false ); \
  1756. } catch( Catch::TestFailureException& ) { \
  1757. throw; \
  1758. } catch( ... ) { \
  1759. INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionResultBuilder( Catch::ResultWas::ThrewException ) << Catch::translateActiveException() ), \
  1760. resultDisposition | Catch::ResultDisposition::ContinueOnFailure, false ); \
  1761. throw; \
  1762. } \
  1763. } while( Catch::isTrue( false ) )
  1764. // #included from: internal/catch_section.hpp
  1765. #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
  1766. #include <string>
  1767. namespace Catch {
  1768. class Section {
  1769. public:
  1770. Section( const std::string& name,
  1771. const std::string& description,
  1772. const SourceLineInfo& lineInfo )
  1773. : m_name( name ),
  1774. m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
  1775. {}
  1776. ~Section() {
  1777. if( m_sectionIncluded )
  1778. getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions );
  1779. }
  1780. // This indicates whether the section should be executed or not
  1781. operator bool() {
  1782. return m_sectionIncluded;
  1783. }
  1784. private:
  1785. std::string m_name;
  1786. Counts m_assertions;
  1787. bool m_sectionIncluded;
  1788. };
  1789. } // end namespace Catch
  1790. #define INTERNAL_CATCH_SECTION( name, desc ) \
  1791. if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, CATCH_INTERNAL_LINEINFO ) )
  1792. // #included from: internal/catch_generators.hpp
  1793. #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
  1794. #include <iterator>
  1795. #include <vector>
  1796. #include <string>
  1797. #include <stdlib.h>
  1798. namespace Catch {
  1799. template<typename T>
  1800. struct IGenerator {
  1801. virtual ~IGenerator() {}
  1802. virtual T getValue( std::size_t index ) const = 0;
  1803. virtual std::size_t size () const = 0;
  1804. };
  1805. template<typename T>
  1806. class BetweenGenerator : public IGenerator<T> {
  1807. public:
  1808. BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
  1809. virtual T getValue( std::size_t index ) const {
  1810. return m_from+static_cast<T>( index );
  1811. }
  1812. virtual std::size_t size() const {
  1813. return static_cast<std::size_t>( 1+m_to-m_from );
  1814. }
  1815. private:
  1816. T m_from;
  1817. T m_to;
  1818. };
  1819. template<typename T>
  1820. class ValuesGenerator : public IGenerator<T> {
  1821. public:
  1822. ValuesGenerator(){}
  1823. void add( T value ) {
  1824. m_values.push_back( value );
  1825. }
  1826. virtual T getValue( std::size_t index ) const {
  1827. return m_values[index];
  1828. }
  1829. virtual std::size_t size() const {
  1830. return m_values.size();
  1831. }
  1832. private:
  1833. std::vector<T> m_values;
  1834. };
  1835. template<typename T>
  1836. class CompositeGenerator {
  1837. public:
  1838. CompositeGenerator() : m_totalSize( 0 ) {}
  1839. // *** Move semantics, similar to auto_ptr ***
  1840. CompositeGenerator( CompositeGenerator& other )
  1841. : m_fileInfo( other.m_fileInfo ),
  1842. m_totalSize( 0 )
  1843. {
  1844. move( other );
  1845. }
  1846. CompositeGenerator& setFileInfo( const char* fileInfo ) {
  1847. m_fileInfo = fileInfo;
  1848. return *this;
  1849. }
  1850. ~CompositeGenerator() {
  1851. deleteAll( m_composed );
  1852. }
  1853. operator T () const {
  1854. size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
  1855. typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
  1856. typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
  1857. for( size_t index = 0; it != itEnd; ++it )
  1858. {
  1859. const IGenerator<T>* generator = *it;
  1860. if( overallIndex >= index && overallIndex < index + generator->size() )
  1861. {
  1862. return generator->getValue( overallIndex-index );
  1863. }
  1864. index += generator->size();
  1865. }
  1866. CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
  1867. 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
  1868. }
  1869. void add( const IGenerator<T>* generator ) {
  1870. m_totalSize += generator->size();
  1871. m_composed.push_back( generator );
  1872. }
  1873. CompositeGenerator& then( CompositeGenerator& other ) {
  1874. move( other );
  1875. return *this;
  1876. }
  1877. CompositeGenerator& then( T value ) {
  1878. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  1879. valuesGen->add( value );
  1880. add( valuesGen );
  1881. return *this;
  1882. }
  1883. private:
  1884. void move( CompositeGenerator& other ) {
  1885. std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
  1886. m_totalSize += other.m_totalSize;
  1887. other.m_composed.clear();
  1888. }
  1889. std::vector<const IGenerator<T>*> m_composed;
  1890. std::string m_fileInfo;
  1891. size_t m_totalSize;
  1892. };
  1893. namespace Generators
  1894. {
  1895. template<typename T>
  1896. CompositeGenerator<T> between( T from, T to ) {
  1897. CompositeGenerator<T> generators;
  1898. generators.add( new BetweenGenerator<T>( from, to ) );
  1899. return generators;
  1900. }
  1901. template<typename T>
  1902. CompositeGenerator<T> values( T val1, T val2 ) {
  1903. CompositeGenerator<T> generators;
  1904. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  1905. valuesGen->add( val1 );
  1906. valuesGen->add( val2 );
  1907. generators.add( valuesGen );
  1908. return generators;
  1909. }
  1910. template<typename T>
  1911. CompositeGenerator<T> values( T val1, T val2, T val3 ){
  1912. CompositeGenerator<T> generators;
  1913. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  1914. valuesGen->add( val1 );
  1915. valuesGen->add( val2 );
  1916. valuesGen->add( val3 );
  1917. generators.add( valuesGen );
  1918. return generators;
  1919. }
  1920. template<typename T>
  1921. CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
  1922. CompositeGenerator<T> generators;
  1923. ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
  1924. valuesGen->add( val1 );
  1925. valuesGen->add( val2 );
  1926. valuesGen->add( val3 );
  1927. valuesGen->add( val4 );
  1928. generators.add( valuesGen );
  1929. return generators;
  1930. }
  1931. } // end namespace Generators
  1932. using namespace Generators;
  1933. } // end namespace Catch
  1934. #define INTERNAL_CATCH_LINESTR2( line ) #line
  1935. #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
  1936. #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
  1937. // #included from: internal/catch_interfaces_exception.h
  1938. #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
  1939. #include <string>
  1940. namespace Catch {
  1941. typedef std::string(*exceptionTranslateFunction)();
  1942. struct IExceptionTranslator {
  1943. virtual ~IExceptionTranslator();
  1944. virtual std::string translate() const = 0;
  1945. };
  1946. struct IExceptionTranslatorRegistry {
  1947. virtual ~IExceptionTranslatorRegistry();
  1948. virtual std::string translateActiveException() const = 0;
  1949. };
  1950. class ExceptionTranslatorRegistrar {
  1951. template<typename T>
  1952. class ExceptionTranslator : public IExceptionTranslator {
  1953. public:
  1954. ExceptionTranslator( std::string(*translateFunction)( T& ) )
  1955. : m_translateFunction( translateFunction )
  1956. {}
  1957. virtual std::string translate() const {
  1958. try {
  1959. throw;
  1960. }
  1961. catch( T& ex ) {
  1962. return m_translateFunction( ex );
  1963. }
  1964. }
  1965. protected:
  1966. std::string(*m_translateFunction)( T& );
  1967. };
  1968. public:
  1969. template<typename T>
  1970. ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
  1971. getMutableRegistryHub().registerTranslator
  1972. ( new ExceptionTranslator<T>( translateFunction ) );
  1973. }
  1974. };
  1975. }
  1976. ///////////////////////////////////////////////////////////////////////////////
  1977. #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) \
  1978. static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \
  1979. namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\
  1980. static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature )
  1981. // #included from: internal/catch_approx.hpp
  1982. #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
  1983. #include <cmath>
  1984. #include <limits>
  1985. namespace Catch {
  1986. namespace Detail {
  1987. class Approx {
  1988. public:
  1989. explicit Approx ( double value )
  1990. : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
  1991. m_scale( 1.0 ),
  1992. m_value( value )
  1993. {}
  1994. Approx( const Approx& other )
  1995. : m_epsilon( other.m_epsilon ),
  1996. m_scale( other.m_scale ),
  1997. m_value( other.m_value )
  1998. {}
  1999. static Approx custom() {
  2000. return Approx( 0 );
  2001. }
  2002. Approx operator()( double value ) {
  2003. Approx approx( value );
  2004. approx.epsilon( m_epsilon );
  2005. approx.scale( m_scale );
  2006. return approx;
  2007. }
  2008. friend bool operator == ( double lhs, const Approx& rhs ) {
  2009. // Thanks to Richard Harris for his help refining this formula
  2010. return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
  2011. }
  2012. friend bool operator == ( const Approx& lhs, double rhs ) {
  2013. return operator==( rhs, lhs );
  2014. }
  2015. friend bool operator != ( double lhs, const Approx& rhs ) {
  2016. return !operator==( lhs, rhs );
  2017. }
  2018. friend bool operator != ( const Approx& lhs, double rhs ) {
  2019. return !operator==( rhs, lhs );
  2020. }
  2021. Approx& epsilon( double newEpsilon ) {
  2022. m_epsilon = newEpsilon;
  2023. return *this;
  2024. }
  2025. Approx& scale( double newScale ) {
  2026. m_scale = newScale;
  2027. return *this;
  2028. }
  2029. std::string toString() const {
  2030. std::ostringstream oss;
  2031. oss << "Approx( " << m_value << " )";
  2032. return oss.str();
  2033. }
  2034. private:
  2035. double m_epsilon;
  2036. double m_scale;
  2037. double m_value;
  2038. };
  2039. }
  2040. template<>
  2041. inline std::string toString<Detail::Approx>( const Detail::Approx& value ) {
  2042. return value.toString();
  2043. }
  2044. } // end namespace Catch
  2045. // #included from: internal/catch_matchers.hpp
  2046. #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
  2047. namespace Catch {
  2048. namespace Matchers {
  2049. namespace Impl {
  2050. template<typename ExpressionT>
  2051. struct Matcher : SharedImpl<IShared>
  2052. {
  2053. typedef ExpressionT ExpressionType;
  2054. virtual ~Matcher() {}
  2055. virtual Ptr<Matcher> clone() const = 0;
  2056. virtual bool match( const ExpressionT& expr ) const = 0;
  2057. virtual std::string toString() const = 0;
  2058. };
  2059. template<typename DerivedT, typename ExpressionT>
  2060. struct MatcherImpl : Matcher<ExpressionT> {
  2061. virtual Ptr<Matcher<ExpressionT> > clone() const {
  2062. return Ptr<Matcher<ExpressionT> >( new DerivedT( static_cast<const DerivedT&>( *this ) ) );
  2063. }
  2064. };
  2065. namespace Generic {
  2066. template<typename ExpressionT>
  2067. class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> {
  2068. public:
  2069. AllOf() {}
  2070. AllOf( const AllOf& other ) : m_matchers( other.m_matchers ) {}
  2071. AllOf& add( const Matcher<ExpressionT>& matcher ) {
  2072. m_matchers.push_back( matcher.clone() );
  2073. return *this;
  2074. }
  2075. virtual bool match( const ExpressionT& expr ) const
  2076. {
  2077. for( std::size_t i = 0; i < m_matchers.size(); ++i )
  2078. if( !m_matchers[i]->match( expr ) )
  2079. return false;
  2080. return true;
  2081. }
  2082. virtual std::string toString() const {
  2083. std::ostringstream oss;
  2084. oss << "( ";
  2085. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  2086. if( i != 0 )
  2087. oss << " and ";
  2088. oss << m_matchers[i]->toString();
  2089. }
  2090. oss << " )";
  2091. return oss.str();
  2092. }
  2093. private:
  2094. std::vector<Ptr<Matcher<ExpressionT> > > m_matchers;
  2095. };
  2096. template<typename ExpressionT>
  2097. class AnyOf : public MatcherImpl<AnyOf<ExpressionT>, ExpressionT> {
  2098. public:
  2099. AnyOf() {}
  2100. AnyOf( const AnyOf& other ) : m_matchers( other.m_matchers ) {}
  2101. AnyOf& add( const Matcher<ExpressionT>& matcher ) {
  2102. m_matchers.push_back( matcher.clone() );
  2103. return *this;
  2104. }
  2105. virtual bool match( const ExpressionT& expr ) const
  2106. {
  2107. for( std::size_t i = 0; i < m_matchers.size(); ++i )
  2108. if( m_matchers[i]->match( expr ) )
  2109. return true;
  2110. return false;
  2111. }
  2112. virtual std::string toString() const {
  2113. std::ostringstream oss;
  2114. oss << "( ";
  2115. for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
  2116. if( i != 0 )
  2117. oss << " or ";
  2118. oss << m_matchers[i]->toString();
  2119. }
  2120. oss << " )";
  2121. return oss.str();
  2122. }
  2123. private:
  2124. std::vector<Ptr<Matcher<ExpressionT> > > m_matchers;
  2125. };
  2126. }
  2127. namespace StdString {
  2128. struct Equals : MatcherImpl<Equals, std::string> {
  2129. Equals( const std::string& str ) : m_str( str ){}
  2130. Equals( const Equals& other ) : m_str( other.m_str ){}
  2131. virtual ~Equals();
  2132. virtual bool match( const std::string& expr ) const {
  2133. return m_str == expr;
  2134. }
  2135. virtual std::string toString() const {
  2136. return "equals: \"" + m_str + "\"";
  2137. }
  2138. std::string m_str;
  2139. };
  2140. struct Contains : MatcherImpl<Contains, std::string> {
  2141. Contains( const std::string& substr ) : m_substr( substr ){}
  2142. Contains( const Contains& other ) : m_substr( other.m_substr ){}
  2143. virtual ~Contains();
  2144. virtual bool match( const std::string& expr ) const {
  2145. return expr.find( m_substr ) != std::string::npos;
  2146. }
  2147. virtual std::string toString() const {
  2148. return "contains: \"" + m_substr + "\"";
  2149. }
  2150. std::string m_substr;
  2151. };
  2152. struct StartsWith : MatcherImpl<StartsWith, std::string> {
  2153. StartsWith( const std::string& substr ) : m_substr( substr ){}
  2154. StartsWith( const StartsWith& other ) : m_substr( other.m_substr ){}
  2155. virtual ~StartsWith();
  2156. virtual bool match( const std::string& expr ) const {
  2157. return expr.find( m_substr ) == 0;
  2158. }
  2159. virtual std::string toString() const {
  2160. return "starts with: \"" + m_substr + "\"";
  2161. }
  2162. std::string m_substr;
  2163. };
  2164. struct EndsWith : MatcherImpl<EndsWith, std::string> {
  2165. EndsWith( const std::string& substr ) : m_substr( substr ){}
  2166. EndsWith( const EndsWith& other ) : m_substr( other.m_substr ){}
  2167. virtual ~EndsWith();
  2168. virtual bool match( const std::string& expr ) const {
  2169. return expr.find( m_substr ) == expr.size() - m_substr.size();
  2170. }
  2171. virtual std::string toString() const {
  2172. return "ends with: \"" + m_substr + "\"";
  2173. }
  2174. std::string m_substr;
  2175. };
  2176. } // namespace StdString
  2177. } // namespace Impl
  2178. // The following functions create the actual matcher objects.
  2179. // This allows the types to be inferred
  2180. template<typename ExpressionT>
  2181. inline Impl::Generic::AllOf<ExpressionT> AllOf( const Impl::Matcher<ExpressionT>& m1,
  2182. const Impl::Matcher<ExpressionT>& m2 ) {
  2183. return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 );
  2184. }
  2185. template<typename ExpressionT>
  2186. inline Impl::Generic::AllOf<ExpressionT> AllOf( const Impl::Matcher<ExpressionT>& m1,
  2187. const Impl::Matcher<ExpressionT>& m2,
  2188. const Impl::Matcher<ExpressionT>& m3 ) {
  2189. return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
  2190. }
  2191. template<typename ExpressionT>
  2192. inline Impl::Generic::AnyOf<ExpressionT> AnyOf( const Impl::Matcher<ExpressionT>& m1,
  2193. const Impl::Matcher<ExpressionT>& m2 ) {
  2194. return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 );
  2195. }
  2196. template<typename ExpressionT>
  2197. inline Impl::Generic::AnyOf<ExpressionT> AnyOf( const Impl::Matcher<ExpressionT>& m1,
  2198. const Impl::Matcher<ExpressionT>& m2,
  2199. const Impl::Matcher<ExpressionT>& m3 ) {
  2200. return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
  2201. }
  2202. inline Impl::StdString::Equals Equals( const std::string& str ){ return Impl::StdString::Equals( str ); }
  2203. inline Impl::StdString::Contains Contains( const std::string& substr ){ return Impl::StdString::Contains( substr ); }
  2204. inline Impl::StdString::StartsWith StartsWith( const std::string& substr ){ return Impl::StdString::StartsWith( substr ); }
  2205. inline Impl::StdString::EndsWith EndsWith( const std::string& substr ){ return Impl::StdString::EndsWith( substr ); }
  2206. } // namespace Matchers
  2207. using namespace Matchers;
  2208. } // namespace Catch
  2209. // These files are included here so the single_include script doesn't put them
  2210. // in the conditionally compiled sections
  2211. // #included from: internal/catch_interfaces_runner.h
  2212. #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
  2213. #include <string>
  2214. namespace Catch {
  2215. class TestCaseInfo;
  2216. struct IRunner {
  2217. virtual ~IRunner();
  2218. };
  2219. }
  2220. #ifdef __OBJC__
  2221. // #included from: internal/catch_objc.hpp
  2222. #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
  2223. #import <objc/runtime.h>
  2224. #include <string>
  2225. // NB. Any general catch headers included here must be included
  2226. // in catch.hpp first to make sure they are included by the single
  2227. // header for non obj-usage
  2228. ///////////////////////////////////////////////////////////////////////////////
  2229. // This protocol is really only here for (self) documenting purposes, since
  2230. // all its methods are optional.
  2231. @protocol OcFixture
  2232. @optional
  2233. -(void) setUp;
  2234. -(void) tearDown;
  2235. @end
  2236. namespace Catch {
  2237. class OcMethod : public SharedImpl<ITestCase> {
  2238. public:
  2239. OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
  2240. virtual void invoke() const {
  2241. id obj = [[m_cls alloc] init];
  2242. performOptionalSelector( obj, @selector(setUp) );
  2243. performOptionalSelector( obj, m_sel );
  2244. performOptionalSelector( obj, @selector(tearDown) );
  2245. arcSafeRelease( obj );
  2246. }
  2247. private:
  2248. virtual ~OcMethod() {}
  2249. Class m_cls;
  2250. SEL m_sel;
  2251. };
  2252. namespace Detail{
  2253. inline bool startsWith( const std::string& str, const std::string& sub ) {
  2254. return str.length() > sub.length() && str.substr( 0, sub.length() ) == sub;
  2255. }
  2256. inline std::string getAnnotation( Class cls,
  2257. const std::string& annotationName,
  2258. const std::string& testCaseName ) {
  2259. NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
  2260. SEL sel = NSSelectorFromString( selStr );
  2261. arcSafeRelease( selStr );
  2262. id value = performOptionalSelector( cls, sel );
  2263. if( value )
  2264. return [(NSString*)value UTF8String];
  2265. return "";
  2266. }
  2267. }
  2268. inline size_t registerTestMethods() {
  2269. size_t noTestMethods = 0;
  2270. int noClasses = objc_getClassList( NULL, 0 );
  2271. Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
  2272. objc_getClassList( classes, noClasses );
  2273. for( int c = 0; c < noClasses; c++ ) {
  2274. Class cls = classes[c];
  2275. {
  2276. u_int count;
  2277. Method* methods = class_copyMethodList( cls, &count );
  2278. for( u_int m = 0; m < count ; m++ ) {
  2279. SEL selector = method_getName(methods[m]);
  2280. std::string methodName = sel_getName(selector);
  2281. if( Detail::startsWith( methodName, "Catch_TestCase_" ) ) {
  2282. std::string testCaseName = methodName.substr( 15 );
  2283. std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
  2284. std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
  2285. const char* className = class_getName( cls );
  2286. getMutableRegistryHub().registerTest( TestCaseInfo( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
  2287. noTestMethods++;
  2288. }
  2289. }
  2290. free(methods);
  2291. }
  2292. }
  2293. return noTestMethods;
  2294. }
  2295. namespace Matchers {
  2296. namespace Impl {
  2297. namespace NSStringMatchers {
  2298. template<typename MatcherT>
  2299. struct StringHolder : MatcherImpl<MatcherT, NSString*>{
  2300. StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
  2301. StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
  2302. StringHolder() {
  2303. arcSafeRelease( m_substr );
  2304. }
  2305. NSString* m_substr;
  2306. };
  2307. struct Equals : StringHolder<Equals> {
  2308. Equals( NSString* substr ) : StringHolder( substr ){}
  2309. virtual bool match( ExpressionType const& str ) const {
  2310. return [str isEqualToString:m_substr];
  2311. }
  2312. virtual std::string toString() const {
  2313. return "equals string: \"" + Catch::toString( m_substr ) + "\"";
  2314. }
  2315. };
  2316. struct Contains : StringHolder<Contains> {
  2317. Contains( NSString* substr ) : StringHolder( substr ){}
  2318. virtual bool match( ExpressionType const& str ) const {
  2319. return [str rangeOfString:m_substr].location != NSNotFound;
  2320. }
  2321. virtual std::string toString() const {
  2322. return "contains string: \"" + Catch::toString( m_substr ) + "\"";
  2323. }
  2324. };
  2325. struct StartsWith : StringHolder<StartsWith> {
  2326. StartsWith( NSString* substr ) : StringHolder( substr ){}
  2327. virtual bool match( ExpressionType const& str ) const {
  2328. return [str rangeOfString:m_substr].location == 0;
  2329. }
  2330. virtual std::string toString() const {
  2331. return "starts with: \"" + Catch::toString( m_substr ) + "\"";
  2332. }
  2333. };
  2334. struct EndsWith : StringHolder<EndsWith> {
  2335. EndsWith( NSString* substr ) : StringHolder( substr ){}
  2336. virtual bool match( ExpressionType const& str ) const {
  2337. return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
  2338. }
  2339. virtual std::string toString() const {
  2340. return "ends with: \"" + Catch::toString( m_substr ) + "\"";
  2341. }
  2342. };
  2343. } // namespace NSStringMatchers
  2344. } // namespace Impl
  2345. inline Impl::NSStringMatchers::Equals
  2346. Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
  2347. inline Impl::NSStringMatchers::Contains
  2348. Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
  2349. inline Impl::NSStringMatchers::StartsWith
  2350. StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
  2351. inline Impl::NSStringMatchers::EndsWith
  2352. EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
  2353. } // namespace Matchers
  2354. using namespace Matchers;
  2355. } // namespace Catch
  2356. ///////////////////////////////////////////////////////////////////////////////
  2357. #define OC_TEST_CASE( name, desc )\
  2358. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
  2359. {\
  2360. return @ name; \
  2361. }\
  2362. +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
  2363. { \
  2364. return @ desc; \
  2365. } \
  2366. -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
  2367. #endif
  2368. #if defined( CATCH_CONFIG_MAIN ) || defined( CATCH_CONFIG_RUNNER )
  2369. // #included from: internal/catch_impl.hpp
  2370. #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
  2371. // Collect all the implementation files together here
  2372. // These are the equivalent of what would usually be cpp files
  2373. #ifdef __clang__
  2374. #pragma clang diagnostic push
  2375. #pragma clang diagnostic ignored "-Wweak-vtables"
  2376. #endif
  2377. // #included from: catch_runner.hpp
  2378. #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
  2379. // #included from: internal/catch_commandline.hpp
  2380. #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
  2381. namespace Catch {
  2382. class Command {
  2383. public:
  2384. Command(){}
  2385. explicit Command( const std::string& name ) : m_name( name ) {
  2386. }
  2387. Command& operator += ( const std::string& arg ) {
  2388. m_args.push_back( arg );
  2389. return *this;
  2390. }
  2391. Command& operator += ( const Command& other ) {
  2392. std::copy( other.m_args.begin(), other.m_args.end(), std::back_inserter( m_args ) );
  2393. if( m_name.empty() )
  2394. m_name = other.m_name;
  2395. return *this;
  2396. }
  2397. Command operator + ( const Command& other ) {
  2398. Command newCommand( *this );
  2399. newCommand += other;
  2400. return newCommand;
  2401. }
  2402. operator SafeBool::type() const {
  2403. return SafeBool::makeSafe( !m_name.empty() || !m_args.empty() );
  2404. }
  2405. std::string name() const { return m_name; }
  2406. std::string operator[]( std::size_t i ) const { return m_args[i]; }
  2407. std::size_t argsCount() const { return m_args.size(); }
  2408. CATCH_ATTRIBUTE_NORETURN
  2409. void raiseError( const std::string& message ) const {
  2410. std::ostringstream oss;
  2411. if( m_name.empty() )
  2412. oss << "Error while parsing " << m_name << ". " << message << ".";
  2413. else
  2414. oss << "Error while parsing arguments. " << message << ".";
  2415. if( m_args.size() > 0 )
  2416. oss << " Arguments were:";
  2417. for( std::size_t i = 0; i < m_args.size(); ++i )
  2418. oss << " " << m_args[i];
  2419. throw std::domain_error( oss.str() );
  2420. }
  2421. private:
  2422. std::string m_name;
  2423. std::vector<std::string> m_args;
  2424. };
  2425. class CommandParser {
  2426. public:
  2427. CommandParser( int argc, char const * const * argv ) : m_argc( static_cast<std::size_t>( argc ) ), m_argv( argv ) {}
  2428. std::string exeName() const {
  2429. return m_argv[0];
  2430. }
  2431. Command find( const std::string& arg1, const std::string& arg2, const std::string& arg3 ) const {
  2432. return find( arg1 ) + find( arg2 ) + find( arg3 );
  2433. }
  2434. Command find( const std::string& shortArg, const std::string& longArg ) const {
  2435. return find( shortArg ) + find( longArg );
  2436. }
  2437. Command find( const std::string& arg ) const {
  2438. if( arg.empty() )
  2439. return getArgs( "", 1 );
  2440. else
  2441. for( std::size_t i = 1; i < m_argc; ++i )
  2442. if( m_argv[i] == arg )
  2443. return getArgs( m_argv[i], i+1 );
  2444. return Command();
  2445. }
  2446. Command getDefaultArgs() const {
  2447. return getArgs( "", 1 );
  2448. }
  2449. private:
  2450. Command getArgs( const std::string& cmdName, std::size_t from ) const {
  2451. Command command( cmdName );
  2452. for( std::size_t i = from; i < m_argc && m_argv[i][0] != '-'; ++i )
  2453. command += m_argv[i];
  2454. return command;
  2455. }
  2456. std::size_t m_argc;
  2457. char const * const * m_argv;
  2458. };
  2459. class OptionParser : public SharedImpl<IShared> {
  2460. public:
  2461. OptionParser( int minArgs = 0, int maxArgs = 0 )
  2462. : m_minArgs( minArgs ), m_maxArgs( maxArgs )
  2463. {}
  2464. virtual ~OptionParser() {}
  2465. Command find( const CommandParser& parser ) const {
  2466. Command cmd;
  2467. for( std::vector<std::string>::const_iterator it = m_optionNames.begin();
  2468. it != m_optionNames.end();
  2469. ++it )
  2470. cmd += parser.find( *it );
  2471. return cmd;
  2472. }
  2473. void validateArgs( const Command& args ) const {
  2474. if( tooFewArgs( args ) || tooManyArgs( args ) ) {
  2475. std::ostringstream oss;
  2476. if( m_maxArgs == -1 )
  2477. oss <<"Expected at least " << pluralise( static_cast<std::size_t>( m_minArgs ), "argument" );
  2478. else if( m_minArgs == m_maxArgs )
  2479. oss <<"Expected " << pluralise( static_cast<std::size_t>( m_minArgs ), "argument" );
  2480. else
  2481. oss <<"Expected between " << m_minArgs << " and " << m_maxArgs << " argument";
  2482. args.raiseError( oss.str() );
  2483. }
  2484. }
  2485. void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
  2486. if( Command cmd = find( parser ) ) {
  2487. validateArgs( cmd );
  2488. parseIntoConfig( cmd, config );
  2489. }
  2490. }
  2491. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) = 0;
  2492. virtual std::string argsSynopsis() const = 0;
  2493. virtual std::string optionSummary() const = 0;
  2494. virtual std::string optionDescription() const { return ""; }
  2495. std::string optionNames() const {
  2496. std::string names;
  2497. for( std::vector<std::string>::const_iterator it = m_optionNames.begin();
  2498. it != m_optionNames.end();
  2499. ++it ) {
  2500. if( !it->empty() ) {
  2501. if( !names.empty() )
  2502. names += ", ";
  2503. names += *it;
  2504. }
  2505. else {
  2506. names = "[" + names;
  2507. }
  2508. }
  2509. if( names[0] == '[' )
  2510. names += "]";
  2511. return names;
  2512. }
  2513. protected:
  2514. bool tooFewArgs( const Command& args ) const {
  2515. return args.argsCount() < static_cast<std::size_t>( m_minArgs );
  2516. }
  2517. bool tooManyArgs( const Command& args ) const {
  2518. return m_maxArgs >= 0 && args.argsCount() > static_cast<std::size_t>( m_maxArgs );
  2519. }
  2520. std::vector<std::string> m_optionNames;
  2521. int m_minArgs;
  2522. int m_maxArgs;
  2523. };
  2524. namespace Options {
  2525. class HelpOptionParser : public OptionParser {
  2526. public:
  2527. HelpOptionParser() {
  2528. m_optionNames.push_back( "-?" );
  2529. m_optionNames.push_back( "-h" );
  2530. m_optionNames.push_back( "--help" );
  2531. }
  2532. virtual std::string argsSynopsis() const {
  2533. return "[<option for help on> ...]";
  2534. }
  2535. virtual std::string optionSummary() const {
  2536. return "Shows this usage summary, or help on a specific option, or options, if supplied";
  2537. }
  2538. virtual std::string optionDescription() const {
  2539. return "";
  2540. }
  2541. virtual void parseIntoConfig( const Command&, ConfigData& ) {
  2542. // Does not affect config
  2543. }
  2544. };
  2545. class TestCaseOptionParser : public OptionParser {
  2546. public:
  2547. TestCaseOptionParser() : OptionParser( 1, -1 ) {
  2548. m_optionNames.push_back( "-t" );
  2549. m_optionNames.push_back( "--test" );
  2550. m_optionNames.push_back( "" ); // default option
  2551. }
  2552. virtual std::string argsSynopsis() const {
  2553. return "<testspec> [<testspec>...]";
  2554. }
  2555. virtual std::string optionSummary() const {
  2556. return "Specifies which test case or cases to run";
  2557. }
  2558. // Lines are split at the nearest prior space char to the 80 char column.
  2559. // Tab chars are removed from the output but their positions are used to align
  2560. // subsequently wrapped lines
  2561. virtual std::string optionDescription() const {
  2562. return
  2563. "This option allows one ore more test specs to be supplied. Each spec either fully "
  2564. "specifies a test case or is a pattern containing wildcards to match a set of test "
  2565. "cases. If this option is not provided then all test cases, except those prefixed "
  2566. "by './' are run\n"
  2567. "\n"
  2568. "Specs must be enclosed in \"quotes\" if they contain spaces. If they do not "
  2569. "contain spaces the quotes are optional.\n"
  2570. "\n"
  2571. "Wildcards consist of the * character at the beginning, end, or both and can substitute for "
  2572. "any number of any characters (including none)\n"
  2573. "\n"
  2574. "If spec is prefixed with exclude: or the ~ character then the pattern matches an exclusion. "
  2575. "This means that tests matching the pattern are excluded from the set - even if a prior "
  2576. "inclusion spec included them. Subsequent inclusion specs will take precedence, however. "
  2577. "Inclusions and exclusions are evaluated in left-to-right order.\n"
  2578. "\n"
  2579. "Examples:\n"
  2580. "\n"
  2581. " -t thisTestOnly \tMatches the test case called, 'thisTestOnly'\n"
  2582. " -t \"this test only\" \tMatches the test case called, 'this test only'\n"
  2583. " -t these/* \tMatches all cases starting with 'these/'\n"
  2584. " -t exclude:notThis \tMatches all tests except, 'notThis'\n"
  2585. " -t ~notThis \tMatches all tests except, 'notThis'\n"
  2586. " -t ~*private* \tMatches all tests except those that contain 'private'\n"
  2587. " -t a/* ~a/b/* a/b/c \tMatches all tests that start with 'a/', except those "
  2588. "that start with 'a/b/', except 'a/b/c', which is included";
  2589. }
  2590. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2591. std::string groupName;
  2592. for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
  2593. if( i != 0 )
  2594. groupName += " ";
  2595. groupName += cmd[i];
  2596. }
  2597. TestCaseFilters filters( groupName );
  2598. for( std::size_t i = 0; i < cmd.argsCount(); ++i )
  2599. filters.addFilter( TestCaseFilter( cmd[i] ) );
  2600. config.filters.push_back( filters );
  2601. }
  2602. };
  2603. class TagOptionParser : public OptionParser {
  2604. public:
  2605. TagOptionParser() : OptionParser( 1, -1 ) {
  2606. m_optionNames.push_back( "-g" );
  2607. m_optionNames.push_back( "--tag" );
  2608. }
  2609. virtual std::string argsSynopsis() const {
  2610. return "<tagspec> [,<tagspec>...]";
  2611. }
  2612. virtual std::string optionSummary() const {
  2613. return "Matches test cases against tags or tag patterns";
  2614. }
  2615. // Lines are split at the nearest prior space char to the 80 char column.
  2616. // Tab chars are removed from the output but their positions are used to align
  2617. // subsequently wrapped lines
  2618. virtual std::string optionDescription() const {
  2619. return
  2620. "This option allows one or more tags or tag patterns to be specified.\n"
  2621. "Each tag is enclosed in square brackets. A series of tags form an AND expression "
  2622. "wheras a comma seperated sequence forms an OR expression. e.g.:\n\n"
  2623. " -g [one][two],[three]\n\n"
  2624. "This matches all tests tagged [one] and [two], as well as all tests tagged [three].\n\n"
  2625. "Tags can be negated with the ~ character. This removes matching tests from the set. e.g.:\n\n"
  2626. " -g [one]~[two]\n\n"
  2627. "matches all tests tagged [one], except those also tagged [two]";
  2628. }
  2629. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2630. std::string groupName;
  2631. for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
  2632. if( i != 0 )
  2633. groupName += " ";
  2634. groupName += cmd[i];
  2635. }
  2636. TestCaseFilters filters( groupName );
  2637. for( std::size_t i = 0; i < cmd.argsCount(); ++i )
  2638. filters.addTags( cmd[i] );
  2639. config.filters.push_back( filters );
  2640. }
  2641. };
  2642. class ListOptionParser : public OptionParser {
  2643. public:
  2644. ListOptionParser() : OptionParser( 0, 2 ) {
  2645. m_optionNames.push_back( "-l" );
  2646. m_optionNames.push_back( "--list" );
  2647. }
  2648. virtual std::string argsSynopsis() const {
  2649. return "[all | tests | reporters [xml]]";
  2650. }
  2651. virtual std::string optionSummary() const {
  2652. return "Lists available tests or reporters";
  2653. }
  2654. virtual std::string optionDescription() const {
  2655. return
  2656. "With no arguments this option will list all registered tests - one per line.\n"
  2657. "Supplying the xml argument formats the list as an xml document (which may be useful for "
  2658. "consumption by other tools).\n"
  2659. "Supplying the tests or reporters lists tests or reporters respectively - with descriptions.\n"
  2660. "\n"
  2661. "Examples:\n"
  2662. "\n"
  2663. " -l\n"
  2664. " -l tests\n"
  2665. " -l reporters xml\n"
  2666. " -l xml";
  2667. }
  2668. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2669. config.listSpec = List::TestNames;
  2670. if( cmd.argsCount() >= 1 ) {
  2671. if( cmd[0] == "all" )
  2672. config.listSpec = List::All;
  2673. else if( cmd[0] == "tests" )
  2674. config.listSpec = List::Tests;
  2675. else if( cmd[0] == "reporters" )
  2676. config.listSpec = List::Reports;
  2677. else
  2678. cmd.raiseError( "Expected [tests] or [reporters]" );
  2679. }
  2680. if( cmd.argsCount() >= 2 ) {
  2681. if( cmd[1] == "xml" )
  2682. config.listSpec = static_cast<List::What>( config.listSpec | List::AsXml );
  2683. else if( cmd[1] == "text" )
  2684. config.listSpec = static_cast<List::What>( config.listSpec | List::AsText );
  2685. else
  2686. cmd.raiseError( "Expected [xml] or [text]" );
  2687. }
  2688. }
  2689. };
  2690. class ReporterOptionParser : public OptionParser {
  2691. public:
  2692. ReporterOptionParser() : OptionParser( 1, 1 ) {
  2693. m_optionNames.push_back( "-r" );
  2694. m_optionNames.push_back( "--reporter" );
  2695. }
  2696. virtual std::string argsSynopsis() const {
  2697. return "<reporter name>";
  2698. }
  2699. virtual std::string optionSummary() const {
  2700. return "Specifies type of reporter";
  2701. }
  2702. virtual std::string optionDescription() const {
  2703. return
  2704. "A reporter is an object that formats and structures the output of running "
  2705. "tests, and potentially summarises the results. By default a basic reporter "
  2706. "is used that writes IDE friendly results. CATCH comes bundled with some "
  2707. "alternative reporters, but more can be added in client code.\n"
  2708. "\n"
  2709. "The bundled reporters are:\n"
  2710. " -r basic\n"
  2711. " -r xml\n"
  2712. " -r junit\n"
  2713. "\n"
  2714. "The JUnit reporter is an xml format that follows the structure of the JUnit "
  2715. "XML Report ANT task, as consumed by a number of third-party tools, "
  2716. "including Continuous Integration servers such as Jenkins.\n"
  2717. "If not otherwise needed, the standard XML reporter is preferred as this is "
  2718. "a streaming reporter, whereas the Junit reporter needs to hold all its "
  2719. "results until the end so it can write the overall results into attributes "
  2720. "of the root node.";
  2721. }
  2722. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2723. config.reporter = cmd[0];
  2724. }
  2725. };
  2726. class OutputOptionParser : public OptionParser {
  2727. public:
  2728. OutputOptionParser() : OptionParser( 1, 1 ) {
  2729. m_optionNames.push_back( "-o" );
  2730. m_optionNames.push_back( "--out" );
  2731. }
  2732. virtual std::string argsSynopsis() const {
  2733. return "<file name>|<%stream name>";
  2734. }
  2735. virtual std::string optionSummary() const {
  2736. return "Sends output to a file or stream";
  2737. }
  2738. virtual std::string optionDescription() const {
  2739. return
  2740. "Use this option to send all output to a file or a stream. By default output is "
  2741. "sent to stdout (note that uses of stdout and stderr from within test cases are "
  2742. "redirected and included in the report - so even stderr will effectively end up "
  2743. "on stdout). If the name begins with % it is interpreted as a stream. "
  2744. "Otherwise it is treated as a filename.\n"
  2745. "\n"
  2746. "Examples are:\n"
  2747. "\n"
  2748. " -o filename.txt\n"
  2749. " -o \"long filename.txt\"\n"
  2750. " -o %stdout\n"
  2751. " -o %stderr\n"
  2752. " -o %debug \t(The IDE's debug output window - currently only Windows' "
  2753. "OutputDebugString is supported).";
  2754. }
  2755. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2756. if( cmd[0][0] == '%' )
  2757. config.stream = cmd[0].substr( 1 );
  2758. else
  2759. config.outputFilename = cmd[0];
  2760. }
  2761. };
  2762. class SuccessOptionParser : public OptionParser {
  2763. public:
  2764. SuccessOptionParser() {
  2765. m_optionNames.push_back( "-s" );
  2766. m_optionNames.push_back( "--success" );
  2767. }
  2768. virtual std::string argsSynopsis() const {
  2769. return "";
  2770. }
  2771. virtual std::string optionSummary() const {
  2772. return "Shows results for successful tests";
  2773. }
  2774. virtual std::string optionDescription() const {
  2775. return
  2776. "Usually you only want to see reporting for failed tests. Sometimes it's useful "
  2777. "to see all the output (especially when you don't trust that that test you just "
  2778. "added worked first time!). To see successful, as well as failing, test results "
  2779. "just pass this option.";
  2780. }
  2781. virtual void parseIntoConfig( const Command&, ConfigData& config ) {
  2782. config.includeWhichResults = Include::SuccessfulResults;
  2783. }
  2784. };
  2785. class DebugBreakOptionParser : public OptionParser {
  2786. public:
  2787. DebugBreakOptionParser() {
  2788. m_optionNames.push_back( "-b" );
  2789. m_optionNames.push_back( "--break" );
  2790. }
  2791. virtual std::string argsSynopsis() const {
  2792. return "";
  2793. }
  2794. virtual std::string optionSummary() const {
  2795. return "Breaks into the debugger on failure";
  2796. }
  2797. virtual std::string optionDescription() const {
  2798. return
  2799. "In some IDEs (currently XCode and Visual Studio) it is possible for CATCH to "
  2800. "break into the debugger on a test failure. This can be very helpful during "
  2801. "debug sessions - especially when there is more than one path through a "
  2802. "particular test. In addition to the command line option, ensure you have "
  2803. "built your code with the DEBUG preprocessor symbol";
  2804. }
  2805. virtual void parseIntoConfig( const Command&, ConfigData& config ) {
  2806. config.shouldDebugBreak = true;
  2807. }
  2808. };
  2809. class NameOptionParser : public OptionParser {
  2810. public:
  2811. NameOptionParser() : OptionParser( 1, 1 ) {
  2812. m_optionNames.push_back( "-n" );
  2813. m_optionNames.push_back( "--name" );
  2814. }
  2815. virtual std::string argsSynopsis() const {
  2816. return "<name>";
  2817. }
  2818. virtual std::string optionSummary() const {
  2819. return "Names a test run";
  2820. }
  2821. virtual std::string optionDescription() const {
  2822. return
  2823. "If a name is supplied it will be used by the reporter to provide an overall "
  2824. "name for the test run. This can be useful if you are sending to a file, for "
  2825. "example, and need to distinguish different test runs - either from different "
  2826. "Catch executables or runs of the same executable with different options.\n"
  2827. "\n"
  2828. "Examples:\n"
  2829. "\n"
  2830. " -n testRun\n"
  2831. " -n \"tests of the widget component\"";
  2832. }
  2833. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2834. config.name = cmd[0];
  2835. }
  2836. };
  2837. class AbortOptionParser : public OptionParser {
  2838. public:
  2839. AbortOptionParser() : OptionParser( 0, 1 ) {
  2840. m_optionNames.push_back( "-a" );
  2841. m_optionNames.push_back( "--abort" );
  2842. }
  2843. virtual std::string argsSynopsis() const {
  2844. return "[#]";
  2845. }
  2846. virtual std::string optionSummary() const {
  2847. return "Aborts after a certain number of failures";
  2848. }
  2849. virtual std::string optionDescription() const {
  2850. return
  2851. "If a REQUIRE assertion fails the test case aborts, but subsequent test cases "
  2852. "are still run. If a CHECK assertion fails even the current test case is not "
  2853. "aborted.\n"
  2854. "\n"
  2855. "Sometimes this results in a flood of failure messages and you'd rather just "
  2856. "see the first few. Specifying -a or --abort on its own will abort the whole "
  2857. "test run on the first failed assertion of any kind. Following it with a "
  2858. "number causes it to abort after that number of assertion failures.";
  2859. }
  2860. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2861. int threshold = 1;
  2862. if( cmd.argsCount() == 1 ) {
  2863. std::stringstream ss;
  2864. ss << cmd[0];
  2865. ss >> threshold;
  2866. if( ss.fail() || threshold <= 0 )
  2867. cmd.raiseError( "threshold must be a number greater than zero" );
  2868. }
  2869. config.cutoff = threshold;
  2870. }
  2871. };
  2872. class NoThrowOptionParser : public OptionParser {
  2873. public:
  2874. NoThrowOptionParser() {
  2875. m_optionNames.push_back( "-nt" );
  2876. m_optionNames.push_back( "--nothrow" );
  2877. }
  2878. virtual std::string argsSynopsis() const {
  2879. return "";
  2880. }
  2881. virtual std::string optionSummary() const {
  2882. return "Elides assertions expected to throw";
  2883. }
  2884. virtual std::string optionDescription() const {
  2885. return
  2886. "Skips all assertions that test that an exception is thrown, "
  2887. "e.g. REQUIRE_THROWS.\n"
  2888. "\n"
  2889. "These can be a nuisance in certain debugging environments that may break when "
  2890. "exceptions are thrown (while this is usually optional for handled exceptions, "
  2891. "it can be useful to have enabled if you are trying to track down something "
  2892. "unexpected).\n"
  2893. "\n"
  2894. "When running with this option the throw checking assertions are skipped so "
  2895. "as not to contribute additional noise.";
  2896. }
  2897. virtual void parseIntoConfig( const Command&, ConfigData& config ) {
  2898. config.allowThrows = false;
  2899. }
  2900. };
  2901. class WarningsOptionParser : public OptionParser {
  2902. public:
  2903. WarningsOptionParser() : OptionParser( 1, -1 ) {
  2904. m_optionNames.push_back( "-w" );
  2905. m_optionNames.push_back( "--warnings" );
  2906. }
  2907. virtual std::string argsSynopsis() const {
  2908. return "<warning>";
  2909. }
  2910. virtual std::string optionSummary() const {
  2911. return "Enable warnings";
  2912. }
  2913. virtual std::string optionDescription() const {
  2914. return
  2915. "Enables the named warnings. If the warnings are violated the test case is "
  2916. "failed.\n"
  2917. "\n"
  2918. "At present only one warning has been provided: NoAssertions. If this warning "
  2919. "is enabled then any test case that completes without an assertions (CHECK, "
  2920. "REQUIRE etc) being encountered violates the warning.\n"
  2921. "\n"
  2922. "e.g.:\n"
  2923. "\n"
  2924. " -w NoAssertions";
  2925. }
  2926. virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
  2927. for( std::size_t i = 0; i < cmd.argsCount(); ++i ) {
  2928. if( cmd[i] == "NoAssertions" )
  2929. config.warnings = (ConfigData::WarnAbout::What)( config.warnings | ConfigData::WarnAbout::NoAssertions );
  2930. else
  2931. cmd.raiseError( "Unrecognised warning: " + cmd[i] );
  2932. }
  2933. }
  2934. };
  2935. }
  2936. class AllOptions
  2937. {
  2938. public:
  2939. typedef std::vector<Ptr<OptionParser> > Parsers;
  2940. typedef Parsers::const_iterator const_iterator;
  2941. typedef Parsers::const_iterator iterator;
  2942. AllOptions() {
  2943. add<Options::TestCaseOptionParser>(); // Keep this one first
  2944. add<Options::TagOptionParser>();
  2945. add<Options::ListOptionParser>();
  2946. add<Options::ReporterOptionParser>();
  2947. add<Options::OutputOptionParser>();
  2948. add<Options::SuccessOptionParser>();
  2949. add<Options::DebugBreakOptionParser>();
  2950. add<Options::NameOptionParser>();
  2951. add<Options::AbortOptionParser>();
  2952. add<Options::NoThrowOptionParser>();
  2953. add<Options::WarningsOptionParser>();
  2954. add<Options::HelpOptionParser>(); // Keep this one last
  2955. }
  2956. void parseIntoConfig( const CommandParser& parser, ConfigData& config ) {
  2957. for( const_iterator it = m_parsers.begin(); it != m_parsers.end(); ++it )
  2958. (*it)->parseIntoConfig( parser, config );
  2959. }
  2960. const_iterator begin() const {
  2961. return m_parsers.begin();
  2962. }
  2963. const_iterator end() const {
  2964. return m_parsers.end();
  2965. }
  2966. private:
  2967. template<typename T>
  2968. void add() {
  2969. m_parsers.push_back( new T() );
  2970. }
  2971. Parsers m_parsers;
  2972. };
  2973. } // end namespace Catch
  2974. // #included from: internal/catch_list.hpp
  2975. #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
  2976. #include <limits>
  2977. namespace Catch {
  2978. inline bool matchesFilters( const std::vector<TestCaseFilters>& filters, const TestCaseInfo& testCase ) {
  2979. std::vector<TestCaseFilters>::const_iterator it = filters.begin();
  2980. std::vector<TestCaseFilters>::const_iterator itEnd = filters.end();
  2981. for(; it != itEnd; ++it )
  2982. if( !it->shouldInclude( testCase ) )
  2983. return false;
  2984. return true;
  2985. }
  2986. inline void List( const ConfigData& config ) {
  2987. if( config.listSpec & List::Reports ) {
  2988. std::cout << "Available reports:\n";
  2989. IReporterRegistry::FactoryMap::const_iterator it = getRegistryHub().getReporterRegistry().getFactories().begin();
  2990. IReporterRegistry::FactoryMap::const_iterator itEnd = getRegistryHub().getReporterRegistry().getFactories().end();
  2991. for(; it != itEnd; ++it ) {
  2992. // !TBD: consider listAs()
  2993. std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
  2994. }
  2995. std::cout << std::endl;
  2996. }
  2997. if( config.listSpec & List::Tests ) {
  2998. if( config.filters.empty() )
  2999. std::cout << "All available test cases:\n";
  3000. else
  3001. std::cout << "Matching test cases:\n";
  3002. std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
  3003. std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
  3004. std::size_t matchedTests = 0;
  3005. for(; it != itEnd; ++it ) {
  3006. if( matchesFilters( config.filters, *it ) ) {
  3007. matchedTests++;
  3008. // !TBD: consider listAs()
  3009. std::cout << "\t" << it->getName() << "\n";
  3010. if( ( config.listSpec & List::TestNames ) != List::TestNames )
  3011. std::cout << "\t\t '" << it->getDescription() << "'\n";
  3012. }
  3013. }
  3014. if( config.filters.empty() )
  3015. std::cout << pluralise( matchedTests, "test case" ) << std::endl;
  3016. else
  3017. std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
  3018. }
  3019. if( ( config.listSpec & List::All ) == 0 ) {
  3020. std::ostringstream oss;
  3021. oss << "Unknown list type";
  3022. throw std::domain_error( oss.str() );
  3023. }
  3024. }
  3025. } // end namespace Catch
  3026. // #included from: internal/catch_runner_impl.hpp
  3027. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  3028. // #included from: catch_running_test.hpp
  3029. #define TWOBLUECUBES_CATCH_RUNNING_TEST_HPP_INCLUDED
  3030. // #included from: catch_section_info.hpp
  3031. #define TWOBLUECUBES_CATCH_SECTION_INFO_HPP_INCLUDED
  3032. #include <map>
  3033. #include <string>
  3034. namespace Catch {
  3035. class SectionInfo {
  3036. public:
  3037. enum Status {
  3038. Root,
  3039. Unknown,
  3040. Branch,
  3041. TestedBranch,
  3042. TestedLeaf
  3043. };
  3044. SectionInfo( SectionInfo* parent )
  3045. : m_status( Unknown ),
  3046. m_parent( parent )
  3047. {}
  3048. SectionInfo()
  3049. : m_status( Root ),
  3050. m_parent( NULL )
  3051. {}
  3052. ~SectionInfo() {
  3053. deleteAllValues( m_subSections );
  3054. }
  3055. bool shouldRun() const {
  3056. return m_status < TestedBranch;
  3057. }
  3058. bool ran() {
  3059. if( m_status < Branch ) {
  3060. m_status = TestedLeaf;
  3061. return true;
  3062. }
  3063. return false;
  3064. }
  3065. bool isBranch() const {
  3066. return m_status == Branch;
  3067. }
  3068. void ranToCompletion() {
  3069. if( m_status == Branch && !hasUntestedSections() )
  3070. m_status = TestedBranch;
  3071. }
  3072. SectionInfo* findSubSection( const std::string& name ) {
  3073. std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
  3074. return it != m_subSections.end()
  3075. ? it->second
  3076. : NULL;
  3077. }
  3078. SectionInfo* addSubSection( const std::string& name ) {
  3079. SectionInfo* subSection = new SectionInfo( this );
  3080. m_subSections.insert( std::make_pair( name, subSection ) );
  3081. m_status = Branch;
  3082. return subSection;
  3083. }
  3084. SectionInfo* getParent() {
  3085. return m_parent;
  3086. }
  3087. bool hasUntestedSections() const {
  3088. if( m_status == Unknown )
  3089. return true;
  3090. std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
  3091. std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
  3092. for(; it != itEnd; ++it ) {
  3093. if( it->second->hasUntestedSections() )
  3094. return true;
  3095. }
  3096. return false;
  3097. }
  3098. private:
  3099. Status m_status;
  3100. std::map<std::string, SectionInfo*> m_subSections;
  3101. SectionInfo* m_parent;
  3102. };
  3103. }
  3104. namespace Catch {
  3105. class RunningTest {
  3106. enum RunStatus {
  3107. NothingRun,
  3108. EncounteredASection,
  3109. RanAtLeastOneSection,
  3110. RanToCompletionWithSections,
  3111. RanToCompletionWithNoSections
  3112. };
  3113. public:
  3114. explicit RunningTest( const TestCaseInfo* info = NULL )
  3115. : m_info( info ),
  3116. m_runStatus( RanAtLeastOneSection ),
  3117. m_currentSection( &m_rootSection ),
  3118. m_changed( false )
  3119. {}
  3120. bool wasSectionSeen() const {
  3121. return m_runStatus == RanAtLeastOneSection ||
  3122. m_runStatus == RanToCompletionWithSections;
  3123. }
  3124. bool isBranchSection() const {
  3125. return m_currentSection &&
  3126. m_currentSection->isBranch();
  3127. }
  3128. bool hasSections() const {
  3129. return m_runStatus == RanAtLeastOneSection ||
  3130. m_runStatus == RanToCompletionWithSections ||
  3131. m_runStatus == EncounteredASection;
  3132. }
  3133. void reset() {
  3134. m_runStatus = NothingRun;
  3135. m_changed = false;
  3136. m_lastSectionToRun = NULL;
  3137. }
  3138. void ranToCompletion() {
  3139. if( m_runStatus == RanAtLeastOneSection ||
  3140. m_runStatus == EncounteredASection ) {
  3141. m_runStatus = RanToCompletionWithSections;
  3142. if( m_lastSectionToRun ) {
  3143. m_lastSectionToRun->ranToCompletion();
  3144. m_changed = true;
  3145. }
  3146. }
  3147. else {
  3148. m_runStatus = RanToCompletionWithNoSections;
  3149. }
  3150. }
  3151. bool addSection( const std::string& name ) {
  3152. if( m_runStatus == NothingRun )
  3153. m_runStatus = EncounteredASection;
  3154. SectionInfo* thisSection = m_currentSection->findSubSection( name );
  3155. if( !thisSection ) {
  3156. thisSection = m_currentSection->addSubSection( name );
  3157. m_changed = true;
  3158. }
  3159. if( !wasSectionSeen() && thisSection->shouldRun() ) {
  3160. m_currentSection = thisSection;
  3161. m_lastSectionToRun = NULL;
  3162. return true;
  3163. }
  3164. return false;
  3165. }
  3166. void endSection( const std::string& ) {
  3167. if( m_currentSection->ran() ) {
  3168. m_runStatus = RanAtLeastOneSection;
  3169. m_changed = true;
  3170. }
  3171. else if( m_runStatus == EncounteredASection ) {
  3172. m_runStatus = RanAtLeastOneSection;
  3173. m_lastSectionToRun = m_currentSection;
  3174. }
  3175. m_currentSection = m_currentSection->getParent();
  3176. }
  3177. const TestCaseInfo& getTestCaseInfo() const {
  3178. return *m_info;
  3179. }
  3180. bool hasUntestedSections() const {
  3181. return m_runStatus == RanAtLeastOneSection ||
  3182. ( m_rootSection.hasUntestedSections() && m_changed );
  3183. }
  3184. private:
  3185. const TestCaseInfo* m_info;
  3186. RunStatus m_runStatus;
  3187. SectionInfo m_rootSection;
  3188. SectionInfo* m_currentSection;
  3189. SectionInfo* m_lastSectionToRun;
  3190. bool m_changed;
  3191. };
  3192. }
  3193. #include <set>
  3194. #include <string>
  3195. namespace Catch {
  3196. class StreamRedirect {
  3197. public:
  3198. StreamRedirect( std::ostream& stream, std::string& targetString )
  3199. : m_stream( stream ),
  3200. m_prevBuf( stream.rdbuf() ),
  3201. m_targetString( targetString )
  3202. {
  3203. stream.rdbuf( m_oss.rdbuf() );
  3204. }
  3205. ~StreamRedirect() {
  3206. m_targetString += m_oss.str();
  3207. m_stream.rdbuf( m_prevBuf );
  3208. }
  3209. private:
  3210. std::ostream& m_stream;
  3211. std::streambuf* m_prevBuf;
  3212. std::ostringstream m_oss;
  3213. std::string& m_targetString;
  3214. };
  3215. ///////////////////////////////////////////////////////////////////////////
  3216. class Runner : public IResultCapture, public IRunner {
  3217. Runner( const Runner& );
  3218. void operator =( const Runner& );
  3219. public:
  3220. explicit Runner( const Config& config, const Ptr<IReporter>& reporter )
  3221. : m_context( getCurrentMutableContext() ),
  3222. m_runningTest( NULL ),
  3223. m_config( config ),
  3224. m_reporter( reporter ),
  3225. m_prevRunner( &m_context.getRunner() ),
  3226. m_prevResultCapture( &m_context.getResultCapture() ),
  3227. m_prevConfig( m_context.getConfig() )
  3228. {
  3229. m_context.setRunner( this );
  3230. m_context.setConfig( &m_config );
  3231. m_context.setResultCapture( this );
  3232. m_reporter->StartTesting();
  3233. }
  3234. virtual ~Runner() {
  3235. m_reporter->EndTesting( m_totals );
  3236. m_context.setRunner( m_prevRunner );
  3237. m_context.setConfig( NULL );
  3238. m_context.setResultCapture( m_prevResultCapture );
  3239. m_context.setConfig( m_prevConfig );
  3240. }
  3241. Totals runMatching( const std::string& testSpec ) {
  3242. std::vector<TestCaseInfo> matchingTests = getRegistryHub().getTestCaseRegistry().getMatchingTestCases( testSpec );
  3243. Totals totals;
  3244. m_reporter->StartGroup( testSpec );
  3245. std::vector<TestCaseInfo>::const_iterator it = matchingTests.begin();
  3246. std::vector<TestCaseInfo>::const_iterator itEnd = matchingTests.end();
  3247. for(; it != itEnd; ++it )
  3248. totals += runTest( *it );
  3249. // !TBD use std::accumulate?
  3250. m_reporter->EndGroup( testSpec, totals );
  3251. return totals;
  3252. }
  3253. Totals runTest( const TestCaseInfo& testInfo ) {
  3254. Totals prevTotals = m_totals;
  3255. std::string redirectedCout;
  3256. std::string redirectedCerr;
  3257. m_reporter->StartTestCase( testInfo );
  3258. m_runningTest = new RunningTest( &testInfo );
  3259. do {
  3260. do {
  3261. runCurrentTest( redirectedCout, redirectedCerr );
  3262. }
  3263. while( m_runningTest->hasUntestedSections() && !aborting() );
  3264. }
  3265. while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
  3266. delete m_runningTest;
  3267. m_runningTest = NULL;
  3268. Totals deltaTotals = m_totals.delta( prevTotals );
  3269. m_totals.testCases += deltaTotals.testCases;
  3270. m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr );
  3271. return deltaTotals;
  3272. }
  3273. const Config& config() const {
  3274. return m_config;
  3275. }
  3276. private: // IResultCapture
  3277. virtual ResultAction::Value acceptExpression( const ExpressionResultBuilder& assertionResult, const AssertionInfo& assertionInfo ) {
  3278. m_lastAssertionInfo = assertionInfo;
  3279. return actOnCurrentResult( assertionResult.buildResult( assertionInfo ) );
  3280. }
  3281. virtual void testEnded( const AssertionResult& result ) {
  3282. if( result.getResultType() == ResultWas::Ok ) {
  3283. m_totals.assertions.passed++;
  3284. }
  3285. else if( !result.isOk() ) {
  3286. m_totals.assertions.failed++;
  3287. {
  3288. std::vector<ScopedInfo*>::const_iterator it = m_scopedInfos.begin();
  3289. std::vector<ScopedInfo*>::const_iterator itEnd = m_scopedInfos.end();
  3290. for(; it != itEnd; ++it )
  3291. m_reporter->Result( (*it)->buildResult( m_lastAssertionInfo ) );
  3292. }
  3293. {
  3294. std::vector<AssertionResult>::const_iterator it = m_assertionResults.begin();
  3295. std::vector<AssertionResult>::const_iterator itEnd = m_assertionResults.end();
  3296. for(; it != itEnd; ++it )
  3297. m_reporter->Result( *it );
  3298. }
  3299. m_assertionResults.clear();
  3300. }
  3301. if( result.getResultType() == ResultWas::Info )
  3302. m_assertionResults.push_back( result );
  3303. else
  3304. m_reporter->Result( result );
  3305. }
  3306. virtual bool sectionStarted (
  3307. const std::string& name,
  3308. const std::string& description,
  3309. const SourceLineInfo& lineInfo,
  3310. Counts& assertions
  3311. )
  3312. {
  3313. std::ostringstream oss;
  3314. oss << name << "@" << lineInfo;
  3315. if( !m_runningTest->addSection( oss.str() ) )
  3316. return false;
  3317. m_lastAssertionInfo.lineInfo = lineInfo;
  3318. m_reporter->StartSection( name, description );
  3319. assertions = m_totals.assertions;
  3320. return true;
  3321. }
  3322. virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) {
  3323. Counts assertions = m_totals.assertions - prevAssertions;
  3324. if( assertions.total() == 0 &&
  3325. ( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
  3326. !m_runningTest->isBranchSection() ) {
  3327. m_reporter->NoAssertionsInSection( name );
  3328. m_totals.assertions.failed++;
  3329. assertions.failed++;
  3330. }
  3331. m_runningTest->endSection( name );
  3332. m_reporter->EndSection( name, assertions );
  3333. }
  3334. virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
  3335. m_scopedInfos.push_back( scopedInfo );
  3336. }
  3337. virtual void popScopedInfo( ScopedInfo* scopedInfo ) {
  3338. if( m_scopedInfos.back() == scopedInfo )
  3339. m_scopedInfos.pop_back();
  3340. }
  3341. virtual bool shouldDebugBreak() const {
  3342. return m_config.shouldDebugBreak();
  3343. }
  3344. virtual std::string getCurrentTestName() const {
  3345. return m_runningTest
  3346. ? m_runningTest->getTestCaseInfo().getName()
  3347. : "";
  3348. }
  3349. virtual const AssertionResult* getLastResult() const {
  3350. return &m_lastResult;
  3351. }
  3352. public:
  3353. // !TBD We need to do this another way!
  3354. bool aborting() const {
  3355. return m_totals.assertions.failed == static_cast<std::size_t>( m_config.getCutoff() );
  3356. }
  3357. private:
  3358. ResultAction::Value actOnCurrentResult( const AssertionResult& result ) {
  3359. m_lastResult = result;
  3360. testEnded( m_lastResult );
  3361. ResultAction::Value action = ResultAction::None;
  3362. if( !m_lastResult.isOk() ) {
  3363. action = ResultAction::Failed;
  3364. if( shouldDebugBreak() )
  3365. action = (ResultAction::Value)( action | ResultAction::Debug );
  3366. if( aborting() )
  3367. action = (ResultAction::Value)( action | ResultAction::Abort );
  3368. }
  3369. return action;
  3370. }
  3371. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
  3372. try {
  3373. m_lastAssertionInfo = AssertionInfo( "TEST_CASE", m_runningTest->getTestCaseInfo().getLineInfo(), "", ResultDisposition::Normal );
  3374. m_runningTest->reset();
  3375. Counts prevAssertions = m_totals.assertions;
  3376. if( m_reporter->shouldRedirectStdout() ) {
  3377. StreamRedirect coutRedir( std::cout, redirectedCout );
  3378. StreamRedirect cerrRedir( std::cerr, redirectedCerr );
  3379. m_runningTest->getTestCaseInfo().invoke();
  3380. }
  3381. else {
  3382. m_runningTest->getTestCaseInfo().invoke();
  3383. }
  3384. Counts assertions = m_totals.assertions - prevAssertions;
  3385. if( assertions.total() == 0 &&
  3386. ( m_config.data().warnings & ConfigData::WarnAbout::NoAssertions ) &&
  3387. !m_runningTest->hasSections() ) {
  3388. m_totals.assertions.failed++;
  3389. m_reporter->NoAssertionsInTestCase( m_runningTest->getTestCaseInfo().getName() );
  3390. }
  3391. m_runningTest->ranToCompletion();
  3392. }
  3393. catch( TestFailureException& ) {
  3394. // This just means the test was aborted due to failure
  3395. }
  3396. catch(...) {
  3397. ExpressionResultBuilder exResult( ResultWas::ThrewException );
  3398. exResult << translateActiveException();
  3399. actOnCurrentResult( exResult.buildResult( m_lastAssertionInfo ) );
  3400. }
  3401. m_assertionResults.clear();
  3402. }
  3403. private:
  3404. IMutableContext& m_context;
  3405. RunningTest* m_runningTest;
  3406. AssertionResult m_lastResult;
  3407. const Config& m_config;
  3408. Totals m_totals;
  3409. Ptr<IReporter> m_reporter;
  3410. std::vector<ScopedInfo*> m_scopedInfos;
  3411. std::vector<AssertionResult> m_assertionResults;
  3412. IRunner* m_prevRunner;
  3413. IResultCapture* m_prevResultCapture;
  3414. const IConfig* m_prevConfig;
  3415. AssertionInfo m_lastAssertionInfo;
  3416. };
  3417. } // end namespace Catch
  3418. #include <fstream>
  3419. #include <stdlib.h>
  3420. #include <limits>
  3421. namespace Catch {
  3422. class Runner2 { // This will become Runner when Runner becomes Context
  3423. public:
  3424. Runner2( Config& configWrapper )
  3425. : m_configWrapper( configWrapper ),
  3426. m_config( configWrapper.data() )
  3427. {
  3428. openStream();
  3429. makeReporter();
  3430. }
  3431. Totals runTests() {
  3432. std::vector<TestCaseFilters> filterGroups = m_config.filters;
  3433. if( filterGroups.empty() ) {
  3434. TestCaseFilters filterGroup( "" );
  3435. filterGroups.push_back( filterGroup );
  3436. }
  3437. Runner context( m_configWrapper, m_reporter ); // This Runner will be renamed Context
  3438. Totals totals;
  3439. std::vector<TestCaseFilters>::const_iterator it = filterGroups.begin();
  3440. std::vector<TestCaseFilters>::const_iterator itEnd = filterGroups.end();
  3441. for(; it != itEnd && !context.aborting(); ++it ) {
  3442. m_reporter->StartGroup( it->getName() );
  3443. totals += runTestsForGroup( context, *it );
  3444. if( context.aborting() )
  3445. m_reporter->Aborted();
  3446. m_reporter->EndGroup( it->getName(), totals );
  3447. }
  3448. return totals;
  3449. }
  3450. Totals runTestsForGroup( Runner& context, const TestCaseFilters& filterGroup ) {
  3451. Totals totals;
  3452. std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
  3453. std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
  3454. int testsRunForGroup = 0;
  3455. for(; it != itEnd; ++it ) {
  3456. if( filterGroup.shouldInclude( *it ) ) {
  3457. testsRunForGroup++;
  3458. if( m_testsAlreadyRun.find( *it ) == m_testsAlreadyRun.end() ) {
  3459. if( context.aborting() )
  3460. break;
  3461. totals += context.runTest( *it );
  3462. m_testsAlreadyRun.insert( *it );
  3463. }
  3464. }
  3465. }
  3466. if( testsRunForGroup == 0 )
  3467. std::cerr << "\n[No test cases matched with: " << filterGroup.getName() << "]" << std::endl;
  3468. return totals;
  3469. }
  3470. private:
  3471. void openStream() {
  3472. if( !m_config.stream.empty() )
  3473. m_configWrapper.useStream( m_config.stream );
  3474. // Open output file, if specified
  3475. if( !m_config.outputFilename.empty() ) {
  3476. m_ofs.open( m_config.outputFilename.c_str() );
  3477. if( m_ofs.fail() ) {
  3478. std::ostringstream oss;
  3479. oss << "Unable to open file: '" << m_config.outputFilename << "'";
  3480. throw std::domain_error( oss.str() );
  3481. }
  3482. m_configWrapper.setStreamBuf( m_ofs.rdbuf() );
  3483. }
  3484. }
  3485. void makeReporter() {
  3486. std::string reporterName = m_config.reporter.empty()
  3487. ? "basic"
  3488. : m_config.reporter;
  3489. ReporterConfig reporterConfig( m_config.name, m_configWrapper.stream(), m_config.includeWhichResults == Include::SuccessfulResults, m_config );
  3490. m_reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig );
  3491. if( !m_reporter ) {
  3492. std::ostringstream oss;
  3493. oss << "No reporter registered with name: '" << reporterName << "'";
  3494. throw std::domain_error( oss.str() );
  3495. }
  3496. }
  3497. private:
  3498. Config& m_configWrapper;
  3499. const ConfigData& m_config;
  3500. std::ofstream m_ofs;
  3501. Ptr<IReporter> m_reporter;
  3502. std::set<TestCaseInfo> m_testsAlreadyRun;
  3503. };
  3504. inline int Main( Config& configWrapper ) {
  3505. int result = 0;
  3506. try
  3507. {
  3508. Runner2 runner( configWrapper );
  3509. const ConfigData& config = configWrapper.data();
  3510. // Handle list request
  3511. if( config.listSpec != List::None ) {
  3512. List( config );
  3513. Catch::cleanUp();
  3514. return 0;
  3515. }
  3516. result = static_cast<int>( runner.runTests().assertions.failed );
  3517. }
  3518. catch( std::exception& ex ) {
  3519. std::cerr << ex.what() << std::endl;
  3520. result = (std::numeric_limits<int>::max)();
  3521. }
  3522. Catch::cleanUp();
  3523. return result;
  3524. }
  3525. inline void showUsage( std::ostream& os ) {
  3526. AllOptions options;
  3527. for( AllOptions::const_iterator it = options.begin(); it != options.end(); ++it ) {
  3528. OptionParser& opt = **it;
  3529. os << " " << opt.optionNames() << " " << opt.argsSynopsis() << "\n";
  3530. }
  3531. os << "\nFor more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line\n" << std::endl;
  3532. }
  3533. inline void addIndent( std::ostream& os, std::size_t indent ) {
  3534. while( indent-- > 0 )
  3535. os << ' ';
  3536. }
  3537. inline void recursivelyWrapLine( std::ostream& os, std::string paragraph, std::size_t columns, std::size_t indent ) {
  3538. std::size_t width = columns-indent;
  3539. std::size_t tab = 0;
  3540. std::size_t wrapPoint = width;
  3541. for( std::size_t pos = 0; pos < paragraph.size(); ++pos ) {
  3542. if( pos == width ) {
  3543. addIndent( os, indent );
  3544. os << paragraph.substr( 0, wrapPoint ) << "\n";
  3545. return recursivelyWrapLine( os, paragraph.substr( wrapPoint+1 ), columns, indent+tab );
  3546. }
  3547. if( paragraph[pos] == '\t' ) {
  3548. tab = pos;
  3549. paragraph = paragraph.substr( 0, tab ) + paragraph.substr( tab+1 );
  3550. pos--;
  3551. }
  3552. else if( paragraph[pos] == ' ' ) {
  3553. wrapPoint = pos;
  3554. }
  3555. }
  3556. addIndent( os, indent );
  3557. os << paragraph << "\n";
  3558. }
  3559. inline std::string addLineBreaks( const std::string& str, std::size_t columns, std::size_t indent = 0 ) {
  3560. std::ostringstream oss;
  3561. std::string::size_type pos = 0;
  3562. std::string::size_type newline = str.find_first_of( '\n' );
  3563. while( newline != std::string::npos ) {
  3564. std::string paragraph = str.substr( pos, newline-pos );
  3565. recursivelyWrapLine( oss, paragraph, columns, indent );
  3566. pos = newline+1;
  3567. newline = str.find_first_of( '\n', pos );
  3568. }
  3569. if( pos != str.size() )
  3570. recursivelyWrapLine( oss, str.substr( pos, str.size()-pos ), columns, indent );
  3571. return oss.str();
  3572. }
  3573. inline void showHelp( const CommandParser& parser ) {
  3574. std::string exeName = parser.exeName();
  3575. std::string::size_type pos = exeName.find_last_of( "/\\" );
  3576. if( pos != std::string::npos ) {
  3577. exeName = exeName.substr( pos+1 );
  3578. }
  3579. AllOptions options;
  3580. Options::HelpOptionParser helpOpt;
  3581. bool displayedSpecificOption = false;
  3582. for( AllOptions::const_iterator it = options.begin(); it != options.end(); ++it ) {
  3583. OptionParser& opt = **it;
  3584. if( opt.find( parser ) && opt.optionNames() != helpOpt.optionNames() ) {
  3585. displayedSpecificOption = true;
  3586. std::cout << "\n" << opt.optionNames() << " " << opt.argsSynopsis() << "\n\n"
  3587. << opt.optionSummary() << "\n\n"
  3588. << addLineBreaks( opt.optionDescription(), 80, 2 ) << "\n" << std::endl;
  3589. }
  3590. }
  3591. if( !displayedSpecificOption ) {
  3592. std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n";
  3593. showUsage( std::cout );
  3594. }
  3595. }
  3596. inline int Main( int argc, char* const argv[], Config& config ) {
  3597. try {
  3598. CommandParser parser( argc, argv );
  3599. if( Command cmd = Options::HelpOptionParser().find( parser ) ) {
  3600. if( cmd.argsCount() != 0 )
  3601. cmd.raiseError( "Does not accept arguments" );
  3602. showHelp( parser );
  3603. Catch::cleanUp();
  3604. return 0;
  3605. }
  3606. AllOptions options;
  3607. options.parseIntoConfig( parser, config.data() );
  3608. }
  3609. catch( std::exception& ex ) {
  3610. std::cerr << ex.what() << "\n\nUsage: ...\n\n";
  3611. showUsage( std::cerr );
  3612. Catch::cleanUp();
  3613. return (std::numeric_limits<int>::max)();
  3614. }
  3615. return Main( config );
  3616. }
  3617. inline int Main( int argc, char* const argv[] ) {
  3618. Config config;
  3619. // !TBD: This doesn't always work, for some reason
  3620. // if( isDebuggerActive() )
  3621. // config.useStream( "debug" );
  3622. return Main( argc, argv, config );
  3623. }
  3624. } // end namespace Catch
  3625. // #included from: catch_registry_hub.hpp
  3626. #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
  3627. // #included from: catch_test_case_registry_impl.hpp
  3628. #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
  3629. #include <vector>
  3630. #include <set>
  3631. #include <sstream>
  3632. #include <iostream>
  3633. namespace Catch {
  3634. class TestRegistry : public ITestCaseRegistry {
  3635. public:
  3636. TestRegistry() : m_unnamedCount( 0 ) {}
  3637. virtual ~TestRegistry();
  3638. virtual void registerTest( const TestCaseInfo& testInfo ) {
  3639. if( testInfo.getName() == "" ) {
  3640. std::ostringstream oss;
  3641. oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount;
  3642. return registerTest( TestCaseInfo( testInfo, oss.str() ) );
  3643. }
  3644. if( m_functions.find( testInfo ) == m_functions.end() ) {
  3645. m_functions.insert( testInfo );
  3646. m_functionsInOrder.push_back( testInfo );
  3647. if( !testInfo.isHidden() )
  3648. m_nonHiddenFunctions.push_back( testInfo );
  3649. }
  3650. else {
  3651. const TestCaseInfo& prev = *m_functions.find( testInfo );
  3652. std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n"
  3653. << "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n"
  3654. << "\tRedefined at " << SourceLineInfo( testInfo.getLineInfo() ) << std::endl;
  3655. exit(1);
  3656. }
  3657. }
  3658. virtual const std::vector<TestCaseInfo>& getAllTests() const {
  3659. return m_functionsInOrder;
  3660. }
  3661. virtual const std::vector<TestCaseInfo>& getAllNonHiddenTests() const {
  3662. return m_nonHiddenFunctions;
  3663. }
  3664. // !TBD deprecated
  3665. virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const {
  3666. std::vector<TestCaseInfo> matchingTests;
  3667. getMatchingTestCases( rawTestSpec, matchingTests );
  3668. return matchingTests;
  3669. }
  3670. // !TBD deprecated
  3671. virtual void getMatchingTestCases( const std::string& rawTestSpec, std::vector<TestCaseInfo>& matchingTestsOut ) const {
  3672. TestCaseFilter filter( rawTestSpec );
  3673. std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
  3674. std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
  3675. for(; it != itEnd; ++it ) {
  3676. if( filter.shouldInclude( *it ) ) {
  3677. matchingTestsOut.push_back( *it );
  3678. }
  3679. }
  3680. }
  3681. virtual void getMatchingTestCases( const TestCaseFilters& filters, std::vector<TestCaseInfo>& matchingTestsOut ) const {
  3682. std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
  3683. std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
  3684. // !TBD: replace with algorithm
  3685. for(; it != itEnd; ++it )
  3686. if( filters.shouldInclude( *it ) )
  3687. matchingTestsOut.push_back( *it );
  3688. }
  3689. private:
  3690. std::set<TestCaseInfo> m_functions;
  3691. std::vector<TestCaseInfo> m_functionsInOrder;
  3692. std::vector<TestCaseInfo> m_nonHiddenFunctions;
  3693. size_t m_unnamedCount;
  3694. };
  3695. ///////////////////////////////////////////////////////////////////////////
  3696. class FreeFunctionTestCase : public SharedImpl<ITestCase> {
  3697. public:
  3698. FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
  3699. virtual void invoke() const {
  3700. m_fun();
  3701. }
  3702. private:
  3703. virtual ~FreeFunctionTestCase();
  3704. TestFunction m_fun;
  3705. };
  3706. inline std::string extractClassName( const std::string& classOrQualifiedMethodName ) {
  3707. std::string className = classOrQualifiedMethodName;
  3708. if( className[0] == '&' )
  3709. {
  3710. std::size_t lastColons = className.rfind( "::" );
  3711. std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
  3712. if( penultimateColons == std::string::npos )
  3713. penultimateColons = 1;
  3714. className = className.substr( penultimateColons, lastColons-penultimateColons );
  3715. }
  3716. return className;
  3717. }
  3718. ///////////////////////////////////////////////////////////////////////////
  3719. AutoReg::AutoReg( TestFunction function,
  3720. const char* name,
  3721. const char* description,
  3722. const SourceLineInfo& lineInfo ) {
  3723. registerTestCase( new FreeFunctionTestCase( function ), "global", name, description, lineInfo );
  3724. }
  3725. AutoReg::~AutoReg() {}
  3726. void AutoReg::registerTestCase( ITestCase* testCase,
  3727. const char* classOrQualifiedMethodName,
  3728. const char* name,
  3729. const char* description,
  3730. const SourceLineInfo& lineInfo ) {
  3731. getMutableRegistryHub().registerTest( TestCaseInfo( testCase, extractClassName( classOrQualifiedMethodName ), name, description, lineInfo ) );
  3732. }
  3733. } // end namespace Catch
  3734. // #included from: catch_reporter_registry.hpp
  3735. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
  3736. #include <map>
  3737. namespace Catch {
  3738. class ReporterRegistry : public IReporterRegistry {
  3739. public:
  3740. virtual ~ReporterRegistry() {
  3741. deleteAllValues( m_factories );
  3742. }
  3743. virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const {
  3744. FactoryMap::const_iterator it = m_factories.find( name );
  3745. if( it == m_factories.end() )
  3746. return NULL;
  3747. return it->second->create( config );
  3748. }
  3749. void registerReporter( const std::string& name, IReporterFactory* factory ) {
  3750. m_factories.insert( std::make_pair( name, factory ) );
  3751. }
  3752. const FactoryMap& getFactories() const {
  3753. return m_factories;
  3754. }
  3755. private:
  3756. FactoryMap m_factories;
  3757. };
  3758. }
  3759. // #included from: catch_exception_translator_registry.hpp
  3760. #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
  3761. #ifdef __OBJC__
  3762. #import "Foundation/Foundation.h"
  3763. #endif
  3764. namespace Catch {
  3765. class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
  3766. public:
  3767. ~ExceptionTranslatorRegistry() {
  3768. deleteAll( m_translators );
  3769. }
  3770. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  3771. m_translators.push_back( translator );
  3772. }
  3773. virtual std::string translateActiveException() const {
  3774. try {
  3775. #ifdef __OBJC__
  3776. // In Objective-C try objective-c exceptions first
  3777. @try {
  3778. throw;
  3779. }
  3780. @catch (NSException *exception) {
  3781. return toString( [exception description] );
  3782. }
  3783. #else
  3784. throw;
  3785. #endif
  3786. }
  3787. catch( std::exception& ex ) {
  3788. return ex.what();
  3789. }
  3790. catch( std::string& msg ) {
  3791. return msg;
  3792. }
  3793. catch( const char* msg ) {
  3794. return msg;
  3795. }
  3796. catch(...) {
  3797. return tryTranslators( m_translators.begin() );
  3798. }
  3799. }
  3800. std::string tryTranslators( std::vector<const IExceptionTranslator*>::const_iterator it ) const {
  3801. if( it == m_translators.end() )
  3802. return "Unknown exception";
  3803. try {
  3804. return (*it)->translate();
  3805. }
  3806. catch(...) {
  3807. return tryTranslators( it+1 );
  3808. }
  3809. }
  3810. private:
  3811. std::vector<const IExceptionTranslator*> m_translators;
  3812. };
  3813. }
  3814. namespace Catch {
  3815. namespace {
  3816. class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
  3817. RegistryHub( const RegistryHub& );
  3818. void operator=( const RegistryHub& );
  3819. public: // IRegistryHub
  3820. RegistryHub() {
  3821. }
  3822. virtual const IReporterRegistry& getReporterRegistry() const {
  3823. return m_reporterRegistry;
  3824. }
  3825. virtual const ITestCaseRegistry& getTestCaseRegistry() const {
  3826. return m_testCaseRegistry;
  3827. }
  3828. virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() {
  3829. return m_exceptionTranslatorRegistry;
  3830. }
  3831. public: // IMutableRegistryHub
  3832. virtual void registerReporter( const std::string& name, IReporterFactory* factory ) {
  3833. m_reporterRegistry.registerReporter( name, factory );
  3834. }
  3835. virtual void registerTest( const TestCaseInfo& testInfo ) {
  3836. m_testCaseRegistry.registerTest( testInfo );
  3837. }
  3838. virtual void registerTranslator( const IExceptionTranslator* translator ) {
  3839. m_exceptionTranslatorRegistry.registerTranslator( translator );
  3840. }
  3841. private:
  3842. TestRegistry m_testCaseRegistry;
  3843. ReporterRegistry m_reporterRegistry;
  3844. ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
  3845. };
  3846. // Single, global, instance
  3847. inline RegistryHub*& getTheRegistryHub() {
  3848. static RegistryHub* theRegistryHub = NULL;
  3849. if( !theRegistryHub )
  3850. theRegistryHub = new RegistryHub();
  3851. return theRegistryHub;
  3852. }
  3853. }
  3854. IRegistryHub& getRegistryHub() {
  3855. return *getTheRegistryHub();
  3856. }
  3857. IMutableRegistryHub& getMutableRegistryHub() {
  3858. return *getTheRegistryHub();
  3859. }
  3860. void cleanUp() {
  3861. delete getTheRegistryHub();
  3862. getTheRegistryHub() = NULL;
  3863. cleanUpContext();
  3864. }
  3865. std::string translateActiveException() {
  3866. return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
  3867. }
  3868. } // end namespace Catch
  3869. // #included from: catch_notimplemented_exception.hpp
  3870. #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
  3871. #include <ostream>
  3872. namespace Catch {
  3873. NotImplementedException::NotImplementedException( const SourceLineInfo& lineInfo )
  3874. : m_lineInfo( lineInfo ) {
  3875. std::ostringstream oss;
  3876. oss << lineInfo << "function ";
  3877. oss << "not implemented";
  3878. m_what = oss.str();
  3879. }
  3880. const char* NotImplementedException::what() const throw() {
  3881. return m_what.c_str();
  3882. }
  3883. } // end namespace Catch
  3884. // #included from: catch_context_impl.hpp
  3885. #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
  3886. namespace Catch {
  3887. class Context : public IMutableContext {
  3888. Context() : m_config( NULL ) {}
  3889. Context( const Context& );
  3890. void operator=( const Context& );
  3891. public: // IContext
  3892. virtual IResultCapture& getResultCapture() {
  3893. return *m_resultCapture;
  3894. }
  3895. virtual IRunner& getRunner() {
  3896. return *m_runner;
  3897. }
  3898. virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) {
  3899. return getGeneratorsForCurrentTest()
  3900. .getGeneratorInfo( fileInfo, totalSize )
  3901. .getCurrentIndex();
  3902. }
  3903. virtual bool advanceGeneratorsForCurrentTest() {
  3904. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  3905. return generators && generators->moveNext();
  3906. }
  3907. virtual const IConfig* getConfig() const {
  3908. return m_config;
  3909. }
  3910. public: // IMutableContext
  3911. virtual void setResultCapture( IResultCapture* resultCapture ) {
  3912. m_resultCapture = resultCapture;
  3913. }
  3914. virtual void setRunner( IRunner* runner ) {
  3915. m_runner = runner;
  3916. }
  3917. virtual void setConfig( const IConfig* config ) {
  3918. m_config = config;
  3919. }
  3920. friend IMutableContext& getCurrentMutableContext();
  3921. private:
  3922. IGeneratorsForTest* findGeneratorsForCurrentTest() {
  3923. std::string testName = getResultCapture().getCurrentTestName();
  3924. std::map<std::string, IGeneratorsForTest*>::const_iterator it =
  3925. m_generatorsByTestName.find( testName );
  3926. return it != m_generatorsByTestName.end()
  3927. ? it->second
  3928. : NULL;
  3929. }
  3930. IGeneratorsForTest& getGeneratorsForCurrentTest() {
  3931. IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
  3932. if( !generators ) {
  3933. std::string testName = getResultCapture().getCurrentTestName();
  3934. generators = createGeneratorsForTest();
  3935. m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
  3936. }
  3937. return *generators;
  3938. }
  3939. private:
  3940. IRunner* m_runner;
  3941. IResultCapture* m_resultCapture;
  3942. const IConfig* m_config;
  3943. std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
  3944. };
  3945. namespace {
  3946. Context* currentContext = NULL;
  3947. }
  3948. IMutableContext& getCurrentMutableContext() {
  3949. if( !currentContext )
  3950. currentContext = new Context();
  3951. return *currentContext;
  3952. }
  3953. IContext& getCurrentContext() {
  3954. return getCurrentMutableContext();
  3955. }
  3956. Stream createStream( const std::string& streamName ) {
  3957. if( streamName == "stdout" ) return Stream( std::cout.rdbuf(), false );
  3958. if( streamName == "stderr" ) return Stream( std::cerr.rdbuf(), false );
  3959. if( streamName == "debug" ) return Stream( new StreamBufImpl<OutputDebugWriter>, true );
  3960. throw std::domain_error( "Unknown stream: " + streamName );
  3961. }
  3962. void cleanUpContext() {
  3963. delete currentContext;
  3964. currentContext = NULL;
  3965. }
  3966. }
  3967. // #included from: catch_console_colour_impl.hpp
  3968. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
  3969. // #included from: catch_console_colour.hpp
  3970. #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
  3971. namespace Catch {
  3972. struct ConsoleColourImpl;
  3973. class TextColour : NonCopyable {
  3974. public:
  3975. enum Colours {
  3976. None,
  3977. FileName,
  3978. ResultError,
  3979. ResultSuccess,
  3980. Error,
  3981. Success,
  3982. OriginalExpression,
  3983. ReconstructedExpression
  3984. };
  3985. TextColour( Colours colour = None );
  3986. void set( Colours colour );
  3987. ~TextColour();
  3988. private:
  3989. ConsoleColourImpl* m_impl;
  3990. };
  3991. } // end namespace Catch
  3992. #if defined( CATCH_CONFIG_USE_ANSI_COLOUR_CODES )
  3993. #include <unistd.h>
  3994. namespace Catch {
  3995. // use POSIX/ ANSI console terminal codes
  3996. // Implementation contributed by Adam Strzelecki (http://github.com/nanoant)
  3997. // https://github.com/philsquared/Catch/pull/131
  3998. TextColour::TextColour( Colours colour ) {
  3999. if( colour )
  4000. set( colour );
  4001. }
  4002. TextColour::~TextColour() {
  4003. set( TextColour::None );
  4004. }
  4005. namespace { const char colourEscape = '\033'; }
  4006. void TextColour::set( Colours colour ) {
  4007. if( isatty( fileno(stdout) ) ) {
  4008. switch( colour ) {
  4009. case TextColour::FileName:
  4010. std::cout << colourEscape << "[0m"; // white/ normal
  4011. break;
  4012. case TextColour::ResultError:
  4013. std::cout << colourEscape << "[1;31m"; // bold red
  4014. break;
  4015. case TextColour::ResultSuccess:
  4016. std::cout << colourEscape << "[1;32m"; // bold green
  4017. break;
  4018. case TextColour::Error:
  4019. std::cout << colourEscape << "[0;31m"; // red
  4020. break;
  4021. case TextColour::Success:
  4022. std::cout << colourEscape << "[0;32m"; // green
  4023. break;
  4024. case TextColour::OriginalExpression:
  4025. std::cout << colourEscape << "[0;36m"; // cyan
  4026. break;
  4027. case TextColour::ReconstructedExpression:
  4028. std::cout << colourEscape << "[0;33m"; // yellow
  4029. break;
  4030. case TextColour::None:
  4031. std::cout << colourEscape << "[0m"; // reset
  4032. }
  4033. }
  4034. }
  4035. } // namespace Catch
  4036. #elif defined ( CATCH_PLATFORM_WINDOWS )
  4037. #include <windows.h>
  4038. namespace Catch {
  4039. namespace {
  4040. WORD mapConsoleColour( TextColour::Colours colour ) {
  4041. switch( colour ) {
  4042. case TextColour::FileName:
  4043. return FOREGROUND_INTENSITY; // greyed out
  4044. case TextColour::ResultError:
  4045. return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
  4046. case TextColour::ResultSuccess:
  4047. return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
  4048. case TextColour::Error:
  4049. return FOREGROUND_RED; // dark red
  4050. case TextColour::Success:
  4051. return FOREGROUND_GREEN; // dark green
  4052. case TextColour::OriginalExpression:
  4053. return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
  4054. case TextColour::ReconstructedExpression:
  4055. return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
  4056. default: return 0;
  4057. }
  4058. }
  4059. }
  4060. struct ConsoleColourImpl {
  4061. ConsoleColourImpl()
  4062. : hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
  4063. wOldColorAttrs( 0 )
  4064. {
  4065. GetConsoleScreenBufferInfo( hStdout, &csbiInfo );
  4066. wOldColorAttrs = csbiInfo.wAttributes;
  4067. }
  4068. ~ConsoleColourImpl() {
  4069. SetConsoleTextAttribute( hStdout, wOldColorAttrs );
  4070. }
  4071. void set( TextColour::Colours colour ) {
  4072. WORD consoleColour = mapConsoleColour( colour );
  4073. if( consoleColour > 0 )
  4074. SetConsoleTextAttribute( hStdout, consoleColour );
  4075. }
  4076. HANDLE hStdout;
  4077. CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
  4078. WORD wOldColorAttrs;
  4079. };
  4080. TextColour::TextColour( Colours colour )
  4081. : m_impl( new ConsoleColourImpl() )
  4082. {
  4083. if( colour )
  4084. m_impl->set( colour );
  4085. }
  4086. TextColour::~TextColour() {
  4087. delete m_impl;
  4088. }
  4089. void TextColour::set( Colours colour ) {
  4090. m_impl->set( colour );
  4091. }
  4092. } // end namespace Catch
  4093. #else
  4094. namespace Catch {
  4095. TextColour::TextColour( Colours ){}
  4096. TextColour::~TextColour(){}
  4097. void TextColour::set( Colours ){}
  4098. } // end namespace Catch
  4099. #endif
  4100. // #included from: catch_generators_impl.hpp
  4101. #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
  4102. #include <vector>
  4103. #include <string>
  4104. #include <map>
  4105. namespace Catch {
  4106. struct GeneratorInfo : IGeneratorInfo {
  4107. GeneratorInfo( std::size_t size )
  4108. : m_size( size ),
  4109. m_currentIndex( 0 )
  4110. {}
  4111. bool moveNext() {
  4112. if( ++m_currentIndex == m_size ) {
  4113. m_currentIndex = 0;
  4114. return false;
  4115. }
  4116. return true;
  4117. }
  4118. std::size_t getCurrentIndex() const {
  4119. return m_currentIndex;
  4120. }
  4121. std::size_t m_size;
  4122. std::size_t m_currentIndex;
  4123. };
  4124. ///////////////////////////////////////////////////////////////////////////
  4125. class GeneratorsForTest : public IGeneratorsForTest {
  4126. public:
  4127. ~GeneratorsForTest() {
  4128. deleteAll( m_generatorsInOrder );
  4129. }
  4130. IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
  4131. std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
  4132. if( it == m_generatorsByName.end() ) {
  4133. IGeneratorInfo* info = new GeneratorInfo( size );
  4134. m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
  4135. m_generatorsInOrder.push_back( info );
  4136. return *info;
  4137. }
  4138. return *it->second;
  4139. }
  4140. bool moveNext() {
  4141. std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
  4142. std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
  4143. for(; it != itEnd; ++it ) {
  4144. if( (*it)->moveNext() )
  4145. return true;
  4146. }
  4147. return false;
  4148. }
  4149. private:
  4150. std::map<std::string, IGeneratorInfo*> m_generatorsByName;
  4151. std::vector<IGeneratorInfo*> m_generatorsInOrder;
  4152. };
  4153. IGeneratorsForTest* createGeneratorsForTest()
  4154. {
  4155. return new GeneratorsForTest();
  4156. }
  4157. } // end namespace Catch
  4158. // #included from: catch_assertionresult.hpp
  4159. #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
  4160. namespace Catch {
  4161. AssertionInfo::AssertionInfo( const std::string& _macroName,
  4162. const SourceLineInfo& _lineInfo,
  4163. const std::string& _capturedExpression,
  4164. ResultDisposition::Flags _resultDisposition )
  4165. : macroName( _macroName ),
  4166. lineInfo( _lineInfo ),
  4167. capturedExpression( _capturedExpression ),
  4168. resultDisposition( _resultDisposition )
  4169. {
  4170. if( shouldNegate( resultDisposition ) )
  4171. capturedExpression = "!" + _capturedExpression;
  4172. }
  4173. AssertionResult::AssertionResult() {}
  4174. AssertionResult::AssertionResult( const AssertionInfo& info, const AssertionResultData& data )
  4175. : m_info( info ),
  4176. m_resultData( data )
  4177. {}
  4178. AssertionResult::~AssertionResult() {}
  4179. // Result was a success
  4180. bool AssertionResult::succeeded() const {
  4181. return Catch::isOk( m_resultData.resultType );
  4182. }
  4183. // Result was a success, or failure is suppressed
  4184. bool AssertionResult::isOk() const {
  4185. return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
  4186. }
  4187. ResultWas::OfType AssertionResult::getResultType() const {
  4188. return m_resultData.resultType;
  4189. }
  4190. bool AssertionResult::hasExpression() const {
  4191. return !m_info.capturedExpression.empty();
  4192. }
  4193. bool AssertionResult::hasMessage() const {
  4194. return !m_resultData.message.empty();
  4195. }
  4196. std::string AssertionResult::getExpression() const {
  4197. return m_info.capturedExpression;
  4198. }
  4199. bool AssertionResult::hasExpandedExpression() const {
  4200. return hasExpression() && getExpandedExpression() != getExpression();
  4201. }
  4202. std::string AssertionResult::getExpandedExpression() const {
  4203. return m_resultData.reconstructedExpression;
  4204. }
  4205. std::string AssertionResult::getMessage() const {
  4206. return m_resultData.message;
  4207. }
  4208. SourceLineInfo AssertionResult::getSourceInfo() const {
  4209. return m_info.lineInfo;
  4210. }
  4211. std::string AssertionResult::getTestMacroName() const {
  4212. return m_info.macroName;
  4213. }
  4214. } // end namespace Catch
  4215. // #included from: catch_expressionresult_builder.hpp
  4216. #define TWOBLUECUBES_CATCH_EXPRESSIONRESULT_BUILDER_HPP_INCLUDED
  4217. #include <assert.h>
  4218. namespace Catch {
  4219. ExpressionResultBuilder::ExpressionResultBuilder( ResultWas::OfType resultType ) {
  4220. m_data.resultType = resultType;
  4221. }
  4222. ExpressionResultBuilder::ExpressionResultBuilder( const ExpressionResultBuilder& other )
  4223. : m_data( other.m_data ),
  4224. m_exprComponents( other.m_exprComponents )
  4225. {
  4226. m_stream << other.m_stream.str();
  4227. }
  4228. ExpressionResultBuilder& ExpressionResultBuilder::operator=(const ExpressionResultBuilder& other ) {
  4229. m_data = other.m_data;
  4230. m_exprComponents = other.m_exprComponents;
  4231. m_stream.str("");
  4232. m_stream << other.m_stream.str();
  4233. return *this;
  4234. }
  4235. ExpressionResultBuilder& ExpressionResultBuilder::setResultType( ResultWas::OfType result ) {
  4236. m_data.resultType = result;
  4237. return *this;
  4238. }
  4239. ExpressionResultBuilder& ExpressionResultBuilder::setResultType( bool result ) {
  4240. m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
  4241. return *this;
  4242. }
  4243. ExpressionResultBuilder& ExpressionResultBuilder::endExpression( ResultDisposition::Flags resultDisposition ) {
  4244. m_exprComponents.shouldNegate = shouldNegate( resultDisposition );
  4245. return *this;
  4246. }
  4247. ExpressionResultBuilder& ExpressionResultBuilder::setLhs( const std::string& lhs ) {
  4248. m_exprComponents.lhs = lhs;
  4249. return *this;
  4250. }
  4251. ExpressionResultBuilder& ExpressionResultBuilder::setRhs( const std::string& rhs ) {
  4252. m_exprComponents.rhs = rhs;
  4253. return *this;
  4254. }
  4255. ExpressionResultBuilder& ExpressionResultBuilder::setOp( const std::string& op ) {
  4256. m_exprComponents.op = op;
  4257. return *this;
  4258. }
  4259. AssertionResult ExpressionResultBuilder::buildResult( const AssertionInfo& info ) const
  4260. {
  4261. assert( m_data.resultType != ResultWas::Unknown );
  4262. AssertionResultData data = m_data;
  4263. // Flip bool results if shouldNegate is set
  4264. if( m_exprComponents.shouldNegate && data.resultType == ResultWas::Ok )
  4265. data.resultType = ResultWas::ExpressionFailed;
  4266. else if( m_exprComponents.shouldNegate && data.resultType == ResultWas::ExpressionFailed )
  4267. data.resultType = ResultWas::Ok;
  4268. data.message = m_stream.str();
  4269. data.reconstructedExpression = reconstructExpression( info );
  4270. if( m_exprComponents.shouldNegate ) {
  4271. if( m_exprComponents.op == "" )
  4272. data.reconstructedExpression = "!" + data.reconstructedExpression;
  4273. else
  4274. data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
  4275. }
  4276. return AssertionResult( info, data );
  4277. }
  4278. std::string ExpressionResultBuilder::reconstructExpression( const AssertionInfo& info ) const {
  4279. if( m_exprComponents.op == "" )
  4280. return m_exprComponents.lhs.empty() ? info.capturedExpression : m_exprComponents.op + m_exprComponents.lhs;
  4281. else if( m_exprComponents.op == "matches" )
  4282. return m_exprComponents.lhs + " " + m_exprComponents.rhs;
  4283. else if( m_exprComponents.op != "!" ) {
  4284. if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 30 )
  4285. return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs;
  4286. else if( m_exprComponents.lhs.size() < 70 && m_exprComponents.rhs.size() < 70 )
  4287. return "\n\t" + m_exprComponents.lhs + "\n\t" + m_exprComponents.op + "\n\t" + m_exprComponents.rhs;
  4288. else
  4289. return "\n" + m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs + "\n\n";
  4290. }
  4291. else
  4292. return "{can't expand - use " + info.macroName + "_FALSE( " + info.capturedExpression.substr(1) + " ) instead of " + info.macroName + "( " + info.capturedExpression + " ) for better diagnostics}";
  4293. }
  4294. } // end namespace Catch
  4295. // #included from: catch_test_case_info.hpp
  4296. #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
  4297. namespace Catch {
  4298. TestCaseInfo::TestCaseInfo( ITestCase* testCase,
  4299. const std::string& className,
  4300. const std::string& name,
  4301. const std::string& description,
  4302. const SourceLineInfo& lineInfo )
  4303. : m_test( testCase ),
  4304. m_className( className ),
  4305. m_name( name ),
  4306. m_description( description ),
  4307. m_lineInfo( lineInfo ),
  4308. m_isHidden( startsWith( name, "./" ) )
  4309. {
  4310. TagExtracter( m_tags ).parse( m_description );
  4311. if( hasTag( "hide" ) )
  4312. m_isHidden = true;
  4313. }
  4314. TestCaseInfo::TestCaseInfo()
  4315. : m_test( NULL ),
  4316. m_className(),
  4317. m_name(),
  4318. m_description(),
  4319. m_isHidden( false )
  4320. {}
  4321. TestCaseInfo::TestCaseInfo( const TestCaseInfo& other, const std::string& name )
  4322. : m_test( other.m_test ),
  4323. m_className( other.m_className ),
  4324. m_name( name ),
  4325. m_description( other.m_description ),
  4326. m_tags( other.m_tags ),
  4327. m_lineInfo( other.m_lineInfo ),
  4328. m_isHidden( other.m_isHidden )
  4329. {}
  4330. TestCaseInfo::TestCaseInfo( const TestCaseInfo& other )
  4331. : m_test( other.m_test ),
  4332. m_className( other.m_className ),
  4333. m_name( other.m_name ),
  4334. m_description( other.m_description ),
  4335. m_tags( other.m_tags ),
  4336. m_lineInfo( other.m_lineInfo ),
  4337. m_isHidden( other.m_isHidden )
  4338. {}
  4339. void TestCaseInfo::invoke() const {
  4340. m_test->invoke();
  4341. }
  4342. const std::string& TestCaseInfo::getClassName() const {
  4343. return m_className;
  4344. }
  4345. const std::string& TestCaseInfo::getName() const {
  4346. return m_name;
  4347. }
  4348. const std::string& TestCaseInfo::getDescription() const {
  4349. return m_description;
  4350. }
  4351. const SourceLineInfo& TestCaseInfo::getLineInfo() const {
  4352. return m_lineInfo;
  4353. }
  4354. bool TestCaseInfo::isHidden() const {
  4355. return m_isHidden;
  4356. }
  4357. bool TestCaseInfo::hasTag( const std::string& tag ) const {
  4358. return m_tags.find( tag ) != m_tags.end();
  4359. }
  4360. bool TestCaseInfo::matchesTags( const std::string& tagPattern ) const {
  4361. TagExpression exp;
  4362. TagExpressionParser( exp ).parse( tagPattern );
  4363. return exp.matches( m_tags );
  4364. }
  4365. const std::set<std::string>& TestCaseInfo::getTags() const {
  4366. return m_tags;
  4367. }
  4368. void TestCaseInfo::swap( TestCaseInfo& other ) {
  4369. m_test.swap( other.m_test );
  4370. m_className.swap( other.m_className );
  4371. m_name.swap( other.m_name );
  4372. m_description.swap( other.m_description );
  4373. std::swap( m_lineInfo, other.m_lineInfo );
  4374. }
  4375. bool TestCaseInfo::operator == ( const TestCaseInfo& other ) const {
  4376. return m_test.get() == other.m_test.get() &&
  4377. m_name == other.m_name &&
  4378. m_className == other.m_className;
  4379. }
  4380. bool TestCaseInfo::operator < ( const TestCaseInfo& other ) const {
  4381. return m_name < other.m_name;
  4382. }
  4383. TestCaseInfo& TestCaseInfo::operator = ( const TestCaseInfo& other ) {
  4384. TestCaseInfo temp( other );
  4385. swap( temp );
  4386. return *this;
  4387. }
  4388. } // end namespace Catch
  4389. // #included from: ../reporters/catch_reporter_basic.hpp
  4390. #define TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED
  4391. // #included from: ../internal/catch_reporter_registrars.hpp
  4392. #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
  4393. namespace Catch {
  4394. template<typename T>
  4395. class ReporterRegistrar {
  4396. class ReporterFactory : public IReporterFactory {
  4397. virtual IReporter* create( const ReporterConfig& config ) const {
  4398. return new T( config );
  4399. }
  4400. virtual std::string getDescription() const {
  4401. return T::getDescription();
  4402. }
  4403. };
  4404. public:
  4405. ReporterRegistrar( const std::string& name ) {
  4406. getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
  4407. }
  4408. };
  4409. }
  4410. #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
  4411. Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name );
  4412. namespace Catch {
  4413. class BasicReporter : public SharedImpl<IReporter> {
  4414. struct SpanInfo {
  4415. SpanInfo()
  4416. : emitted( false )
  4417. {}
  4418. SpanInfo( const std::string& spanName )
  4419. : name( spanName ),
  4420. emitted( false )
  4421. {}
  4422. SpanInfo( const SpanInfo& other )
  4423. : name( other.name ),
  4424. emitted( other.emitted )
  4425. {}
  4426. std::string name;
  4427. bool emitted;
  4428. };
  4429. public:
  4430. BasicReporter( const ReporterConfig& config )
  4431. : m_config( config ),
  4432. m_firstSectionInTestCase( true ),
  4433. m_aborted( false )
  4434. {}
  4435. virtual ~BasicReporter();
  4436. static std::string getDescription() {
  4437. return "Reports test results as lines of text";
  4438. }
  4439. private:
  4440. void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) {
  4441. if( counts.passed )
  4442. m_config.stream << counts.failed << " of " << counts.total() << " " << label << "s failed";
  4443. else
  4444. m_config.stream << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
  4445. }
  4446. void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) {
  4447. if( totals.assertions.total() == 0 ) {
  4448. m_config.stream << "No tests ran";
  4449. }
  4450. else if( totals.assertions.failed ) {
  4451. TextColour colour( TextColour::ResultError );
  4452. ReportCounts( "test case", totals.testCases, allPrefix );
  4453. if( totals.testCases.failed > 0 ) {
  4454. m_config.stream << " (";
  4455. ReportCounts( "assertion", totals.assertions, allPrefix );
  4456. m_config.stream << ")";
  4457. }
  4458. }
  4459. else {
  4460. TextColour colour( TextColour::ResultSuccess );
  4461. m_config.stream << allPrefix << "tests passed ("
  4462. << pluralise( totals.assertions.passed, "assertion" ) << " in "
  4463. << pluralise( totals.testCases.passed, "test case" ) << ")";
  4464. }
  4465. }
  4466. private: // IReporter
  4467. virtual bool shouldRedirectStdout() const {
  4468. return false;
  4469. }
  4470. virtual void StartTesting() {
  4471. m_testingSpan = SpanInfo();
  4472. }
  4473. virtual void Aborted() {
  4474. m_aborted = true;
  4475. }
  4476. virtual void EndTesting( const Totals& totals ) {
  4477. // Output the overall test results even if "Started Testing" was not emitted
  4478. if( m_aborted ) {
  4479. m_config.stream << "\n[Testing aborted. ";
  4480. ReportCounts( totals, "The first " );
  4481. }
  4482. else {
  4483. m_config.stream << "\n[Testing completed. ";
  4484. ReportCounts( totals );
  4485. }
  4486. m_config.stream << "]\n" << std::endl;
  4487. }
  4488. virtual void StartGroup( const std::string& groupName ) {
  4489. m_groupSpan = groupName;
  4490. }
  4491. virtual void EndGroup( const std::string& groupName, const Totals& totals ) {
  4492. if( m_groupSpan.emitted && !groupName.empty() ) {
  4493. m_config.stream << "[End of group: '" << groupName << "'. ";
  4494. ReportCounts( totals );
  4495. m_config.stream << "]\n" << std::endl;
  4496. m_groupSpan = SpanInfo();
  4497. }
  4498. }
  4499. virtual void StartTestCase( const TestCaseInfo& testInfo ) {
  4500. m_testSpan = testInfo.getName();
  4501. }
  4502. virtual void StartSection( const std::string& sectionName, const std::string& ) {
  4503. m_sectionSpans.push_back( SpanInfo( sectionName ) );
  4504. }
  4505. virtual void NoAssertionsInSection( const std::string& sectionName ) {
  4506. startSpansLazily();
  4507. TextColour colour( TextColour::ResultError );
  4508. m_config.stream << "\nNo assertions in section, '" << sectionName << "'\n" << std::endl;
  4509. }
  4510. virtual void NoAssertionsInTestCase( const std::string& testName ) {
  4511. startSpansLazily();
  4512. TextColour colour( TextColour::ResultError );
  4513. m_config.stream << "\nNo assertions in test case, '" << testName << "'\n" << std::endl;
  4514. }
  4515. virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
  4516. SpanInfo& sectionSpan = m_sectionSpans.back();
  4517. if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
  4518. m_config.stream << "[End of section: '" << sectionName << "' ";
  4519. if( assertions.failed ) {
  4520. TextColour colour( TextColour::ResultError );
  4521. ReportCounts( "assertion", assertions);
  4522. }
  4523. else {
  4524. TextColour colour( TextColour::ResultSuccess );
  4525. m_config.stream << ( assertions.passed > 1 ? "All " : "" )
  4526. << pluralise( assertions.passed, "assertion" ) << " passed" ;
  4527. }
  4528. m_config.stream << "]\n" << std::endl;
  4529. }
  4530. m_sectionSpans.pop_back();
  4531. }
  4532. virtual void Result( const AssertionResult& assertionResult ) {
  4533. if( !m_config.includeSuccessfulResults && assertionResult.getResultType() == ResultWas::Ok )
  4534. return;
  4535. startSpansLazily();
  4536. if( !assertionResult.getSourceInfo().empty() ) {
  4537. TextColour colour( TextColour::FileName );
  4538. m_config.stream << assertionResult.getSourceInfo();
  4539. }
  4540. if( assertionResult.hasExpression() ) {
  4541. TextColour colour( TextColour::OriginalExpression );
  4542. m_config.stream << assertionResult.getExpression();
  4543. if( assertionResult.succeeded() ) {
  4544. TextColour successColour( TextColour::Success );
  4545. m_config.stream << " succeeded";
  4546. }
  4547. else {
  4548. TextColour errorColour( TextColour::Error );
  4549. m_config.stream << " failed";
  4550. if( assertionResult.isOk() ) {
  4551. TextColour okAnywayColour( TextColour::Success );
  4552. m_config.stream << " - but was ok";
  4553. }
  4554. }
  4555. }
  4556. switch( assertionResult.getResultType() ) {
  4557. case ResultWas::ThrewException:
  4558. {
  4559. TextColour colour( TextColour::Error );
  4560. if( assertionResult.hasExpression() )
  4561. m_config.stream << " with unexpected";
  4562. else
  4563. m_config.stream << "Unexpected";
  4564. m_config.stream << " exception with message: '" << assertionResult.getMessage() << "'";
  4565. }
  4566. break;
  4567. case ResultWas::DidntThrowException:
  4568. {
  4569. TextColour colour( TextColour::Error );
  4570. if( assertionResult.hasExpression() )
  4571. m_config.stream << " because no exception was thrown where one was expected";
  4572. else
  4573. m_config.stream << "No exception thrown where one was expected";
  4574. }
  4575. break;
  4576. case ResultWas::Info:
  4577. {
  4578. TextColour colour( TextColour::ReconstructedExpression );
  4579. streamVariableLengthText( "info", assertionResult.getMessage() );
  4580. }
  4581. break;
  4582. case ResultWas::Warning:
  4583. {
  4584. TextColour colour( TextColour::ReconstructedExpression );
  4585. streamVariableLengthText( "warning", assertionResult.getMessage() );
  4586. }
  4587. break;
  4588. case ResultWas::ExplicitFailure:
  4589. {
  4590. TextColour colour( TextColour::Error );
  4591. m_config.stream << "failed with message: '" << assertionResult.getMessage() << "'";
  4592. }
  4593. break;
  4594. case ResultWas::Unknown: // These cases are here to prevent compiler warnings
  4595. case ResultWas::Ok:
  4596. case ResultWas::FailureBit:
  4597. case ResultWas::ExpressionFailed:
  4598. case ResultWas::Exception:
  4599. if( !assertionResult.hasExpression() ) {
  4600. if( assertionResult.succeeded() ) {
  4601. TextColour colour( TextColour::Success );
  4602. m_config.stream << " succeeded";
  4603. }
  4604. else {
  4605. TextColour colour( TextColour::Error );
  4606. m_config.stream << " failed";
  4607. if( assertionResult.isOk() ) {
  4608. TextColour okAnywayColour( TextColour::Success );
  4609. m_config.stream << " - but was ok";
  4610. }
  4611. }
  4612. }
  4613. break;
  4614. }
  4615. if( assertionResult.hasExpandedExpression() ) {
  4616. m_config.stream << " for: ";
  4617. if( assertionResult.getExpandedExpression().size() > 40 ) {
  4618. m_config.stream << "\n";
  4619. if( assertionResult.getExpandedExpression().size() < 70 )
  4620. m_config.stream << "\t";
  4621. }
  4622. TextColour colour( TextColour::ReconstructedExpression );
  4623. m_config.stream << assertionResult.getExpandedExpression();
  4624. }
  4625. m_config.stream << std::endl;
  4626. }
  4627. virtual void EndTestCase( const TestCaseInfo& testInfo,
  4628. const Totals& totals,
  4629. const std::string& stdOut,
  4630. const std::string& stdErr ) {
  4631. if( !stdOut.empty() ) {
  4632. startSpansLazily();
  4633. streamVariableLengthText( "stdout", stdOut );
  4634. }
  4635. if( !stdErr.empty() ) {
  4636. startSpansLazily();
  4637. streamVariableLengthText( "stderr", stdErr );
  4638. }
  4639. if( m_testSpan.emitted ) {
  4640. m_config.stream << "[Finished: '" << testInfo.getName() << "' ";
  4641. ReportCounts( totals );
  4642. m_config.stream << "]" << std::endl;
  4643. }
  4644. }
  4645. private: // helpers
  4646. void startSpansLazily() {
  4647. if( !m_testingSpan.emitted ) {
  4648. if( m_config.name.empty() )
  4649. m_config.stream << "[Started testing]" << std::endl;
  4650. else
  4651. m_config.stream << "[Started testing: " << m_config.name << "]" << std::endl;
  4652. m_testingSpan.emitted = true;
  4653. }
  4654. if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) {
  4655. m_config.stream << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
  4656. m_groupSpan.emitted = true;
  4657. }
  4658. if( !m_testSpan.emitted ) {
  4659. m_config.stream << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
  4660. m_testSpan.emitted = true;
  4661. }
  4662. if( !m_sectionSpans.empty() ) {
  4663. SpanInfo& sectionSpan = m_sectionSpans.back();
  4664. if( !sectionSpan.emitted && !sectionSpan.name.empty() ) {
  4665. if( m_firstSectionInTestCase ) {
  4666. m_config.stream << "\n";
  4667. m_firstSectionInTestCase = false;
  4668. }
  4669. std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
  4670. std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end();
  4671. for(; it != itEnd; ++it ) {
  4672. SpanInfo& prevSpan = *it;
  4673. if( !prevSpan.emitted && !prevSpan.name.empty() ) {
  4674. m_config.stream << "[Started section: '" << prevSpan.name << "']" << std::endl;
  4675. prevSpan.emitted = true;
  4676. }
  4677. }
  4678. }
  4679. }
  4680. }
  4681. void streamVariableLengthText( const std::string& prefix, const std::string& text ) {
  4682. std::string trimmed = trim( text );
  4683. if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) {
  4684. m_config.stream << "[" << prefix << ": " << trimmed << "]";
  4685. }
  4686. else {
  4687. m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
  4688. << "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n";
  4689. }
  4690. }
  4691. private:
  4692. ReporterConfig m_config;
  4693. bool m_firstSectionInTestCase;
  4694. SpanInfo m_testingSpan;
  4695. SpanInfo m_groupSpan;
  4696. SpanInfo m_testSpan;
  4697. std::vector<SpanInfo> m_sectionSpans;
  4698. bool m_aborted;
  4699. };
  4700. } // end namespace Catch
  4701. // #included from: ../reporters/catch_reporter_xml.hpp
  4702. #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
  4703. // #included from: ../internal/catch_xmlwriter.hpp
  4704. #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
  4705. #include <sstream>
  4706. #include <iostream>
  4707. #include <string>
  4708. #include <vector>
  4709. namespace Catch {
  4710. class XmlWriter {
  4711. public:
  4712. class ScopedElement {
  4713. public:
  4714. ScopedElement( XmlWriter* writer )
  4715. : m_writer( writer )
  4716. {}
  4717. ScopedElement( const ScopedElement& other )
  4718. : m_writer( other.m_writer ){
  4719. other.m_writer = NULL;
  4720. }
  4721. ~ScopedElement() {
  4722. if( m_writer )
  4723. m_writer->endElement();
  4724. }
  4725. ScopedElement& writeText( const std::string& text ) {
  4726. m_writer->writeText( text );
  4727. return *this;
  4728. }
  4729. template<typename T>
  4730. ScopedElement& writeAttribute( const std::string& name, const T& attribute ) {
  4731. m_writer->writeAttribute( name, attribute );
  4732. return *this;
  4733. }
  4734. private:
  4735. mutable XmlWriter* m_writer;
  4736. };
  4737. XmlWriter()
  4738. : m_tagIsOpen( false ),
  4739. m_needsNewline( false ),
  4740. m_os( &std::cout )
  4741. {}
  4742. XmlWriter( std::ostream& os )
  4743. : m_tagIsOpen( false ),
  4744. m_needsNewline( false ),
  4745. m_os( &os )
  4746. {}
  4747. ~XmlWriter() {
  4748. while( !m_tags.empty() )
  4749. endElement();
  4750. }
  4751. XmlWriter& operator = ( const XmlWriter& other ) {
  4752. XmlWriter temp( other );
  4753. swap( temp );
  4754. return *this;
  4755. }
  4756. void swap( XmlWriter& other ) {
  4757. std::swap( m_tagIsOpen, other.m_tagIsOpen );
  4758. std::swap( m_needsNewline, other.m_needsNewline );
  4759. std::swap( m_tags, other.m_tags );
  4760. std::swap( m_indent, other.m_indent );
  4761. std::swap( m_os, other.m_os );
  4762. }
  4763. XmlWriter& startElement( const std::string& name ) {
  4764. ensureTagClosed();
  4765. newlineIfNecessary();
  4766. stream() << m_indent << "<" << name;
  4767. m_tags.push_back( name );
  4768. m_indent += " ";
  4769. m_tagIsOpen = true;
  4770. return *this;
  4771. }
  4772. ScopedElement scopedElement( const std::string& name ) {
  4773. ScopedElement scoped( this );
  4774. startElement( name );
  4775. return scoped;
  4776. }
  4777. XmlWriter& endElement() {
  4778. newlineIfNecessary();
  4779. m_indent = m_indent.substr( 0, m_indent.size()-2 );
  4780. if( m_tagIsOpen ) {
  4781. stream() << "/>\n";
  4782. m_tagIsOpen = false;
  4783. }
  4784. else {
  4785. stream() << m_indent << "</" << m_tags.back() << ">\n";
  4786. }
  4787. m_tags.pop_back();
  4788. return *this;
  4789. }
  4790. XmlWriter& writeAttribute( const std::string& name, const std::string& attribute ) {
  4791. if( !name.empty() && !attribute.empty() ) {
  4792. stream() << " " << name << "=\"";
  4793. writeEncodedText( attribute );
  4794. stream() << "\"";
  4795. }
  4796. return *this;
  4797. }
  4798. XmlWriter& writeAttribute( const std::string& name, bool attribute ) {
  4799. stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\"";
  4800. return *this;
  4801. }
  4802. template<typename T>
  4803. XmlWriter& writeAttribute( const std::string& name, const T& attribute ) {
  4804. if( !name.empty() )
  4805. stream() << " " << name << "=\"" << attribute << "\"";
  4806. return *this;
  4807. }
  4808. XmlWriter& writeText( const std::string& text ) {
  4809. if( !text.empty() ){
  4810. bool tagWasOpen = m_tagIsOpen;
  4811. ensureTagClosed();
  4812. if( tagWasOpen )
  4813. stream() << m_indent;
  4814. writeEncodedText( text );
  4815. m_needsNewline = true;
  4816. }
  4817. return *this;
  4818. }
  4819. XmlWriter& writeComment( const std::string& text ) {
  4820. ensureTagClosed();
  4821. stream() << m_indent << "<!--" << text << "-->";
  4822. m_needsNewline = true;
  4823. return *this;
  4824. }
  4825. XmlWriter& writeBlankLine() {
  4826. ensureTagClosed();
  4827. stream() << "\n";
  4828. return *this;
  4829. }
  4830. private:
  4831. std::ostream& stream() {
  4832. return *m_os;
  4833. }
  4834. void ensureTagClosed() {
  4835. if( m_tagIsOpen ) {
  4836. stream() << ">\n";
  4837. m_tagIsOpen = false;
  4838. }
  4839. }
  4840. void newlineIfNecessary() {
  4841. if( m_needsNewline ) {
  4842. stream() << "\n";
  4843. m_needsNewline = false;
  4844. }
  4845. }
  4846. void writeEncodedText( const std::string& text ) {
  4847. static const char* charsToEncode = "<&\"";
  4848. std::string mtext = text;
  4849. std::string::size_type pos = mtext.find_first_of( charsToEncode );
  4850. while( pos != std::string::npos ) {
  4851. stream() << mtext.substr( 0, pos );
  4852. switch( mtext[pos] ) {
  4853. case '<':
  4854. stream() << "&lt;";
  4855. break;
  4856. case '&':
  4857. stream() << "&amp;";
  4858. break;
  4859. case '\"':
  4860. stream() << "&quot;";
  4861. break;
  4862. }
  4863. mtext = mtext.substr( pos+1 );
  4864. pos = mtext.find_first_of( charsToEncode );
  4865. }
  4866. stream() << mtext;
  4867. }
  4868. bool m_tagIsOpen;
  4869. bool m_needsNewline;
  4870. std::vector<std::string> m_tags;
  4871. std::string m_indent;
  4872. std::ostream* m_os;
  4873. };
  4874. }
  4875. namespace Catch {
  4876. class XmlReporter : public SharedImpl<IReporter> {
  4877. public:
  4878. XmlReporter( const ReporterConfig& config ) : m_config( config ) {}
  4879. static std::string getDescription() {
  4880. return "Reports test results as an XML document";
  4881. }
  4882. virtual ~XmlReporter();
  4883. private: // IReporter
  4884. virtual bool shouldRedirectStdout() const {
  4885. return true;
  4886. }
  4887. virtual void StartTesting() {
  4888. m_xml = XmlWriter( m_config.stream );
  4889. m_xml.startElement( "Catch" );
  4890. if( !m_config.name.empty() )
  4891. m_xml.writeAttribute( "name", m_config.name );
  4892. }
  4893. virtual void EndTesting( const Totals& totals ) {
  4894. m_xml.scopedElement( "OverallResults" )
  4895. .writeAttribute( "successes", totals.assertions.passed )
  4896. .writeAttribute( "failures", totals.assertions.failed );
  4897. m_xml.endElement();
  4898. }
  4899. virtual void StartGroup( const std::string& groupName ) {
  4900. m_xml.startElement( "Group" )
  4901. .writeAttribute( "name", groupName );
  4902. }
  4903. virtual void EndGroup( const std::string&, const Totals& totals ) {
  4904. m_xml.scopedElement( "OverallResults" )
  4905. .writeAttribute( "successes", totals.assertions.passed )
  4906. .writeAttribute( "failures", totals.assertions.failed );
  4907. m_xml.endElement();
  4908. }
  4909. virtual void StartSection( const std::string& sectionName, const std::string& description ) {
  4910. m_xml.startElement( "Section" )
  4911. .writeAttribute( "name", sectionName )
  4912. .writeAttribute( "description", description );
  4913. }
  4914. virtual void NoAssertionsInSection( const std::string& ) {}
  4915. virtual void NoAssertionsInTestCase( const std::string& ) {}
  4916. virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) {
  4917. m_xml.scopedElement( "OverallResults" )
  4918. .writeAttribute( "successes", assertions.passed )
  4919. .writeAttribute( "failures", assertions.failed );
  4920. m_xml.endElement();
  4921. }
  4922. virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
  4923. m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.getName() );
  4924. m_currentTestSuccess = true;
  4925. }
  4926. virtual void Result( const Catch::AssertionResult& assertionResult ) {
  4927. if( !m_config.includeSuccessfulResults && assertionResult.getResultType() == ResultWas::Ok )
  4928. return;
  4929. if( assertionResult.hasExpression() ) {
  4930. m_xml.startElement( "Expression" )
  4931. .writeAttribute( "success", assertionResult.succeeded() )
  4932. .writeAttribute( "filename", assertionResult.getSourceInfo().file )
  4933. .writeAttribute( "line", assertionResult.getSourceInfo().line );
  4934. m_xml.scopedElement( "Original" )
  4935. .writeText( assertionResult.getExpression() );
  4936. m_xml.scopedElement( "Expanded" )
  4937. .writeText( assertionResult.getExpandedExpression() );
  4938. m_currentTestSuccess &= assertionResult.succeeded();
  4939. }
  4940. switch( assertionResult.getResultType() ) {
  4941. case ResultWas::ThrewException:
  4942. m_xml.scopedElement( "Exception" )
  4943. .writeAttribute( "filename", assertionResult.getSourceInfo().file )
  4944. .writeAttribute( "line", assertionResult.getSourceInfo().line )
  4945. .writeText( assertionResult.getMessage() );
  4946. m_currentTestSuccess = false;
  4947. break;
  4948. case ResultWas::Info:
  4949. m_xml.scopedElement( "Info" )
  4950. .writeText( assertionResult.getMessage() );
  4951. break;
  4952. case ResultWas::Warning:
  4953. m_xml.scopedElement( "Warning" )
  4954. .writeText( assertionResult.getMessage() );
  4955. break;
  4956. case ResultWas::ExplicitFailure:
  4957. m_xml.scopedElement( "Failure" )
  4958. .writeText( assertionResult.getMessage() );
  4959. m_currentTestSuccess = false;
  4960. break;
  4961. case ResultWas::Unknown:
  4962. case ResultWas::Ok:
  4963. case ResultWas::FailureBit:
  4964. case ResultWas::ExpressionFailed:
  4965. case ResultWas::Exception:
  4966. case ResultWas::DidntThrowException:
  4967. break;
  4968. }
  4969. if( assertionResult.hasExpression() )
  4970. m_xml.endElement();
  4971. }
  4972. virtual void Aborted() {
  4973. // !TBD
  4974. }
  4975. virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string&, const std::string& ) {
  4976. m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess );
  4977. m_xml.endElement();
  4978. }
  4979. private:
  4980. ReporterConfig m_config;
  4981. bool m_currentTestSuccess;
  4982. XmlWriter m_xml;
  4983. };
  4984. } // end namespace Catch
  4985. // #included from: ../reporters/catch_reporter_junit.hpp
  4986. #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
  4987. namespace Catch {
  4988. class JunitReporter : public SharedImpl<IReporter> {
  4989. struct TestStats {
  4990. std::string m_element;
  4991. std::string m_resultType;
  4992. std::string m_message;
  4993. std::string m_content;
  4994. };
  4995. struct TestCaseStats {
  4996. TestCaseStats( const std::string& className, const std::string& name )
  4997. : m_className( className ),
  4998. m_name( name )
  4999. {}
  5000. double m_timeInSeconds;
  5001. std::string m_status;
  5002. std::string m_className;
  5003. std::string m_name;
  5004. std::vector<TestStats> m_testStats;
  5005. };
  5006. struct Stats {
  5007. Stats( const std::string& name = std::string() )
  5008. : m_testsCount( 0 ),
  5009. m_failuresCount( 0 ),
  5010. m_disabledCount( 0 ),
  5011. m_errorsCount( 0 ),
  5012. m_timeInSeconds( 0 ),
  5013. m_name( name )
  5014. {}
  5015. std::size_t m_testsCount;
  5016. std::size_t m_failuresCount;
  5017. std::size_t m_disabledCount;
  5018. std::size_t m_errorsCount;
  5019. double m_timeInSeconds;
  5020. std::string m_name;
  5021. std::vector<TestCaseStats> m_testCaseStats;
  5022. };
  5023. public:
  5024. JunitReporter( const ReporterConfig& config )
  5025. : m_config( config ),
  5026. m_testSuiteStats( "AllTests" ),
  5027. m_currentStats( &m_testSuiteStats )
  5028. {}
  5029. virtual ~JunitReporter();
  5030. static std::string getDescription() {
  5031. return "Reports test results in an XML format that looks like Ant's junitreport target";
  5032. }
  5033. private: // IReporter
  5034. virtual bool shouldRedirectStdout() const {
  5035. return true;
  5036. }
  5037. virtual void StartTesting(){}
  5038. virtual void StartGroup( const std::string& groupName ) {
  5039. m_statsForSuites.push_back( Stats( groupName ) );
  5040. m_currentStats = &m_statsForSuites.back();
  5041. }
  5042. virtual void EndGroup( const std::string&, const Totals& totals ) {
  5043. m_currentStats->m_testsCount = totals.assertions.total();
  5044. m_currentStats = &m_testSuiteStats;
  5045. }
  5046. virtual void StartSection( const std::string&, const std::string& ){}
  5047. virtual void NoAssertionsInSection( const std::string& ) {}
  5048. virtual void NoAssertionsInTestCase( const std::string& ) {}
  5049. virtual void EndSection( const std::string&, const Counts& ) {}
  5050. virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
  5051. m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getClassName(), testInfo.getName() ) );
  5052. }
  5053. virtual void Result( const Catch::AssertionResult& assertionResult ) {
  5054. if( assertionResult.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) {
  5055. TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
  5056. TestStats stats;
  5057. std::ostringstream oss;
  5058. if( !assertionResult.getMessage().empty() )
  5059. oss << assertionResult.getMessage() << " at ";
  5060. oss << assertionResult.getSourceInfo();
  5061. stats.m_content = oss.str();
  5062. stats.m_message = assertionResult.getExpandedExpression();
  5063. stats.m_resultType = assertionResult.getTestMacroName();
  5064. switch( assertionResult.getResultType() ) {
  5065. case ResultWas::ThrewException:
  5066. stats.m_element = "error";
  5067. m_currentStats->m_errorsCount++;
  5068. break;
  5069. case ResultWas::Info:
  5070. stats.m_element = "info"; // !TBD ?
  5071. break;
  5072. case ResultWas::Warning:
  5073. stats.m_element = "warning"; // !TBD ?
  5074. break;
  5075. case ResultWas::ExplicitFailure:
  5076. stats.m_element = "failure";
  5077. m_currentStats->m_failuresCount++;
  5078. break;
  5079. case ResultWas::ExpressionFailed:
  5080. stats.m_element = "failure";
  5081. m_currentStats->m_failuresCount++;
  5082. break;
  5083. case ResultWas::Ok:
  5084. stats.m_element = "success";
  5085. break;
  5086. case ResultWas::Unknown:
  5087. case ResultWas::FailureBit:
  5088. case ResultWas::Exception:
  5089. case ResultWas::DidntThrowException:
  5090. break;
  5091. }
  5092. testCaseStats.m_testStats.push_back( stats );
  5093. }
  5094. }
  5095. virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string& stdOut, const std::string& stdErr ) {
  5096. if( !stdOut.empty() )
  5097. m_stdOut << stdOut << "\n";
  5098. if( !stdErr.empty() )
  5099. m_stdErr << stdErr << "\n";
  5100. }
  5101. virtual void Aborted() {
  5102. // !TBD
  5103. }
  5104. virtual void EndTesting( const Totals& ) {
  5105. std::ostream& str = m_config.stream;
  5106. {
  5107. XmlWriter xml( str );
  5108. if( m_statsForSuites.size() > 0 )
  5109. xml.startElement( "testsuites" );
  5110. std::vector<Stats>::const_iterator it = m_statsForSuites.begin();
  5111. std::vector<Stats>::const_iterator itEnd = m_statsForSuites.end();
  5112. for(; it != itEnd; ++it ) {
  5113. XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
  5114. xml.writeAttribute( "name", it->m_name );
  5115. xml.writeAttribute( "errors", it->m_errorsCount );
  5116. xml.writeAttribute( "failures", it->m_failuresCount );
  5117. xml.writeAttribute( "tests", it->m_testsCount );
  5118. xml.writeAttribute( "hostname", "tbd" );
  5119. xml.writeAttribute( "time", "tbd" );
  5120. xml.writeAttribute( "timestamp", "tbd" );
  5121. OutputTestCases( xml, *it );
  5122. }
  5123. xml.scopedElement( "system-out" ).writeText( trim( m_stdOut.str() ) );
  5124. xml.scopedElement( "system-err" ).writeText( trim( m_stdErr.str() ) );
  5125. }
  5126. }
  5127. void OutputTestCases( XmlWriter& xml, const Stats& stats ) {
  5128. std::vector<TestCaseStats>::const_iterator it = stats.m_testCaseStats.begin();
  5129. std::vector<TestCaseStats>::const_iterator itEnd = stats.m_testCaseStats.end();
  5130. for(; it != itEnd; ++it ) {
  5131. xml.writeBlankLine();
  5132. xml.writeComment( "Test case" );
  5133. XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
  5134. xml.writeAttribute( "classname", it->m_className );
  5135. xml.writeAttribute( "name", it->m_name );
  5136. xml.writeAttribute( "time", "tbd" );
  5137. OutputTestResult( xml, *it );
  5138. }
  5139. }
  5140. void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats ) {
  5141. std::vector<TestStats>::const_iterator it = stats.m_testStats.begin();
  5142. std::vector<TestStats>::const_iterator itEnd = stats.m_testStats.end();
  5143. for(; it != itEnd; ++it ) {
  5144. if( it->m_element != "success" ) {
  5145. XmlWriter::ScopedElement e = xml.scopedElement( it->m_element );
  5146. xml.writeAttribute( "message", it->m_message );
  5147. xml.writeAttribute( "type", it->m_resultType );
  5148. if( !it->m_content.empty() )
  5149. xml.writeText( it->m_content );
  5150. }
  5151. }
  5152. }
  5153. private:
  5154. ReporterConfig m_config;
  5155. bool m_currentTestSuccess;
  5156. Stats m_testSuiteStats;
  5157. Stats* m_currentStats;
  5158. std::vector<Stats> m_statsForSuites;
  5159. std::ostringstream m_stdOut;
  5160. std::ostringstream m_stdErr;
  5161. };
  5162. } // end namespace Catch
  5163. namespace Catch {
  5164. NonCopyable::~NonCopyable() {}
  5165. IShared::~IShared() {}
  5166. StreamBufBase::~StreamBufBase() {}
  5167. IContext::~IContext() {}
  5168. IResultCapture::~IResultCapture() {}
  5169. ITestCase::~ITestCase() {}
  5170. ITestCaseRegistry::~ITestCaseRegistry() {}
  5171. IRegistryHub::~IRegistryHub() {}
  5172. IMutableRegistryHub::~IMutableRegistryHub() {}
  5173. IExceptionTranslator::~IExceptionTranslator() {}
  5174. IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
  5175. IReporter::~IReporter() {}
  5176. IReporterFactory::~IReporterFactory() {}
  5177. IReporterRegistry::~IReporterRegistry() {}
  5178. BasicReporter::~BasicReporter() {}
  5179. IRunner::~IRunner() {}
  5180. IMutableContext::~IMutableContext() {}
  5181. IConfig::~IConfig() {}
  5182. XmlReporter::~XmlReporter() {}
  5183. JunitReporter::~JunitReporter() {}
  5184. TestRegistry::~TestRegistry() {}
  5185. FreeFunctionTestCase::~FreeFunctionTestCase() {}
  5186. IGeneratorInfo::~IGeneratorInfo() {}
  5187. IGeneratorsForTest::~IGeneratorsForTest() {}
  5188. TagParser::~TagParser() {}
  5189. TagExtracter::~TagExtracter() {}
  5190. TagExpressionParser::~TagExpressionParser() {}
  5191. Matchers::Impl::StdString::Equals::~Equals() {}
  5192. Matchers::Impl::StdString::Contains::~Contains() {}
  5193. Matchers::Impl::StdString::StartsWith::~StartsWith() {}
  5194. Matchers::Impl::StdString::EndsWith::~EndsWith() {}
  5195. void Config::dummy() {}
  5196. INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter )
  5197. INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
  5198. INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
  5199. }
  5200. #ifdef __clang__
  5201. #pragma clang diagnostic pop
  5202. #endif
  5203. #endif
  5204. #ifdef CATCH_CONFIG_MAIN
  5205. // #included from: internal/catch_default_main.hpp
  5206. #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
  5207. #ifndef __OBJC__
  5208. // Standard C/C++ main entry point
  5209. int main (int argc, char * const argv[]) {
  5210. return Catch::Main( argc, argv );
  5211. }
  5212. #else // __OBJC__
  5213. // Objective-C entry point
  5214. int main (int argc, char * const argv[]) {
  5215. #if !CATCH_ARC_ENABLED
  5216. NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
  5217. #endif
  5218. Catch::registerTestMethods();
  5219. int result = Catch::Main( argc, (char* const*)argv );
  5220. #if !CATCH_ARC_ENABLED
  5221. [pool drain];
  5222. #endif
  5223. return result;
  5224. }
  5225. #endif // __OBJC__
  5226. #endif
  5227. //////
  5228. // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
  5229. #ifdef CATCH_CONFIG_PREFIX_ALL
  5230. #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" )
  5231. #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::NegateResult, "CATCH_REQUIRE_FALSE" )
  5232. #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS" )
  5233. #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
  5234. #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
  5235. #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
  5236. #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::NegateResult, "CATCH_CHECK_FALSE" )
  5237. #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" )
  5238. #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" )
  5239. #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" )
  5240. #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" )
  5241. #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
  5242. #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
  5243. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
  5244. #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" )
  5245. #define CATCH_INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "CATCH_INFO" )
  5246. #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN" )
  5247. #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL" )
  5248. #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED" )
  5249. #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "CATCH_SCOPED_INFO" )
  5250. #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CAPTURE" )
  5251. #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "CATCH_SCOPED_CAPTURE" )
  5252. #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  5253. #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  5254. #define CATCH_TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description )
  5255. #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "Anonymous test case" )
  5256. #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  5257. #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  5258. #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  5259. // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
  5260. #else
  5261. #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" )
  5262. #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::NegateResult, "REQUIRE_FALSE" )
  5263. #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., Catch::ResultDisposition::Normal, "REQUIRE_THROWS" )
  5264. #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
  5265. #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
  5266. #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
  5267. #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::NegateResult, "CHECK_FALSE" )
  5268. #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" )
  5269. #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" )
  5270. #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" )
  5271. #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS" )
  5272. #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
  5273. #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
  5274. #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
  5275. #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" )
  5276. #define INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "INFO" )
  5277. #define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN" )
  5278. #define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL" )
  5279. #define SUCCEED( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED" )
  5280. #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg, "SCOPED_INFO" )
  5281. #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, Catch::ResultDisposition::ContinueOnFailure, "CAPTURE" )
  5282. #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_SCOPED_INFO( #msg " := " << msg, "SCOPED_CAPTURE" )
  5283. #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
  5284. #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
  5285. #define TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description )
  5286. #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "Anonymous test case" )
  5287. #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
  5288. #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
  5289. #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
  5290. #endif
  5291. #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
  5292. using Catch::Detail::Approx;
  5293. #ifdef __clang__
  5294. #pragma clang diagnostic pop
  5295. #endif
  5296. #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED