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

TemporaryWorkingDirectory helper #11385

Merged
merged 2 commits into from
May 20, 2021
Merged

Conversation

cameel
Copy link
Member

@cameel cameel commented May 12, 2021

Depends on #11384. Marked as draft until the dependency gets merged.

This PR adds a very simple TemporaryWorkingDirectory test helper that lets you change working directory in a test without risking the change being permanent and affecting other tests. If your test crashes, the object ensures upon destruction that the directory gets changed back.

@cameel cameel self-assigned this May 12, 2021
@cameel cameel marked this pull request as draft May 12, 2021 16:21
/**
* An object that changes current working directory and restores it upon destruction.
*/
class TemporaryWorkingDirectory
Copy link
Member Author

Choose a reason for hiding this comment

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

I put the class in TemporaryDirectory.h which already contains a similar helper but maybe I should create a separate TemporaryWorkingDirectory.h instead?

Copy link
Member

Choose a reason for hiding this comment

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

If we have such a granular separation in the test directory, then yes, otherwise I think it is fine.

Base automatically changed from expose-temporary-directory-helper to develop May 18, 2021 10:44
@axic axic marked this pull request as ready for review May 18, 2021 10:47
@cameel cameel force-pushed the temporary-working-directory-helper branch from 4415682 to bf431b0 Compare May 19, 2021 18:56
@cameel cameel force-pushed the temporary-working-directory-helper branch from f286252 to 4a2080b Compare May 19, 2021 22:09
@cameel
Copy link
Member Author

cameel commented May 19, 2021

I solved the CI problems so this is now ready for review.

The issue was that the path to a tmp dir I was receiving on macOS was through a symlink. I was using that path to change directory but then, upon asking what the current directory is I was getting canonical path and the comparison in a test was failing. Switching to boost::filesystem::equivalent() for path comparison solved the problem.

@axic axic merged commit 13388e2 into develop May 20, 2021
@axic axic deleted the temporary-working-directory-helper branch May 20, 2021 19: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