Skip to content

test: add UserInfo and ProfileInit unit test suites#1492

Merged
annejan merged 3 commits into
mainfrom
test/userinfo-profileinit-tests
May 16, 2026
Merged

test: add UserInfo and ProfileInit unit test suites#1492
annejan merged 3 commits into
mainfrom
test/userinfo-profileinit-tests

Conversation

@nogeenharrie
Copy link
Copy Markdown
Contributor

@nogeenharrie nogeenharrie commented May 16, 2026

Summary

  • tst_userinfo (17 tests): covers fullyValid(), marginallyValid(), and isValid() across all GPG validity codes (f, u, m, -, n, ?), plus default field values. Uses QTEST_APPLESS_MAIN — no display or event loop needed.

  • tst_profileinit (7 tests): covers ProfileInit::needsInit() for non-existent paths, empty path, directory without .gpg-id, directory with .gpg-id, and the before/after transition.

  • Bug fix in ProfileInit::needsInit(): previously an empty QString argument resolved to QDir("") (Qt's current directory), which returned a spurious true. Now returns false for empty paths.

Test plan

  • tst_userinfo: 17 passed, 0 failed
  • tst_profileinit: 7 passed, 0 failed
  • clang-format --dry-run -Werror clean on all new files
  • CI green

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Profile initialization now treats empty paths as non-initialized immediately, avoiding unnecessary processing and related errors.
  • Tests

    • Automated test suite expanded with new coverage for profile initialization and comprehensive user information validation, plus added test targets and platform metadata templates to support running these tests.

Review Change Stack

tst_userinfo (17 tests): covers fullyValid(), marginallyValid() and
isValid() for all relevant GPG validity codes (f, u, m, -, n, ?)
plus default field values. Uses QTEST_APPLESS_MAIN — no Qt event
loop or display needed.

tst_profileinit (7 tests): covers ProfileInit::needsInit() for
non-existent paths, empty path, dir without .gpg-id, dir with
.gpg-id, and the before/after transition.

Also fixes ProfileInit::needsInit() to return false for an empty
path argument. Previously, QDir("") resolved to the current
working directory, causing a spurious true return.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

📝 Walkthrough

Walkthrough

Adds an empty-path guard to ProfileInit::needsInit(), plus unit tests and QMake/test fixtures for ProfileInit and UserInfo, and registers the new test subdirectories in the top-level tests project.

Changes

Test Coverage Expansion

Layer / File(s) Summary
ProfileInit initialization guard and unit tests
src/profileinit.cpp, tests/auto/profileinit/tst_profileinit.cpp, tests/auto/profileinit/profileinit.pro, tests/auto/profileinit/qtpass.plist
ProfileInit::needsInit() now returns false immediately when path is empty. Unit tests cover nonexistent paths, empty path, temporary directories missing .gpg-id, and state after creating .gpg-id.
UserInfo validity unit tests
tests/auto/userinfo/tst_userinfo.cpp, tests/auto/userinfo/userinfo.pro, tests/auto/userinfo/qtpass.plist
New test suite verifies isValid(), fullyValid(), and marginallyValid() across validity characters and checks default UserInfo field values and invalid expiry/created states.
Test suite registration
tests/auto/auto.pro
Top-level test project SUBDIRS is expanded to include the new profileinit and userinfo test subdirectories.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • IJHack/QtPass#1036: Adds ConfigDialog::initializeNewProfiles() that depends on ProfileInit::needsInit().

Suggested labels

size:M

Suggested reviewers

  • annejan

Poem

🐇 A tiny guard hops on the trail,
Empty paths now safely pale.
Tests arrive with steady cheer,
Profiles and users tested here.
The rabbit twitches whiskers: code is hale.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: adding two new unit test suites (UserInfo and ProfileInit) to the project.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/userinfo-profileinit-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/auto/profileinit/tst_profileinit.cpp`:
- Around line 32-33: The tests use bare QVERIFY() assertions which give no
failure context; replace each QVERIFY(expr) call (e.g., the checks for
dir.isValid() and ProfileInit::needsInit(dir.path()) and the other listed
assertions) with QVERIFY2(expr, "descriptive message") providing a clear message
indicating what was expected (for example "directory should be valid" and
"ProfileInit::needsInit should return true for fresh dir") so failures provide
useful context; update all occurrences referenced (lines checking dir.isValid,
ProfileInit::needsInit and the other listed assertions) to use QVERIFY2 with
concise, explanatory strings.
- Around line 22-24: The test tst_profileinit::needsInitFalseForNonexistentPath
uses a hardcoded POSIX path; change it to construct a guaranteed-nonexistent
path from the system temp location (e.g., QTemporaryDir or QDir::tempPath()) and
append a random/unique component so the resulting path is guaranteed absent,
then call ProfileInit::needsInit(...) with that generated QString instead of
QStringLiteral("/nonexistent/path/abc123"); ensure the generated path is not
created during the test so the assertion QVERIFY(!ProfileInit::needsInit(...))
remains valid.

In `@tests/auto/userinfo/tst_userinfo.cpp`:
- Line 37: Replace message-less QVERIFY(...) calls with QVERIFY2(...) and
provide a short descriptive failure message for each assertion in
tst_userinfo.cpp; e.g., change QVERIFY(u.fullyValid()); to
QVERIFY2(u.fullyValid(), "u.fullyValid() failed") and do the same for the other
occurrences (the assertions at the same pattern around lines asserting validity
in this test: the calls to QVERIFY(...) referencing the user object or its
methods) so each assertion includes a clear, concise string describing what
failed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: efdb0160-e70e-419d-8a6f-16168704856c

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4a157 and a44214a.

📒 Files selected for processing (8)
  • src/profileinit.cpp
  • tests/auto/auto.pro
  • tests/auto/profileinit/profileinit.pro
  • tests/auto/profileinit/qtpass.plist
  • tests/auto/profileinit/tst_profileinit.cpp
  • tests/auto/userinfo/qtpass.plist
  • tests/auto/userinfo/tst_userinfo.cpp
  • tests/auto/userinfo/userinfo.pro

Comment thread tests/auto/profileinit/tst_profileinit.cpp
Comment thread tests/auto/profileinit/tst_profileinit.cpp Outdated
Comment thread tests/auto/userinfo/tst_userinfo.cpp Outdated
nogeenharrie and others added 2 commits May 16, 2026 02:15
QTEST_APPLESS_MAIN does not create a QApplication, so the test runner's
--platform offscreen argument was rejected as unknown.  Replace with
QTEST_MAIN in both tst_userinfo and tst_profileinit so the platform
plugin argument is accepted on headless CI.

Also improve all bare QVERIFY() calls to QVERIFY2() with descriptive
failure messages, and replace the hardcoded /nonexistent/path with a
temp-dir-based absent path for portability.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

coveralls commented May 16, 2026

Coverage Status

coverage: 53.917% (+0.08%) from 53.836% — test/userinfo-profileinit-tests into main

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/auto/userinfo/tst_userinfo.cpp`:
- Line 126: Replace the QTEST_MAIN macro with QTEST_APPLESS_MAIN for the
tst_userinfo test suite: locate the test suite declaration using
QTEST_MAIN(tst_userinfo) and change it to QTEST_APPLESS_MAIN(tst_userinfo) so
the tests run without creating a QApplication/event loop (consistent with the PR
description that UserInfo has no GUI).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5b32983b-c074-474d-8425-59186d85ced1

📥 Commits

Reviewing files that changed from the base of the PR and between c5ffffb and 2c13163.

📒 Files selected for processing (2)
  • tests/auto/profileinit/tst_profileinit.cpp
  • tests/auto/userinfo/tst_userinfo.cpp

Comment thread tests/auto/userinfo/tst_userinfo.cpp
@annejan annejan merged commit aea9e99 into main May 16, 2026
24 of 25 checks passed
@annejan annejan deleted the test/userinfo-profileinit-tests branch May 16, 2026 00:29
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.

3 participants