Skip to content

Commit 04c3110

Browse files
committed
Use test(output=) instead of capture.output()
A comment near 1832.2 said that output= was inapplicable due to square bracket matching. The actual source of the problem was the caret only matching start of string instead of start of line.
1 parent 28f4d84 commit 04c3110

File tree

1 file changed

+55
-56
lines changed

1 file changed

+55
-56
lines changed

inst/tests/tests.Rraw

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11810,15 +11810,15 @@ test(1775.1, capture.output(print(DT1, print.keys = TRUE)),
1181011810
c("Key: <a>", " a", "1: 1", "2: 2", "3: 3"))
1181111811
DT2 <- data.table(a = 1:3, b = 4:6)
1181211812
setindexv(DT2, c("b","a"))
11813-
test(1775.2, capture.output(print(DT2, print.keys = TRUE)),
11814-
c("Index: <b__a>", " a b", "1: 1 4", "2: 2 5", "3: 3 6"))
11813+
test(1775.2, print(DT2, print.keys = TRUE),
11814+
output = c("Index: <b__a>", " a b", "1: 1 4", "2: 2 5", "3: 3 6"))
1181511815
setindexv(DT2, "b")
11816-
test(1775.3, capture.output(print(DT2, print.keys = TRUE)),
11817-
c("Indices: <b__a>, <b>", " a b", "1: 1 4", "2: 2 5", "3: 3 6"))
11816+
test(1775.3, print(DT2, print.keys = TRUE),
11817+
output = c("Indices: <b__a>, <b>", " a b", "1: 1 4", "2: 2 5", "3: 3 6"))
1181811818
setkey(DT2, a)
1181911819
setindexv(DT2, c("b","a"))
11820-
test(1775.4, capture.output(print(DT2, print.keys = TRUE)),
11821-
c("Key: <a>", "Indices: <b__a>, <b>", " a b", "1: 1 4", "2: 2 5", "3: 3 6")) ## index 'b' is still good, so we keep it
11820+
test(1775.4, print(DT2, print.keys = TRUE),
11821+
output = c("Key: <a>", "Indices: <b__a>, <b>", " a b", "1: 1 4", "2: 2 5", "3: 3 6")) ## index 'b' is still good, so we keep it
1182211822

1182311823
# dev regression #2285
1182411824
cat("A B C\n1 2 3\n4 5 6", file=f<-tempfile())
@@ -12142,8 +12142,7 @@ test(1831.4, fread(paste0("A\n", "1.", src2)), data.table(A=1.1234567890098766))
1214212142
DT = as.data.table(matrix(5L, nrow=10, ncol=10))
1214312143
test(1832.1, fwrite(DT, f<-tempfile(), verbose=TRUE), output="Column writers")
1214412144
DT = as.data.table(matrix(5L, nrow=10, ncol=60))
12145-
# Using capture.output directly to look for the "..." because test(,output=) intercepts [] for convenience elsewhere
12146-
test(1832.2, any(grepl("^Column writers.* [.][.][.] ", capture.output(fwrite(DT, f, verbose=TRUE)))))
12145+
test(1832.2, fwrite(DT, f, verbose=TRUE), output = "\nColumn writers.* [.][.][.] ")
1214712146
unlink(f)
1214812147

