diff --git a/R/data.table.R b/R/data.table.R index fe41ed2d3..7b48704a1 100644 --- a/R/data.table.R +++ b/R/data.table.R @@ -2256,8 +2256,8 @@ tail.data.table = function(x, n=6L, ...) { "$<-.data.table" = function(x, name, value) { if (!cedta()) { - ans = `$<-.data.frame`(x, name, value) - return(setalloccol(ans)) # over-allocate (again) + ans = `$<-.data.frame`(x, name, value) # nocov + return(setalloccol(ans)) # nocov. over-allocate (again) } x = copy(x) set(x,j=name,value=value) # important i is missing here @@ -2430,7 +2430,7 @@ which_ = function(x, bool = TRUE) { } is.na.data.table = function(x) { - if (!cedta()) return(is.na.data.frame(x)) + if (!cedta()) return(is.na.data.frame(x)) # nocov do.call(cbind, lapply(x, is.na)) } diff --git a/R/fread.R b/R/fread.R index 883d445c1..e4970749d 100644 --- a/R/fread.R +++ b/R/fread.R @@ -158,6 +158,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC") } # whitespace at the beginning or end of na.strings is checked at C level and is an error there; test 1804 } + # nocov start. Tested in other.Rraw tests 16, not in the main suite. if (yaml) { if (!requireNamespace('yaml', quietly = TRUE)) stopf("'data.table' relies on the package 'yaml' to parse the file header; please add this to your library with install.packages('yaml') and try again.") # nocov @@ -267,6 +268,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC") } if (is.integer(skip)) skip = skip + n_read } + # nocov end warnings2errors = getOption("warn") >= 2 stopifnot(identical(tz,"UTC") || identical(tz,"")) if (tz=="") { @@ -341,7 +343,7 @@ yaml=FALSE, autostart=NA, tmpdir=tempdir(), tz="UTC") key = cols_from_csv(key) setkeyv(ans, key) } - if (yaml) setattr(ans, 'yaml_metadata', yaml_header) + if (yaml) setattr(ans, 'yaml_metadata', yaml_header) # nocov if (!is.null(index) && data.table) { if (!all(vapply_1b(index, is.character))) stopf("index argument of data.table() must be a character vector naming columns (NB: col.names are applied before this)") diff --git a/R/fwrite.R b/R/fwrite.R index ad92859f3..d67c886d1 100644 --- a/R/fwrite.R +++ b/R/fwrite.R @@ -91,6 +91,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto", return(invisible()) } } + # nocov start. See test 17 in other.Rraw, not tested in the main suite. yaml = if (!yaml) "" else { if (!requireNamespace('yaml', quietly=TRUE)) stopf("'data.table' relies on the package 'yaml' to write the file header; please add this to your library with install.packages('yaml') and try again.") # nocov @@ -114,6 +115,7 @@ fwrite = function(x, file="", append=FALSE, quote="auto", ) paste0('---', eol, yaml::as.yaml(yaml_header, line.sep=eol), '---', eol) # NB: as.yaml adds trailing newline } + # nocov end file = enc2native(file) # CfwriteR cannot handle UTF-8 if that is not the native encoding, see #3078. .Call(CfwriteR, x, file, sep, sep2, eol, na, dec, quote, qmethod=="escape", append, row.names, col.names, logical01, scipen, dateTimeAs, buffMB, nThread, diff --git a/R/last.R b/R/last.R index 0a889e622..a93ec3173 100644 --- a/R/last.R +++ b/R/last.R @@ -1,6 +1,7 @@ # data.table defined last(x) with no arguments, just for last. If you need the last 10 then use tail(x,10). # for xts class objects it will dispatch to xts::last # reworked to avoid loading xts namespace (#3857) then again to fix dispatching of xts class (#4053) +# nocov start. Tests 19.* in other.Rraw, not in the main suite. last = function(x, n=1L, ...) { verbose = isTRUE(getOption("datatable.verbose", FALSE)) if (!inherits(x, "xts")) { @@ -82,3 +83,4 @@ first = function(x, n=1L, ...) { xts::first(x, n=n, ...) } } +# nocov end diff --git a/R/xts.R b/R/xts.R index 234f36cac..bd4cb75b3 100644 --- a/R/xts.R +++ b/R/xts.R @@ -1,3 +1,4 @@ +# nocov start. See tests 18.* in other.Rraw, not in the main suite. as.data.table.xts = function(x, keep.rownames = TRUE, key=NULL, ...) { stopifnot(requireNamespace("xts"), !missing(x), xts::is.xts(x)) if (length(keep.rownames) != 1L) stopf("keep.rownames must be length 1") @@ -26,3 +27,4 @@ as.xts.data.table = function(x, numeric.only = TRUE, ...) { } return(xts::xts(as.matrix(r), order.by = if (inherits(x[[1L]], "IDate")) as.Date(x[[1L]]) else x[[1L]])) } +# nocov end diff --git a/src/assign.c b/src/assign.c index dc6b9a6de..b280c2259 100644 --- a/src/assign.c +++ b/src/assign.c @@ -1190,7 +1190,7 @@ const char *memrecycle(const SEXP target, const SEXP where, const int start, con } } } break; - default : + default : // # nocov error(_("Unsupported column type in assign.c:memrecycle '%s'"), type2char(TYPEOF(target))); // # nocov } UNPROTECT(protecti); @@ -1244,7 +1244,7 @@ void writeNA(SEXP v, const int from, const int n, const bool listNA) case EXPRSXP : for (int i=from; i<=to; ++i) SET_VECTOR_ELT(v, i, R_NilValue); break; - default : + default : // # nocov internal_error(__func__, "Unsupported type '%s' for v", type2char(TYPEOF(v))); // # nocov } } @@ -1283,8 +1283,8 @@ void savetl_init(void) { saveds = (SEXP *)malloc(nalloc * sizeof(SEXP)); savedtl = (R_len_t *)malloc(nalloc * sizeof(R_len_t)); if (!saveds || !savedtl) { - free(saveds); free(savedtl); - savetl_end(); // # nocov + free(saveds); free(savedtl); // # nocov + savetl_end(); // # nocov error(_("Failed to allocate initial %d items in savetl_init"), nalloc); // # nocov } } diff --git a/src/between.c b/src/between.c index 25d85b57c..808bf2d35 100644 --- a/src/between.c +++ b/src/between.c @@ -192,7 +192,7 @@ SEXP between(SEXP x, SEXP lower, SEXP upper, SEXP incbounds, SEXP NAboundsArg, S } if (verbose) Rprintf(_("between non-parallel processing of character took %8.3fs\n"), omp_get_wtime()-tic); } break; - default: + default: // # nocov internal_error(__func__, "unsupported type '%s' should have been caught at R level", type2char(TYPEOF(x))); // # nocov } UNPROTECT(nprotect); diff --git a/src/bmerge.c b/src/bmerge.c index cb71f9c20..f6f640e71 100644 --- a/src/bmerge.c +++ b/src/bmerge.c @@ -381,8 +381,8 @@ void bmerge_r(int xlowIn, int xuppIn, int ilowIn, int iuppIn, int col, int thisg } break; // supported types were checked up front to avoid handling an error here in (future) parallel region - default: - error(_("Type '%s' is not supported for joining/merging"), type2char(TYPEOF(xc))); + default: // # nocov + internal_error("Invalid join/merge type '%s' should have been caught earlier", type2char(TYPEOF(xc))); // # nocov } if (xlow= 0; } } break; - default : + default : // # nocov STOP(_("type '%s' is not yet supported"), type2char(TYPEOF(x))); // # nocov } if (!ok) return ScalarLogical(FALSE); // not sorted so return early diff --git a/src/fread.c b/src/fread.c index 1169f645d..7b89b3294 100644 --- a/src/fread.c +++ b/src/fread.c @@ -442,7 +442,7 @@ double copyFile(size_t fileSize) // only called in very very rare cases double tt = wallclock(); mmp_copy = (char *)malloc((size_t)fileSize + 1 /* extra \0 */); if (!mmp_copy) - return -1.0; + return -1.0; // # nocov memcpy(mmp_copy, mmp, fileSize); sof = mmp_copy; eof = (char *)mmp_copy + fileSize; @@ -563,7 +563,7 @@ static void Field(FieldParseContext *ctx) if (ch!=ch2) fieldStart--; // field ending is this sep|eol; neither (*1) or (*2) happened; opening quote wasn't really an opening quote } break; - default: + default: // # nocov return; // # nocov Internal error: undefined quote rule } target->len = (int32_t)(ch - fieldStart); @@ -1540,14 +1540,16 @@ int freadMain(freadMainArgs _args) { // In future, we may discover a way to mmap fileSize+1 on all OS when fileSize%4096==0, reliably. If and when, this clause can be updated with no code impact elsewhere. double time_taken = copyFile(fileSize); if (time_taken == -1.0) { + // # nocov start if (!verbose) DTPRINT("%s. Attempt to copy file in RAM failed.", msg); STOP(_("Unable to allocate %s of contiguous virtual RAM."), filesize_to_str(fileSize)); + // # nocov end } if (verbose) DTPRINT(_(" File copy in RAM took %.3f seconds.\n"), time_taken); else if (time_taken > 0.5) - DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded + DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // # nocov. not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded } } *_const_cast(eof) = '\0'; // cow page @@ -1822,14 +1824,16 @@ int freadMain(freadMainArgs _args) { ASSERT(mmp_copy==NULL, "mmp has already been copied due to abrupt non-eol ending, so it does not end with 2 or more eol.%s", ""/*dummy arg for macro*/); // #nocov double time_taken = copyFile(fileSize); if (time_taken == -1.0) { + // # nocov start if (!verbose) DTPRINT("%s. Attempt to copy file in RAM failed.", msg); STOP(_("Unable to allocate %s of contiguous virtual RAM."), filesize_to_str(fileSize)); + // # nocov end } if (verbose) DTPRINT(_(" File copy in RAM took %.3f seconds.\n"), time_taken); - else if (tt>0.5) - DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded + else if (tt>0.5) // # nocov + DTPRINT(_("Avoidable file copy in RAM took %.3f seconds. %s.\n"), time_taken, msg); // # nocov. not warning as that could feasibly cause CRAN tests to fail, say, if test machine is heavily loaded pos = sof + (pos-(const char *)mmp); firstJumpEnd = sof + (firstJumpEnd-(const char *)mmp); } else { @@ -1858,8 +1862,8 @@ int freadMain(freadMainArgs _args) { type = (int8_t *)malloc((size_t)ncol * sizeof(int8_t)); tmpType = (int8_t *)malloc((size_t)ncol * sizeof(int8_t)); // used i) in sampling to not stop on errors when bad jump point and ii) when accepting user overrides if (!type || !tmpType) { - free(type); free(tmpType); - STOP(_("Failed to allocate 2 x %d bytes for type and tmpType: %s"), ncol, strerror(errno)); + free(type); free(tmpType); // # nocov + STOP(_("Failed to allocate 2 x %d bytes for type and tmpType: %s"), ncol, strerror(errno)); // # nocov } if (sep == ',' && dec == '\0') { // if sep=',' detected, don't attempt to detect dec [NB: . is not par of seps] @@ -2119,7 +2123,7 @@ int freadMain(freadMainArgs _args) { } else { colNames = (lenOff*) calloc((size_t)ncol, sizeof(lenOff)); if (!colNames) - STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(lenOff), strerror(errno)); + STOP(_("Unable to allocate %d*%d bytes for column name pointers: %s"), ncol, sizeof(lenOff), strerror(errno)); // # nocov if (sep==' ') while (*ch==' ') ch++; void *targets[9] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, colNames + autoFirstColName}; FieldParseContext fctx = { @@ -2174,7 +2178,7 @@ int freadMain(freadMainArgs _args) { rowSize8 = 0; size = (int8_t *)malloc((size_t)ncol * sizeof(int8_t)); // TODO: remove size[] when we implement Pasha's idea to += size inside processor if (!size) - STOP(_("Failed to allocate %d bytes for '%s': %s"), (int)(ncol * sizeof(int8_t)), "size", strerror(errno)); + STOP(_("Failed to allocate %d bytes for '%s': %s"), (int)(ncol * sizeof(int8_t)), "size", strerror(errno)); // # nocov nStringCols = 0; nNonStringCols = 0; for (int j=0; j= ((int64_t *)xd)[previ] : dtwiddle(xd[thisi]) >= dtwiddle(xd[previ]); } break; - default: + default: // # nocov error(_("Type '%s' is not supported"), type2char(TYPEOF(v))); // # nocov } }