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

Move logic in run.sh to rust #98

Merged
merged 7 commits into from
Nov 28, 2023
Merged

Move logic in run.sh to rust #98

merged 7 commits into from
Nov 28, 2023

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Nov 26, 2023

Moving all logic to Rust makes it easier to understand what the test runner does. It also paves the way for some more substantial refactoring that may cross the previous boundary between shell script and rust executable.

@senekor senekor requested a review from a team as a code owner November 26, 2023 22:12
Copy link
Contributor Author

@senekor senekor left a comment

Choose a reason for hiding this comment

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

I intentionally tried to keep the rust code as close to the shell script as possible for now to make the review simpler. There are several refactoring opportunities which I intend to address in a future PR. For now, it should be possible to put the script and rust code side-by-side and confirm that more or less the same thing is happening.

@@ -24,7 +25,7 @@ for test_dir in tests/*; do
rm -rf "${test_dir_path}/target"
rm -f "${test_dir_path}/Cargo.lock"

bin/run.sh "${test_dir_name}" "${test_dir_path}" "${test_dir_path}" > /dev/null 2>&1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this initially for debugging purposes, but I didn't put it back because the run script isn't supposed to write to stdout / stderr anyway. Suppressing it only leads to more confusion when something does go wrong.

@@ -1,9 +1,12 @@
[package]
name = "transform-output"
name = "rust_test_runner"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rename reflects that all test running logic is now in rust, not just the transformation of cargo's output.

version = "0.1.0"
authors = ["Peter Goodspeed-Niklaus <[email protected]>"]
edition = "2018"
edition = "2021"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are always compiler warnings when some code is doing something that was deprecated / will change in a future edition. Since we didn't get any warnings for 2018, it is safe to upgrade.

@@ -1,4 +1,5 @@
{
"version": 2,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I actually caught a bug here? For two test cases, the run.sh script would not emit the version property.

std::env::set_current_dir(&cli_args.input_dir)
.context("failed to 'cd' into the input directory")?;

let mut results_out = String::new();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One thing I did change compared to the logic in run.sh is that the file results.out is not written to anymore. As far as I know, it is not part of the test runner interface. Internally, it is only used to store temporary data. So I left it as a mutable variable instead of writing the content to the filesystem.

Copy link
Member

Choose a reason for hiding this comment

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

That's perfectly fine as we do indeed not use that file.

Comment on lines +65 to +68
let out = convert(
serde_json::Deserializer::from_slice(&cargo_output.stdout).into_iter::<TestEvent>(),
);
let mut results_json = serde_json::to_string_pretty(&out)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is basically what main.rs contained before. (excluding reading from stdin and writing to stdout) Everything above and below is adapted from the shell script.

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

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

LGTM

std::env::set_current_dir(&cli_args.input_dir)
.context("failed to 'cd' into the input directory")?;

let mut results_out = String::new();
Copy link
Member

Choose a reason for hiding this comment

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

That's perfectly fine as we do indeed not use that file.

@senekor senekor merged commit 9b9bb6b into main Nov 28, 2023
1 check passed
@senekor senekor deleted the v2 branch November 28, 2023 08:06
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