Skip to main content

Workflow for writing a C++ test

We strongly recommend each developer to write C++ unit tests when sending a PR.

  • We use googletest as the C++ test infrastructure.
  • C++ tests should be added to the tests/cpp/ directory.
  • Make sure your C++ test source file is covered by this CMake glob.

Build and run Taichi C++ tests#

# inside build/cmake .. -DTI_BUILD_TESTS=ON # ... other regular Taichi cmake argsmake
# run the C++ testTI_LIB_DIR=$TAICHI_INSTALL_DIR/lib ./taichi_cpp_tests
note

In order to run the C++ tests, please setup the environment variable, $TI_LIB_DIR, to point to $TAICHI_INSTALL_DIR/lib. $TAICHI_INSTALL_DIR can be retrieved from taichi.__path__[0] in python.

note

On Windows, taichi_cpp_tests.exe will be placed inside the %TAICHI_REPO_DIR%\bin directory.

note

Consider polishing the C++ test infrastructure:

  • Separate each translation unit into its own test executable
  • Have a unified script to control the execution of which set of tests

Adding a new test case#

Please follow Googletest Primer and Advanced googletest Topics.