Skip to content

Commit 182432b

Browse files
fix updated test errors
1 parent e39259c commit 182432b

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

inst/tests/tests.Rraw

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,9 @@ TZnotUTC = !identical(tt,"") && !is_utc(tt)
158158
# (3) function factory for matching messages exactly by substituting anything between delimiters [delim, fmt=TRUE]
159159
# (4) function factory for matching messages exactly by substituting a generic string [fmt=string]
160160
get_msg = function(e, delim, fmt=FALSE) {
161+
ufq = options(useFancyQuotes = FALSE) # otherwise we get angled quotes, hard to match robustly
162+
on.exit(options(ufq))
163+
161164
condition = tryCatch({e; NULL}, error=identity, warning=identity)
162165
if (is.null(condition)) return(condition)
163166
msg = condition$message
@@ -169,17 +172,13 @@ get_msg = function(e, delim, fmt=FALSE) {
169172
sprintf("%s%s%s", delim[1L], if (fmt) "%s" else ".+", delim[2L]),
170173
msg
171174
)
172-
if (fmt) return(function(x) sprintf(msg, x))
175+
if (fmt) return(function(...) sprintf(msg, ...))
173176
return(msg)
174177
}
175178
base_messages = list(
176179
missing_object = get_msg(`__dt_test_missing_` + 1, "'", fmt=TRUE),
177180
missing_function = get_msg(`__dt_test_missing_`(), '"', fmt=TRUE),
178-
missing_coerce_method = get_msg(delim = '"', {
179-
old = options(useFancyQuotes = FALSE) # otherwise we get angled quotes, hard to match robustly
180-
on.exit(options(old))
181-
methods::as(TRUE, 'foo')
182-
}),
181+
missing_coerce_method = get_msg(methods::as(TRUE, 'foo'), delim = '"'),
183182
missing_dispatch_method = get_msg(conditionMessage(structure(1, class="foo")), '[\'"]'),
184183
invalid_arg_unary_operator = get_msg(-'a'),
185184
invalid_arg_binary_operator = get_msg(1 + 'a'),
@@ -198,7 +197,8 @@ base_messages = list(
198197
stopifnot = get_msg(stopifnot(FALSE), fmt="FALSE"),
199198
not_yet_used = get_msg(.NotYetUsed("abc"), "'", fmt=TRUE), # NB: need fmt= because the English message has '(yet)' --> parens in regex
200199
ambiguous_date_fmt = get_msg(as.Date('xxx')),
201-
match_arg_length = get_msg(match.arg(c('a', 'b'), letters))
200+
match_arg_length = get_msg(match.arg(c('a', 'b'), letters)),
201+
match_arg_4_choices = get_msg(match.arg('e', letters[1:4]), delim='"', fmt=TRUE),
202202
NULL
203203
)
204204

@@ -10944,9 +10944,9 @@ DT = data.table(
1094410944
D = as.POSIXct(dt<-paste(d,t), tz="UTC"),
1094510945
E = as.POSIXct(paste0(dt,c(".999",".0",".5",".111112",".123456",".023",".0",".999999",".99",".0009")), tz="UTC"))
1094610946

10947-
test(1740.0, fwrite(DT,dateTimeAs="iso"), error="ISO")
10948-
test(1740.1, fwrite(DT,dateTimeAs=c("ISO","squash")), error="dateTimeAs must be a single string")
10949-
test(1740.2, capture.output(fwrite(DT,dateTimeAs="ISO")), c(
10947+
test(1740.1, fwrite(DT,dateTimeAs="iso"), error=base_messages$match_arg_4_choices("ISO", "epoch", "squash", "write.csv"))
10948+
test(1740.2, fwrite(DT,dateTimeAs=c("ISO","squash")), error=base_messages$match_arg_length)
10949+
test(1740.3, capture.output(fwrite(DT,dateTimeAs="ISO")), c(
1095010950
"A,B,C,D,E",
1095110951
"1907-10-21,1907-10-21,23:59:59,1907-10-21T23:59:59Z,1907-10-21T23:59:59.999Z",
1095210952
"1907-10-22,1907-10-22,00:00:00,1907-10-22T00:00:00Z,1907-10-22T00:00:00Z",
@@ -10958,7 +10958,7 @@ test(1740.2, capture.output(fwrite(DT,dateTimeAs="ISO")), c(
1095810958
"1999-12-31,1999-12-31,01:23:45,1999-12-31T01:23:45Z,1999-12-31T01:23:45.999999Z",
1095910959
"2000-02-29,2000-02-29,23:59:59,2000-02-29T23:59:59Z,2000-02-29T23:59:59.990Z",
1096010960
"2016-09-12,2016-09-12,01:30:30,2016-09-12T01:30:30Z,2016-09-12T01:30:30.000900Z"))
10961-
test(1740.3, capture.output(fwrite(DT,dateTimeAs="squash")), c(
10961+
test(1740.4, capture.output(fwrite(DT,dateTimeAs="squash")), c(
1096210962
"A,B,C,D,E",
1096310963
"19071021,19071021,235959,19071021235959000,19071021235959999",
1096410964
"19071022,19071022,000000,19071022000000000,19071022000000000",
@@ -10970,7 +10970,7 @@ test(1740.3, capture.output(fwrite(DT,dateTimeAs="squash")), c(
1097010970
"19991231,19991231,012345,19991231012345000,19991231012345999",
1097110971
"20000229,20000229,235959,20000229235959000,20000229235959990",
1097210972
"20160912,20160912,013030,20160912013030000,20160912013030000"))
10973-
test(1740.4, capture.output(fwrite(DT,dateTimeAs="epoch")), c(
10973+
test(1740.5, capture.output(fwrite(DT,dateTimeAs="epoch")), c(
1097410974
"A,B,C,D,E",
1097510975
"-22718,-22718,86399,-1962748801,-1962748800.001",
1097610976
"-22717,-22717,0,-1962748800,-1962748800",

0 commit comments

Comments
 (0)