Skip to content

Commit

Permalink
test: fix windows paths
Browse files Browse the repository at this point in the history
- C:\Users\x can not work as parsed like \U0000 character; winslash needs to be changed to /

issue #224
  • Loading branch information
statnmap committed Aug 16, 2023
1 parent 7925fc9 commit 1d3b460
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 73 deletions.
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# fusen 0.5.2

## New features

- Allow a styler function with parameter `stylers` in `inflate_all*()`

## Minor changes

- Fix use of `packageVersion()` with character
- Allow "." for current package when adding flat file without DESCRIPTION (#224)

# fusen 0.5.1

## New features
Expand Down
12 changes: 6 additions & 6 deletions R/add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ add_dev_history <- function(pkg = ".",
}

flat_template_choices <- c(
"full",
"minimal_package", "minpkg",
"minimal_flat", "minflat", "add", "additional",
"teach", "teaching",
"dev_history", "dev"
)
"full",
"minimal_package", "minpkg",
"minimal_flat", "minflat", "add", "additional",
"teach", "teaching",
"dev_history", "dev"
)

create_fusen_choices <- c("full", "minimal", "teaching", "dev_history")

Expand Down
8 changes: 4 additions & 4 deletions R/init_share_on_github.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#'
#' @param ask Logical. `TRUE` (default) to ask the user to apply the instructions each time needed,
#' or `FALSE` if the user already know what to do.
#'
#'
#' @details
#'
#'
#' `init_share_on_github()` runs multiple steps to be able to share a proper package on GitHub:
#'
#'
#' - Start versionning with git if not already
#' - Connect to your GitHub account
#' - Create a minimal DESCRIPTION file if missing
Expand All @@ -24,7 +24,7 @@
#' - Init continuous deployment (CD) of the {pkgdown} website documentation
#' - Commit and push to GitHub
#' - List remaining manual steps to make the website public
#'
#'
#' Read `vignette("share-on-a-github-website", package = "fusen")`
#'
#' @return The URL of the website created
Expand Down
2 changes: 1 addition & 1 deletion R/register_config_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ df_to_config <- function(df_files,
yaml_paths[!all_exists],
collapse = ", "
), ".\n",
"Please open the configuration file: ", config_file," to verify, and delete the non-existing files if needed."
"Please open the configuration file: ", config_file, " to verify, and delete the non-existing files if needed."
)
if (isTRUE(force)) {
cli_alert_warning(
Expand Down
87 changes: 47 additions & 40 deletions dev/flat_create_flat.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ test_that("add dev_history template works with windows \\users path", {
expect_true(file.exists(dev_file_path))
# Test specific \\users path
newdir_uu <- tempfile("aa\\U/gzv")
newdir_uu <- tempfile("aa\\Users/gzv")
dir.create(newdir_uu, recursive = TRUE)
usethis::with_project(dummypackage, {
Expand Down Expand Up @@ -450,8 +450,10 @@ test_that("all templates to knit and inflate a second time", {
for (template in all_templates) {
# template <- all_templates[1]
main_flat_file_name <- template
if (template %in% c("minimal_package", "minpkg",
"minimal_flat", "minflat")) {
if (template %in% c(
"minimal_package", "minpkg",
"minimal_flat", "minflat"
)) {
main_flat_file_name <- "minimal"
} else if (template == "add") {
main_flat_file_name <- "additional"
Expand All @@ -467,40 +469,36 @@ for (template in all_templates) {
withr::with_dir(dummypackage4, {
# Add template
dev_file_path <- suppressMessages(add_flat_template(template = template, open = FALSE))
flat_file <- dev_file_path[grepl("flat", dev_file_path)]
# Change lines asking for pkg name
lines_template <- readLines(flat_file)
lines_template[grepl("<my_package_name>", lines_template)] <-
gsub(
"<my_package_name>", basename(dummypackage4),
lines_template[grepl("<my_package_name>", lines_template)]
)
# Run description chunk to build DESCRIPTION file and make it a proper pkg
desc_line <- grep("\\{r description", lines_template)
if (length(desc_line) != 0) {
lines_template[desc_line] <- "```{r description, eval=TRUE}"
}
# pkgload::load_all in the template cannot work in non interactive R CMD Check
if (template == "full" & !interactive()) {
loadall_line <- grep("^pkgload::load_all", lines_template)
lines_template[loadall_line] <- "# pkgload::load_all() commented"
data_line <- grep("datafile <- system.file", lines_template)
lines_template[data_line] <- glue::glue('datafile <- file.path(normalize_path_winslash("{dummypackage4}"), "inst", "nyc_squirrels_sample.csv")')
}
dev_file_path <- suppressMessages(add_flat_template(template = template, open = FALSE))
flat_file <- dev_file_path[grepl("flat", dev_file_path)]
lines_template <- readLines(flat_file)
# Run description chunk to build DESCRIPTION file and make it a proper pkg
desc_line <- grep("\\{r description", lines_template)
if (length(desc_line) != 0) {
lines_template[desc_line] <- "```{r description, eval=TRUE}"
}
# pkgload::load_all in the template cannot work in non interactive R CMD Check
if (template == "full" & !interactive()) {
# if (template == "full" & interactive()) {
loadall_line <- grep("^pkgload::load_all", lines_template)
lines_template[loadall_line] <- "# pkgload::load_all() commented"
data_line <- grep("datafile <- system.file", lines_template)
lines_template[data_line] <-
glue::glue('datafile <- file.path("{normalize_path_winslash(dummypackage4)}", "inst", "nyc_squirrels_sample.csv")')
}
cat(enc2utf8(lines_template), file = flat_file, sep = "\n")
cat(enc2utf8(lines_template), file = flat_file, sep = "\n")
# description chunk as eval=TRUE
if (any(grepl("dev_history", dev_file_path))) {
dev_hist_path <- dev_file_path[grepl("dev_history", dev_file_path)]
lines_dev <- readLines(dev_hist_path)
lines_dev[grepl("\\{r description", lines_dev)] <- "```{r description, eval=TRUE}"
cat(enc2utf8(lines_dev), file = dev_hist_path, sep = "\n")
}
# description chunk as eval=TRUE
if (any(grepl("dev_history", dev_file_path))) {
dev_hist_path <- dev_file_path[grepl("dev_history", dev_file_path)]
lines_dev <- readLines(dev_hist_path)
lines_dev[grepl("\\{r description", lines_dev)] <- "```{r description, eval=TRUE}"
cat(enc2utf8(lines_dev), file = dev_hist_path, sep = "\n")
}
# Simulate as being inside project
# Simulate as being inside project
usethis::proj_set(dummypackage4)
here:::do_refresh_here(dummypackage4)
Expand All @@ -514,12 +512,18 @@ for (template in all_templates) {
input = dev_hist_path,
output_file = file.path(dummypackage4, "dev", "dev_history.html"),
envir = new.env(), quiet = TRUE
), regexp = NA)
),
regexp = NA
)
})
} else if (template %in% c("additional", "add",
"minimal_flat", "minflat")) {
fusen::fill_description(pkg = here::here(),
fields = list(Title = "Dummy Package"))
} else if (template %in% c(
"additional", "add",
"minimal_flat", "minflat"
)) {
fusen::fill_description(
pkg = here::here(),
fields = list(Title = "Dummy Package")
)
# Define License with use_*_license()
usethis::use_mit_license("John Doe")
}
Expand All @@ -533,7 +537,9 @@ for (template in all_templates) {
input = flat_to_render,
output_file = file.path(dummypackage4, "dev", paste0("flat_", main_flat_file_name, ".html")),
envir = new.env(), quiet = TRUE
), regexp = NA)
),
regexp = NA
)
})
}
Expand Down Expand Up @@ -741,6 +747,7 @@ test_that("add_flat_template allows bad flat_name for function name with add", {
expect_equal(length(grep("bad_for_function_but_ok2", dev_lines)), 8)
})
unlink(dummypackage, recursive = TRUE)
```

## add_additional & co.
Expand Down
13 changes: 5 additions & 8 deletions tests/testthat/test-add_flat_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test_that("add dev_history template works with windows \\users path", {

expect_true(file.exists(dev_file_path))
# Test specific \\users path
newdir_uu <- tempfile("aa\\U/gzv")
newdir_uu <- tempfile("aa\\Users/gzv")
dir.create(newdir_uu, recursive = TRUE)

usethis::with_project(dummypackage, {
Expand Down Expand Up @@ -192,24 +192,20 @@ for (template in all_templates) {
dev_file_path <- suppressMessages(add_flat_template(template = template, open = FALSE))
flat_file <- dev_file_path[grepl("flat", dev_file_path)]

# Change lines asking for pkg name
lines_template <- readLines(flat_file)
lines_template[grepl("<my_package_name>", lines_template)] <-
gsub(
"<my_package_name>", basename(dummypackage4),
lines_template[grepl("<my_package_name>", lines_template)]
)
# Run description chunk to build DESCRIPTION file and make it a proper pkg
desc_line <- grep("\\{r description", lines_template)
if (length(desc_line) != 0) {
lines_template[desc_line] <- "```{r description, eval=TRUE}"
}
# pkgload::load_all in the template cannot work in non interactive R CMD Check
if (template == "full" & !interactive()) {
# if (template == "full" & interactive()) {
loadall_line <- grep("^pkgload::load_all", lines_template)
lines_template[loadall_line] <- "# pkgload::load_all() commented"
data_line <- grep("datafile <- system.file", lines_template)
lines_template[data_line] <- glue::glue('datafile <- file.path(normalize_path_winslash("{dummypackage4}"), "inst", "nyc_squirrels_sample.csv")')
lines_template[data_line] <-
glue::glue('datafile <- file.path("{normalize_path_winslash(dummypackage4)}", "inst", "nyc_squirrels_sample.csv")')
}

cat(enc2utf8(lines_template), file = flat_file, sep = "\n")
Expand Down Expand Up @@ -472,6 +468,7 @@ test_that("add_flat_template allows bad flat_name for function name with add", {
})
unlink(dummypackage, recursive = TRUE)


# add_full ----
dummypackage <- tempfile(pattern = "add.wrappers")
dir.create(dummypackage)
Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-create_fusen_rsproject.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ unlink(dummypackage, recursive = TRUE)
## Create a new project

for (template.to.try in fusen:::create_fusen_choices) {

# template.to.try <- "full"
dummypackage <- tempfile(pattern = paste0("create.fusen.", template.to.try))
dir.create(dummypackage)
Expand All @@ -75,7 +74,6 @@ for (template.to.try in fusen:::create_fusen_choices) {

withr::with_dir(dummypackage, {
test_that(paste("Create fusen works with template:", template.to.try), {

if (template.to.try %in% "dev_history") {
expected_rmd_template_with_fusen_name <- NULL
} else {
Expand All @@ -86,19 +84,22 @@ for (template.to.try in fusen:::create_fusen_choices) {

expect_message(
expected_rmd_template_with_fusen_name <- readLines(
system.file(paste0("flat-template-", template.to.try.rmd, ".Rmd"), package = "fusen")) %>%
system.file(paste0("flat-template-", template.to.try.rmd, ".Rmd"), package = "fusen")
) %>%
gsub("<my_package_name>", pkgname, .) %>%
gsub("flat_template[.]Rmd", paste0("flat_",flat_name,".Rmd"), .) %>%
gsub("flat_template[.]Rmd", paste0("flat_", flat_name, ".Rmd"), .) %>%
gsub("my_fun", flat_name, .),
regexp = NA)
regexp = NA
)
}

path_foosen <- file.path(dummypackage, pkgname)

expect_error(
path_dev_history <- suppressMessages(
create_fusen(path_foosen, template = template.to.try, flat_name = flat_name, open = FALSE)
), regexp = NA
),
regexp = NA
)

expect_true(dir.exists(path_foosen))
Expand Down Expand Up @@ -158,7 +159,6 @@ for (template.to.try in c("full", "minimal", "teaching", "dev_history")) {
dummygui <- create_dummygui()
withr::with_dir(dummygui$dirname, {
test_that(paste("Can create in a project with gui for:", template.to.try), {

dev_path <- expect_error(
suppressMessages(
create_fusen_gui(dummygui$basename, template = template.to.try, with_git = FALSE)
Expand Down
21 changes: 14 additions & 7 deletions tests/testthat/test-user-story.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ for (template in all_templates_second) {

# Follow dev_history
suppressMessages(
fill_description(pkg = here::here(),
fields = list(Title = "Dummy Package"))
fill_description(
pkg = here::here(),
fields = list(Title = "Dummy Package")
)
)
# Define License with use_*_license()
suppressMessages(usethis::use_mit_license("John Doe"))

# Inflate first flat file
suppressMessages(inflate(flat_file = "dev/flat_first.Rmd", vignette_name = "My First",
open_vignette = FALSE, check = FALSE))
suppressMessages(inflate(
flat_file = "dev/flat_first.Rmd", vignette_name = "My First",
open_vignette = FALSE, check = FALSE
))

test_that(paste0("full process -", template, "- first minimal basis ok"), {
expect_true(file.exists("DESCRIPTION"))
Expand All @@ -47,12 +51,15 @@ for (template in all_templates_second) {
test_that(paste0("full process -", template, "- add and inflate new template"), {
expect_error(
add_flat_template(template = template, flat_name = "second", open = FALSE),
regexp = NA)
regexp = NA
)
expect_true(file.exists("dev/flat_second.Rmd"))

# Inflate second flat file
suppressMessages(inflate(flat_file = "dev/flat_second.Rmd", vignette_name = "My Second",
open_vignette = FALSE, check = FALSE))
suppressMessages(inflate(
flat_file = "dev/flat_second.Rmd", vignette_name = "My Second",
open_vignette = FALSE, check = FALSE
))
expect_true(file.exists("vignettes/my-second.Rmd"))


Expand Down

0 comments on commit 1d3b460

Please sign in to comment.