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

Added tests for load_overrides() in Artifacts.jl #51833

Merged
merged 5 commits into from
Oct 26, 2023

Conversation

u7581147
Copy link
Contributor

Fixes #48551
Continued from #51815
The load_overrides() method in Artifacts.jl has a large untested branch. This PR increases the test coverage for this method.

image
https://app.codecov.io/gh/JuliaLang/julia/blob/master/stdlib%2FArtifacts%2Fsrc%2FArtifacts.jl#L121

@KristofferC
Copy link
Sponsor Member

Nice work. Would it be better to create a temporary folder (mktemp) and set the DEPOT_PATH to that folder and create the override file inside there? Then the temp folder would automatically be deleted in the end and there isn't a need for any explicit teardown, you just have to restore DEPOT_PATH to what it was before?

@u7581147
Copy link
Contributor Author

That's a great idea! I'll be working on that.

…o that no explicit file/directory deletion is needed after the test.
@u7581147
Copy link
Contributor Author

OK, I think I know why the new commit fails. Apparently, I saved a file in my Virtual Machine but forgot to delete it, so my machine was the only one where the code runs.

Copy link
Sponsor Member

@staticfloat staticfloat left a comment

Choose a reason for hiding this comment

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

Overall, looks great to me, thank you for increasing test coverage in this area! I had a few style notes that I made for the test implementation.

@test load_overrides() == expected_output

# Create a temporary directory and set DEPOT_PATH to that directory
temp_dir = mktempdir()
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

You can use the do-block form of mktempdir() to explicitly scope when the temporary directory gets deleted, otherwise it only gets deleted at Julia exit. Example:

mktempdir() do temp_dir
    ...
end


# Create a temporary directory and set DEPOT_PATH to that directory
temp_dir = mktempdir()
old_depot_path = DEPOT_PATH[1]
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The old depot path can have multiple elements, so the most correct way to do this is to do:

old_depot_path = copy(DEPOT_PATH)
empty!(DEPOT_PATH)
push!(DEPOT_PATH, temp_dir)
try
    ...
finally
    empty!(DEPOT_PATH)
    append!(DEPOT_PATH, old_depot_path)
end

The try/finally is so that even if something goes horribly wrong, the depot path doesn't cause cascading failures for other tests within this same file that may still run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you so much for your idea! Yes, making sure that DEPOT_PATH will be restored to the status quo in the event of a bug is definitely the best practice.

@staticfloat staticfloat merged commit 837522a into JuliaLang:master Oct 26, 2023
3 of 7 checks passed
@staticfloat
Copy link
Sponsor Member

Thanks, @u7581147!

staticfloat pushed a commit that referenced this pull request Oct 27, 2023
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.

Override functionality for Artifacts seems to be untested
3 participants