Skip to content

mruby-string-ext: skip four UTF-8 tests where they cannot run - #7139

Merged
matz merged 1 commit into
mruby:masterfrom
takumin:string-ext-utf8-test-guard
Aug 14, 2026
Merged

mruby-string-ext: skip four UTF-8 tests where they cannot run#7139
matz merged 1 commit into
mruby:masterfrom
takumin:string-ext-utf8-test-guard

Conversation

@takumin

@takumin takumin commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Four tests in mrbgems/mruby-string-ext/test/string.rb hold their MRB_UTF8_STRING guard inside the assertion block rather than on the assert call:

assert('String#chop! on a binary string removes one byte') do
  if UTF8STRING
    s = "\u{1F600}".b
    s.chop!
    assert_equal "\xF0\x9F\x98".b, s
    ...
  end
end

On a build without MRB_UTF8_STRING the block still runs and reaches no assertion, which mrbtest counts as a warning:

Warn: String#inspect of a binary string escapes every byte => no assertion
Warn: String#chop! on a binary string removes one byte => no assertion
Warn: String#rindex on a binary string counts bytes => no assertion
Warn: a needle that spells no character is found nowhere => no assertion
...
Warning: 4

MRB_UTF8_STRING is turned on by mruby-encoding, which the default gembox does not carry, so a plain rake test is one of the builds that reports this.

The rest of the file already guards its UTF-8 tests on the assert call, so this PR moves these four to the same form:

assert('String#chop! on a binary string removes one byte') do
  s = "\u{1F600}".b
  s.chop!
  assert_equal "\xF0\x9F\x98".b, s
  ...
end if UTF8STRING

A build that cannot run the test no longer defines it. The assertions themselves are unchanged, and the diff is the removal of the inner if plus one level of indentation.

The guard is needed in all four cases, since each asserts behaviour that only a UTF-8 build has: "る".inspect comes back with every byte escaped without it, chop! cuts a byte instead of a character, and a needle such as "\x81" is searched for as a byte rather than refused as a sequence that spells no character.

Testing

rake test with the default gembox (MRB_UTF8_STRING off):

before after
Total 2067 2063
OK 2040 2040
KO 0 0
Warning 4 0

The four tests that ran without asserting anything are the only ones that disappear; nothing that used to assert stops asserting.

A full-core build (MRB_UTF8_STRING on) still runs all four: Total: 2269 / OK: 2259 / KO: 0 / Warning: 0.

Summary by CodeRabbit

  • Tests
    • Simplified conditional handling for UTF-8-specific string tests.
    • Preserved existing coverage for string inspection, binary chop!, binary rindex, and malformed-needle behavior.

Four tests in mruby-string-ext keep their `MRB_UTF8_STRING` guard inside
the assertion block, so a build without UTF-8 strings enters the block,
reaches no assertion, and mrbtest reports each of them:

    Warn: String#inspect of a binary string escapes every byte => no assertion
    Warn: String#chop! on a binary string removes one byte => no assertion
    Warn: String#rindex on a binary string counts bytes => no assertion
    Warn: a needle that spells no character is found nowhere => no assertion

The `default` gembox does not carry `mruby-encoding`, which is what turns
`MRB_UTF8_STRING` on, so a plain `rake test` ends its run with
`Warning: 4`.

Move the guard out to the `assert` call, the form the rest of the file
already uses for its UTF-8 tests, so a build that cannot run the test does
not define it. The assertions themselves are unchanged.

A default build now reports `Warning: 0` with `OK: 2040` as before, and a
full-core build still runs all four.
@takumin
takumin requested a review from matz as a code owner August 13, 2026 16:32
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d394bd4-3417-402f-bb17-5df9e3d1e07e

📥 Commits

Reviewing files that changed from the base of the PR and between 3adb9e4 and 6086321.

📒 Files selected for processing (1)
  • mrbgems/mruby-string-ext/test/string.rb

📝 Walkthrough

Walkthrough

UTF-8-specific tests in mruby-string-ext now use trailing if UTF8STRING modifiers. The assertions for inspection, chop!, rindex, and malformed needles remain unchanged.

Changes

String extension test guards

Layer / File(s) Summary
Simplify UTF-8 test conditions
mrbgems/mruby-string-ext/test/string.rb
Four test blocks replace nested UTF8STRING conditionals with trailing modifiers. Test assertions remain unchanged.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Mergeability Score: ⚪ Minimal · up to 60863

This PR prevents four unsupported UTF-8 tests from running on builds that cannot execute them, without changing their assertions or UTF-8-enabled behavior. No actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

Suggested reviewers: matz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: skipping four UTF-8-dependent tests when UTF-8 support is unavailable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit 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.

@matz
matz merged commit 65e4639 into mruby:master Aug 14, 2026
21 checks passed
@takumin
takumin deleted the string-ext-utf8-test-guard branch August 14, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants