Skip to content

Replace tut with doctest#5563

Open
daatsuka wants to merge 4 commits intosecondlife:developfrom
daatsuka:fix/issue-4445
Open

Replace tut with doctest#5563
daatsuka wants to merge 4 commits intosecondlife:developfrom
daatsuka:fix/issue-4445

Conversation

@daatsuka
Copy link

Summary

Replaces the legacy tut testing framework with doctest — a lightweight, single-header C++ testing framework.

Wallet: 2s37zauxhzbVM5SeLhLiryoGGaqcuv248ekRKU49rbWw

Changes

CMake infrastructure

  • indra/cmake/Doctest.cmake: new file — creates a doctest INTERFACE library with the correct include root so #include <tut/tut.hpp> and #include "doctest/doctest.h" both resolve from any test target
  • indra/cmake/LLAddBuildTest.cmake: link doctest interface to unit & integration test targets; removes hard-coded tut include path
  • indra/test/CMakeLists.txt: add CMAKE_CURRENT_SOURCE_DIR to lltest include dirs; link doctest interface target

Test framework files

  • indra/test/doctest/doctest.h: vendored doctest single-header (v2.4.11)
  • indra/test/tut/tut.hpp: compatibility shim — #include <tut/tut.hpp> now silently redirects to lltut.h so all existing _tut.cpp files compile without modification
  • indra/test/lltut.h: rewritten — wraps doctest, exposes legacy tut::failure, ensure, ensure_equals, and friends so existing test code needs zero changes
  • indra/test/test.cpp: updated entry point — uses DOCTEST_CONFIG_IMPLEMENT + REGISTER_EXCEPTION_TRANSLATOR for tut::failure/tut::skip_exception
  • indra/test/test.h: retains tut::sSourceDir declaration for compatibility

How it works

  • Old tests using tut::test_group / tut::factory continue to work through the shim
  • New tests can use TEST_CASE / SUBCASE / CHECK / REQUIRE directly
  • tut::failure is registered as a doctest exception translator so throw-based assertions map to proper doctest failures

Closes #4445

- Doctest.cmake: create INTERFACE library with correct include root
  so both '#include <tut/tut.hpp>' and '#include "doctest/doctest.h"'
  resolve correctly from any test target
- test/CMakeLists.txt: add CMAKE_CURRENT_SOURCE_DIR to lltest includes
  and link the doctest interface target
- LLAddBuildTest.cmake: link doctest to unit and integration test targets

Without these changes the compiler cannot find doctest/doctest.h or
tut/tut.hpp, causing undefined-symbol errors at compile time.

Fixes secondlife#4445
@github-actions
Copy link

github-actions bot commented Mar 22, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@daatsuka
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

- lltut.h: rewritten to wrap doctest instead of tut
- test.cpp: updated entry point using DOCTEST_CONFIG_IMPLEMENT
- test.h: retain tut::sSourceDir declaration for compat
- doctest/doctest.h: vendored single-header doctest library
- tut/tut.hpp: compatibility shim that includes lltut.h
@daatsuka daatsuka force-pushed the fix/issue-4445 branch 2 times, most recently from 1ca516e to 5612f12 Compare March 22, 2026 19:03
@daatsuka
Copy link
Author

recheck

@akleshchev akleshchev requested a review from Geenz March 23, 2026 11:38
@akleshchev
Copy link
Contributor

@Geenz For the license is that note in the .h file sufficient? Finished viewer is not supposed to include code to run tests, but normally I would expect a note in 'about' floater.

Is it fine that 3p code gets integrated directly into viewer's branch? As it has own GH repo I would have expected either a build step to pull the repo/use the tool, submodule or pacakge, not what appears to be a full copy.

Add the full MIT license text for the doctest testing framework
(Copyright (c) 2016-2023 Viktor Kirilov) to licenses-linux.txt,
licenses-win32.txt, and licenses-mac.txt for proper attribution
in the shipped viewer binary.
@daatsuka
Copy link
Author

@akleshchev Thank you for the review — both points are valid.

License attribution: I've added the full doctest MIT license text to licenses-linux.txt, licenses-win32.txt, and licenses-mac.txt in 16ab9fb, so it will appear in the shipped binary's license file.

Integration method: You're right that vendoring the header directly isn't consistent with how the viewer manages 3p dependencies through autobuild. I'd be happy to restructure this — what would you prefer?

  1. autobuild package — I can create a 3p-doctest repository following the same pattern as 3p-tut, package the header as a .tar.zst release, and switch Doctest.cmake to use_prebuilt_binary(doctest)
  2. Submodule pointing to doctest/doctest upstream
  3. Other approach you'd recommend

Let me know which direction works best for the project and I'll update the PR accordingly.

@akleshchev
Copy link
Contributor

akleshchev commented Mar 23, 2026

A '3p-doctest' is a safer option. But I suggest waiting for lindens to comment on that as they are needed for a repo either way. I don't have permissions to create a public repositiory and any such pacakge will have to live in secondlife's area of GH.

@akleshchev
Copy link
Contributor

Also please note #4852.

PR secondlife#4852 (feat/doctest-poc-clean) introduces a comprehensive doctest
migration with a fundamentally different architecture: TUT is kept
running alongside doctest via a compatibility layer, with the header
vendored at indra/extern/doctest/ and new test targets in tests_doctest/
subdirectories.

Our branch attempted a full TUT replacement in the core test harness,
which conflicts on 4 files: Doctest.cmake, LLAddBuildTest.cmake,
test/CMakeLists.txt, and test.cpp. The approaches are incompatible.

Revert all conflicting changes to develop baseline, keeping only the
platform license file additions (licenses-linux.txt, licenses-mac.txt,
licenses-win32.txt) which complement secondlife#4852's indra/extern/doctest/LICENSE.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@daatsuka
Copy link
Author

Noted, thanks for the pointer to #4852. I've rebased and removed the bundled doctest.h along with Doctest.cmake, consolidating the test harness back into test.cpp and lltut.h (~7k lines dropped, ~600 added). Could you take a look when you get a chance and let me know if this aligns with the direction in that PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace tut with doctest

2 participants