tinytest icon indicating copy to clipboard operation
tinytest copied to clipboard

Testing internal functions with test_file as well as build_install_test

Open grimmjulian opened this issue 1 year ago • 2 comments

This is a question, not a bug.

I write a test function for an internal function in a testfile, I use the :::-approach for the function and use build_install_test(). But if I only use test_file for this internal function, it does not work as the package is not installed or an older version. Also I cannot simply load the function in the global environment, as the three colons let R search for the package. So how can I tackle this problem: using test_file() as well as build_install_test() for internal functions?

grimmjulian avatar Nov 10 '22 16:11 grimmjulian

hmm, I don't think I ever used that workflow as I tend to only test functions that are exposed to the user, but I see your point. I can't think of a quick workaround. Perhaps you could use pkgload::load_package() and then run test_file? (disclaimer: I never use pkgload, so I have no idea if that would work)

markvanderloo avatar Nov 14 '22 22:11 markvanderloo

So I tried using pkgload::load_all() before the test_*-function, so I could run the tests without :::. This works, but then the build_install_test() function does not work anymore. Maybe I could use a conditional test, but right now I cannot think of a good condition.

grimmjulian avatar Nov 15 '22 13:11 grimmjulian