pdrhlik / sweary

R package that collects swear words from different languages.
MIT License
19 stars 8 forks source link

testthat/helper_file_names.R in tests brakes #5

Closed MarcinKosinski closed 5 years ago

MarcinKosinski commented 5 years ago

@pdrhlik I think this is related to that line in tests https://github.com/pdrhlik/sweary/blob/master/tests/testthat/helper_file_names.R#L2

  Running 'testthat.R'
Running the tests in 'tests/testthat.R' failed.
Last 13 lines of output:
  -- 1. Failure: swear word lists folder exists (@test_raw_swear_words.R#4)  --------------------------------------------------
  file.exists(swear_word_folder) isn't true.

========================================================================================================
  OK: 0 SKIPPED: 0 FAILED: 1
  1. Failure: swear word lists folder exists (@test_raw_swear_words.R#4) 

  Error: testthat unit tests failed
  Execution halted
MarcinKosinski commented 5 years ago

@pdrhlik also add dplyr to Suggests in DESCRIPTION

pdrhlik commented 5 years ago

It works when using devtools::test() but not using devtools::check(). That's because I'm relying on the raw swear word lists that are stored in data-raw/swear-word-lists right now. Probably because it's a non-standard directory, it's not copied to the assumed placed.

pdrhlik commented 5 years ago

So the real problem with this test failing is the difference between testing the source/installation. We have the folder data-raw/swear-word-lists that contains all the currently completed language files.

If we use devtools::check(), this folder isn't installed. So when the tests are run, there are actually no files to be tested. It works just fine when doing devtools::test() because the folder can be accessed.

There are to possible solutions to this.

First: Don't run these tests on an installed package at all. We probably don't need to have the raw files present there. That means that these tests are only for local testing when creating/editing language files. We already have all the data in an exported data frame.

Second: Move the folder to inst/ so that it can be accessed in an installed package. I tried that, it works. The only thing is that we have to check the folder in which the word lists are. It will be either swear-word-lists/ or inst/swear-word-lists/.

I would personally prefer the first solution. It will make our package even smaller and probably makes more sense. What do you think, @MarcinKosinski?

mczyzj commented 5 years ago

I had similar problem with my package and the solution was to add sample file to the test folder (not very elegant, but worked)

MarcinKosinski commented 5 years ago

@mczyzj @pdrhlik if we only test that locally let's have those tests in a directory that is then listed in the .Rbuildignore. So the 3rd option is to move test for the data-raw to data-raw and then to extend .Rbuildignore with data-raw.

pdrhlik commented 5 years ago

I'll try Marcin's suggestion. That's probably the best option.

pdrhlik commented 5 years ago

The local tests should be run using testthat::test_dir("data-raw/tests-local/"). I'll close this for now. We'll see in the future if this approach is sustainable.