Skip to content

tests/**/*.py.exp: protect trailing spaces with \$ - #19073

Closed
dhalbert wants to merge 9 commits into
micropython:masterfrom
dhalbert:protect-py-exp-trailing-spaces
Closed

dhalbert wants to merge 9 commits into
micropython:masterfrom
dhalbert:protect-py-exp-trailing-spaces

Conversation

@dhalbert

@dhalbert dhalbert commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Necessary trailing spaces in tests/**/*.py.exp files are not visible to the naked eye and may be removed by an editor if the file is edited manually. These changes protect those trailing spaces from accidental removal and make their presence visible by suffixing them with the regexp construct \$.

I'll note there are still plenty of (unnecessary) trailing spaces elsewhere: in shell scripts, various C files (maybe third-party). A pass was made to remove those in #13777, but some still remain.

Testing

CI testing will run the tests to verify these changes are OK

Generative AI

I did not use generative AI tools when creating this PR.

@dhalbert
dhalbert force-pushed the protect-py-exp-trailing-spaces branch 4 times, most recently from 1612607 to e460097 Compare April 9, 2026 13:49
@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (1f601e8) to head (2f9da6e).
⚠️ Report is 13 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #19073   +/-   ##
=======================================
  Coverage   98.47%   98.47%           
=======================================
  Files         176      176           
  Lines       22811    22811           
=======================================
  Hits        22463    22463           
  Misses        348      348           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dhalbert

dhalbert commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

The failing test I think is a intermittent glitch: extmod/asyncio_lock.py.

This is a little less comprehensive than I would have liked. There are trailing spaces in some .py.exp's outside of tests/cmdline and tests/feature_check:

tests/micropython/heapalloc_traceback.py.native.exp
tests/micropython/heapalloc_traceback.py.exp
tests/ports/esp32/check_err_str.py.exp
tests/ports/unix/extra_coverage.py.exp
tests/thread/thread_exc2.py.native.exp
tests/thread/thread_exc2.py.exp
tests/extmod/vfs_basic.py.exp
tests/basics/string_tstring_basic.py.exp

But those other test directories are not marked as is_special in run-tests.py. They could be. Would it make sense to make those is_special?

In addition:

tests/cmdline/repl_paste.py
tests/cmdline/repl_autocomplete_underscore.py

contain trailing spaces as input. Not so terrible, but again they're invisble

Comment thread tests/cmdline/cmd_showbc.py.exp
Comment thread tests/cmdline/repl_autocomplete_underscore.py.exp Outdated
@dpgeorge dpgeorge added the tests Relates to tests/ directory in source label Apr 13, 2026
@dhalbert
dhalbert force-pushed the protect-py-exp-trailing-spaces branch 6 times, most recently from b454dea to e0a2723 Compare April 13, 2026 15:33
@dhalbert

Copy link
Copy Markdown
Contributor Author

There was some CI failure in the latest run which I think will go away on a re-run (which I can't invoke without another push).

@dpgeorge

Copy link
Copy Markdown
Member

In addition:

tests/cmdline/repl_paste.py
tests/cmdline/repl_autocomplete_underscore.py

contain trailing spaces as input.

For tests/cmdline/repl_paste.py it's probably possible to use input escape sequences like {\x20} instead of a space, eg as the 4th space in the line at the end of the line.

I think tests/cmdline/repl_autocomplete_underscore.py is now fixed in this PR by removing the trailing spaces.

tests/extmod/vfs_basic.py.exp

I think it's safe to modify the test for this so it doesn't print a space at the end. Eg some logic that doesn't print dir if it's the empty string.

tests/basics/string_tstring_basic.py.exp

As above, could modify this test to not print out a space at the end of the line.

I didn't check the other .py.exp's but maybe they can all have their test tweaked so it doesn't have trailing spaces in the output. I'd prefer that over making the output special.

@dhalbert
dhalbert force-pushed the protect-py-exp-trailing-spaces branch 2 times, most recently from c15616b to ccf57f8 Compare April 15, 2026 15:24
@dhalbert

Copy link
Copy Markdown
Contributor Author

Ready for re-review (though I think one test is stuck).

  • There are now no more bare trailing spaces in tests/ .py and .exp files. In many cases where a possibly empty string was being printed via, say, print(..., some_str), causing a trailing space, I used print(..., repr(some_str)) instead. This makes the empty string visible and prevents bare trailing spaces.

  • I added ports/unix/extra_coverage.py to the tests_with_regex_output list in run-tests.py. Changing the C code to remove the trailing spaces is not easy and not worth it.

  • In run-tests.py, the {\xnn} escapes were treating nn as decimal instead of hex. This only became obvious when I added some {\x20} escapes. Fixed.

  • run-tests.py was not looking for .native.exp files when those files were regexp files. Fixed.

In the long run, I wonder if it would be easier to mark regexp .exp files with some special filename, like .re.exp or .expre. That would eliminate some is_special treatment and the special-case tests_with_regex_output list. But I'd leave that for another PR.

@dhalbert
dhalbert requested a review from dpgeorge April 15, 2026 17:12

@dpgeorge dpgeorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for making this more comprehensive, it looks really good now. Definitely better to be explicit about whitespace.

Comment thread tests/ports/esp32/check_err_str.py Outdated
Comment thread tests/run-tests.py
Comment thread tests/run-tests.py
@dpgeorge

Copy link
Copy Markdown
Member

In the long run, I wonder if it would be easier to mark regexp .exp files with some special filename, like .re.exp or .expre. That would eliminate some is_special treatment and the special-case tests_with_regex_output list. But I'd leave that for another PR.

Yes, that sounds like a good idea!

Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
Signed-off-by: Dan Halbert <halbert@halwitz.org>
@dhalbert
dhalbert force-pushed the protect-py-exp-trailing-spaces branch from f335f20 to d598019 Compare April 16, 2026 14:21
@dhalbert

Copy link
Copy Markdown
Contributor Author

@dpgeorge I think I addressed all your review remarks. One test failed in the unix qemu_arm job: thread/stress_heap.py. Again looks like some intermittent thing.

@dhalbert

Copy link
Copy Markdown
Contributor Author

Two more tests are stuck on web fetches. I think a re-run is in order.

Signed-off-by: Dan Halbert <halbert@halwitz.org>
@dhalbert
dhalbert force-pushed the protect-py-exp-trailing-spaces branch from 236978e to 2f9da6e Compare April 17, 2026 02:09
@dhalbert
dhalbert requested a review from dpgeorge April 17, 2026 02:23

@dpgeorge dpgeorge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for updating, looks good!

@dpgeorge

Copy link
Copy Markdown
Member

Rebased and merged in 6b97759 through d54e675

@dpgeorge dpgeorge closed this Apr 30, 2026
@dhalbert
dhalbert deleted the protect-py-exp-trailing-spaces branch April 30, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Relates to tests/ directory in source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Handle trailing whitespace in test .exp files using regexp syntax

3 participants