test: add UserInfo and ProfileInit unit test suites#1492
Conversation
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>
📝 WalkthroughWalkthroughAdds 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. ChangesTest Coverage Expansion
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (8)
src/profileinit.cpptests/auto/auto.protests/auto/profileinit/profileinit.protests/auto/profileinit/qtpass.plisttests/auto/profileinit/tst_profileinit.cpptests/auto/userinfo/qtpass.plisttests/auto/userinfo/tst_userinfo.cpptests/auto/userinfo/userinfo.pro
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>
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
tests/auto/profileinit/tst_profileinit.cpptests/auto/userinfo/tst_userinfo.cpp
Summary
tst_userinfo(17 tests): coversfullyValid(),marginallyValid(), andisValid()across all GPG validity codes (f,u,m,-,n,?), plus default field values. UsesQTEST_APPLESS_MAIN— no display or event loop needed.tst_profileinit(7 tests): coversProfileInit::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 emptyQStringargument resolved toQDir("")(Qt's current directory), which returned a spurioustrue. Now returnsfalsefor empty paths.Test plan
tst_userinfo: 17 passed, 0 failedtst_profileinit: 7 passed, 0 failedclang-format --dry-run -Werrorclean on all new files🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests