doctest for C/C++ which run tests by using clang-repl interaction comments.
Project description
C/C++ DocTest
A C/C++ DocTest that runs tests using clang-repl interaction comments. Supports Linux (macOS is untested; Windows DLLs are not supported).
Prerequisites
clang-repl-kernelversion 0.1.8libclangmust be installed and functioning properly
Usage
sample.cpp
#include "sample.h"
namespace test {
/**
>>> test::Fac fac;
>>> printf("%d\n", fac.fac(7));
5040
*/
int Fac::fac(int n) {
return (n > 1) ? n * fac(n - 1) : 1;
}
/**
>>> test::Fac fac;
>>> printf("%d\n", fac.fac2(5));
120
*/
int Fac::fac2(int n) {
return (n > 1) ? n * fac(n - 1) : 1;
}
}
sample.h
#pragma once
/**
>>> test::Fac fac;
>>> printf("%d\n", fac.fac(5));
120
>>> printf("%d\n", fac.fac2(5));
120
*/
namespace test {
class Fac {
public:
/**
>>> test::Fac fac;
>>> printf("%d\n", fac.fac(5));
120
*/
int fac(int n);
int fac2(int n);
};
}
Building the Shared Library on Linux
clang -c -o sample.o sample.cpp
clang -shared sample.o -o sample.so
Building the DLL on Windows
clang-cl -c -o sample.o sample.cpp
clang -shared sample.o -o sample.dll
Running Tests with Source Code and Shared Library on Linux
python3 -m cdoctest -cdtt=sample.h -cdtl=sample.so -cdtip=.
Running Tests with Source Code and DLL on Windows
python -m cdoctest -cdtt=sample.h -cdtl=sample.dll -cdtip=.
Installing clang-repl Manually
Due to GitHub's LFS limit, you need to install clang-repl manually until a better binary distribution method is available.
Place the clang-repl binary in the clang_repl_kernel/[Linux|Windows] directory (e.g., clang_repl_kernel/Windows/clang-repl.exe).
Fixing a Bug in clang-repl
There is a minor bug in clang-repl. You can clone a branch with the fix applied:
git clone -b private/ormastes_current https://github.com/ormastes/llvm-project.git
Alternatively, modify llvm/lib/LineEditor/LineEditor.cpp by adding a call to flush the output buffer after printing the prompt.
Building clang-repl
Refer to the Clang REPL documentation for detailed instructions:
cd llvm-project
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm
cmake --build . --target clang clang-repl -j n
Support vscode extension
Handle next input to interact with vscode extension. list
cdoctest --cdt_cmake_build_path=cmake/build --cdt_cmake_target=sample --cdt_list_testcase
${test_suite_name}::${test_case_name},${file_path},${line_number},start_col,end_line,end_col
run
cdoctest --cdt_cmake_build_path=cmake/build --cdt_cmake_target=sample --cdt_run_testcase=${test_suite_name}::${test_case_name}
output.vsc >> contents xml <unitest-results failedtests="0" ><test suite="" name="" passMessage="" ...>
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cdoctest-0.0.5-py3-none-any.whl.
File metadata
- Download URL: cdoctest-0.0.5-py3-none-any.whl
- Upload date:
- Size: 20.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
595dc6dee44221697919dba0bcb333fb953568fb1ca6d6b28135dede986739c5
|
|
| MD5 |
335ad29a5b3eb56c17ef41beb4fc1eb7
|
|
| BLAKE2b-256 |
c5dee3307ba64e2aac9b0cd9d506a0051e018621ab098a8889e1a81b1997a0c4
|