From cfa3b99dcb2282f21e6c85f166c00bc7ed05f835 Mon Sep 17 00:00:00 2001 From: Diego H Date: Mon, 12 Feb 2024 18:46:11 +0100 Subject: [PATCH] Try new test suite --- .github/workflows/test-ci.yaml | 9 ++--- tests/testthat/test_ci/.gitignore | 1 + tests/testthat/test_ci/test-new.R | 61 +++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 tests/testthat/test_ci/test-new.R diff --git a/.github/workflows/test-ci.yaml b/.github/workflows/test-ci.yaml index 7ec4d6a1..d6ef39ef 100644 --- a/.github/workflows/test-ci.yaml +++ b/.github/workflows/test-ci.yaml @@ -104,10 +104,7 @@ jobs: message("Installing ", length(toinstall)," packages: ", paste0(toinstall, collapse = ",")) - install.packages(toinstall, - dependencies = TRUE, - verbose = TRUE, quiet = TRUE - ) + #install.packages(toinstall, dependencies = TRUE, verbose = TRUE, quiet = TRUE) # Update binary # update.packages(type = "binary") @@ -122,7 +119,7 @@ jobs: devtools::load_all() # Run the tests - testthat::test_dir("tests/testthat/test_ci") + source("tests/testthat/test_ci/test-new.R") shell: Rscript {0} @@ -131,5 +128,5 @@ jobs: shell: bash run: | # OK :) - cat ./tests/testthat/test_ci/_snaps/full_cff.md >$GITHUB_STEP_SUMMARY + cat ./tests/testthat/test_ci/results.md >$GITHUB_STEP_SUMMARY diff --git a/tests/testthat/test_ci/.gitignore b/tests/testthat/test_ci/.gitignore index a7cc310b..97a04fb1 100644 --- a/tests/testthat/test_ci/.gitignore +++ b/tests/testthat/test_ci/.gitignore @@ -1,3 +1,4 @@ _snaps CITATION allpackages.csv +results.md diff --git a/tests/testthat/test_ci/test-new.R b/tests/testthat/test_ci/test-new.R new file mode 100644 index 00000000..87126b1d --- /dev/null +++ b/tests/testthat/test_ci/test-new.R @@ -0,0 +1,61 @@ + +library(cffr) + +installed <- as.data.frame(installed.packages()[, c("Package", "Version")]) +installed <- installed[order(installed$Package), ] +# installed <- installed[1:50, ] + +rownames(installed) <- seq_len(nrow(installed)) + +l <- nrow(installed) + +dir_path <- "./tests/testthat/test_ci/" +dbcsv <- file.path(dir_path, "allpackages.csv") + +# Initial set of packages +write.csv(installed, file = dbcsv, row.names = FALSE) + +res <- c() +withcit <- c() +note <- c() +for (i in seq_len(nrow(installed))) { + pkg <- installed[i, ]$Package + # Display some advances + message( + "Testing ", i, "/", nrow(installed), + " (", sprintf("%05.02f", i / nrow(installed) * 100), "%) [" + ,installed[i, ]$Package, "]") + cit_path <- file.path(find.package(installed[i, ]$Package), "CITATION") + + + if (file.exists(cit_path)) { + withcit <- c(withcit, TRUE) + } else { + withcit <- c(withcit, FALSE) + } + + # Add cffobj + cffobj <- try( + cff_create(pkg, gh_keywords = FALSE, dependencies = FALSE), silent = TRUE) + + if(inherits(cffobj, "cff")){ + s <- try(cff_validate(cffobj, verbose = FALSE), silent = TRUE) + if(!is.logical(s)) s <- FALSE + + res <- c(res, s) + note <- c(note, "ok, cff") + } else { + res <- c(res, FALSE) + note <- c(note, "Other errors") + } +} + +installed$with_citation <- withcit +installed$is_ok <- res +installed$note <- note + + +outmd <- file.path(dir_path, "results.md") +capture.output(knitr::kable(installed), file = outmd) + +