Skip to content

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

Open
@reedacartwright

Description

@reedacartwright

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]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions