Skip to content
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

Migrate tests to use python scripts instead of rust test helper #210

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

soenkehahn
Copy link
Owner

@soenkehahn soenkehahn commented May 4, 2022

This PR tries to get rid of the test_executables_helper in favor of specifying test programs in python. This has some advantages:

  • It allows us to specify the test programs in (potentially multi-line) strings within the tests. Currently, some tests are pretty ugly, since the test program is inside a match statement in src/test_executables/helper.rs.
  • It's faster. Executing small python snippets is faster than compiling small rust snippets and executing them. Surprisingly, it's also faster than executing rust snippets with rust-script, even when the compilation artifacts are already cached.
  • Hopefully, it allows us to get rid of the test_executables_helper and the test_executables feature in Cargo.toml. I think these details ideally shouldn't be in that file.
  • Hopefully it allows us to get rid of the bitflags dependency. Not sure though.

There's also some disadvantages:

  • You need python3 to execute the tests. Fortunately, that is installed on lots of systems. For example to make this PR run on CI, I didn't have to install anything there.
  • You need to know python to write tests. I think this is pretty minor though, since python is fairly easy to learn and google things for, and also you only have to write very small test snippets.

src/lib.rs Outdated
Comment on lines 865 to 868
r#"
import sys
print("foo", file=sys.stderr)
"#,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you use single quotes you can avoid raw strings:

Suggested change
r#"
import sys
print("foo", file=sys.stderr)
"#,
"
import sys
print('foo', file=sys.stderr)
",

@casey
Copy link
Collaborator

casey commented May 4, 2022

Having the code be out-of-line doesn't bother me so much, so I think I still prefer keeping it in Rust vs adding Python. That being said, I don't feel super strongly about it. I can definitely see the readability benefit of having the code be in-line. Overall the PR looks good.

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