Skip to content

Commit 4c585bf

Browse files
author
kalibera
committed
Avoid non-determinism in test output (dependency on when GC is triggered).
git-svn-id: https://svn.r-project.org/R/trunk@87452 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 44b4eed commit 4c585bf

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

tests/reg-tests-2.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,10 @@ sink(type="message")
506506
sink()
507507
try(log("a"))
508508

509+
op <- options(warn = -1)
510+
# *ignore* warnings (for now) to keep the output deterministic wrt to
511+
# warning about closing an unused connections by the gc
512+
509513
## capture all the output to a file.
510514
zz <- file("all.Rout", open="wt")
511515
sink(zz)
@@ -516,6 +520,7 @@ try(log("a"))
516520
closeAllConnections()
517521
(foo <- showConnections())
518522
stopifnot(nrow(foo) == 0)
523+
options(op) # re-enable warnings
519524
try(log("a"))
520525
unlink("all.Rout")
521526
## many of these were untested before 1.4.0.

tests/reg-tests-2.Rout.save

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

2-
R Under development (unstable) (2024-09-12 r87143) -- "Unsuffered Consequences"
2+
R Under development (unstable) (2024-12-19 r87451) -- "Unsuffered Consequences"
33
Copyright (C) 2024 The R Foundation for Statistical Computing
44
Platform: x86_64-pc-linux-gnu
55

@@ -1465,6 +1465,10 @@ Y 4 10 16 22
14651465
> try(log("a"))
14661466
Error in log("a") : non-numeric argument to mathematical function
14671467
>
1468+
> op <- options(warn = -1)
1469+
> # *ignore* warnings (for now) to keep the output deterministic wrt to
1470+
> # warning about closing an unused connections by the gc
1471+
>
14681472
> ## capture all the output to a file.
14691473
> zz <- file("all.Rout", open="wt")
14701474
> sink(zz)
@@ -1473,12 +1477,10 @@ Error in log("a") : non-numeric argument to mathematical function
14731477
>
14741478
> ## bail out
14751479
> closeAllConnections()
1476-
Warning message:
1477-
In .Internal(gc(verbose, reset, full)) :
1478-
closing unused connection 3 (all.Rout)
14791480
> (foo <- showConnections())
14801481
description class mode text isopen can read can write
14811482
> stopifnot(nrow(foo) == 0)
1483+
> options(op) # re-enable warnings
14821484
> try(log("a"))
14831485
Error in log("a") : non-numeric argument to mathematical function
14841486
> unlink("all.Rout")
@@ -6391,7 +6393,7 @@ function(given = NULL) {
63916393
if (is.null(given)) callObj$default <- TRUE
63926394
callObj
63936395
}
6394-
<bytecode: 0x5576bf5fbdf8>
6396+
<bytecode: 0x6176199e3d98>
63956397
> print(foo, useSource = FALSE)
63966398
function (given = NULL)
63976399
{
@@ -6402,7 +6404,7 @@ function (given = NULL)
64026404
callObj$default <- TRUE
64036405
callObj
64046406
}
6405-
<bytecode: 0x5576bf5fbdf8>
6407+
<bytecode: 0x6176199e3d98>
64066408
> attr(foo, "srcref") <- NULL
64076409
> foo
64086410
function (given = NULL)
@@ -6414,7 +6416,7 @@ function (given = NULL)
64146416
callObj$default <- TRUE
64156417
callObj
64166418
}
6417-
<bytecode: 0x5576bf5fbdf8>
6419+
<bytecode: 0x6176199e3d98>
64186420
> (f <- structure(function(){}, note = "just a note",
64196421
+ yada = function() "not the same"))
64206422
function(){}
@@ -8367,7 +8369,7 @@ Error in f() : argument is missing, with no default
83678369
> withAutoprint({ show.srcref() })
83688370
language show.srcref()
83698371
- attr(*, "srcref")= 'srcref' int [1:8] 1 21 1 33 21 33 3 3
8370-
..- attr(*, "srcfile")=Classes 'srcfilealias', 'srcfile' <environment: 0x5576bf84ef28>
8372+
..- attr(*, "srcfile")=Classes 'srcfilealias', 'srcfile' <environment: 0x61761aa14088>
83718373
> ## no attr(*, "src..") in R <= 4.3.1
83728374
> ##
83738375
> withAutoprint({
@@ -8380,5 +8382,5 @@ Error in f() : argument is missing, with no default
83808382
>
83818383
> # ----- Last line -------------
83828384
> cat('Time elapsed: ', proc.time(),'\n')
8383-
Time elapsed: 1.611 0.108 1.836 0.002 0.004
8385+
Time elapsed: 0.735 0.05 0.793 0.001 0.001
83848386
>

0 commit comments

Comments
 (0)