Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2016-11-19 James J Balamuta <balamut2@illinois.edu>

* inst/unitTests/runit.environments.R: Added environment find unit tests
as well as a symbol access test for environment get.
* inst/unitTests/cpp/Environment.cpp: Idem

2016-11-16 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION: Release 0.12.8
Expand Down
7 changes: 7 additions & 0 deletions inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
\newcommand{\ghpr}{\href{https://github.com/RcppCore/Rcpp/pull/#1}{##1}}
\newcommand{\ghit}{\href{https://github.com/RcppCore/Rcpp/issues/#1}{##1}}

\section{Changes in Rcpp version 0.12.9 (2017-01-xx)}{
\item Changes in Rcpp unit tests
\itemize{
\item Added Environment::find unit tests and an Environment::get(Symbol)
test (James Balamuta in \ghpr{595} addressing issue \ghit{594}).
}
}
\section{Changes in Rcpp version 0.12.8 (2016-11-16)}{
\itemize{
\item Changes in Rcpp API:
Expand Down
15 changes: 15 additions & 0 deletions inst/unitTests/cpp/Environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ SEXP runit_get( Environment env, std::string name){
return env.get( name ) ;
}

// [[Rcpp::export]]
SEXP runit_get_symbol( Environment env, Symbol name){
return env.get( name ) ;
}

// [[Rcpp::export]]
SEXP runit_find( Environment env, std::string name){
return env.find( name ) ;
}

// [[Rcpp::export]]
SEXP runit_find_symbol( Environment env, Symbol name){
return env.find( name ) ;
}

// [[Rcpp::export]]
bool runit_exists( Environment env, std::string st){
return env.exists( st ) ;
Expand Down
44 changes: 37 additions & 7 deletions inst/unitTests/runit.environments.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,44 @@ if (.runThisTest) {
e <- new.env( )
e$a <- 1:10
e$b <- "foo"

checkEquals( runit_get( e, "a" ), e$a, msg = "Environment::get()" )
checkEquals( runit_get( e, "foobar" ), NULL, msg = "Environment::get()" )

# Access with string
checkEquals( runit_get( e, "a" ), e$a, msg = "Environment::get(string)" )
checkEquals( runit_get( e, "foobar" ), NULL, msg = "Environment::get(string)" )
checkEquals( runit_get( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
msg = "Environment(namespace)::get() " )

}

msg = "Environment(namespace)::get(string) " )

# Access with Symbol constructed on call from string
checkEquals( runit_get_symbol( e, "a" ), e$a, msg = "Environment::get(Symbol)" )
checkEquals( runit_get_symbol( e, "foobar" ), NULL, msg = "Environment::get(Symbol)" )
checkEquals( runit_get_symbol( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
msg = "Environment(namespace)::get(Symbol) " )

}

test.environment.find <- function(){
e <- new.env( )
e$a <- 1:10
e$b <- "foo"
bar <- "me"

# Access with string
checkEquals( runit_find( e, "a" ), e$a, msg = "Environment::find(string)" )
checkException( runit_find( e, "foobar" ), NULL, msg = "Environment::find(string) not found" )
checkEquals( runit_find( e, "bar"), bar, msg = "Environment::find(string) inheritance" )
checkEquals( runit_find( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
msg = "Environment(namespace)::find(string)" )

# Access with Symbol constructed on call from string
checkEquals( runit_find_symbol( e, "a" ), e$a, msg = "Environment::find(Symbol)" )
checkException( runit_find_symbol( e, "foobar" ), NULL, msg = "Environment::find(Symbol) not found" )
checkEquals( runit_find_symbol( e, "bar"), bar, msg = "Environment::find(Symbol) inheritance" )
checkEquals( runit_find_symbol( asNamespace("Rcpp"), "CxxFlags"), Rcpp:::CxxFlags,
msg = "Environment(namespace)::find(Symbol)" )

}


test.environment.exists <- function(){
e <- new.env( )
e$a <- 1:10
Expand Down