1214912148
# ensure explicitly setting select to default value doesn't error, #2007
@@ -16568,69 +16567,69 @@ DT = data.table(a = vector("integer", 102L),
1656816567
b = "bbbbbbbbbbbbb",
1656916568
c = "ccccccccccccc",
1657016569
d = c("ddddddddddddd", "d"))
16571-
test(2125.02, capture.output(print(DT, trunc.cols=TRUE)),
16572-
c(" a b c",
16573-
" 1: 0 bbbbbbbbbbbbb ccccccccccccc",
16574-
" 2: 0 bbbbbbbbbbbbb ccccccccccccc",
16575-
" 3: 0 bbbbbbbbbbbbb ccccccccccccc",
16576-
" 4: 0 bbbbbbbbbbbbb ccccccccccccc",
16577-
" 5: 0 bbbbbbbbbbbbb ccccccccccccc",
16578-
" --- ",
16579-
" 98: 0 bbbbbbbbbbbbb ccccccccccccc",
16580-
" 99: 0 bbbbbbbbbbbbb ccccccccccccc",
16581-
"100: 0 bbbbbbbbbbbbb ccccccccccccc",
16582-
"101: 0 bbbbbbbbbbbbb ccccccccccccc",
16583-
"102: 0 bbbbbbbbbbbbb ccccccccccccc",
16584-
"1 variable not shown: [d]"))
16585-
test(2125.03, capture.output(print(DT, trunc.cols=TRUE, row.names=FALSE)),
16586-
c(" a b c",
16587-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16588-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16589-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16590-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16591-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16592-
" --- --- ---",
16593-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16594-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16595-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16596-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16597-
" 0 bbbbbbbbbbbbb ccccccccccccc",
16598-
"1 variable not shown: [d]" ))
16570+
test(2125.02, print(DT, trunc.cols=TRUE),
16571+
output=c(" a b c",
16572+
" 1: 0 bbbbbbbbbbbbb ccccccccccccc",
16573+
" 2: 0 bbbbbbbbbbbbb ccccccccccccc",
16574+
" 3: 0 bbbbbbbbbbbbb ccccccccccccc",
16575+
" 4: 0 bbbbbbbbbbbbb ccccccccccccc",
16576+
" 5: 0 bbbbbbbbbbbbb ccccccccccccc",
16577+
" --- ",
16578+
" 98: 0 bbbbbbbbbbbbb ccccccccccccc",
16579+
" 99: 0 bbbbbbbbbbbbb ccccccccccccc",
16580+
"100: 0 bbbbbbbbbbbbb ccccccccccccc",
16581+
"101: 0 bbbbbbbbbbbbb ccccccccccccc",
16582+
"102: 0 bbbbbbbbbbbbb ccccccccccccc",
16583+
"1 variable not shown: [d]"))
16584+
test(2125.03, print(DT, trunc.cols=TRUE, row.names=FALSE),
16585+
output=c(" a b c",
16586+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16587+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16588+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16589+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16590+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16591+
" --- --- ---",
16592+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16593+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16594+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16595+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16596+
" 0 bbbbbbbbbbbbb ccccccccccccc",
16597+
"1 variable not shown: [d]" ))
1659916598
# also testing #4266 -- getting width of row #s register right
1660016599
# TODO: understand why 2 variables truncated here. a,b,c combined have width
1660116600
# _exactly_ 40, but still wraps. If we set options(width=41) it won't truncate.
1660216601
# seems to be an issue with print.default.
16603-
test(2125.04, capture.output(print(DT, trunc.cols=TRUE, class=TRUE))[14L],
16604-
"2 variables not shown: [c <char>, d <char>]")
16605-
test(2125.05, capture.output(print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE))[c(1,14)],
16606-
c(" a b c",
16607-
"1 variable not shown: [d <char>]" ))
16608-
test(2125.06, capture.output(print(DT, trunc.cols=TRUE, col.names="none"))[c(1,12)],
16609-
c(" 1: 0 bbbbbbbbbbbbb ccccccccccccc",
16610-
"1 variable not shown: [d]" ))
16611-
test(2125.07, capture.output(print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"))[c(1,13)],
16612-
c(" 1: 0 bbbbbbbbbbbbb",
16613-
"2 variables not shown: [c, d]" ),
16602+
test(2125.04, print(DT, trunc.cols=TRUE, class=TRUE),
16603+
output="2 variables not shown: [c <char>, d <char>]")
16604+
test(2125.05, print(DT, trunc.cols=TRUE, class=TRUE, row.names=FALSE),
16605+
output=c("^ a b c", ".*",
16606+
"1 variable not shown: \\[d <char>\\]"))
16607+
test(2125.06, print(DT, trunc.cols=TRUE, col.names="none"),
16608+
output=c("^ 1: 0 bbbbbbbbbbbbb ccccccccccccc", ".*",
16609+
"1 variable not shown: \\[d\\]", ""))
16610+
test(2125.07, print(DT, trunc.cols=TRUE, class=TRUE, col.names="none"),
16611+
output=c("^ 1: 0 bbbbbbbbbbbbb", ".*",
16612+
"2 variables not shown: \\[c, d\\]", ""),
1661416613
warning = "Column classes will be suppressed when col.names is 'none'")
1661516614
options("width" = 20)
1661616615
DT = data.table(a = vector("integer", 2),
1661716616
b = "bbbbbbbbbbbbb",
1661816617
c = "ccccccccccccc",
1661916618
d = "ddddddddddddd")
16620-
test(2125.08, capture.output(print(DT, trunc.cols=TRUE)),
16621-
c(" a b",
16622-
"1: 0 bbbbbbbbbbbbb",
16623-
"2: 0 bbbbbbbbbbbbb",
16624-
"2 variables not shown: [c, d]"))
16619+
test(2125.08, print(DT, trunc.cols=TRUE),
16620+
output=c(" a b",
16621+
"1: 0 bbbbbbbbbbbbb",
16622+
"2: 0 bbbbbbbbbbbbb",
16623+
"2 variables not shown: [c, d]"))
1662516624
options("width" = 10)
1662616625
DT = data.table(a = "aaaaaaaaaaaaa",
1662716626
b = "bbbbbbbbbbbbb",
1662816627
c = "ccccccccccccc",
1662916628
d = "ddddddddddddd")
16630-
test(2125.09, capture.output(print(DT, trunc.cols=TRUE)),
16631-
"4 variables not shown: [a, b, c, d]")
16632-
test(2125.10, capture.output(print(DT, trunc.cols=TRUE, class=TRUE)),
16633-
"4 variables not shown: [a <char>, b <char>, c <char>, d <char>]")
16629+
test(2125.09, print(DT, trunc.cols=TRUE),
16630+
output="4 variables not shown: [a, b, c, d]")
16631+
test(2125.10, print(DT, trunc.cols=TRUE, class=TRUE),
16632+
output="4 variables not shown: [a <char>, b <char>, c <char>, d <char>]")
1663416633
options(old_width)
1663516634

1663616635
# segfault when i is NULL or zero-column, #4060

0 commit comments

Comments
 (0)