Skip to content

feat(test): Support expected-failure tests via should_fail option#6588

Merged
waruqi merged 3 commits intoxmake-io:devfrom
romeoxbm:feat-test-should-fail
Jun 26, 2025
Merged

feat(test): Support expected-failure tests via should_fail option#6588
waruqi merged 3 commits intoxmake-io:devfrom
romeoxbm:feat-test-should-fail

Conversation

@romeoxbm
Copy link
Contributor

@romeoxbm romeoxbm commented Jun 25, 2025

This patch adds support for marking test cases as expected to fail using the should_fail option in add_tests(). This is useful for validating crash handling, incomplete features, or contract-breaking behavior in a controlled manner.

The test report has also been slightly modified to:

  • Distinguish expected failures and unexpected passes.
  • Print a detailed summary of failed tests, unexpected passes, and expected failures at the end.

Documentation PR: xmake-io/xmake-docs#230

This patch adds support for marking test cases as expected to fail using the should_fail option in add_tests(). This is useful for validating crash handling, incomplete features, or contract-breaking behavior in a controlled manner.

The test report has also been slightly modified to:
- Distinguish expected failures and unexpected passes.
- Print a detailed summary of failed tests, unexpected passes, and expected failures at the end.
passed_rate, report.total - report.passed, report.total, spent / 1000)

-- Print the summary
local summary = string.format("\n${color.success}%d%%%%${clear} tests passed, ${color.failure}%d${clear} test(s) failed", passed_rate, #failed_tests)
Copy link
Member

@waruqi waruqi Jun 25, 2025

Choose a reason for hiding this comment

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

we should move this summary to the last line.

Detailed summary:
Failed tests:
 - test_11/compile_pass
 - test_5/fail_output
 - test_5/pass_output
 - test_7/args
 - test_7/default
 - test_7/fail_output
 - test_7/pass_output
 - test_8/pass_output
 - test_timeout/run_timeout

78% tests passed, 9 test(s) failed out of 42, spent 1.217s

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I've updated the documentation accordingly. As for the failing pipeline jobs, I'm not quite sure if I introduced the issue, but I'd guess it's about the opt.errors manipulation in _do_test_target.

@waruqi waruqi added this to the v3.0.1 milestone Jun 26, 2025
@waruqi waruqi merged commit 2439edb into xmake-io:dev Jun 26, 2025
13 of 22 checks passed
@romeoxbm romeoxbm deleted the feat-test-should-fail branch June 26, 2025 07:24
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