| 1 |
library(testit) |
| 2 |
|
| 3 |
if (requireNamespace('otelsdk', quietly = TRUE)) { |
| 4 |
|
| 5 |
record = with_otel_record({ |
| 6 |
knit( |
| 7 |
text = c('<<tidy=FALSE, eval=1:2, echo=FALSE, results="asis">>=', '1', '1+', '1', '1', '@'), |
| 8 |
quiet = TRUE |
| 9 |
) |
| 10 |
}) |
| 11 |
|
| 12 |
traces = record$traces |
| 13 |
|
| 14 |
assert('otel tracing works on text input', { |
| 15 |
(length(traces) %==% 3L) |
| 16 |
(startsWith(traces[[1L]]$name, 'knitr processing')) |
| 17 |
(traces[[1L]]$attributes$knitr.format %==% 'latex') |
| 18 |
(traces[[1L]]$attributes$knitr.input %==% '') |
| 19 |
(traces[[1L]]$attributes$knitr.output %==% '') |
| 20 |
(traces[[2L]]$name %==% 'knit unnamed-chunk-1') |
| 21 |
(traces[[2L]]$attributes$knitr.chunk.device %==% 'pdf') |
| 22 |
(traces[[2L]]$attributes$knitr.chunk.echo %==% FALSE) |
| 23 |
(traces[[2L]]$attributes$knitr.chunk.engine %==% 'R') |
| 24 |
(traces[[2L]]$attributes$knitr.chunk.eval %==% c(1, 2)) |
| 25 |
(traces[[2L]]$attributes$knitr.chunk.label %==% 'unnamed-chunk-1') |
| 26 |
(startsWith(traces[[3L]]$name, 'knitr output')) |
| 27 |
(traces[[3L]]$attributes$knitr.format %==% 'latex') |
| 28 |
(traces[[3L]]$attributes$knitr.input %==% '') |
| 29 |
(traces[[3L]]$attributes$knitr.output %==% '') |
| 30 |
}) |
| 31 |
|
| 32 |
record = with_otel_record({ |
| 33 |
local({ |
| 34 |
env = new.env() |
| 35 |
env$y = 1:3 |
| 36 |
z = 5 |
| 37 |
on.exit(file.remove('knit-envir.md')) |
| 38 |
knit('knit-envir.Rmd', envir = env, quiet = TRUE) |
| 39 |
}) |
| 40 |
}) |
| 41 |
|
| 42 |
traces = record$traces |
| 43 |
|
| 44 |
assert('otel tracing works when knitting files', { |
| 45 |
(length(traces) %==% 3L) |
| 46 |
(traces[[1L]]$name %==% 'knitr processing knit-envir.Rmd') |
| 47 |
(traces[[1L]]$attributes$knitr.format %==% 'markdown') |
| 48 |
(traces[[1L]]$attributes$knitr.input %==% 'knit-envir.Rmd') |
| 49 |
(traces[[1L]]$attributes$knitr.output %==% 'knit-envir.md') |
| 50 |
(traces[[2L]]$name %==% 'knit test') |
| 51 |
(traces[[2L]]$attributes$knitr.chunk.device %==% 'png') |
| 52 |
(traces[[2L]]$attributes$knitr.chunk.echo %==% TRUE) |
| 53 |
(traces[[2L]]$attributes$knitr.chunk.engine %==% 'R') |
| 54 |
(traces[[2L]]$attributes$knitr.chunk.eval %==% TRUE) |
| 55 |
(traces[[2L]]$attributes$knitr.chunk.label %==% 'test') |
| 56 |
(traces[[3L]]$name %==% 'knitr output knit-envir.md') |
| 57 |
(traces[[3L]]$attributes$knitr.format %==% 'markdown') |
| 58 |
(traces[[3L]]$attributes$knitr.input %==% 'knit-envir.Rmd') |
| 59 |
(traces[[3L]]$attributes$knitr.output %==% 'knit-envir.md') |
| 60 |
}) |
| 61 |
|
| 62 |
} |