From 390f87b2879ee41fc7e632c5eff053a43ae10261 Mon Sep 17 00:00:00 2001 From: andres Date: Wed, 3 Jan 2024 19:58:01 -0500 Subject: [PATCH] Adds unit testing workflows --- .github/workflows/pkgdown.yaml | 7 +----- .github/workflows/tests.yaml | 36 +++++++++++++++++++++++++++++ DESCRIPTION | 4 +++- tests/testthat.R | 12 ++++++++++ tests/testthat/test-parse_cookies.R | 6 +++++ 5 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100644 tests/testthat.R create mode 100644 tests/testthat/test-parse_cookies.R diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index ed7650c..b7a5210 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -2,12 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master] - pull_request: - branches: [main, master] - release: - types: [published] - workflow_dispatch: + branches: [main] name: pkgdown diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..456af27 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,36 @@ +on: + pull_request: + branches: + - main + +name: Unit testing + +jobs: + r_cmd_check: + name: R CMD check + runs-on: ubuntu-latests + steps: + - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + - uses: r-lib/actions/check-r-package@v2 + with: + error-on: '"error"' + r_cmd_check_as_cran: + name: R CMD check as CRAN + runs-on: ubuntu-latests + steps: + - uses: actions/checkout@v3 + - uses: r-lib/actions/setup-r@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + - uses: r-lib/actions/check-r-package@v2 + with: + args: 'c("--no-manual", "--as-cran")' + error-on: '"error"' + check-dir: '"check"' diff --git a/DESCRIPTION b/DESCRIPTION index 1ca12e2..2c73594 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -31,5 +31,7 @@ Imports: Suggests: knitr, rmarkdown, - shiny + shiny, + testthat (>= 3.0.0) VignetteBuilder: knitr +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..9a18897 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(tapLock) + +test_check("tapLock") diff --git a/tests/testthat/test-parse_cookies.R b/tests/testthat/test-parse_cookies.R new file mode 100644 index 0000000..024e78d --- /dev/null +++ b/tests/testthat/test-parse_cookies.R @@ -0,0 +1,6 @@ +test_that("coorkie parsing works!", { + EXAMPLE_COOKIE <- "foo=bar; baz=quux" + EXPECTED_RESULT <- list(foo = "bar", baz = "quux") + result <- parse_cookies(EXAMPLE_COOKIE) + testthat::expect_equal(result, EXPECTED_RESULT) +})