import{_ as i,c as e,o as t,ae as a}from"./chunks/framework.l7bN90nj.js";const r=JSON.parse('{"title":"Test and Debug","description":"","frontmatter":{},"headers":[],"relativePath":"dev/test-and-debug.md","filePath":"en/dev/test-and-debug.md"}'),n={name:"dev/test-and-debug.md"};function l(h,s,p,o,d,c){return t(),e("div",null,[...s[0]||(s[0]=[a(`<h1 id="test-and-debug" tabindex="-1">Test and Debug <a class="header-anchor" href="#test-and-debug" aria-label="Permalink to &quot;Test and Debug&quot;">​</a></h1><h2 id="run-tests" tabindex="-1">Run Tests <a class="header-anchor" href="#run-tests" aria-label="Permalink to &quot;Run Tests&quot;">​</a></h2><p>clice has two types of tests: unit tests and integration tests.</p><ul><li>Run unit tests</li></ul><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./build/bin/unit_tests</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --test-dir=</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;./tests/data&quot;</span></span></code></pre></div><ul><li>Run integration tests</li></ul><p>We use pytest to run integration tests. Please refer to <code>pyproject.toml</code> to install the required Python libraries.</p><div class="language-bash vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">bash</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pytest</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --log-cli-level=INFO</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tests/integration</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --executable=./build/bin/clice</span></span></code></pre></div><p>If you use xmake as your build system, you can run the tests directly with xmake:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xmake</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> run</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --verbose</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> unit_tests</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> xmake</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> test</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --verbose</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> integration_tests/default</span></span></code></pre></div><h2 id="debug" tabindex="-1">Debug <a class="header-anchor" href="#debug" aria-label="Permalink to &quot;Debug&quot;">​</a></h2><p>If you want to attach a debugger to clice for debugging, it is recommended to first start clice in socket mode independently, and then connect the client to it.</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> ./build/bin/clice</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --mode=socket</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --port=50051</span></span></code></pre></div><p>After the server starts, you can connect a client to the server in the following two ways:</p><ul><li>Connect by running a specific test with pytest</li></ul><p>You can run a single integration test case to connect to a running clice instance. This is very useful for reproducing and debugging specific scenarios.</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> pytest</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> -s</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --log-cli-level=INFO</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> tests/integration/test_file_operation.py::test_did_open</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --mode=socket</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> --port=50051</span></span></code></pre></div><ul><li>Use VS Code for practical testing</li></ul><p>You can also connect to a running clice service by configuring the clice-vscode extension, allowing you to debug in a real-world usage scenario.</p><ol><li><p>Download the <a href="https://marketplace.visualstudio.com/items?itemName=ykiko.clice-vscode" target="_blank" rel="noreferrer">clice-vscode</a> extension from the Marketplace.</p></li><li><p>Configure <code>settings.json</code>: Create a <code>.vscode/settings.json</code> file in your project&#39;s root directory and add the following content:</p><div class="language-jsonc vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">jsonc</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">{</span></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // Point this to the clice binary you downloaded.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  &quot;clice.executable&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;/path/to/your/clice/executable&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // Enable socket mode.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  &quot;clice.mode&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;socket&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  &quot;clice.port&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">50051</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">  // Optional: Set this to an empty string to turn off the clangd.</span></span>
<span class="line"><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;">  &quot;clangd.path&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">: </span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;">&quot;&quot;</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">,</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div></li><li><p>Reload Window: After modifying the configuration, execute the <code>Developer: Reload Window</code> command in VS Code for the settings to take effect. The extension will automatically connect to the clice instance listening on port 50051.</p></li></ol><p>If you need to modify or debug the clice-vscode extension itself, follow these steps:</p><ol><li><p>Clone and install dependencies:</p><div class="language-shell vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">shell</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> git</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clone</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> https://github.com/clice-io/clice-vscode</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> cd</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> clice-vscode</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">$</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> npm</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> install</span></span></code></pre></div></li><li><p>Open the extension project with VS Code: Open the <code>clice-vscode</code> folder in a new VS Code window.</p></li><li><p>Create debug configuration: In the <code>clice-vscode</code> project, also create a <code>.vscode/settings.json</code> file with the same content as above.</p></li><li><p>Press <code>F5</code>. This will launch an [Extension Development Host] window. This is a new VS Code window with your local clice-vscode extension code loaded. Open your C++ project in this new window, and it should automatically connect to clice.</p></li></ol>`,22)])])}const g=i(n,[["render",l]]);export{r as __pageData,g as default};
