Skip to content

fix: silence -Wunused-result in color selector unit test - #736

Open
52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master
Open

52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master

Conversation

@52cyb

@52cyb 52cyb commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
  1. Wrap the bare qWaitFor() call added by ccb129a in EXPECT_TRUE()
  2. Silence GCC -Wunused-result on Qt 6, which breaks the -Werror build
  3. Test now fails when the palette binding never settles

Log: No user-facing changes

Influence:

  1. Build the unit-test target in Debug with warnings treated as errors
  2. Run unit-test --gtest_filter='ut_ColorSelector.*', expect 4 passed
  3. Break the palette binding on purpose to verify the new assert fires

fix: 修复颜色选择器单测 qWaitFor 返回值未使用告警

  1. 将 ccb129a 引入的裸 qWaitFor() 调用包进 EXPECT_TRUE()
  2. 消除 Qt6 上的 GCC -Wunused-result 告警,避免 -Werror 下编译失败
  3. 调色板绑定未生效时用例会断言失败,而不是静默通过

Log: 无用户可见变化

Influence:

  1. Debug 配置下构建 unit-test 目标,确认无告警、编译通过
  2. 运行 unit-test --gtest_filter='ut_ColorSelector.*',预期 4 个用例通过
  3. 临时破坏调色板绑定,确认新加的断言能让用例失败

PMS: TASK-397289

Summary by Sourcery

Ensure the color selector test validates asynchronous palette binding completion while keeping strict-warning builds clean.

Bug Fixes:

  • Make the color selector unit test fail when the palette binding does not settle instead of silently ignoring the wait result.

Build:

  • Resolve the Qt 6 GCC unused-result warning so the unit-test target builds cleanly with warnings treated as errors.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai

sourcery-ai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the color selector unit test to assert that the palette binding settles successfully, both eliminating the Qt 6 GCC -Wunused-result warning under -Werror and preventing silent success when the binding fails.

File-Level Changes

Change Details Files
Turn the asynchronous palette-binding wait into an explicit test assertion.
  • Wrap QTest::qWaitFor() in ASSERT_TRUE() so the test fails if the condition does not settle.
  • Preserve the existing wait predicate and final color equality check.
tests/ut_colorselector.cpp
Resolve the Qt 6 unused-result warning that causes warning-as-error test builds to fail.
  • Consume qWaitFor’s return value through the assertion while retaining failure diagnostics from the test framework.
tests/ut_colorselector.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="tests/ut_colorselector.cpp" line_range="56" />
<code_context>

     ASSERT_TRUE(QQmlProperty::write(helper.object, "palette.window", QColor(Qt::white)));
-    QTest::qWaitFor([&] {
+    ASSERT_TRUE(QTest::qWaitFor([&] {
         return background->property("color")
                 == engine.evaluate("background.color1.normal.common.color()").toVariant();
</code_context>
<issue_to_address>
**Stale palette colors pass**

When the background and selector colors are already equal before the palette update settles, `getColorFromProperty` lets `qWaitFor` return immediately when the background color already equals the selector color, and the final assertion at line 60 checks only that same equality. The test therefore passes even if the palette update never occurs.

Assert that the palette write produces an expected color distinct from the pre-write value, then wait for the background color to reach that expected value.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread tests/ut_colorselector.cpp Outdated
1. Wrap the bare qWaitFor() call added by ccb129a in EXPECT_TRUE()
2. Silence GCC -Wunused-result on Qt 6, which breaks the -Werror build
3. Test now fails when the palette binding never settles

Log: No user-facing changes

Influence:
1. Build the unit-test target in Debug with warnings treated as errors
2. Run unit-test --gtest_filter='ut_ColorSelector.*', expect 4 passed
3. Break the palette binding on purpose to verify the new assert fires

fix: 修复颜色选择器单测 qWaitFor 返回值未使用告警

1. 将 ccb129a 引入的裸 qWaitFor() 调用包进 EXPECT_TRUE()
2. 消除 Qt6 上的 GCC -Wunused-result 告警,避免 -Werror 下编译失败
3. 调色板绑定未生效时用例会断言失败,而不是静默通过

Log: 无用户可见变化

Influence:
1. Debug 配置下构建 unit-test 目标,确认无告警、编译通过
2. 运行 unit-test --gtest_filter='ut_ColorSelector.*',预期 4 个用例通过
3. 临时破坏调色板绑定,确认新加的断言能让用例失败

PMS: TASK-397289
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 100 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交目的是消除颜色选择器单元测试中 -Wunused-result 编译器警告。变更将 QTest::qWaitFor() 的返回值用 EXPECT_TRUE() 包裹, 既消除了警告又增加了有意义的断言,验证等待条件确实被满足。变更仅涉及测试文件,范围极小且正确, 四维度均无问题,无安全漏洞。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 当前代码已经是正确的修复方式,无需额外修改。 // EXPECT_TRUE(QTest::qWaitFor([&] { //     return background->property("color") //             == engine.evaluate("background.color1.normal.common.color()").toVariant(); // }));

本报告由 AI 代码审查工具自动生成

@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.52
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #738

This branch has not been deployed

No deployments
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.

2 participants