Skip to content

Conversation

@mattdowle
Copy link
Member

@mattdowle mattdowle commented Aug 25, 2021

Follows #5104

Closes #5106 by making DT() always print. This printing can't be tested afaik because test() uses capture.output() which always invokes the printed output. That's why tests/autoprint.R exists because that's the only known way to test R's autoprinting mechanism (i.e. what happens at the R prompt). However, we can't add a |> test to that because |> depends on R>4.1.0 and any sort of conditional like that will change the scripts output (autoprint.Rout) which gets compared against the fixed autoprint.Rout.save. However, since the always-print solution is simple and absolute, and there's no known way, then I think it's acceptable to proceed.

Closes #5107. All tests added.

@mattdowle mattdowle added this to the 1.14.1 milestone Aug 25, 2021
@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #5113 (e8fdf37) into master (7f3fba9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head e8fdf37 differs from pull request most recent head 72f1f48. Consider uploading reports for the commit 72f1f48 to get more accurate results
Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5113   +/-   ##
=======================================
  Coverage   99.53%   99.53%           
=======================================
  Files          76       76           
  Lines       14448    14459   +11     
=======================================
+ Hits        14381    14392   +11     
  Misses         67       67           
Impacted Files Coverage Δ
R/data.table.R 99.94% <100.00%> (+<0.01%) ⬆️
R/test.data.table.R 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76cfe11...72f1f48. Read the comment docs.

@mattdowle mattdowle added the WIP label Aug 26, 2021
@jangorecki
Copy link
Member

jangorecki commented Sep 14, 2022

However, we can't add a |> test to that because |> depends on R>4.1.0 and any sort of conditional like that will change the scripts output (autoprint.Rout) which gets compared against the fixed autoprint.Rout.save

There is a trick I did in cat tests/knitr.R

if (suppressPackageStartupMessages(requireNamespace("knitr", quietly = TRUE))) {
    require(knitr)
    knit("knitr.Rmd", quiet=TRUE)
    cat(readLines("knitr.md"), sep="\n")
    invisible(file.remove("knitr.md"))
} else {
    cat(readLines("knitr.Rout.mock", warn = FALSE), sep="\n")
}

and then mock file is just expected output. So in this case instead of requireNamespace we can test R version, and cat(readLines()) expected output from 4.1+ on older R versions.

@MichaelChirico
Copy link
Member

We can also use .Rin files I believe:

Test code can either be provided directly in a .R (or .r as from R 3.4.0) file, or via a .Rin file containing code which in turn creates the corresponding .R file

https://cran.r-project.org/doc/manuals/r-release/R-exts.html#Package-subdirectories

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

3 participants