From 6ec3f4a6f616f1908d126fcfc7f237118c588fa9 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 11:14:07 +0900 Subject: [PATCH 1/7] Use nicer build matrix --- .travis.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 96735f5..5118488 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,20 @@ language: R sudo: false cache: packages -r: - - release - - devel + +matrix: + include: + - r: release + - r: devel + - r: oldrel + # test with the dev version of ggplot2 + - r: release + env: USE_VDIFFR=true + r_github_packages: + - tidyverse/ggplot2 + - lionel-/vdiffr + +env: + global: + # switch off vdiffr by default + - USE_VDIFFR=false From 2ebc40a495fbf37c830bbe0b636c363cd17a9efa Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 11:16:29 +0900 Subject: [PATCH 2/7] Suggest vdiffr --- DESCRIPTION | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index bfb2f4f..71237c5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,5 +26,6 @@ RoxygenNote: 6.0.1.9000 Suggests: testthat, knitr, - rmarkdown + rmarkdown, + vdiffr VignetteBuilder: knitr From 1d33fc9127942fbd9e96ce5396fa518d2d456cad Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 11:27:46 +0900 Subject: [PATCH 3/7] Add a helper --- tests/testthat/helper-vdiffr.R | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/testthat/helper-vdiffr.R diff --git a/tests/testthat/helper-vdiffr.R b/tests/testthat/helper-vdiffr.R new file mode 100644 index 0000000..5287f30 --- /dev/null +++ b/tests/testthat/helper-vdiffr.R @@ -0,0 +1,16 @@ +expect_doppelganger_if_not_cran <- function(title, fig, path = NULL, ..., verbose = NULL, + writer = vdiffr::write_svg) { + # skip on cran or vdiffr is old + if (!identical(Sys.getenv("NOT_CRAN"), "true") && + utils::packageVersion("vdiffr") < "0.2.3.9001") { + return(invisible(NULL)) + } + + vdiffr::expect_doppelganger(title = title, + fig = fig, + path = path, + ..., + verbose = verbose, + writer = writer) +} + From 437c41449df1f8eccc2c97270dc6bb0bf764bb16 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 12:02:37 +0900 Subject: [PATCH 4/7] Add a simple case --- tests/figs/deps.txt | 3 + .../simple-bar-chart-with-facet.svg | 254 ++++++++++++++++++ tests/figs/visual-tests/simple-bar-chart.svg | 77 ++++++ tests/testthat/test-vdiffr.R | 18 ++ 4 files changed, 352 insertions(+) create mode 100644 tests/figs/deps.txt create mode 100644 tests/figs/visual-tests/simple-bar-chart-with-facet.svg create mode 100644 tests/figs/visual-tests/simple-bar-chart.svg create mode 100644 tests/testthat/test-vdiffr.R diff --git a/tests/figs/deps.txt b/tests/figs/deps.txt new file mode 100644 index 0000000..bb57216 --- /dev/null +++ b/tests/figs/deps.txt @@ -0,0 +1,3 @@ +- vdiffr-svg-engine: 0.9000 +- vdiffr: 0.2.3.9001 +- freetypeharfbuzz: 0.2.5 \ No newline at end of file diff --git a/tests/figs/visual-tests/simple-bar-chart-with-facet.svg b/tests/figs/visual-tests/simple-bar-chart-with-facet.svg new file mode 100644 index 0000000..f283b4f --- /dev/null +++ b/tests/figs/visual-tests/simple-bar-chart-with-facet.svg @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +6 + + + + + + + + + + + +8 + + + + + + + + + + + +4 + + + + + + + + + + + +5 + + + + + + + + + + + + +2seater +compact +midsize +minivan +pickup +subcompact +suv + + + + + + + +2seater +compact +midsize +minivan +pickup +subcompact +suv +0 +20 +40 +60 + + + + +0 +20 +40 +60 + + + + +class +count +simple bar chart with facet + diff --git a/tests/figs/visual-tests/simple-bar-chart.svg b/tests/figs/visual-tests/simple-bar-chart.svg new file mode 100644 index 0000000..37ab299 --- /dev/null +++ b/tests/figs/visual-tests/simple-bar-chart.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +20 +40 +60 + + + + + + + + + + + +2seater +compact +midsize +minivan +pickup +subcompact +suv +class +count +simple bar chart + diff --git a/tests/testthat/test-vdiffr.R b/tests/testthat/test-vdiffr.R new file mode 100644 index 0000000..5b1e000 --- /dev/null +++ b/tests/testthat/test-vdiffr.R @@ -0,0 +1,18 @@ +context("visual tests") + +test_that("gghighlight() highlights correctly", { + expect_doppelganger_if_not_cran( + "simple bar chart", + ggplot(mpg, aes(class, fill = factor(cyl))) + + geom_bar() + + gghighlight(cyl >= 8, use_group_by = FALSE) + ) + + expect_doppelganger_if_not_cran( + "simple bar chart with facet", + ggplot(mpg, aes(class, fill = factor(cyl))) + + geom_bar() + + gghighlight() + + facet_wrap(vars(cyl)) + ) +}) From c5ccbc23e645450800e54423a5141357b4cd73f0 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 12:04:28 +0900 Subject: [PATCH 5/7] Simplify .travis.yml --- .travis.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5118488..5c70851 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,12 +11,6 @@ matrix: - r: oldrel # test with the dev version of ggplot2 - r: release - env: USE_VDIFFR=true r_github_packages: - tidyverse/ggplot2 - lionel-/vdiffr - -env: - global: - # switch off vdiffr by default - - USE_VDIFFR=false From 1589c207bc52c5997e98716e5ab6c256906d37be Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 12:39:41 +0900 Subject: [PATCH 6/7] Add simple line chart --- tests/figs/visual-tests/simple-line-chart.svg | 62 +++++++++++++++++++ tests/testthat/test-vdiffr.R | 10 +++ 2 files changed, 72 insertions(+) create mode 100644 tests/figs/visual-tests/simple-line-chart.svg diff --git a/tests/figs/visual-tests/simple-line-chart.svg b/tests/figs/visual-tests/simple-line-chart.svg new file mode 100644 index 0000000..390aec1 --- /dev/null +++ b/tests/figs/visual-tests/simple-line-chart.svg @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + +psavert + +uempmed + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + +1970 +1980 +1990 +2000 +2010 +date +value01 +simple line chart + diff --git a/tests/testthat/test-vdiffr.R b/tests/testthat/test-vdiffr.R index 5b1e000..e0877d5 100644 --- a/tests/testthat/test-vdiffr.R +++ b/tests/testthat/test-vdiffr.R @@ -15,4 +15,14 @@ test_that("gghighlight() highlights correctly", { gghighlight() + facet_wrap(vars(cyl)) ) + + # to avoid warnings about old format of grouped_df + economics_long <- dplyr::group_by(economics_long, add = TRUE) + + expect_doppelganger_if_not_cran( + "simple line chart", + ggplot(economics_long, aes(date, value01, colour = variable)) + + geom_line() + + gghighlight(mean(value) < 10, label_params = list(seed = 1)) + ) }) From c755f678f6cae9dc04576a0304bd7ab31d0646c1 Mon Sep 17 00:00:00 2001 From: Hiroaki Yutani Date: Fri, 28 Dec 2018 12:57:38 +0900 Subject: [PATCH 7/7] Add simple scatterplots --- .../figs/visual-tests/simple-point-chart.svg | 110 ++++++++++++++++++ tests/testthat/test-vdiffr.R | 7 ++ 2 files changed, 117 insertions(+) create mode 100644 tests/figs/visual-tests/simple-point-chart.svg diff --git a/tests/figs/visual-tests/simple-point-chart.svg b/tests/figs/visual-tests/simple-point-chart.svg new file mode 100644 index 0000000..d8a9104 --- /dev/null +++ b/tests/figs/visual-tests/simple-point-chart.svg @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +10 +15 +20 +25 +30 +35 + + + + + + + + + + +2 +3 +4 +5 +wt +mpg + +factor(cyl) + + + + + + +4 +6 +8 +simple point chart + diff --git a/tests/testthat/test-vdiffr.R b/tests/testthat/test-vdiffr.R index e0877d5..b40d08f 100644 --- a/tests/testthat/test-vdiffr.R +++ b/tests/testthat/test-vdiffr.R @@ -25,4 +25,11 @@ test_that("gghighlight() highlights correctly", { geom_line() + gghighlight(mean(value) < 10, label_params = list(seed = 1)) ) + + expect_doppelganger_if_not_cran( + "simple point chart", + ggplot(mtcars, aes(wt, mpg, colour = factor(cyl))) + + geom_point() + + gghighlight(100 < disp, disp <= 300, use_group_by = FALSE) + ) })