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

Make testthat tests more reliable when called from the interpreter. #80

Merged
merged 1 commit into from
Jul 19, 2013

Conversation

craigcitro
Copy link
Contributor

Currently, running test_dir on the testthat tests will fail on many systems when run interactively, due to what seems to be a race condition in the watcher code. (I'm waffling a little there, since the "race" seems to be 100% repeatable on some machines.) These patches clean that up, and do one more bit of cleanup-on-failure.

if (hash) {
sapply(files, digest::digest, file = TRUE)
vapply(files, safe_digest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that should be vapply(files, safe_digest, character(1))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I'd forgotten to give the template. Done.

Any strong feelings on character(1) vs. just ""? I only ask because I use "" below, so I figure they might as well match -- I prefer character(1), especially below where it's mixed in with string arguments, but I could see a strong argument for "" on brevity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer character(1) because it's more evocative of creating a data structure to fill - the important thing is that it's a character and length 1, not the contents.

@craigcitro
Copy link
Contributor Author

PTAL -- I think I've picked up everything.

@@ -33,7 +33,7 @@ StopReporter <- setRefClass("StopReporter", contains = "Reporter",
test <<- NULL
if (length(failures) == 0) return()

messages <- vapply(failures, "[[", "", "message")
messages <- vapply(failures, as.character, "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have said other comment here: character(1) instead of "" please

@hadley
Copy link
Member

hadley commented Jul 18, 2013

Apart from one last tiny change, looks good!

@unDocUMeantIt
Copy link

this hoepfully fixes some issues i'm having right now: tests fail when run by "R CMD check", but if i run them from an R session, everything is fine. the package tested creates some files in a tempdir and i want to check for their existance.

i've noticed errors like
"Error in file(filename, "r", encoding = encoding) : cannot open the connection
Calls: local ... eval.parent -> eval -> eval -> eval -> eval -> source -> file
In addition: Warning message:
In file(filename, "r", encoding = encoding): cannot open file 'startup.Rs': No such file or directory"
my package functions use some setwd() calls. when i create a dummy "startup.Rs" file in the directory the functions jump to, these errors disappear. i have no clue what this file is supposed to do or why it's only missing when "R CMD check" is running the tests. anyway, the tests still fail after all.

in addition, testthat didn't load all dependencies, i had do manually add a require() call to the test suite. here's the package, if you want to try to replicate the problem: http://reaktanz.de/stuff/R/roxyPackage_0.03-11.tar.gz

hope this helps.

@hadley
Copy link
Member

hadley commented Jul 18, 2013

@unDocUMeantIt That's unlikely to be the problem - can you please file a separate bug report?

@craigcitro
Copy link
Contributor Author

@hadley Made the last change -- do you want me to squash?

@hadley
Copy link
Member

hadley commented Jul 18, 2013

Yes please!

@craigcitro
Copy link
Contributor Author

Should be squashed and ready to go.

@hadley
Copy link
Member

hadley commented Jul 18, 2013

Sorry, forgot one last thing - can you please add a bullet point to NEWS briefly describing the change and thanking yourself?

@craigcitro
Copy link
Contributor Author

Will do -- I'm just walking out the door, but I'll --amend in some NEWS items to both pull requests after lunch.

Currently, `dir_state` can fail in unfortuate ways when a file disappears
between reading a directory listing and calculating a hash of its contents;
this patch fixes the problem by catching the failure and returning NA.
@craigcitro
Copy link
Contributor Author

NEWS updated -- should be good to go.

hadley added a commit that referenced this pull request Jul 19, 2013
Make testthat tests more reliable when called from the interpreter.
@hadley hadley merged commit 492b4e0 into r-lib:master Jul 19, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants