test_that("qmd_to_r_script() errors on wrong qmd", { expect_snapshot( error = TRUE, qmd_to_r_script("nonexistent.qmd") ) }) test_that("qmd_to_r_script() errors on existing script", { r_script <- withr::local_tempfile(pattern = "purl", fileext = ".R") file.create(r_script) expect_snapshot( error = TRUE, qmd_to_r_script(resources_path("purl-r.qmd"), script = r_script), transform = function(x) { gsub("(! File ).*( already exists.)", "\\1\\2", x) } ) }) test_that("qmd_to_r_script() writes R file that renders", { skip_if_no_quarto() r_script <- withr::local_tempfile(pattern = "purl", fileext = ".R") announce_snapshot_file(name = "purl.R") expect_snapshot_file( path = qmd_to_r_script( resources_path("purl-r.qmd"), script = r_script ), name = "purl.R" ) skip_if_no_quarto("1.4.511") announce_snapshot_file(name = "purl.md") md_file <- xfun::with_ext(r_script, "md") .render( r_script, output_file = basename(md_file), output_format = "markdown", .quiet = TRUE ) expect_snapshot_file( path = md_file, name = "purl.md" ) }) test_that("qmd_to_r_script() comment cells with eval = TRUE", { r_script <- withr::local_tempfile(pattern = "purl", fileext = ".R") qmd_to_r_script( resources_path("purl-r.qmd"), script = r_script ) content <- xfun::file_string(r_script) expect_match( content, "# # This code should not run.", fixed = TRUE ) expect_no_match( content, "(?