diff --git a/.Rbuildignore b/.Rbuildignore index 544114a..8162756 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -9,3 +9,4 @@ ^README\.Rmd$ ^\.travis\.yml$ ^codecov\.yml$ +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..3ac34c8 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,126 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, caste, color, religion, or sexual +identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall + community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of + any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email address, + without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at codeofconduct@posit.co. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of +actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or permanent +ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the +community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.1, available at +. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][https://github.com/mozilla/inclusion]. + +For answers to common questions about this code of conduct, see the FAQ at +. Translations are available at . + +[homepage]: https://www.contributor-covenant.org diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..ee65ccb --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,62 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +# +# NOTE: This workflow is overkill for most R packages and +# check-standard.yaml is likely a better choice. +# usethis::use_github_action("check-standard") will install it. +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +name: R-CMD-check + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + + - {os: windows-latest, r: 'release'} + # Use 3.6 to trigger usage of RTools35 + - {os: windows-latest, r: '3.6'} + # use 4.1 to check with rtools40's older compiler + - {os: windows-latest, r: '4.1'} + + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + - {os: ubuntu-latest, r: 'oldrel-2'} + - {os: ubuntu-latest, r: 'oldrel-3'} + - {os: ubuntu-latest, r: 'oldrel-4'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml new file mode 100644 index 0000000..ed7650c --- /dev/null +++ b/.github/workflows/pkgdown.yaml @@ -0,0 +1,48 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# 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: + +name: pkgdown + +jobs: + pkgdown: + runs-on: ubuntu-latest + # Only restrict concurrency for non-PR jobs + concurrency: + group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::pkgdown, local::. + needs: website + + - name: Build site + run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) + shell: Rscript {0} + + - name: Deploy to GitHub pages 🚀 + if: github.event_name != 'pull_request' + uses: JamesIves/github-pages-deploy-action@v4.4.1 + with: + clean: false + branch: gh-pages + folder: docs diff --git a/.github/workflows/pr-commands.yaml b/.github/workflows/pr-commands.yaml new file mode 100644 index 0000000..71f335b --- /dev/null +++ b/.github/workflows/pr-commands.yaml @@ -0,0 +1,79 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + issue_comment: + types: [created] + +name: Commands + +jobs: + document: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/document') }} + name: document + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::roxygen2 + needs: pr-document + + - name: Document + run: roxygen2::roxygenise() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add man/\* NAMESPACE + git commit -m 'Document' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + style: + if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} + name: style + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/pr-fetch@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + + - uses: r-lib/actions/setup-r@v2 + + - name: Install dependencies + run: install.packages("styler") + shell: Rscript {0} + + - name: Style + run: styler::style_pkg() + shell: Rscript {0} + + - name: commit + run: | + git config --local user.name "$GITHUB_ACTOR" + git config --local user.email "$GITHUB_ACTOR@users.noreply.github.com" + git add \*.R + git commit -m 'Style' + + - uses: r-lib/actions/pr-push@v2 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml new file mode 100644 index 0000000..27d4528 --- /dev/null +++ b/.github/workflows/test-coverage.yaml @@ -0,0 +1,50 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# 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] + +name: test-coverage + +jobs: + test-coverage: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + + steps: + - uses: actions/checkout@v3 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr + needs: coverage + + - name: Test coverage + run: | + covr::codecov( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + shell: Rscript {0} + + - name: Show testthat output + if: always() + run: | + ## -------------------------------------------------------------------- + find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash + + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.gitignore b/.gitignore index d89139a..4f24c69 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ docs/ .Rproj.user .Rhistory .RData +docs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9779fae..0000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -# R for travis: see documentation at https://docs.travis-ci.com/user/languages/r - -language: R -sudo: false -cache: packages - -# Don't check on older versions: would be a lot of work to figure out -# precise changes, and it doesn't seem like it would pay off since this -# sloop is for interactive exploration. -matrix: - include: - - r: devel - - r: release - after_success: - - Rscript -e 'covr::codecov()' - before_cache: - - Rscript -e 'remotes::install_github("r-lib/pkgdown")' - - Rscript -e 'remotes::install_github("tidyverse/tidytemplate")' - deploy: - provider: script - script: Rscript -e 'pkgdown::deploy_site_github(verbose = TRUE)' - skip_cleanup: true - - r: oldrel - -after_success: - - Rscript -e 'covr::codecov()' diff --git a/DESCRIPTION b/DESCRIPTION index 8a2ac53..4f17c40 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -2,17 +2,17 @@ Package: sloop Title: Helpers for 'OOP' in R Version: 1.0.1.9000 Authors@R: c( - person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre")), - person("RStudio", role = "cph") + person("Hadley", "Wickham", , "hadley@posit.co", role = c("aut", "cre")), + person(given = "Posit Software, PBC", role = c("cph", "fnd")) ) -Description: A collection of helper functions designed to help - you to better understand object oriented programming in R, - particularly using 'S3'. +Description: A collection of helper functions designed to help you to + better understand object oriented programming in R, particularly using + 'S3'. License: GPL-3 URL: https://github.com/r-lib/sloop, https://sloop.r-lib.org BugReports: https://github.com/r-lib/sloop/issues Depends: - R (>= 3.3) + R (>= 3.6) Imports: codetools, crayon, @@ -22,8 +22,10 @@ Imports: tibble (>= 2.0.1) Suggests: covr, - testthat + testthat (>= 3.0.0) +Config/Needs/website: tidyverse/tidytemplate +Config/testthat/edition: 3 Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 6.1.1 +RoxygenNote: 7.2.3 diff --git a/R/sloop-package.R b/R/sloop-package.R new file mode 100644 index 0000000..a65cf64 --- /dev/null +++ b/R/sloop-package.R @@ -0,0 +1,6 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +## usethis namespace: end +NULL diff --git a/README.Rmd b/README.Rmd index 1467f63..1c1b030 100644 --- a/README.Rmd +++ b/README.Rmd @@ -12,11 +12,13 @@ knitr::opts_chunk$set( ) ``` -# sloop +# sloop sloop website + [![CRAN status](https://www.r-pkg.org/badges/version/sloop)](https://cran.r-project.org/package=sloop) -[![Travis build status](https://travis-ci.org/r-lib/sloop.svg?branch=master)](https://travis-ci.org/r-lib/sloop) -[![Codecov test coverage](https://codecov.io/gh/r-lib/sloop/branch/master/graph/badge.svg)](https://codecov.io/github/r-lib/sloop?branch=master) +[![R-CMD-check](https://github.com/r-lib/sloop/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/sloop/actions/workflows/R-CMD-check.yaml) +[![Codecov test coverage](https://codecov.io/gh/r-lib/sloop/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/sloop?branch=main) + The goal of sloop is to provide tools to help you interactively explore and understand object oriented programming in R, particularly with S3. @@ -27,8 +29,8 @@ Please note that unlike other [r-lib](https://github.com/r-lib) packages, sloop You can install sloop from github with: ```{r gh-installation, eval = FALSE} -# install.packages("devtools") -devtools::install_github("r-lib/sloop") +# install.packages("pak") +pak::pak("r-lib/sloop") ``` ## Usage diff --git a/README.md b/README.md index 5df2ac9..3cbb5fb 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ -# sloop +# sloop sloop website + + [![CRAN status](https://www.r-pkg.org/badges/version/sloop)](https://cran.r-project.org/package=sloop) -[![Travis build -status](https://travis-ci.org/r-lib/sloop.svg?branch=master)](https://travis-ci.org/r-lib/sloop) +[![R-CMD-check](https://github.com/r-lib/sloop/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/sloop/actions/workflows/R-CMD-check.yaml) [![Codecov test -coverage](https://codecov.io/gh/r-lib/sloop/branch/master/graph/badge.svg)](https://codecov.io/github/r-lib/sloop?branch=master) +coverage](https://codecov.io/gh/r-lib/sloop/branch/main/graph/badge.svg)](https://app.codecov.io/gh/r-lib/sloop?branch=main) + The goal of sloop is to provide tools to help you interactively explore and understand object oriented programming in R, particularly with S3. @@ -21,8 +23,8 @@ packages, sloop only works with R 3.3 and later. You can install sloop from github with: ``` r -# install.packages("devtools") -devtools::install_github("r-lib/sloop") +# install.packages("pak") +pak::pak("r-lib/sloop") ``` ## Usage @@ -107,7 +109,7 @@ And for retrieving the methods associated with a generic or class: ``` r s3_methods_class("factor") -#> # A tibble: 27 x 4 +#> # A tibble: 28 × 4 #> generic class visible source #> #> 1 [ factor TRUE base @@ -120,10 +122,10 @@ s3_methods_class("factor") #> 8 as.Date factor TRUE base #> 9 as.list factor TRUE base #> 10 as.logical factor TRUE base -#> # … with 17 more rows +#> # ℹ 18 more rows s3_methods_generic("summary") -#> # A tibble: 36 x 4 +#> # A tibble: 39 × 4 #> generic class visible source #> #> 1 summary aov TRUE stats @@ -136,5 +138,5 @@ s3_methods_generic("summary") #> 8 summary default TRUE base #> 9 summary ecdf FALSE registered S3method #> 10 summary factor TRUE base -#> # … with 26 more rows +#> # ℹ 29 more rows ``` diff --git a/_pkgdown.yml b/_pkgdown.yml index 5a5d829..915f5f2 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,2 +1,12 @@ -destination: docs url: https://sloop.r-lib.org + +template: + package: tidytemplate + bootstrap: 5 + + includes: + in_header: | + + +development: + mode: auto diff --git a/codecov.yml b/codecov.yml index 8f36b6c..04c5585 100644 --- a/codecov.yml +++ b/codecov.yml @@ -6,7 +6,9 @@ coverage: default: target: auto threshold: 1% + informational: true patch: default: target: auto threshold: 1% + informational: true diff --git a/cran-comments.md b/cran-comments.md index 447b848..c1c7ce6 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,8 +1,3 @@ -## Test environments -* local OS X install, R 3.5.1 -* ubuntu 14.04 (on travis-ci), R 3.5.1 -* win-builder (devel and release) - ## R CMD check results 0 errors | 0 warnings | 1 note diff --git a/man/figures/logo.png b/man/figures/logo.png new file mode 100644 index 0000000..6e2f567 Binary files /dev/null and b/man/figures/logo.png differ diff --git a/man/s3_dispatch.Rd b/man/s3_dispatch.Rd index ba89a70..23e9000 100644 --- a/man/s3_dispatch.Rd +++ b/man/s3_dispatch.Rd @@ -15,8 +15,8 @@ s3_dispatch(call, env = parent.frame()) \code{s3_dispatch()} prints a list of all possible function names that will be considered for method dispatch. There are four possible states: \itemize{ -\item \code{=>} method exists and is found by \code{UseMethod()}. -\item \code{->} method exists and is used by \code{NextMethod()}. +\item \verb{=>} method exists and is found by \code{UseMethod()}. +\item \verb{->} method exists and is used by \code{NextMethod()}. \item \code{*} method exists but is not used. \item Nothing (and greyed out in console): method does not exist. } diff --git a/man/sloop-package.Rd b/man/sloop-package.Rd new file mode 100644 index 0000000..b4ebe32 --- /dev/null +++ b/man/sloop-package.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sloop-package.R +\docType{package} +\name{sloop-package} +\alias{sloop} +\alias{sloop-package} +\title{sloop: Helpers for 'OOP' in R} +\description{ +A collection of helper functions designed to help you to better understand object oriented programming in R, particularly using 'S3'. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/r-lib/sloop} + \item \url{https://sloop.r-lib.org} + \item Report bugs at \url{https://github.com/r-lib/sloop/issues} +} + +} +\author{ +\strong{Maintainer}: Hadley Wickham \email{hadley@posit.co} + +Other contributors: +\itemize{ + \item Posit Software, PBC [copyright holder, funder] +} + +} +\keyword{internal} diff --git a/pkgdown/favicon/apple-touch-icon-120x120.png b/pkgdown/favicon/apple-touch-icon-120x120.png new file mode 100644 index 0000000..9d30f49 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-120x120.png differ diff --git a/pkgdown/favicon/apple-touch-icon-152x152.png b/pkgdown/favicon/apple-touch-icon-152x152.png new file mode 100644 index 0000000..de46eb3 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-152x152.png differ diff --git a/pkgdown/favicon/apple-touch-icon-180x180.png b/pkgdown/favicon/apple-touch-icon-180x180.png new file mode 100644 index 0000000..d675001 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-180x180.png differ diff --git a/pkgdown/favicon/apple-touch-icon-60x60.png b/pkgdown/favicon/apple-touch-icon-60x60.png new file mode 100644 index 0000000..53fde26 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-60x60.png differ diff --git a/pkgdown/favicon/apple-touch-icon-76x76.png b/pkgdown/favicon/apple-touch-icon-76x76.png new file mode 100644 index 0000000..6462ac8 Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon-76x76.png differ diff --git a/pkgdown/favicon/apple-touch-icon.png b/pkgdown/favicon/apple-touch-icon.png new file mode 100644 index 0000000..9a4dacf Binary files /dev/null and b/pkgdown/favicon/apple-touch-icon.png differ diff --git a/pkgdown/favicon/favicon-16x16.png b/pkgdown/favicon/favicon-16x16.png new file mode 100644 index 0000000..b984b1d Binary files /dev/null and b/pkgdown/favicon/favicon-16x16.png differ diff --git a/pkgdown/favicon/favicon-32x32.png b/pkgdown/favicon/favicon-32x32.png new file mode 100644 index 0000000..03327c6 Binary files /dev/null and b/pkgdown/favicon/favicon-32x32.png differ diff --git a/pkgdown/favicon/favicon.ico b/pkgdown/favicon/favicon.ico new file mode 100644 index 0000000..7e4b39e Binary files /dev/null and b/pkgdown/favicon/favicon.ico differ diff --git a/tests/testthat.R b/tests/testthat.R index aad1e09..373c98a 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# 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(sloop) diff --git a/tests/testthat/_snaps/dispatch.md b/tests/testthat/_snaps/dispatch.md new file mode 100644 index 0000000..4b213ae --- /dev/null +++ b/tests/testthat/_snaps/dispatch.md @@ -0,0 +1,19 @@ +# has nice output + + Code + s3_dispatch(Sys.Date() + 1) + Output + => +.Date + +.default + * Ops.Date + Ops.default + * + (internal) + Code + s3_dispatch(Sys.Date() * 1) + Output + *.Date + *.default + => Ops.Date + Ops.default + -> * (internal) + diff --git a/tests/testthat/test-dispatch-print-nextmethod.txt b/tests/testthat/test-dispatch-print-nextmethod.txt deleted file mode 100644 index ac25904..0000000 --- a/tests/testthat/test-dispatch-print-nextmethod.txt +++ /dev/null @@ -1,5 +0,0 @@ - *.Date - *.default -=> Ops.Date - Ops.default --> * (internal) diff --git a/tests/testthat/test-dispatch-print.txt b/tests/testthat/test-dispatch-print.txt deleted file mode 100644 index d3bbd39..0000000 --- a/tests/testthat/test-dispatch-print.txt +++ /dev/null @@ -1,5 +0,0 @@ -=> +.Date - +.default - * Ops.Date - Ops.default - * + (internal) diff --git a/tests/testthat/test-dispatch.R b/tests/testthat/test-dispatch.R index 01808bc..2539c98 100644 --- a/tests/testthat/test-dispatch.R +++ b/tests/testthat/test-dispatch.R @@ -1,5 +1,3 @@ -context("dispatch") - test_that("finds methods in other namespaces", { mod1 <- glm(mpg ~ wt, data = mtcars) @@ -25,13 +23,8 @@ test_that("includes group generics", { }) test_that("has nice output", { - expect_known_output( - print(s3_dispatch(Sys.Date() + 1)), - test_path("test-dispatch-print.txt") - ) - - expect_known_output( - print(s3_dispatch(Sys.Date() * 1)), - test_path("test-dispatch-print-nextmethod.txt") - ) + expect_snapshot({ + s3_dispatch(Sys.Date() + 1) + s3_dispatch(Sys.Date() * 1) + }) }) diff --git a/tests/testthat/test-ftype.R b/tests/testthat/test-ftype.R index e0ab368..541e7c6 100644 --- a/tests/testthat/test-ftype.R +++ b/tests/testthat/test-ftype.R @@ -1,5 +1,3 @@ -context("ftype") - test_that("functions return as expected", { f <- function(x) x expect_equal(ftype(f), "function") diff --git a/tests/testthat/test-is_s3.R b/tests/testthat/test-is_s3.R index 26efa43..2c7541c 100644 --- a/tests/testthat/test-is_s3.R +++ b/tests/testthat/test-is_s3.R @@ -1,5 +1,3 @@ -context("test-is_s3") - test_that("works with internal and regular generics", { expect_true(is_s3_generic("sum")) expect_true(is_s3_generic("[[")) diff --git a/tests/testthat/test-methods.R b/tests/testthat/test-methods.R index a0c507d..459430f 100644 --- a/tests/testthat/test-methods.R +++ b/tests/testthat/test-methods.R @@ -1,5 +1,3 @@ -context("test-methods") - test_that("multiplication works", { registerS3method("sloop_foo", "blah", function(x) {}, envir = asNamespace("sloop")) diff --git a/tests/testthat/test-otype.R b/tests/testthat/test-otype.R index 5f64974..5a00c0b 100644 --- a/tests/testthat/test-otype.R +++ b/tests/testthat/test-otype.R @@ -1,5 +1,3 @@ -context("test-otype") - test_that("otype yields correct value for sample inputs", { expect_equal(otype(1:10), "base") expect_equal(otype(mtcars), "S3") diff --git a/tests/testthat/test-s3_class.R b/tests/testthat/test-s3_class.R index 0dd8419..541a491 100644 --- a/tests/testthat/test-s3_class.R +++ b/tests/testthat/test-s3_class.R @@ -1,5 +1,3 @@ -context("s3_class") - test_that("integer and double have final component", { expect_equal(s3_class(1:10), c("integer", "numeric")) expect_equal(s3_class(matrix(1.5, 1, 1)), c("matrix", "double", "numeric"))