Skip to content

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

@CorradoLanera

Description

@CorradoLanera

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions