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

isolate tests.Rraw from variables created by user in .GlobalEnv #5101

Merged
merged 4 commits into from
Aug 18, 2021

Conversation

mattdowle
Copy link
Member

@mattdowle mattdowle commented Aug 18, 2021

Closes #3705

Could change z to be an unusual name such as foo6937265 and skip the test in the unusual case that even that was in .GlobalEnv. However, trying to tackle the root cause by changing the parent of the env that tests run inside, so we never have this issue again.

First commit set parent to parent.env(.GlobalEnv) which is search()[2]. This worked in that test 1894 no longer sees the z in .GlobalEnv. However, then other tests which load bit64 fail because when they are loaded at the top of tests.Rraw they become the new position 2 and functions like as.integer64() are not found because the parent of the env is now position 3 (the old position 2).

Hence tests.Rraw now attaches suggests at the end of search().

@mattdowle mattdowle added this to the 1.14.1 milestone Aug 18, 2021
@mattdowle mattdowle changed the title attempt 1 doesn't work, see comments in PR isolate tests.Rraw from variables created by user in .GlobalEnv Aug 18, 2021
@MichaelChirico
Copy link
Member

pretty cool & straightforward if it works. otherwise, what about something like

(1) copy .GlobalEnv to tmpEnv
(2) run tests
(3) on.exit, copy tmpEnv to .GlobalEnv

risk being user has large objects which are expensive to copy...

@mattdowle
Copy link
Member Author

mattdowle commented Aug 18, 2021

I guess there's a missing step (1.5) which removes everything in .GlobalEnv. If so, that not allowed by CRAN policy; e.g. what if the on.exit somehow doesn't run, or the on.exit does run but only gets through half the restore.

@MichaelChirico
Copy link
Member

mitigated by iterating the overwrite but fair, it's not a great solution if we can avoid it.

@mattdowle
Copy link
Member Author

I checked R 3.1.0's library() function has all the arguments this PR uses: character.only, logical.return, quietly, warn.conflicts and pos.

@mattdowle mattdowle merged commit 69ce691 into master Aug 18, 2021
@mattdowle mattdowle deleted the test-fail-if-z-defined branch August 18, 2021 03:40
@jangorecki jangorecki modified the milestones: 1.14.9, 1.15.0 Oct 29, 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.

tests fail if z in .GlobalEnv
3 participants