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

testing output using patterns disabled when parentheses present #3422

Closed
jangorecki opened this issue Feb 20, 2019 · 1 comment
Closed

testing output using patterns disabled when parentheses present #3422

jangorecki opened this issue Feb 20, 2019 · 1 comment
Milestone

Comments

@jangorecki
Copy link
Member

jangorecki commented Feb 20, 2019

At least the last test call in below example should pass. Ideally second to last also.
If possible would be great to have that for 1.12.2 as it blocks some other PR that should goes for 1.12.2.

#test = data.table:::test 
#cc(F)
dummy = function(..., use.parentheses=FALSE) {
  part_of_msg = "fun"
  if (use.parentheses) part_of_msg = paste0("(", part_of_msg, ")") 
  cat(sprintf("starting dummy %s\n", part_of_msg))
  t = system.time(Sys.sleep(0.001))[["elapsed"]]
  cat(sprintf("dummy took %.3fs\n", t))
  list(...)
}
dummy(1)
#starting dummy fun
#dummy took 0.001s
#[[1]]
#[1] 1
#
dummy(1, use.parentheses=TRUE)
#starting dummy (fun)
#dummy took 0.001s
#[[1]]
#[1] 1

isTRUE(test(1, dummy(1), output=c("starting dummy fun", "dummy took.*s")))
#[1] TRUE
test(1, dummy(1, use.parentheses=TRUE), output=c("starting dummy (fun)", "dummy took.*s"))
#Test 1 didn't produce correct output:
#Expected: <<starting dummy (fun)\ndummy took.*s>>
#Observed: <<starting dummy (fun)\ndummy took 0.001s\n[[1]]\n[1] 1\n>>
test(1, {dummy(1, use.parentheses=TRUE); NULL}, output=c("starting dummy (fun)", "dummy took.*s"))
#Test 1 didn't produce correct output:
#Expected: <<starting dummy (fun)\ndummy took.*s>>
#Observed: <<starting dummy (fun)\ndummy took 0.001s>>

overcomplicated attempt to solve that was made in https://github.com/Rdatatable/data.table/pull/3394/files

@jangorecki
Copy link
Member Author

jangorecki commented Feb 20, 2019

Actually the solution is good enough is to wrap round brackets ( and ) into square brackets when defining ouput for test

test(1, dummy(1, use.parentheses=TRUE), output=c("starting dummy [(]fun[)]", "dummy took.*s"))

This is pretty much enough, as doesn't require to change the code, but escape character that have special meaning, which can be made just inside unit tests. Closing then.

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

No branches or pull requests

1 participant