Skip to content

Commit 404e0ba

Browse files
committed
Simple rostest example in python
I'll use this as an example to write a rust library that works with rostest.
1 parent 9c7e404 commit 404e0ba

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ project(ros_rust)
33

44
catkin_package()
55

6+
if(CATKIN_ENABLE_TESTING)
7+
find_package(rostest REQUIRED)
8+
add_rostest(test/empty.test)
9+
endif()

scripts/test_empty

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
import re
3+
import sys
4+
5+
filename_out = None
6+
f = open('/tmp/foo', 'w+')
7+
f.write(str(sys.argv))
8+
for arg in sys.argv[1:]:
9+
m = re.match('--gtest_output=xml:(.+.xml)', arg)
10+
if m is not None:
11+
print >> f, m.groups()[0]
12+
filename_out = m.groups()[0]
13+
f.close()
14+
15+
output = '''\
16+
<?xml version="1.0" encoding="UTF-8"?>
17+
<testsuites tests="3" failures="1" errors="0" time="35" name="AllTests">
18+
<testsuite name="MathTest" tests="2" failures="1" errors="0" time="15">
19+
<testcase name="Addition" status="run" time="7" classname="">
20+
<failure message="Value of: add(1, 1)&#x0A; Actual: 3&#x0A;Expected: 2" type=""/>
21+
<failure message="Value of: add(1, -1)&#x0A; Actual: 1&#x0A;Expected: 0" type=""/>
22+
</testcase>
23+
<testcase name="Subtraction" status="run" time="5" classname="">
24+
</testcase>
25+
</testsuite>
26+
<testsuite name="LogicTest" tests="1" failures="0" errors="0" time="5">
27+
<testcase name="NonContradiction" status="run" time="5" classname="">
28+
</testcase>
29+
</testsuite>
30+
</testsuites>
31+
'''
32+
33+
if filename_out is not None:
34+
f_out = open(filename_out, 'w+')
35+
f_out.write(output)
36+
f_out.close()
37+
38+

test/empty.test

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<launch>
2+
<test test-name="test_empty_node" pkg="ros_rust" type="test_empty" />
3+
</launch>

0 commit comments

Comments
 (0)