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

call_wd() returns wrong directory in tests run by run_test_dir() #128

Open
reedacartwright opened this issue Feb 7, 2024 · 1 comment
Open

Comments

@reedacartwright
Copy link

reedacartwright commented Feb 7, 2024

First, assume that getwd() returns "pkg". Then if I run tests via run_test_dir("tests"), and use call_wd() to access the previous working directory, it will return "pkg/tests" instead of "pkg".

I believe that the bug can be traced to https://github.com/markvanderloo/tinytest/blob/master/pkg/R/tinytest.R#L20

While set_call_wd() contains logic to not update CALLDIR if it is already set, it does not have logic to prevent it from being unset prematurely. The logic flow looks like this:

  1. run_test_dir("tests") calls set_call_wd("pkg") and changes directory to "tests" => CALLDIR set to "pkg"
  2. run_test_file("test-a.R") calls set_call_wd("pkg/tests") and changes directory to "tests" => CALLDIR not changed
  3. run_test_file("test-a.R") calls set_call_wd("") on exit and changes directory to "tests" => CALLDIR set to ""
  4. run_test_file("test-b.R") calls set_call_wd("pkg/tests") and changes directory to "tests" => CALLDIR set to "pkg/tests"

I think the simplest solution would be:

  1. set_call_wd(dir) to push dir onto the back of CALLDIR and
  2. set_call_wd("") to pop the back of CALLDIR
  3. And get_call_wd() only return CALLDIR[1]
@markvanderloo
Copy link
Owner

Thanks, I will look into this. it will require some heavy reverse dependency testing.

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

No branches or pull requests

2 participants