Skip to content

Commit dcde69d

Browse files
committed
Merge branch 'master' of github.com:hadley/testthat
2 parents 9fd6124 + a75cad9 commit dcde69d

4 files changed

Lines changed: 38 additions & 28 deletions

File tree

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
language: r
44
cache: packages
55
sudo: false
6-
r_github_packages:
7-
- jimhester/covr@v2
6+
7+
r_packages:
8+
- covr
89

910
after_success:
1011
- Rscript -e 'covr::codecov(line_exclusions = c("inst/include/testthat/testthat.h", "inst/include/testthat/vendor/catch.h"))'

NEWS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ factor("a") %>%
2222
The exception to this rule are the expectations that evaluate (i.e.
2323
for messages, warnings, errors, output etc), which invisibly return `NULL`. These functions are now more consistent: using `NA` will cause a failure if there is a errors/warnings/mesages/output (i.e. they're not missing), and will `NULL` fail if there aren't any errors/warnings/mesages/output. This previously didn't work for `expect_output()` (#323), and the error messages were confusing with `expect_error(..., NA)` (#342, @nealrichardson + @krlmlr, #317).
2424

25-
Another change is that `expect_output()` now requires you to explicit print the output if you want to test a print method: `expect_output("a", "a")` will fail, `expect_output(print("a"), "a")` will succeed.
25+
Another change is that `expect_output()` now requires you to explicitly print the output if you want to test a print method: `expect_output("a", "a")` will fail, `expect_output(print("a"), "a")` will succeed.
2626

2727
There are six new expectations:
2828

inst/include/testthat/testthat.h

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@
1313
* TESTTHAT_DISABLED takes precedence.
1414
* 'testthat' is disabled on Solaris by default.
1515
*/
16-
#if !defined(__sun) && !defined(__SVR4)
16+
#if defined(__GNUC__) || defined(__clang__)
1717
# define TESTTHAT_ENABLED
1818
#endif
1919

20+
#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__sun) || defined(__SVR4)
21+
# define TESTTHAT_DISABLED
22+
#endif
23+
2024
#ifndef TESTTHAT_ENABLED
2125
# define TESTTHAT_DISABLED
2226
#endif
@@ -30,22 +34,20 @@
3034
# define CATCH_CONFIG_RUNNER
3135
# endif
3236

33-
// Catch has calls to 'exit' on failure, which upset R CMD check.
34-
// We won't bump into them during normal test execution so just temporarily
35-
// hide it when we include 'catch'. Make sure we get 'exit' from the normal
36-
// places first, though.
37-
# include <cstddef> // std::size_t
38-
# include <cstdlib> // exit
37+
# include <climits> // CHAR_MAX
3938
# include <cstdio> // EOF
40-
extern "C" inline void testthat_exit_override(int status) throw() {}
4139

4240
# ifdef __GNUC__
4341
# pragma GCC diagnostic ignored "-Wparentheses"
4442
# endif
4543

46-
# define exit testthat_exit_override
44+
// Catch has calls to 'exit' on failure, which upsets R CMD check.
45+
// We won't bump into them during normal test execution so just override
46+
// it in the Catch namespace before we include 'catch'.
47+
namespace Catch {
48+
inline void exit(int status) throw() {}
49+
}
4750
# include "vendor/catch.h"
48-
# undef exit
4951

5052
// Implement an output stream that avoids writing to stdout / stderr.
5153
extern "C" void Rprintf(const char*, ...);
@@ -61,12 +63,22 @@ class r_streambuf : public std::streambuf {
6163
protected:
6264

6365
virtual std::streamsize xsputn(const char* s, std::streamsize n) {
64-
Rprintf("%.*s", n, s);
66+
67+
if (n == 1)
68+
Rprintf("%c", *s);
69+
else
70+
Rprintf("%.*s", n, s);
71+
6572
return n;
73+
6674
}
6775

6876
virtual int overflow(int c = EOF) {
69-
if (c != EOF) Rprintf("%.1s", &c);
77+
if (c == EOF)
78+
return c;
79+
if (c > CHAR_MAX)
80+
return c;
81+
Rprintf("%c", (char) c);
7082
return c;
7183
}
7284

@@ -78,15 +90,8 @@ class r_streambuf : public std::streambuf {
7890
};
7991

8092
class r_ostream : public std::ostream {
81-
8293
public:
83-
84-
r_ostream() :
85-
std::ostream(new r_streambuf), pBuffer(static_cast<r_streambuf*>(rdbuf()))
86-
{}
87-
88-
private:
89-
r_streambuf* pBuffer;
94+
r_ostream() : std::ostream(new r_streambuf) {}
9095

9196
};
9297

tests/test-catch.R

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@ library(testthat)
22

33
local({
44

5+
if (!requireNamespace("devtools", quietly = TRUE))
6+
return()
7+
8+
devel <- try(devtools::has_devel(), silent = TRUE)
9+
if (!isTRUE(devel))
10+
return()
11+
512
quietly <- function(expr) {
613
suppressMessages(capture.output(result <- expr))
714
result
815
}
916

10-
if (!requireNamespace("devtools", quietly = TRUE))
11-
skip("'devtools' not available")
12-
1317
owd <- setwd(tempdir())
1418
on.exit(setwd(owd), add = TRUE)
1519

1620
pkgName <- "testthatclient"
1721
pkgPath <- file.path(tempdir(), pkgName)
1822
libPath <- file.path(tempdir(), "rlib")
19-
if (!dir.exists(libPath))
23+
if (!utils::file_test("-d", libPath))
2024
dir.create(libPath)
2125
.libPaths(c(libPath, .libPaths()))
2226

@@ -26,7 +30,7 @@ local({
2630
}, add = TRUE)
2731

2832
quietly(devtools::create(pkgPath))
29-
quietly(use_catch(pkgPath))
33+
quietly(testthat::use_catch(pkgPath))
3034

3135
cat("LinkingTo: testthat",
3236
file = file.path(pkgPath, "DESCRIPTION"),

0 commit comments

Comments
 (0)