Skip to content

Commit 766e6e4

Browse files
committed
code health
1 parent 32b2a95 commit 766e6e4

File tree

2 files changed

+79
-82
lines changed

2 files changed

+79
-82
lines changed

R/LdFlags.R

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ getCompiler <- function() {
33
}
44

55
runCmd <- function(...) {
6-
args <- list(command = paste(...))
7-
args$ignore.stdout = TRUE
8-
args$ignore.stderr = TRUE
9-
do.call(system, args)
6+
system(paste(...), ignore.stdout = TRUE, ignore.stderr = TRUE)
107
}
118

129
createTestFiles <- function() {
1310
src <- tempfile("test", fileext = ".cpp")
14-
lib <- tempfile("test", fileext = ".out")
15-
c(src = src, lib = lib)
11+
out <- tempfile("test", fileext = ".out")
12+
c(src = src, out = out)
1613
}
1714

1815
writeLibAtomicTest <- function(file) {
@@ -33,7 +30,7 @@ checkForLibAtomic <- function() {
3330

3431
tmp <- createTestFiles()
3532
writeLibAtomicTest(tmp["src"])
36-
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["lib"], "-latomic")
33+
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["out"], "-latomic")
3734
unlink(tmp)
3835

3936
!failed
@@ -45,7 +42,7 @@ hasAtomicSupport <- function() {
4542

4643
tmp <- createTestFiles()
4744
writeLibAtomicTest(tmp["src"])
48-
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["lib"])
45+
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["out"])
4946
unlink(tmp)
5047

5148
!failed
@@ -57,7 +54,7 @@ checkForLibPthread <- function() {
5754

5855
tmp <- createTestFiles()
5956
cat("#include <pthread.h> \n int main() { return 0; }", file = tmp["src"])
60-
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["lib"], "-lpthread")
57+
failed <- runCmd(getCompiler(), tmp["src"], "-o", tmp["out"], "-lpthread")
6158
unlink(tmp)
6259

6360
!failed

