Skip to content

Commit a93dbdb

Browse files
committed
Add Travis CI support
1 parent a0fd32d commit a93dbdb

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
langauge: cpp
2+
compiler: gcc
3+
dist: trusty
4+
5+
before_script:
6+
- cd test
7+
script:
8+
- ./test.sh

test/clean.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rm *.h

test/extract_snippets.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/python3
2+
import re
3+
import os
4+
5+
def write_snippet(name, lines):
6+
file_name = '{}.h'.format(name)
7+
with open(file_name, 'w') as f:
8+
for line in lines:
9+
f.write(line)
10+
11+
def extract_tests(filepath):
12+
filepath_short = os.path.basename(filepath)
13+
article_name = filepath_short.split('.')[0]
14+
15+
snippet_start = re.compile(r"^```cpp\s+(\S+)$")
16+
snippet_end = re.compile(r"^```$")
17+
18+
with open(filepath) as f:
19+
in_snippet = False;
20+
for line in f:
21+
m_start = snippet_start.match(line)
22+
m_end = snippet_end.match(line)
23+
24+
if in_snippet and m_end:
25+
in_snippet = False
26+
write_snippet(snippet_name, lines)
27+
28+
if in_snippet:
29+
lines.append(line)
30+
elif m_start:
31+
snippet_name = m_start.group(1)
32+
lines = []
33+
in_snippet = True
34+
35+
36+
if __name__ == '__main__':
37+
for subdir, dirs, files in os.walk('../src/'):
38+
for filename in files:
39+
if filename.endswith(".md"):
40+
extract_tests(os.path.join(subdir, filename))

test/test.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
python extract_snippets.py
3+
4+
if [ -z "$CXX" ];
5+
then
6+
CXX=g++
7+
fi
8+
9+
TESTS=0
10+
SUCCESS=0
11+
for cppfile in *.cpp;
12+
do
13+
TESTS=$((TESTS + 1))
14+
$CXX -std=c++11 $cppfile -o $cppfile.out
15+
COMPILATION=$?
16+
if [ $COMPILATION -eq 0 ];
17+
then
18+
./$cppfile.out
19+
TEST_SUCCESS=$?
20+
if [ $TEST_SUCCESS -eq 0 ];
21+
then
22+
SUCCESS=$((SUCCESS + 1))
23+
else
24+
echo "Test $cppfile failed!"
25+
fi
26+
else
27+
echo "Error while compiling $cppfile!"
28+
fi
29+
30+
rm $cppfile.out
31+
done
32+
33+
echo "$SUCCESS / $TESTS tests were successful."
34+
if [ $SUCCESS -eq $TESTS ];
35+
then
36+
exit 0
37+
else
38+
exit 1
39+
fi

0 commit comments

Comments
 (0)