Skip to content

Commit bb94c7f

Browse files
committed
Signal failure when testting interactively
1 parent 1246a0c commit bb94c7f

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

R/utils.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,5 +172,5 @@ hash_encode_url <- function(url){
172172
}
173173

174174
is_ci <- function() {
175-
nzchar(Sys.getenv("CI"))
175+
nzchar(Sys.getenv("CI")) || nzchar(Sys.getenv("NOT_CRAN"))
176176
}

tests/mock.Rout.fail

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,43 @@ Failed doppelganger: myplot (../figs//myplot.svg)
4343
Mi41Mg==)' />
4444
<defs>
4545

46+
47+
Failed doppelganger: myplot (../figs//myplot.svg)
48+
49+
< before
50+
> after
51+
@@ 50,4 / 50,5 @@
52+
<rect x='641.72' y='401.98' width='20.80' height='118.58' style='stroke-wi
53+
dth: 1.07; stroke: none; stroke-linecap: butt; fill: #595959;' clip-path='
54+
url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wyMi41Mg==)' />
55+
<rect x='662.52' y='401.98' width='20.80' height='118.58' style='stroke-wi
56+
dth: 1.07; stroke: none; stroke-linecap: butt; fill: #595959;' clip-path='
57+
url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wyMi41Mg==)' />
58+
> <line x1='417.09' y1='544.27' x2='417.09' y2='22.52' style='stroke-width:
59+
: 1.07; stroke-linecap: butt;' clip-path='url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3w
60+
: yMi41Mg==)' />
61+
<rect x='28.09' y='22.52' width='686.43' height='521.75' style='stroke-wid
62+
th: 1.07; stroke: #333333;' clip-path='url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wy
63+
Mi41Mg==)' />
64+
<defs>
65+
66+
67+
Failed doppelganger: myplot (../figs//myplot.svg)
68+
69+
< before
70+
> after
71+
@@ 50,4 / 50,5 @@
72+
<rect x='641.72' y='401.98' width='20.80' height='118.58' style='stroke-wi
73+
dth: 1.07; stroke: none; stroke-linecap: butt; fill: #595959;' clip-path='
74+
url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wyMi41Mg==)' />
75+
<rect x='662.52' y='401.98' width='20.80' height='118.58' style='stroke-wi
76+
dth: 1.07; stroke: none; stroke-linecap: butt; fill: #595959;' clip-path='
77+
url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wyMi41Mg==)' />
78+
> <line x1='417.09' y1='544.27' x2='417.09' y2='22.52' style='stroke-width:
79+
: 1.07; stroke-linecap: butt;' clip-path='url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3w
80+
: yMi41Mg==)' />
81+
<rect x='28.09' y='22.52' width='686.43' height='521.75' style='stroke-wid
82+
th: 1.07; stroke: #333333;' clip-path='url(#cpMjguMDl8NzE0LjUyfDU0NC4yN3wy
83+
Mi41Mg==)' />
84+
<defs>
85+

tests/testthat/mock-pkg/tests/testthat/test-failed.R

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ skip_if_maintenance <- function() {
1212
}
1313
}
1414

15-
test_that("New plots work are collected", {
15+
test_that("mismatches are hard failures when NOT_CRAN is set", {
1616
skip_if_maintenance()
1717
expect_doppelganger("myplot", p1_fail, "")
1818
})
@@ -22,9 +22,15 @@ test_that("Duplicated expectations issue a warning", {
2222
expect_doppelganger("myplot", p1_fail, "")
2323
})
2424

25-
test_that("figure mismatches are hard failures on CI", {
25+
test_that("mismatches are hard failures when CI is set", {
2626
skip_if_maintenance()
27-
withr::local_envvar(c(CI = "true"))
27+
withr::local_envvar(c(NOT_CRAN = "", CI = "true"))
28+
expect_doppelganger("myplot", p1_fail, "")
29+
})
30+
31+
test_that("mismatches are skipped when NOT_CRAN is unset", {
32+
skip_if_maintenance()
33+
withr::local_envvar(c(NOT_CRAN = "", CI = ""))
2834
expect_doppelganger("myplot", p1_fail, "")
2935
})
3036

tests/testthat/test-expectations.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

22
context("Expectations")
33

4-
test_that("Mismatches are skipped except on CI", {
5-
skipped_result <- subset_results(test_results, "test-failed.R", "New plots work are collected")[[1]]
6-
expect_match(skipped_result$message, "Figures don't match: myplot.svg\n")
7-
expect_is(skipped_result, "expectation_regression")
4+
test_that("Mismatches are skipped except on CI and interactively", {
5+
notcran_result <- subset_results(test_results, "test-failed.R", "mismatches are hard failures when NOT_CRAN is set")[[1]]
6+
expect_match(notcran_result$message, "Figures don't match: myplot.svg\n")
7+
expect_is(notcran_result, "expectation_failure")
88

9-
failed_result <- subset_results(test_results, "test-failed.R", "figure mismatches are hard failures on CI")[[1]]
9+
failed_result <- subset_results(test_results, "test-failed.R", "mismatches are hard failures when CI is set")[[1]]
1010
expect_match(failed_result$message, "Figures don't match: myplot.svg\n")
1111
expect_is(failed_result, "expectation_failure")
12+
13+
skipped_result <- subset_results(test_results, "test-failed.R", "mismatches are skipped when NOT_CRAN is unset")[[1]]
14+
expect_match(skipped_result$message, "Figures don't match: myplot.svg\n")
15+
expect_is(skipped_result, "expectation_regression")
1216
})
1317

1418
test_that("Duplicated expectations issue warning", {

0 commit comments

Comments
 (0)