tests/testthat/test-golem_hook.R

# Generated by fusen: do not edit by hand

test_that("golem_hook works", {
  skip_on_cran()
  skip_if_not_installed("golem")
  skip_if_not_installed("usethis")
  old <- setwd(tempdir())
  on.exit(setwd(old))
  unlink("testgolembrochure", TRUE, TRUE)
  golem::create_golem(file.path(tempdir(), "testgolembrochure"), project_hook = brochure::golem_hook)
  setwd(file.path(tempdir(), "testgolembrochure"))
  expect_true(
    file.exists("R/mod_home.R")
  )
  expect_true(
    file.exists("R/run_app.R")
  )
  expect_equal(
    readLines(
      system.file(
        "golem/mod_home.R",
        package = "brochure"
      )
    ),
    readLines(
      "R/mod_home.R"
    )
  )

  expect_equal(
    list.files("R"),
    c("app_config.R", "mod_home.R", "run_app.R")
  )

  expect_true(
    file.exists("tests/testthat/test-mod_home.R")
  )

  # The golem recommended tests test `app_ui()` and `app_server()`, which the
  # hook deletes, and `use_recommended_tests()` errors on an existing file.
  expect_true(
    file.exists("tests/testthat/test-golem-recommended.R")
  )
  expect_false(
    any(
      grepl(
        "golem::use_recommended_tests()",
        readLines("dev/01_start.R"),
        fixed = TRUE
      )
    )
  )

  expect_equal(
    readLines("tests/testthat.R"),
    c(
      "library(testthat)",
      "library(testgolembrochure)",
      "",
      'test_check("testgolembrochure")'
    )
  )

  # The module template calls `page()`, so the app has to depend on brochure.
  expect_true(
    grepl(
      "brochure",
      paste(readLines("DESCRIPTION"), collapse = " ")
    )
  )

  expect_true(
    grepl(
      "brochure",
      paste(readLines("dev/02_dev.R"), collapse = " ")
    )
  )
})

# Generated by fusen: do not edit by hand

test_that("new_page adds a brochure page module", {
  x <- tempfile(fileext = ".R")
  new_page("pouet", x)

  tmplt <- readLines(
    x
  )
  expect_true(
    tmplt[1] == "#' pouet UI Function"
  )
  tmplt <- paste(tmplt, collapse = " ")
  expect_true(
    grepl("pouet", tmplt)
  )
  expect_true(
    grepl("page", tmplt)
  )

  skip_on_cran()
  skip_if_not_installed("golem")
  skip_if_not_installed("usethis")
  old <- setwd(tempdir())
  on.exit(setwd(old))
  unlink("testgolembrochure", TRUE, TRUE)
  golem::create_golem(file.path(tempdir(), "testgolembrochure"), project_hook = brochure::golem_hook)
  setwd(file.path(tempdir(), "testgolembrochure"))
  golem::add_module(name = "pouet", module_template = brochure::new_page, open = FALSE)
  expect_true(
    file.exists("R/mod_pouet.R")
  )
})

Try the brochure package in your browser

Any scripts or data that you put into this service are public.

brochure documentation built on Oct. 14, 2026, 5:08 p.m.