-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make non-interactive tests fail on mismatch
- Loading branch information
Showing
3 changed files
with
87 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
options( | ||
coursekata.quiet = FALSE, | ||
coursekata.quickstart = TRUE | ||
) | ||
Sys.setenv(`_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_` = "false") | ||
options(coursekata.quiet = FALSE, coursekata.quickstart = TRUE, cli.width = 80) | ||
|
||
# ensure this package is uninstalled | ||
suppressMessages(try(remove.packages("fivethirtyeightdata"), silent = TRUE)) | ||
|
||
# function to compare output to a snapshot | ||
test_output_snapshot <- function(expr, snapshot) { | ||
output <- capture.output(expr, type = "message") | ||
output <- trimws(output, "right") | ||
output <- paste(output, collapse = "\n") | ||
comp <- waldo::compare(output, snapshot) | ||
if (length(comp) > 0) stop(paste0(comp, collapse = "\n\n"), call. = FALSE) | ||
} | ||
|
||
# loading should not trigger the install prompt or show any messages | ||
library(coursekata) | ||
test_output_snapshot(library(coursekata), "") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
options( | ||
coursekata.quiet = TRUE, | ||
coursekata.quickstart = FALSE | ||
) | ||
Sys.setenv(`_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_` = "false") | ||
options(coursekata.quiet = TRUE, coursekata.quickstart = FALSE, cli.width = 80) | ||
|
||
# ensure this package is uninstalled | ||
suppressMessages(try(remove.packages("fivethirtyeightdata"), silent = TRUE)) | ||
|
||
# loading should trigger the install prompt if interactive, and not if not | ||
# function to compare output to a snapshot | ||
test_output_snapshot <- function(expr, snapshot) { | ||
output <- capture.output(expr, type = "message") | ||
output <- trimws(output, "right") | ||
output <- paste(output, collapse = "\n") | ||
comp <- waldo::compare(output, snapshot) | ||
if (length(comp) > 0) stop(paste0(comp, collapse = "\n\n"), call. = FALSE) | ||
} | ||
|
||
# individual package start messages should not be printed (only the CourseKata message) | ||
library(coursekata) | ||
test_output_snapshot(library(coursekata), trimws(" | ||
── CourseKata packages ──────────────────────────────────── coursekata 0.14.1 ── | ||
✔ dslabs 0.7.6 ✔ Metrics 0.1.4 | ||
✔ Lock5withR 1.2.2 ✔ lsr 0.5.2 | ||
x fivethirtyeightdata ✔ mosaic 1.8.4.2 | ||
✔ fivethirtyeight 0.6.2 ✔ supernova 2.5.7 | ||
")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
#!/usr/bin/env Rscript | ||
|
||
options( | ||
coursekata.quiet = FALSE, | ||
coursekata.quickstart = FALSE | ||
) | ||
Sys.setenv(`_R_S3_METHOD_REGISTRATION_NOTE_OVERWRITES_` = "false") | ||
options(coursekata.quiet = FALSE, coursekata.quickstart = FALSE, cli.width = 80) | ||
|
||
# ensure this package is uninstalled | ||
suppressMessages(try(remove.packages("fivethirtyeightdata"), silent = TRUE)) | ||
|
||
# loading should trigger the install prompt if interactive, and not if not | ||
library(coursekata) | ||
# function to compare output to a snapshot | ||
test_output_snapshot <- function(expr, snapshot) { | ||
output <- capture.output(expr, type = "message") | ||
output <- trimws(output, "right") | ||
output <- paste(output, collapse = "\n") | ||
comp <- waldo::compare(output, snapshot) | ||
if (length(comp) > 0) stop(paste0(comp, collapse = "\n\n"), call. = FALSE) | ||
} | ||
|
||
test_output_snapshot(library(coursekata), trimws(" | ||
Loading required package: dslabs | ||
Loading required package: Lock5withR | ||
Loading required package: fivethirtyeight | ||
Some larger datasets need to be installed separately, like senators and | ||
house_district_forecast. To install these, we recommend you install the | ||
fivethirtyeightdata package by running: | ||
install.packages('fivethirtyeightdata', repos = | ||
'https://fivethirtyeightdata.github.io/drat/', type = 'source') | ||
Loading required package: Metrics | ||
Loading required package: lsr | ||
Loading required package: mosaic | ||
The 'mosaic' package masks several functions from core packages in order to add | ||
additional features. The original behavior of these functions should not be affected by this. | ||
Attaching package: ‘mosaic’ | ||
The following objects are masked from ‘package:dplyr’: | ||
count, do, tally | ||
The following object is masked from ‘package:Matrix’: | ||
mean | ||
The following object is masked from ‘package:ggplot2’: | ||
stat | ||
The following objects are masked from ‘package:stats’: | ||
binom.test, cor, cor.test, cov, fivenum, IQR, median, prop.test, | ||
quantile, sd, t.test, var | ||
The following objects are masked from ‘package:base’: | ||
max, mean, min, prod, range, sample, sum | ||
Loading required package: supernova | ||
── CourseKata packages ──────────────────────────────────── coursekata 0.14.1 ── | ||
✔ dslabs 0.7.6 ✔ Metrics 0.1.4 | ||
✔ Lock5withR 1.2.2 ✔ lsr 0.5.2 | ||
x fivethirtyeightdata ✔ mosaic 1.8.4.2 | ||
✔ fivethirtyeight 0.6.2 ✔ supernova 2.5.7 | ||
")) |