-
Notifications
You must be signed in to change notification settings - Fork 5
Parallelize tests and implement CmdArgument for TempDir #74
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think I'd prefer not making this change. For the doctests: I think that the main concern should be what would be the best documentation for users. And introducing a tempdir
is not really useful and might even be confusing. And by default it doesn't even work for users, since the tempdir
feature is not enabled. And for the unit tests: I think introducing a tempdir
as an argument to cmd!
is not really nice, because it moves the tests slightly further away from the real use-cases that are tested. And personally I have nothing against how in_temporary_directory
works.
I do agree that it'd be nice to solve the problems this PR solves: Allowing cargo test
to work out of the box and avoiding to write test files into the root directory of the repo. But I think there are different solutions for these problems, that don't come with the above-mentioned drawbacks. For example we could wrap the doctests in in_temporary_directory
and comment the lines where that happens, so that they don't show up in the docs. And to allow cargo test
, we could have a test wrapper (similar to in_temporary_directory
) that acquires a global lock.
But yeah, you also wrote that the initial intention for this PR was to make the tests faster. I agree that that would be great! At the same time I also think that the two solvable problems from above don't have a really high priority. So I would propose to close this PR unmerged. If you feel that either of the two problems are really important, of course feel free to open issues or PRs for them.
What do you think?
}); | ||
let tempdir = TempDir::new().unwrap(); | ||
let args: [&str; 1] = ["foo bar"]; | ||
cmd_unit!("touch", args, &tempdir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the previous version better, since it is closer to what we actually want to test. And since this doesn't seem much faster, I wouldn't change this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Same for the other tests in here.)
I definitely agree with a lot of your points. The doctests should be as good as possible, and definitely shouldn't rely on an optional feature. That could be done with, instead of having a let tmpdir = Tempdir::new().unwrap();
cmd_unit!(%"touch foo", CurrentDir(tmpdir.path())); I think that I find One non-aesthetic downside of |
Closing in favor of solving these problems (parallelize tests, get rid of weird |
I did this because I thought the tests were slow because of
--test-threads=1
, but it turns out it's because doctests are just inherently slow, so this doesn't actually improve the speed.It does allow tests to be run with
cargo test
(at least if the test helper binaries are built), which is nice.I also changed it to avoid creating tempfiles in the project root, and removed the corresponding entries in
.gitignore
.To do this, I added a
CmdArgument
forTempDir
, which I think is super useful, so I made it an optional feature.You can enable the
tepdir
feature to enable theCmdArgument
forTempDir
, which enables the optional dependency ontempfile
.