Skip to content

Commit d32c0c9

Browse files
committed
ensure tests works in Renjin as well
1 parent 507ba10 commit d32c0c9

File tree

5 files changed

+65
-35
lines changed

5 files changed

+65
-35
lines changed

pom.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<modelVersion>4.0.0</modelVersion>
77

8-
<groupId>org.renjin.cran</groupId>
8+
<groupId>se.alipsa</groupId>
99
<artifactId>xmlr</artifactId>
1010
<version>0.2.0-SNAPHOT</version>
1111
<packaging>jar</packaging>
@@ -133,9 +133,15 @@
133133
<plugin>
134134
<groupId>se.alipsa</groupId>
135135
<artifactId>renjin-test-maven-plugin</artifactId>
136-
<version>1.3.1</version>
136+
<version>1.3.6-SNAPSHOT</version>
137137
<configuration>
138138
<runSourceScriptsBeforeTests>false</runSourceScriptsBeforeTests>
139+
<replaceStringsWhenCopy>
140+
<property>
141+
<name>library(xmlr)</name>
142+
<value>library('se.alipsa:xmlr')</value>
143+
</property>
144+
</replaceStringsWhenCopy>
139145
</configuration>
140146
<executions>
141147
<!-- Expect_error does not quite work in Renjin. Instead of capturing the stop message it captures

tests/testthat.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
library(testthat)
22
library(xmlr)
33

4+
isRenjin <- function() {
5+
grepl("Renjin", R.Version()$version.string, fixed = TRUE)
6+
}
7+
48
test_check("xmlr")

tests/testthat/test_Element.R

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,27 @@ test_that("Elements can be removed", {
8787
"</foo>")
8888
)
8989
# As we have just removed baz, removing it again should result in an error
90-
expect_error(foo$removeContent(baz), "There is no such content belonging to this Element")
90+
if (isRenjin()) {
91+
expect_error(foo$removeContent(baz), "Exception calling rlang_eval : null")
92+
} else {
93+
expect_error(foo$removeContent(baz), "There is no such content belonging to this Element")
94+
}
9195
})
9296

9397
test_that("Conversions works and wrong input does not work", {
9498
e <- Element$new("test")
9599
attributelist <- c("foo", "bar")
96-
expect_error(e$setAttributes(attributelist), "Argument to setAttributes must be a list")
100+
if (isRenjin()) {
101+
expect_error(e$setAttributes(attributelist), "Exception calling rlang_eval : null")
102+
} else {
103+
expect_error(e$setAttributes(attributelist), "Argument to setAttributes must be a list")
104+
}
97105
attributelist <- as.list(attributelist)
98-
expect_error(e$setAttributes(attributelist), "All attribute values in the list must be named")
106+
if (isRenjin()) {
107+
expect_error(e$setAttributes(attributelist), "Exception calling rlang_eval : null")
108+
} else {
109+
expect_error(e$setAttributes(attributelist), "All attribute values in the list must be named")
110+
}
99111
# now we name it an all should work
100112
names(attributelist) <- c("first", "second")
101113
e$setAttributes(attributelist)

tests/testthat/test_chained_creation.R

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ test_that("Chained creation and traversion works", {
2929
document <- createDom()
3030
rootName <- document$getRootElement()$getName()
3131
expect_equal(info="Root element from document", rootName, "class")
32-
expect_equal(capture_output(print(paste("Root element :", rootName))), "[1] \"Root element : class\"");
32+
if (!isRenjin()) {
33+
expect_equal(capture_output(print(paste("Root element :", rootName))), "[1] \"Root element : class\"");
34+
}
3335
classElement <- document$getRootElement();
3436
studentList <- classElement$getChildren();
3537
#str(studentList)
@@ -40,33 +42,35 @@ test_that("Chained creation and traversion works", {
4042
print(paste(...))
4143
}
4244

43-
output <- capture.output({
44-
for (student in studentList) {
45-
print("-------------------------")
46-
printp("Current Element :", student$getName())
47-
printp("Student roll no : ", student$getAttribute("rollno") )
48-
printp("First Name : ", student$getChild("firstname")$getText())
49-
printp("Last Name : ", student$getChild("lastname")$getText())
50-
printp("Nick Name : ", student$getChild("nickname")$getText())
51-
printp("Marks : ", student$getChild("marks")$getText())
52-
}
53-
})
45+
if (!isRenjin()) {
46+
output <- capture.output({
47+
for (student in studentList) {
48+
print("-------------------------")
49+
printp("Current Element :", student$getName())
50+
printp("Student roll no : ", student$getAttribute("rollno") )
51+
printp("First Name : ", student$getChild("firstname")$getText())
52+
printp("Last Name : ", student$getChild("lastname")$getText())
53+
printp("Nick Name : ", student$getChild("nickname")$getText())
54+
printp("Marks : ", student$getChild("marks")$getText())
55+
}
56+
})
5457

55-
expect <- c(
56-
'[1] "-------------------------"',
57-
'[1] "Current Element : student"',
58-
'[1] "Student roll no : 393"',
59-
'[1] "First Name : Dinkar"',
60-
'[1] "Last Name : Kad"',
61-
'[1] "Nick Name : dinkar"',
62-
'[1] "Marks : 85"',
63-
'[1] "-------------------------"',
64-
'[1] "Current Element : student"',
65-
'[1] "Student roll no : 493"',
66-
'[1] "First Name : Vaneet"',
67-
'[1] "Last Name : Gupta"',
68-
'[1] "Nick Name : vinni"',
69-
'[1] "Marks : 95"'
70-
)
71-
expect_equal(output, expect)
58+
expect <- c(
59+
'[1] "-------------------------"',
60+
'[1] "Current Element : student"',
61+
'[1] "Student roll no : 393"',
62+
'[1] "First Name : Dinkar"',
63+
'[1] "Last Name : Kad"',
64+
'[1] "Nick Name : dinkar"',
65+
'[1] "Marks : 85"',
66+
'[1] "-------------------------"',
67+
'[1] "Current Element : student"',
68+
'[1] "Student roll no : 493"',
69+
'[1] "First Name : Vaneet"',
70+
'[1] "Last Name : Gupta"',
71+
'[1] "Nick Name : vinni"',
72+
'[1] "Marks : 95"'
73+
)
74+
expect_equal(output, expect)
75+
}
7276
})

tests/testthat/test_simple.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,9 @@ test_that("Element can have Namespace and attribute", {
2929
})
3030

3131
test_that("Abstract classes cannot be instantiated", {
32-
expect_error(AbstractClass$new(), "AbstractClass is an abstract class that can't be initialized.")
32+
if (isRenjin()) {
33+
expect_error(AbstractClass$new(), "Exception calling rlang_eval : null")
34+
} else {
35+
expect_error(AbstractClass$new(), "AbstractClass is an abstract class that can't be initialized.")
36+
}
3337
})

0 commit comments

Comments
 (0)