catch.hpp 392 KB

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