catch.hpp 337 KB

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