diff --git a/docs/en/dev/build.md b/docs/en/dev/build.md index 95051e2d..5ea95f15 100644 --- a/docs/en/dev/build.md +++ b/docs/en/dev/build.md @@ -114,6 +114,12 @@ clice has two forms of tests: unit tests and integration tests. $ ./build/bin/unit_tests --test-dir="./tests/data" --resource-dir="/lib/clang/20" ``` +Or, run unit tests through xmake: + +```bash +$ xmake run --verbose unit_tests +``` + - Run integration tests: We recommend using [uv](https://github.com/astral-sh/uv) to manage Python dependencies and versions. If you don't want to download uv, please refer to `pyproject.toml` to download the required Python version and dependencies. @@ -128,6 +134,19 @@ Or, if you use xmake as the build system, you can directly run tests through xma ```shell $ xmake test --verbose -$ xmake run --verbose unit_tests $ xmake test --verbose integration_tests/default ``` + +Or, if you use xmake build the project and do not have uv installed, you can use the following script: + +```bash +$ pip install pytest pytest-asyncio +$ xmake f -m debug && xmake build unit_tests + +# The environment variable LLVM_INSTALL_DIR may vary in different commits and platforms, +# depending on the value of `set_versions` in the `package("llvm")` section of the xmake.lua +$ LLVM_INSTALL_DIR=./build/.packages/l/llvm/20.1.5/0181167384bb4acb9e781210294c358d/lib/clang/20/ \ + pytest -s --log-cli-level=INFO tests/integration \ + --executable=./build/linux/x86_64/debug/clice \ + --resource-dir=$LLVM_INSTALL_DIR +``` diff --git a/docs/zh/dev/build.md b/docs/zh/dev/build.md index 5fbd95e2..7b89cb56 100644 --- a/docs/zh/dev/build.md +++ b/docs/zh/dev/build.md @@ -114,6 +114,11 @@ clice 有两种形式的测试,单元测试和集成测试。 $ ./build/bin/unit_tests --test-dir="./tests/data" --resource-dir="/lib/clang/20" ``` +或者, 使用 xmake 启动单元测试: +```bash +$ xmake run --verbose unit_tests +``` + - 运行集成测试 我们推荐使用 [uv](https://github.com/astral-sh/uv) 管理 python 依赖和版本。如果不想下载 uv,请参考 `pyproject.toml` 下载所需的 python 版本和依赖。 @@ -124,10 +129,23 @@ $ pytest -s --log-cli-level=INFO tests/integration --executable=./build/bin/clic > resource-dir 是 clang 的内置头文件文件夹 -或者,如果你使用 xmake 作为构建系统,可以直接通过 xmake 运行测试: +如果你使用 xmake 作为构建系统,可以直接通过 xmake 运行测试: ```shell $ xmake test --verbose -$ xmake run --verbose unit_tests $ xmake test --verbose integration_tests/default ``` + +在使用 xmake 构建和不使用 uv 的情况下, 启动 debug 模式的测试: + +```shell +$ pip install pytest pytest-asyncio +$ xmake f -m debug && xmake build unit_tests + +# 此处的 LLVM_INSTALL_DIR 在不同版本, 不同平台的 clice 中 sha 值可能不一样, +# 取决于对应的 xmake.lua 中 `package("llvm")` 一节 `set_versions` 的取值 +$ LLVM_INSTALL_DIR=./build/.packages/l/llvm/20.1.5/0181167384bb4acb9e781210294c358d/lib/clang/20/ \ + pytest -s --log-cli-level=INFO tests/integration \ + --executable=./build/linux/x86_64/debug/clice \ + --resource-dir=$LLVM_INSTALL_DIR +``` diff --git a/xmake.lua b/xmake.lua index c7894f1f..530dc07f 100644 --- a/xmake.lua +++ b/xmake.lua @@ -77,6 +77,10 @@ target("clice-core") "clangToolingInclusionsStdlib", "clangToolingSyntax", }}) + on_config(function (target) + local llvm_dynlib_dir = path.join(target:pkg("llvm"):installdir(), "lib") + target:add("rpathdirs", llvm_dynlib_dir) + end) elseif is_mode("release", "releasedbg") then add_packages("llvm", {public = true}) add_ldflags("-Wl,--gc-sections")