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

auto_test_package do not update helpers when a test is changed #896

Closed
CorradoLanera opened this issue Jul 12, 2019 · 0 comments
Closed
Labels
bug an unexpected problem or unintended behavior

Comments

@CorradoLanera
Copy link
Contributor

If you modify a script, all tests (and helpers) are run.
If you modify a test, only that test is run, correctly.
The problem rises if you create a helper file to extract some preprocessing from a test.

When you create the helper it is run, it contains no test, and the results are all green zeros, correctly. Next, when you return to the test function, and you remove the no more necessary code, only this test is run, but not the helper, and it rises a (wrong) error.

On the other hand, the first script you modify later provide a run of the whole test folder, helper included, and from that time on the objects are stored in the test environment, and so everything return working. The problem occurs only the first time.

example:

  1. Create foo.R in R/:
foo <- function(x) x
  1. Create a test-foo.R
a <- 1
expect_equal(foo(a), 1)

All the test pass!

  1. Create helper-foo.R
a <- 1

The "test" helper-foo.R is runned reporting no test and no erorr :-)

  1. Remove assignment from test-foo.R which becomes simply
expect_equal(foo(a), 1)

And now the test report an error

object 'a' not found

  1. Make any modification to any script, for example, add curly braces to foo.R, just to save it and trig the call to the tests
foo <- function(x) {
    x
}

And everything is evaluated, and all the test passed.

  1. Even if you modify test-foo.R, e.g.
expect_equal(foo(a), 1)
expect_equal(foo(a), 1)

And only this test is called and run, from now it passes correctly. Until you change the helper:

  1. Modify helper-foo.R
a <- 2

The "test" helper-foo.R is run reporting no test and no errors

  1. Modify test-foo.R accordingly
expect_equal(foo(a), 2)

And the test is run reporting an error:

'a' not equal to 2
1/1 mismatches
[1] 1 - 2 == -1"

Adopting a solution like the one purposed in #376 could help.

@hadley hadley added the bug an unexpected problem or unintended behavior label Jul 15, 2019
@hadley hadley closed this as completed in d908e2c Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants