[{"data":1,"prerenderedAt":275},["ShallowReactive",2],{"doc-event-listeners":3},{"id":4,"title":5,"body":6,"description":98,"extension":268,"meta":269,"navigation":127,"path":270,"seo":271,"slug":53,"source":272,"stem":273,"__hash__":274},"docs\u002Fdocs\u002Fevent-listeners.md","Event Listeners",{"type":7,"value":8,"toc":266},"minimark",[9,50,54,62,78,89,92,249,255,262],[10,11,12],"blockquote",{},[13,14,15,19,20,24,25,28,29,32,33,36,37,36,40,43,44,49],"p",{},[16,17,18],"strong",{},"Catch3 compatibility reference:"," This page describes the test-writing API Catch3 shares with Catch2: the macros, such as ",[21,22,23],"code",{},"TEST_CASE"," and ",[21,26,27],{},"REQUIRE",", and the ",[21,30,31],{},"Catch::"," namespace keep Catch2's names. Headers and build names are Catch3's own (",[21,34,35],{},"\u003CProgmasoft\u002FCatch3\u002FTestMacros.hpp>",", ",[21,38,39],{},"find_package(Catch3)",[21,41,42],{},"Catch3::Catch3WithMain","). See ",[45,46,48],"a",{"href":47},"\u002Fdocs\u002Fprogmasoft-catch3\u002F","Catch3 additions"," for Progmasoft APIs.",[51,52,5],"h1",{"id":53},"event-listeners",[13,55,56,57,61],{},"An event listener responds to the events of a test run, but it is not\nexpected to write the run's output; that is the job of the\n",[45,58,60],{"href":59},"\u002Fdocs\u002Freporters\u002F","reports",". Instead, an event listener performs actions\nwithin the test process, such as performing global initialization (e.g. of\na C library), or cleaning out in-memory logs if they are not needed (the\ntest case passed).",[13,63,64,65,69,70,73,74,77],{},"Every registered event listener is always active. The\n",[45,66,68],{"href":67},"\u002Fdocs\u002Fprogmasoft-runner\u002F","Catch3 runner"," runs tests in worker processes,\nand each worker is a test run of its own for its listeners: they are created\nin every worker, and see ",[21,71,72],{},"testRunStarting"," when it starts and ",[21,75,76],{},"testRunEnded","\nwhen it ends. What a listener prints outside a test reaches the runner's\nstandard error.",[13,79,80,81,84,85,88],{},"To write your own event listener, you should derive from ",[21,82,83],{},"Catch::EventListenerBase",",\nas it provides empty stubs for all reporter events, allowing you to\nonly override events you care for. Afterwards you have to register it\nwith Catch2 using ",[21,86,87],{},"CATCH_REGISTER_LISTENER"," macro, so that Catch2 knows\nabout it and instantiates it before running tests.",[13,90,91],{},"Example event listener:",[93,94,99],"pre",{"className":95,"code":96,"language":97,"meta":98,"style":98},"language-cpp shiki shiki-themes github-dark","#include \u003CProgmasoft\u002FCatch3\u002FReporters\u002FEventListener.hpp>\n#include \u003CProgmasoft\u002FCatch3\u002FReporters\u002FRegistrars.hpp>\n\nclass testRunListener : public Catch::EventListenerBase {\npublic:\n    using Catch::EventListenerBase::EventListenerBase;\n\n    void testRunStarting(Catch::TestRunInfo const&) override {\n        lib_foo_init();\n    }\n};\n\nCATCH_REGISTER_LISTENER(testRunListener)\n","cpp","",[21,100,101,114,122,129,158,164,179,184,215,224,230,236,241],{"__ignoreMap":98},[102,103,106,110],"span",{"class":104,"line":105},"line",1,[102,107,109],{"class":108},"snl16","#include",[102,111,113],{"class":112},"sU2Wk"," \u003CProgmasoft\u002FCatch3\u002FReporters\u002FEventListener.hpp>\n",[102,115,117,119],{"class":104,"line":116},2,[102,118,109],{"class":108},[102,120,121],{"class":112}," \u003CProgmasoft\u002FCatch3\u002FReporters\u002FRegistrars.hpp>\n",[102,123,125],{"class":104,"line":124},3,[102,126,128],{"emptyLinePlaceholder":127},true,"\n",[102,130,132,135,139,143,146,149,152,155],{"class":104,"line":131},4,[102,133,134],{"class":108},"class",[102,136,138],{"class":137},"svObZ"," testRunListener",[102,140,142],{"class":141},"s95oV"," : ",[102,144,145],{"class":108},"public",[102,147,148],{"class":137}," Catch",[102,150,151],{"class":141},"::",[102,153,154],{"class":137},"EventListenerBase",[102,156,157],{"class":141}," {\n",[102,159,161],{"class":104,"line":160},5,[102,162,163],{"class":108},"public:\n",[102,165,167,170,172,174,176],{"class":104,"line":166},6,[102,168,169],{"class":108},"    using",[102,171,148],{"class":137},[102,173,151],{"class":141},[102,175,154],{"class":137},[102,177,178],{"class":141},"::EventListenerBase;\n",[102,180,182],{"class":104,"line":181},7,[102,183,128],{"emptyLinePlaceholder":127},[102,185,187,190,193,196,199,201,204,207,210,213],{"class":104,"line":186},8,[102,188,189],{"class":108},"    void",[102,191,192],{"class":137}," testRunStarting",[102,194,195],{"class":141},"(",[102,197,198],{"class":137},"Catch",[102,200,151],{"class":141},[102,202,203],{"class":137},"TestRunInfo",[102,205,206],{"class":108}," const&",[102,208,209],{"class":141},") ",[102,211,212],{"class":108},"override",[102,214,157],{"class":141},[102,216,218,221],{"class":104,"line":217},9,[102,219,220],{"class":137},"        lib_foo_init",[102,222,223],{"class":141},"();\n",[102,225,227],{"class":104,"line":226},10,[102,228,229],{"class":141},"    }\n",[102,231,233],{"class":104,"line":232},11,[102,234,235],{"class":141},"};\n",[102,237,239],{"class":104,"line":238},12,[102,240,128],{"emptyLinePlaceholder":127},[102,242,244,246],{"class":104,"line":243},13,[102,245,87],{"class":137},[102,247,248],{"class":141},"(testRunListener)\n",[13,250,251],{},[252,253,254],"em",{},"Note that you should not use any assertion macros within a Listener!",[13,256,257,261],{},[45,258,260],{"href":259},"\u002Fdocs\u002Freporter-events\u002F","You can find the list of events that the listeners can react to on its\nown page",".",[263,264,265],"style",{},"html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html pre.shiki code .svObZ, html code.shiki .svObZ{--shiki-default:#B392F0}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":98,"searchDepth":116,"depth":116,"links":267},[],"md",{},"\u002Fdocs\u002Fevent-listeners",{"title":5,"description":98},"docs\u002Fevent-listeners.md","docs\u002Fevent-listeners","E-G0D1_7eR8Fog_jdhMerQdgR2em_wW8fC8_eeOcVWA",1794961594216]