fix: address additional AI findings in util tests#880
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIntroduce a Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
- Add exact path content assertions in normalizeFolderPath test - Move PassStoreGuard to class member for reuse - Add file existence check after opening in findBinaryInPath test
947232e to
cf84199
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
tests/auto/util/tst_util.cpp (2)
36-41: Consider makingPassStoreGuardnon-copyable/non-movable.This RAII guard could be accidentally copied or moved, leading to double-restoration of the original value. Adding move/copy prevention makes the intent clearer and prevents subtle bugs.
♻️ Suggested improvement
private: struct PassStoreGuard { QString original; explicit PassStoreGuard(const QString &orig) : original(orig) {} ~PassStoreGuard() { QtPassSettings::setPassStore(original); } + PassStoreGuard(const PassStoreGuard &) = delete; + PassStoreGuard &operator=(const PassStoreGuard &) = delete; };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/auto/util/tst_util.cpp` around lines 36 - 41, PassStoreGuard can be accidentally copied/moved causing double-restoration; make it non-copyable and non-movable by deleting its copy constructor, copy assignment, move constructor and move assignment (i.e., add deleted declarations for PassStoreGuard(const PassStoreGuard&) = delete, PassStoreGuard& operator=(const PassStoreGuard&) = delete, PassStoreGuard(PassStoreGuard&&) = delete, and PassStoreGuard& operator=(PassStoreGuard&&) = delete) so only a single instance created via the explicit PassStoreGuard(const QString&) exists and the destructor (~PassStoreGuard) runs exactly once.
594-605: Consider usingPassStoreGuardfor consistency withgetDirWithIndex().
getDirWithIndex()usesPassStoreGuardfor RAII-based restoration (lines 626-627), but this test uses manual save/restore. Using the guard here ensures restoration even if an assertion fails between lines 595 and 605.♻️ Suggested refactor for consistency
QModelIndex rootIndex = fsm.index(tempDir.path()); QVERIFY2(rootIndex.isValid(), "Filesystem model root index should be valid"); const QString originalStore = QtPassSettings::getPassStore(); + PassStoreGuard passStoreGuard(originalStore); QtPassSettings::setPassStore(tempDir.path()); QString result = Util::getDir(QModelIndex(), false, fsm, sm); QString expectedDir = QDir(tempDir.path()).absolutePath(); if (!expectedDir.endsWith(QDir::separator())) { expectedDir += QDir::separator(); } QVERIFY2( result == expectedDir, qPrintable(QString("Expected '%1', got '%2'").arg(expectedDir, result))); - QtPassSettings::setPassStore(originalStore); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/auto/util/tst_util.cpp` around lines 594 - 605, Replace the manual save/restore of the pass store in the test with the RAII guard used elsewhere: instead of calling QtPassSettings::getPassStore() and later QtPassSettings::setPassStore(originalStore) around the Util::getDir(...) call, construct a PassStoreGuard (as used in getDirWithIndex()) around the tempDir setup so the original pass store is automatically restored even if assertions fail; locate the test around Util::getDir(QModelIndex(), false, fsm, sm) in tests/auto/util/tst_util.cpp and swap the manual QtPassSettings calls for a PassStoreGuard instance that is initialized with tempDir.path().
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/auto/util/tst_util.cpp`:
- Around line 36-41: PassStoreGuard can be accidentally copied/moved causing
double-restoration; make it non-copyable and non-movable by deleting its copy
constructor, copy assignment, move constructor and move assignment (i.e., add
deleted declarations for PassStoreGuard(const PassStoreGuard&) = delete,
PassStoreGuard& operator=(const PassStoreGuard&) = delete,
PassStoreGuard(PassStoreGuard&&) = delete, and PassStoreGuard&
operator=(PassStoreGuard&&) = delete) so only a single instance created via the
explicit PassStoreGuard(const QString&) exists and the destructor
(~PassStoreGuard) runs exactly once.
- Around line 594-605: Replace the manual save/restore of the pass store in the
test with the RAII guard used elsewhere: instead of calling
QtPassSettings::getPassStore() and later
QtPassSettings::setPassStore(originalStore) around the Util::getDir(...) call,
construct a PassStoreGuard (as used in getDirWithIndex()) around the tempDir
setup so the original pass store is automatically restored even if assertions
fail; locate the test around Util::getDir(QModelIndex(), false, fsm, sm) in
tests/auto/util/tst_util.cpp and swap the manual QtPassSettings calls for a
PassStoreGuard instance that is initialized with tempDir.path().
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 141a0eb5-d562-463b-83d5-f851b5e26d84
📒 Files selected for processing (1)
tests/auto/util/tst_util.cpp
Summary
normalizeFolderPathtestPassStoreGuardto class member for reusefindBinaryInPathtestSummary by CodeRabbit