r-lib / rcmdcheck

Run R CMD check from R and collect the results
https://rcmdcheck.r-lib.org
Other
115 stars 27 forks source link

Function/Variables disappear using rmcdcheck() on tests #217

Closed latot closed 1 year ago

latot commented 1 year ago

Hi all, this was initially related to https://github.com/moodymudskipper/typed/issues/33.

Actually when we run tests on the sample I send we have this error:

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]

══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-bug_typed.R:4:3'): test_assert ─────────────────────────────────
Error: In `test_assert()` at `custom_var <- ...`:
could not find function "cassert"
Backtrace:
    ▆
 1. ├─bugtyped::test_assert() at test-bug_typed.R:4:3
 2. └─typed (local) `<fn>`(base::quote(1L))

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 0 ]
Error: Test failures
Execution halted

1 error ✖ | 1 warning ✖ | 0 notes ✔

What is weird, cassert is a function in the library, I thought this was a error on the typed library, until today when I notice this:

devtools::test()
ℹ Testing bugtyped
✔ | F W  S  OK | Context
✔ |          1 | bug_typed                                                                                                                                                                                         

══ Results ════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════════
[ FAIL 0 | WARN 0 | SKIP 0 | PASS 1 ]

Using devtools to run the tests actually works, so maybe this is more related to rcmdcheck and a bug in some part with env.

We can load the library, cassert exists, we can use it and all, only fails when we run rcmdcheck::rcmdcheck()

Thx!

bug_typed.zip

gaborcsardi commented 1 year ago

Do you have a reproducible example? E.g. can you share your package with us?

latot commented 1 year ago

Hi, I included the zip file in the end of the issue when I posted it :)

gaborcsardi commented 1 year ago

For the record, for us the easiest is if you share your reproducible example on GitHub, e.g. then we can refer to the code. In any case, I see the same issue with R CMD check, for which rcmdcheck is merely a wrapper of, so it is definitely not an issue with rcmdcheck.

latot commented 1 year ago

Hi, @gaborcsardi I know is a wrapper, I usually agree, but in this case, all tests passes with devtools::test(), also all in the example works, only fails from rcmdcheck::rcmdcheck().

I would appreciate if you can tell me to where this would belongs if is not testthat nor typed nor devtools.

Here the example: https://github.com/latot/bugs/tree/rcmdcheck-217

gaborcsardi commented 1 year ago

I would appreciate if you can tell me to where this would belongs if is not testthat nor typed nor devtools.

If I remove testthat.R, and then add another file tests/mytest.R:

library(bugtyped)
test_assert()

and then run R CMD check:

* checking tests ...
  Running ‘mytest.R’
 ERROR
Running the tests in ‘tests/mytest.R’ failed.
Complete output:
  >
  > library(bugtyped)
  > test_assert()
  Error: In `test_assert()` at `custom_var <- ...`:
  could not find function "cassert"
  Execution halted

Actually, even if I just install the package, and then load it and run test_assert(), I get the same:

❯ library(bugtyped)
❯ test_assert()
Error: In `test_assert()` at `custom_var <- ...`:
could not find function "cassert"

So this happens without testthat, and without rcmdcheck.

I don't know enough of typed to know if this is a bug in typed or you are not using it correctly, but it must be either one or the other.

latot commented 1 year ago

:O Thx! a new clue!

From the typed library, that is the way to declare assertions, I have a lot of them! and works pretty good, except this case which I have no idea why it fails, when I tried to get a reprex was also hard, touch one line and works, but seems to be more probable to happens with longer codes...

Thx!