tests/testthat/tests.R

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,99 @@
1-
if (hasAtomicSupport()) {
1+
if (RcppThread:::hasAtomicSupport()) {
22

3-
context("Compile test functions")
4-
Rcpp::sourceCpp(file = normalizePath("../tests.cpp"))
3+
context("Compile test functions")
4+
Rcpp::sourceCpp(file = normalizePath("../tests.cpp"))
55

6-
runs <- 10
7-
for (run in seq_len(runs)) {
8-
context(paste0("---------------------------- run ", run, "/", runs))
9-
test_that("start", expect_true(TRUE))
6+
runs <- 10
7+
for (run in seq_len(runs)) {
8+
context(paste0("---------------------------- run ", run, "/", runs))
9+
test_that("start", expect_true(TRUE))
1010

11-
## -------------------------------------------------------
12-
context("R-monitor")
13-
test_that("R-monitor works", {
14-
expect_output(testMonitor(), "RcppThread says hi!", fixed = TRUE)
15-
})
11+
## -------------------------------------------------------
12+
context("R-monitor")
13+
test_that("R-monitor works", {
14+
expect_output(testMonitor(), "RcppThread says hi!", fixed = TRUE)
15+
})
1616

1717

18-
## -------------------------------------------------------
19-
context("Thread class")
20-
test_that("Thread class works", {
21-
expect_output(testThreadClass())
22-
})
18+
## -------------------------------------------------------
19+
context("Thread class")
20+
test_that("Thread class works", {
21+
expect_output(testThreadClass())
22+
})
2323

2424

25-
## -------------------------------------------------------
26-
context("Thread pool")
25+
## -------------------------------------------------------
26+
context("Thread pool")
2727

28-
test_that("push works", {
29-
testThreadPoolPush()
30-
expect_silent(testThreadPoolPush())
31-
})
28+
test_that("push works", {
29+
testThreadPoolPush()
30+
expect_silent(testThreadPoolPush())
31+
})
3232

33-
test_that("pushReturn works", {
34-
expect_silent(testThreadPoolPushReturn())
35-
})
33+
test_that("pushReturn works", {
34+
expect_silent(testThreadPoolPushReturn())
35+
})
3636

37-
test_that("map works", {
38-
expect_silent(testThreadPoolMap())
39-
})
37+
test_that("map works", {
38+
expect_silent(testThreadPoolMap())
39+
})
4040

41-
test_that("parallelFor works", {
42-
expect_silent(testThreadPoolParallelFor())
43-
})
41+
test_that("parallelFor works", {
42+
expect_silent(testThreadPoolParallelFor())
43+
})
4444

45-
test_that("nested parallelFor works", {
46-
expect_silent(testThreadPoolNestedParallelFor())
47-
})
45+
test_that("nested parallelFor works", {
46+
expect_silent(testThreadPoolNestedParallelFor())
47+
})
4848

49-
test_that("parallelForEach works", {
50-
expect_silent(testThreadPoolParallelForEach())
51-
})
49+
test_that("parallelForEach works", {
50+
expect_silent(testThreadPoolParallelForEach())
51+
})
5252

53-
test_that("nested parallelForEach works", {
54-
expect_silent(testThreadPoolNestedParallelForEach())
55-
})
53+
test_that("nested parallelForEach works", {
54+
expect_silent(testThreadPoolNestedParallelForEach())
55+
})
5656

57-
test_that("works single threaded", {
58-
expect_silent(testThreadPoolSingleThreaded())
59-
})
57+
test_that("works single threaded", {
58+
expect_silent(testThreadPoolSingleThreaded())
59+
})
6060

61-
test_that("destructible without join", {
62-
expect_silent(testThreadPoolDestructWOJoin())
63-
})
61+
test_that("destructible without join", {
62+
expect_silent(testThreadPoolDestructWOJoin())
63+
})
6464

65-
# test_that("rethrows exceptions", {
66-
# expect_silent(testThreadPoolExceptionHandling())
67-
# })
65+
# test_that("rethrows exceptions", {
66+
# expect_silent(testThreadPoolExceptionHandling())
67+
# })
6868

69-
## -------------------------------------------------------
70-
context("Parallel for functions")
69+
## -------------------------------------------------------
70+
context("Parallel for functions")
7171

72-
test_that("parallelFor works", {
73-
expect_silent(testParallelFor())
74-
})
72+
test_that("parallelFor works", {
73+
expect_silent(testParallelFor())
74+
})
7575

76-
test_that("nested parallelFor works", {
77-
expect_silent(testNestedParallelFor())
78-
})
76+
test_that("nested parallelFor works", {
77+
expect_silent(testNestedParallelFor())
78+
})
7979

80-
test_that("parallelForEach works", {
81-
expect_silent(testParallelForEach())
82-
})
80+
test_that("parallelForEach works", {
81+
expect_silent(testParallelForEach())
82+
})
8383

84-
test_that("nested parallelForEach works", {
85-
expect_silent(testNestedParallelForEach())
86-
})
84+
test_that("nested parallelForEach works", {
85+
expect_silent(testNestedParallelForEach())
86+
})
8787

88-
# ------------------------------------------------------
89-
context("Progress tracking")
90-
test_that("ProgressCounter works", {
91-
expect_output(testProgressCounter(), "100% \\(done\\)")
92-
})
88+
# ------------------------------------------------------
89+
context("Progress tracking")
90+
test_that("ProgressCounter works", {
91+
expect_output(testProgressCounter(), "100% \\(done\\)")
92+
})
9393

94-
test_that("ProgressBar works", {
95-
expect_output(testProgressBar(), "100% \\(done\\)")
96-
})
97-
}
94+
test_that("ProgressBar works", {
95+
expect_output(testProgressBar(), "100% \\(done\\)")
96+
})
97+
}
9898

9999
}

0 commit comments

Comments
 (0)