Skip to content

Commit

Permalink
Merge pull request #1036 from RcppCore/feature/more_nocov
Browse files Browse the repository at this point in the history
more nocov
  • Loading branch information
eddelbuettel committed Dec 14, 2019
2 parents 1e6bf21 + 84dd399 commit 43a6d84
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 46 deletions.
10 changes: 10 additions & 0 deletions ChangeLog
@@ -1,3 +1,13 @@
2019-12-14 Dirk Eddelbuettel <edd@debian.org>

* src/date.cpp: A few more #nocov tage

2019-12-13 Dirk Eddelbuettel <edd@debian.org>

* src/api.cpp: A few more #nocov tags
* src/attributes.cpp: Idem
* src/barrier.cpp: Idem

2019-12-08 Dirk Eddelbuettel <edd@debian.org>

* tests/tinytest.R: Turn verbose tests on in dev and on Travis
Expand Down
6 changes: 3 additions & 3 deletions src/api.cpp
Expand Up @@ -2,7 +2,7 @@
//
// api.cpp: Rcpp R/C++ interface class library -- Rcpp api
//
// Copyright (C) 2012 - 2016 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2012 - 2019 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand Down Expand Up @@ -82,7 +82,7 @@ namespace Rcpp {
}

// [[Rcpp::register]]
unsigned long beginSuspendRNGSynchronization() {
unsigned long beginSuspendRNGSynchronization() {// #nocov start
++rngSynchronizationSuspended;
return rngSynchronizationSuspended;
}
Expand All @@ -91,7 +91,7 @@ namespace Rcpp {
unsigned long endSuspendRNGSynchronization() {
--rngSynchronizationSuspended;
return rngSynchronizationSuspended;
}
} // #nocov end

// [[Rcpp::register]]
char* get_string_buffer() {
Expand Down
40 changes: 20 additions & 20 deletions src/attributes.cpp
Expand Up @@ -957,7 +957,7 @@ namespace attributes {
parseSourceDependencies(sourceFile, &dependencies);

// remove main source file
dependencies.erase(std::remove(dependencies.begin(),
dependencies.erase(std::remove(dependencies.begin(), // #nocov
dependencies.end(),
FileInfo(sourceFile)),
dependencies.end());
Expand Down Expand Up @@ -1263,9 +1263,9 @@ namespace attributes {
// check for a match
Rcpp::CharacterVector match = initMatches[i];
if (match.size() > 0) {
hasPackageInit_ = true;
hasPackageInit_ = true; // #nocov start
break;
}
} // #nocov end
}

// Parse embedded R
Expand All @@ -1285,9 +1285,9 @@ namespace attributes {
SourceFileAttributesParser parser(dependency, packageName, false);

// copy to base attributes (if it's a new attribute)
for (SourceFileAttributesParser::const_iterator
for (SourceFileAttributesParser::const_iterator // #nocov start
it = parser.begin(); it != parser.end(); ++it) {
if (std::find(attributes_.begin(), // #nocov start
if (std::find(attributes_.begin(),
attributes_.end(),
*it) == attributes_.end()) {
attributes_.push_back(*it); // #nocov end
Expand Down Expand Up @@ -1454,8 +1454,8 @@ namespace attributes {
beginParenLoc == std::string::npos ||
endParenLoc < beginParenLoc) {

rcppExportNoFunctionFoundWarning(lineNumber);
return Function();
rcppExportNoFunctionFoundWarning(lineNumber); // #nocov
return Function(); // #nocov
}

// Find the type and name by scanning backwards for the whitespace that
Expand Down Expand Up @@ -1510,7 +1510,7 @@ namespace attributes {
trimWhitespace(&arg);
if (arg.empty()) {
// we don't warn here because the compilation will fail anyway
continue;
continue; // #nocov
}

// If the argument has an = within it then it has a default value
Expand Down Expand Up @@ -1656,12 +1656,12 @@ namespace attributes {
case '>':
templateCount--;
break;
case '(':
parenCount++; // #nocov
break; // #nocov
case '(': // #nocov start
parenCount++;
break;
case ')':
parenCount--; // #nocov
break; // #nocov
parenCount--;
break; // #nocov end
}
}
}
Expand Down Expand Up @@ -2445,12 +2445,12 @@ namespace attributes {
ostr() << "invisible("; // #nocov
ostr() << ".Call(";
if (!registration_)
ostr() << "'";
ostr() << "'"; // #nocov
else
ostr() << "`";
ostr() << packageCppPrefix() << "_" << function.name();
if (!registration_)
ostr() << "', " << "PACKAGE = '" << package() << "'";
ostr() << "', " << "PACKAGE = '" << package() << "'"; // #nocov
else
ostr() << "`";

Expand Down Expand Up @@ -2972,7 +2972,7 @@ namespace attributes {

// skip empty case
if (pStr->empty())
return;
return; // #nocov

// trim right
std::string::size_type pos = pStr->find_last_not_of(kWhitespaceChars);
Expand Down Expand Up @@ -3572,14 +3572,14 @@ BEGIN_RCPP
// don't process RcppExports.cpp
std::string cppFile = cppFiles[i];
if (endsWith(cppFile, "RcppExports.cpp"))
continue;
continue; // #nocov

// parse file
SourceFileAttributesParser attributes(cppFile, packageName, false);

// note if we found a package init function
if (!hasPackageInit && attributes.hasPackageInit())
hasPackageInit = true;
hasPackageInit = true; // #nocov

// continue if no generator output
if (!attributes.hasGeneratorOutput())
Expand Down Expand Up @@ -3618,7 +3618,7 @@ BEGIN_RCPP
depends.begin(), depends.end(),
std::back_inserter(diff));
if (!diff.empty()) {
std::string msg =
std::string msg = // #nocov start
"The following packages are referenced using Rcpp::depends "
"attributes however are not listed in the Depends, Imports or "
"LinkingTo fields of the package DESCRIPTION file: ";
Expand All @@ -3633,7 +3633,7 @@ BEGIN_RCPP
// verbose output
if (verbose) {
for (size_t i=0; i<updated.size(); i++)
Rcpp::Rcout << updated[i] << " updated." << std::endl;
Rcpp::Rcout << updated[i] << " updated." << std::endl; // #nocov end
}

// return files updated
Expand Down
11 changes: 5 additions & 6 deletions src/barrier.cpp
Expand Up @@ -2,7 +2,7 @@
//
// barrier.cpp: Rcpp R/C++ interface class library -- write barrier
//
// Copyright (C) 2010 - 2015 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
//
// This file is part of Rcpp.
//
Expand All @@ -29,7 +29,7 @@
#include <Rcpp/protection/Shield.h>

// [[Rcpp::register]]
SEXP get_string_elt(SEXP x, R_xlen_t i) {
SEXP get_string_elt(SEXP x, R_xlen_t i) { // #nocov start
return STRING_ELT(x, i);
}

Expand Down Expand Up @@ -65,7 +65,7 @@ void set_vector_elt(SEXP x, R_xlen_t i, SEXP value) {

// [[Rcpp::register]]
SEXP* get_vector_ptr(SEXP x) {
return VECTOR_PTR(x);
return VECTOR_PTR(x); // #nocov end
}

// [[Rcpp::register]]
Expand Down Expand Up @@ -153,7 +153,7 @@ SEXP init_Rcpp_cache() {
}

// [[Rcpp::register]]
SEXP reset_current_error() {
SEXP reset_current_error() { // #nocov start
SEXP cache = get_rcpp_cache();

// error occured
Expand Down Expand Up @@ -189,7 +189,7 @@ SEXP rcpp_error_recorder(SEXP e) {

// [[Rcpp::register]]
SEXP rcpp_get_current_error() {
return VECTOR_ELT(get_rcpp_cache(), 2);
return VECTOR_ELT(get_rcpp_cache(), 2); // #nocov end
}

// [[Rcpp::register]]
Expand All @@ -206,4 +206,3 @@ int* get_cache(int m) {
std::fill(res, res+m, 0);
return res;
}

33 changes: 16 additions & 17 deletions src/date.cpp
@@ -1,9 +1,8 @@
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
// jedit: :folding=explicit:

//
// Date.cpp: Rcpp R/C++ interface class library -- Date type
//
// Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
// Copyright (C) 2010 - 2019 Dirk Eddelbuettel and Romain Francois
//
// The mktime00() as well as the gmtime_() replacement function are
// Copyright (C) 2000 - 2010 The R Development Core Team.
Expand Down Expand Up @@ -85,11 +84,11 @@ namespace Rcpp {
year0 = year_base + tm.tm_year;
/* safety check for unbounded loops */
if (year0 > 3000) {
excess = (int)(year0/2000) - 1;
excess = (int)(year0/2000) - 1; // #nocov start
year0 -= excess * 2000;
} else if (year0 < 0) {
excess = -1 - (int)(-year0/2000);
year0 -= excess * 2000;
year0 -= excess * 2000; // #nocov end
}

for(i = 0; i < tm.tm_mon; i++) day += days_in_month[i];
Expand Down Expand Up @@ -461,12 +460,12 @@ struct tzhead {
** or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow.
*/
if ((i >= 0) ? (j > INT_MAX - i) : (j < INT_MIN - i))
return TRUE;
return TRUE; // #nocov
*ip += j;
return FALSE;
}

static int increment_overflow_time(time_t *tp, int_fast32_t j) {
static int increment_overflow_time(time_t *tp, int_fast32_t j) { // #nocov start
/*
** This is like
** 'if (! (time_t_min <= *tp + j && *tp + j <= time_t_max)) ...',
Expand All @@ -477,10 +476,10 @@ struct tzhead {
: *tp <= time_t_max - j))
return TRUE;
*tp += j;
return FALSE;
return FALSE;
}

static int_fast32_t detzcode(const char *const codep) { // #nocov start
static int_fast32_t detzcode(const char *const codep) {
int_fast32_t result = (codep[0] & 0x80) ? -1 : 0;
for (int i = 0; i < 4; ++i)
result = (result << 8) | (codep[i] & 0xff);
Expand Down Expand Up @@ -1241,7 +1240,7 @@ struct tzhead {
hit = 0;
i = sp->leapcnt;
while (--i >= 0) {
lp = &sp->lsis[i];
lp = &sp->lsis[i]; // #nocov start
if (*timep >= lp->ls_trans) {
if (*timep == lp->ls_trans) {
hit = ((i == 0 && lp->ls_corr > 0) ||
Expand All @@ -1257,7 +1256,7 @@ struct tzhead {
}
}
corr = lp->ls_corr;
break;
break; // #nocov end
}
}
y = EPOCH_YEAR;
Expand All @@ -1272,13 +1271,13 @@ struct tzhead {
tdelta = tdays / DAYSPERLYEAR;
if (! ((! TYPE_SIGNED(time_t) || INT_MIN <= tdelta)
&& tdelta <= INT_MAX))
return NULL;
return NULL; // #nocov
idelta = (int)tdelta;
if (idelta == 0)
idelta = (tdays < 0) ? -1 : 1;
newy = y;
if (increment_overflow(&newy, idelta))
return NULL;
return NULL; // #nocov
leapdays = leaps_thru_end_of(newy - 1) -
leaps_thru_end_of(y - 1);
tdays -= ((time_t) newy - y) * DAYSPERNYEAR;
Expand All @@ -1297,7 +1296,7 @@ struct tzhead {
*/
idays = (int)tdays;
rem += offset - corr;
while (rem < 0) {
while (rem < 0) { // #nocov start
rem += SECSPERDAY;
--idays;
}
Expand All @@ -1313,14 +1312,14 @@ struct tzhead {
while (idays >= year_lengths[isleap(y)]) {
idays -= year_lengths[isleap(y)];
if (increment_overflow(&y, 1))
return NULL;
return NULL; // #nocov end
}
// Previously we returned 'year + base', so keep behaviour
// It seems like R now returns just 'year - 1900' (as libc does)
// But better for continuity to do as before
tmp->tm_year = y + TM_YEAR_BASE;
if (increment_overflow(&tmp->tm_year, -TM_YEAR_BASE))
return NULL;
return NULL; // #nocov
tmp->tm_yday = idays;
/*
** The "extra" mods below avoid overflow problems.
Expand All @@ -1333,7 +1332,7 @@ struct tzhead {
idays;
tmp->tm_wday %= DAYSPERWEEK;
if (tmp->tm_wday < 0)
tmp->tm_wday += DAYSPERWEEK;
tmp->tm_wday += DAYSPERWEEK; // #nocov
tmp->tm_hour = (int) (rem / SECSPERHOUR);
rem %= SECSPERHOUR;
tmp->tm_min = (int) (rem / SECSPERMIN);
Expand Down

0 comments on commit 43a6d84

Please sign in to comment.