Skip to content

print MDTEST_TEST_FILTER value in single-quotes (and escaped) #16548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

ericmarkmartin
Copy link
Contributor

Summary

If an mdtest fails, the error output will include an example command that can be run to re-run just the failing test, e.g

To rerun this specific test, set the environment variable: MDTEST_TEST_FILTER="sync.md - With statements - Context manager with non-callable `__exit__` attribute"
MDTEST_TEST_FILTER="sync.md - With statements - Context manager with non-callable `__exit__` attribute" cargo test -p red_knot_python_semantic --test mdtest -- mdtest__with_sync

This is very helpful, but because we're printing the envvar value surrounded in double-quotes, the bits between backticks in this example get interpreted as a shell interpolation. When running this in zsh, for example, I see

MDTEST_TEST_FILTER="sync.md - With statements - Context manager with non-callable `__exit__` attribute" cargo test -p red_knot_python_semantic --test mdtest -- mdtest__with_sync  
zsh: command not found: __exit__
   Compiling red_knot_python_semantic v0.0.0 (/home/ericmarkmartin/Development/ruff/crates/red_knot_python_semantic)
   Compiling red_knot_test v0.0.0 (/home/ericmarkmartin/Development/ruff/crates/red_knot_test)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 6.09s
     Running tests/mdtest.rs (target/debug/deps/mdtest-149b8f9d937e36bc)

running 1 test
test mdtest__with_sync ... ok

1

This is a minor annoyance which we can solve by using single-quotes instead of double-quotes for this string. To do so safely, we also escape single-quotes possibly contained within the string.

There is a shell-quote crate, which seems to handle all this escaping stuff for you but fixing this issue perfectly isn't a big deal (if there are more things to escape we can deal with it then), so adding a new dependency (even a dev one) seemed overkill.

Test Plan

I broke the ## Context manager with non-callable `__exit__` attribute test by deleting the error assertion, then successfully ran the new command it printed out.

Footnotes

  1. The filter does still work---it turns out that the filter MDTEST_TEST_FILTER="sync.md - With statements - Context manager with non-callable attribute" (what you get after the failed interpolation) is still good enough

@AlexWaygood AlexWaygood added the ty Multi-file analysis & type inference label Mar 7, 2025
@MichaReiser
Copy link
Member

Thanks. I verified that this doesn't break fish shell.

@MichaReiser MichaReiser merged commit 05a4c29 into astral-sh:main Mar 7, 2025
21 checks passed
@ericmarkmartin ericmarkmartin deleted the mdtest-escape-backticks branch March 8, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ty Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants