File: test_mdtangle.R

package info (click to toggle)
r-cran-simplermarkdown 0.0.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: makefile: 2
file content (63 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# mdtangle a couple of documents and check if the output is the
# same as the corresponding reference documents

library(simplermarkdown)

if (simplermarkdown:::has_pandoc()) {

  # Create tempdir
  dir <- tempdir()
  dir.create(dir, recursive = TRUE, showWarnings = FALSE)
  oldwd <- setwd(dir)

  # When running tests the environment variable R_TESTS is set. This
  # causes issues when running a second R instance as mdweave does. Therefore
  # we unser it.
  old_env <- Sys.getenv("R_TESTS")
  Sys.setenv("R_TESTS" = "")


  # =============================================================================
  message("Checking iris.md")
  md <- "iris.md"
  r <- "iris.R"

  message("Tangle file")
  fn <- system.file(file.path("examples", md), package = "simplermarkdown")
  mdtangle(fn)

  message("Compare to reference")
  lines <- readLines(r)
  fn_ref <- system.file(file.path("examples_output", r), 
    package = "simplermarkdown")
  lines_ref <- readLines(fn_ref)
  stopifnot(isTRUE(all.equal(lines, lines_ref)))

  message("Cleanup")
  unlink(r)

  # =============================================================================
  message("Checking example1.md")
  md <- "example1.md"
  r <- "example1.R"

  message("Tangle file")
  fn <- system.file(file.path("examples", md), package = "simplermarkdown")
  mdtangle(fn)

  message("Compare to reference")
  lines <- readLines(r)
  fn_ref <- system.file(file.path("examples_output", r), 
    package = "simplermarkdown")
  lines_ref <- readLines(fn_ref)
  stopifnot(isTRUE(all.equal(lines, lines_ref)))

  message("Cleanup")
  unlink(r)


  Sys.setenv("R_TESTS" = old_env)
  setwd(oldwd)

}