Skip to content

Add GoogleTest unit tests and CI - #21

Merged
Staaaszek merged 5 commits into
mainfrom
dev/testing
Oct 29, 2026
Merged

Staaaszek merged 5 commits into
mainfrom
dev/testing

Conversation

@Staaaszek

@Staaaszek Staaaszek commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds unit tests with GoogleTest (including GMock) and a GitHub Actions CI that builds the project and runs the tests on every push to any branch and on every pull request, on Arch Linux and Ubuntu.

There is only one example test (tests/backend/html_parser_test.cpp), to show the conventions. Real tests come in later PRs.

just test                  # configure with -DBUILD_TESTS=ON, build, run the tests
just test -R HtmlParser    # extra arguments go to ctest

How

  • email_client_core library: all sources except src/main.cpp are now built into a static library. Both email_client and the test binary link against it, so the tests use the same code as the client. The dependencies are linked PUBLIC, so the tests get their headers and libraries too.
  • BUILD_TESTS option, off by default: a normal build (and the AUR package) does not download GoogleTest. GoogleTest is built statically, even though the project sets BUILD_SHARED_LIBS ON.
  • One test binary (email_client_tests), with tests registered in CTest through gtest_discover_tests, so every TEST shows up as a separate ctest test.
  • libxml2's own tests are turned off (LIBXML2_WITH_TESTS). They were registered in CTest but never built, so ctest reported them as failed. The commands run ctest --test-dir build/tests, so build directories created before this change still work.
  • CI: two jobs, arch and ubuntu.
    • arch runs in the archlinux:latest container. Arch is the target platform (the client is packaged for the AUR), and it gets the newest GCC, ICU, GnuTLS and ncurses first.
    • ubuntu stays as a stable baseline. Arch is a rolling release, so if arch fails and ubuntu passes, an Arch update is the likely cause rather than our code.
    • Runs on every push to any branch and on pull requests (needed for PRs from forks). A newer push to the same branch cancels the older run, except on main, where every commit is tested.
    • ccache also caches the VMime build, so later runs are faster.

Requiring CI before merging

The workflow itself cannot block merging. After this PR is merged, a repository admin needs to add a branch protection rule for main (Settings → Branches) that requires the arch and ubuntu status checks to pass.

Conventions

They are also written down in the README under "Tests":

  • Test files mirror src/: tests for src/backend/html_parser.cpp go in tests/backend/html_parser_test.cpp, and each new file is added to tests/CMakeLists.txt.
  • Suite name: the tested class + Test. Test name: what the code should do, as a sentence.
  • EXPECT_* by default, ASSERT_* only when the rest of the test makes no sense after a failure.
  • Unit tests do not use the network or the user's config.

The tests can then link against the same code as the client. Also adds the
BUILD_TESTS option and turns off libxml2's own tests.
Arch is the target platform (AUR); the Ubuntu job stays as a stable baseline.
Outdated runs on the same branch are cancelled, except on main.
The v1.2 tag still points to a release that targets the deprecated Node.js 20.
@Staaaszek
Staaaszek merged commit 528a2d0 into main Oct 29, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant