@@ -4,6 +4,7 @@ pdf("reg-tests-1d.pdf", encoding = "ISOLatin1.enc")
4
4
.pt <- proc.time()
5
5
tryCid <- function (expr ) tryCatch(expr , error = identity )
6
6
identCO <- function (x ,y , ... ) identical(capture.output(x ), capture.output(y ), ... )
7
+ assertErrV <- function (... ) tools :: assertError(... , verbose = TRUE )
7
8
onWindows <- .Platform $ OS.type == " windows"
8
9
9
10
# # body() / formals() notably the replacement versions
@@ -611,7 +612,7 @@ stopifnot(exprs = {
611
612
identical(c(1L , 3L ), seq.int(1L , 3L , length.out = 2 ))
612
613
})
613
614
# # the first was missing(.), the others "double" in R < 3.4.0
614
- tools :: assertError (seq(1 ,7 , by = 1 : 2 ))# gave warnings in R < 3.4.0
615
+ assertErrV (seq(1 ,7 , by = 1 : 2 ))# gave warnings in R < 3.4.0
615
616
# # seq() for <complex> / <integer>
616
617
stopifnot(exprs = {
617
618
all.equal(seq(1 + 1i , 9 + 2i , length.out = 9 ) - > sCplx ,
@@ -837,8 +838,8 @@ if(englishMsgs)
837
838
stopifnot(grepl(" indexing '...' with .* index 0" , mt0 ),
838
839
identical(" the ... list contains fewer than 2 elements" , mt2.0 ),
839
840
identical(mt2.0 , mt2.1 ))
840
- tools :: assertError (t0(1 ))
841
- tools :: assertError (t0(1 , 2 ))
841
+ assertErrV (t0(1 ))
842
+ assertErrV (t0(1 , 2 ))
842
843
# # the first gave a different error msg, the next gave no error in R < 3.5.0
843
844
844
845
@@ -1078,9 +1079,9 @@ stopifnot(exprs = {
1078
1079
# # invalid user device function options(device = *) -- PR#15883
1079
1080
graphics.off() # just in case
1080
1081
op <- options(device = function (... ){}) # non-sense device
1081
- tools :: assertError (plot.new(), verbose = TRUE )
1082
+ assertErrV (plot.new())
1082
1083
if (no.grid <- ! (" grid" %in% loadedNamespaces())) requireNamespace(" grid" )
1083
- tools :: assertError (grid :: grid.newpage(), verbose = TRUE )
1084
+ assertErrV (grid :: grid.newpage())
1084
1085
if (no.grid ) unloadNamespace(" grid" ) ; options(op )
1085
1086
# # both errors gave segfaults in R <= 3.4.1
1086
1087
@@ -1280,7 +1281,7 @@ stopifnot(exprs = {
1280
1281
if (no.splines <- ! (" splines" %in% loadedNamespaces())) requireNamespace(" splines" )
1281
1282
x <- (0 : 8 )/ 8
1282
1283
aKnots <- c(rep(0 , 4 ), c(0.3 , 0.5 , 0.6 ), rep(1 , 4 ))
1283
- tools :: assertError (splines :: splineDesign(aKnots , x , derivs = 4 ), verbose = TRUE )
1284
+ assertErrV (splines :: splineDesign(aKnots , x , derivs = 4 ))
1284
1285
# # gave seg.fault in R <= 3.4.1
1285
1286
1286
1287
@@ -2661,7 +2662,7 @@ stopifnot(exprs = {
2661
2662
2662
2663
2663
2664
# # Failed to work after r76382--8:
2664
- tools :: assertError (formula(" 3" ), verbose = TRUE )
2665
+ assertErrV (formula(" 3" ))
2665
2666
stopifnot(exprs = {
2666
2667
# # New formula(<character>) specs:
2667
2668
# # These give deprecation warnings:
@@ -3368,7 +3369,7 @@ stopifnot(exprs = {
3368
3369
NextMethod(" [" )
3369
3370
}
3370
3371
noC <- structure(datasets :: trees , class = c(" noCol" , " data.frame" ))
3371
- tools :: assertError ( noC [1 ,2 ], verbose = TRUE ) # fails indeed
3372
+ assertErrV ( noC [1 ,2 ]) # fails indeed
3372
3373
stopifnot(exprs = {
3373
3374
identical(head(noC ), noC [1 : 6 ,])
3374
3375
identical(head(noC , 1 ), noC [1 , ])
@@ -3380,8 +3381,8 @@ stopifnot(exprs = {
3380
3381
str(Alis <- lapply(1 : 4 , function (n ) {d <- 1 + (1 : n ); array (seq_len(prod(d )), d ) }))
3381
3382
h2 <- lapply(Alis , head , 2 )
3382
3383
t2 <- lapply(Alis , head , 2 )
3383
- tools :: assertError ( head(Alis [[1 ]], c(1 , NA )), verbose = TRUE )
3384
- tools :: assertError ( tail(1 : 5 , c(1 , NA )), verbose = TRUE )
3384
+ assertErrV ( head(Alis [[1 ]], c(1 , NA )))
3385
+ assertErrV ( tail(1 : 5 , c(1 , NA )))
3385
3386
h1 <- lapply(Alis , head , 1 )
3386
3387
t1 <- lapply(Alis , tail , 1 )
3387
3388
dh1 <- lapply(h1 , dim )
@@ -3390,7 +3391,7 @@ Alis2p <- Alis[-1]
3390
3391
h1N <- lapply(Alis2p , head , c(1 , NA ))
3391
3392
t1N <- lapply(Alis2p , tail , c(1 , NA ))
3392
3393
Foolis <- lapply(Alis , `class<-` , " foo" )
3393
- tools :: assertError ( head(Foolis [[1 ]], c(1 , NA )), verbose = TRUE )
3394
+ assertErrV ( head(Foolis [[1 ]], c(1 , NA )))
3394
3395
h1F <- lapply(Foolis , head , 1 )
3395
3396
h2F <- lapply(Foolis , head , 2 )
3396
3397
t1F <- lapply(Foolis , tail , 1 )
@@ -3531,8 +3532,8 @@ stopifnot(exprs = {
3531
3532
all.equal(attributes(x ), list (tsp = c(2.5 , 107.5 , 0.2 ), class = " ts" ))
3532
3533
all.equal(wx , structure(c(0.5 , 0.6 ), .Tsp = c(22.5 , 27.5 , 0.2 ), class = " ts" ))
3533
3534
})
3534
- tools :: assertError (cbind(ts(1 : 2 , start = 0.5 , end = 1.5 ),
3535
- ts(1 : 2 , start = 0 , end = 1 )), verbose = TRUE )
3535
+ assertErrV (cbind(ts(1 : 2 , start = 0.5 , end = 1.5 ),
3536
+ ts(1 : 2 , start = 0 , end = 1 )))
3536
3537
# # Wrong results in R < 4.0.0
3537
3538
# # New checks needed tweaks :
3538
3539
# # -- 1 --
@@ -3809,10 +3810,9 @@ stopifnot(is.integer(y1), is.integer(y2), y1[-3] == y2[-3],
3809
3810
3810
3811
3811
3812
# # stopifnot() custom message now via <named> args:
3812
- e <- tools :: assertError (stopifnot(" ehmm, you must be kidding!" = 1 == 0 ), verbose = TRUE )
3813
+ e <- assertErrV (stopifnot(" ehmm, you must be kidding!" = 1 == 0 ))
3813
3814
stopifnot(grepl(" must be kidding!" , e [[1 ]]$ message ))
3814
- e2 <- tools :: assertError(
3815
- stopifnot(" 2 is not approximately 2.1" = all.equal(2 , 2.1 )), verbose = TRUE )
3815
+ e2 <- assertErrV(stopifnot(" 2 is not approximately 2.1" = all.equal(2 , 2.1 )))
3816
3816
stopifnot(grepl(" not approximately" , e2 [[1 ]]$ message ))
3817
3817
# # did not work in original stopifnot(<named>) patch
3818
3818
CHK <- function (... ) stopifnot(... )
@@ -4030,7 +4030,6 @@ cat("Case 2 : round(x=1.12345,2): ", round(x=1.12345, 2),"\n")
4030
4030
cat(" Case 3 : round(x=1.12345,digits=2): " , round(x = 1.12345 , digits = 2 )," \n " )
4031
4031
cat(" Case 4 : round(digits=2,x=1.12345): " , round(digits = 2 , x = 1.12345 )," \n " )
4032
4032
cat(" Case 4b: round(digits=2,1.12345): " , round(digits = 2 ,1.12345 )," \n " )
4033
- assertErrV <- function (... ) tools :: assertError(... , verbose = TRUE )
4034
4033
# # R <= 4.0.0 does not produce error in cases 5,6 but should :
4035
4034
cat(" Case 5: round(digits=x): \n " )
4036
4035
assertErrV(cat(" round(digits=99.23456): " , round(digits = 99.23456 )))
@@ -4058,6 +4057,14 @@ boxplot(cbind(x = 1:10, y = c(16,9:1)), xlab = quote(x^{y[2]}), ylab = quote(X[t
4058
4057
# # failed in R <= 4.0.1
4059
4058
4060
4059
4060
+ # # on.exit() argument matching -- PR#17815
4061
+ f <- function () { on.exit(add = FALSE , expr = cat(' bar\n ' )) ; ' foo' }
4062
+ stopifnot(identical(f(), ' foo' )) # and write 'bar' line
4063
+ g <- function () { on.exit(add = stop(' boom' ), expr = {cat(' bar\n ' ); FALSE }) ; " foo" }
4064
+ assertErrV(g())
4065
+ # # f() :> "Error in on.exit(....): invalid 'add' argument" and no error for g() in R <= 4.0.1
4066
+
4067
+
4061
4068
4062
4069
# # keep at end
4063
4070
rbind(last = proc.time() - .pt ,
0 commit comments