catch.hpp 413 KB

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